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"
57 #include "AliRunLoader.h"
59 #include "AliEMCALLoader.h"
61 ClassImp(AliEMCALGetter)
63 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
64 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
65 Int_t AliEMCALGetter::fgDebug = 0;
67 // TFile * AliEMCALGetter::fgFile = 0 ;
69 //____________________________________________________________________________
70 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
72 // ctor only called by Instance()
74 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
76 rl = AliRunLoader::Open(headerFile, version, openingOption);
78 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
81 if (rl->GetAliRun() == 0x0) {
83 gAlice = rl->GetAliRun(); // should be removed
86 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
88 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
90 fgEmcalLoader->SetTitle(version);
93 // initialize data members
100 //____________________________________________________________________________
101 AliEMCALGetter::~AliEMCALGetter()
104 delete fgEmcalLoader ;
108 fPrimaries->Delete() ;
112 //____________________________________________________________________________
113 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
115 AliEMCALClusterizer * rv ;
116 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
119 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
125 //____________________________________________________________________________
126 TClonesArray * AliEMCALGetter::Digits()
128 // asks the Loader to return the Digits container
130 TClonesArray * rv = 0 ;
131 rv = EmcalLoader()->Digits() ;
134 EmcalLoader()->MakeDigitsArray() ;
135 rv = EmcalLoader()->Digits() ;
140 //____________________________________________________________________________
141 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
143 AliEMCALDigitizer * rv ;
144 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
147 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
153 //____________________________________________________________________________
154 TObjArray * AliEMCALGetter::PRERecPoints()
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()
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()
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()
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 AliEMCALTrackSegmentMaker * rv ;
217 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
220 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
225 //____________________________________________________________________________
226 TClonesArray * AliEMCALGetter::RecParticles()
228 // asks the Loader to return the TrackSegments container
230 TClonesArray * rv = 0 ;
232 rv = EmcalLoader()->RecParticles() ;
234 EmcalLoader()->MakeRecParticlesArray() ;
235 rv = EmcalLoader()->RecParticles() ;
239 //____________________________________________________________________________
240 void AliEMCALGetter::Event(const Int_t event, const char* opt)
242 // Reads the content of all Tree's S, D and R
244 if ( event >= MaxEvent() ) {
245 Error("Event", "%d not found in TreeE !", event) ;
249 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
251 // checks if we are dealing with test-beam data
252 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
255 // fBTE = new AliEMCALBeamTestEvent() ;
256 // btb->SetAddress(&fBTE) ;
257 // btb->GetEntry(event) ;
266 // Loads the type of object(s) requested
268 rl->GetEvent(event) ;
270 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
279 if( strstr(opt,"D") )
282 if( strstr(opt,"R") )
285 if( strstr(opt,"T") )
288 if( strstr(opt,"P") )
291 // if( strstr(opt,"Q") )
297 //____________________________________________________________________________
298 Int_t AliEMCALGetter::EventNumber() const
300 // return the current event number
301 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
302 return static_cast<Int_t>(rl->GetEventNumber()) ;
305 //____________________________________________________________________________
306 TClonesArray * AliEMCALGetter::Hits()
308 // asks the loader to return the Hits container
310 TClonesArray * rv = 0 ;
312 rv = EmcalLoader()->Hits() ;
314 EmcalLoader()->LoadHits("read");
315 rv = EmcalLoader()->Hits() ;
320 //____________________________________________________________________________
321 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
323 // Creates and returns the pointer of the unique instance
324 // Must be called only when the environment has changed
326 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
328 if(!fgObjGetter){ // first time the getter is called
329 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
331 else { // the getter has been called previously
332 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
333 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
334 // check if the file is already open
335 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
338 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
340 else { // the file is already open check the version name
341 TString currentVersionName = rl->GetEventFolder()->GetName() ;
342 TString newVersionName(version) ;
343 if (currentVersionName == newVersionName)
345 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
347 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
352 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
355 ::Error("Instance", "Failed to create the EMCAL Getter object") ;
363 //____________________________________________________________________________
364 AliEMCALGetter * AliEMCALGetter::Instance()
366 // Returns the pointer of the unique instance already defined
369 ::Error("Instance", "Getter not initialized") ;
375 //____________________________________________________________________________
376 Int_t AliEMCALGetter::MaxEvent() const
378 // returns the number of events in the run (from TE)
380 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
381 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
384 //____________________________________________________________________________
385 TParticle * AliEMCALGetter::Primary(Int_t index) const
387 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
388 return rl->Stack()->Particle(index) ;
391 //____________________________________________________________________________
392 AliEMCAL * AliEMCALGetter:: EMCAL() const
394 // returns the EMCAL object
395 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
398 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
404 //____________________________________________________________________________
405 AliEMCALPID * AliEMCALGetter::PID()
408 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
411 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
416 //____________________________________________________________________________
417 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
419 // Returns EMCAL geometry
421 AliEMCALGeometry * rv = 0 ;
423 rv = EMCAL()->GetGeometry() ;
427 //____________________________________________________________________________
428 TClonesArray * AliEMCALGetter::Primaries()
430 // creates the Primaries container if needed
433 Info("Primaries", "Creating a new TClonesArray for primaries") ;
434 fPrimaries = new TClonesArray("TParticle", 1000) ;
439 //____________________________________________________________________________
440 void AliEMCALGetter::Print()
442 // Print usefull information about the getter
444 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
445 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
448 //____________________________________________________________________________
449 void AliEMCALGetter::ReadPrimaries()
451 // Read Primaries from Kinematics.root
453 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
455 // gets kine tree from the root file (Kinematics.root)
456 if ( ! rl->TreeK() ) // load treeK the first time
457 rl->LoadKinematics() ;
459 fNPrimaries = rl->Stack()->GetNtrack() ;
462 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
465 // first time creates the container
467 fPrimaries->Clear() ;
470 for (index = 0 ; index < fNPrimaries; index++) {
471 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
475 //____________________________________________________________________________
476 Int_t AliEMCALGetter::ReadTreeD()
481 // gets TreeD from the root file (EMCAL.SDigits.root)
482 if ( !IsLoaded("D") ) {
483 EmcalLoader()->LoadDigits("UPDATE") ;
484 EmcalLoader()->LoadDigitizer("UPDATE") ;
487 return Digits()->GetEntries() ;
490 //____________________________________________________________________________
491 Int_t AliEMCALGetter::ReadTreeH()
495 // gets TreeH from the root file (EMCAL.Hit.root)
496 if ( !IsLoaded("H") ) {
497 EmcalLoader()->LoadHits("UPDATE") ;
500 return Hits()->GetEntries() ;
503 //____________________________________________________________________________
504 Int_t AliEMCALGetter::ReadTreeR()
506 // Read the RecPoints
509 // gets TreeR from the root file (EMCAL.RecPoints.root)
510 if ( !IsLoaded("R") ) {
511 EmcalLoader()->LoadRecPoints("UPDATE") ;
512 EmcalLoader()->LoadClusterizer("UPDATE") ;
516 return ECARecPoints()->GetEntries() ;
519 //____________________________________________________________________________
520 Int_t AliEMCALGetter::ReadTreeT()
522 // Read the TrackSegments
525 // gets TreeT from the root file (EMCAL.TrackSegments.root)
526 if ( !IsLoaded("T") ) {
527 EmcalLoader()->LoadTracks("UPDATE") ;
528 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
532 return TrackSegments()->GetEntries() ;
534 //____________________________________________________________________________
535 Int_t AliEMCALGetter::ReadTreeP()
537 // Read the TrackSegments
540 // gets TreeT from the root file (EMCAL.TrackSegments.root)
541 if ( !IsLoaded("P") ) {
542 EmcalLoader()->LoadRecParticles("UPDATE") ;
543 EmcalLoader()->LoadPID("UPDATE") ;
547 return RecParticles()->GetEntries() ;
549 //____________________________________________________________________________
550 Int_t AliEMCALGetter::ReadTreeS()
555 // gets TreeS from the root file (EMCAL.SDigits.root)
556 if ( !IsLoaded("S") ) {
557 EmcalLoader()->LoadSDigits("UPDATE") ;
558 EmcalLoader()->LoadSDigitizer("UPDATE") ;
562 return SDigits()->GetEntries() ;
565 //____________________________________________________________________________
566 TClonesArray * AliEMCALGetter::SDigits()
568 // asks the Loader to return the Digits container
570 TClonesArray * rv = 0 ;
572 rv = EmcalLoader()->SDigits() ;
574 EmcalLoader()->MakeSDigitsArray() ;
575 rv = EmcalLoader()->SDigits() ;
580 //____________________________________________________________________________
581 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
583 AliEMCALSDigitizer * rv ;
584 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
587 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
592 //____________________________________________________________________________
593 TParticle * AliEMCALGetter::Secondary(const TParticle* p, const Int_t index) const
595 // Return first (index=1) or second (index=2) secondary particle of primary particle p
603 Int_t daughterIndex = p->GetDaughter(index-1) ;
604 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
605 return rl->GetAliRun()->Particle(daughterIndex) ;
611 //____________________________________________________________________________
612 void AliEMCALGetter::Track(const Int_t itrack)
614 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
616 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
618 if( !TreeH() ) // load treeH the first time
621 // first time create the container
622 TClonesArray * hits = Hits() ;
626 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
627 emcalbranch->SetAddress(&hits) ;
628 emcalbranch->GetEntry(itrack) ;
631 //____________________________________________________________________________
632 TTree * AliEMCALGetter::TreeD() const
635 rv = EmcalLoader()->TreeD() ;
637 EmcalLoader()->MakeTree("D");
638 rv = EmcalLoader()->TreeD() ;
644 //____________________________________________________________________________
645 TTree * AliEMCALGetter::TreeH() const
648 rv = EmcalLoader()->TreeH() ;
650 EmcalLoader()->MakeTree("H");
651 rv = EmcalLoader()->TreeH() ;
657 //____________________________________________________________________________
658 TTree * AliEMCALGetter::TreeR() const
661 rv = EmcalLoader()->TreeR() ;
663 EmcalLoader()->MakeTree("R");
664 rv = EmcalLoader()->TreeR() ;
670 //____________________________________________________________________________
671 TTree * AliEMCALGetter::TreeT() const
674 rv = EmcalLoader()->TreeT() ;
676 EmcalLoader()->MakeTree("T");
677 rv = EmcalLoader()->TreeT() ;
682 //____________________________________________________________________________
683 TTree * AliEMCALGetter::TreeP() const
686 rv = EmcalLoader()->TreeP() ;
688 EmcalLoader()->MakeTree("P");
689 rv = EmcalLoader()->TreeP() ;
695 //____________________________________________________________________________
696 TTree * AliEMCALGetter::TreeS() const
699 rv = EmcalLoader()->TreeS() ;
701 EmcalLoader()->MakeTree("S");
702 rv = EmcalLoader()->TreeS() ;
708 //____________________________________________________________________________
709 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
711 // checks if the version with the present name already exists in the same directory
715 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
716 TString version( rl->GetEventFolder()->GetName() ) ;
720 if ( opt == "sdigits") {
721 // add the version name to the root file name
722 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
723 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
724 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
725 if ( !(gSystem->AccessPathName(fileName)) ) {
726 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
729 EmcalLoader()->SetSDigitsFileName(fileName) ;
732 if ( opt == "digits") {
733 // add the version name to the root file name
734 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
735 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
736 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
737 if ( !(gSystem->AccessPathName(fileName)) ) {
738 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
741 EmcalLoader()->SetDigitsFileName(fileName) ;
748 //____________________________________________________________________________
749 UShort_t AliEMCALGetter::EventPattern(void) const
751 // Return the pattern (trigger bit register) of the beam-test event
753 // return fBTE->GetPattern() ;
757 //____________________________________________________________________________
758 Float_t AliEMCALGetter::BeamEnergy(void) const
760 // Return the beam energy of the beam-test event
762 // return fBTE->GetBeamEnergy() ;