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 AliPHOSAnalyser):
28 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ;
29 // for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
30 // AliPHOSRecParticle * 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 AliPHOSIndexToObject and make
38 //*-- systematic usage of TFolders without changing the interface
39 //////////////////////////////////////////////////////////////////////////////
41 // --- ROOT system ---
47 // --- Standard library ---
49 // --- AliRoot header files ---
50 #include "AliPHOSGetter.h"
52 #include "AliRunLoader.h"
54 #include "AliPHOSLoader.h"
55 #include "AliPHOSBeamTestEvent.h"
59 ClassImp(AliPHOSGetter)
61 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
62 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
63 Int_t AliPHOSGetter::fgDebug = 0;
65 // TFile * AliPHOSGetter::fgFile = 0 ;
67 //____________________________________________________________________________
68 AliPHOSGetter::AliPHOSGetter(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("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
79 if (rl->GetAliRun() == 0x0) {
81 gAlice = rl->GetAliRun(); // should be removed
84 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
86 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
88 fgPhosLoader->SetTitle(version);
91 // initialize data members
96 fESDFileName = "AliESDs.root" ;
100 //____________________________________________________________________________
101 AliPHOSGetter::~AliPHOSGetter()
104 delete fgPhosLoader ;
108 fPrimaries->Delete() ;
112 //____________________________________________________________________________
113 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
115 // Returns pointer to the Clusterizer task
116 AliPHOSClusterizer * rv ;
117 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
120 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
125 //____________________________________________________________________________
126 TObjArray * AliPHOSGetter::CpvRecPoints()
128 // asks the Loader to return the CPV RecPoints container
132 rv = PhosLoader()->CpvRecPoints() ;
134 PhosLoader()->MakeRecPointsArray() ;
135 rv = PhosLoader()->CpvRecPoints() ;
140 //____________________________________________________________________________
141 TClonesArray * AliPHOSGetter::Digits()
143 // asks the Loader to return the Digits container
145 TClonesArray * rv = 0 ;
146 rv = PhosLoader()->Digits() ;
149 PhosLoader()->MakeDigitsArray() ;
150 rv = PhosLoader()->Digits() ;
155 //____________________________________________________________________________
156 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
158 // Returns pointer to the Digitizer task
159 AliPHOSDigitizer * rv ;
160 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
163 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
169 //____________________________________________________________________________
170 TObjArray * AliPHOSGetter::EmcRecPoints()
172 // asks the Loader to return the EMC RecPoints container
176 rv = PhosLoader()->EmcRecPoints() ;
178 PhosLoader()->MakeRecPointsArray() ;
179 rv = PhosLoader()->EmcRecPoints() ;
184 //____________________________________________________________________________
185 TClonesArray * AliPHOSGetter::TrackSegments()
187 // asks the Loader to return the TrackSegments container
189 TClonesArray * rv = 0 ;
191 rv = PhosLoader()->TrackSegments() ;
193 PhosLoader()->MakeTrackSegmentsArray() ;
194 rv = PhosLoader()->TrackSegments() ;
199 //____________________________________________________________________________
200 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
202 // Returns pointer to the TrackSegmentMaker task
203 AliPHOSTrackSegmentMaker * rv ;
204 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
207 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
212 //____________________________________________________________________________
213 TClonesArray * AliPHOSGetter::RecParticles()
215 // asks the Loader to return the TrackSegments container
217 TClonesArray * rv = 0 ;
219 rv = PhosLoader()->RecParticles() ;
221 PhosLoader()->MakeRecParticlesArray() ;
222 rv = PhosLoader()->RecParticles() ;
226 //____________________________________________________________________________
227 void AliPHOSGetter::Event(const Int_t event, const char* opt)
229 // Reads the content of all Tree's S, D and R
231 if ( event >= MaxEvent() ) {
232 Error("Event", "%d not found in TreeE !", event) ;
236 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
238 // checks if we are dealing with test-beam data
239 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
242 fBTE = new AliPHOSBeamTestEvent() ;
243 btb->SetAddress(&fBTE) ;
244 btb->GetEntry(event) ;
253 // Loads the type of object(s) requested
255 rl->GetEvent(event) ;
257 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
266 if( strstr(opt,"D") )
269 if( strstr(opt,"R") )
272 if( strstr(opt,"T") )
275 if( strstr(opt,"P") )
278 // if( strstr(opt,"Q") )
284 //____________________________________________________________________________
285 Int_t AliPHOSGetter::EventNumber() const
287 // return the current event number
288 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
289 return static_cast<Int_t>(rl->GetEventNumber()) ;
292 //____________________________________________________________________________
293 TClonesArray * AliPHOSGetter::Hits()
295 // asks the loader to return the Hits container
297 TClonesArray * rv = 0 ;
299 rv = PhosLoader()->Hits() ;
301 PhosLoader()->LoadHits("read");
302 rv = PhosLoader()->Hits() ;
307 //____________________________________________________________________________
308 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
310 // Creates and returns the pointer of the unique instance
311 // Must be called only when the environment has changed
313 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
315 if(!fgObjGetter){ // first time the getter is called
316 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
318 else { // the getter has been called previously
319 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
320 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
321 // check if the file is already open
322 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
325 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
327 else { // the file is already open check the version name
328 TString currentVersionName = rl->GetEventFolder()->GetName() ;
329 TString newVersionName(version) ;
330 if (currentVersionName == newVersionName)
332 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
334 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
339 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
342 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
350 //____________________________________________________________________________
351 AliPHOSGetter * AliPHOSGetter::Instance()
353 // Returns the pointer of the unique instance already defined
355 if(!fgObjGetter && fgDebug)
356 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
362 //____________________________________________________________________________
363 Int_t AliPHOSGetter::MaxEvent() const
365 // returns the number of events in the run (from TE)
367 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
368 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
371 //____________________________________________________________________________
372 TParticle * AliPHOSGetter::Primary(Int_t index) const
374 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
375 return rl->Stack()->Particle(index) ;
378 //____________________________________________________________________________
379 AliPHOS * AliPHOSGetter:: PHOS() const
381 // returns the PHOS object
382 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
385 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
391 //____________________________________________________________________________
392 AliPHOSPID * AliPHOSGetter::PID()
394 // Returns pointer to the PID task
396 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
399 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
404 //____________________________________________________________________________
405 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
407 // Returns PHOS geometry
409 AliPHOSGeometry * rv = 0 ;
411 rv = PHOS()->GetGeometry() ;
415 //____________________________________________________________________________
416 TClonesArray * AliPHOSGetter::Primaries()
418 // creates the Primaries container if needed
421 Info("Primaries", "Creating a new TClonesArray for primaries") ;
422 fPrimaries = new TClonesArray("TParticle", 1000) ;
427 //____________________________________________________________________________
428 void AliPHOSGetter::Print()
430 // Print usefull information about the getter
432 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
433 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
436 //____________________________________________________________________________
437 void AliPHOSGetter::ReadPrimaries()
439 // Read Primaries from Kinematics.root
441 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
443 // gets kine tree from the root file (Kinematics.root)
444 if ( ! rl->TreeK() ) // load treeK the first time
445 rl->LoadKinematics() ;
447 fNPrimaries = rl->Stack()->GetNtrack() ;
450 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
453 // first time creates the container
455 fPrimaries->Clear() ;
458 for (index = 0 ; index < fNPrimaries; index++) {
459 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
463 //____________________________________________________________________________
464 AliESD * AliPHOSGetter::ESD(Int_t event)
470 TString esdEvent("ESD") ;
472 AliESD * esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ;
476 //____________________________________________________________________________
477 Bool_t AliPHOSGetter::OpenESDFile(TString name)
480 fESDFileName = name ;
482 fESDFile = new TFile(fESDFileName) ;
483 else if (fESDFile->IsOpen()) {
485 fESDFile = TFile::Open(fESDFileName) ;
487 if (!fESDFile->IsOpen())
492 //____________________________________________________________________________
493 Int_t AliPHOSGetter::ReadTreeD()
498 // gets TreeD from the root file (PHOS.SDigits.root)
499 if ( !IsLoaded("D") ) {
500 PhosLoader()->LoadDigits("UPDATE") ;
501 PhosLoader()->LoadDigitizer("UPDATE") ;
504 return Digits()->GetEntries() ;
507 //____________________________________________________________________________
508 Int_t AliPHOSGetter::ReadTreeH()
512 // gets TreeH from the root file (PHOS.Hit.root)
513 if ( !IsLoaded("H") ) {
514 PhosLoader()->LoadHits("UPDATE") ;
517 return Hits()->GetEntries() ;
520 //____________________________________________________________________________
521 Int_t AliPHOSGetter::ReadTreeR()
523 // Read the RecPoints
526 // gets TreeR from the root file (PHOS.RecPoints.root)
527 if ( !IsLoaded("R") ) {
528 PhosLoader()->LoadRecPoints("UPDATE") ;
529 PhosLoader()->LoadClusterizer("UPDATE") ;
533 return EmcRecPoints()->GetEntries() ;
536 //____________________________________________________________________________
537 Int_t AliPHOSGetter::ReadTreeT()
539 // Read the TrackSegments
542 // gets TreeT from the root file (PHOS.TrackSegments.root)
543 if ( !IsLoaded("T") ) {
544 PhosLoader()->LoadTracks("UPDATE") ;
545 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
549 return TrackSegments()->GetEntries() ;
551 //____________________________________________________________________________
552 Int_t AliPHOSGetter::ReadTreeP()
554 // Read the TrackSegments
557 // gets TreeT from the root file (PHOS.TrackSegments.root)
558 if ( !IsLoaded("P") ) {
559 PhosLoader()->LoadRecParticles("UPDATE") ;
560 PhosLoader()->LoadPID("UPDATE") ;
564 return RecParticles()->GetEntries() ;
566 //____________________________________________________________________________
567 Int_t AliPHOSGetter::ReadTreeS()
572 // gets TreeS from the root file (PHOS.SDigits.root)
573 if ( !IsLoaded("S") ) {
574 PhosLoader()->LoadSDigits("UPDATE") ;
575 PhosLoader()->LoadSDigitizer("UPDATE") ;
579 return SDigits()->GetEntries() ;
582 //____________________________________________________________________________
583 TClonesArray * AliPHOSGetter::SDigits()
585 // asks the Loader to return the Digits container
587 TClonesArray * rv = 0 ;
589 rv = PhosLoader()->SDigits() ;
591 PhosLoader()->MakeSDigitsArray() ;
592 rv = PhosLoader()->SDigits() ;
597 //____________________________________________________________________________
598 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
600 // Returns pointer to the SDigitizer task
601 AliPHOSSDigitizer * rv ;
602 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
605 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
610 //____________________________________________________________________________
611 TParticle * AliPHOSGetter::Secondary(const TParticle* p, const Int_t index) const
613 // Return first (index=1) or second (index=2) secondary particle of primary particle p
621 Int_t daughterIndex = p->GetDaughter(index-1) ;
622 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
623 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
629 //____________________________________________________________________________
630 void AliPHOSGetter::Track(const Int_t itrack)
632 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
634 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
636 if( !TreeH() ) // load treeH the first time
639 // first time create the container
640 TClonesArray * hits = Hits() ;
644 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
645 phosbranch->SetAddress(&hits) ;
646 phosbranch->GetEntry(itrack) ;
649 //____________________________________________________________________________
650 TTree * AliPHOSGetter::TreeD() const
652 // Returns pointer to the Digits Tree
654 rv = PhosLoader()->TreeD() ;
656 PhosLoader()->MakeTree("D");
657 rv = PhosLoader()->TreeD() ;
663 //____________________________________________________________________________
664 TTree * AliPHOSGetter::TreeH() const
666 // Returns pointer to the Hits Tree
668 rv = PhosLoader()->TreeH() ;
670 PhosLoader()->MakeTree("H");
671 rv = PhosLoader()->TreeH() ;
677 //____________________________________________________________________________
678 TTree * AliPHOSGetter::TreeR() const
680 // Returns pointer to the RecPoints Tree
682 rv = PhosLoader()->TreeR() ;
684 PhosLoader()->MakeTree("R");
685 rv = PhosLoader()->TreeR() ;
691 //____________________________________________________________________________
692 TTree * AliPHOSGetter::TreeT() const
694 // Returns pointer to the TrackSegments Tree
696 rv = PhosLoader()->TreeT() ;
698 PhosLoader()->MakeTree("T");
699 rv = PhosLoader()->TreeT() ;
704 //____________________________________________________________________________
705 TTree * AliPHOSGetter::TreeP() const
707 // Returns pointer to the RecParticles Tree
709 rv = PhosLoader()->TreeP() ;
711 PhosLoader()->MakeTree("P");
712 rv = PhosLoader()->TreeP() ;
718 //____________________________________________________________________________
719 TTree * AliPHOSGetter::TreeS() const
721 // Returns pointer to the SDigits Tree
723 rv = PhosLoader()->TreeS() ;
725 PhosLoader()->MakeTree("S");
726 rv = PhosLoader()->TreeS() ;
732 //____________________________________________________________________________
733 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
735 // checks if the version with the present name already exists in the same directory
739 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
740 TString version( rl->GetEventFolder()->GetName() ) ;
744 if ( opt == "sdigits") {
745 // add the version name to the root file name
746 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
747 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
748 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
749 if ( !(gSystem->AccessPathName(fileName)) ) {
750 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
753 PhosLoader()->SetSDigitsFileName(fileName) ;
756 if ( opt == "digits") {
757 // add the version name to the root file name
758 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
759 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
760 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
761 if ( !(gSystem->AccessPathName(fileName)) ) {
762 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
765 PhosLoader()->SetDigitsFileName(fileName) ;
772 //____________________________________________________________________________
773 UShort_t AliPHOSGetter::EventPattern(void) const
775 // Return the pattern (trigger bit register) of the beam-test event
777 return fBTE->GetPattern() ;
781 //____________________________________________________________________________
782 Float_t AliPHOSGetter::BeamEnergy(void) const
784 // Return the beam energy of the beam-test event
786 return fBTE->GetBeamEnergy() ;