Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
comparison_ascii.C
이 파일의 문서화 페이지로 가기
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 
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);
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];
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);
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 }
ntupleExperimental Fill(depthExp, EdepExp)
Float_t f4
hipStyle SetTextSize(0.05)
vector< Float_t > vec_iX
Float_t dose
gr2 SetMarkerSize(0.5)
hist1 Draw("HIST")
gr1 SetMarkerStyle(20)
TLegend * leg
Definition: compare.C:67
experimentalTree SetBranchAddress("EdepExp",&EdepExp)
Float_t normFactor
Float_t f2
TString doseFileExp
leg SetFillColor(0)
cout<< t1-> GetEntries()
Definition: plottest35.C:29
Float_t depthExp
Definition: comparison.C:22
nlines
G4float Float_t
Float_t f3
G4int Int_t
cout<< "Reading file \" "<< doseFileExp<< "\" ... ";Long64_t nlines=ntupleExperimental-> ReadFile(doseFileExp,"depthExp:EdepExp")
Float_t EdepExp
Definition: comparison.C:22
ntupleExperimental Reset()
printf("%d Experimental points found\n", nlines)
Float_t sumDose
Float_t f1
Int_t oldX
Int_t nentries
Definition: comparison.C:29
leg AddEntry(gr1,"Reference data","lp")
Float_t iX
ifstream in
Definition: comparison.C:7
Float_t norm
gr1 SetMarkerColor(1)
TFile * file
Char_t n[5]
vector< Float_t > vec_dose
TNtuple * TNtupleSim
TNtuple * ntupleExperimental
Definition: comparison.C:28
ntupleExperimental GetEntry(0)
TString doseFileSim