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 ---
53 #include "AliEMCALGetter.h"
54 #include "AliEMCALLoader.h"
55 #include "AliHeader.h"
57 #include "AliRunLoader.h"
60 ClassImp(AliEMCALGetter)
62 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
63 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
64 Int_t AliEMCALGetter::fgDebug = 0;
66 // TFile * AliEMCALGetter::fgFile = 0 ;
68 //____________________________________________________________________________
69 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
71 // ctor only called by Instance()
73 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
75 rl = AliRunLoader::Open(headerFile, version, openingOption);
77 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
80 if (rl->GetAliRun() == 0x0) {
82 gAlice = rl->GetAliRun(); // should be removed
85 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
87 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
89 fgEmcalLoader->SetTitle(version);
92 // initialize data members
99 //____________________________________________________________________________
100 AliEMCALGetter::~AliEMCALGetter()
103 delete fgEmcalLoader ;
107 fPrimaries->Delete() ;
112 //____________________________________________________________________________
113 void AliEMCALGetter::Reset()
115 // resets things in case the getter is called consecutively with different files
116 // the EMCAL Loader is already deleted by the Run Loader
119 fPrimaries->Delete() ;
126 //____________________________________________________________________________
127 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
129 // return pointer to Clusterizer Tree
130 AliEMCALClusterizer * rv ;
131 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
134 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
140 //____________________________________________________________________________
141 TClonesArray * AliEMCALGetter::Digits() const
143 // asks the Loader to return the Digits container
145 TClonesArray * rv = 0 ;
146 rv = EmcalLoader()->Digits() ;
149 EmcalLoader()->MakeDigitsArray() ;
150 rv = EmcalLoader()->Digits() ;
155 //____________________________________________________________________________
156 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
158 // return pointer to Digitizer Tree
159 AliEMCALDigitizer * rv ;
160 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
163 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
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 TClonesArray * AliEMCALGetter::TrackSegments() const
186 // asks the Loader to return the TrackSegments container
188 TClonesArray * rv = 0 ;
190 rv = EmcalLoader()->TrackSegments() ;
192 EmcalLoader()->MakeTrackSegmentsArray() ;
193 rv = EmcalLoader()->TrackSegments() ;
198 //____________________________________________________________________________
199 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
201 // return pointer to TrackSegmentMaker Tree
202 AliEMCALTrackSegmentMaker * rv ;
203 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
206 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
211 //____________________________________________________________________________
212 TClonesArray * AliEMCALGetter::RecParticles() const
214 // asks the Loader to return the TrackSegments container
216 TClonesArray * rv = 0 ;
218 rv = EmcalLoader()->RecParticles() ;
220 EmcalLoader()->MakeRecParticlesArray() ;
221 rv = EmcalLoader()->RecParticles() ;
225 //____________________________________________________________________________
226 void AliEMCALGetter::Event(Int_t event, const char* opt)
228 // Reads the content of all Tree's S, D and R
230 if ( event >= MaxEvent() ) {
231 Error("Event", "%d not found in TreeE !", event) ;
235 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
236 // checks if we are dealing with test-beam data
237 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
240 // fBTE = new AliEMCALBeamTestEvent() ;
241 // btb->SetAddress(&fBTE) ;
242 // btb->GetEntry(event) ;
251 // Loads the type of object(s) requested
253 rl->GetEvent(event) ;
255 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
264 if( strstr(opt,"D") )
267 if( strstr(opt,"R") )
270 if( strstr(opt,"T") )
273 if( strstr(opt,"P") )
279 //____________________________________________________________________________
280 Int_t AliEMCALGetter::EventNumber() const
282 // return the current event number
283 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
284 return static_cast<Int_t>(rl->GetEventNumber()) ;
287 //____________________________________________________________________________
288 TClonesArray * AliEMCALGetter::Hits() const
290 // asks the loader to return the Hits container
292 TClonesArray * rv = 0 ;
294 rv = EmcalLoader()->Hits() ;
296 EmcalLoader()->LoadHits("read");
297 rv = EmcalLoader()->Hits() ;
302 //____________________________________________________________________________
303 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
305 // Creates and returns the pointer of the unique instance
306 // Must be called only when the environment has changed
308 if(!fgObjGetter){ // first time the getter is called
309 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
311 else { // the getter has been called previously
312 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
313 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
314 // check if the file is already open
315 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
318 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
320 else { // the file is already open check the version name
321 TString currentVersionName = rl->GetEventFolder()->GetName() ;
322 TString newVersionName(version) ;
323 if (currentVersionName == newVersionName)
325 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
327 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
332 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
333 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
335 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
339 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
347 //____________________________________________________________________________
348 AliEMCALGetter * AliEMCALGetter::Instance()
350 // Returns the pointer of the unique instance already defined
352 if(!fgObjGetter && fgDebug)
353 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
359 //____________________________________________________________________________
360 Int_t AliEMCALGetter::MaxEvent() const
362 // returns the number of events in the run (from TE)
364 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
365 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
368 //____________________________________________________________________________
369 TParticle * AliEMCALGetter::Primary(Int_t index) const
371 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
372 return rl->Stack()->Particle(index) ;
375 //____________________________________________________________________________
376 AliEMCAL * AliEMCALGetter:: EMCAL() const
378 // returns the EMCAL object
379 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
382 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
388 //____________________________________________________________________________
389 AliEMCALPID * AliEMCALGetter::PID()
391 // return pointer to PID Tree
393 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
396 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
401 //____________________________________________________________________________
402 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
404 // Returns EMCAL geometry
406 AliEMCALGeometry * rv = 0 ;
408 rv = EMCAL()->GetGeometry() ;
412 //____________________________________________________________________________
413 TClonesArray * AliEMCALGetter::Primaries()
415 // creates the Primaries container if needed
418 Info("Primaries", "Creating a new TClonesArray for primaries") ;
419 fPrimaries = new TClonesArray("TParticle", 1000) ;
424 //____________________________________________________________________________
425 void AliEMCALGetter::Print()
427 // Print usefull information about the getter
429 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
430 ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
433 //____________________________________________________________________________
434 void AliEMCALGetter::ReadPrimaries()
436 // Read Primaries from Kinematics.root
438 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
440 // gets kine tree from the root file (Kinematics.root)
441 if ( ! rl->TreeK() ) // load treeK the first time
442 rl->LoadKinematics() ;
444 fNPrimaries = (rl->GetHeader())->GetNtrack();
446 Info("ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
448 // first time creates the container
450 fPrimaries->Clear() ;
453 for (index = 0 ; index < fNPrimaries; index++) {
454 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
458 //____________________________________________________________________________
459 Int_t AliEMCALGetter::ReadTreeD()
464 // gets TreeD from the root file (EMCAL.SDigits.root)
465 if ( !IsLoaded("D") ) {
466 EmcalLoader()->LoadDigits("UPDATE") ;
467 EmcalLoader()->LoadDigitizer("UPDATE") ;
470 return Digits()->GetEntries() ;
473 //____________________________________________________________________________
474 Int_t AliEMCALGetter::ReadTreeH()
478 // gets TreeH from the root file (EMCAL.Hit.root)
479 if ( !IsLoaded("H") ) {
480 EmcalLoader()->LoadHits("READ") ;
483 return Hits()->GetEntries() ;
486 //____________________________________________________________________________
487 Int_t AliEMCALGetter::ReadTreeR()
489 // Read the RecPoints
492 // gets TreeR from the root file (EMCAL.RecPoints.root)
493 if ( !IsLoaded("R") ) {
494 EmcalLoader()->LoadRecPoints("UPDATE") ;
495 EmcalLoader()->LoadClusterizer("UPDATE") ;
499 return ECARecPoints()->GetEntries() ;
502 //____________________________________________________________________________
503 Int_t AliEMCALGetter::ReadTreeT()
505 // Read the TrackSegments
508 // gets TreeT from the root file (EMCAL.TrackSegments.root)
509 if ( !IsLoaded("T") ) {
510 EmcalLoader()->LoadTracks("UPDATE") ;
511 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
515 return TrackSegments()->GetEntries() ;
517 //____________________________________________________________________________
518 Int_t AliEMCALGetter::ReadTreeP()
520 // Read the TrackSegments
523 // gets TreeT from the root file (EMCAL.TrackSegments.root)
524 if ( !IsLoaded("P") ) {
525 EmcalLoader()->LoadRecParticles("UPDATE") ;
526 EmcalLoader()->LoadPID("UPDATE") ;
530 return RecParticles()->GetEntries() ;
532 //____________________________________________________________________________
533 Int_t AliEMCALGetter::ReadTreeS()
538 // gets TreeS from the root file (EMCAL.SDigits.root)
539 if ( !IsLoaded("S") ) {
540 EmcalLoader()->LoadSDigits("READ") ;
541 EmcalLoader()->LoadSDigitizer("READ") ;
545 return SDigits()->GetEntries() ;
548 //____________________________________________________________________________
549 TClonesArray * AliEMCALGetter::SDigits() const
551 // asks the Loader to return the Digits container
553 TClonesArray * rv = 0 ;
555 rv = EmcalLoader()->SDigits() ;
557 EmcalLoader()->MakeSDigitsArray() ;
558 rv = EmcalLoader()->SDigits() ;
563 //____________________________________________________________________________
564 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
566 // Return pointer to SDigitizer task
567 AliEMCALSDigitizer * rv ;
568 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
571 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
576 //____________________________________________________________________________
577 TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
579 // Return first (index=1) or second (index=2) secondary particle of primary particle p
587 Int_t daughterIndex = p->GetDaughter(index-1) ;
588 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
589 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
595 //____________________________________________________________________________
596 void AliEMCALGetter::Track(Int_t itrack)
598 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
600 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
602 if( !TreeH() ) // load treeH the first time
605 // first time create the container
606 TClonesArray * hits = Hits() ;
610 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
611 emcalbranch->SetAddress(&hits) ;
612 emcalbranch->GetEntry(itrack) ;
615 //____________________________________________________________________________
616 TTree * AliEMCALGetter::TreeD() const
618 // return pointer to Digits Tree
620 rv = EmcalLoader()->TreeD() ;
622 EmcalLoader()->MakeTree("D");
623 rv = EmcalLoader()->TreeD() ;
629 //____________________________________________________________________________
630 TTree * AliEMCALGetter::TreeH() const
632 // return pointer to Hits Tree
634 rv = EmcalLoader()->TreeH() ;
636 EmcalLoader()->MakeTree("H");
637 rv = EmcalLoader()->TreeH() ;
643 //____________________________________________________________________________
644 TTree * AliEMCALGetter::TreeR() const
646 // return pointer to RecPoints Tree
649 rv = EmcalLoader()->TreeR() ;
651 EmcalLoader()->MakeTree("R");
652 rv = EmcalLoader()->TreeR() ;
658 //____________________________________________________________________________
659 TTree * AliEMCALGetter::TreeT() const
661 // return pointer to TrackSegments Tree
663 rv = EmcalLoader()->TreeT() ;
665 EmcalLoader()->MakeTree("T");
666 rv = EmcalLoader()->TreeT() ;
671 //____________________________________________________________________________
672 TTree * AliEMCALGetter::TreeP() const
674 // return pointer to RecParticles Tree
676 rv = EmcalLoader()->TreeP() ;
678 EmcalLoader()->MakeTree("P");
679 rv = EmcalLoader()->TreeP() ;
685 //____________________________________________________________________________
686 TTree * AliEMCALGetter::TreeS() const
688 // return pointer to SDigits Tree
690 rv = EmcalLoader()->TreeS() ;
692 EmcalLoader()->MakeTree("S");
693 rv = EmcalLoader()->TreeS() ;
699 //____________________________________________________________________________
700 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
702 // checks if the version with the present name already exists in the same directory
706 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
707 TString version( rl->GetEventFolder()->GetName() ) ;
711 if ( opt == "sdigits") {
712 // add the version name to the root file name
713 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
714 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
715 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
716 if ( !(gSystem->AccessPathName(fileName)) ) {
717 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
720 EmcalLoader()->SetSDigitsFileName(fileName) ;
723 if ( opt == "digits") {
724 // add the version name to the root file name
725 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
726 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
727 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
728 if ( !(gSystem->AccessPathName(fileName)) ) {
729 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
738 //____________________________________________________________________________
739 UShort_t AliEMCALGetter::EventPattern(void) const
741 // Return the pattern (trigger bit register) of the beam-test event
743 // return fBTE->GetPattern() ;
747 //____________________________________________________________________________
748 Float_t AliEMCALGetter::BeamEnergy(void) const
750 // Return the beam energy of the beam-test event
752 // return fBTE->GetBeamEnergy() ;