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()) ;
153 //____________________________________________________________________________
154 TObjArray * AliEMCALGetter::PRERecPoints() const
156 // asks the Loader to return the EMC RecPoints container
160 rv = EmcalLoader()->PRERecPoints() ;
162 EmcalLoader()->MakeRecPointsArray() ;
163 rv = EmcalLoader()->PRERecPoints() ;
168 //____________________________________________________________________________
169 TObjArray * AliEMCALGetter::ECARecPoints() const
171 // asks the Loader to return the EMC RecPoints container
175 rv = EmcalLoader()->ECARecPoints() ;
177 EmcalLoader()->MakeRecPointsArray() ;
178 rv = EmcalLoader()->ECARecPoints() ;
183 //____________________________________________________________________________
184 TObjArray * AliEMCALGetter::HCARecPoints() const
186 // asks the Loader to return the EMC RecPoints container
190 rv = EmcalLoader()->HCARecPoints() ;
192 EmcalLoader()->MakeRecPointsArray() ;
193 rv = EmcalLoader()->HCARecPoints() ;
198 //____________________________________________________________________________
199 TClonesArray * AliEMCALGetter::TrackSegments() const
201 // asks the Loader to return the TrackSegments container
203 TClonesArray * rv = 0 ;
205 rv = EmcalLoader()->TrackSegments() ;
207 EmcalLoader()->MakeTrackSegmentsArray() ;
208 rv = EmcalLoader()->TrackSegments() ;
213 //____________________________________________________________________________
214 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
216 // return pointer to TrackSegmentMaker Tree
217 AliEMCALTrackSegmentMaker * rv ;
218 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
221 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
226 //____________________________________________________________________________
227 TClonesArray * AliEMCALGetter::RecParticles() const
229 // asks the Loader to return the TrackSegments container
231 TClonesArray * rv = 0 ;
233 rv = EmcalLoader()->RecParticles() ;
235 EmcalLoader()->MakeRecParticlesArray() ;
236 rv = EmcalLoader()->RecParticles() ;
240 //____________________________________________________________________________
241 void AliEMCALGetter::Event(const Int_t event, const char* opt)
243 // Reads the content of all Tree's S, D and R
245 if ( event >= MaxEvent() ) {
246 Error("Event", "%d not found in TreeE !", event) ;
250 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
252 // checks if we are dealing with test-beam data
253 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
256 // fBTE = new AliEMCALBeamTestEvent() ;
257 // btb->SetAddress(&fBTE) ;
258 // btb->GetEntry(event) ;
267 // Loads the type of object(s) requested
269 rl->GetEvent(event) ;
271 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
280 if( strstr(opt,"D") )
283 if( strstr(opt,"R") )
286 if( strstr(opt,"T") )
289 if( strstr(opt,"P") )
292 // if( strstr(opt,"Q") )
298 //____________________________________________________________________________
299 Int_t AliEMCALGetter::EventNumber() const
301 // return the current event number
302 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
303 return static_cast<Int_t>(rl->GetEventNumber()) ;
306 //____________________________________________________________________________
307 TClonesArray * AliEMCALGetter::Hits() const
309 // asks the loader to return the Hits container
311 TClonesArray * rv = 0 ;
313 rv = EmcalLoader()->Hits() ;
315 EmcalLoader()->LoadHits("read");
316 rv = EmcalLoader()->Hits() ;
321 //____________________________________________________________________________
322 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
324 // Creates and returns the pointer of the unique instance
325 // Must be called only when the environment has changed
327 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
329 if(!fgObjGetter){ // first time the getter is called
330 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
332 else { // the getter has been called previously
333 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
334 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
335 // check if the file is already open
336 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
339 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
341 else { // the file is already open check the version name
342 TString currentVersionName = rl->GetEventFolder()->GetName() ;
343 TString newVersionName(version) ;
344 if (currentVersionName == newVersionName)
346 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
348 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
353 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
356 ::Error("Instance", "Failed to create the EMCAL Getter object") ;
364 //____________________________________________________________________________
365 AliEMCALGetter * AliEMCALGetter::Instance()
367 // Returns the pointer of the unique instance already defined
370 ::Error("Instance", "Getter not initialized") ;
376 //____________________________________________________________________________
377 Int_t AliEMCALGetter::MaxEvent() const
379 // returns the number of events in the run (from TE)
381 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
382 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
385 //____________________________________________________________________________
386 TParticle * AliEMCALGetter::Primary(Int_t index) const
388 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
389 return rl->Stack()->Particle(index) ;
392 //____________________________________________________________________________
393 AliEMCAL * AliEMCALGetter:: EMCAL() const
395 // returns the EMCAL object
396 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
399 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
405 //____________________________________________________________________________
406 AliEMCALPID * AliEMCALGetter::PID()
408 // return pointer to PID Tree
410 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
413 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
418 //____________________________________________________________________________
419 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
421 // Returns EMCAL geometry
423 AliEMCALGeometry * rv = 0 ;
425 rv = EMCAL()->GetGeometry() ;
429 //____________________________________________________________________________
430 TClonesArray * AliEMCALGetter::Primaries()
432 // creates the Primaries container if needed
435 Info("Primaries", "Creating a new TClonesArray for primaries") ;
436 fPrimaries = new TClonesArray("TParticle", 1000) ;
441 //____________________________________________________________________________
442 void AliEMCALGetter::Print()
444 // Print usefull information about the getter
446 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
447 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
450 //____________________________________________________________________________
451 void AliEMCALGetter::ReadPrimaries()
453 // Read Primaries from Kinematics.root
455 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
457 // gets kine tree from the root file (Kinematics.root)
458 if ( ! rl->TreeK() ) // load treeK the first time
459 rl->LoadKinematics() ;
461 fNPrimaries = rl->Stack()->GetNtrack() ;
464 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
467 // first time creates the container
469 fPrimaries->Clear() ;
472 for (index = 0 ; index < fNPrimaries; index++) {
473 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
477 //____________________________________________________________________________
478 Int_t AliEMCALGetter::ReadTreeD()
483 // gets TreeD from the root file (EMCAL.SDigits.root)
484 if ( !IsLoaded("D") ) {
485 EmcalLoader()->LoadDigits("UPDATE") ;
486 EmcalLoader()->LoadDigitizer("UPDATE") ;
489 return Digits()->GetEntries() ;
492 //____________________________________________________________________________
493 Int_t AliEMCALGetter::ReadTreeH()
497 // gets TreeH from the root file (EMCAL.Hit.root)
498 if ( !IsLoaded("H") ) {
499 EmcalLoader()->LoadHits("UPDATE") ;
502 return Hits()->GetEntries() ;
505 //____________________________________________________________________________
506 Int_t AliEMCALGetter::ReadTreeR()
508 // Read the RecPoints
511 // gets TreeR from the root file (EMCAL.RecPoints.root)
512 if ( !IsLoaded("R") ) {
513 EmcalLoader()->LoadRecPoints("UPDATE") ;
514 EmcalLoader()->LoadClusterizer("UPDATE") ;
518 return ECARecPoints()->GetEntries() ;
521 //____________________________________________________________________________
522 Int_t AliEMCALGetter::ReadTreeT()
524 // Read the TrackSegments
527 // gets TreeT from the root file (EMCAL.TrackSegments.root)
528 if ( !IsLoaded("T") ) {
529 EmcalLoader()->LoadTracks("UPDATE") ;
530 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
534 return TrackSegments()->GetEntries() ;
536 //____________________________________________________________________________
537 Int_t AliEMCALGetter::ReadTreeP()
539 // Read the TrackSegments
542 // gets TreeT from the root file (EMCAL.TrackSegments.root)
543 if ( !IsLoaded("P") ) {
544 EmcalLoader()->LoadRecParticles("UPDATE") ;
545 EmcalLoader()->LoadPID("UPDATE") ;
549 return RecParticles()->GetEntries() ;
551 //____________________________________________________________________________
552 Int_t AliEMCALGetter::ReadTreeS()
557 // gets TreeS from the root file (EMCAL.SDigits.root)
558 if ( !IsLoaded("S") ) {
559 EmcalLoader()->LoadSDigits("UPDATE") ;
560 EmcalLoader()->LoadSDigitizer("UPDATE") ;
564 return SDigits()->GetEntries() ;
567 //____________________________________________________________________________
568 TClonesArray * AliEMCALGetter::SDigits() const
570 // asks the Loader to return the Digits container
572 TClonesArray * rv = 0 ;
574 rv = EmcalLoader()->SDigits() ;
576 EmcalLoader()->MakeSDigitsArray() ;
577 rv = EmcalLoader()->SDigits() ;
582 //____________________________________________________________________________
583 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
585 // return pointer to SDigitizer Tree
586 AliEMCALSDigitizer * rv ;
587 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
590 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
595 //____________________________________________________________________________
596 TParticle * AliEMCALGetter::Secondary(const TParticle* p, const Int_t index) const
598 // Return first (index=1) or second (index=2) secondary particle of primary particle p
606 Int_t daughterIndex = p->GetDaughter(index-1) ;
607 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
608 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
614 //____________________________________________________________________________
615 void AliEMCALGetter::Track(const Int_t itrack)
617 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
619 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
621 if( !TreeH() ) // load treeH the first time
624 // first time create the container
625 TClonesArray * hits = Hits() ;
629 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
630 emcalbranch->SetAddress(&hits) ;
631 emcalbranch->GetEntry(itrack) ;
634 //____________________________________________________________________________
635 TTree * AliEMCALGetter::TreeD() const
637 // return pointer to Digits Tree
639 rv = EmcalLoader()->TreeD() ;
641 EmcalLoader()->MakeTree("D");
642 rv = EmcalLoader()->TreeD() ;
648 //____________________________________________________________________________
649 TTree * AliEMCALGetter::TreeH() const
651 // return pointer to Hits Tree
653 rv = EmcalLoader()->TreeH() ;
655 EmcalLoader()->MakeTree("H");
656 rv = EmcalLoader()->TreeH() ;
662 //____________________________________________________________________________
663 TTree * AliEMCALGetter::TreeR() const
665 // return pointer to RecPoints Tree
668 rv = EmcalLoader()->TreeR() ;
670 EmcalLoader()->MakeTree("R");
671 rv = EmcalLoader()->TreeR() ;
677 //____________________________________________________________________________
678 TTree * AliEMCALGetter::TreeT() const
680 // return pointer to TrackSegments Tree
682 rv = EmcalLoader()->TreeT() ;
684 EmcalLoader()->MakeTree("T");
685 rv = EmcalLoader()->TreeT() ;
690 //____________________________________________________________________________
691 TTree * AliEMCALGetter::TreeP() const
693 // return pointer to RecParticles Tree
695 rv = EmcalLoader()->TreeP() ;
697 EmcalLoader()->MakeTree("P");
698 rv = EmcalLoader()->TreeP() ;
704 //____________________________________________________________________________
705 TTree * AliEMCALGetter::TreeS() const
707 // return pointer to SDigits Tree
709 rv = EmcalLoader()->TreeS() ;
711 EmcalLoader()->MakeTree("S");
712 rv = EmcalLoader()->TreeS() ;
718 //____________________________________________________________________________
719 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
721 // checks if the version with the present name already exists in the same directory
725 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
726 TString version( rl->GetEventFolder()->GetName() ) ;
730 if ( opt == "sdigits") {
731 // add the version name to the root file name
732 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
733 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
734 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
735 if ( !(gSystem->AccessPathName(fileName)) ) {
736 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
739 EmcalLoader()->SetSDigitsFileName(fileName) ;
742 if ( opt == "digits") {
743 // add the version name to the root file name
744 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
745 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
746 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
747 if ( !(gSystem->AccessPathName(fileName)) ) {
748 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
751 EmcalLoader()->SetDigitsFileName(fileName) ;
758 //____________________________________________________________________________
759 UShort_t AliEMCALGetter::EventPattern(void) const
761 // Return the pattern (trigger bit register) of the beam-test event
763 // return fBTE->GetPattern() ;
767 //____________________________________________________________________________
768 Float_t AliEMCALGetter::BeamEnergy(void) const
770 // Return the beam energy of the beam-test event
772 // return fBTE->GetBeamEnergy() ;