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() ;
113 //____________________________________________________________________________
114 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
116 // Returns pointer to the Clusterizer task
117 AliPHOSClusterizer * rv ;
118 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
121 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
126 //____________________________________________________________________________
127 TObjArray * AliPHOSGetter::CpvRecPoints()
129 // asks the Loader to return the CPV RecPoints container
133 rv = PhosLoader()->CpvRecPoints() ;
135 PhosLoader()->MakeRecPointsArray() ;
136 rv = PhosLoader()->CpvRecPoints() ;
141 //____________________________________________________________________________
142 TClonesArray * AliPHOSGetter::Digits()
144 // asks the Loader to return the Digits container
146 TClonesArray * rv = 0 ;
147 rv = PhosLoader()->Digits() ;
150 PhosLoader()->MakeDigitsArray() ;
151 rv = PhosLoader()->Digits() ;
156 //____________________________________________________________________________
157 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
159 // Returns pointer to the Digitizer task
160 AliPHOSDigitizer * rv ;
161 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
164 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
170 //____________________________________________________________________________
171 TObjArray * AliPHOSGetter::EmcRecPoints()
173 // asks the Loader to return the EMC RecPoints container
177 rv = PhosLoader()->EmcRecPoints() ;
179 PhosLoader()->MakeRecPointsArray() ;
180 rv = PhosLoader()->EmcRecPoints() ;
185 //____________________________________________________________________________
186 TClonesArray * AliPHOSGetter::TrackSegments()
188 // asks the Loader to return the TrackSegments container
190 TClonesArray * rv = 0 ;
192 rv = PhosLoader()->TrackSegments() ;
194 PhosLoader()->MakeTrackSegmentsArray() ;
195 rv = PhosLoader()->TrackSegments() ;
200 //____________________________________________________________________________
201 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
203 // Returns pointer to the TrackSegmentMaker task
204 AliPHOSTrackSegmentMaker * rv ;
205 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
208 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
213 //____________________________________________________________________________
214 TClonesArray * AliPHOSGetter::RecParticles()
216 // asks the Loader to return the TrackSegments container
218 TClonesArray * rv = 0 ;
220 rv = PhosLoader()->RecParticles() ;
222 PhosLoader()->MakeRecParticlesArray() ;
223 rv = PhosLoader()->RecParticles() ;
227 //____________________________________________________________________________
228 void AliPHOSGetter::Event(Int_t event, const char* opt)
230 // Reads the content of all Tree's S, D and R
232 if ( event >= MaxEvent() ) {
233 Error("Event", "%d not found in TreeE !", event) ;
237 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
239 // checks if we are dealing with test-beam data
240 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
243 fBTE = new AliPHOSBeamTestEvent() ;
244 btb->SetAddress(&fBTE) ;
245 btb->GetEntry(event) ;
254 // Loads the type of object(s) requested
256 rl->GetEvent(event) ;
258 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
267 if( strstr(opt,"D") )
270 if( strstr(opt,"R") )
273 if( strstr(opt,"T") )
276 if( strstr(opt,"P") )
279 // if( strstr(opt,"Q") )
285 //____________________________________________________________________________
286 Int_t AliPHOSGetter::EventNumber() const
288 // return the current event number
289 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
290 return static_cast<Int_t>(rl->GetEventNumber()) ;
293 //____________________________________________________________________________
294 TClonesArray * AliPHOSGetter::Hits()
296 // asks the loader to return the Hits container
298 TClonesArray * rv = 0 ;
300 rv = PhosLoader()->Hits() ;
302 PhosLoader()->LoadHits("read");
303 rv = PhosLoader()->Hits() ;
308 //____________________________________________________________________________
309 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
311 // Creates and returns the pointer of the unique instance
312 // Must be called only when the environment has changed
314 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
316 if(!fgObjGetter){ // first time the getter is called
317 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
319 else { // the getter has been called previously
320 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
321 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
322 // check if the file is already open
323 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
326 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
328 else { // the file is already open check the version name
329 TString currentVersionName = rl->GetEventFolder()->GetName() ;
330 TString newVersionName(version) ;
331 if (currentVersionName == newVersionName)
333 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
335 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
340 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
341 if ( strstr(version, AliConfig::fgkDefaultEventFolderName) ) // false in case of merging
343 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
347 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
355 //____________________________________________________________________________
356 AliPHOSGetter * AliPHOSGetter::Instance()
358 // Returns the pointer of the unique instance already defined
360 if(!fgObjGetter && fgDebug)
361 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
367 //____________________________________________________________________________
368 Int_t AliPHOSGetter::MaxEvent() const
370 // returns the number of events in the run (from TE)
372 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
373 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
376 //____________________________________________________________________________
377 TParticle * AliPHOSGetter::Primary(Int_t index) const
379 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
380 return rl->Stack()->Particle(index) ;
383 //____________________________________________________________________________
384 AliPHOS * AliPHOSGetter:: PHOS() const
386 // returns the PHOS object
387 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
390 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
396 //____________________________________________________________________________
397 AliPHOSPID * AliPHOSGetter::PID()
399 // Returns pointer to the PID task
401 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
404 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
409 //____________________________________________________________________________
410 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
412 // Returns PHOS geometry
414 AliPHOSGeometry * rv = 0 ;
416 rv = PHOS()->GetGeometry() ;
420 //____________________________________________________________________________
421 TClonesArray * AliPHOSGetter::Primaries()
423 // creates the Primaries container if needed
426 Info("Primaries", "Creating a new TClonesArray for primaries") ;
427 fPrimaries = new TClonesArray("TParticle", 1000) ;
432 //____________________________________________________________________________
433 void AliPHOSGetter::Print()
435 // Print usefull information about the getter
437 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
438 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
441 //____________________________________________________________________________
442 void AliPHOSGetter::ReadPrimaries()
444 // Read Primaries from Kinematics.root
446 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
448 // gets kine tree from the root file (Kinematics.root)
449 if ( ! rl->TreeK() ) { // load treeK the first time
450 rl->LoadKinematics() ;
453 fNPrimaries = (rl->GetHeader())->GetNtrack();
455 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
458 // first time creates the container
460 fPrimaries->Clear() ;
463 for (index = 0 ; index < fNPrimaries; index++) {
464 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
468 //____________________________________________________________________________
469 AliESD * AliPHOSGetter::ESD(Int_t event)
475 TString esdEvent("ESD") ;
477 AliESD * esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ;
481 //____________________________________________________________________________
482 Bool_t AliPHOSGetter::OpenESDFile(TString name)
485 fESDFileName = name ;
487 fESDFile = new TFile(fESDFileName) ;
488 else if (fESDFile->IsOpen()) {
490 fESDFile = TFile::Open(fESDFileName) ;
492 if (!fESDFile->IsOpen())
497 //____________________________________________________________________________
498 Int_t AliPHOSGetter::ReadTreeD()
503 // gets TreeD from the root file (PHOS.SDigits.root)
504 if ( !IsLoaded("D") ) {
505 PhosLoader()->LoadDigits("UPDATE") ;
506 PhosLoader()->LoadDigitizer("UPDATE") ;
509 return Digits()->GetEntries() ;
512 //____________________________________________________________________________
513 Int_t AliPHOSGetter::ReadTreeH()
517 // gets TreeH from the root file (PHOS.Hit.root)
518 if ( !IsLoaded("H") ) {
519 PhosLoader()->LoadHits("UPDATE") ;
522 return Hits()->GetEntries() ;
525 //____________________________________________________________________________
526 Int_t AliPHOSGetter::ReadTreeR()
528 // Read the RecPoints
531 // gets TreeR from the root file (PHOS.RecPoints.root)
532 if ( !IsLoaded("R") ) {
533 PhosLoader()->LoadRecPoints("UPDATE") ;
534 PhosLoader()->LoadClusterizer("UPDATE") ;
538 return EmcRecPoints()->GetEntries() ;
541 //____________________________________________________________________________
542 Int_t AliPHOSGetter::ReadTreeT()
544 // Read the TrackSegments
547 // gets TreeT from the root file (PHOS.TrackSegments.root)
548 if ( !IsLoaded("T") ) {
549 PhosLoader()->LoadTracks("UPDATE") ;
550 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
554 return TrackSegments()->GetEntries() ;
556 //____________________________________________________________________________
557 Int_t AliPHOSGetter::ReadTreeP()
559 // Read the TrackSegments
562 // gets TreeT from the root file (PHOS.TrackSegments.root)
563 if ( !IsLoaded("P") ) {
564 PhosLoader()->LoadRecParticles("UPDATE") ;
565 PhosLoader()->LoadPID("UPDATE") ;
569 return RecParticles()->GetEntries() ;
571 //____________________________________________________________________________
572 Int_t AliPHOSGetter::ReadTreeS()
577 // gets TreeS from the root file (PHOS.SDigits.root)
578 if ( !IsLoaded("S") ) {
579 PhosLoader()->LoadSDigits("READ") ;
580 PhosLoader()->LoadSDigitizer("READ") ;
584 return SDigits()->GetEntries() ;
587 //____________________________________________________________________________
588 TClonesArray * AliPHOSGetter::SDigits()
590 // asks the Loader to return the Digits container
592 TClonesArray * rv = 0 ;
594 rv = PhosLoader()->SDigits() ;
596 PhosLoader()->MakeSDigitsArray() ;
597 rv = PhosLoader()->SDigits() ;
602 //____________________________________________________________________________
603 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
605 // Returns pointer to the SDigitizer task
606 AliPHOSSDigitizer * rv ;
607 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
610 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
615 //____________________________________________________________________________
616 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
618 // Return first (index=1) or second (index=2) secondary particle of primary particle p
626 Int_t daughterIndex = p->GetDaughter(index-1) ;
627 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
628 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
634 //____________________________________________________________________________
635 void AliPHOSGetter::Track(Int_t itrack)
637 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
639 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
641 if( !TreeH() ) // load treeH the first time
644 // first time create the container
645 TClonesArray * hits = Hits() ;
649 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
650 phosbranch->SetAddress(&hits) ;
651 phosbranch->GetEntry(itrack) ;
654 //____________________________________________________________________________
655 TTree * AliPHOSGetter::TreeD() const
657 // Returns pointer to the Digits Tree
659 rv = PhosLoader()->TreeD() ;
661 PhosLoader()->MakeTree("D");
662 rv = PhosLoader()->TreeD() ;
668 //____________________________________________________________________________
669 TTree * AliPHOSGetter::TreeH() const
671 // Returns pointer to the Hits Tree
673 rv = PhosLoader()->TreeH() ;
675 PhosLoader()->MakeTree("H");
676 rv = PhosLoader()->TreeH() ;
682 //____________________________________________________________________________
683 TTree * AliPHOSGetter::TreeR() const
685 // Returns pointer to the RecPoints Tree
687 rv = PhosLoader()->TreeR() ;
689 PhosLoader()->MakeTree("R");
690 rv = PhosLoader()->TreeR() ;
696 //____________________________________________________________________________
697 TTree * AliPHOSGetter::TreeT() const
699 // Returns pointer to the TrackSegments Tree
701 rv = PhosLoader()->TreeT() ;
703 PhosLoader()->MakeTree("T");
704 rv = PhosLoader()->TreeT() ;
709 //____________________________________________________________________________
710 TTree * AliPHOSGetter::TreeP() const
712 // Returns pointer to the RecParticles Tree
714 rv = PhosLoader()->TreeP() ;
716 PhosLoader()->MakeTree("P");
717 rv = PhosLoader()->TreeP() ;
723 //____________________________________________________________________________
724 TTree * AliPHOSGetter::TreeS() const
726 // Returns pointer to the SDigits Tree
728 rv = PhosLoader()->TreeS() ;
730 PhosLoader()->MakeTree("S");
731 rv = PhosLoader()->TreeS() ;
737 //____________________________________________________________________________
738 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
740 // checks if the version with the present name already exists in the same directory
744 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
745 TString version( rl->GetEventFolder()->GetName() ) ;
749 if ( opt == "sdigits") {
750 // add the version name to the root file name
751 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
752 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
753 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
754 if ( !(gSystem->AccessPathName(fileName)) ) {
755 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
758 PhosLoader()->SetSDigitsFileName(fileName) ;
761 if ( opt == "digits") {
762 // add the version name to the root file name
763 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
764 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
765 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
766 if ( !(gSystem->AccessPathName(fileName)) ) {
767 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
776 //____________________________________________________________________________
777 UShort_t AliPHOSGetter::EventPattern(void) const
779 // Return the pattern (trigger bit register) of the beam-test event
781 return fBTE->GetPattern() ;
785 //____________________________________________________________________________
786 Float_t AliPHOSGetter::BeamEnergy(void) const
788 // Return the beam energy of the beam-test event
790 return fBTE->GetBeamEnergy() ;