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 "AliEMCALLoader.h"
58 ClassImp(AliEMCALGetter)
60 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
61 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
62 Int_t AliEMCALGetter::fgDebug = 0;
64 // TFile * AliEMCALGetter::fgFile = 0 ;
66 //____________________________________________________________________________
67 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
69 // ctor only called by Instance()
71 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
73 rl = AliRunLoader::Open(headerFile, version, openingOption);
75 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
78 if (rl->GetAliRun() == 0x0) {
80 gAlice = rl->GetAliRun(); // should be removed
83 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
85 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
87 fgEmcalLoader->SetTitle(version);
90 // initialize data members
97 //____________________________________________________________________________
98 AliEMCALGetter::~AliEMCALGetter()
101 delete fgEmcalLoader ;
105 fPrimaries->Delete() ;
109 //____________________________________________________________________________
110 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
112 // return pointer to Clusterizer Tree
113 AliEMCALClusterizer * rv ;
114 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
117 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
123 //____________________________________________________________________________
124 TClonesArray * AliEMCALGetter::Digits() const
126 // asks the Loader to return the Digits container
128 TClonesArray * rv = 0 ;
129 rv = EmcalLoader()->Digits() ;
132 EmcalLoader()->MakeDigitsArray() ;
133 rv = EmcalLoader()->Digits() ;
138 //____________________________________________________________________________
139 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
141 // return pointer to Digitizer Tree
142 AliEMCALDigitizer * rv ;
143 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
146 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
151 //____________________________________________________________________________
152 TObjArray * AliEMCALGetter::ECARecPoints() const
154 // asks the Loader to return the EMC RecPoints container
158 rv = EmcalLoader()->ECARecPoints() ;
160 EmcalLoader()->MakeRecPointsArray() ;
161 rv = EmcalLoader()->ECARecPoints() ;
166 //____________________________________________________________________________
167 TClonesArray * AliEMCALGetter::TrackSegments() const
169 // asks the Loader to return the TrackSegments container
171 TClonesArray * rv = 0 ;
173 rv = EmcalLoader()->TrackSegments() ;
175 EmcalLoader()->MakeTrackSegmentsArray() ;
176 rv = EmcalLoader()->TrackSegments() ;
181 //____________________________________________________________________________
182 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
184 // return pointer to TrackSegmentMaker Tree
185 AliEMCALTrackSegmentMaker * rv ;
186 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
189 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
194 //____________________________________________________________________________
195 TClonesArray * AliEMCALGetter::RecParticles() const
197 // asks the Loader to return the TrackSegments container
199 TClonesArray * rv = 0 ;
201 rv = EmcalLoader()->RecParticles() ;
203 EmcalLoader()->MakeRecParticlesArray() ;
204 rv = EmcalLoader()->RecParticles() ;
208 //____________________________________________________________________________
209 void AliEMCALGetter::Event(Int_t event, const char* opt)
211 // Reads the content of all Tree's S, D and R
213 if ( event >= MaxEvent() ) {
214 Error("Event", "%d not found in TreeE !", event) ;
218 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
220 // checks if we are dealing with test-beam data
221 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
224 // fBTE = new AliEMCALBeamTestEvent() ;
225 // btb->SetAddress(&fBTE) ;
226 // btb->GetEntry(event) ;
235 // Loads the type of object(s) requested
237 rl->GetEvent(event) ;
239 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
248 if( strstr(opt,"D") )
251 if( strstr(opt,"R") )
254 if( strstr(opt,"T") )
257 if( strstr(opt,"P") )
263 //____________________________________________________________________________
264 Int_t AliEMCALGetter::EventNumber() const
266 // return the current event number
267 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
268 return static_cast<Int_t>(rl->GetEventNumber()) ;
271 //____________________________________________________________________________
272 TClonesArray * AliEMCALGetter::Hits() const
274 // asks the loader to return the Hits container
276 TClonesArray * rv = 0 ;
278 rv = EmcalLoader()->Hits() ;
280 EmcalLoader()->LoadHits("read");
281 rv = EmcalLoader()->Hits() ;
286 //____________________________________________________________________________
287 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
289 // Creates and returns the pointer of the unique instance
290 // Must be called only when the environment has changed
292 if(!fgObjGetter){ // first time the getter is called
293 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
295 else { // the getter has been called previously
296 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
297 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
298 // check if the file is already open
299 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
302 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
304 else { // the file is already open check the version name
305 TString currentVersionName = rl->GetEventFolder()->GetName() ;
306 TString newVersionName(version) ;
307 if (currentVersionName == newVersionName)
309 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
311 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
316 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
319 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
327 //____________________________________________________________________________
328 AliEMCALGetter * AliEMCALGetter::Instance()
330 // Returns the pointer of the unique instance already defined
332 if(!fgObjGetter && fgDebug)
333 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
339 //____________________________________________________________________________
340 Int_t AliEMCALGetter::MaxEvent() const
342 // returns the number of events in the run (from TE)
344 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
345 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
348 //____________________________________________________________________________
349 TParticle * AliEMCALGetter::Primary(Int_t index) const
351 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
352 return rl->Stack()->Particle(index) ;
355 //____________________________________________________________________________
356 AliEMCAL * AliEMCALGetter:: EMCAL() const
358 // returns the EMCAL object
359 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
362 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
368 //____________________________________________________________________________
369 AliEMCALPID * AliEMCALGetter::PID()
371 // return pointer to PID Tree
373 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
376 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
381 //____________________________________________________________________________
382 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
384 // Returns EMCAL geometry
386 AliEMCALGeometry * rv = 0 ;
388 rv = EMCAL()->GetGeometry() ;
392 //____________________________________________________________________________
393 TClonesArray * AliEMCALGetter::Primaries()
395 // creates the Primaries container if needed
398 Info("Primaries", "Creating a new TClonesArray for primaries") ;
399 fPrimaries = new TClonesArray("TParticle", 1000) ;
404 //____________________________________________________________________________
405 void AliEMCALGetter::Print()
407 // Print usefull information about the getter
409 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
410 ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
413 //____________________________________________________________________________
414 void AliEMCALGetter::ReadPrimaries()
416 // Read Primaries from Kinematics.root
418 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
420 // gets kine tree from the root file (Kinematics.root)
421 if ( ! rl->TreeK() ) // load treeK the first time
422 rl->LoadKinematics() ;
424 fNPrimaries = rl->Stack()->GetNtrack() ;
427 Info("ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
430 // first time creates the container
432 fPrimaries->Clear() ;
435 for (index = 0 ; index < fNPrimaries; index++) {
436 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
440 //____________________________________________________________________________
441 Int_t AliEMCALGetter::ReadTreeD()
446 // gets TreeD from the root file (EMCAL.SDigits.root)
447 if ( !IsLoaded("D") ) {
448 EmcalLoader()->LoadDigits("UPDATE") ;
449 EmcalLoader()->LoadDigitizer("UPDATE") ;
452 return Digits()->GetEntries() ;
455 //____________________________________________________________________________
456 Int_t AliEMCALGetter::ReadTreeH()
460 // gets TreeH from the root file (EMCAL.Hit.root)
461 if ( !IsLoaded("H") ) {
462 EmcalLoader()->LoadHits("UPDATE") ;
465 return Hits()->GetEntries() ;
468 //____________________________________________________________________________
469 Int_t AliEMCALGetter::ReadTreeR()
471 // Read the RecPoints
474 // gets TreeR from the root file (EMCAL.RecPoints.root)
475 if ( !IsLoaded("R") ) {
476 EmcalLoader()->LoadRecPoints("UPDATE") ;
477 EmcalLoader()->LoadClusterizer("UPDATE") ;
481 return ECARecPoints()->GetEntries() ;
484 //____________________________________________________________________________
485 Int_t AliEMCALGetter::ReadTreeT()
487 // Read the TrackSegments
490 // gets TreeT from the root file (EMCAL.TrackSegments.root)
491 if ( !IsLoaded("T") ) {
492 EmcalLoader()->LoadTracks("UPDATE") ;
493 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
497 return TrackSegments()->GetEntries() ;
499 //____________________________________________________________________________
500 Int_t AliEMCALGetter::ReadTreeP()
502 // Read the TrackSegments
505 // gets TreeT from the root file (EMCAL.TrackSegments.root)
506 if ( !IsLoaded("P") ) {
507 EmcalLoader()->LoadRecParticles("UPDATE") ;
508 EmcalLoader()->LoadPID("UPDATE") ;
512 return RecParticles()->GetEntries() ;
514 //____________________________________________________________________________
515 Int_t AliEMCALGetter::ReadTreeS()
520 // gets TreeS from the root file (EMCAL.SDigits.root)
521 if ( !IsLoaded("S") ) {
522 EmcalLoader()->LoadSDigits("UPDATE") ;
523 EmcalLoader()->LoadSDigitizer("UPDATE") ;
527 return SDigits()->GetEntries() ;
530 //____________________________________________________________________________
531 TClonesArray * AliEMCALGetter::SDigits() const
533 // asks the Loader to return the Digits container
535 TClonesArray * rv = 0 ;
537 rv = EmcalLoader()->SDigits() ;
539 EmcalLoader()->MakeSDigitsArray() ;
540 rv = EmcalLoader()->SDigits() ;
545 //____________________________________________________________________________
546 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
548 // Return pointer to SDigitizer task
549 AliEMCALSDigitizer * rv ;
550 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
553 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
558 //____________________________________________________________________________
559 TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
561 // Return first (index=1) or second (index=2) secondary particle of primary particle p
569 Int_t daughterIndex = p->GetDaughter(index-1) ;
570 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
571 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
577 //____________________________________________________________________________
578 void AliEMCALGetter::Track(Int_t itrack)
580 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
582 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
584 if( !TreeH() ) // load treeH the first time
587 // first time create the container
588 TClonesArray * hits = Hits() ;
592 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
593 emcalbranch->SetAddress(&hits) ;
594 emcalbranch->GetEntry(itrack) ;
597 //____________________________________________________________________________
598 TTree * AliEMCALGetter::TreeD() const
600 // return pointer to Digits Tree
602 rv = EmcalLoader()->TreeD() ;
604 EmcalLoader()->MakeTree("D");
605 rv = EmcalLoader()->TreeD() ;
611 //____________________________________________________________________________
612 TTree * AliEMCALGetter::TreeH() const
614 // return pointer to Hits Tree
616 rv = EmcalLoader()->TreeH() ;
618 EmcalLoader()->MakeTree("H");
619 rv = EmcalLoader()->TreeH() ;
625 //____________________________________________________________________________
626 TTree * AliEMCALGetter::TreeR() const
628 // return pointer to RecPoints Tree
631 rv = EmcalLoader()->TreeR() ;
633 EmcalLoader()->MakeTree("R");
634 rv = EmcalLoader()->TreeR() ;
640 //____________________________________________________________________________
641 TTree * AliEMCALGetter::TreeT() const
643 // return pointer to TrackSegments Tree
645 rv = EmcalLoader()->TreeT() ;
647 EmcalLoader()->MakeTree("T");
648 rv = EmcalLoader()->TreeT() ;
653 //____________________________________________________________________________
654 TTree * AliEMCALGetter::TreeP() const
656 // return pointer to RecParticles Tree
658 rv = EmcalLoader()->TreeP() ;
660 EmcalLoader()->MakeTree("P");
661 rv = EmcalLoader()->TreeP() ;
667 //____________________________________________________________________________
668 TTree * AliEMCALGetter::TreeS() const
670 // return pointer to SDigits Tree
672 rv = EmcalLoader()->TreeS() ;
674 EmcalLoader()->MakeTree("S");
675 rv = EmcalLoader()->TreeS() ;
681 //____________________________________________________________________________
682 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
684 // checks if the version with the present name already exists in the same directory
688 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
689 TString version( rl->GetEventFolder()->GetName() ) ;
693 if ( opt == "sdigits") {
694 // add the version name to the root file name
695 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
696 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
697 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
698 if ( !(gSystem->AccessPathName(fileName)) ) {
699 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
702 EmcalLoader()->SetSDigitsFileName(fileName) ;
705 if ( opt == "digits") {
706 // add the version name to the root file name
707 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
708 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
709 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
710 if ( !(gSystem->AccessPathName(fileName)) ) {
711 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
720 //____________________________________________________________________________
721 UShort_t AliEMCALGetter::EventPattern(void) const
723 // Return the pattern (trigger bit register) of the beam-test event
725 // return fBTE->GetPattern() ;
729 //____________________________________________________________________________
730 Float_t AliEMCALGetter::BeamEnergy(void) const
732 // Return the beam energy of the beam-test event
734 // return fBTE->GetBeamEnergy() ;