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 "AliHeader.h"
55 #include "AliPHOSLoader.h"
56 #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
97 fESDFileName = "AliESDs.root" ;
101 //____________________________________________________________________________
102 AliPHOSGetter::~AliPHOSGetter()
105 delete fgPhosLoader ;
109 fPrimaries->Delete() ;
114 //____________________________________________________________________________
115 void AliPHOSGetter::Reset()
117 // resets things in case the getter is called consecutively with different files
118 // the PHOS Loader is already deleted by the Run Loader
121 fPrimaries->Delete() ;
128 //____________________________________________________________________________
129 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
131 // Returns pointer to the Clusterizer task
132 AliPHOSClusterizer * rv ;
133 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
136 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
141 //____________________________________________________________________________
142 TObjArray * AliPHOSGetter::CpvRecPoints()
144 // asks the Loader to return the CPV RecPoints container
148 rv = PhosLoader()->CpvRecPoints() ;
150 PhosLoader()->MakeRecPointsArray() ;
151 rv = PhosLoader()->CpvRecPoints() ;
156 //____________________________________________________________________________
157 TClonesArray * AliPHOSGetter::Digits()
159 // asks the Loader to return the Digits container
161 TClonesArray * rv = 0 ;
162 rv = PhosLoader()->Digits() ;
165 PhosLoader()->MakeDigitsArray() ;
166 rv = PhosLoader()->Digits() ;
171 //____________________________________________________________________________
172 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
174 // Returns pointer to the Digitizer task
175 AliPHOSDigitizer * rv ;
176 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
179 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
185 //____________________________________________________________________________
186 TObjArray * AliPHOSGetter::EmcRecPoints()
188 // asks the Loader to return the EMC RecPoints container
192 rv = PhosLoader()->EmcRecPoints() ;
194 PhosLoader()->MakeRecPointsArray() ;
195 rv = PhosLoader()->EmcRecPoints() ;
200 //____________________________________________________________________________
201 TClonesArray * AliPHOSGetter::TrackSegments()
203 // asks the Loader to return the TrackSegments container
205 TClonesArray * rv = 0 ;
207 rv = PhosLoader()->TrackSegments() ;
209 PhosLoader()->MakeTrackSegmentsArray() ;
210 rv = PhosLoader()->TrackSegments() ;
215 //____________________________________________________________________________
216 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
218 // Returns pointer to the TrackSegmentMaker task
219 AliPHOSTrackSegmentMaker * rv ;
220 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
223 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
228 //____________________________________________________________________________
229 TClonesArray * AliPHOSGetter::RecParticles()
231 // asks the Loader to return the TrackSegments container
233 TClonesArray * rv = 0 ;
235 rv = PhosLoader()->RecParticles() ;
237 PhosLoader()->MakeRecParticlesArray() ;
238 rv = PhosLoader()->RecParticles() ;
242 //____________________________________________________________________________
243 void AliPHOSGetter::Event(Int_t event, const char* opt)
245 // Reads the content of all Tree's S, D and R
247 if ( event >= MaxEvent() ) {
248 Error("Event", "%d not found in TreeE !", event) ;
252 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
254 // checks if we are dealing with test-beam data
255 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
258 fBTE = new AliPHOSBeamTestEvent() ;
259 btb->SetAddress(&fBTE) ;
260 btb->GetEntry(event) ;
269 // Loads the type of object(s) requested
271 rl->GetEvent(event) ;
273 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
282 if( strstr(opt,"D") )
285 if( strstr(opt,"R") )
288 if( strstr(opt,"T") )
291 if( strstr(opt,"P") )
294 // if( strstr(opt,"Q") )
300 //____________________________________________________________________________
301 Int_t AliPHOSGetter::EventNumber() const
303 // return the current event number
304 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
305 return static_cast<Int_t>(rl->GetEventNumber()) ;
308 //____________________________________________________________________________
309 TClonesArray * AliPHOSGetter::Hits()
311 // asks the loader to return the Hits container
313 TClonesArray * rv = 0 ;
315 rv = PhosLoader()->Hits() ;
317 PhosLoader()->LoadHits("read");
318 rv = PhosLoader()->Hits() ;
323 //____________________________________________________________________________
324 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
326 // Creates and returns the pointer of the unique instance
327 // Must be called only when the environment has changed
329 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
331 if(!fgObjGetter){ // first time the getter is called
332 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
334 else { // the getter has been called previously
335 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
336 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
337 // check if the file is already open
338 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
341 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
343 else { // the file is already open check the version name
344 TString currentVersionName = rl->GetEventFolder()->GetName() ;
345 TString newVersionName(version) ;
346 if (currentVersionName == newVersionName)
348 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
350 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
355 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
356 if ( strstr(version, AliConfig::fgkDefaultEventFolderName) ) // false in case of merging
358 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
362 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
370 //____________________________________________________________________________
371 AliPHOSGetter * AliPHOSGetter::Instance()
373 // Returns the pointer of the unique instance already defined
375 if(!fgObjGetter && fgDebug)
376 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
382 //____________________________________________________________________________
383 Int_t AliPHOSGetter::MaxEvent() const
385 // returns the number of events in the run (from TE)
387 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
388 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
391 //____________________________________________________________________________
392 TParticle * AliPHOSGetter::Primary(Int_t index) const
394 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
395 return rl->Stack()->Particle(index) ;
398 //____________________________________________________________________________
399 AliPHOS * AliPHOSGetter:: PHOS() const
401 // returns the PHOS object
402 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
405 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
411 //____________________________________________________________________________
412 AliPHOSPID * AliPHOSGetter::PID()
414 // Returns pointer to the PID task
416 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
419 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
424 //____________________________________________________________________________
425 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
427 // Returns PHOS geometry
429 AliPHOSGeometry * rv = 0 ;
431 rv = PHOS()->GetGeometry() ;
435 //____________________________________________________________________________
436 TClonesArray * AliPHOSGetter::Primaries()
438 // creates the Primaries container if needed
441 Info("Primaries", "Creating a new TClonesArray for primaries") ;
442 fPrimaries = new TClonesArray("TParticle", 1000) ;
447 //____________________________________________________________________________
448 void AliPHOSGetter::Print()
450 // Print usefull information about the getter
452 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
453 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
456 //____________________________________________________________________________
457 void AliPHOSGetter::ReadPrimaries()
459 // Read Primaries from Kinematics.root
461 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
463 // gets kine tree from the root file (Kinematics.root)
464 if ( ! rl->TreeK() ) { // load treeK the first time
465 rl->LoadKinematics() ;
468 fNPrimaries = (rl->GetHeader())->GetNtrack();
470 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
473 // first time creates the container
475 fPrimaries->Clear() ;
478 for (index = 0 ; index < fNPrimaries; index++) {
479 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
483 //____________________________________________________________________________
484 AliESD * AliPHOSGetter::ESD(Int_t event)
490 TString esdEvent("ESD") ;
492 AliESD * esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ;
496 //____________________________________________________________________________
497 Bool_t AliPHOSGetter::OpenESDFile(TString name)
500 fESDFileName = name ;
502 fESDFile = new TFile(fESDFileName) ;
503 else if (fESDFile->IsOpen()) {
505 fESDFile = TFile::Open(fESDFileName) ;
507 if (!fESDFile->IsOpen())
512 //____________________________________________________________________________
513 Int_t AliPHOSGetter::ReadTreeD()
518 // gets TreeD from the root file (PHOS.SDigits.root)
519 if ( !IsLoaded("D") ) {
520 PhosLoader()->LoadDigits("UPDATE") ;
521 PhosLoader()->LoadDigitizer("UPDATE") ;
524 return Digits()->GetEntries() ;
527 //____________________________________________________________________________
528 Int_t AliPHOSGetter::ReadTreeH()
532 // gets TreeH from the root file (PHOS.Hit.root)
533 if ( !IsLoaded("H") ) {
534 PhosLoader()->LoadHits("UPDATE") ;
537 return Hits()->GetEntries() ;
540 //____________________________________________________________________________
541 Int_t AliPHOSGetter::ReadTreeR()
543 // Read the RecPoints
546 // gets TreeR from the root file (PHOS.RecPoints.root)
547 if ( !IsLoaded("R") ) {
548 PhosLoader()->LoadRecPoints("UPDATE") ;
549 PhosLoader()->LoadClusterizer("UPDATE") ;
553 return EmcRecPoints()->GetEntries() ;
556 //____________________________________________________________________________
557 Int_t AliPHOSGetter::ReadTreeT()
559 // Read the TrackSegments
562 // gets TreeT from the root file (PHOS.TrackSegments.root)
563 if ( !IsLoaded("T") ) {
564 PhosLoader()->LoadTracks("UPDATE") ;
565 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
569 return TrackSegments()->GetEntries() ;
571 //____________________________________________________________________________
572 Int_t AliPHOSGetter::ReadTreeP()
574 // Read the TrackSegments
577 // gets TreeT from the root file (PHOS.TrackSegments.root)
578 if ( !IsLoaded("P") ) {
579 PhosLoader()->LoadRecParticles("UPDATE") ;
580 PhosLoader()->LoadPID("UPDATE") ;
584 return RecParticles()->GetEntries() ;
586 //____________________________________________________________________________
587 Int_t AliPHOSGetter::ReadTreeS()
592 // gets TreeS from the root file (PHOS.SDigits.root)
593 if ( !IsLoaded("S") ) {
594 PhosLoader()->LoadSDigits("READ") ;
595 PhosLoader()->LoadSDigitizer("READ") ;
599 return SDigits()->GetEntries() ;
602 //____________________________________________________________________________
603 TClonesArray * AliPHOSGetter::SDigits()
605 // asks the Loader to return the Digits container
607 TClonesArray * rv = 0 ;
609 rv = PhosLoader()->SDigits() ;
611 PhosLoader()->MakeSDigitsArray() ;
612 rv = PhosLoader()->SDigits() ;
617 //____________________________________________________________________________
618 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
620 // Returns pointer to the SDigitizer task
621 AliPHOSSDigitizer * rv ;
622 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
625 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
630 //____________________________________________________________________________
631 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
633 // Return first (index=1) or second (index=2) secondary particle of primary particle p
641 Int_t daughterIndex = p->GetDaughter(index-1) ;
642 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
643 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
649 //____________________________________________________________________________
650 void AliPHOSGetter::Track(Int_t itrack)
652 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
654 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
656 if( !TreeH() ) // load treeH the first time
659 // first time create the container
660 TClonesArray * hits = Hits() ;
664 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
665 phosbranch->SetAddress(&hits) ;
666 phosbranch->GetEntry(itrack) ;
669 //____________________________________________________________________________
670 TTree * AliPHOSGetter::TreeD() const
672 // Returns pointer to the Digits Tree
674 rv = PhosLoader()->TreeD() ;
676 PhosLoader()->MakeTree("D");
677 rv = PhosLoader()->TreeD() ;
683 //____________________________________________________________________________
684 TTree * AliPHOSGetter::TreeH() const
686 // Returns pointer to the Hits Tree
688 rv = PhosLoader()->TreeH() ;
690 PhosLoader()->MakeTree("H");
691 rv = PhosLoader()->TreeH() ;
697 //____________________________________________________________________________
698 TTree * AliPHOSGetter::TreeR() const
700 // Returns pointer to the RecPoints Tree
702 rv = PhosLoader()->TreeR() ;
704 PhosLoader()->MakeTree("R");
705 rv = PhosLoader()->TreeR() ;
711 //____________________________________________________________________________
712 TTree * AliPHOSGetter::TreeT() const
714 // Returns pointer to the TrackSegments Tree
716 rv = PhosLoader()->TreeT() ;
718 PhosLoader()->MakeTree("T");
719 rv = PhosLoader()->TreeT() ;
724 //____________________________________________________________________________
725 TTree * AliPHOSGetter::TreeP() const
727 // Returns pointer to the RecParticles Tree
729 rv = PhosLoader()->TreeP() ;
731 PhosLoader()->MakeTree("P");
732 rv = PhosLoader()->TreeP() ;
738 //____________________________________________________________________________
739 TTree * AliPHOSGetter::TreeS() const
741 // Returns pointer to the SDigits Tree
743 rv = PhosLoader()->TreeS() ;
745 PhosLoader()->MakeTree("S");
746 rv = PhosLoader()->TreeS() ;
752 //____________________________________________________________________________
753 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
755 // checks if the version with the present name already exists in the same directory
759 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
760 TString version( rl->GetEventFolder()->GetName() ) ;
764 if ( opt == "sdigits") {
765 // add the version name to the root file name
766 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
767 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
768 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
769 if ( !(gSystem->AccessPathName(fileName)) ) {
770 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
773 PhosLoader()->SetSDigitsFileName(fileName) ;
776 if ( opt == "digits") {
777 // add the version name to the root file name
778 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
779 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
780 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
781 if ( !(gSystem->AccessPathName(fileName)) ) {
782 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
791 //____________________________________________________________________________
792 UShort_t AliPHOSGetter::EventPattern(void) const
794 // Return the pattern (trigger bit register) of the beam-test event
796 return fBTE->GetPattern() ;
800 //____________________________________________________________________________
801 Float_t AliPHOSGetter::BeamEnergy(void) const
803 // Return the beam energy of the beam-test event
805 return fBTE->GetBeamEnergy() ;