1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // A singleton. This class should be used in the analysis stage to get
20 // reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21 // instead of directly reading them from galice.root file. This container
22 // ensures, that one reads Digits, made of these particular digits, RecPoints,
23 // made of these particular RecPoints, TrackSegments and RecParticles.
24 // This becomes non trivial if there are several identical branches, produced with
25 // different set of parameters.
27 // An example of how to use (see also class AliEMCALAnalyser):
28 // AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
29 // for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
30 // AliEMCALRecParticle * part = gime->RecParticle(1) ;
32 // gime->Event(event) ; // reads new event from galice.root
34 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35 //*-- Completely redesigned by Dmitri Peressounko March 2001
37 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
38 //*-- systematic usage of TFolders without changing the interface
39 //////////////////////////////////////////////////////////////////////////////
41 // --- ROOT system ---
48 // --- Standard library ---
50 // --- AliRoot header files ---
52 #include "AliEMCALGetter.h"
54 #include "AliRunLoader.h"
56 #include "AliEMCALLoader.h"
59 ClassImp(AliEMCALGetter)
61 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
62 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
63 Int_t AliEMCALGetter::fgDebug = 0;
65 // TFile * AliEMCALGetter::fgFile = 0 ;
67 //____________________________________________________________________________
68 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
70 // ctor only called by Instance()
72 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
74 rl = AliRunLoader::Open(headerFile, version, openingOption);
76 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
79 if (rl->GetAliRun() == 0x0) {
81 gAlice = rl->GetAliRun(); // should be removed
84 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
86 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
88 fgEmcalLoader->SetTitle(version);
91 // initialize data members
98 //____________________________________________________________________________
99 AliEMCALGetter::~AliEMCALGetter()
102 delete fgEmcalLoader ;
106 fPrimaries->Delete() ;
110 //____________________________________________________________________________
111 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
113 // return pointer to Clusterizer Tree
114 AliEMCALClusterizer * rv ;
115 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
118 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
124 //____________________________________________________________________________
125 TClonesArray * AliEMCALGetter::Digits() const
127 // asks the Loader to return the Digits container
129 TClonesArray * rv = 0 ;
130 rv = EmcalLoader()->Digits() ;
133 EmcalLoader()->MakeDigitsArray() ;
134 rv = EmcalLoader()->Digits() ;
139 //____________________________________________________________________________
140 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
142 // return pointer to Digitizer Tree
143 AliEMCALDigitizer * rv ;
144 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
147 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
152 //____________________________________________________________________________
153 TObjArray * AliEMCALGetter::ECARecPoints() const
155 // asks the Loader to return the EMC RecPoints container
159 rv = EmcalLoader()->ECARecPoints() ;
161 EmcalLoader()->MakeRecPointsArray() ;
162 rv = EmcalLoader()->ECARecPoints() ;
167 //____________________________________________________________________________
168 TClonesArray * AliEMCALGetter::TrackSegments() const
170 // asks the Loader to return the TrackSegments container
172 TClonesArray * rv = 0 ;
174 rv = EmcalLoader()->TrackSegments() ;
176 EmcalLoader()->MakeTrackSegmentsArray() ;
177 rv = EmcalLoader()->TrackSegments() ;
182 //____________________________________________________________________________
183 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
185 // return pointer to TrackSegmentMaker Tree
186 AliEMCALTrackSegmentMaker * rv ;
187 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
190 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
195 //____________________________________________________________________________
196 TClonesArray * AliEMCALGetter::RecParticles() const
198 // asks the Loader to return the TrackSegments container
200 TClonesArray * rv = 0 ;
202 rv = EmcalLoader()->RecParticles() ;
204 EmcalLoader()->MakeRecParticlesArray() ;
205 rv = EmcalLoader()->RecParticles() ;
209 //____________________________________________________________________________
210 void AliEMCALGetter::Event(const Int_t event, const char* opt)
212 // Reads the content of all Tree's S, D and R
214 if ( event >= MaxEvent() ) {
215 Error("Event", "%d not found in TreeE !", event) ;
219 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
221 // checks if we are dealing with test-beam data
222 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
225 // fBTE = new AliEMCALBeamTestEvent() ;
226 // btb->SetAddress(&fBTE) ;
227 // btb->GetEntry(event) ;
236 // Loads the type of object(s) requested
238 rl->GetEvent(event) ;
240 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
249 if( strstr(opt,"D") )
252 if( strstr(opt,"R") )
255 if( strstr(opt,"T") )
258 if( strstr(opt,"P") )
264 //____________________________________________________________________________
265 Int_t AliEMCALGetter::EventNumber() const
267 // return the current event number
268 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
269 return static_cast<Int_t>(rl->GetEventNumber()) ;
272 //____________________________________________________________________________
273 TClonesArray * AliEMCALGetter::Hits() const
275 // asks the loader to return the Hits container
277 TClonesArray * rv = 0 ;
279 rv = EmcalLoader()->Hits() ;
281 EmcalLoader()->LoadHits("read");
282 rv = EmcalLoader()->Hits() ;
287 //____________________________________________________________________________
288 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
290 // Creates and returns the pointer of the unique instance
291 // Must be called only when the environment has changed
293 if(!fgObjGetter){ // first time the getter is called
294 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
296 else { // the getter has been called previously
297 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
298 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
299 // check if the file is already open
300 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
303 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
305 else { // the file is already open check the version name
306 TString currentVersionName = rl->GetEventFolder()->GetName() ;
307 TString newVersionName(version) ;
308 if (currentVersionName == newVersionName)
310 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
312 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
317 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
320 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
328 //____________________________________________________________________________
329 AliEMCALGetter * AliEMCALGetter::Instance()
331 // Returns the pointer of the unique instance already defined
333 if(!fgObjGetter && fgDebug)
334 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
340 //____________________________________________________________________________
341 Int_t AliEMCALGetter::MaxEvent() const
343 // returns the number of events in the run (from TE)
345 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
346 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
349 //____________________________________________________________________________
350 TParticle * AliEMCALGetter::Primary(Int_t index) const
352 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
353 return rl->Stack()->Particle(index) ;
356 //____________________________________________________________________________
357 AliEMCAL * AliEMCALGetter:: EMCAL() const
359 // returns the EMCAL object
360 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
363 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
369 //____________________________________________________________________________
370 AliEMCALPID * AliEMCALGetter::PID()
372 // return pointer to PID Tree
374 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
377 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
382 //____________________________________________________________________________
383 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
385 // Returns EMCAL geometry
387 AliEMCALGeometry * rv = 0 ;
389 rv = EMCAL()->GetGeometry() ;
393 //____________________________________________________________________________
394 TClonesArray * AliEMCALGetter::Primaries()
396 // creates the Primaries container if needed
399 printf("Primaries: Creating a new TClonesArray for primaries") ;
400 fPrimaries = new TClonesArray("TParticle", 1000) ;
405 //____________________________________________________________________________
406 void AliEMCALGetter::Print()
408 // Print usefull information about the getter
410 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
411 printf("Print: gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
414 //____________________________________________________________________________
415 void AliEMCALGetter::ReadPrimaries()
417 // Read Primaries from Kinematics.root
419 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
421 // gets kine tree from the root file (Kinematics.root)
422 if ( ! rl->TreeK() ) // load treeK the first time
423 rl->LoadKinematics() ;
425 fNPrimaries = rl->Stack()->GetNtrack() ;
428 printf("ReadTreeK: Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
431 // first time creates the container
433 fPrimaries->Clear() ;
436 for (index = 0 ; index < fNPrimaries; index++) {
437 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
441 //____________________________________________________________________________
442 Int_t AliEMCALGetter::ReadTreeD()
447 // gets TreeD from the root file (EMCAL.SDigits.root)
448 if ( !IsLoaded("D") ) {
449 EmcalLoader()->LoadDigits("UPDATE") ;
450 EmcalLoader()->LoadDigitizer("UPDATE") ;
453 return Digits()->GetEntries() ;
456 //____________________________________________________________________________
457 Int_t AliEMCALGetter::ReadTreeH()
461 // gets TreeH from the root file (EMCAL.Hit.root)
462 if ( !IsLoaded("H") ) {
463 EmcalLoader()->LoadHits("UPDATE") ;
466 return Hits()->GetEntries() ;
469 //____________________________________________________________________________
470 Int_t AliEMCALGetter::ReadTreeR()
472 // Read the RecPoints
475 // gets TreeR from the root file (EMCAL.RecPoints.root)
476 if ( !IsLoaded("R") ) {
477 EmcalLoader()->LoadRecPoints("UPDATE") ;
478 EmcalLoader()->LoadClusterizer("UPDATE") ;
482 return ECARecPoints()->GetEntries() ;
485 //____________________________________________________________________________
486 Int_t AliEMCALGetter::ReadTreeT()
488 // Read the TrackSegments
491 // gets TreeT from the root file (EMCAL.TrackSegments.root)
492 if ( !IsLoaded("T") ) {
493 EmcalLoader()->LoadTracks("UPDATE") ;
494 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
498 return TrackSegments()->GetEntries() ;
500 //____________________________________________________________________________
501 Int_t AliEMCALGetter::ReadTreeP()
503 // Read the TrackSegments
506 // gets TreeT from the root file (EMCAL.TrackSegments.root)
507 if ( !IsLoaded("P") ) {
508 EmcalLoader()->LoadRecParticles("UPDATE") ;
509 EmcalLoader()->LoadPID("UPDATE") ;
513 return RecParticles()->GetEntries() ;
515 //____________________________________________________________________________
516 Int_t AliEMCALGetter::ReadTreeS()
521 // gets TreeS from the root file (EMCAL.SDigits.root)
522 if ( !IsLoaded("S") ) {
523 EmcalLoader()->LoadSDigits("UPDATE") ;
524 EmcalLoader()->LoadSDigitizer("UPDATE") ;
528 return SDigits()->GetEntries() ;
531 //____________________________________________________________________________
532 TClonesArray * AliEMCALGetter::SDigits() const
534 // asks the Loader to return the Digits container
536 TClonesArray * rv = 0 ;
538 rv = EmcalLoader()->SDigits() ;
540 EmcalLoader()->MakeSDigitsArray() ;
541 rv = EmcalLoader()->SDigits() ;
546 //____________________________________________________________________________
547 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
549 // return pointer to SDigitizer Tree
550 AliEMCALSDigitizer * rv ;
551 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
554 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
559 //____________________________________________________________________________
560 TParticle * AliEMCALGetter::Secondary(const TParticle* p, const Int_t index) const
562 // Return first (index=1) or second (index=2) secondary particle of primary particle p
570 Int_t daughterIndex = p->GetDaughter(index-1) ;
571 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
572 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
578 //____________________________________________________________________________
579 void AliEMCALGetter::Track(const Int_t itrack)
581 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
583 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
585 if( !TreeH() ) // load treeH the first time
588 // first time create the container
589 TClonesArray * hits = Hits() ;
593 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
594 emcalbranch->SetAddress(&hits) ;
595 emcalbranch->GetEntry(itrack) ;
598 //____________________________________________________________________________
599 TTree * AliEMCALGetter::TreeD() const
601 // return pointer to Digits Tree
603 rv = EmcalLoader()->TreeD() ;
605 EmcalLoader()->MakeTree("D");
606 rv = EmcalLoader()->TreeD() ;
612 //____________________________________________________________________________
613 TTree * AliEMCALGetter::TreeH() const
615 // return pointer to Hits Tree
617 rv = EmcalLoader()->TreeH() ;
619 EmcalLoader()->MakeTree("H");
620 rv = EmcalLoader()->TreeH() ;
626 //____________________________________________________________________________
627 TTree * AliEMCALGetter::TreeR() const
629 // return pointer to RecPoints Tree
632 rv = EmcalLoader()->TreeR() ;
634 EmcalLoader()->MakeTree("R");
635 rv = EmcalLoader()->TreeR() ;
641 //____________________________________________________________________________
642 TTree * AliEMCALGetter::TreeT() const
644 // return pointer to TrackSegments Tree
646 rv = EmcalLoader()->TreeT() ;
648 EmcalLoader()->MakeTree("T");
649 rv = EmcalLoader()->TreeT() ;
654 //____________________________________________________________________________
655 TTree * AliEMCALGetter::TreeP() const
657 // return pointer to RecParticles Tree
659 rv = EmcalLoader()->TreeP() ;
661 EmcalLoader()->MakeTree("P");
662 rv = EmcalLoader()->TreeP() ;
668 //____________________________________________________________________________
669 TTree * AliEMCALGetter::TreeS() const
671 // return pointer to SDigits Tree
673 rv = EmcalLoader()->TreeS() ;
675 EmcalLoader()->MakeTree("S");
676 rv = EmcalLoader()->TreeS() ;
682 //____________________________________________________________________________
683 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
685 // checks if the version with the present name already exists in the same directory
689 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
690 TString version( rl->GetEventFolder()->GetName() ) ;
694 if ( opt == "sdigits") {
695 // add the version name to the root file name
696 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
697 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
698 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
699 if ( !(gSystem->AccessPathName(fileName)) ) {
700 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
703 EmcalLoader()->SetSDigitsFileName(fileName) ;
706 if ( opt == "digits") {
707 // add the version name to the root file name
708 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
709 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
710 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
711 if ( !(gSystem->AccessPathName(fileName)) ) {
712 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
715 EmcalLoader()->SetDigitsFileName(fileName) ;
722 //____________________________________________________________________________
723 UShort_t AliEMCALGetter::EventPattern(void) const
725 // Return the pattern (trigger bit register) of the beam-test event
727 // return fBTE->GetPattern() ;
731 //____________________________________________________________________________
732 Float_t AliEMCALGetter::BeamEnergy(void) const
734 // Return the beam energy of the beam-test event
736 // return fBTE->GetBeamEnergy() ;