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 // #include "TObjString.h"
48 // #include "TFolder.h"
49 // #include "TParticle.h"
51 // --- Standard library ---
53 // --- AliRoot header files ---
54 // #include "AliRun.h"
55 // #include "AliConfig.h"
56 #include "AliEMCALGetter.h"
58 #include "AliRunLoader.h"
60 #include "AliEMCALLoader.h"
63 ClassImp(AliEMCALGetter)
65 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
66 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
67 Int_t AliEMCALGetter::fgDebug = 0;
69 // TFile * AliEMCALGetter::fgFile = 0 ;
71 //____________________________________________________________________________
72 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
74 // ctor only called by Instance()
76 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
78 rl = AliRunLoader::Open(headerFile, version, openingOption);
80 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
83 if (rl->GetAliRun() == 0x0) {
85 gAlice = rl->GetAliRun(); // should be removed
88 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
90 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
92 fgEmcalLoader->SetTitle(version);
95 // initialize data members
102 //____________________________________________________________________________
103 AliEMCALGetter::~AliEMCALGetter()
106 delete fgEmcalLoader ;
110 fPrimaries->Delete() ;
114 //____________________________________________________________________________
115 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
117 AliEMCALClusterizer * rv ;
118 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
121 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
127 //____________________________________________________________________________
128 TClonesArray * AliEMCALGetter::Digits()
130 // asks the Loader to return the Digits container
132 TClonesArray * rv = 0 ;
133 rv = EmcalLoader()->Digits() ;
136 EmcalLoader()->MakeDigitsArray() ;
137 rv = EmcalLoader()->Digits() ;
142 //____________________________________________________________________________
143 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
145 AliEMCALDigitizer * rv ;
146 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
149 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
155 //____________________________________________________________________________
156 TObjArray * AliEMCALGetter::PRERecPoints()
158 // asks the Loader to return the EMC RecPoints container
162 rv = EmcalLoader()->PRERecPoints() ;
164 EmcalLoader()->MakeRecPointsArray() ;
165 rv = EmcalLoader()->PRERecPoints() ;
170 //____________________________________________________________________________
171 TObjArray * AliEMCALGetter::ECARecPoints()
173 // asks the Loader to return the EMC RecPoints container
177 rv = EmcalLoader()->ECARecPoints() ;
179 EmcalLoader()->MakeRecPointsArray() ;
180 rv = EmcalLoader()->ECARecPoints() ;
185 //____________________________________________________________________________
186 TObjArray * AliEMCALGetter::HCARecPoints()
188 // asks the Loader to return the EMC RecPoints container
192 rv = EmcalLoader()->HCARecPoints() ;
194 EmcalLoader()->MakeRecPointsArray() ;
195 rv = EmcalLoader()->HCARecPoints() ;
200 //____________________________________________________________________________
201 TClonesArray * AliEMCALGetter::TrackSegments()
203 // asks the Loader to return the TrackSegments container
205 TClonesArray * rv = 0 ;
207 rv = EmcalLoader()->TrackSegments() ;
209 EmcalLoader()->MakeTrackSegmentsArray() ;
210 rv = EmcalLoader()->TrackSegments() ;
215 //____________________________________________________________________________
216 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
218 AliEMCALTrackSegmentMaker * rv ;
219 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
222 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
227 //____________________________________________________________________________
228 TClonesArray * AliEMCALGetter::RecParticles()
230 // asks the Loader to return the TrackSegments container
232 TClonesArray * rv = 0 ;
234 rv = EmcalLoader()->RecParticles() ;
236 EmcalLoader()->MakeRecParticlesArray() ;
237 rv = EmcalLoader()->RecParticles() ;
241 //____________________________________________________________________________
242 void AliEMCALGetter::Event(const Int_t event, const char* opt)
244 // Reads the content of all Tree's S, D and R
246 if ( event >= MaxEvent() ) {
247 Error("Event", "%d not found in TreeE !", event) ;
251 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
253 // checks if we are dealing with test-beam data
254 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
257 // fBTE = new AliEMCALBeamTestEvent() ;
258 // btb->SetAddress(&fBTE) ;
259 // btb->GetEntry(event) ;
268 // Loads the type of object(s) requested
270 rl->GetEvent(event) ;
272 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
281 if( strstr(opt,"D") )
284 if( strstr(opt,"R") )
287 if( strstr(opt,"T") )
290 if( strstr(opt,"P") )
293 // if( strstr(opt,"Q") )
299 //____________________________________________________________________________
300 Int_t AliEMCALGetter::EventNumber() const
302 // return the current event number
303 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
304 return static_cast<Int_t>(rl->GetEventNumber()) ;
307 //____________________________________________________________________________
308 TClonesArray * AliEMCALGetter::Hits()
310 // asks the loader to return the Hits container
312 TClonesArray * rv = 0 ;
314 rv = EmcalLoader()->Hits() ;
316 EmcalLoader()->LoadHits("read");
317 rv = EmcalLoader()->Hits() ;
322 //____________________________________________________________________________
323 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
325 // Creates and returns the pointer of the unique instance
326 // Must be called only when the environment has changed
328 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
330 if(!fgObjGetter){ // first time the getter is called
331 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
333 else { // the getter has been called previously
334 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
335 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
336 // check if the file is already open
337 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
340 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
342 else { // the file is already open check the version name
343 TString currentVersionName = rl->GetEventFolder()->GetName() ;
344 TString newVersionName(version) ;
345 if (currentVersionName == newVersionName)
347 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
349 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
354 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
357 ::Error("Instance", "Failed to create the EMCAL Getter object") ;
365 //____________________________________________________________________________
366 AliEMCALGetter * AliEMCALGetter::Instance()
368 // Returns the pointer of the unique instance already defined
371 ::Error("Instance", "Getter not initialized") ;
377 //____________________________________________________________________________
378 Int_t AliEMCALGetter::MaxEvent() const
380 // returns the number of events in the run (from TE)
382 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
383 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
386 //____________________________________________________________________________
387 TParticle * AliEMCALGetter::Primary(Int_t index) const
389 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
390 return rl->Stack()->Particle(index) ;
393 //____________________________________________________________________________
394 AliEMCAL * AliEMCALGetter:: EMCAL() const
396 // returns the EMCAL object
397 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
400 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
406 //____________________________________________________________________________
407 AliEMCALPID * AliEMCALGetter::PID()
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()
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 AliEMCALSDigitizer * rv ;
586 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
589 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
594 //____________________________________________________________________________
595 TParticle * AliEMCALGetter::Secondary(const TParticle* p, const Int_t index) const
597 // Return first (index=1) or second (index=2) secondary particle of primary particle p
605 Int_t daughterIndex = p->GetDaughter(index-1) ;
606 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
607 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
613 //____________________________________________________________________________
614 void AliEMCALGetter::Track(const Int_t itrack)
616 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
618 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
620 if( !TreeH() ) // load treeH the first time
623 // first time create the container
624 TClonesArray * hits = Hits() ;
628 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
629 emcalbranch->SetAddress(&hits) ;
630 emcalbranch->GetEntry(itrack) ;
633 //____________________________________________________________________________
634 TTree * AliEMCALGetter::TreeD() const
637 rv = EmcalLoader()->TreeD() ;
639 EmcalLoader()->MakeTree("D");
640 rv = EmcalLoader()->TreeD() ;
646 //____________________________________________________________________________
647 TTree * AliEMCALGetter::TreeH() const
650 rv = EmcalLoader()->TreeH() ;
652 EmcalLoader()->MakeTree("H");
653 rv = EmcalLoader()->TreeH() ;
659 //____________________________________________________________________________
660 TTree * AliEMCALGetter::TreeR() const
663 rv = EmcalLoader()->TreeR() ;
665 EmcalLoader()->MakeTree("R");
666 rv = EmcalLoader()->TreeR() ;
672 //____________________________________________________________________________
673 TTree * AliEMCALGetter::TreeT() const
676 rv = EmcalLoader()->TreeT() ;
678 EmcalLoader()->MakeTree("T");
679 rv = EmcalLoader()->TreeT() ;
684 //____________________________________________________________________________
685 TTree * AliEMCALGetter::TreeP() const
688 rv = EmcalLoader()->TreeP() ;
690 EmcalLoader()->MakeTree("P");
691 rv = EmcalLoader()->TreeP() ;
697 //____________________________________________________________________________
698 TTree * AliEMCALGetter::TreeS() const
701 rv = EmcalLoader()->TreeS() ;
703 EmcalLoader()->MakeTree("S");
704 rv = EmcalLoader()->TreeS() ;
710 //____________________________________________________________________________
711 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
713 // checks if the version with the present name already exists in the same directory
717 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
718 TString version( rl->GetEventFolder()->GetName() ) ;
722 if ( opt == "sdigits") {
723 // add the version name to the root file name
724 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
725 if (version != AliConfig::fgkDefaultEventFolderName) // 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()) ;
731 EmcalLoader()->SetSDigitsFileName(fileName) ;
734 if ( opt == "digits") {
735 // add the version name to the root file name
736 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
737 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
738 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
739 if ( !(gSystem->AccessPathName(fileName)) ) {
740 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
743 EmcalLoader()->SetDigitsFileName(fileName) ;
750 //____________________________________________________________________________
751 UShort_t AliEMCALGetter::EventPattern(void) const
753 // Return the pattern (trigger bit register) of the beam-test event
755 // return fBTE->GetPattern() ;
759 //____________________________________________________________________________
760 Float_t AliEMCALGetter::BeamEnergy(void) const
762 // Return the beam energy of the beam-test event
764 // return fBTE->GetBeamEnergy() ;