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 "AliHeader.h"
55 #include "AliPHOSBeamTestEvent.h"
56 #include "AliPHOSGetter.h"
57 #include "AliPHOSLoader.h"
58 #include "AliRunLoader.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
99 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
100 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
104 //____________________________________________________________________________
105 AliPHOSGetter::~AliPHOSGetter()
108 delete fgPhosLoader ;
112 fPrimaries->Delete() ;
117 //____________________________________________________________________________
118 void AliPHOSGetter::Reset()
120 // resets things in case the getter is called consecutively with different files
121 // the PHOS Loader is already deleted by the Run Loader
124 fPrimaries->Delete() ;
131 //____________________________________________________________________________
132 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
134 // Returns pointer to the Clusterizer task
135 AliPHOSClusterizer * rv ;
136 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
139 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
144 //____________________________________________________________________________
145 TObjArray * AliPHOSGetter::CpvRecPoints()
147 // asks the Loader to return the CPV RecPoints container
151 rv = PhosLoader()->CpvRecPoints() ;
153 PhosLoader()->MakeRecPointsArray() ;
154 rv = PhosLoader()->CpvRecPoints() ;
159 //____________________________________________________________________________
160 TClonesArray * AliPHOSGetter::Digits()
162 // asks the Loader to return the Digits container
164 TClonesArray * rv = 0 ;
165 rv = PhosLoader()->Digits() ;
168 PhosLoader()->MakeDigitsArray() ;
169 rv = PhosLoader()->Digits() ;
174 //____________________________________________________________________________
175 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
177 // Returns pointer to the Digitizer task
178 AliPHOSDigitizer * rv ;
179 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
182 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
188 //____________________________________________________________________________
189 TObjArray * AliPHOSGetter::EmcRecPoints()
191 // asks the Loader to return the EMC RecPoints container
195 rv = PhosLoader()->EmcRecPoints() ;
197 PhosLoader()->MakeRecPointsArray() ;
198 rv = PhosLoader()->EmcRecPoints() ;
203 //____________________________________________________________________________
204 TClonesArray * AliPHOSGetter::TrackSegments()
206 // asks the Loader to return the TrackSegments container
208 TClonesArray * rv = 0 ;
210 rv = PhosLoader()->TrackSegments() ;
212 PhosLoader()->MakeTrackSegmentsArray() ;
213 rv = PhosLoader()->TrackSegments() ;
218 //____________________________________________________________________________
219 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
221 // Returns pointer to the TrackSegmentMaker task
222 AliPHOSTrackSegmentMaker * rv ;
223 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
226 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
231 //____________________________________________________________________________
232 TClonesArray * AliPHOSGetter::RecParticles()
234 // asks the Loader to return the TrackSegments container
236 TClonesArray * rv = 0 ;
238 rv = PhosLoader()->RecParticles() ;
240 PhosLoader()->MakeRecParticlesArray() ;
241 rv = PhosLoader()->RecParticles() ;
245 //____________________________________________________________________________
246 void AliPHOSGetter::Event(Int_t event, const char* opt)
248 // Reads the content of all Tree's S, D and R
250 if ( event >= MaxEvent() ) {
251 Error("Event", "%d not found in TreeE !", event) ;
255 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
257 // checks if we are dealing with test-beam data
258 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
261 fBTE = new AliPHOSBeamTestEvent() ;
262 btb->SetAddress(&fBTE) ;
263 btb->GetEntry(event) ;
272 // Loads the type of object(s) requested
274 rl->GetEvent(event) ;
276 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
285 if( strstr(opt,"D") )
288 if( strstr(opt,"R") )
291 if( strstr(opt,"T") )
294 if( strstr(opt,"P") )
297 // if( strstr(opt,"Q") )
303 //____________________________________________________________________________
304 Int_t AliPHOSGetter::EventNumber() const
306 // return the current event number
307 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
308 return static_cast<Int_t>(rl->GetEventNumber()) ;
311 //____________________________________________________________________________
312 TClonesArray * AliPHOSGetter::Hits()
314 // asks the loader to return the Hits container
316 TClonesArray * rv = 0 ;
318 rv = PhosLoader()->Hits() ;
320 PhosLoader()->LoadHits("read");
321 rv = PhosLoader()->Hits() ;
326 //____________________________________________________________________________
327 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
329 // Creates and returns the pointer of the unique instance
330 // Must be called only when the environment has changed
332 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
334 if(!fgObjGetter){ // first time the getter is called
335 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
337 else { // the getter has been called previously
338 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
339 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
340 // check if the file is already open
341 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
344 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
346 else { // the file is already open check the version name
347 TString currentVersionName = rl->GetEventFolder()->GetName() ;
348 TString newVersionName(version) ;
349 if (currentVersionName == newVersionName)
351 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
353 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
358 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
359 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
361 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
365 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
373 //____________________________________________________________________________
374 AliPHOSGetter * AliPHOSGetter::Instance()
376 // Returns the pointer of the unique instance already defined
378 if(!fgObjGetter && fgDebug)
379 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
385 //____________________________________________________________________________
386 Int_t AliPHOSGetter::MaxEvent() const
388 // returns the number of events in the run (from TE)
390 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
391 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
394 //____________________________________________________________________________
395 TParticle * AliPHOSGetter::Primary(Int_t index) const
397 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
398 return rl->Stack()->Particle(index) ;
401 //____________________________________________________________________________
402 AliPHOS * AliPHOSGetter:: PHOS() const
404 // returns the PHOS object
405 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
408 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
414 //____________________________________________________________________________
415 AliPHOSPID * AliPHOSGetter::PID()
417 // Returns pointer to the PID task
419 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
422 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
427 //____________________________________________________________________________
428 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
430 // Returns PHOS geometry
432 AliPHOSGeometry * rv = 0 ;
434 rv = PHOS()->GetGeometry() ;
438 //____________________________________________________________________________
439 TClonesArray * AliPHOSGetter::Primaries()
441 // creates the Primaries container if needed
444 Info("Primaries", "Creating a new TClonesArray for primaries") ;
445 fPrimaries = new TClonesArray("TParticle", 1000) ;
450 //____________________________________________________________________________
451 void AliPHOSGetter::Print()
453 // Print usefull information about the getter
455 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
456 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
459 //____________________________________________________________________________
460 void AliPHOSGetter::ReadPrimaries()
462 // Read Primaries from Kinematics.root
464 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
466 // gets kine tree from the root file (Kinematics.root)
467 if ( ! rl->TreeK() ) { // load treeK the first time
468 rl->LoadKinematics() ;
471 fNPrimaries = (rl->GetHeader())->GetNtrack();
473 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
476 // first time creates the container
478 fPrimaries->Clear() ;
481 for (index = 0 ; index < fNPrimaries; index++) {
482 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
486 //____________________________________________________________________________
487 AliESD * AliPHOSGetter::ESD(Int_t event)
493 if ( !OpenESDFile() )
496 TString esdEvent("ESD") ;
498 esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ;
502 //____________________________________________________________________________
503 Bool_t AliPHOSGetter::OpenESDFile()
508 fESDFile = TFile::Open(fESDFileName) ;
512 else if (fESDFile->IsOpen()) {
514 fESDFile = TFile::Open(fESDFileName) ;
516 if (!fESDFile->IsOpen())
521 //____________________________________________________________________________
522 Int_t AliPHOSGetter::ReadTreeD()
527 // gets TreeD from the root file (PHOS.SDigits.root)
528 if ( !IsLoaded("D") ) {
529 PhosLoader()->LoadDigits("UPDATE") ;
530 PhosLoader()->LoadDigitizer("UPDATE") ;
533 return Digits()->GetEntries() ;
536 //____________________________________________________________________________
537 Int_t AliPHOSGetter::ReadTreeH()
541 // gets TreeH from the root file (PHOS.Hit.root)
542 if ( !IsLoaded("H") ) {
543 PhosLoader()->LoadHits("UPDATE") ;
546 return Hits()->GetEntries() ;
549 //____________________________________________________________________________
550 Int_t AliPHOSGetter::ReadTreeR()
552 // Read the RecPoints
555 // gets TreeR from the root file (PHOS.RecPoints.root)
556 if ( !IsLoaded("R") ) {
557 PhosLoader()->LoadRecPoints("UPDATE") ;
558 PhosLoader()->LoadClusterizer("UPDATE") ;
562 return EmcRecPoints()->GetEntries() ;
565 //____________________________________________________________________________
566 Int_t AliPHOSGetter::ReadTreeT()
568 // Read the TrackSegments
571 // gets TreeT from the root file (PHOS.TrackSegments.root)
572 if ( !IsLoaded("T") ) {
573 PhosLoader()->LoadTracks("UPDATE") ;
574 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
578 return TrackSegments()->GetEntries() ;
580 //____________________________________________________________________________
581 Int_t AliPHOSGetter::ReadTreeP()
583 // Read the TrackSegments
586 // gets TreeT from the root file (PHOS.TrackSegments.root)
587 if ( !IsLoaded("P") ) {
588 PhosLoader()->LoadRecParticles("UPDATE") ;
589 PhosLoader()->LoadPID("UPDATE") ;
593 return RecParticles()->GetEntries() ;
595 //____________________________________________________________________________
596 Int_t AliPHOSGetter::ReadTreeS()
601 // gets TreeS from the root file (PHOS.SDigits.root)
602 if ( !IsLoaded("S") ) {
603 PhosLoader()->LoadSDigits("READ") ;
604 PhosLoader()->LoadSDigitizer("READ") ;
608 return SDigits()->GetEntries() ;
611 //____________________________________________________________________________
612 TClonesArray * AliPHOSGetter::SDigits()
614 // asks the Loader to return the Digits container
616 TClonesArray * rv = 0 ;
618 rv = PhosLoader()->SDigits() ;
620 PhosLoader()->MakeSDigitsArray() ;
621 rv = PhosLoader()->SDigits() ;
626 //____________________________________________________________________________
627 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
629 // Returns pointer to the SDigitizer task
630 AliPHOSSDigitizer * rv ;
631 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
634 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
639 //____________________________________________________________________________
640 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
642 // Return first (index=1) or second (index=2) secondary particle of primary particle p
650 Int_t daughterIndex = p->GetDaughter(index-1) ;
651 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
652 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
658 //____________________________________________________________________________
659 void AliPHOSGetter::Track(Int_t itrack)
661 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
663 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
665 if( !TreeH() ) // load treeH the first time
668 // first time create the container
669 TClonesArray * hits = Hits() ;
673 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
674 phosbranch->SetAddress(&hits) ;
675 phosbranch->GetEntry(itrack) ;
678 //____________________________________________________________________________
679 TTree * AliPHOSGetter::TreeD() const
681 // Returns pointer to the Digits Tree
683 rv = PhosLoader()->TreeD() ;
685 PhosLoader()->MakeTree("D");
686 rv = PhosLoader()->TreeD() ;
692 //____________________________________________________________________________
693 TTree * AliPHOSGetter::TreeH() const
695 // Returns pointer to the Hits Tree
697 rv = PhosLoader()->TreeH() ;
699 PhosLoader()->MakeTree("H");
700 rv = PhosLoader()->TreeH() ;
706 //____________________________________________________________________________
707 TTree * AliPHOSGetter::TreeR() const
709 // Returns pointer to the RecPoints Tree
711 rv = PhosLoader()->TreeR() ;
713 PhosLoader()->MakeTree("R");
714 rv = PhosLoader()->TreeR() ;
720 //____________________________________________________________________________
721 TTree * AliPHOSGetter::TreeT() const
723 // Returns pointer to the TrackSegments Tree
725 rv = PhosLoader()->TreeT() ;
727 PhosLoader()->MakeTree("T");
728 rv = PhosLoader()->TreeT() ;
733 //____________________________________________________________________________
734 TTree * AliPHOSGetter::TreeP() const
736 // Returns pointer to the RecParticles Tree
738 rv = PhosLoader()->TreeP() ;
740 PhosLoader()->MakeTree("P");
741 rv = PhosLoader()->TreeP() ;
747 //____________________________________________________________________________
748 TTree * AliPHOSGetter::TreeS() const
750 // Returns pointer to the SDigits Tree
752 rv = PhosLoader()->TreeS() ;
754 PhosLoader()->MakeTree("S");
755 rv = PhosLoader()->TreeS() ;
761 //____________________________________________________________________________
762 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
764 // checks if the version with the present name already exists in the same directory
768 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
769 TString version( rl->GetEventFolder()->GetName() ) ;
773 if ( opt == "sdigits") {
774 // add the version name to the root file name
775 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
776 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
777 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
778 if ( !(gSystem->AccessPathName(fileName)) ) {
779 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
782 PhosLoader()->SetSDigitsFileName(fileName) ;
785 if ( opt == "digits") {
786 // add the version name to the root file name
787 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
788 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
789 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
790 if ( !(gSystem->AccessPathName(fileName)) ) {
791 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
800 //____________________________________________________________________________
801 UShort_t AliPHOSGetter::EventPattern(void) const
803 // Return the pattern (trigger bit register) of the beam-test event
805 return fBTE->GetPattern() ;
809 //____________________________________________________________________________
810 Float_t AliPHOSGetter::BeamEnergy(void) const
812 // Return the beam energy of the beam-test event
814 return fBTE->GetBeamEnergy() ;