1 | // $Id: EEvent.cc 2918 2011-06-10 22:22:31Z mabl $ |
---|
2 | // Author: M. Pallavicini , 12 2002 |
---|
3 | |
---|
4 | /***************************************************************************** |
---|
5 | * ESAF: Euso Simulation and Analysis Framework * |
---|
6 | * * |
---|
7 | * Id: EEvent * |
---|
8 | * Package: SimuEvent * |
---|
9 | * Coordinator: Alessandro.Thea * |
---|
10 | * * |
---|
11 | *****************************************************************************/ |
---|
12 | |
---|
13 | #include "EEvent.hh" |
---|
14 | #include "Etypes.hh" |
---|
15 | |
---|
16 | #include "ETruth.hh" |
---|
17 | #include "EHeader.hh" |
---|
18 | #include "EGeometry.hh" |
---|
19 | #include "EDetector.hh" |
---|
20 | #include "ESimpleDetector.hh" |
---|
21 | #include "EShower.hh" |
---|
22 | #include "EAtmosphere.hh" |
---|
23 | #include "EChipTrackTrigger.hh" |
---|
24 | #include "ELblTrackTrigger.hh" |
---|
25 | #include "ERunParameters.hh" |
---|
26 | #include "ELTTTrigger.hh" |
---|
27 | #include "EPTTTrigger.hh" |
---|
28 | #include "ECCB_LTTTrigger.hh" |
---|
29 | |
---|
30 | ClassImp (EEvent) |
---|
31 | ClassImp (EEvTreeLink) |
---|
32 | EEvent * EEvent::fgCurrent = 0; |
---|
33 | |
---|
34 | // class EEvent |
---|
35 | //______________________________________________________________________________ |
---|
36 | EEvent::EEvent (Int_t branches):fTreeLink (0) |
---|
37 | { |
---|
38 | // |
---|
39 | // Constructor |
---|
40 | // |
---|
41 | |
---|
42 | // branches |
---|
43 | fHeader = new EHeader (); |
---|
44 | fTruth = new ETruth (); |
---|
45 | fGeometry = new EGeometry (); |
---|
46 | |
---|
47 | fShower = (branches & kShower) ? new EShower () : 0; |
---|
48 | fAtmosphere = (branches & kAtmosphere) ? new EAtmosphere () : 0; |
---|
49 | fDetector = (branches & kDetector) ? new EDetector () : 0; |
---|
50 | fSimpleDetector = (branches & kSimpleDetector) ? new ESimpleDetector () : 0; |
---|
51 | fChipTrackTrigger = |
---|
52 | (branches & kChipTrackTrigger) ? new EChipTrackTrigger () : 0; |
---|
53 | fLblTrackTrigger = |
---|
54 | (branches & kLblTrackTrigger) ? new ELblTrackTrigger () : 0; |
---|
55 | fPTTTrigger = (branches & kPTTTrigger) ? new EPTTTrigger () : 0; |
---|
56 | fLTTTrigger = (branches & kLTTTrigger) ? new ELTTTrigger () : 0; |
---|
57 | fCCB_LTTTrigger = (branches & kCCB_LTTTrigger) ? new ECCB_LTTTrigger () : 0; |
---|
58 | |
---|
59 | // build pars |
---|
60 | fRunPars = new ERunParameters (); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | //______________________________________________________________________________ |
---|
65 | EEvent::EEvent (const EEvent & other): |
---|
66 | TObject () |
---|
67 | { |
---|
68 | // copy ctor |
---|
69 | |
---|
70 | other.Copy (*this); |
---|
71 | } |
---|
72 | |
---|
73 | //______________________________________________________________________________ |
---|
74 | EEvent::~EEvent () |
---|
75 | { |
---|
76 | // destructor |
---|
77 | |
---|
78 | Delete (); |
---|
79 | |
---|
80 | if (GetCurrent () == this) |
---|
81 | SetCurrent (0); |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | //______________________________________________________________________________ |
---|
86 | void EEvent::Copy (TObject & other) const { |
---|
87 | // |
---|
88 | // Copy this to other |
---|
89 | // |
---|
90 | |
---|
91 | // EEvent& event = (EEvent&)other; |
---|
92 | |
---|
93 | // TODO |
---|
94 | } |
---|
95 | |
---|
96 | //______________________________________________________________________________ |
---|
97 | Bool_t EEvent::BranchTree (TTree * t, Bool_t link) |
---|
98 | { |
---|
99 | // |
---|
100 | // Branch tree on EEvent data members |
---|
101 | // |
---|
102 | |
---|
103 | Bool_t branched = kTRUE; |
---|
104 | |
---|
105 | // add capability not to branch on a subevent if requested |
---|
106 | // branches |
---|
107 | if (fHeader) |
---|
108 | t->Branch ("header", "EHeader", &fHeader); |
---|
109 | if (fTruth) |
---|
110 | t->Branch ("truth", "ETruth", &fTruth); |
---|
111 | if (fGeometry) |
---|
112 | t->Branch ("geometry", "EGeometry", &fGeometry); |
---|
113 | |
---|
114 | if (fShower) |
---|
115 | t->Branch ("shower", "EShower", &fShower); |
---|
116 | if (fAtmosphere) |
---|
117 | t->Branch ("atmosphere", "EAtmosphere", &fAtmosphere); |
---|
118 | if (fDetector) |
---|
119 | t->Branch ("detector", "EDetector", &fDetector); |
---|
120 | if (fSimpleDetector) |
---|
121 | t->Branch ("simpledetector", "ESimpleDetector", &fSimpleDetector); |
---|
122 | if (fChipTrackTrigger) |
---|
123 | t->Branch ("trigger", "EChipTrackTrigger", &fChipTrackTrigger); |
---|
124 | if (fLblTrackTrigger) |
---|
125 | t->Branch ("lbltrigger", "ELblTrackTrigger", &fLblTrackTrigger); |
---|
126 | if (fPTTTrigger) |
---|
127 | t->Branch ("PTT_trigger", "EPTTTrigger", &fPTTTrigger); |
---|
128 | if (fLTTTrigger) |
---|
129 | t->Branch ("LTT_trigger", "ELTTTrigger", &fLTTTrigger); |
---|
130 | if (fCCB_LTTTrigger) |
---|
131 | t->Branch ("CCB_LTTTrigger", "ECCB_LTTTrigger", &fCCB_LTTTrigger); |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | // pars |
---|
136 | if (link) |
---|
137 | { |
---|
138 | t->GetUserInfo ()->Add (fRunPars); |
---|
139 | LinkTree (t); |
---|
140 | } |
---|
141 | return branched; |
---|
142 | |
---|
143 | } |
---|
144 | |
---|
145 | //______________________________________________________________________________ |
---|
146 | Bool_t EEvent::SetBranches (TTree * t, Bool_t clone) |
---|
147 | { |
---|
148 | // |
---|
149 | // Sets branches addresses for reading. Returns kTRUE if any of the |
---|
150 | // container exists in the tree. If one of the data member is 0 and |
---|
151 | // corresponding branch is found, it is automatically allocated. |
---|
152 | // If clone is true, a clone of ERunParameters (and the other eventual data |
---|
153 | // stored in the etree)is created and the tree is not linked. |
---|
154 | // |
---|
155 | |
---|
156 | if (!t) |
---|
157 | return kFALSE; |
---|
158 | |
---|
159 | Delete (); |
---|
160 | |
---|
161 | Bool_t branched = kFALSE; |
---|
162 | |
---|
163 | TBranch *branch; |
---|
164 | |
---|
165 | // branches |
---|
166 | if ((branch = t->GetBranch ("header"))) |
---|
167 | t->SetBranchAddress ("header", &fHeader); |
---|
168 | branched |= (branch != 0); |
---|
169 | |
---|
170 | if ((branch = t->GetBranch ("truth"))) |
---|
171 | t->SetBranchAddress ("truth", &fTruth); |
---|
172 | branched |= (branch != 0); |
---|
173 | |
---|
174 | if ((branch = t->GetBranch ("geometry"))) |
---|
175 | t->SetBranchAddress ("geometry", &fGeometry); |
---|
176 | branched |= (branch != 0); |
---|
177 | |
---|
178 | if ((branch = t->GetBranch ("shower"))) |
---|
179 | t->SetBranchAddress ("shower", &fShower); |
---|
180 | branched |= (branch != 0); |
---|
181 | |
---|
182 | if ((branch = t->GetBranch ("atmosphere"))) |
---|
183 | t->SetBranchAddress ("atmosphere", &fAtmosphere); |
---|
184 | branched |= (branch != 0); |
---|
185 | |
---|
186 | if ((branch = t->GetBranch ("detector"))) |
---|
187 | t->SetBranchAddress ("detector", &fDetector); |
---|
188 | branched |= (branch != 0); |
---|
189 | |
---|
190 | if ((branch = t->GetBranch ("simpledetector"))) |
---|
191 | t->SetBranchAddress ("simpledetector", &fSimpleDetector); |
---|
192 | branched |= (branch != 0); |
---|
193 | |
---|
194 | if ((branch = t->GetBranch ("trigger"))) |
---|
195 | t->SetBranchAddress ("trigger", &fChipTrackTrigger); |
---|
196 | branched |= (branch != 0); |
---|
197 | |
---|
198 | if ((branch = t->GetBranch ("lbltrigger"))) |
---|
199 | t->SetBranchAddress ("lbltrigger", &fLblTrackTrigger); |
---|
200 | branched |= (branch != 0); |
---|
201 | |
---|
202 | if ((branch = t->GetBranch ("PTT_trigger"))) |
---|
203 | t->SetBranchAddress ("PTT_trigger", &fPTTTrigger); |
---|
204 | branched |= (branch != 0); |
---|
205 | |
---|
206 | if ((branch = t->GetBranch ("LTT_trigger"))) |
---|
207 | t->SetBranchAddress ("LTT_trigger", &fLTTTrigger); |
---|
208 | branched |= (branch != 0); |
---|
209 | |
---|
210 | if ((branch = t->GetBranch ("CCB_LTTTrigger"))) |
---|
211 | t->SetBranchAddress ("CCB_LTTTrigger", &fCCB_LTTTrigger); |
---|
212 | branched |= (branch != 0); |
---|
213 | |
---|
214 | |
---|
215 | // pars |
---|
216 | SafeDelete (fRunPars); |
---|
217 | |
---|
218 | // FIXME: temporary workaround for old rootfiles |
---|
219 | if (t->GetDirectory ()) |
---|
220 | { |
---|
221 | TTree *runtree = (TTree *) t->GetDirectory ()->Get ("runtree"); |
---|
222 | |
---|
223 | if (runtree) |
---|
224 | { |
---|
225 | |
---|
226 | runtree->SetBranchAddress ("runpars", &fRunPars); |
---|
227 | runtree->GetEntry (); |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | // if runpars is still null, look for it in UserInfo |
---|
232 | if (!fRunPars) |
---|
233 | { |
---|
234 | ERunParameters *pars = |
---|
235 | (ERunParameters *) t->GetUserInfo ()->FindObject ("ERunParameters"); |
---|
236 | if (pars && clone) |
---|
237 | fRunPars = (ERunParameters *) pars->Clone (); |
---|
238 | else |
---|
239 | { |
---|
240 | fRunPars = pars; |
---|
241 | LinkTree (t); |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | return branched; |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | //______________________________________________________________________________ |
---|
252 | void EEvent::LinkTree (TTree * t) |
---|
253 | { |
---|
254 | // |
---|
255 | // |
---|
256 | // |
---|
257 | |
---|
258 | if (!t) |
---|
259 | return; |
---|
260 | |
---|
261 | fTreeLink = (EEvTreeLink *) t->GetUserInfo ()->FindObject ("EEvTreeLink"); |
---|
262 | |
---|
263 | if (!fTreeLink) |
---|
264 | { |
---|
265 | fTreeLink = new EEvTreeLink (t, this); |
---|
266 | t->GetUserInfo ()->Add (fTreeLink); |
---|
267 | } |
---|
268 | else |
---|
269 | fTreeLink->SetEvent (this); |
---|
270 | |
---|
271 | } |
---|
272 | |
---|
273 | //______________________________________________________________________________ |
---|
274 | void EEvent::UnlinkTree () |
---|
275 | { |
---|
276 | // |
---|
277 | // Disconnect tree from the event. This is required before deleting the tree |
---|
278 | // If the tree holds ERunParameters, they are cloned and the clone is |
---|
279 | // stored in the tree |
---|
280 | // |
---|
281 | |
---|
282 | if (!fTreeLink) |
---|
283 | return; |
---|
284 | |
---|
285 | fTreeLink->SetEvent (0); |
---|
286 | // runpars are hold by the tree |
---|
287 | fRunPars = 0; |
---|
288 | // and linktree as well |
---|
289 | fTreeLink = 0; |
---|
290 | |
---|
291 | |
---|
292 | // if ( !GetTree() ) return; |
---|
293 | // |
---|
294 | // TList* user = GetTree()->GetUserInfo(); |
---|
295 | // |
---|
296 | // Bool_t clone=kTRUE; |
---|
297 | // TTree *fTree = GetTree(); |
---|
298 | // if ( user->FindObject(fRunPars) && clone ) { |
---|
299 | // user->Remove(fRunPars); |
---|
300 | // user->Add(fRunPars->Clone()); |
---|
301 | // } |
---|
302 | // |
---|
303 | // fTreeLink = 0; |
---|
304 | // |
---|
305 | // if ( fTree && fRunPars && fTree->GetUserInfo()->FindObject(fRunPars) ) |
---|
306 | // fTree->GetUserInfo()->Remove(fRunPars); |
---|
307 | // |
---|
308 | // fTree = 0; |
---|
309 | } |
---|
310 | |
---|
311 | //______________________________________________________________________________ |
---|
312 | void EEvent::Build (Int_t run, Int_t ev, const char *name) |
---|
313 | { |
---|
314 | // build header |
---|
315 | |
---|
316 | if (fHeader) |
---|
317 | { |
---|
318 | fHeader->SetNum (ev); |
---|
319 | fHeader->SetRun (run); |
---|
320 | fHeader->SetRunName (name); |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | //______________________________________________________________________________ |
---|
325 | void EEvent::Clear (Option_t * opt) |
---|
326 | { |
---|
327 | // clear event |
---|
328 | |
---|
329 | TString options (opt); |
---|
330 | |
---|
331 | // branches |
---|
332 | if (fHeader) |
---|
333 | fHeader->Clear (opt); |
---|
334 | if (fTruth) |
---|
335 | fTruth->Clear (opt); |
---|
336 | if (fGeometry) |
---|
337 | fGeometry->Clear (opt); |
---|
338 | |
---|
339 | if (fShower) |
---|
340 | fShower->Clear (opt); |
---|
341 | if (fAtmosphere) |
---|
342 | fAtmosphere->Clear (opt); |
---|
343 | if (fDetector) |
---|
344 | fDetector->Clear (opt); |
---|
345 | if (fSimpleDetector) |
---|
346 | fSimpleDetector->Clear (opt); |
---|
347 | if (fChipTrackTrigger) |
---|
348 | fChipTrackTrigger->Clear (opt); |
---|
349 | if (fLblTrackTrigger) |
---|
350 | fLblTrackTrigger->Clear (opt); |
---|
351 | if (fPTTTrigger) |
---|
352 | fPTTTrigger->Clear (opt); |
---|
353 | if (fLTTTrigger) |
---|
354 | fLTTTrigger->Clear (opt); |
---|
355 | if (fCCB_LTTTrigger) |
---|
356 | fCCB_LTTTrigger->Clear (opt); |
---|
357 | |
---|
358 | // pars |
---|
359 | // if (fRunPars && options.Contains ("C")) |
---|
360 | // fRunPars->Clear (); //DN: do not clean it. It causes crash in EEventViewer. |
---|
361 | |
---|
362 | // if ( options.Contains("C") ) |
---|
363 | // Delete(); |
---|
364 | } |
---|
365 | |
---|
366 | //______________________________________________________________________________ |
---|
367 | void EEvent::ClearAndShrink (Option_t * opt) |
---|
368 | { |
---|
369 | // |
---|
370 | // |
---|
371 | // |
---|
372 | |
---|
373 | Clear (opt); |
---|
374 | if (fShower) |
---|
375 | fShower->ClearAndShrink (opt); |
---|
376 | if (fAtmosphere) |
---|
377 | fAtmosphere->ClearAndShrink (opt); |
---|
378 | if (fDetector) |
---|
379 | fDetector->ClearAndShrink (opt); |
---|
380 | if (fSimpleDetector) |
---|
381 | fSimpleDetector->ClearAndShrink (opt); |
---|
382 | } |
---|
383 | |
---|
384 | //______________________________________________________________________________ |
---|
385 | void EEvent::Delete (Option_t *) |
---|
386 | { |
---|
387 | // |
---|
388 | // Delete all containers |
---|
389 | // |
---|
390 | |
---|
391 | // branches |
---|
392 | SafeDelete (fHeader); |
---|
393 | SafeDelete (fTruth); |
---|
394 | SafeDelete (fGeometry); |
---|
395 | |
---|
396 | SafeDelete (fShower); |
---|
397 | SafeDelete (fAtmosphere); |
---|
398 | SafeDelete (fDetector); |
---|
399 | SafeDelete (fSimpleDetector); |
---|
400 | SafeDelete (fChipTrackTrigger); |
---|
401 | SafeDelete (fLblTrackTrigger); |
---|
402 | SafeDelete (fPTTTrigger); |
---|
403 | SafeDelete (fLTTTrigger); |
---|
404 | SafeDelete (fCCB_LTTTrigger); |
---|
405 | |
---|
406 | // pars |
---|
407 | if (IsLinked ()) |
---|
408 | // |
---|
409 | // ERunParamters are owned by the tree. |
---|
410 | // Just forget about them |
---|
411 | // |
---|
412 | UnlinkTree (); |
---|
413 | else |
---|
414 | SafeDelete (fRunPars); |
---|
415 | |
---|
416 | } |
---|
417 | |
---|
418 | //______________________________________________________________________________ |
---|
419 | Bool_t EEvent::Fill (EFiller & f) |
---|
420 | { |
---|
421 | // |
---|
422 | // Deliver filler to its target |
---|
423 | // |
---|
424 | |
---|
425 | TString target (f.GetTarget ()); |
---|
426 | |
---|
427 | EFillable *fillable; |
---|
428 | |
---|
429 | if (target == "ETruth") |
---|
430 | { |
---|
431 | fillable = fTruth; |
---|
432 | } |
---|
433 | else if (target == "EGeometry") |
---|
434 | { |
---|
435 | fillable = fGeometry; |
---|
436 | } |
---|
437 | else if (target == "EShower") |
---|
438 | { |
---|
439 | fillable = fShower; |
---|
440 | } |
---|
441 | else if (target == "EAtmosphere") |
---|
442 | { |
---|
443 | fillable = fAtmosphere; |
---|
444 | } |
---|
445 | else if (target == "EDetector") |
---|
446 | { |
---|
447 | fillable = fDetector; |
---|
448 | } |
---|
449 | else if (target == "ESimpleDetector") |
---|
450 | { |
---|
451 | fillable = fSimpleDetector; |
---|
452 | } |
---|
453 | else if (target == "EChipTrackTrigger") |
---|
454 | { |
---|
455 | fillable = fChipTrackTrigger; |
---|
456 | } |
---|
457 | else if (target == "ELblTrackTrigger") |
---|
458 | { |
---|
459 | fillable = fLblTrackTrigger; |
---|
460 | } |
---|
461 | else if (target == "EPTTTrigger") |
---|
462 | { |
---|
463 | fillable = fPTTTrigger; |
---|
464 | } |
---|
465 | else if (target == "ELTTTrigger") |
---|
466 | { |
---|
467 | fillable = fLTTTrigger; |
---|
468 | } |
---|
469 | else if (target == "ECCB_LTTTrigger") |
---|
470 | { |
---|
471 | fillable = fCCB_LTTTrigger; |
---|
472 | } |
---|
473 | else |
---|
474 | { |
---|
475 | Error ("Fill", "Filler type %s unknown", target.Data ()); |
---|
476 | return kFALSE; |
---|
477 | } |
---|
478 | |
---|
479 | // if filled is a null pointer return |
---|
480 | if (!fillable) |
---|
481 | return kFALSE; |
---|
482 | |
---|
483 | // try to fill the selected object |
---|
484 | Bool_t filled = fillable->Fill (f); |
---|
485 | |
---|
486 | if (!filled) |
---|
487 | Error ("Fill", "Unable to fill %s with filler type %s", |
---|
488 | fillable->Class_Name (), target.Data ()); |
---|
489 | |
---|
490 | return filled; |
---|
491 | |
---|
492 | } |
---|
493 | |
---|
494 | |
---|
495 | //______________________________________________________________________________ |
---|
496 | EEvTreeLink::EEvTreeLink ():fEvent (0) |
---|
497 | { |
---|
498 | // |
---|
499 | // Default constructor |
---|
500 | // |
---|
501 | |
---|
502 | } |
---|
503 | |
---|
504 | |
---|
505 | //______________________________________________________________________________ |
---|
506 | EEvTreeLink::EEvTreeLink (TTree * t):fEvent (0) |
---|
507 | { |
---|
508 | // |
---|
509 | // |
---|
510 | // |
---|
511 | |
---|
512 | fTreeRef = t; |
---|
513 | } |
---|
514 | |
---|
515 | |
---|
516 | //______________________________________________________________________________ |
---|
517 | EEvTreeLink::EEvTreeLink (TTree * t, EEvent * ev):fEvent (ev) |
---|
518 | { |
---|
519 | // |
---|
520 | // Destructor |
---|
521 | // |
---|
522 | |
---|
523 | fTreeRef = t; |
---|
524 | } |
---|
525 | |
---|
526 | //______________________________________________________________________________ |
---|
527 | EEvTreeLink::~EEvTreeLink () |
---|
528 | { |
---|
529 | // |
---|
530 | // Destructor |
---|
531 | // |
---|
532 | |
---|
533 | if (fEvent) |
---|
534 | fEvent->UnlinkTree (); |
---|
535 | } |
---|