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 ---
48 // --- Standard library ---
50 // --- AliRoot header files ---
52 #include "AliPHOSGetter.h"
53 #include "AliRunLoader.h"
55 #include "AliPHOSLoader.h"
56 // #include "AliPHOSRaw2Digits.h"
57 //#include "AliPHOSCalibrationDB.h"
58 #include "AliPHOSBeamTestEvent.h"
61 ClassImp(AliPHOSGetter)
63 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
64 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
65 Int_t AliPHOSGetter::fgDebug = 0;
67 // TFile * AliPHOSGetter::fgFile = 0 ;
69 //____________________________________________________________________________
70 AliPHOSGetter::AliPHOSGetter(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("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
81 if (rl->GetAliRun() == 0x0) {
83 gAlice = rl->GetAliRun(); // should be removed
86 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
88 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
90 fgPhosLoader->SetTitle(version);
93 // initialize data members
100 //____________________________________________________________________________
101 AliPHOSGetter::~AliPHOSGetter()
104 delete fgPhosLoader ;
108 fPrimaries->Delete() ;
112 //____________________________________________________________________________
113 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
115 AliPHOSClusterizer * rv ;
116 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
119 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
124 //____________________________________________________________________________
125 TObjArray * AliPHOSGetter::CpvRecPoints()
127 // asks the Loader to return the CPV RecPoints container
131 rv = PhosLoader()->CpvRecPoints() ;
133 PhosLoader()->MakeRecPointsArray() ;
134 rv = PhosLoader()->CpvRecPoints() ;
139 //____________________________________________________________________________
140 TClonesArray * AliPHOSGetter::Digits()
142 // asks the Loader to return the Digits container
144 TClonesArray * rv = 0 ;
145 rv = PhosLoader()->Digits() ;
148 PhosLoader()->MakeDigitsArray() ;
149 rv = PhosLoader()->Digits() ;
154 //____________________________________________________________________________
155 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
157 AliPHOSDigitizer * rv ;
158 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
161 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
167 //____________________________________________________________________________
168 TObjArray * AliPHOSGetter::EmcRecPoints()
170 // asks the Loader to return the EMC RecPoints container
174 rv = PhosLoader()->EmcRecPoints() ;
176 PhosLoader()->MakeRecPointsArray() ;
177 rv = PhosLoader()->EmcRecPoints() ;
182 //____________________________________________________________________________
183 TClonesArray * AliPHOSGetter::TrackSegments()
185 // asks the Loader to return the TrackSegments container
187 TClonesArray * rv = 0 ;
189 rv = PhosLoader()->TrackSegments() ;
191 PhosLoader()->MakeTrackSegmentsArray() ;
192 rv = PhosLoader()->TrackSegments() ;
197 //____________________________________________________________________________
198 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
200 AliPHOSTrackSegmentMaker * rv ;
201 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
204 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
209 //____________________________________________________________________________
210 TClonesArray * AliPHOSGetter::RecParticles()
212 // asks the Loader to return the TrackSegments container
214 TClonesArray * rv = 0 ;
216 rv = PhosLoader()->RecParticles() ;
218 PhosLoader()->MakeRecParticlesArray() ;
219 rv = PhosLoader()->RecParticles() ;
223 //____________________________________________________________________________
224 void AliPHOSGetter::Event(const Int_t event, const char* opt)
226 // Reads the content of all Tree's S, D and R
228 if ( event >= MaxEvent() ) {
229 Error("Event", "%d not found in TreeE !", event) ;
233 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
235 // checks if we are dealing with test-beam data
236 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
239 fBTE = new AliPHOSBeamTestEvent() ;
240 btb->SetAddress(&fBTE) ;
241 btb->GetEntry(event) ;
250 // Loads the type of object(s) requested
252 rl->GetEvent(event) ;
254 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
263 if( strstr(opt,"D") )
266 if( strstr(opt,"R") )
269 if( strstr(opt,"T") )
272 if( strstr(opt,"P") )
275 // if( strstr(opt,"Q") )
281 //____________________________________________________________________________
282 Int_t AliPHOSGetter::EventNumber() const
284 // return the current event number
285 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
286 return static_cast<Int_t>(rl->GetEventNumber()) ;
289 //____________________________________________________________________________
290 TClonesArray * AliPHOSGetter::Hits()
292 // asks the loader to return the Hits container
294 TClonesArray * rv = 0 ;
296 rv = PhosLoader()->Hits() ;
298 PhosLoader()->LoadHits("read");
299 rv = PhosLoader()->Hits() ;
304 //____________________________________________________________________________
305 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
307 // Creates and returns the pointer of the unique instance
308 // Must be called only when the environment has changed
310 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
312 if(!fgObjGetter){ // first time the getter is called
313 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
315 else { // the getter has been called previously
316 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
317 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
318 // check if the file is already open
319 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
322 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
324 else { // the file is already open check the version name
325 TString currentVersionName = rl->GetEventFolder()->GetName() ;
326 TString newVersionName(version) ;
327 if (currentVersionName == newVersionName)
329 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
331 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
336 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
339 ::Error("Instance", "Failed to create the PHOS Getter object") ;
347 //____________________________________________________________________________
348 AliPHOSGetter * AliPHOSGetter::Instance()
350 // Returns the pointer of the unique instance already defined
353 ::Error("Instance", "Getter not initialized") ;
359 //____________________________________________________________________________
360 Int_t AliPHOSGetter::MaxEvent() const
362 // returns the number of events in the run (from TE)
364 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
365 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
368 //____________________________________________________________________________
369 TParticle * AliPHOSGetter::Primary(Int_t index) const
371 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
372 return rl->Stack()->Particle(index) ;
375 //____________________________________________________________________________
376 AliPHOS * AliPHOSGetter:: PHOS() const
378 // returns the PHOS object
379 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
382 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
388 //____________________________________________________________________________
389 AliPHOSPID * AliPHOSGetter::PID()
392 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
395 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
400 //____________________________________________________________________________
401 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
403 // Returns PHOS geometry
405 AliPHOSGeometry * rv = 0 ;
407 rv = PHOS()->GetGeometry() ;
411 //____________________________________________________________________________
412 TClonesArray * AliPHOSGetter::Primaries()
414 // creates the Primaries container if needed
417 Info("Primaries", "Creating a new TClonesArray for primaries") ;
418 fPrimaries = new TClonesArray("TParticle", 1000) ;
423 //____________________________________________________________________________
424 void AliPHOSGetter::Print()
426 // Print usefull information about the getter
428 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
429 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
432 //____________________________________________________________________________
433 void AliPHOSGetter::ReadPrimaries()
435 // Read Primaries from Kinematics.root
437 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
439 // gets kine tree from the root file (Kinematics.root)
440 if ( ! rl->TreeK() ) // load treeK the first time
441 rl->LoadKinematics() ;
443 fNPrimaries = rl->Stack()->GetNtrack() ;
446 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
449 // first time creates the container
451 fPrimaries->Clear() ;
454 for (index = 0 ; index < fNPrimaries; index++) {
455 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
459 //____________________________________________________________________________
460 Int_t AliPHOSGetter::ReadTreeD()
465 // gets TreeD from the root file (PHOS.SDigits.root)
466 if ( !IsLoaded("D") ) {
467 PhosLoader()->LoadDigits("UPDATE") ;
468 PhosLoader()->LoadDigitizer("UPDATE") ;
471 return Digits()->GetEntries() ;
474 //____________________________________________________________________________
475 Int_t AliPHOSGetter::ReadTreeH()
479 // gets TreeH from the root file (PHOS.Hit.root)
480 if ( !IsLoaded("H") ) {
481 PhosLoader()->LoadHits("UPDATE") ;
484 return Hits()->GetEntries() ;
487 //____________________________________________________________________________
488 Int_t AliPHOSGetter::ReadTreeR()
490 // Read the RecPoints
493 // gets TreeR from the root file (PHOS.RecPoints.root)
494 if ( !IsLoaded("R") ) {
495 PhosLoader()->LoadRecPoints("UPDATE") ;
496 PhosLoader()->LoadClusterizer("UPDATE") ;
500 return EmcRecPoints()->GetEntries() ;
503 //____________________________________________________________________________
504 Int_t AliPHOSGetter::ReadTreeT()
506 // Read the TrackSegments
509 // gets TreeT from the root file (PHOS.TrackSegments.root)
510 if ( !IsLoaded("T") ) {
511 PhosLoader()->LoadTracks("UPDATE") ;
512 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
516 return TrackSegments()->GetEntries() ;
518 //____________________________________________________________________________
519 Int_t AliPHOSGetter::ReadTreeP()
521 // Read the TrackSegments
524 // gets TreeT from the root file (PHOS.TrackSegments.root)
525 if ( !IsLoaded("P") ) {
526 PhosLoader()->LoadRecParticles("UPDATE") ;
527 PhosLoader()->LoadPID("UPDATE") ;
531 return RecParticles()->GetEntries() ;
533 //____________________________________________________________________________
534 Int_t AliPHOSGetter::ReadTreeS()
539 // gets TreeS from the root file (PHOS.SDigits.root)
540 if ( !IsLoaded("S") ) {
541 PhosLoader()->LoadSDigits("UPDATE") ;
542 PhosLoader()->LoadSDigitizer("UPDATE") ;
546 return SDigits()->GetEntries() ;
549 //____________________________________________________________________________
550 TClonesArray * AliPHOSGetter::SDigits()
552 // asks the Loader to return the Digits container
554 TClonesArray * rv = 0 ;
556 rv = PhosLoader()->SDigits() ;
558 PhosLoader()->MakeSDigitsArray() ;
559 rv = PhosLoader()->SDigits() ;
564 //____________________________________________________________________________
565 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
567 AliPHOSSDigitizer * rv ;
568 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
571 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
576 //____________________________________________________________________________
577 TParticle * AliPHOSGetter::Secondary(const TParticle* p, const 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(PhosLoader()->GetTitle());
589 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
595 //____________________________________________________________________________
596 void AliPHOSGetter::Track(const Int_t itrack)
598 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
600 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
602 if( !TreeH() ) // load treeH the first time
605 // first time create the container
606 TClonesArray * hits = Hits() ;
610 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
611 phosbranch->SetAddress(&hits) ;
612 phosbranch->GetEntry(itrack) ;
615 //____________________________________________________________________________
616 TTree * AliPHOSGetter::TreeD() const
619 rv = PhosLoader()->TreeD() ;
621 PhosLoader()->MakeTree("D");
622 rv = PhosLoader()->TreeD() ;
628 //____________________________________________________________________________
629 TTree * AliPHOSGetter::TreeH() const
632 rv = PhosLoader()->TreeH() ;
634 PhosLoader()->MakeTree("H");
635 rv = PhosLoader()->TreeH() ;
641 //____________________________________________________________________________
642 TTree * AliPHOSGetter::TreeR() const
645 rv = PhosLoader()->TreeR() ;
647 PhosLoader()->MakeTree("R");
648 rv = PhosLoader()->TreeR() ;
654 //____________________________________________________________________________
655 TTree * AliPHOSGetter::TreeT() const
658 rv = PhosLoader()->TreeT() ;
660 PhosLoader()->MakeTree("T");
661 rv = PhosLoader()->TreeT() ;
666 //____________________________________________________________________________
667 TTree * AliPHOSGetter::TreeP() const
670 rv = PhosLoader()->TreeP() ;
672 PhosLoader()->MakeTree("P");
673 rv = PhosLoader()->TreeP() ;
679 //____________________________________________________________________________
680 TTree * AliPHOSGetter::TreeS() const
683 rv = PhosLoader()->TreeS() ;
685 PhosLoader()->MakeTree("S");
686 rv = PhosLoader()->TreeS() ;
692 //____________________________________________________________________________
693 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
695 // checks if the version with the present name already exists in the same directory
699 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
700 TString version( rl->GetEventFolder()->GetName() ) ;
704 if ( opt == "sdigits") {
705 // add the version name to the root file name
706 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
707 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
708 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
709 if ( !(gSystem->AccessPathName(fileName)) ) {
710 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
713 PhosLoader()->SetSDigitsFileName(fileName) ;
716 if ( opt == "digits") {
717 // add the version name to the root file name
718 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
719 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
720 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
721 if ( !(gSystem->AccessPathName(fileName)) ) {
722 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
725 PhosLoader()->SetDigitsFileName(fileName) ;
732 //____________________________________________________________________________
733 UShort_t AliPHOSGetter::EventPattern(void) const
735 // Return the pattern (trigger bit register) of the beam-test event
737 return fBTE->GetPattern() ;
741 //____________________________________________________________________________
742 Float_t AliPHOSGetter::BeamEnergy(void) const
744 // Return the beam energy of the beam-test event
746 return fBTE->GetBeamEnergy() ;