1 | // |
---|
2 | // Usage : |
---|
3 | // OS> cd ELYSE/<version>/cmt |
---|
4 | // OS> <source setup> |
---|
5 | // OS> <have a ELYSE.root file in current directory> |
---|
6 | // OS> root |
---|
7 | // root[] gSystem->Load("libELYSEAIDADict"); |
---|
8 | // root[] .x ../scripts/ROOT/aida_ROOT.C |
---|
9 | // |
---|
10 | |
---|
11 | // |
---|
12 | // rootcint version of the applications/ELYSE_analysis.C program. |
---|
13 | // The ELYSE.root data are read by using OpenScientist/AIDA (and |
---|
14 | // then Rio) and the histos are done by using ROOT/TH*. |
---|
15 | // |
---|
16 | // WARNING : CINT can't handle the dynamic_cast, then we use |
---|
17 | // the cast methods found on the AIDA interfaces basic classes. |
---|
18 | // |
---|
19 | |
---|
20 | ////////////////////////////////////////////////////////////////////////////// |
---|
21 | ////////////////////////////////////////////////////////////////////////////// |
---|
22 | ////////////////////////////////////////////////////////////////////////////// |
---|
23 | AIDA::ITuple* cast_Tuple( |
---|
24 | AIDA::ITupleEntry* aEntry |
---|
25 | ) |
---|
26 | ////////////////////////////////////////////////////////////////////////////// |
---|
27 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
28 | { |
---|
29 | #ifdef __CINT__ |
---|
30 | //FIXME : CINT can't handle dynamic_cast : |
---|
31 | //AIDA-3.2.1 : ITupleEntry does not have the cast method. |
---|
32 | //return (AIDA::ITuple*)aEntry->cast("AIDA::ITuple"); |
---|
33 | return cast_ITuple(aEntry); |
---|
34 | #else |
---|
35 | return dynamic_cast<AIDA::ITuple*>(aEntry); |
---|
36 | #endif |
---|
37 | } |
---|
38 | ////////////////////////////////////////////////////////////////////////////// |
---|
39 | bool get_XYZ( |
---|
40 | AIDA::ITuple& aParent |
---|
41 | ,int aColumn |
---|
42 | ,double& aX |
---|
43 | ,double& aY |
---|
44 | ,double& aZ |
---|
45 | ) |
---|
46 | ////////////////////////////////////////////////////////////////////////////// |
---|
47 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
48 | { |
---|
49 | AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(aColumn); |
---|
50 | if(!entry) return false; |
---|
51 | |
---|
52 | AIDA::ITuple* tuple = cast_Tuple(entry); |
---|
53 | if(!tuple) return false; |
---|
54 | |
---|
55 | tuple->start(); |
---|
56 | if(!tuple->next()) return false; |
---|
57 | |
---|
58 | aX = tuple->getDouble(0); |
---|
59 | aY = tuple->getDouble(1); |
---|
60 | aZ = tuple->getDouble(2); |
---|
61 | |
---|
62 | return true; |
---|
63 | } |
---|
64 | ////////////////////////////////////////////////////////////////////////////// |
---|
65 | ////////////////////////////////////////////////////////////////////////////// |
---|
66 | ////////////////////////////////////////////////////////////////////////////// |
---|
67 | bool dump_tracks( |
---|
68 | AIDA::ITuple& aParent |
---|
69 | ) |
---|
70 | ////////////////////////////////////////////////////////////////////////////// |
---|
71 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
72 | { |
---|
73 | AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(8); |
---|
74 | if(!entry) return false; |
---|
75 | |
---|
76 | AIDA::ITuple* tuple = cast_Tuple(entry); |
---|
77 | if(!tuple) return false; |
---|
78 | |
---|
79 | //if(nPart!=tracks->rows()) { |
---|
80 | // std::cout << "read: nPart / tracks mismatch " |
---|
81 | // << nPart << " " << tracks->rows() << std::endl; |
---|
82 | // return false; |
---|
83 | //} |
---|
84 | |
---|
85 | tuple->start(); |
---|
86 | int irow = 0; |
---|
87 | while(tuple->next()) { |
---|
88 | |
---|
89 | int pId = tuple->getInt(0); |
---|
90 | int parent = tuple->getInt(1); |
---|
91 | float timeStart = tuple->getFloat(2); |
---|
92 | |
---|
93 | double dx,dy,dz; |
---|
94 | if(!get_XYZ(*tuple,3,dx,dy,dz)) return false; |
---|
95 | |
---|
96 | double mass = tuple->getDouble(4); |
---|
97 | double pTot = tuple->getDouble(5); |
---|
98 | double ETot = tuple->getDouble(6); |
---|
99 | |
---|
100 | double px,py,pz; |
---|
101 | if(!get_XYZ(*tuple,7,px,py,pz)) return false; |
---|
102 | |
---|
103 | double start_x,start_y,start_z; |
---|
104 | if(!get_XYZ(*tuple,8,start_x,start_y,start_z)) return false; |
---|
105 | |
---|
106 | double stop_x,stop_y,stop_z; |
---|
107 | if(!get_XYZ(*tuple,9,stop_x,stop_y,stop_z)) return false; |
---|
108 | |
---|
109 | int startVol = tuple->getInt(10); |
---|
110 | int stopVol = tuple->getInt(11); |
---|
111 | |
---|
112 | std::cout << "----> Tk{"<<irow<<"}: " |
---|
113 | << " pId " << pId |
---|
114 | << " parent " << parent |
---|
115 | << " creation time " << timeStart |
---|
116 | << " Volumes " << startVol << " " << stopVol << "\n" |
---|
117 | << " Start Pos (" << start_x |
---|
118 | << "," << start_y << "," << start_z << ")\n" |
---|
119 | << " Stop Pos (" << stop_x |
---|
120 | << "," << stop_y << "," << stop_z << ")\n" |
---|
121 | << " dx,dy,dz " << dx << " " << dy << " " << dz << "\n" |
---|
122 | << " m " << mass |
---|
123 | << " ETot " << ETot |
---|
124 | << " pTot " << pTot |
---|
125 | << " px,py,pz " << px << " " << py << " " << pz << "\n" |
---|
126 | << std::endl; |
---|
127 | |
---|
128 | irow++; |
---|
129 | } |
---|
130 | return true; |
---|
131 | } |
---|
132 | ////////////////////////////////////////////////////////////////////////////// |
---|
133 | bool process_hits_times( |
---|
134 | AIDA::ITuple& aParent |
---|
135 | ,TH1D& aHisto |
---|
136 | ) |
---|
137 | ////////////////////////////////////////////////////////////////////////////// |
---|
138 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
139 | { |
---|
140 | AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(2); |
---|
141 | if(!entry) return false; |
---|
142 | |
---|
143 | AIDA::ITuple* tuple = cast_Tuple(entry); |
---|
144 | if(!tuple) return false; |
---|
145 | |
---|
146 | tuple->start(); |
---|
147 | while(tuple->next()) { |
---|
148 | |
---|
149 | float time = tuple->getFloat(0); |
---|
150 | |
---|
151 | aHisto.Fill(time); |
---|
152 | } |
---|
153 | return true; |
---|
154 | } |
---|
155 | ////////////////////////////////////////////////////////////////////////////// |
---|
156 | bool process_hits( |
---|
157 | AIDA::ITuple& aParent |
---|
158 | ,TH1D& aHisto |
---|
159 | ) |
---|
160 | ////////////////////////////////////////////////////////////////////////////// |
---|
161 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
162 | { |
---|
163 | AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(10); |
---|
164 | if(!entry) return false; |
---|
165 | |
---|
166 | AIDA::ITuple* tuple = cast_Tuple(entry); |
---|
167 | if(!tuple) return false; |
---|
168 | |
---|
169 | tuple->start(); |
---|
170 | while(tuple->next()) { |
---|
171 | |
---|
172 | //int tubeId = tuple->getInt(0); |
---|
173 | //int totalPE = tuple->getInt(1); |
---|
174 | |
---|
175 | if(!process_hits_times(*tuple,aHisto)) return false; |
---|
176 | } |
---|
177 | return true; |
---|
178 | } |
---|
179 | ////////////////////////////////////////////////////////////////////////////// |
---|
180 | bool process_digits( |
---|
181 | AIDA::ITuple& aParent |
---|
182 | ,TH2D& aHisto |
---|
183 | ) |
---|
184 | ////////////////////////////////////////////////////////////////////////////// |
---|
185 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
186 | { |
---|
187 | AIDA::ITupleEntry* entry = (AIDA::ITupleEntry*)aParent.getObject(13); |
---|
188 | if(!entry) return false; |
---|
189 | |
---|
190 | AIDA::ITuple* tuple = cast_Tuple(entry); |
---|
191 | if(!tuple) return false; |
---|
192 | |
---|
193 | tuple->start(); |
---|
194 | while(tuple->next()) { |
---|
195 | |
---|
196 | //int tubeId = tuple->getInt(0); |
---|
197 | double pe = tuple->getDouble(1); |
---|
198 | double time = tuple->getDouble(2); |
---|
199 | //printf("debug : ++++ : %g %g\n",time,pe); |
---|
200 | |
---|
201 | aHisto.Fill(time,pe); |
---|
202 | } |
---|
203 | return true; |
---|
204 | } |
---|
205 | ////////////////////////////////////////////////////////////////////////////// |
---|
206 | bool plot( |
---|
207 | TH1D& aHisto1D |
---|
208 | ,TH2D& aHisto2D |
---|
209 | ) |
---|
210 | ////////////////////////////////////////////////////////////////////////////// |
---|
211 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
212 | { |
---|
213 | TCanvas* plotter = new TCanvas("canvas","",10,10,800,600); |
---|
214 | plotter->Divide(1,2); |
---|
215 | |
---|
216 | plotter->cd(1); |
---|
217 | aHisto1D.Draw(); |
---|
218 | |
---|
219 | plotter->cd(2); |
---|
220 | aHisto2D.Draw(); |
---|
221 | |
---|
222 | plotter->Update(); |
---|
223 | |
---|
224 | return true; |
---|
225 | } |
---|
226 | ////////////////////////////////////////////////////////////////////////////// |
---|
227 | ////////////////////////////////////////////////////////////////////////////// |
---|
228 | ////////////////////////////////////////////////////////////////////////////// |
---|
229 | int aida_ROOT() |
---|
230 | ////////////////////////////////////////////////////////////////////////////// |
---|
231 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
232 | { |
---|
233 | std::string program = "aida_ROOT"; |
---|
234 | std::string header = program + " : "; |
---|
235 | |
---|
236 | std::cout << header << "begin..." << std::endl; |
---|
237 | |
---|
238 | //////////////////////////////////////////////////////// |
---|
239 | // Create histograms /////////////////////////////////// |
---|
240 | //////////////////////////////////////////////////////// |
---|
241 | TH1D* hits_times = new TH1D("hits_times","Hits times",100,0,3000); |
---|
242 | |
---|
243 | TH2D* digits_time_pe = |
---|
244 | new TH2D("digits_pe_time","Digits PE time",100,0,3000,100,0,10); |
---|
245 | |
---|
246 | //////////////////////////////////////////////////////// |
---|
247 | /// Read data an file histos /////////////////////////// |
---|
248 | //////////////////////////////////////////////////////// |
---|
249 | |
---|
250 | AIDA::IAnalysisFactory* aida = AIDA_createAnalysisFactory(); |
---|
251 | if(!aida) { |
---|
252 | std::cout << header << "AIDA not found." << std::endl; |
---|
253 | return 1; |
---|
254 | } |
---|
255 | |
---|
256 | AIDA::ITreeFactory* treeFactory = aida->createTreeFactory(); |
---|
257 | if(!treeFactory) { |
---|
258 | std::cout << header << "can't get a TreeFactory." << std::endl; |
---|
259 | return 1; |
---|
260 | } |
---|
261 | |
---|
262 | AIDA::ITree* tree = treeFactory->create("ELYSE.root","root",true,false); |
---|
263 | if(!tree) { |
---|
264 | std::cout << header << "can't open data file." << std::endl; |
---|
265 | return 1; |
---|
266 | } |
---|
267 | |
---|
268 | AIDA::IManagedObject* object = tree->find("Event"); |
---|
269 | if(!object) { |
---|
270 | std::cout << header |
---|
271 | << "object Event not found in tree." |
---|
272 | << std::endl; |
---|
273 | return 1; |
---|
274 | } |
---|
275 | #ifdef __CINT__ |
---|
276 | //FIXME : CINT can't handle dynamic_cast : |
---|
277 | AIDA::ITuple* tuple = (AIDA::ITuple*)object->cast("AIDA::ITuple"); |
---|
278 | #else |
---|
279 | AIDA::ITuple* tuple = dynamic_cast<AIDA::ITuple*>(object); |
---|
280 | #endif |
---|
281 | if(!tuple) { |
---|
282 | std::cout << header << "object not an AIDA::ITuple." << std::endl; |
---|
283 | return 1; |
---|
284 | } |
---|
285 | |
---|
286 | int coln = tuple->columns(); |
---|
287 | for(int index=0;index<coln;index++) { |
---|
288 | std::cout << header |
---|
289 | << " icol = " << index |
---|
290 | << ", label = " << tuple->columnName(index) |
---|
291 | << ", type = " << tuple->columnType(index) |
---|
292 | << std::endl; |
---|
293 | } |
---|
294 | |
---|
295 | std::cout << header << "rows = " << tuple->rows() << std::endl; |
---|
296 | |
---|
297 | int nentries = tuple->rows(); |
---|
298 | //nentries = 100000; |
---|
299 | //nentries = 40; |
---|
300 | std::cout << header |
---|
301 | << "traitements de " << nentries << " entrees..." |
---|
302 | << std::endl; |
---|
303 | |
---|
304 | int irow = 0; |
---|
305 | tuple->start(); |
---|
306 | while(tuple->next() && (irow<nentries)) { |
---|
307 | |
---|
308 | /* |
---|
309 | int eventId = tuple->getInt(0); |
---|
310 | //int inputEvtId = tuple->getInt(1); |
---|
311 | //int interMode = tuple->getInt(2); |
---|
312 | //int vtxVol = tuple->getInt(3); |
---|
313 | |
---|
314 | int nPart = tuple->getInt(5); |
---|
315 | //int leptonIndex = tuple->getInt(6); |
---|
316 | //int protonIndex = tuple->getInt(7); |
---|
317 | |
---|
318 | int nHits = tuple->getInt(9); |
---|
319 | int nDigits = tuple->getInt(11); |
---|
320 | double sumPE = tuple->getDouble(12); |
---|
321 | |
---|
322 | std::cout << ">>>>>>>>>>>>> Event{" << irow << "}: " |
---|
323 | << " evt Id " << eventId |
---|
324 | // << " evt Input Id " << inputEvtId |
---|
325 | // << "\n interaction mode " << interMode |
---|
326 | // << " start in volume " << vtxVol << "\n" |
---|
327 | <<" #tracks: " << nPart |
---|
328 | <<" #hits: " << nHits |
---|
329 | <<" #digits: " << nDigits |
---|
330 | <<" sumPE " << sumPE |
---|
331 | << std::endl; |
---|
332 | |
---|
333 | if(!dump_tracks(*tuple)) return 1; |
---|
334 | */ |
---|
335 | |
---|
336 | if(!process_hits(*tuple,*hits_times)) return 1; |
---|
337 | if(!process_digits(*tuple,*digits_time_pe)) return 1; |
---|
338 | |
---|
339 | irow++; |
---|
340 | } |
---|
341 | |
---|
342 | delete treeFactory; |
---|
343 | delete aida; |
---|
344 | |
---|
345 | //////////////////////////////////////////////////////// |
---|
346 | // Plot histograms ///////////////////////////////////// |
---|
347 | //////////////////////////////////////////////////////// |
---|
348 | std::cout << header << "plot..." << std::endl; |
---|
349 | plot(*hits_times,*digits_time_pe); |
---|
350 | |
---|
351 | return 0; |
---|
352 | } |
---|