1 | int main() |
---|
2 | { |
---|
3 | void average_time_distri(); |
---|
4 | average_time_distri(); |
---|
5 | return 0; |
---|
6 | } |
---|
7 | |
---|
8 | // |
---|
9 | // test.C |
---|
10 | // |
---|
11 | // |
---|
12 | // Created by moretto on 13/06/13. |
---|
13 | // |
---|
14 | // |
---|
15 | |
---|
16 | |
---|
17 | #include <TROOT.h> |
---|
18 | #include <TRint.h> |
---|
19 | #include <TFile.h> |
---|
20 | #include <TGFileDialog.h> |
---|
21 | #include <TCanvas.h> |
---|
22 | #include <TStyle.h> |
---|
23 | #include <TTree.h> |
---|
24 | #include <TChain.h> |
---|
25 | #include <TH1.h> |
---|
26 | #include <TH2.h> |
---|
27 | #include <TProfile.h> |
---|
28 | #include <TF1.h> |
---|
29 | #include <TRandom.h> |
---|
30 | #include <TRandom1.h> |
---|
31 | #include <TMath.h> |
---|
32 | #include <TLegend.h> |
---|
33 | #include <TGraph.h> |
---|
34 | #include <TMarker.h> |
---|
35 | #include <TArrow.h> |
---|
36 | #include <TGraphErrors.h> |
---|
37 | #include <TGraphAsymmErrors.h> |
---|
38 | #include <TLatex.h> |
---|
39 | #include <TLegend.h> |
---|
40 | #include <TLegendEntry.h> |
---|
41 | #include <TPaveText.h> |
---|
42 | #include <TMath.h> |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | #include "Riostream.h" |
---|
47 | #include "TCanvas.h" |
---|
48 | #include "TFile.h" |
---|
49 | #include "TTree.h" |
---|
50 | #include "TControlBar.h" |
---|
51 | #include "TSystem.h" |
---|
52 | #include "TGFileDialog.h" |
---|
53 | #include "TPaveText.h" |
---|
54 | #include "TString.h" |
---|
55 | #include "TView.h" |
---|
56 | #include "TApplication.h" |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | #include "EEvent.hh" |
---|
61 | #include "EDetPhoton.hh" |
---|
62 | #include "EDetector.hh" |
---|
63 | |
---|
64 | |
---|
65 | #include <iostream> |
---|
66 | #include <cmath> |
---|
67 | #include <cstring> |
---|
68 | #include <list> |
---|
69 | #include <utility> |
---|
70 | #include <numeric> |
---|
71 | #include <functional> |
---|
72 | #include <algorithm> |
---|
73 | #include <vector> |
---|
74 | |
---|
75 | const char* inputfile1="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/30_ns_TimeResolution__100_event/simu.root"; |
---|
76 | const char* inputfile2="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/10_ns_TimeResolution__100_event/simu.root"; |
---|
77 | const char* inputfile3="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/5_ns_TimeResolution__100_event/simu.root"; |
---|
78 | const char* inputfile4="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/0_ns_TimeResolution__100_event/simu.root"; |
---|
79 | const char* inputfile5="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/1_ns_TimeResolution__100_event/simu.root"; |
---|
80 | const char* inputfile6="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/20_ns_TimeResolution__100_event/simu.root"; |
---|
81 | const char* inputfile7="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/bis_10_ns__100_event/simu.root"; |
---|
82 | const char* inputfile8="/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/camille_work/KIT_phase1_study/60_ns_TimeResolution__100_event/simu.root"; |
---|
83 | |
---|
84 | |
---|
85 | TFile *f; |
---|
86 | EEvent* ev = 0; |
---|
87 | EDetector* gDetector = NULL; |
---|
88 | TTree* tree = 0; |
---|
89 | |
---|
90 | int nb_entries = 0; |
---|
91 | int nb_photons = 0; |
---|
92 | int macrocell_status = 0; |
---|
93 | int photon_type = 0; |
---|
94 | |
---|
95 | void init(const char*, int index); |
---|
96 | Bool_t loadevent(int i=0); |
---|
97 | void process(int num); |
---|
98 | |
---|
99 | //______________________________________________________________________________ |
---|
100 | void average_time_distri() |
---|
101 | { |
---|
102 | init(inputfile8, 1); |
---|
103 | process(1); |
---|
104 | } |
---|
105 | |
---|
106 | //______________________________________________________________________________ |
---|
107 | void init(const char* fname, int index) |
---|
108 | { |
---|
109 | f = new TFile(fname); |
---|
110 | |
---|
111 | char ttree_name[50]; |
---|
112 | sprintf(ttree_name, "tree_%d", index); |
---|
113 | |
---|
114 | tree = new TTree (ttree_name, "output tree from esaf simulation"); |
---|
115 | tree = (TTree*)gDirectory->Get("etree"); |
---|
116 | if ( tree ) |
---|
117 | { |
---|
118 | nb_entries = tree->GetEntries(); |
---|
119 | //Printf("# tree found with %d events stored.", nb_entries); |
---|
120 | } |
---|
121 | |
---|
122 | } |
---|
123 | |
---|
124 | //______________________________________________________________________________ |
---|
125 | Bool_t loadevent(int i) |
---|
126 | { |
---|
127 | if ( !tree ) |
---|
128 | { |
---|
129 | Printf("# ERROR: init(): unable to retrieve etree from TFile. Exiting"); |
---|
130 | return kFALSE; |
---|
131 | } |
---|
132 | |
---|
133 | // associate the tree and the event |
---|
134 | if ( !ev ) |
---|
135 | { |
---|
136 | ev = new EEvent(); |
---|
137 | ev->SetBranches(tree); |
---|
138 | |
---|
139 | //Printf("# tree and event associated"); |
---|
140 | } |
---|
141 | |
---|
142 | tree->GetEntry(i); |
---|
143 | |
---|
144 | gDetector = ev->GetDetector(); |
---|
145 | |
---|
146 | //Printf("# Event %d loaded", i); |
---|
147 | |
---|
148 | return kTRUE; |
---|
149 | } |
---|
150 | |
---|
151 | //______________________________________________________________________________ |
---|
152 | void process(int num) |
---|
153 | { |
---|
154 | TH1F *histo[200]; |
---|
155 | |
---|
156 | //Get the histo distribution of GTU time arrival of photon for each event |
---|
157 | |
---|
158 | char canvas_histo_name[50]; |
---|
159 | sprintf(canvas_histo_name, "c_histo_%d", num); |
---|
160 | |
---|
161 | TCanvas *c1 = new TCanvas(canvas_histo_name, "GTU Distribution"); |
---|
162 | c1->Divide(4,4); |
---|
163 | |
---|
164 | for (int i=0; i<nb_entries; i++) |
---|
165 | { |
---|
166 | loadevent(i); |
---|
167 | nb_photons = gDetector->GetNumPhotons(); |
---|
168 | //Printf("# Number of photon for event %d => %d", i, nb_photons); |
---|
169 | |
---|
170 | char histo_name[50]; |
---|
171 | sprintf(histo_name, "histo_%d_%d", num, i); |
---|
172 | histo[i] = new TH1F(histo_name, "histo for one event", 128, 0, 128); |
---|
173 | histo[i]->Reset(); |
---|
174 | |
---|
175 | |
---|
176 | for (int j=0; j<nb_photons; j++) |
---|
177 | { |
---|
178 | macrocell_status = gDetector->GetPhoton(j)->GetMacroCell(); |
---|
179 | photon_type = gDetector->GetPhoton(j)->GetType(); |
---|
180 | |
---|
181 | if (macrocell_status == 1 & photon_type != 2) //on ne sélectionne que les photons étant détectés par l'électronique & autre que les Cerenkov |
---|
182 | { |
---|
183 | Float_t gtu = gDetector->GetPhoton(j)->GetGtu(); |
---|
184 | histo[i]->Fill(gtu); |
---|
185 | } |
---|
186 | |
---|
187 | } |
---|
188 | |
---|
189 | c1->cd(i+1); |
---|
190 | histo[i]->GetXaxis()->SetTitle("GTU"); |
---|
191 | histo[i]->Draw(); |
---|
192 | |
---|
193 | } |
---|
194 | |
---|
195 | //Loop on the histo array to produce a TProfile |
---|
196 | |
---|
197 | char hprof_name[50]; |
---|
198 | sprintf(hprof_name, "hprof_%d", num); |
---|
199 | TProfile *hprof; |
---|
200 | |
---|
201 | hprof = new TProfile(hprof_name, "Average number of photons per GTU", 128, 0, 128); |
---|
202 | hprof->Reset(); |
---|
203 | |
---|
204 | for (int k=0; k<nb_entries; k++) |
---|
205 | { |
---|
206 | for (int l=0; l<128; l++) |
---|
207 | { |
---|
208 | hprof->Fill(l, histo[k]->GetBinContent(l)); |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | char canvas_hprof_name[50]; |
---|
213 | sprintf(canvas_hprof_name, "c_hprof_%d", num); |
---|
214 | |
---|
215 | TCanvas *c2 = new TCanvas(canvas_hprof_name, "TProfile distribution of the GTU arrival time of photons"); |
---|
216 | c2->cd(); |
---|
217 | hprof->Draw(); |
---|
218 | |
---|
219 | //Save the TProfile one a .root file |
---|
220 | |
---|
221 | TFile file("/Users/moretto/Documents/thesis/ESAF/Code/esaf_lal/esaf/packages/analysis/average_time_distri_60ns.root", "new"); |
---|
222 | hprof->Write(); |
---|
223 | |
---|
224 | } |
---|