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"
60 ClassImp(AliPHOSGetter)
62 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
63 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
64 Int_t AliPHOSGetter::fgDebug = 0;
66 // TFile * AliPHOSGetter::fgFile = 0 ;
68 //____________________________________________________________________________
69 AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
71 // ctor only called by Instance()
73 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
75 rl = AliRunLoader::Open(headerFile, version, openingOption);
77 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
80 if (rl->GetAliRun() == 0x0) {
82 gAlice = rl->GetAliRun(); // should be removed
85 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
87 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
89 fgPhosLoader->SetTitle(version);
92 // initialize data members
99 //____________________________________________________________________________
100 AliPHOSGetter::~AliPHOSGetter()
103 delete fgPhosLoader ;
107 fPrimaries->Delete() ;
111 //____________________________________________________________________________
112 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
114 AliPHOSClusterizer * rv ;
115 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
118 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
123 //____________________________________________________________________________
124 TObjArray * AliPHOSGetter::CpvRecPoints()
126 // asks the Loader to return the CPV RecPoints container
130 rv = PhosLoader()->CpvRecPoints() ;
132 PhosLoader()->MakeRecPointsArray() ;
133 rv = PhosLoader()->CpvRecPoints() ;
138 //____________________________________________________________________________
139 TClonesArray * AliPHOSGetter::Digits()
141 // asks the Loader to return the Digits container
143 TClonesArray * rv = 0 ;
144 rv = PhosLoader()->Digits() ;
147 PhosLoader()->MakeDigitsArray() ;
148 rv = PhosLoader()->Digits() ;
153 //____________________________________________________________________________
154 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
156 AliPHOSDigitizer * rv ;
157 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
160 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
166 //____________________________________________________________________________
167 TObjArray * AliPHOSGetter::EmcRecPoints()
169 // asks the Loader to return the EMC RecPoints container
173 rv = PhosLoader()->EmcRecPoints() ;
175 PhosLoader()->MakeRecPointsArray() ;
176 rv = PhosLoader()->EmcRecPoints() ;
181 //____________________________________________________________________________
182 TClonesArray * AliPHOSGetter::TrackSegments()
184 // asks the Loader to return the TrackSegments container
186 TClonesArray * rv = 0 ;
188 rv = PhosLoader()->TrackSegments() ;
190 PhosLoader()->MakeTrackSegmentsArray() ;
191 rv = PhosLoader()->TrackSegments() ;
196 //____________________________________________________________________________
197 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
199 AliPHOSTrackSegmentMaker * rv ;
200 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
203 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
208 //____________________________________________________________________________
209 TClonesArray * AliPHOSGetter::RecParticles()
211 // asks the Loader to return the TrackSegments container
213 TClonesArray * rv = 0 ;
215 rv = PhosLoader()->RecParticles() ;
217 PhosLoader()->MakeRecParticlesArray() ;
218 rv = PhosLoader()->RecParticles() ;
222 //____________________________________________________________________________
223 void AliPHOSGetter::Event(const Int_t event, const char* opt)
225 // Reads the content of all Tree's S, D and R
227 if ( event >= MaxEvent() ) {
228 Error("Event", "%d not found in TreeE !", event) ;
232 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
234 // checks if we are dealing with test-beam data
235 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
238 fBTE = new AliPHOSBeamTestEvent() ;
239 btb->SetAddress(&fBTE) ;
240 btb->GetEntry(event) ;
249 // Loads the type of object(s) requested
251 rl->GetEvent(event) ;
253 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
262 if( strstr(opt,"D") )
265 if( strstr(opt,"R") )
268 if( strstr(opt,"T") )
271 if( strstr(opt,"P") )
274 // if( strstr(opt,"Q") )
280 //____________________________________________________________________________
281 Int_t AliPHOSGetter::EventNumber() const
283 // return the current event number
284 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
285 return static_cast<Int_t>(rl->GetEventNumber()) ;
288 //____________________________________________________________________________
289 TClonesArray * AliPHOSGetter::Hits()
291 // asks the loader to return the Hits container
293 TClonesArray * rv = 0 ;
295 rv = PhosLoader()->Hits() ;
297 PhosLoader()->LoadHits("read");
298 rv = PhosLoader()->Hits() ;
303 //____________________________________________________________________________
304 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
306 // Creates and returns the pointer of the unique instance
307 // Must be called only when the environment has changed
309 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
311 if(!fgObjGetter){ // first time the getter is called
312 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
314 else { // the getter has been called previously
315 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
316 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
317 // check if the file is already open
318 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
321 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
323 else { // the file is already open check the version name
324 TString currentVersionName = rl->GetEventFolder()->GetName() ;
325 TString newVersionName(version) ;
326 if (currentVersionName == newVersionName)
328 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
330 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
335 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
338 ::Error("Instance", "Failed to create the PHOS Getter object") ;
346 //____________________________________________________________________________
347 AliPHOSGetter * AliPHOSGetter::Instance()
349 // Returns the pointer of the unique instance already defined
352 ::Error("Instance", "Getter not initialized") ;
358 //____________________________________________________________________________
359 Int_t AliPHOSGetter::MaxEvent() const
361 // returns the number of events in the run (from TE)
363 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
364 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
367 //____________________________________________________________________________
368 TParticle * AliPHOSGetter::Primary(Int_t index) const
370 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
371 return rl->Stack()->Particle(index) ;
374 //____________________________________________________________________________
375 AliPHOS * AliPHOSGetter:: PHOS() const
377 // returns the PHOS object
378 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
381 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
387 //____________________________________________________________________________
388 AliPHOSPID * AliPHOSGetter::PID()
391 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
394 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
399 //____________________________________________________________________________
400 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
402 // Returns PHOS geometry
404 AliPHOSGeometry * rv = 0 ;
406 rv = PHOS()->GetGeometry() ;
410 //____________________________________________________________________________
411 TClonesArray * AliPHOSGetter::Primaries()
413 // creates the Primaries container if needed
416 Info("Primaries", "Creating a new TClonesArray for primaries") ;
417 fPrimaries = new TClonesArray("TParticle", 1000) ;
422 //____________________________________________________________________________
423 void AliPHOSGetter::Print()
425 // Print usefull information about the getter
427 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
428 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
431 //____________________________________________________________________________
432 void AliPHOSGetter::ReadPrimaries()
434 // Read Primaries from Kinematics.root
436 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
438 // gets kine tree from the root file (Kinematics.root)
439 if ( ! rl->TreeK() ) // load treeK the first time
440 rl->LoadKinematics() ;
442 fNPrimaries = rl->Stack()->GetNtrack() ;
445 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
448 // first time creates the container
450 fPrimaries->Clear() ;
453 for (index = 0 ; index < fNPrimaries; index++) {
454 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
458 //____________________________________________________________________________
459 Int_t AliPHOSGetter::ReadTreeD()
464 // gets TreeD from the root file (PHOS.SDigits.root)
465 if ( !IsLoaded("D") ) {
466 PhosLoader()->LoadDigits("UPDATE") ;
467 PhosLoader()->LoadDigitizer("UPDATE") ;
470 return Digits()->GetEntries() ;
473 //____________________________________________________________________________
474 Int_t AliPHOSGetter::ReadTreeH()
478 // gets TreeH from the root file (PHOS.Hit.root)
479 if ( !IsLoaded("H") ) {
480 PhosLoader()->LoadHits("UPDATE") ;
483 return Hits()->GetEntries() ;
486 //____________________________________________________________________________
487 Int_t AliPHOSGetter::ReadTreeR()
489 // Read the RecPoints
492 // gets TreeR from the root file (PHOS.RecPoints.root)
493 if ( !IsLoaded("R") ) {
494 PhosLoader()->LoadRecPoints("UPDATE") ;
495 PhosLoader()->LoadClusterizer("UPDATE") ;
499 return EmcRecPoints()->GetEntries() ;
502 //____________________________________________________________________________
503 Int_t AliPHOSGetter::ReadTreeT()
505 // Read the TrackSegments
508 // gets TreeT from the root file (PHOS.TrackSegments.root)
509 if ( !IsLoaded("T") ) {
510 PhosLoader()->LoadTracks("UPDATE") ;
511 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
515 return TrackSegments()->GetEntries() ;
517 //____________________________________________________________________________
518 Int_t AliPHOSGetter::ReadTreeP()
520 // Read the TrackSegments
523 // gets TreeT from the root file (PHOS.TrackSegments.root)
524 if ( !IsLoaded("P") ) {
525 PhosLoader()->LoadRecParticles("UPDATE") ;
526 PhosLoader()->LoadPID("UPDATE") ;
530 return RecParticles()->GetEntries() ;
532 //____________________________________________________________________________
533 Int_t AliPHOSGetter::ReadTreeS()
538 // gets TreeS from the root file (PHOS.SDigits.root)
539 if ( !IsLoaded("S") ) {
540 PhosLoader()->LoadSDigits("UPDATE") ;
541 PhosLoader()->LoadSDigitizer("UPDATE") ;
545 return SDigits()->GetEntries() ;
548 //____________________________________________________________________________
549 TClonesArray * AliPHOSGetter::SDigits()
551 // asks the Loader to return the Digits container
553 TClonesArray * rv = 0 ;
555 rv = PhosLoader()->SDigits() ;
557 PhosLoader()->MakeSDigitsArray() ;
558 rv = PhosLoader()->SDigits() ;
563 //____________________________________________________________________________
564 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
566 AliPHOSSDigitizer * rv ;
567 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
570 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
575 //____________________________________________________________________________
576 TParticle * AliPHOSGetter::Secondary(const TParticle* p, const Int_t index) const
578 // Return first (index=1) or second (index=2) secondary particle of primary particle p
586 Int_t daughterIndex = p->GetDaughter(index-1) ;
587 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
588 return rl->GetAliRun()->Particle(daughterIndex) ;
594 //____________________________________________________________________________
595 void AliPHOSGetter::Track(const Int_t itrack)
597 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
599 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
601 if( !TreeH() ) // load treeH the first time
604 // first time create the container
605 TClonesArray * hits = Hits() ;
609 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
610 phosbranch->SetAddress(&hits) ;
611 phosbranch->GetEntry(itrack) ;
614 //____________________________________________________________________________
615 TTree * AliPHOSGetter::TreeD() const
618 rv = PhosLoader()->TreeD() ;
620 PhosLoader()->MakeTree("D");
621 rv = PhosLoader()->TreeD() ;
627 //____________________________________________________________________________
628 TTree * AliPHOSGetter::TreeH() const
631 rv = PhosLoader()->TreeH() ;
633 PhosLoader()->MakeTree("H");
634 rv = PhosLoader()->TreeH() ;
640 //____________________________________________________________________________
641 TTree * AliPHOSGetter::TreeR() const
644 rv = PhosLoader()->TreeR() ;
646 PhosLoader()->MakeTree("R");
647 rv = PhosLoader()->TreeR() ;
653 //____________________________________________________________________________
654 TTree * AliPHOSGetter::TreeT() const
657 rv = PhosLoader()->TreeT() ;
659 PhosLoader()->MakeTree("T");
660 rv = PhosLoader()->TreeT() ;
665 //____________________________________________________________________________
666 TTree * AliPHOSGetter::TreeP() const
669 rv = PhosLoader()->TreeP() ;
671 PhosLoader()->MakeTree("P");
672 rv = PhosLoader()->TreeP() ;
678 //____________________________________________________________________________
679 TTree * AliPHOSGetter::TreeS() const
682 rv = PhosLoader()->TreeS() ;
684 PhosLoader()->MakeTree("S");
685 rv = PhosLoader()->TreeS() ;
691 //____________________________________________________________________________
692 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
694 // checks if the version with the present name already exists in the same directory
698 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
699 TString version( rl->GetEventFolder()->GetName() ) ;
703 if ( opt == "sdigits") {
704 // add the version name to the root file name
705 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
706 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
707 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
708 if ( !(gSystem->AccessPathName(fileName)) ) {
709 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
712 PhosLoader()->SetSDigitsFileName(fileName) ;
715 if ( opt == "digits") {
716 // add the version name to the root file name
717 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
718 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
719 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
720 if ( !(gSystem->AccessPathName(fileName)) ) {
721 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
724 PhosLoader()->SetDigitsFileName(fileName) ;
731 //____________________________________________________________________________
732 UShort_t AliPHOSGetter::EventPattern(void) const
734 // Return the pattern (trigger bit register) of the beam-test event
736 return fBTE->GetPattern() ;
740 //____________________________________________________________________________
741 Float_t AliPHOSGetter::BeamEnergy(void) const
743 // Return the beam energy of the beam-test event
745 return fBTE->GetBeamEnergy() ;