comparison_ascii.C
Go to the documentation of this file.
1 {
2 #include <vector>
3  gROOT->Reset();
4  ifstream in;
5  TFile * file = new TFile("Dose.root","RECREATE");
6  // LOAD THE EXPERIMENTAL DATA FILE
7  // CONTAINED IN THE DIRECTORY
8  // hadrontherapy/experimentalData/proton/BraggPeak
9 
10 
11  TNtuple *ntupleExperimental = new TNtuple("ntupleExperimental","Protons, exp. data", "depthExp:EdepExp");
12 
13  vector <Float_t> vec_dose, vec_iX;
14 
15  TString doseFileExp = "../../../experimentalData/proton/BraggPeak/62MeVInWater.out";
16 
17  cout << "Reading file \" " << doseFileExp << "\" ... ";
18  Long64_t nlines = ntupleExperimental -> ReadFile(doseFileExp, "depthExp:EdepExp");
19  if (nlines <=0){cout << "Error: Check file \"" << doseFileExp << "\"\n"; return;}
20 
21  printf("%d Experimental points found\n", nlines);
22 
23  Float_t depthExp, EdepExp;
24  ntupleExperimental -> SetBranchAddress("EdepExp", &EdepExp);
25  ntupleExperimental -> SetBranchAddress("depthExp", &depthExp);
26 
27 
28  // CREATION AND NORMALISATION TO THE FIRST POINT OF AN NTUPLE CONTAINING THE EXPERIMENTAL DATA
29  Int_t nentries = (Int_t)ntupleExperimental -> GetEntries();
30  ntupleExperimental -> GetEntry(0);
31  Float_t normFactor = EdepExp;
32  for (Int_t l = 0; l<nentries; l++)
33  {
34  ntupleExperimental -> GetEntry(l);
35  vec_dose.push_back(EdepExp);
36  vec_iX.push_back(depthExp);
37  }
38 
39  ntupleExperimental->Reset();
40 
41  for (Int_t l=0;l<vec_dose.size();l++)
42  {
43  depthExp = vec_iX[l];
44  EdepExp = vec_dose[l]/normFactor;
45  ntupleExperimental -> Fill(depthExp, EdepExp);
46  }
47 
48  //*****************************************************************************
49  // Load Simulation file
50  TString doseFileSim = "../../../SimulationOutputs/proton/BraggPeak/Dose.out";
51  TNtuple *TNtupleSim = new TNtuple("SimTree","dose from ascii file", "iX:jY:kZ:dose");
52 
53  in.open(doseFileSim);
54  if (!in.is_open()){cout << "Error: Check file \"" << doseFileSim << "\"\n"; return;}
55  Char_t n[5];
56  Float_t f1, f2, f3, f4;
57  nlines = 0;
58  cout << "Reading file \" " << doseFileSim << "\" ... ";
59  // Skip j,j,k,Dose strings
60  in >> n >> n >> n >> n;
61  do{
62  in >> f1 >> f2 >> f3 >> f4;
63  nlines++;
64  TNtupleSim -> Fill(f1, f2, f3, f4);
65  nlines++;}
66  while(in.good());
67 
68  if (nlines <= 0){cout << "\nNo data found! Check file \"" << doseFileSim << "\"\n"; return;}
69  in.close();
70 
71  Float_t iX, dose, sumDose = 0., norm = 0. ;
72  TNtupleSim -> SetBranchAddress("dose", &dose);
73  TNtupleSim -> SetBranchAddress("iX", &iX);
74 
75  // Normalize data to 1 at the entry!
76 
77  nentries = (Int_t)TNtupleSim -> GetEntries();
78  TNtupleSim -> GetEntry(0);
79  Int_t oldX = iX;
80  vec_iX.clear();
81  vec_dose.clear();
82  // Sum dose along X --> i
83  for (Int_t l = 0; l<nentries; l++)
84  {
85  TNtupleSim -> GetEntry(l);
86  if (iX==oldX){ sumDose+=dose;}
87  else
88  {
89  vec_dose.push_back(sumDose);
90  vec_iX.push_back(oldX);
91  sumDose = dose;
92  oldX = iX;
93  }
94  }
95  printf("%d Simulated points found\n", vec_iX.size());
96  // Mean over the first points
97  for (Int_t l=0; l<5; l++)
98  {
99  norm +=vec_dose[l];
100  }
101  norm /=l;
102 
103  TNtupleSim -> Reset();
104  // Fill with normalized values. I suppose that slabs/voxel are 0.2 mm depth
105  for (Int_t l=0;l<vec_dose.size();l++)
106  {
107  // Slabs (voxels) are 0.2 mm depth
108  iX = 0.1 + (vec_iX[l]*0.2);
109  dose = vec_dose[l]/norm;
110  TNtupleSim -> Fill(iX, 0, 0, dose);
111  }
112 
113  TCanvas *c1 = new TCanvas ("c1","c1",200,10,600,400);
114  // Triangle
115  TNtupleSim-> SetMarkerStyle(26);
116  TNtupleSim-> SetMarkerSize(0.8);
117  // Square
118  //TNtupleSim-> SetMarkerStyle(25);
119  // Star
120  //TNtupleSim-> SetMarkerStyle(3);
121  // circle
122  ntupleExperimental -> SetMarkerStyle(4);
123  ntupleExperimental -> SetMarkerColor(2);
124  ntupleExperimental -> SetMarkerSize(0.8);
125 
126  ntupleExperimental -> Draw("EdepExp:depthExp");
127  TNtupleSim -> Draw("dose:iX","","same");
128 
129 
130  // LEGEND
131  leg = new TLegend(0.50,0.60,0.20,0.70);
132  leg -> SetTextSize(0.035);
133  leg -> SetFillColor(0);
134  leg -> AddEntry(ntupleExperimental, "Experiment", "P");
135  leg -> AddEntry(TNtupleSim, "Simulation", "P");
136  leg -> Draw();
137 
138 
139  //c1->SaveAs("braggPeakComparison.pdf");
140 }
TNtuple * ntupleExperimental
Float_t f4
Float_t EdepExp
vector< Float_t > vec_iX
leg AddEntry(ntupleExperimental,"Experiment","P")
Float_t dose
ntupleExperimental Draw("EdepExp:depthExp")
TNtupleSim Fill(f1, f2, f3, f4)
Float_t normFactor
Float_t f2
TString doseFileExp
TNtupleSim SetMarkerSize(0.8)
cout<< t1-> GetEntries()
Definition: plottest35.C:29
TCanvas * c1
nlines
Float_t f3
cout<< "Reading file \" "<< doseFileExp<< "\" ... ";Long64_t nlines=ntupleExperimental-> ReadFile(doseFileExp,"depthExp:EdepExp")
Int_t nentries
ntupleExperimental Reset()
printf("%d Experimental points found\n", nlines)
Float_t sumDose
Float_t f1
TNtupleSim SetMarkerStyle(26)
Float_t depthExp
leg SetTextSize(0.035)
OStream cout
Definition: OStream.cxx:6
Int_t oldX
leg SetFillColor(0)
ifstream in
Float_t iX
Float_t norm
TFile * file
Char_t n[5]
vector< Float_t > vec_dose
ntupleExperimental SetMarkerColor(2)
TNtuple * TNtupleSim
ntupleExperimental SetBranchAddress("EdepExp",&EdepExp)
ntupleExperimental GetEntry(0)
TString doseFileSim