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 ---
46 #include <TParticle.h>
49 // --- Standard library ---
51 // --- AliRoot header files ---
53 #include "AliHeader.h"
56 #include "AliPHOSBeamTestEvent.h"
57 #include "AliPHOSGetter.h"
58 #include "AliPHOSLoader.h"
59 #include "AliRunLoader.h"
62 ClassImp(AliPHOSGetter)
64 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
65 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
66 Int_t AliPHOSGetter::fgDebug = 0;
68 // TFile * AliPHOSGetter::fgFile = 0 ;
70 //____________________________________________________________________________
71 AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
73 // ctor only called by Instance()
75 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
77 rl = AliRunLoader::Open(headerFile, version, openingOption);
79 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
82 if (rl->GetAliRun() == 0x0) {
84 gAlice = rl->GetAliRun(); // should be removed
87 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
89 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
91 fgPhosLoader->SetTitle(version);
94 // initialize data members
100 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
101 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
105 //____________________________________________________________________________
106 AliPHOSGetter::~AliPHOSGetter()
109 delete fgPhosLoader ;
113 fPrimaries->Delete() ;
118 //____________________________________________________________________________
119 void AliPHOSGetter::Reset()
121 // resets things in case the getter is called consecutively with different files
122 // the PHOS Loader is already deleted by the Run Loader
125 fPrimaries->Delete() ;
132 //____________________________________________________________________________
133 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
135 // Returns pointer to the Clusterizer task
136 AliPHOSClusterizer * rv ;
137 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
140 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
145 //____________________________________________________________________________
146 TObjArray * AliPHOSGetter::CpvRecPoints()
148 // asks the Loader to return the CPV RecPoints container
152 rv = PhosLoader()->CpvRecPoints() ;
154 PhosLoader()->MakeRecPointsArray() ;
155 rv = PhosLoader()->CpvRecPoints() ;
160 //____________________________________________________________________________
161 TClonesArray * AliPHOSGetter::Digits()
163 // asks the Loader to return the Digits container
165 TClonesArray * rv = 0 ;
166 rv = PhosLoader()->Digits() ;
169 PhosLoader()->MakeDigitsArray() ;
170 rv = PhosLoader()->Digits() ;
175 //____________________________________________________________________________
176 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
178 // Returns pointer to the Digitizer task
179 AliPHOSDigitizer * rv ;
180 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
183 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
189 //____________________________________________________________________________
190 TObjArray * AliPHOSGetter::EmcRecPoints()
192 // asks the Loader to return the EMC RecPoints container
196 rv = PhosLoader()->EmcRecPoints() ;
198 PhosLoader()->MakeRecPointsArray() ;
199 rv = PhosLoader()->EmcRecPoints() ;
204 //____________________________________________________________________________
205 TClonesArray * AliPHOSGetter::TrackSegments()
207 // asks the Loader to return the TrackSegments container
209 TClonesArray * rv = 0 ;
211 rv = PhosLoader()->TrackSegments() ;
213 PhosLoader()->MakeTrackSegmentsArray() ;
214 rv = PhosLoader()->TrackSegments() ;
219 //____________________________________________________________________________
220 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
222 // Returns pointer to the TrackSegmentMaker task
223 AliPHOSTrackSegmentMaker * rv ;
224 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
227 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
232 //____________________________________________________________________________
233 TClonesArray * AliPHOSGetter::RecParticles()
235 // asks the Loader to return the TrackSegments container
237 TClonesArray * rv = 0 ;
239 rv = PhosLoader()->RecParticles() ;
241 PhosLoader()->MakeRecParticlesArray() ;
242 rv = PhosLoader()->RecParticles() ;
246 //____________________________________________________________________________
247 void AliPHOSGetter::Event(Int_t event, const char* opt)
249 // Reads the content of all Tree's S, D and R
251 if ( event >= MaxEvent() ) {
252 Error("Event", "%d not found in TreeE !", event) ;
256 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
258 // checks if we are dealing with test-beam data
259 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
262 fBTE = new AliPHOSBeamTestEvent() ;
263 btb->SetAddress(&fBTE) ;
264 btb->GetEntry(event) ;
273 // Loads the type of object(s) requested
275 rl->GetEvent(event) ;
277 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
286 if( strstr(opt,"D") )
289 if( strstr(opt,"R") )
292 if( strstr(opt,"T") )
295 if( strstr(opt,"P") )
298 // if( strstr(opt,"Q") )
304 //____________________________________________________________________________
305 Int_t AliPHOSGetter::EventNumber() const
307 // return the current event number
308 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
309 return static_cast<Int_t>(rl->GetEventNumber()) ;
312 //____________________________________________________________________________
313 TClonesArray * AliPHOSGetter::Hits()
315 // asks the loader to return the Hits container
317 TClonesArray * rv = 0 ;
319 rv = PhosLoader()->Hits() ;
321 PhosLoader()->LoadHits("read");
322 rv = PhosLoader()->Hits() ;
327 //____________________________________________________________________________
328 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
330 // Creates and returns the pointer of the unique instance
331 // Must be called only when the environment has changed
333 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
335 if(!fgObjGetter){ // first time the getter is called
336 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
338 else { // the getter has been called previously
339 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
340 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
341 // check if the file is already open
342 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
345 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
347 else { // the file is already open check the version name
348 TString currentVersionName = rl->GetEventFolder()->GetName() ;
349 TString newVersionName(version) ;
350 if (currentVersionName == newVersionName)
352 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
354 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
359 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
360 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
362 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
366 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
374 //____________________________________________________________________________
375 AliPHOSGetter * AliPHOSGetter::Instance()
377 // Returns the pointer of the unique instance already defined
379 if(!fgObjGetter && fgDebug)
380 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
386 //____________________________________________________________________________
387 Int_t AliPHOSGetter::MaxEvent() const
389 // returns the number of events in the run (from TE)
391 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
392 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
395 //____________________________________________________________________________
396 TParticle * AliPHOSGetter::Primary(Int_t index) const
398 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
399 return rl->Stack()->Particle(index) ;
402 //____________________________________________________________________________
403 AliPHOS * AliPHOSGetter:: PHOS() const
405 // returns the PHOS object
406 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
409 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
415 //____________________________________________________________________________
416 AliPHOSPID * AliPHOSGetter::PID()
418 // Returns pointer to the PID task
420 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
423 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
428 //____________________________________________________________________________
429 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
431 // Returns PHOS geometry
433 AliPHOSGeometry * rv = 0 ;
435 rv = PHOS()->GetGeometry() ;
439 //____________________________________________________________________________
440 TClonesArray * AliPHOSGetter::Primaries()
442 // creates the Primaries container if needed
445 Info("Primaries", "Creating a new TClonesArray for primaries") ;
446 fPrimaries = new TClonesArray("TParticle", 1000) ;
451 //____________________________________________________________________________
452 void AliPHOSGetter::Print()
454 // Print usefull information about the getter
456 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
457 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
460 //____________________________________________________________________________
461 void AliPHOSGetter::ReadPrimaries()
463 // Read Primaries from Kinematics.root
465 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
467 // gets kine tree from the root file (Kinematics.root)
468 if ( ! rl->TreeK() ) { // load treeK the first time
469 rl->LoadKinematics() ;
472 fNPrimaries = (rl->GetHeader())->GetNtrack();
474 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
477 // first time creates the container
479 fPrimaries->Clear() ;
482 for (index = 0 ; index < fNPrimaries; index++) {
483 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
487 //____________________________________________________________________________
488 AliESD * AliPHOSGetter::ESD(Int_t event)
494 if ( !OpenESDFile() )
497 TString esdEvent("ESD") ;
499 esd = dynamic_cast<AliESD *>(fESDFile->Get(esdEvent)) ;
503 //____________________________________________________________________________
504 Bool_t AliPHOSGetter::OpenESDFile()
509 fESDFile = TFile::Open(fESDFileName) ;
513 else if (fESDFile->IsOpen()) {
515 fESDFile = TFile::Open(fESDFileName) ;
517 if (!fESDFile->IsOpen())
522 //____________________________________________________________________________
523 Int_t AliPHOSGetter::ReadTreeD()
527 PhosLoader()->CleanDigits() ;
528 // gets TreeD from the root file (PHOS.Digits.root)
529 // if ( !IsLoaded("D") ) {
530 PhosLoader()->LoadDigits("UPDATE") ;
531 PhosLoader()->LoadDigitizer("UPDATE") ;
534 return Digits()->GetEntries() ;
537 //____________________________________________________________________________
538 Int_t AliPHOSGetter::ReadTreeH()
541 PhosLoader()->CleanHits() ;
542 // gets TreeH from the root file (PHOS.Hit.root)
543 //if ( !IsLoaded("H") ) {
544 PhosLoader()->LoadHits("UPDATE") ;
547 return Hits()->GetEntries() ;
550 //____________________________________________________________________________
551 Int_t AliPHOSGetter::ReadTreeR()
553 // Read the RecPoints
555 PhosLoader()->CleanRecPoints() ;
556 // gets TreeR from the root file (PHOS.RecPoints.root)
557 //if ( !IsLoaded("R") ) {
558 PhosLoader()->LoadRecPoints("UPDATE") ;
559 PhosLoader()->LoadClusterizer("UPDATE") ;
563 return EmcRecPoints()->GetEntries() ;
566 //____________________________________________________________________________
567 Int_t AliPHOSGetter::ReadTreeT()
569 // Read the TrackSegments
571 PhosLoader()->CleanTracks() ;
572 // gets TreeT from the root file (PHOS.TrackSegments.root)
573 //if ( !IsLoaded("T") ) {
574 PhosLoader()->LoadTracks("UPDATE") ;
575 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
579 return TrackSegments()->GetEntries() ;
581 //____________________________________________________________________________
582 Int_t AliPHOSGetter::ReadTreeP()
584 // Read the RecParticles
586 PhosLoader()->CleanRecParticles() ;
588 // gets TreeT from the root file (PHOS.TrackSegments.root)
589 // if ( !IsLoaded("P") ) {
590 PhosLoader()->LoadRecParticles("UPDATE") ;
591 PhosLoader()->LoadPID("UPDATE") ;
595 return RecParticles()->GetEntries() ;
597 //____________________________________________________________________________
598 Int_t AliPHOSGetter::ReadTreeS()
602 PhosLoader()->CleanSDigits() ;
603 // gets TreeS from the root file (PHOS.SDigits.root)
604 //if ( !IsLoaded("S") ) {
605 PhosLoader()->LoadSDigits("READ") ;
606 PhosLoader()->LoadSDigitizer("READ") ;
610 return SDigits()->GetEntries() ;
613 //____________________________________________________________________________
614 TClonesArray * AliPHOSGetter::SDigits()
616 // asks the Loader to return the Digits container
618 TClonesArray * rv = 0 ;
620 rv = PhosLoader()->SDigits() ;
622 PhosLoader()->MakeSDigitsArray() ;
623 rv = PhosLoader()->SDigits() ;
628 //____________________________________________________________________________
629 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
631 // Returns pointer to the SDigitizer task
632 AliPHOSSDigitizer * rv ;
633 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
636 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
641 //____________________________________________________________________________
642 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
644 // Return first (index=1) or second (index=2) secondary particle of primary particle p
652 Int_t daughterIndex = p->GetDaughter(index-1) ;
653 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
654 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
660 //____________________________________________________________________________
661 void AliPHOSGetter::Track(Int_t itrack)
663 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
665 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
667 if( !TreeH() ) // load treeH the first time
670 // first time create the container
671 TClonesArray * hits = Hits() ;
675 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
676 phosbranch->SetAddress(&hits) ;
677 phosbranch->GetEntry(itrack) ;
680 //____________________________________________________________________________
681 TTree * AliPHOSGetter::TreeD() const
683 // Returns pointer to the Digits Tree
685 rv = PhosLoader()->TreeD() ;
687 PhosLoader()->MakeTree("D");
688 rv = PhosLoader()->TreeD() ;
694 //____________________________________________________________________________
695 TTree * AliPHOSGetter::TreeH() const
697 // Returns pointer to the Hits Tree
699 rv = PhosLoader()->TreeH() ;
701 PhosLoader()->MakeTree("H");
702 rv = PhosLoader()->TreeH() ;
708 //____________________________________________________________________________
709 TTree * AliPHOSGetter::TreeR() const
711 // Returns pointer to the RecPoints Tree
713 rv = PhosLoader()->TreeR() ;
715 PhosLoader()->MakeTree("R");
716 rv = PhosLoader()->TreeR() ;
722 //____________________________________________________________________________
723 TTree * AliPHOSGetter::TreeT() const
725 // Returns pointer to the TrackSegments Tree
727 rv = PhosLoader()->TreeT() ;
729 PhosLoader()->MakeTree("T");
730 rv = PhosLoader()->TreeT() ;
735 //____________________________________________________________________________
736 TTree * AliPHOSGetter::TreeP() const
738 // Returns pointer to the RecParticles Tree
740 rv = PhosLoader()->TreeP() ;
742 PhosLoader()->MakeTree("P");
743 rv = PhosLoader()->TreeP() ;
749 //____________________________________________________________________________
750 TTree * AliPHOSGetter::TreeS() const
752 // Returns pointer to the SDigits Tree
754 rv = PhosLoader()->TreeS() ;
756 PhosLoader()->MakeTree("S");
757 rv = PhosLoader()->TreeS() ;
763 //____________________________________________________________________________
764 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
766 // checks if the version with the present name already exists in the same directory
770 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
771 TString version( rl->GetEventFolder()->GetName() ) ;
775 if ( opt == "sdigits") {
776 // add the version name to the root file name
777 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
778 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
779 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
780 if ( !(gSystem->AccessPathName(fileName)) ) {
781 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
784 PhosLoader()->SetSDigitsFileName(fileName) ;
787 if ( opt == "digits") {
788 // add the version name to the root file name
789 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
790 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
791 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
792 if ( !(gSystem->AccessPathName(fileName)) ) {
793 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
802 //____________________________________________________________________________
803 UShort_t AliPHOSGetter::EventPattern(void) const
805 // Return the pattern (trigger bit register) of the beam-test event
807 return fBTE->GetPattern() ;
811 //____________________________________________________________________________
812 Float_t AliPHOSGetter::BeamEnergy(void) const
814 // Return the beam energy of the beam-test event
816 return fBTE->GetBeamEnergy() ;