readMyTextFile.C
Go to the documentation of this file.
1 #include "Riostream.h"
2 void readMyTextFile(string testFile) {
3  // Read data from an ascii file and create a root file with an histogram and an ntuple.
4  // see a variant of this macro in basic2.C
5  //Author: Rene Brun
6 
7 
8  // read file $ROOTSYS/tutorials/tree/basic.dat
9  // this file has 3 columns of float data
10 
11  ifstream in;
12  in.open(("test_"+testFile+".txt").c_str());//Form("%stest.txt",dir.Data()));
13 
14  ifstream intrain;
15  intrain.open(("train_"+testFile+".txt").c_str());
16 
17  Float_t iteration,lossTest,accuracyTest,lossTrain, iterationTrain;
18  Int_t nlinesTest = 0;
19  Int_t nlinesTrain = 0;
20  TFile *f = new TFile((testFile+".root").c_str(),"RECREATE");
21  //TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
22  TNtuple *ntupleTrain = new TNtuple("ntupleTrain","data from ascii file","iterationTrain:lossTrain");
23  TNtuple *ntupleTest = new TNtuple("ntupleTest","data from ascii file","iteration:lossTest:accuracyTest");
24 
25  while (1) {
26  intrain >> iterationTrain >> lossTrain;
27  if (!intrain.good()) break;
28  if (nlinesTrain < 5) printf("iterationTrain=%8f,lossTrain=%8f\n",iterationTrain,lossTrain);
29  //h1->Fill(x);
30  ntupleTrain->Fill(iterationTrain,lossTrain);
31  nlinesTrain++;
32  }
33  printf(" found %d points\n",nlinesTrain);
34 
35  while (1) {
36  in >> iteration >> lossTest >> accuracyTest;
37  if (!in.good()) break;
38  if (nlinesTest < 5) printf("iteration=%8f, lossTest=%8f, accuracyTest=%8f\n",iteration, lossTest, accuracyTest);
39  //h1->Fill(x);
40  ntupleTest->Fill(iteration,lossTest,accuracyTest);
41  nlinesTest++;
42  }
43  printf(" found %d points\n",nlinesTest);
44 
45  in.close();
46  intrain.close();
47 
48  f->Write();
49 }
printf("%d Experimental points found\n", nlines)
ifstream in
Definition: comparison.C:7
void readMyTextFile(string testFile)
Definition: readMyTextFile.C:2