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") ;
107 //____________________________________________________________________________
108 AliPHOSGetter::~AliPHOSGetter()
111 delete fgPhosLoader ;
115 fPrimaries->Delete() ;
124 //____________________________________________________________________________
125 void AliPHOSGetter::Reset()
127 // resets things in case the getter is called consecutively with different files
128 // the PHOS Loader is already deleted by the Run Loader
131 fPrimaries->Delete() ;
138 //____________________________________________________________________________
139 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
141 // Returns pointer to the Clusterizer task
142 AliPHOSClusterizer * rv ;
143 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
146 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
151 //____________________________________________________________________________
152 TObjArray * AliPHOSGetter::CpvRecPoints()
154 // asks the Loader to return the CPV RecPoints container
158 rv = PhosLoader()->CpvRecPoints() ;
160 PhosLoader()->MakeRecPointsArray() ;
161 rv = PhosLoader()->CpvRecPoints() ;
166 //____________________________________________________________________________
167 TClonesArray * AliPHOSGetter::Digits()
169 // asks the Loader to return the Digits container
171 TClonesArray * rv = 0 ;
172 rv = PhosLoader()->Digits() ;
175 PhosLoader()->MakeDigitsArray() ;
176 rv = PhosLoader()->Digits() ;
181 //____________________________________________________________________________
182 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
184 // Returns pointer to the Digitizer task
185 AliPHOSDigitizer * rv ;
186 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
189 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
195 //____________________________________________________________________________
196 TObjArray * AliPHOSGetter::EmcRecPoints()
198 // asks the Loader to return the EMC RecPoints container
202 rv = PhosLoader()->EmcRecPoints() ;
204 PhosLoader()->MakeRecPointsArray() ;
205 rv = PhosLoader()->EmcRecPoints() ;
210 //____________________________________________________________________________
211 TClonesArray * AliPHOSGetter::TrackSegments()
213 // asks the Loader to return the TrackSegments container
215 TClonesArray * rv = 0 ;
217 rv = PhosLoader()->TrackSegments() ;
219 PhosLoader()->MakeTrackSegmentsArray() ;
220 rv = PhosLoader()->TrackSegments() ;
225 //____________________________________________________________________________
226 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
228 // Returns pointer to the TrackSegmentMaker task
229 AliPHOSTrackSegmentMaker * rv ;
230 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
233 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
238 //____________________________________________________________________________
239 TClonesArray * AliPHOSGetter::RecParticles()
241 // asks the Loader to return the TrackSegments container
243 TClonesArray * rv = 0 ;
245 rv = PhosLoader()->RecParticles() ;
247 PhosLoader()->MakeRecParticlesArray() ;
248 rv = PhosLoader()->RecParticles() ;
252 //____________________________________________________________________________
253 void AliPHOSGetter::Event(Int_t event, const char* opt)
255 // Reads the content of all Tree's S, D and R
257 if ( event >= MaxEvent() ) {
258 Error("Event", "%d not found in TreeE !", event) ;
262 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
264 // checks if we are dealing with test-beam data
265 TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
268 fBTE = new AliPHOSBeamTestEvent() ;
269 btb->SetAddress(&fBTE) ;
270 btb->GetEntry(event) ;
279 // Loads the type of object(s) requested
281 rl->GetEvent(event) ;
283 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
292 if( strstr(opt,"D") )
295 if( strstr(opt,"R") )
298 if( strstr(opt,"T") )
301 if( strstr(opt,"P") )
304 if( strstr(opt,"E") )
308 // if( strstr(opt,"Q") )
314 //____________________________________________________________________________
315 Int_t AliPHOSGetter::EventNumber() const
317 // return the current event number
318 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
319 return static_cast<Int_t>(rl->GetEventNumber()) ;
322 //____________________________________________________________________________
323 TClonesArray * AliPHOSGetter::Hits()
325 // asks the loader to return the Hits container
327 TClonesArray * rv = 0 ;
329 rv = PhosLoader()->Hits() ;
331 PhosLoader()->LoadHits("read");
332 rv = PhosLoader()->Hits() ;
337 //____________________________________________________________________________
338 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
340 // Creates and returns the pointer of the unique instance
341 // Must be called only when the environment has changed
343 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
345 if(!fgObjGetter){ // first time the getter is called
346 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
348 else { // the getter has been called previously
349 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
350 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
351 // check if the file is already open
352 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
355 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
357 else { // the file is already open check the version name
358 TString currentVersionName = rl->GetEventFolder()->GetName() ;
359 TString newVersionName(version) ;
360 if (currentVersionName == newVersionName)
362 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
364 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
369 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
370 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
372 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
376 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
384 //____________________________________________________________________________
385 AliPHOSGetter * AliPHOSGetter::Instance()
387 // Returns the pointer of the unique instance already defined
389 if(!fgObjGetter && fgDebug)
390 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
396 //____________________________________________________________________________
397 Int_t AliPHOSGetter::MaxEvent() const
399 // returns the number of events in the run (from TE)
401 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
402 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
405 //____________________________________________________________________________
406 TParticle * AliPHOSGetter::Primary(Int_t index) const
408 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
409 return rl->Stack()->Particle(index) ;
412 //____________________________________________________________________________
413 AliPHOS * AliPHOSGetter:: PHOS() const
415 // returns the PHOS object
416 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
419 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
425 //____________________________________________________________________________
426 AliPHOSPID * AliPHOSGetter::PID()
428 // Returns pointer to the PID task
430 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
433 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
438 //____________________________________________________________________________
439 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
441 // Returns PHOS geometry
443 AliPHOSGeometry * rv = 0 ;
445 rv = PHOS()->GetGeometry() ;
449 //____________________________________________________________________________
450 TClonesArray * AliPHOSGetter::Primaries()
452 // creates the Primaries container if needed
455 Info("Primaries", "Creating a new TClonesArray for primaries") ;
456 fPrimaries = new TClonesArray("TParticle", 1000) ;
461 //____________________________________________________________________________
462 void AliPHOSGetter::Print()
464 // Print usefull information about the getter
466 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
467 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
470 //____________________________________________________________________________
471 void AliPHOSGetter::ReadPrimaries()
473 // Read Primaries from Kinematics.root
475 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
477 // gets kine tree from the root file (Kinematics.root)
478 if ( ! rl->TreeK() ) { // load treeK the first time
479 rl->LoadKinematics() ;
482 fNPrimaries = (rl->GetHeader())->GetNtrack();
484 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
487 // first time creates the container
489 fPrimaries->Clear() ;
492 for (index = 0 ; index < fNPrimaries; index++) {
493 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
497 //____________________________________________________________________________
498 Bool_t AliPHOSGetter::OpenESDFile()
503 fESDFile = TFile::Open(fESDFileName) ;
507 else if (fESDFile->IsOpen()) {
509 fESDFile = TFile::Open(fESDFileName) ;
511 if (!fESDFile->IsOpen())
516 //____________________________________________________________________________
517 Int_t AliPHOSGetter::ReadTreeD()
521 PhosLoader()->CleanDigits() ;
522 // gets TreeD from the root file (PHOS.Digits.root)
523 // if ( !IsLoaded("D") ) {
524 PhosLoader()->LoadDigits("UPDATE") ;
525 PhosLoader()->LoadDigitizer("UPDATE") ;
528 return Digits()->GetEntries() ;
531 //____________________________________________________________________________
532 Int_t AliPHOSGetter::ReadTreeH()
535 PhosLoader()->CleanHits() ;
536 // gets TreeH from the root file (PHOS.Hit.root)
537 //if ( !IsLoaded("H") ) {
538 PhosLoader()->LoadHits("UPDATE") ;
541 return Hits()->GetEntries() ;
544 //____________________________________________________________________________
545 Int_t AliPHOSGetter::ReadTreeR()
547 // Read the RecPoints
549 PhosLoader()->CleanRecPoints() ;
550 // gets TreeR from the root file (PHOS.RecPoints.root)
551 //if ( !IsLoaded("R") ) {
552 PhosLoader()->LoadRecPoints("UPDATE") ;
553 PhosLoader()->LoadClusterizer("UPDATE") ;
557 return EmcRecPoints()->GetEntries() ;
560 //____________________________________________________________________________
561 Int_t AliPHOSGetter::ReadTreeT()
563 // Read the TrackSegments
565 PhosLoader()->CleanTracks() ;
566 // gets TreeT from the root file (PHOS.TrackSegments.root)
567 //if ( !IsLoaded("T") ) {
568 PhosLoader()->LoadTracks("UPDATE") ;
569 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
573 return TrackSegments()->GetEntries() ;
575 //____________________________________________________________________________
576 Int_t AliPHOSGetter::ReadTreeP()
578 // Read the RecParticles
580 PhosLoader()->CleanRecParticles() ;
582 // gets TreeT from the root file (PHOS.TrackSegments.root)
583 // if ( !IsLoaded("P") ) {
584 PhosLoader()->LoadRecParticles("UPDATE") ;
585 PhosLoader()->LoadPID("UPDATE") ;
589 return RecParticles()->GetEntries() ;
591 //____________________________________________________________________________
592 Int_t AliPHOSGetter::ReadTreeS()
596 PhosLoader()->CleanSDigits() ;
597 // gets TreeS from the root file (PHOS.SDigits.root)
598 //if ( !IsLoaded("S") ) {
599 PhosLoader()->LoadSDigits("READ") ;
600 PhosLoader()->LoadSDigitizer("READ") ;
604 return SDigits()->GetEntries() ;
607 //____________________________________________________________________________
608 Int_t AliPHOSGetter::ReadTreeE(Int_t event)
612 // gets esdTree from the root file (AliESDs.root)
614 if ( !OpenESDFile() )
617 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
621 Error("ReadTreeE", "no ESD tree found");
624 fESDTree->SetBranchAddress("ESD", &fESD);
625 fESDTree->GetEvent(event);
630 //____________________________________________________________________________
631 TClonesArray * AliPHOSGetter::SDigits()
633 // asks the Loader to return the Digits container
635 TClonesArray * rv = 0 ;
637 rv = PhosLoader()->SDigits() ;
639 PhosLoader()->MakeSDigitsArray() ;
640 rv = PhosLoader()->SDigits() ;
645 //____________________________________________________________________________
646 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
648 // Returns pointer to the SDigitizer task
649 AliPHOSSDigitizer * rv ;
650 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
653 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
658 //____________________________________________________________________________
659 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
661 // Return first (index=1) or second (index=2) secondary particle of primary particle p
669 Int_t daughterIndex = p->GetDaughter(index-1) ;
670 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
671 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
677 //____________________________________________________________________________
678 void AliPHOSGetter::Track(Int_t itrack)
680 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
682 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
684 if( !TreeH() ) // load treeH the first time
687 // first time create the container
688 TClonesArray * hits = Hits() ;
692 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
693 phosbranch->SetAddress(&hits) ;
694 phosbranch->GetEntry(itrack) ;
697 //____________________________________________________________________________
698 TTree * AliPHOSGetter::TreeD() const
700 // Returns pointer to the Digits Tree
702 rv = PhosLoader()->TreeD() ;
704 PhosLoader()->MakeTree("D");
705 rv = PhosLoader()->TreeD() ;
711 //____________________________________________________________________________
712 TTree * AliPHOSGetter::TreeH() const
714 // Returns pointer to the Hits Tree
716 rv = PhosLoader()->TreeH() ;
718 PhosLoader()->MakeTree("H");
719 rv = PhosLoader()->TreeH() ;
725 //____________________________________________________________________________
726 TTree * AliPHOSGetter::TreeR() const
728 // Returns pointer to the RecPoints Tree
730 rv = PhosLoader()->TreeR() ;
732 PhosLoader()->MakeTree("R");
733 rv = PhosLoader()->TreeR() ;
739 //____________________________________________________________________________
740 TTree * AliPHOSGetter::TreeT() const
742 // Returns pointer to the TrackSegments Tree
744 rv = PhosLoader()->TreeT() ;
746 PhosLoader()->MakeTree("T");
747 rv = PhosLoader()->TreeT() ;
752 //____________________________________________________________________________
753 TTree * AliPHOSGetter::TreeP() const
755 // Returns pointer to the RecParticles Tree
757 rv = PhosLoader()->TreeP() ;
759 PhosLoader()->MakeTree("P");
760 rv = PhosLoader()->TreeP() ;
766 //____________________________________________________________________________
767 TTree * AliPHOSGetter::TreeS() const
769 // Returns pointer to the SDigits Tree
771 rv = PhosLoader()->TreeS() ;
773 PhosLoader()->MakeTree("S");
774 rv = PhosLoader()->TreeS() ;
780 //____________________________________________________________________________
781 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
783 // checks if the version with the present name already exists in the same directory
787 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
788 TString version( rl->GetEventFolder()->GetName() ) ;
792 if ( opt == "sdigits") {
793 // add the version name to the root file name
794 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
795 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
796 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
797 if ( !(gSystem->AccessPathName(fileName)) ) {
798 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
801 PhosLoader()->SetSDigitsFileName(fileName) ;
804 if ( opt == "digits") {
805 // add the version name to the root file name
806 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
807 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
808 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
809 if ( !(gSystem->AccessPathName(fileName)) ) {
810 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
819 //____________________________________________________________________________
820 UShort_t AliPHOSGetter::EventPattern(void) const
822 // Return the pattern (trigger bit register) of the beam-test event
824 return fBTE->GetPattern() ;
828 //____________________________________________________________________________
829 Float_t AliPHOSGetter::BeamEnergy(void) const
831 // Return the beam energy of the beam-test event
833 return fBTE->GetBeamEnergy() ;