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 AliEMCALAnalyser):
28 // AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
29 // for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
30 // AliEMCALRecParticle * 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 AliEMCALIndexToObject and make
38 //*-- systematic usage of TFolders without changing the interface
39 //////////////////////////////////////////////////////////////////////////////
41 // --- ROOT system ---
47 // --- Standard library ---
49 // --- AliRoot header files ---
51 #include "AliEMCALGetter.h"
53 #include "AliRunLoader.h"
55 #include "AliHeader.h"
56 #include "AliEMCALLoader.h"
59 ClassImp(AliEMCALGetter)
61 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
62 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
63 Int_t AliEMCALGetter::fgDebug = 0;
65 // TFile * AliEMCALGetter::fgFile = 0 ;
67 //____________________________________________________________________________
68 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
70 // ctor only called by Instance()
72 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
74 rl = AliRunLoader::Open(headerFile, version, openingOption);
76 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
79 if (rl->GetAliRun() == 0x0) {
81 gAlice = rl->GetAliRun(); // should be removed
84 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
86 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
88 fgEmcalLoader->SetTitle(version);
91 // initialize data members
98 //____________________________________________________________________________
99 AliEMCALGetter::~AliEMCALGetter()
102 delete fgEmcalLoader ;
106 fPrimaries->Delete() ;
110 //____________________________________________________________________________
111 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
113 // return pointer to Clusterizer Tree
114 AliEMCALClusterizer * rv ;
115 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
118 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
124 //____________________________________________________________________________
125 TClonesArray * AliEMCALGetter::Digits() const
127 // asks the Loader to return the Digits container
129 TClonesArray * rv = 0 ;
130 rv = EmcalLoader()->Digits() ;
133 EmcalLoader()->MakeDigitsArray() ;
134 rv = EmcalLoader()->Digits() ;
139 //____________________________________________________________________________
140 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
142 // return pointer to Digitizer Tree
143 AliEMCALDigitizer * rv ;
144 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
147 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
152 //____________________________________________________________________________
153 TObjArray * AliEMCALGetter::ECARecPoints() const
155 // asks the Loader to return the EMC RecPoints container
159 rv = EmcalLoader()->ECARecPoints() ;
161 EmcalLoader()->MakeRecPointsArray() ;
162 rv = EmcalLoader()->ECARecPoints() ;
167 //____________________________________________________________________________
168 TClonesArray * AliEMCALGetter::TrackSegments() const
170 // asks the Loader to return the TrackSegments container
172 TClonesArray * rv = 0 ;
174 rv = EmcalLoader()->TrackSegments() ;
176 EmcalLoader()->MakeTrackSegmentsArray() ;
177 rv = EmcalLoader()->TrackSegments() ;
182 //____________________________________________________________________________
183 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
185 // return pointer to TrackSegmentMaker Tree
186 AliEMCALTrackSegmentMaker * rv ;
187 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
190 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
195 //____________________________________________________________________________
196 TClonesArray * AliEMCALGetter::RecParticles() const
198 // asks the Loader to return the TrackSegments container
200 TClonesArray * rv = 0 ;
202 rv = EmcalLoader()->RecParticles() ;
204 EmcalLoader()->MakeRecParticlesArray() ;
205 rv = EmcalLoader()->RecParticles() ;
209 //____________________________________________________________________________
210 void AliEMCALGetter::Event(Int_t event, const char* opt)
212 // Reads the content of all Tree's S, D and R
214 if ( event >= MaxEvent() ) {
215 Error("Event", "%d not found in TreeE !", event) ;
219 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
220 // checks if we are dealing with test-beam data
221 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
224 // fBTE = new AliEMCALBeamTestEvent() ;
225 // btb->SetAddress(&fBTE) ;
226 // btb->GetEntry(event) ;
235 // Loads the type of object(s) requested
237 rl->GetEvent(event) ;
239 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
248 if( strstr(opt,"D") )
251 if( strstr(opt,"R") )
254 if( strstr(opt,"T") )
257 if( strstr(opt,"P") )
263 //____________________________________________________________________________
264 Int_t AliEMCALGetter::EventNumber() const
266 // return the current event number
267 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
268 return static_cast<Int_t>(rl->GetEventNumber()) ;
271 //____________________________________________________________________________
272 TClonesArray * AliEMCALGetter::Hits() const
274 // asks the loader to return the Hits container
276 TClonesArray * rv = 0 ;
278 rv = EmcalLoader()->Hits() ;
280 EmcalLoader()->LoadHits("read");
281 rv = EmcalLoader()->Hits() ;
286 //____________________________________________________________________________
287 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
289 // Creates and returns the pointer of the unique instance
290 // Must be called only when the environment has changed
292 if(!fgObjGetter){ // first time the getter is called
293 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
295 else { // the getter has been called previously
296 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
297 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
298 // check if the file is already open
299 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
302 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
304 else { // the file is already open check the version name
305 TString currentVersionName = rl->GetEventFolder()->GetName() ;
306 TString newVersionName(version) ;
307 if (currentVersionName == newVersionName)
309 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
311 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
316 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
317 if ( strstr(version, AliConfig::fgkDefaultEventFolderName) ) // false in case of merging
319 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
323 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
331 //____________________________________________________________________________
332 AliEMCALGetter * AliEMCALGetter::Instance()
334 // Returns the pointer of the unique instance already defined
336 if(!fgObjGetter && fgDebug)
337 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
343 //____________________________________________________________________________
344 Int_t AliEMCALGetter::MaxEvent() const
346 // returns the number of events in the run (from TE)
348 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
349 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
352 //____________________________________________________________________________
353 TParticle * AliEMCALGetter::Primary(Int_t index) const
355 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
356 return rl->Stack()->Particle(index) ;
359 //____________________________________________________________________________
360 AliEMCAL * AliEMCALGetter:: EMCAL() const
362 // returns the EMCAL object
363 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
366 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
372 //____________________________________________________________________________
373 AliEMCALPID * AliEMCALGetter::PID()
375 // return pointer to PID Tree
377 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
380 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
385 //____________________________________________________________________________
386 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
388 // Returns EMCAL geometry
390 AliEMCALGeometry * rv = 0 ;
392 rv = EMCAL()->GetGeometry() ;
396 //____________________________________________________________________________
397 TClonesArray * AliEMCALGetter::Primaries()
399 // creates the Primaries container if needed
402 Info("Primaries", "Creating a new TClonesArray for primaries") ;
403 fPrimaries = new TClonesArray("TParticle", 1000) ;
408 //____________________________________________________________________________
409 void AliEMCALGetter::Print()
411 // Print usefull information about the getter
413 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
414 ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
417 //____________________________________________________________________________
418 void AliEMCALGetter::ReadPrimaries()
420 // Read Primaries from Kinematics.root
422 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
424 // gets kine tree from the root file (Kinematics.root)
425 if ( ! rl->TreeK() ) // load treeK the first time
426 rl->LoadKinematics() ;
428 fNPrimaries = (rl->GetHeader())->GetNtrack();
430 Info("ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
432 // first time creates the container
434 fPrimaries->Clear() ;
437 for (index = 0 ; index < fNPrimaries; index++) {
438 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
442 //____________________________________________________________________________
443 Int_t AliEMCALGetter::ReadTreeD()
448 // gets TreeD from the root file (EMCAL.SDigits.root)
449 if ( !IsLoaded("D") ) {
450 EmcalLoader()->LoadDigits("UPDATE") ;
451 EmcalLoader()->LoadDigitizer("UPDATE") ;
454 return Digits()->GetEntries() ;
457 //____________________________________________________________________________
458 Int_t AliEMCALGetter::ReadTreeH()
462 // gets TreeH from the root file (EMCAL.Hit.root)
463 if ( !IsLoaded("H") ) {
464 EmcalLoader()->LoadHits("UPDATE") ;
467 return Hits()->GetEntries() ;
470 //____________________________________________________________________________
471 Int_t AliEMCALGetter::ReadTreeR()
473 // Read the RecPoints
476 // gets TreeR from the root file (EMCAL.RecPoints.root)
477 if ( !IsLoaded("R") ) {
478 EmcalLoader()->LoadRecPoints("UPDATE") ;
479 EmcalLoader()->LoadClusterizer("UPDATE") ;
483 return ECARecPoints()->GetEntries() ;
486 //____________________________________________________________________________
487 Int_t AliEMCALGetter::ReadTreeT()
489 // Read the TrackSegments
492 // gets TreeT from the root file (EMCAL.TrackSegments.root)
493 if ( !IsLoaded("T") ) {
494 EmcalLoader()->LoadTracks("UPDATE") ;
495 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
499 return TrackSegments()->GetEntries() ;
501 //____________________________________________________________________________
502 Int_t AliEMCALGetter::ReadTreeP()
504 // Read the TrackSegments
507 // gets TreeT from the root file (EMCAL.TrackSegments.root)
508 if ( !IsLoaded("P") ) {
509 EmcalLoader()->LoadRecParticles("UPDATE") ;
510 EmcalLoader()->LoadPID("UPDATE") ;
514 return RecParticles()->GetEntries() ;
516 //____________________________________________________________________________
517 Int_t AliEMCALGetter::ReadTreeS()
522 // gets TreeS from the root file (EMCAL.SDigits.root)
523 if ( !IsLoaded("S") ) {
524 EmcalLoader()->LoadSDigits("UPDATE") ;
525 EmcalLoader()->LoadSDigitizer("UPDATE") ;
529 return SDigits()->GetEntries() ;
532 //____________________________________________________________________________
533 TClonesArray * AliEMCALGetter::SDigits() const
535 // asks the Loader to return the Digits container
537 TClonesArray * rv = 0 ;
539 rv = EmcalLoader()->SDigits() ;
541 EmcalLoader()->MakeSDigitsArray() ;
542 rv = EmcalLoader()->SDigits() ;
547 //____________________________________________________________________________
548 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
550 // Return pointer to SDigitizer task
551 AliEMCALSDigitizer * rv ;
552 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
555 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
560 //____________________________________________________________________________
561 TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
563 // Return first (index=1) or second (index=2) secondary particle of primary particle p
571 Int_t daughterIndex = p->GetDaughter(index-1) ;
572 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
573 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
579 //____________________________________________________________________________
580 void AliEMCALGetter::Track(Int_t itrack)
582 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
584 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
586 if( !TreeH() ) // load treeH the first time
589 // first time create the container
590 TClonesArray * hits = Hits() ;
594 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
595 emcalbranch->SetAddress(&hits) ;
596 emcalbranch->GetEntry(itrack) ;
599 //____________________________________________________________________________
600 TTree * AliEMCALGetter::TreeD() const
602 // return pointer to Digits Tree
604 rv = EmcalLoader()->TreeD() ;
606 EmcalLoader()->MakeTree("D");
607 rv = EmcalLoader()->TreeD() ;
613 //____________________________________________________________________________
614 TTree * AliEMCALGetter::TreeH() const
616 // return pointer to Hits Tree
618 rv = EmcalLoader()->TreeH() ;
620 EmcalLoader()->MakeTree("H");
621 rv = EmcalLoader()->TreeH() ;
627 //____________________________________________________________________________
628 TTree * AliEMCALGetter::TreeR() const
630 // return pointer to RecPoints Tree
633 rv = EmcalLoader()->TreeR() ;
635 EmcalLoader()->MakeTree("R");
636 rv = EmcalLoader()->TreeR() ;
642 //____________________________________________________________________________
643 TTree * AliEMCALGetter::TreeT() const
645 // return pointer to TrackSegments Tree
647 rv = EmcalLoader()->TreeT() ;
649 EmcalLoader()->MakeTree("T");
650 rv = EmcalLoader()->TreeT() ;
655 //____________________________________________________________________________
656 TTree * AliEMCALGetter::TreeP() const
658 // return pointer to RecParticles Tree
660 rv = EmcalLoader()->TreeP() ;
662 EmcalLoader()->MakeTree("P");
663 rv = EmcalLoader()->TreeP() ;
669 //____________________________________________________________________________
670 TTree * AliEMCALGetter::TreeS() const
672 // return pointer to SDigits Tree
674 rv = EmcalLoader()->TreeS() ;
676 EmcalLoader()->MakeTree("S");
677 rv = EmcalLoader()->TreeS() ;
683 //____________________________________________________________________________
684 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
686 // checks if the version with the present name already exists in the same directory
690 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
691 TString version( rl->GetEventFolder()->GetName() ) ;
695 if ( opt == "sdigits") {
696 // add the version name to the root file name
697 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
698 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
699 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
700 if ( !(gSystem->AccessPathName(fileName)) ) {
701 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
704 EmcalLoader()->SetSDigitsFileName(fileName) ;
707 if ( opt == "digits") {
708 // add the version name to the root file name
709 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
710 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
711 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
712 if ( !(gSystem->AccessPathName(fileName)) ) {
713 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
722 //____________________________________________________________________________
723 UShort_t AliEMCALGetter::EventPattern(void) const
725 // Return the pattern (trigger bit register) of the beam-test event
727 // return fBTE->GetPattern() ;
731 //____________________________________________________________________________
732 Float_t AliEMCALGetter::BeamEnergy(void) const
734 // Return the beam energy of the beam-test event
736 // return fBTE->GetBeamEnergy() ;