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"
58 ClassImp(AliPHOSGetter)
60 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
61 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
62 Int_t AliPHOSGetter::fgDebug = 0;
64 // TFile * AliPHOSGetter::fgFile = 0 ;
66 //____________________________________________________________________________
67 AliPHOSGetter::AliPHOSGetter(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("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
78 if (rl->GetAliRun() == 0x0) {
80 gAlice = rl->GetAliRun(); // should be removed
83 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
85 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
87 fgPhosLoader->SetTitle(version);
90 // initialize data members
97 //____________________________________________________________________________
98 AliPHOSGetter::~AliPHOSGetter()
101 delete fgPhosLoader ;
105 fPrimaries->Delete() ;
109 //____________________________________________________________________________
110 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
112 // Returns pointer to the Clusterizer task
113 AliPHOSClusterizer * rv ;
114 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
117 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
122 //____________________________________________________________________________
123 TObjArray * AliPHOSGetter::CpvRecPoints()
125 // asks the Loader to return the CPV RecPoints container
129 rv = PhosLoader()->CpvRecPoints() ;
131 PhosLoader()->MakeRecPointsArray() ;
132 rv = PhosLoader()->CpvRecPoints() ;
137 //____________________________________________________________________________
138 TClonesArray * AliPHOSGetter::Digits()
140 // asks the Loader to return the Digits container
142 TClonesArray * rv = 0 ;
143 rv = PhosLoader()->Digits() ;
146 PhosLoader()->MakeDigitsArray() ;
147 rv = PhosLoader()->Digits() ;
152 //____________________________________________________________________________
153 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
155 // Returns pointer to the Digitizer task
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 // Returns pointer to the TrackSegmentMaker task
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()
391 // Returns pointer to the PID task
393 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
396 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
401 //____________________________________________________________________________
402 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
404 // Returns PHOS geometry
406 AliPHOSGeometry * rv = 0 ;
408 rv = PHOS()->GetGeometry() ;
412 //____________________________________________________________________________
413 TClonesArray * AliPHOSGetter::Primaries()
415 // creates the Primaries container if needed
418 Info("Primaries", "Creating a new TClonesArray for primaries") ;
419 fPrimaries = new TClonesArray("TParticle", 1000) ;
424 //____________________________________________________________________________
425 void AliPHOSGetter::Print()
427 // Print usefull information about the getter
429 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
430 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
433 //____________________________________________________________________________
434 void AliPHOSGetter::ReadPrimaries()
436 // Read Primaries from Kinematics.root
438 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
440 // gets kine tree from the root file (Kinematics.root)
441 if ( ! rl->TreeK() ) // load treeK the first time
442 rl->LoadKinematics() ;
444 fNPrimaries = rl->Stack()->GetNtrack() ;
447 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
450 // first time creates the container
452 fPrimaries->Clear() ;
455 for (index = 0 ; index < fNPrimaries; index++) {
456 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
460 //____________________________________________________________________________
461 Int_t AliPHOSGetter::ReadTreeD()
466 // gets TreeD from the root file (PHOS.SDigits.root)
467 if ( !IsLoaded("D") ) {
468 PhosLoader()->LoadDigits("UPDATE") ;
469 PhosLoader()->LoadDigitizer("UPDATE") ;
472 return Digits()->GetEntries() ;
475 //____________________________________________________________________________
476 Int_t AliPHOSGetter::ReadTreeH()
480 // gets TreeH from the root file (PHOS.Hit.root)
481 if ( !IsLoaded("H") ) {
482 PhosLoader()->LoadHits("UPDATE") ;
485 return Hits()->GetEntries() ;
488 //____________________________________________________________________________
489 Int_t AliPHOSGetter::ReadTreeR()
491 // Read the RecPoints
494 // gets TreeR from the root file (PHOS.RecPoints.root)
495 if ( !IsLoaded("R") ) {
496 PhosLoader()->LoadRecPoints("UPDATE") ;
497 PhosLoader()->LoadClusterizer("UPDATE") ;
501 return EmcRecPoints()->GetEntries() ;
504 //____________________________________________________________________________
505 Int_t AliPHOSGetter::ReadTreeT()
507 // Read the TrackSegments
510 // gets TreeT from the root file (PHOS.TrackSegments.root)
511 if ( !IsLoaded("T") ) {
512 PhosLoader()->LoadTracks("UPDATE") ;
513 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
517 return TrackSegments()->GetEntries() ;
519 //____________________________________________________________________________
520 Int_t AliPHOSGetter::ReadTreeP()
522 // Read the TrackSegments
525 // gets TreeT from the root file (PHOS.TrackSegments.root)
526 if ( !IsLoaded("P") ) {
527 PhosLoader()->LoadRecParticles("UPDATE") ;
528 PhosLoader()->LoadPID("UPDATE") ;
532 return RecParticles()->GetEntries() ;
534 //____________________________________________________________________________
535 Int_t AliPHOSGetter::ReadTreeS()
540 // gets TreeS from the root file (PHOS.SDigits.root)
541 if ( !IsLoaded("S") ) {
542 PhosLoader()->LoadSDigits("UPDATE") ;
543 PhosLoader()->LoadSDigitizer("UPDATE") ;
547 return SDigits()->GetEntries() ;
550 //____________________________________________________________________________
551 TClonesArray * AliPHOSGetter::SDigits()
553 // asks the Loader to return the Digits container
555 TClonesArray * rv = 0 ;
557 rv = PhosLoader()->SDigits() ;
559 PhosLoader()->MakeSDigitsArray() ;
560 rv = PhosLoader()->SDigits() ;
565 //____________________________________________________________________________
566 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
568 // Returns pointer to the SDigitizer task
569 AliPHOSSDigitizer * rv ;
570 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
573 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
578 //____________________________________________________________________________
579 TParticle * AliPHOSGetter::Secondary(const TParticle* p, const Int_t index) const
581 // Return first (index=1) or second (index=2) secondary particle of primary particle p
589 Int_t daughterIndex = p->GetDaughter(index-1) ;
590 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
591 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
597 //____________________________________________________________________________
598 void AliPHOSGetter::Track(const Int_t itrack)
600 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
602 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
604 if( !TreeH() ) // load treeH the first time
607 // first time create the container
608 TClonesArray * hits = Hits() ;
612 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
613 phosbranch->SetAddress(&hits) ;
614 phosbranch->GetEntry(itrack) ;
617 //____________________________________________________________________________
618 TTree * AliPHOSGetter::TreeD() const
620 // Returns pointer to the Digits Tree
622 rv = PhosLoader()->TreeD() ;
624 PhosLoader()->MakeTree("D");
625 rv = PhosLoader()->TreeD() ;
631 //____________________________________________________________________________
632 TTree * AliPHOSGetter::TreeH() const
634 // Returns pointer to the Hits Tree
636 rv = PhosLoader()->TreeH() ;
638 PhosLoader()->MakeTree("H");
639 rv = PhosLoader()->TreeH() ;
645 //____________________________________________________________________________
646 TTree * AliPHOSGetter::TreeR() const
648 // Returns pointer to the RecPoints Tree
650 rv = PhosLoader()->TreeR() ;
652 PhosLoader()->MakeTree("R");
653 rv = PhosLoader()->TreeR() ;
659 //____________________________________________________________________________
660 TTree * AliPHOSGetter::TreeT() const
662 // Returns pointer to the TrackSegments Tree
664 rv = PhosLoader()->TreeT() ;
666 PhosLoader()->MakeTree("T");
667 rv = PhosLoader()->TreeT() ;
672 //____________________________________________________________________________
673 TTree * AliPHOSGetter::TreeP() const
675 // Returns pointer to the RecParticles Tree
677 rv = PhosLoader()->TreeP() ;
679 PhosLoader()->MakeTree("P");
680 rv = PhosLoader()->TreeP() ;
686 //____________________________________________________________________________
687 TTree * AliPHOSGetter::TreeS() const
689 // Returns pointer to the SDigits Tree
691 rv = PhosLoader()->TreeS() ;
693 PhosLoader()->MakeTree("S");
694 rv = PhosLoader()->TreeS() ;
700 //____________________________________________________________________________
701 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
703 // checks if the version with the present name already exists in the same directory
707 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
708 TString version( rl->GetEventFolder()->GetName() ) ;
712 if ( opt == "sdigits") {
713 // add the version name to the root file name
714 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
715 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
716 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
717 if ( !(gSystem->AccessPathName(fileName)) ) {
718 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
721 PhosLoader()->SetSDigitsFileName(fileName) ;
724 if ( opt == "digits") {
725 // add the version name to the root file name
726 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
727 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
728 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
729 if ( !(gSystem->AccessPathName(fileName)) ) {
730 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
733 PhosLoader()->SetDigitsFileName(fileName) ;
740 //____________________________________________________________________________
741 UShort_t AliPHOSGetter::EventPattern(void) const
743 // Return the pattern (trigger bit register) of the beam-test event
745 return fBTE->GetPattern() ;
749 //____________________________________________________________________________
750 Float_t AliPHOSGetter::BeamEnergy(void) const
752 // Return the beam energy of the beam-test event
754 return fBTE->GetBeamEnergy() ;