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 ---
47 // --- Standard library ---
49 // --- AliRoot header files ---
51 #include "AliEMCALGetter.h"
53 #include "AliRunLoader.h"
55 #include "AliHeader.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() ;
111 //____________________________________________________________________________
112 void AliEMCALGetter::Reset()
114 // resets things in case the getter is called consecutively with different files
115 // the EMCAL Loader is already deleted by the Run Loader
118 fPrimaries->Delete() ;
125 //____________________________________________________________________________
126 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
128 // return pointer to Clusterizer Tree
129 AliEMCALClusterizer * rv ;
130 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
133 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
139 //____________________________________________________________________________
140 TClonesArray * AliEMCALGetter::Digits() const
142 // asks the Loader to return the Digits container
144 TClonesArray * rv = 0 ;
145 rv = EmcalLoader()->Digits() ;
148 EmcalLoader()->MakeDigitsArray() ;
149 rv = EmcalLoader()->Digits() ;
154 //____________________________________________________________________________
155 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
157 // return pointer to Digitizer Tree
158 AliEMCALDigitizer * rv ;
159 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
162 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
167 //____________________________________________________________________________
168 TObjArray * AliEMCALGetter::ECARecPoints() const
170 // asks the Loader to return the EMC RecPoints container
174 rv = EmcalLoader()->ECARecPoints() ;
176 EmcalLoader()->MakeRecPointsArray() ;
177 rv = EmcalLoader()->ECARecPoints() ;
182 //____________________________________________________________________________
183 TClonesArray * AliEMCALGetter::TrackSegments() const
185 // asks the Loader to return the TrackSegments container
187 TClonesArray * rv = 0 ;
189 rv = EmcalLoader()->TrackSegments() ;
191 EmcalLoader()->MakeTrackSegmentsArray() ;
192 rv = EmcalLoader()->TrackSegments() ;
197 //____________________________________________________________________________
198 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
200 // return pointer to TrackSegmentMaker Tree
201 AliEMCALTrackSegmentMaker * rv ;
202 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
205 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
210 //____________________________________________________________________________
211 TClonesArray * AliEMCALGetter::RecParticles() const
213 // asks the Loader to return the TrackSegments container
215 TClonesArray * rv = 0 ;
217 rv = EmcalLoader()->RecParticles() ;
219 EmcalLoader()->MakeRecParticlesArray() ;
220 rv = EmcalLoader()->RecParticles() ;
224 //____________________________________________________________________________
225 void AliEMCALGetter::Event(Int_t event, const char* opt)
227 // Reads the content of all Tree's S, D and R
229 if ( event >= MaxEvent() ) {
230 Error("Event", "%d not found in TreeE !", event) ;
234 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
235 // checks if we are dealing with test-beam data
236 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
239 // fBTE = new AliEMCALBeamTestEvent() ;
240 // btb->SetAddress(&fBTE) ;
241 // btb->GetEntry(event) ;
250 // Loads the type of object(s) requested
252 rl->GetEvent(event) ;
254 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
263 if( strstr(opt,"D") )
266 if( strstr(opt,"R") )
269 if( strstr(opt,"T") )
272 if( strstr(opt,"P") )
278 //____________________________________________________________________________
279 Int_t AliEMCALGetter::EventNumber() const
281 // return the current event number
282 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
283 return static_cast<Int_t>(rl->GetEventNumber()) ;
286 //____________________________________________________________________________
287 TClonesArray * AliEMCALGetter::Hits() const
289 // asks the loader to return the Hits container
291 TClonesArray * rv = 0 ;
293 rv = EmcalLoader()->Hits() ;
295 EmcalLoader()->LoadHits("read");
296 rv = EmcalLoader()->Hits() ;
301 //____________________________________________________________________________
302 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
304 // Creates and returns the pointer of the unique instance
305 // Must be called only when the environment has changed
307 if(!fgObjGetter){ // first time the getter is called
308 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
310 else { // the getter has been called previously
311 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
312 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
313 // check if the file is already open
314 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
317 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
319 else { // the file is already open check the version name
320 TString currentVersionName = rl->GetEventFolder()->GetName() ;
321 TString newVersionName(version) ;
322 if (currentVersionName == newVersionName)
324 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
326 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
331 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
332 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
334 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
338 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
346 //____________________________________________________________________________
347 AliEMCALGetter * AliEMCALGetter::Instance()
349 // Returns the pointer of the unique instance already defined
351 if(!fgObjGetter && fgDebug)
352 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
358 //____________________________________________________________________________
359 Int_t AliEMCALGetter::MaxEvent() const
361 // returns the number of events in the run (from TE)
363 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
364 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
367 //____________________________________________________________________________
368 TParticle * AliEMCALGetter::Primary(Int_t index) const
370 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
371 return rl->Stack()->Particle(index) ;
374 //____________________________________________________________________________
375 AliEMCAL * AliEMCALGetter:: EMCAL() const
377 // returns the EMCAL object
378 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
381 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
387 //____________________________________________________________________________
388 AliEMCALPID * AliEMCALGetter::PID()
390 // return pointer to PID Tree
392 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
395 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
400 //____________________________________________________________________________
401 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
403 // Returns EMCAL geometry
405 AliEMCALGeometry * rv = 0 ;
407 rv = EMCAL()->GetGeometry() ;
411 //____________________________________________________________________________
412 TClonesArray * AliEMCALGetter::Primaries()
414 // creates the Primaries container if needed
417 Info("Primaries", "Creating a new TClonesArray for primaries") ;
418 fPrimaries = new TClonesArray("TParticle", 1000) ;
423 //____________________________________________________________________________
424 void AliEMCALGetter::Print()
426 // Print usefull information about the getter
428 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
429 ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
432 //____________________________________________________________________________
433 void AliEMCALGetter::ReadPrimaries()
435 // Read Primaries from Kinematics.root
437 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
439 // gets kine tree from the root file (Kinematics.root)
440 if ( ! rl->TreeK() ) // load treeK the first time
441 rl->LoadKinematics() ;
443 fNPrimaries = (rl->GetHeader())->GetNtrack();
445 Info("ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
447 // first time creates the container
449 fPrimaries->Clear() ;
452 for (index = 0 ; index < fNPrimaries; index++) {
453 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
457 //____________________________________________________________________________
458 Int_t AliEMCALGetter::ReadTreeD()
463 // gets TreeD from the root file (EMCAL.SDigits.root)
464 if ( !IsLoaded("D") ) {
465 EmcalLoader()->LoadDigits("UPDATE") ;
466 EmcalLoader()->LoadDigitizer("UPDATE") ;
469 return Digits()->GetEntries() ;
472 //____________________________________________________________________________
473 Int_t AliEMCALGetter::ReadTreeH()
477 // gets TreeH from the root file (EMCAL.Hit.root)
478 if ( !IsLoaded("H") ) {
479 EmcalLoader()->LoadHits("READ") ;
482 return Hits()->GetEntries() ;
485 //____________________________________________________________________________
486 Int_t AliEMCALGetter::ReadTreeR()
488 // Read the RecPoints
491 // gets TreeR from the root file (EMCAL.RecPoints.root)
492 if ( !IsLoaded("R") ) {
493 EmcalLoader()->LoadRecPoints("UPDATE") ;
494 EmcalLoader()->LoadClusterizer("UPDATE") ;
498 return ECARecPoints()->GetEntries() ;
501 //____________________________________________________________________________
502 Int_t AliEMCALGetter::ReadTreeT()
504 // Read the TrackSegments
507 // gets TreeT from the root file (EMCAL.TrackSegments.root)
508 if ( !IsLoaded("T") ) {
509 EmcalLoader()->LoadTracks("UPDATE") ;
510 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
514 return TrackSegments()->GetEntries() ;
516 //____________________________________________________________________________
517 Int_t AliEMCALGetter::ReadTreeP()
519 // Read the TrackSegments
522 // gets TreeT from the root file (EMCAL.TrackSegments.root)
523 if ( !IsLoaded("P") ) {
524 EmcalLoader()->LoadRecParticles("UPDATE") ;
525 EmcalLoader()->LoadPID("UPDATE") ;
529 return RecParticles()->GetEntries() ;
531 //____________________________________________________________________________
532 Int_t AliEMCALGetter::ReadTreeS()
537 // gets TreeS from the root file (EMCAL.SDigits.root)
538 if ( !IsLoaded("S") ) {
539 EmcalLoader()->LoadSDigits("READ") ;
540 EmcalLoader()->LoadSDigitizer("READ") ;
544 return SDigits()->GetEntries() ;
547 //____________________________________________________________________________
548 TClonesArray * AliEMCALGetter::SDigits() const
550 // asks the Loader to return the Digits container
552 TClonesArray * rv = 0 ;
554 rv = EmcalLoader()->SDigits() ;
556 EmcalLoader()->MakeSDigitsArray() ;
557 rv = EmcalLoader()->SDigits() ;
562 //____________________________________________________________________________
563 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
565 // Return pointer to SDigitizer task
566 AliEMCALSDigitizer * rv ;
567 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
570 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
575 //____________________________________________________________________________
576 TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
578 // Return first (index=1) or second (index=2) secondary particle of primary particle p
586 Int_t daughterIndex = p->GetDaughter(index-1) ;
587 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
588 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
594 //____________________________________________________________________________
595 void AliEMCALGetter::Track(Int_t itrack)
597 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
599 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
601 if( !TreeH() ) // load treeH the first time
604 // first time create the container
605 TClonesArray * hits = Hits() ;
609 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
610 emcalbranch->SetAddress(&hits) ;
611 emcalbranch->GetEntry(itrack) ;
614 //____________________________________________________________________________
615 TTree * AliEMCALGetter::TreeD() const
617 // return pointer to Digits Tree
619 rv = EmcalLoader()->TreeD() ;
621 EmcalLoader()->MakeTree("D");
622 rv = EmcalLoader()->TreeD() ;
628 //____________________________________________________________________________
629 TTree * AliEMCALGetter::TreeH() const
631 // return pointer to Hits Tree
633 rv = EmcalLoader()->TreeH() ;
635 EmcalLoader()->MakeTree("H");
636 rv = EmcalLoader()->TreeH() ;
642 //____________________________________________________________________________
643 TTree * AliEMCALGetter::TreeR() const
645 // return pointer to RecPoints Tree
648 rv = EmcalLoader()->TreeR() ;
650 EmcalLoader()->MakeTree("R");
651 rv = EmcalLoader()->TreeR() ;
657 //____________________________________________________________________________
658 TTree * AliEMCALGetter::TreeT() const
660 // return pointer to TrackSegments Tree
662 rv = EmcalLoader()->TreeT() ;
664 EmcalLoader()->MakeTree("T");
665 rv = EmcalLoader()->TreeT() ;
670 //____________________________________________________________________________
671 TTree * AliEMCALGetter::TreeP() const
673 // return pointer to RecParticles Tree
675 rv = EmcalLoader()->TreeP() ;
677 EmcalLoader()->MakeTree("P");
678 rv = EmcalLoader()->TreeP() ;
684 //____________________________________________________________________________
685 TTree * AliEMCALGetter::TreeS() const
687 // return pointer to SDigits Tree
689 rv = EmcalLoader()->TreeS() ;
691 EmcalLoader()->MakeTree("S");
692 rv = EmcalLoader()->TreeS() ;
698 //____________________________________________________________________________
699 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
701 // checks if the version with the present name already exists in the same directory
705 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
706 TString version( rl->GetEventFolder()->GetName() ) ;
710 if ( opt == "sdigits") {
711 // add the version name to the root file name
712 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
713 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
714 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
715 if ( !(gSystem->AccessPathName(fileName)) ) {
716 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
719 EmcalLoader()->SetSDigitsFileName(fileName) ;
722 if ( opt == "digits") {
723 // add the version name to the root file name
724 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
725 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
726 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
727 if ( !(gSystem->AccessPathName(fileName)) ) {
728 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
737 //____________________________________________________________________________
738 UShort_t AliEMCALGetter::EventPattern(void) const
740 // Return the pattern (trigger bit register) of the beam-test event
742 // return fBTE->GetPattern() ;
746 //____________________________________________________________________________
747 Float_t AliEMCALGetter::BeamEnergy(void) const
749 // Return the beam energy of the beam-test event
751 // return fBTE->GetBeamEnergy() ;