88cb7938 |
1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
3 | * * |
4 | * Author: The ALICE Off-line Project. * |
5 | * Contributors are mentioned in the code where appropriate. * |
6 | * * |
7 | * Permission to use, copy, modify and distribute this software and its * |
8 | * documentation strictly for non-commercial purposes is hereby granted * |
9 | * without fee, provided that the above copyright notice appears in all * |
10 | * copies and that both the copyright notice and this permission notice * |
11 | * appear in the supporting documentation. The authors make no claims * |
12 | * about the suitability of this software for any purpose. It is * |
13 | * provided "as is" without express or implied warranty. * |
14 | **************************************************************************/ |
15 | |
16 | /* $Id: */ |
17 | |
18 | /* $Log: |
19 | 29.05.2001 Yuri Kharlov: |
20 | Everywhere reading the treese TTree->GetEvent(i) |
21 | is replaced by reading the branches TBranch->GetEntry(0) |
22 | */ |
23 | |
24 | //_________________________________________________________________________ |
25 | // A singleton. This class should be used in the analysis stage to get |
26 | // reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles, |
27 | // instead of directly reading them from galice.root file. This container |
28 | // ensures, that one reads Digits, made of these particular digits, RecPoints, |
29 | // made of these particular RecPoints, TrackSegments and RecParticles. |
30 | // This becomes non trivial if there are several identical branches, produced with |
31 | // different set of parameters. |
32 | // |
33 | // An example of how to use (see also class AliEMCALAnalyser): |
34 | // for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++) |
35 | // AliEMCALRecParticle * part = gime->RecParticle(1) ; |
36 | // ................ |
37 | // please->GetEvent(event) ; // reads new event from galice.root |
38 | // |
39 | //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH) |
40 | //*-- Completely redesigned by Dmitri Peressounko March 2001 |
41 | // |
42 | //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make |
43 | //*-- systematic usage of TFolders without changing the interface |
44 | ////////////////////////////////////////////////////////////////////////////// |
45 | |
46 | |
47 | // --- ROOT system --- |
48 | |
49 | #include "TFile.h" |
50 | #include "TTree.h" |
51 | #include "TROOT.h" |
52 | #include "TObjString.h" |
53 | #include "TFolder.h" |
54 | #include "TParticle.h" |
55 | |
56 | // --- Standard library --- |
57 | #include <Riostream.h> |
58 | |
59 | // --- AliRoot header files --- |
60 | |
61 | #include "AliRun.h" |
62 | #include "AliConfig.h" |
63 | #include "AliDataLoader.h" |
64 | #include "AliEMCALLoader.h" |
65 | #include "AliEMCAL.h" |
66 | #include "AliEMCALDigitizer.h" |
67 | #include "AliEMCALSDigitizer.h" |
68 | #include "AliEMCALClusterizer.h" |
69 | #include "AliEMCALClusterizerv1.h" |
70 | #include "AliEMCALTrackSegmentMaker.h" |
71 | #include "AliEMCALTrackSegmentMakerv1.h" |
72 | #include "AliEMCALTrackSegment.h" |
73 | #include "AliEMCALPID.h" |
74 | #include "AliEMCALPIDv1.h" |
75 | #include "AliEMCALGeometry.h" |
76 | //#include "AliEMCALCalibrationDB.h" |
77 | |
78 | ClassImp(AliEMCALLoader) |
79 | |
80 | |
81 | const TString AliEMCALLoader::fgkHitsName("HITS");//Name for TClonesArray with hits from one event |
82 | const TString AliEMCALLoader::fgkSDigitsName("SDIGITS");//Name for TClonesArray |
83 | const TString AliEMCALLoader::fgkDigitsName("DIGITS");//Name for TClonesArray |
84 | const TString AliEMCALLoader::fgkPRERecPointsName("PRERECPOINTS");//Name for TClonesArray |
85 | const TString AliEMCALLoader::fgkECARecPointsName("ECARECPOINTS");//Name for TClonesArray |
86 | const TString AliEMCALLoader::fgkHCARecPointsName("HCARECPOINTS");//Name for TClonesArray |
87 | const TString AliEMCALLoader::fgkTracksName("TRACKS");//Name for TClonesArray |
88 | const TString AliEMCALLoader::fgkRecParticlesName("RECPARTICLES");//Name for TClonesArray |
89 | |
90 | const TString AliEMCALLoader::fgkPRERecPointsBranchName("EMCALPRERP");//Name for branch with PreShower Reconstructed Points |
91 | const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points |
92 | const TString AliEMCALLoader::fgkHCARecPointsBranchName("EMCALHCARP");//Name for branch with HCA Reconstructed Points |
93 | const TString AliEMCALLoader::fgkTrackSegmentsBranchName("EMCALTS");//Name for branch with TrackSegments |
94 | const TString AliEMCALLoader::fgkRecParticlesBranchName("EMCALRP");//Name for branch with Reconstructed Particles |
95 | //____________________________________________________________________________ |
96 | AliEMCALLoader::AliEMCALLoader() |
97 | { |
98 | fDebug = 0; |
99 | fRecParticlesLoaded = kFALSE; |
100 | } |
101 | //____________________________________________________________________________ |
102 | AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername): |
103 | AliLoader(detname,eventfoldername) |
104 | { |
105 | fDebug=0; |
106 | fRecParticlesLoaded = kFALSE; |
107 | } |
108 | //____________________________________________________________________________ |
109 | |
110 | AliEMCALLoader::~AliEMCALLoader() |
111 | { |
112 | //remove and delete arrays |
113 | Clean(fgkHitsName); |
114 | Clean(fgkSDigitsName); |
115 | Clean(fgkDigitsName); |
116 | Clean(fgkPRERecPointsName); |
117 | Clean(fgkECARecPointsName); |
118 | Clean(fgkHCARecPointsName); |
119 | Clean(fgkTracksName); |
120 | Clean(fgkRecParticlesName); |
121 | } |
122 | //____________________________________________________________________________ |
123 | |
124 | void AliEMCALLoader::CleanFolders() |
125 | { |
126 | CleanRecParticles(); |
127 | AliLoader::CleanFolders(); |
128 | } |
129 | //____________________________________________________________________________ |
130 | |
131 | Int_t AliEMCALLoader::SetEvent() |
132 | { |
133 | //Cleans loaded stuff and and sets Files and Directories |
134 | // do not post any data to folder/tasks |
135 | |
136 | |
137 | Int_t retval = AliLoader::SetEvent(); |
138 | if (retval) |
139 | { |
140 | Error("SetEvent","AliLoader::SetEvent returned error"); |
141 | return retval; |
142 | } |
143 | |
144 | |
145 | if (Hits()) Hits()->Clear(); |
146 | if (SDigits()) SDigits()->Clear(); |
147 | if (Digits()) Digits()->Clear(); |
148 | if (PRERecPoints()) PRERecPoints()->Clear(); |
149 | if (ECARecPoints()) ECARecPoints()->Clear(); |
150 | if (HCARecPoints()) HCARecPoints()->Clear(); |
151 | if (TrackSegments()) TrackSegments()->Clear(); |
152 | if (RecParticles()) RecParticles()->Clear(); |
153 | |
154 | return 0; |
155 | } |
156 | //____________________________________________________________________________ |
157 | |
158 | Int_t AliEMCALLoader::GetEvent() |
159 | { |
160 | //Overloads GetEvent method called by AliRunLoader::GetEvent(Int_t) method |
161 | //to add Rec Particles specific for EMCAL |
162 | |
163 | //First call the original method to get whatever from std. setup is needed |
164 | Int_t retval; |
165 | |
166 | retval = AliLoader::GetEvent(); |
167 | if (retval) |
168 | { |
169 | Error("GetEvent","AliLoader::GetEvent returned error"); |
170 | return retval; |
171 | } |
172 | |
173 | if (GetHitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadHits(); |
174 | if (GetSDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadSDigits(); |
175 | if (GetDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadDigits(); |
176 | if (GetRecPointsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecPoints(); |
177 | if (GetTracksDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadTracks(); |
178 | if (GetRecParticlesDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecParticles(); |
179 | |
180 | |
181 | //Now, check if RecPart were loaded |
182 | return 0; |
183 | } |
184 | //____________________________________________________________________________ |
185 | |
186 | |
187 | //____________________________________________________________________________ |
188 | const AliEMCAL * AliEMCALLoader::EMCAL() |
189 | { |
190 | // returns the EMCAL object |
191 | AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(GetModulesFolder()->FindObject(fDetectorName)); |
192 | if ( emcal == 0x0) |
193 | if (fDebug) |
194 | cout << "WARNING: AliEMCALLoader::EMCAL -> EMCAL module not found in Folders" << endl ; |
195 | return emcal ; |
196 | } |
197 | |
198 | //____________________________________________________________________________ |
199 | const AliEMCALGeometry * AliEMCALLoader::EMCALGeometry() |
200 | { |
201 | AliEMCALGeometry * rv = 0 ; |
202 | if (EMCAL() ) |
203 | rv = EMCAL()->GetGeometry(); |
204 | return rv ; |
205 | } |
206 | |
207 | |
208 | //____________________________________________________________________________ |
209 | Int_t AliEMCALLoader::LoadHits(Option_t* opt) |
210 | { |
211 | //------- Hits ---------------------- |
212 | //Overload (extends) LoadHits implemented in AliLoader |
213 | // |
214 | Int_t res; |
215 | |
216 | //First call the AliLoader's method to send the TreeH to folder |
217 | res = AliLoader::LoadHits(opt); |
218 | |
219 | if (res) |
220 | {//oops, error |
221 | Error("LoadHits","AliLoader::LoadHits returned error"); |
222 | return res; |
223 | } |
224 | |
225 | //read the data from tree in folder and send it to folder |
226 | res = ReadHits(); |
227 | return 0; |
228 | } |
229 | |
230 | |
231 | //____________________________________________________________________________ |
232 | Int_t AliEMCALLoader::LoadSDigits(Option_t* opt) |
233 | { //---------- SDigits ------------------------- |
234 | Int_t res; |
235 | //First call the AliLoader's method to send the TreeS to folder |
236 | res = AliLoader::LoadSDigits(opt); |
237 | if (res) |
238 | {//oops, error |
239 | Error("PostSDigits","AliLoader::LoadSDigits returned error"); |
240 | return res; |
241 | } |
242 | return ReadSDigits(); |
243 | |
244 | } |
245 | //____________________________________________________________________________ |
246 | Int_t AliEMCALLoader::LoadDigits(Option_t* opt) |
247 | { |
248 | Int_t res; |
249 | //First call the AliLoader's method to send the TreeS to folder |
250 | res = AliLoader::LoadDigits(opt); |
251 | if (res) |
252 | {//oops, error |
253 | Error("LoadDigits","AliLoader::LoadDigits returned error"); |
254 | return res; |
255 | } |
256 | return ReadDigits(); |
257 | } |
258 | //____________________________________________________________________________ |
259 | Int_t AliEMCALLoader::LoadRecPoints(Option_t* opt) |
260 | { // -------------- RecPoints ------------------------------------------- |
261 | Int_t res; |
262 | //First call the AliLoader's method to send the TreeR to folder |
263 | res = AliLoader::LoadRecPoints(opt); |
264 | if (res) |
265 | {//oops, error |
266 | Error("LoadRecPoints","AliLoader::LoadRecPoints returned error"); |
267 | return res; |
268 | } |
269 | |
270 | TFolder * emcalFolder = GetDetectorDataFolder(); |
271 | if ( emcalFolder == 0x0 ) |
272 | { |
273 | Error("LoadRecPoints","Can not get detector data folder"); |
274 | return 1; |
275 | } |
276 | return ReadRecPoints(); |
277 | } |
278 | //____________________________________________________________________________ |
279 | |
280 | Int_t AliEMCALLoader::LoadTracks(Option_t* opt) |
281 | { |
282 | //Loads Tracks: Open File, Reads Tree and posts, Read Data and Posts |
283 | if (GetDebug()) Info("LoadTracks","opt = %s",opt); |
284 | if (fTracksLoaded) |
285 | { |
286 | Warning("LoadTracks","Tracks are already loaded"); |
287 | return 0; |
288 | } |
289 | Int_t res; |
290 | //First call the AliLoader's method to send the TreeS to folder |
291 | if (GetTracksDataLoader()->GetBaseLoader(0)->IsLoaded() == kFALSE) |
292 | {//tracks can be loaded by LoadRecPoints |
293 | res = AliLoader::LoadTracks(opt); |
294 | if (res) |
295 | {//oops, error |
296 | Error("LoadTracks","AliLoader::LoadTracks returned error"); |
297 | return res; |
298 | } |
299 | } |
300 | res = ReadTracks(); |
301 | if (res) |
302 | { |
303 | Error("LoadTracks","Error occured while reading Tracks"); |
304 | return res; |
305 | } |
306 | |
307 | fTracksLoaded = kTRUE; |
308 | return 0; |
309 | } |
310 | |
311 | //____________________________________________________________________________ |
312 | Int_t AliEMCALLoader::LoadRecParticles(Option_t* opt) |
313 | { // -------------- RecPoints ------------------------------------------- |
314 | Int_t res; |
315 | //First call the AliLoader's method to send the TreeS to folder |
316 | res = AliLoader::LoadRecParticles(opt); |
317 | if (res) |
318 | {//oops, error |
319 | Error("LoadRecParticles","AliLoader::LoadRecParticles returned error"); |
320 | return res; |
321 | } |
322 | |
323 | TFolder * emcalFolder = GetDetectorDataFolder(); |
324 | if ( emcalFolder == 0x0 ) |
325 | { |
326 | Error("PostDigits","Can not get detector data folder"); |
327 | return 1; |
328 | } |
329 | return ReadRecParticles(); |
330 | } |
331 | |
332 | //____________________________________________________________________________ |
333 | |
334 | Int_t AliEMCALLoader::PostHits() |
335 | { |
336 | Int_t reval = AliLoader::PostHits(); |
337 | if (reval) |
338 | { |
339 | Error("PostHits","AliLoader:: returned error"); |
340 | return reval; |
341 | } |
342 | return ReadHits(); |
343 | } |
344 | //____________________________________________________________________________ |
345 | |
346 | Int_t AliEMCALLoader::PostSDigits() |
347 | { |
348 | Int_t reval = AliLoader::PostSDigits(); |
349 | if (reval) |
350 | { |
351 | Error("PostSDigits","AliLoader::PostSDigits returned error"); |
352 | return reval; |
353 | } |
354 | return ReadSDigits(); |
355 | } |
356 | //____________________________________________________________________________ |
357 | |
358 | Int_t AliEMCALLoader::PostDigits() |
359 | { |
360 | Int_t reval = AliLoader::PostDigits(); |
361 | if (reval) |
362 | { |
363 | Error("PostDigits","AliLoader::PostDigits returned error"); |
364 | return reval; |
365 | } |
366 | return ReadDigits(); |
367 | } |
368 | //____________________________________________________________________________ |
369 | |
370 | Int_t AliEMCALLoader::PostRecPoints() |
371 | { |
372 | Int_t reval = AliLoader::PostRecPoints(); |
373 | if (reval) |
374 | { |
375 | Error("PostRecPoints","AliLoader::PostRecPoints returned error"); |
376 | return reval; |
377 | } |
378 | return ReadRecPoints(); |
379 | } |
380 | |
381 | //____________________________________________________________________________ |
382 | |
383 | Int_t AliEMCALLoader::PostRecParticles() |
384 | { |
385 | Int_t reval = AliLoader::PostRecParticles(); |
386 | if (reval) |
387 | { |
388 | Error("PostRecParticles","AliLoader::PostRecParticles returned error"); |
389 | return reval; |
390 | } |
391 | return ReadRecParticles(); |
392 | } |
393 | //____________________________________________________________________________ |
394 | |
395 | Int_t AliEMCALLoader::PostTracks() |
396 | { |
397 | Int_t reval = AliLoader::PostTracks(); |
398 | if (reval) |
399 | { |
400 | Error("PostTracks","AliLoader::PostTracks returned error"); |
401 | return reval; |
402 | } |
403 | return ReadTracks(); |
404 | } |
405 | //____________________________________________________________________________ |
406 | |
407 | |
408 | |
409 | //____________________________________________________________________________ |
410 | Int_t AliEMCALLoader::ReadHits() |
411 | { |
412 | // If there is no Clones Array in folder creates it and sends to folder |
413 | // then tries to read |
414 | // Reads the first entry of EMCAL branch in hit tree TreeH() |
415 | // Reads data from TreeH and stores it in TClonesArray that sits in DetectorDataFolder |
416 | // |
417 | TObject** hitref = HitsRef(); |
418 | if(hitref == 0x0) |
419 | { |
420 | MakeHitsArray(); |
421 | hitref = HitsRef(); |
422 | } |
423 | |
424 | TClonesArray* hits = dynamic_cast<TClonesArray*>(*hitref); |
425 | |
426 | TTree* treeh = TreeH(); |
427 | |
428 | if(treeh == 0) |
429 | { |
430 | Error("ReadHits"," Cannot read TreeH from folder"); |
431 | return 1; |
432 | } |
433 | |
434 | TBranch * hitsbranch = treeh->GetBranch(fDetectorName); |
435 | if (hitsbranch == 0) |
436 | { |
437 | Error("ReadHits"," Cannot find branch EMCAL"); |
438 | return 1; |
439 | } |
440 | |
441 | if (GetDebug()) Info("ReadHits","Reading Hits"); |
442 | |
443 | if (hitsbranch->GetEntries() > 1) |
444 | { |
445 | TClonesArray * tempo = new TClonesArray("AliEMCALHit",1000); |
446 | |
447 | hitsbranch->SetAddress(&tempo); |
448 | Int_t index = 0 ; |
449 | Int_t i = 0 ; |
450 | for (i = 0 ; i < hitsbranch->GetEntries(); i++) |
451 | { |
452 | hitsbranch->GetEntry(i) ; |
453 | Int_t j = 0 ; |
454 | for ( j = 0 ; j < tempo->GetEntries() ; j++) |
455 | { |
456 | AliEMCALHit* hit = (AliEMCALHit*)tempo->At(j); |
457 | new((*hits)[index]) AliEMCALHit( *hit ) ; |
458 | index++ ; |
459 | } |
460 | } |
461 | delete tempo; |
462 | } |
463 | else |
464 | { |
465 | hitsbranch->SetAddress(hitref); |
466 | hitsbranch->GetEntry(0) ; |
467 | } |
468 | |
469 | return 0; |
470 | } |
471 | //____________________________________________________________________________ |
472 | Int_t AliEMCALLoader::ReadSDigits() |
473 | { |
474 | // Read the summable digits tree TreeS(): |
475 | // Check if TClones is in folder |
476 | // if not create and add to folder |
477 | // connect to tree if available |
478 | // Read the data |
479 | |
480 | TObject** sdref = SDigitsRef(); |
481 | if(sdref == 0x0) |
482 | { |
483 | MakeSDigitsArray(); |
484 | sdref = SDigitsRef(); |
485 | } |
486 | |
487 | TTree * treeS = TreeS(); |
488 | if(treeS==0) |
489 | { |
490 | //May happen if file is truncated or new in LoadSDigits |
491 | //Error("ReadSDigits","There is no SDigit Tree"); |
492 | return 0; |
493 | } |
494 | |
495 | TBranch * branch = treeS->GetBranch(fDetectorName); |
496 | if (branch == 0) |
497 | {//easy, maybe just a new tree |
498 | //Error("ReadSDigits"," Cannot find branch EMCAL"); |
499 | return 0; |
500 | } |
501 | |
502 | branch->SetAddress(SDigitsRef()); |
503 | branch->GetEntry(0); |
504 | return 0; |
505 | } |
506 | |
507 | //____________________________________________________________________________ |
508 | Int_t AliEMCALLoader::ReadDigits() |
509 | { |
510 | // Read the summable digits tree TreeS(): |
511 | // Check if TClones is in folder |
512 | // if not create and add to folder |
513 | // connect to tree if available |
514 | // Read the data |
515 | |
516 | TObject** dref = DigitsRef(); |
517 | if(dref == 0x0) |
518 | {//if there is not array in folder, create it and put it there |
519 | MakeDigitsArray(); |
520 | dref = DigitsRef(); |
521 | } |
522 | |
523 | TTree * treeD = TreeD(); |
524 | if(treeD==0) |
525 | { |
526 | //May happen if file is truncated or new in LoadSDigits |
527 | //Error("ReadDigits","There is no Digit Tree"); |
528 | return 0; |
529 | } |
530 | |
531 | TBranch * branch = treeD->GetBranch(fDetectorName); |
532 | if (branch == 0) |
533 | {//easy, maybe just a new tree |
534 | //Error("ReadDigits"," Cannot find branch ",fDetectorName.Data()); |
535 | return 0; |
536 | } |
537 | |
538 | branch->SetAddress(dref);//connect branch to buffer sitting in folder |
539 | branch->GetEntry(0);//get first event |
540 | |
541 | return 0; |
542 | } |
543 | //____________________________________________________________________________ |
544 | |
545 | void AliEMCALLoader::UnloadRecParticles() |
546 | { |
547 | fRecParticlesLoaded = kFALSE; |
548 | CleanRecParticles(); |
549 | if (fTracksLoaded == kFALSE) UnloadTracks(); |
550 | } |
551 | //____________________________________________________________________________ |
552 | |
553 | void AliEMCALLoader::UnloadTracks() |
554 | { |
555 | CleanTracks();//free the memory |
556 | //in case RecPart are loaded we can not onload tree and close the file |
557 | if (fRecParticlesLoaded == kFALSE) AliLoader::UnloadTracks(); |
558 | fTracksLoaded = kFALSE;//mark that nobody needs them |
559 | } |
560 | //____________________________________________________________________________ |
561 | |
562 | void AliEMCALLoader::Track(Int_t itrack) |
563 | { |
564 | // Read the first entry of EMCAL branch in hit tree gAlice->TreeH() |
565 | if(TreeH()== 0) |
566 | { |
567 | if (LoadHits()) |
568 | { |
569 | Error("Track","Can not load hits."); |
570 | return; |
571 | } |
572 | } |
573 | |
574 | TBranch * hitsbranch = dynamic_cast<TBranch*>(TreeH()->GetListOfBranches()->FindObject("EMCAL")) ; |
575 | if ( !hitsbranch ) { |
576 | if (fDebug) |
577 | cout << "WARNING: AliEMCALLoader::ReadTreeH -> Cannot find branch EMCAL" << endl ; |
578 | return ; |
579 | } |
580 | if(!Hits()) PostHits(); |
581 | |
582 | hitsbranch->SetAddress(HitsRef()); |
583 | hitsbranch->GetEntry(itrack); |
584 | |
585 | } |
586 | //____________________________________________________________________________ |
587 | void AliEMCALLoader::ReadTreeQA() |
588 | { |
589 | // Read the digit tree gAlice->TreeQA() |
590 | // so far only EMCAL knows about this Tree |
591 | |
592 | if(EMCAL()->TreeQA()== 0){ |
593 | cerr << "ERROR: AliEMCALLoader::ReadTreeQA: can not read TreeQA " << endl ; |
594 | return ; |
595 | } |
596 | |
597 | TBranch * qabranch = EMCAL()->TreeQA()->GetBranch("EMCAL"); |
598 | if (!qabranch) { |
599 | if (fDebug) |
600 | cout << "WARNING: AliEMCALLoader::ReadTreeQA -> Cannot find QA Alarms for EMCAL" << endl ; |
601 | return ; |
602 | } |
603 | |
604 | // if(!Alarms()) PostQA(); |
605 | |
606 | qabranch->SetAddress(AlarmsRef()) ; |
607 | |
608 | qabranch->GetEntry(0) ; |
609 | |
610 | } |
611 | |
612 | |
613 | //____________________________________________________________________________ |
614 | Int_t AliEMCALLoader::ReadRecPoints() |
615 | { |
616 | //Creates and posts to folder an array container, |
617 | //connects branch in tree (if exists), and reads data to array |
618 | |
619 | MakeRecPointsArray(); |
620 | |
621 | TObjArray * pre = 0x0 ; |
622 | TObjArray * eca = 0x0 ; |
623 | TObjArray * hca = 0x0 ; |
624 | |
625 | TTree * treeR = TreeR(); |
626 | |
627 | if(treeR==0) |
628 | { |
629 | //May happen if file is truncated or new in LoadSDigits |
630 | return 0; |
631 | } |
632 | |
633 | Int_t retval = 0; |
634 | TBranch * prebranch = treeR->GetBranch(fgkPRERecPointsBranchName); |
635 | |
636 | if (prebranch == 0x0) |
637 | { |
638 | Error("ReadRecPoints","Can not get branch with PRE Rec. Points named %s",fgkPRERecPointsBranchName.Data()); |
639 | retval = 1; |
640 | } |
641 | else |
642 | { |
643 | prebranch->SetAddress(&pre) ; |
644 | prebranch->GetEntry(0) ; |
645 | } |
646 | TBranch * ecabranch = treeR->GetBranch(fgkECARecPointsBranchName); |
647 | if (ecabranch == 0x0) |
648 | { |
649 | Error("ReadRecPoints","Can not get branch with ECA Rec. Points named %s",fgkECARecPointsBranchName.Data()); |
650 | retval = 2; |
651 | } |
652 | else |
653 | { |
654 | ecabranch->SetAddress(&eca); |
655 | ecabranch->GetEntry(0) ; |
656 | } |
657 | TBranch * hcabranch = treeR->GetBranch(fgkHCARecPointsBranchName); |
658 | if (hcabranch == 0x0) |
659 | { |
660 | Error("ReadRecPoints","Can not get branch with HCA Rec. Points named %s",fgkHCARecPointsBranchName.Data()); |
661 | retval = 2; |
662 | } |
663 | else |
664 | { |
665 | hcabranch->SetAddress(&hca); |
666 | hcabranch->GetEntry(0) ; |
667 | } |
668 | |
669 | Int_t ii ; |
670 | Int_t maxpre = pre->GetEntries() ; |
671 | for ( ii= 0 ; ii < maxpre ; ii++ ) |
672 | PRERecPoints()->Add(pre->At(ii)) ; |
673 | |
674 | Int_t maxeca = eca->GetEntries() ; |
675 | for ( ii= 0 ; ii < maxeca ; ii++ ) |
676 | ECARecPoints()->Add(eca->At(ii)) ; |
677 | |
678 | Int_t maxhca = hca->GetEntries() ; |
679 | for ( ii= 0 ; ii < maxhca ; ii++ ) |
680 | HCARecPoints()->Add(hca->At(ii)) ; |
681 | |
682 | return retval; |
683 | } |
684 | |
685 | //____________________________________________________________________________ |
686 | Int_t AliEMCALLoader::ReadTracks() |
687 | { |
688 | //Creates and posts to folder an array container, |
689 | //connects branch in tree (if exists), and reads data to arry |
690 | |
691 | TObject** trkref = TracksRef(); |
692 | if ( trkref == 0x0 ) |
693 | {//Create and post array |
694 | MakeTrackSegmentsArray(); |
695 | trkref = TracksRef(); |
696 | } |
697 | |
698 | TTree * treeT = TreeT(); |
699 | if(treeT==0) |
700 | { |
701 | //May happen if file is truncated or new in LoadSDigits, or the file is in update mode, |
702 | //but tracking was not performed yet for a current event |
703 | //Error("ReadTracks","There is no Tree with Tracks"); |
704 | return 0; |
705 | } |
706 | |
707 | TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName); |
708 | if (branch == 0) |
709 | {//easy, maybe just a new tree |
710 | Error("ReadTracks"," Cannot find branch named %s",fgkTrackSegmentsBranchName.Data()); |
711 | return 0; |
712 | } |
713 | |
714 | branch->SetAddress(trkref);//connect branch to buffer sitting in folder |
715 | branch->GetEntry(0);//get first event |
716 | |
717 | return 0; |
718 | } |
719 | //____________________________________________________________________________ |
720 | |
721 | Int_t AliEMCALLoader::ReadRecParticles() |
722 | { |
723 | //Reads Reconstructed Particles from file |
724 | //Creates and posts to folder an array container, |
725 | //connects branch in tree (if exists), and reads data to arry |
726 | |
727 | TObject** recpartref = RecParticlesRef(); |
728 | |
729 | if ( recpartref == 0x0 ) |
730 | {//Create and post array |
731 | MakeRecParticlesArray(); |
732 | recpartref = RecParticlesRef(); |
733 | } |
734 | |
735 | TTree * treeP = TreeP(); |
736 | if(treeP==0) |
737 | { |
738 | //May happen if file is truncated or new in LoadSDigits, |
739 | //or the file is in update mode, |
740 | //but tracking was not performed yet for a current event |
741 | // Error("ReadRecParticles","There is no Tree with Tracks and Reconstructed Particles"); |
742 | return 0; |
743 | } |
744 | |
745 | TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName); |
746 | if (branch == 0) |
747 | {//easy, maybe just a new tree |
748 | Error("ReadRecParticles"," Cannot find branch %s",fgkRecParticlesBranchName.Data()); |
749 | return 0; |
750 | } |
751 | |
752 | branch->SetAddress(recpartref);//connect branch to buffer sitting in folder |
753 | branch->GetEntry(0);//get first event |
754 | |
755 | return 0; |
756 | } |
757 | |
758 | |
759 | AliEMCALGeometry* AliEMCALLoader::GetEMCALGeometry() |
760 | { |
761 | //returns EMCAL geometry from gAlice |
762 | //static Method used by some classes where it is not convienient to pass eventfoldername |
763 | if (gAlice == 0x0) |
764 | return 0x0; |
765 | AliEMCAL* emcal=dynamic_cast<AliEMCAL*>(gAlice->GetDetector("EMCAL")); |
766 | if (emcal == 0x0) |
767 | return 0x0; |
768 | return emcal->GetGeometry(); |
769 | } |
770 | /***************************************************************************************/ |
771 | |
772 | AliEMCALLoader* AliEMCALLoader::GetEMCALLoader(const char* eventfoldername) |
773 | { |
774 | AliRunLoader* rn = AliRunLoader::GetRunLoader(eventfoldername); |
775 | if (rn == 0x0) |
776 | { |
777 | cerr<<"Error: <AliEMCALLoader::GetEMCALLoader>: " |
778 | << "Can not find Run Loader in folder "<<eventfoldername<<endl; |
779 | return 0x0; |
780 | } |
781 | return dynamic_cast<AliEMCALLoader*>(rn->GetLoader("EMCALLoader")); |
782 | } |
783 | /***************************************************************************************/ |
784 | |
785 | Bool_t AliEMCALLoader::BranchExists(const TString& recName) |
786 | { |
787 | if (fBranchTitle.IsNull()) return kFALSE; |
788 | TString dataname, zername ; |
789 | TTree* tree; |
790 | if(recName == "SDigits") { |
791 | tree = TreeS(); |
792 | dataname = GetDetectorName(); |
793 | zername = "AliEMCALSDigitizer" ; |
794 | } |
795 | else if(recName == "Digits"){ |
796 | tree = TreeD(); |
797 | dataname = GetDetectorName(); |
798 | zername = "AliEMCALDigitizer" ; |
799 | } |
800 | else if(recName == "PRERecPoints"){ |
801 | tree = TreeR(); |
802 | dataname = fgkPRERecPointsBranchName; |
803 | zername = "AliEMCALClusterizer" ; |
804 | } |
805 | else if(recName == "ECARecPoints"){ |
806 | tree = TreeR(); |
807 | dataname = fgkECARecPointsBranchName; |
808 | zername = "AliEMCALClusterizer" ; |
809 | } |
810 | else if(recName == "HCARecPoints"){ |
811 | tree = TreeR(); |
812 | dataname = fgkHCARecPointsBranchName; |
813 | zername = "AliEMCALClusterizer" ; |
814 | } |
815 | else if(recName == "TrackSegments"){ |
816 | tree = TreeT(); |
817 | dataname = fgkTrackSegmentsBranchName; |
818 | zername = "AliEMCALTrackSegmentMaker"; |
819 | } |
820 | else if(recName == "RecParticles"){ |
821 | tree = TreeP(); |
822 | dataname = fgkRecParticlesBranchName; |
823 | zername = "AliEMCALPID"; |
824 | } |
825 | else |
826 | return kFALSE ; |
827 | |
828 | |
829 | if(!tree ) |
830 | return kFALSE ; |
831 | |
832 | TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ; |
833 | TIter next(lob) ; |
834 | TBranch * branch = 0 ; |
835 | TString titleName(fBranchTitle); |
836 | titleName+=":"; |
837 | |
838 | while ((branch = (static_cast<TBranch*>(next())))) { |
839 | TString branchName(branch->GetName() ) ; |
840 | TString branchTitle(branch->GetTitle() ) ; |
841 | if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){ |
842 | Warning("BranchExists","branch %s with title %s ",dataname.Data(),fBranchTitle.Data()); |
843 | return kTRUE ; |
844 | } |
845 | if ( branchName.BeginsWith(zername) && branchTitle.BeginsWith(titleName) ){ |
846 | Warning("BranchExists","branch AliEMCAL... with title %s ",branch->GetTitle()); |
847 | return kTRUE ; |
848 | } |
849 | } |
850 | return kFALSE ; |
851 | |
852 | } |
853 | |
854 | void AliEMCALLoader::SetBranchTitle(const TString& btitle) |
855 | { |
856 | if (btitle.CompareTo(fBranchTitle) == 0) return; |
857 | fBranchTitle = btitle; |
858 | ReloadAll(); |
859 | } |
860 | //____________________________________________________________________________ |
861 | |
862 | void AliEMCALLoader::CleanHits() |
863 | { |
864 | AliLoader::CleanHits(); |
865 | //Clear an array |
866 | TClonesArray* hits = Hits(); |
867 | if (hits) hits->Clear(); |
868 | } |
869 | //____________________________________________________________________________ |
870 | |
871 | void AliEMCALLoader::CleanSDigits() |
872 | { |
873 | AliLoader::CleanSDigits(); |
874 | TClonesArray* sdigits = SDigits(); |
875 | if (sdigits) sdigits->Clear(); |
876 | |
877 | } |
878 | //____________________________________________________________________________ |
879 | |
880 | void AliEMCALLoader::CleanDigits() |
881 | { |
882 | AliLoader::CleanDigits(); |
883 | TClonesArray* digits = Digits(); |
884 | if (digits) digits->Clear(); |
885 | } |
886 | //____________________________________________________________________________ |
887 | |
888 | void AliEMCALLoader::CleanRecPoints() |
889 | { |
890 | AliLoader::CleanRecPoints(); |
891 | TObjArray* recpoints = PRERecPoints(); |
892 | if (recpoints) recpoints->Clear(); |
893 | recpoints = ECARecPoints(); |
894 | if (recpoints) recpoints->Clear(); |
895 | recpoints = HCARecPoints(); |
896 | if (recpoints) recpoints->Clear(); |
897 | } |
898 | //____________________________________________________________________________ |
899 | |
900 | void AliEMCALLoader::CleanTracks() |
901 | { |
902 | //Cleans Tracks stuff |
903 | |
904 | AliLoader::CleanTracks();//tree |
905 | |
906 | //and clear the array |
907 | TClonesArray* tracks = TrackSegments(); |
908 | if (tracks) tracks->Clear(); |
909 | |
910 | } |
911 | //____________________________________________________________________________ |
912 | |
913 | void AliEMCALLoader::CleanRecParticles() |
914 | { |
915 | |
916 | TClonesArray *recpar = RecParticles(); |
917 | if (recpar) recpar->Clear(); |
918 | |
919 | |
920 | } |
921 | //____________________________________________________________________________ |
922 | |
923 | // void AliEMCALLoader::ReadCalibrationDB(const char * database,const char * filename) |
924 | // { |
925 | |
926 | // if(fcdb && (strcmp(database,fcdb->GetTitle())==0)) |
927 | // return ; |
928 | |
929 | // TFile * file = gROOT->GetFile(filename) ; |
930 | // if(!file) |
931 | // file = TFile::Open(filename); |
932 | // if(!file){ |
933 | // Error ("ReadCalibrationDB", "Cannot open file %s", filename) ; |
934 | // return ; |
935 | // } |
936 | // if(fcdb) |
937 | // fcdb->Delete() ; |
938 | // fcdb = dynamic_cast<AliEMCALCalibrationDB *>(file->Get("AliEMCALCalibrationDB")) ; |
939 | // if(!fcdb) |
940 | // Error ("ReadCalibrationDB", "No database %s in file %s", database, filename) ; |
941 | // } |
942 | //____________________________________________________________________________ |
943 | |
944 | // AliEMCALSDigitizer* AliEMCALLoader::EMCALSDigitizer() |
945 | // { |
946 | // //return EMCAL SDigitizer |
947 | // return dynamic_cast<AliEMCALSDigitizer*>(SDigitizer()) ; |
948 | // } |
949 | |
950 | //____________________________________________________________________________ |
951 | void AliEMCALLoader::MakeHitsArray() |
952 | { |
953 | if (Hits()) return; |
954 | TClonesArray* hits = new TClonesArray("AliEMCALHit",1000); |
955 | hits->SetName(fgkHitsName); |
956 | GetDetectorDataFolder()->Add(hits); |
957 | } |
958 | |
959 | //____________________________________________________________________________ |
960 | void AliEMCALLoader::MakeSDigitsArray() |
961 | { |
962 | if ( SDigits()) return; |
963 | TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",1); |
964 | sdigits->SetName(fgkSDigitsName); |
965 | GetDetectorDataFolder()->Add(sdigits); |
966 | } |
967 | |
968 | //____________________________________________________________________________ |
969 | void AliEMCALLoader::MakeDigitsArray() |
970 | { |
971 | if ( Digits()) return; |
972 | TClonesArray* digits = new TClonesArray("AliEMCALDigit",1); |
973 | digits->SetName(fgkDigitsName); |
974 | GetDetectorDataFolder()->Add(digits); |
975 | |
976 | } |
977 | |
978 | //____________________________________________________________________________ |
979 | void AliEMCALLoader::MakeRecPointsArray() |
980 | { |
981 | if ( PRERecPoints() == 0x0) { |
982 | if (GetDebug()>9) |
983 | Info("MakeRecPointsArray","Making array for PRE"); |
984 | TObjArray* pre = new TObjArray(100) ; |
985 | pre->SetName(fgkPRERecPointsName) ; |
986 | GetDetectorDataFolder()->Add(pre); |
987 | } |
988 | if ( ECARecPoints() == 0x0) { |
989 | if (GetDebug()>9) |
990 | Info("MakeRecPointsArray","Making array for ECA"); |
991 | TObjArray* eca = new TObjArray(100) ; |
992 | eca->SetName(fgkECARecPointsName) ; |
993 | GetDetectorDataFolder()->Add(eca); |
994 | } |
995 | if ( HCARecPoints() == 0x0) { |
996 | if (GetDebug()>9) |
997 | Info("MakeRecPointsArray","Making array for HCA"); |
998 | TObjArray* hca = new TObjArray(100) ; |
999 | hca->SetName(fgkHCARecPointsName) ; |
1000 | GetDetectorDataFolder()->Add(hca); |
1001 | } |
1002 | } |
1003 | |
1004 | //____________________________________________________________________________ |
1005 | void AliEMCALLoader::MakeTrackSegmentsArray() |
1006 | { |
1007 | if ( TrackSegments()) return; |
1008 | TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ; |
1009 | ts->SetName(fgkTracksName); |
1010 | GetDetectorDataFolder()->Add(ts); |
1011 | |
1012 | } |
1013 | |
1014 | //____________________________________________________________________________ |
1015 | void AliEMCALLoader::MakeRecParticlesArray() |
1016 | { |
1017 | if ( RecParticles()) return; |
1018 | TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ; |
1019 | rp->SetName(fgkRecParticlesName); |
1020 | GetDetectorDataFolder()->Add(rp); |
1021 | } |