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 ---
49 // --- Standard library ---
51 // --- AliRoot header files ---
54 #include "AliEMCALGetter.h"
55 #include "AliEMCALLoader.h"
56 #include "AliHeader.h"
58 #include "AliRunLoader.h"
60 #include "AliEMCALRawStream.h"
61 #include "AliRawReaderFile.h"
63 ClassImp(AliEMCALGetter)
65 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
66 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
67 Int_t AliEMCALGetter::fgDebug = 0;
68 TString AliEMCALGetter::fVersion = "";
70 // TFile * AliEMCALGetter::fgFile = 0 ;
72 //____________________________________________________________________________
73 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
75 // ctor only called by Instance()
77 // initialize data members
85 OpenFile(headerFile,version,openingOption);
89 //____________________________________________________________________________
90 AliEMCALGetter::~AliEMCALGetter()
92 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
99 //____________________________________________________________________________
100 void AliEMCALGetter::OpenFile(const char* headerFile, const char* version, Option_t * openingOption) {
102 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
104 rl = AliRunLoader::Open(headerFile, version, openingOption);
106 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
109 if (rl->GetAliRun() == 0x0) {
111 gAlice = rl->GetAliRun(); // should be removed
114 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
115 if ( !fgEmcalLoader )
116 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
118 fgEmcalLoader->SetTitle(version);
121 //____________________________________________________________________________
122 void AliEMCALGetter::Reset()
124 // resets things in case the getter is called consecutively with different files
125 // the EMCAL Loader is already deleted by the Run Loader
129 //____________________________________________________________________________
130 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
132 // return pointer to Clusterizer Tree
133 AliEMCALClusterizer * rv ;
134 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
137 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
143 //____________________________________________________________________________
144 TClonesArray * AliEMCALGetter::Digits() const
146 // asks the Loader to return the Digits container
148 TClonesArray * rv = 0 ;
149 rv = EmcalLoader()->Digits() ;
152 EmcalLoader()->MakeDigitsArray() ;
153 rv = EmcalLoader()->Digits() ;
158 //____________________________________________________________________________
159 AliEMCALDigitizer * AliEMCALGetter::Digitizer()
161 // return pointer to Digitizer Tree
162 AliEMCALDigitizer * rv ;
163 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
166 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
171 //____________________________________________________________________________
172 TObjArray * AliEMCALGetter::ECARecPoints() const
174 // asks the Loader to return the EMC RecPoints container
178 rv = EmcalLoader()->ECARecPoints() ;
180 EmcalLoader()->MakeRecPointsArray() ;
181 rv = EmcalLoader()->ECARecPoints() ;
186 //____________________________________________________________________________
187 TClonesArray * AliEMCALGetter::TrackSegments() const
189 // asks the Loader to return the TrackSegments container
191 TClonesArray * rv = 0 ;
193 rv = EmcalLoader()->TrackSegments() ;
195 EmcalLoader()->MakeTrackSegmentsArray() ;
196 rv = EmcalLoader()->TrackSegments() ;
201 //____________________________________________________________________________
202 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
204 // return pointer to TrackSegmentMaker Tree
205 AliEMCALTrackSegmentMaker * rv ;
206 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
209 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
214 //____________________________________________________________________________
215 TClonesArray * AliEMCALGetter::RecParticles() const
217 // asks the Loader to return the TrackSegments container
219 TClonesArray * rv = 0 ;
221 rv = EmcalLoader()->RecParticles() ;
223 EmcalLoader()->MakeRecParticlesArray() ;
224 rv = EmcalLoader()->RecParticles() ;
228 //____________________________________________________________________________
229 void AliEMCALGetter::Event(Int_t event, const char* opt)
231 // Reads the content of all Tree's S, D and R
233 if ( event >= MaxEvent() ) {
234 Error("Event", "%d not found in TreeE !", event) ;
238 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
239 // checks if we are dealing with test-beam data
240 // TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
243 // fBTE = new AliEMCALBeamTestEvent() ;
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,"W") )
285 //____________________________________________________________________________
286 Int_t AliEMCALGetter::EventNumber() const
288 // return the current event number
289 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
290 return static_cast<Int_t>(rl->GetEventNumber()) ;
293 //____________________________________________________________________________
294 TClonesArray * AliEMCALGetter::Hits() const
296 // asks the loader to return the Hits container
298 TClonesArray * rv = 0 ;
300 rv = EmcalLoader()->Hits() ;
302 EmcalLoader()->LoadHits("read");
303 rv = EmcalLoader()->Hits() ;
308 //____________________________________________________________________________
309 AliEMCALGetter * AliEMCALGetter::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 if(!fgObjGetter){ // first time the getter is called
315 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
317 else { // the getter has been called previously
318 AliRunLoader * rl = AliRunLoader::GetRunLoader(fVersion);
319 if (rl == 0) fgObjGetter->OpenFile(alirunFileName, version, openingOption) ;
320 else if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
321 // check if the file is already open
322 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
325 fgObjGetter->OpenFile(alirunFileName, version, openingOption);
327 else { // the file is already open check the version name
328 TString currentVersionName = rl->GetEventFolder()->GetName() ;
329 TString newVersionName(version) ;
330 if (currentVersionName == newVersionName)
332 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
334 fgEmcalLoader->SetTitle(version); fVersion = version;
339 AliRunLoader * rl = AliRunLoader::GetRunLoader(fVersion);
340 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
342 fgObjGetter->OpenFile(alirunFileName, version, openingOption) ;
346 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
354 //____________________________________________________________________________
355 AliEMCALGetter * AliEMCALGetter::Instance()
357 // Returns the pointer of the unique instance already defined
359 if(!fgObjGetter && fgDebug)
360 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
366 //____________________________________________________________________________
367 Int_t AliEMCALGetter::MaxEvent() const
369 // returns the number of events in the run (from TE)
371 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
372 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
375 //____________________________________________________________________________
376 TParticle * AliEMCALGetter::Primary(Int_t index) const
378 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
379 return rl->Stack()->Particle(index) ;
382 //____________________________________________________________________________
383 Int_t AliEMCALGetter::NPrimaries() const
385 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
386 return (rl->GetHeader())->GetNtrack();
389 //____________________________________________________________________________
390 AliEMCAL * AliEMCALGetter:: EMCAL() const
392 // returns the EMCAL object
393 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
396 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
402 //____________________________________________________________________________
403 AliEMCALPID * AliEMCALGetter::PID()
405 // return pointer to PID Tree
407 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
410 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
415 //____________________________________________________________________________
416 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
418 // Returns EMCAL geometry
420 AliEMCALGeometry * rv = 0 ;
422 rv = EMCAL()->GetGeometry() ;
426 //____________________________________________________________________________
427 void AliEMCALGetter::Print()
429 // Print usefull information about the getter
431 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
432 ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
435 //____________________________________________________________________________
436 void AliEMCALGetter::ReadPrimaries()
438 // Read Primaries from Kinematics.root
440 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
442 // gets kine tree from the root file (Kinematics.root)
443 if ( ! rl->TreeK() ) // load treeK the first time
444 rl->LoadKinematics() ;
447 Info("ReadTreeK", "Found %d particles in event # %d", NPrimaries(), EventNumber() ) ;
450 //____________________________________________________________________________
451 Int_t AliEMCALGetter::ReadRaw(Int_t event)
453 // reads the raw format data, converts it into digits format and store digits in Digits()
456 AliRawReaderFile rawReader(event) ;
457 AliEMCALRawStream in(&rawReader);
459 const Int_t kHighGainIdOffset = EMCALGeometry()->GetNTowers()
460 * EMCALGeometry()->GetNPhi()
461 * EMCALGeometry()->GetNZ()
464 Bool_t first = kTRUE ;
466 TH1D hLowGain("hLowGain", "Low Gain", 1000, 0., EMCAL()->GetRawFormatTimeMax()) ;
467 TH1D hHighGain("hHighGain", "High Gain", 1000, 0., EMCAL()->GetRawFormatTimeMax()) ;
469 // fit half the gaussian decay rather than AliEMCAL::RawResponseFunction because thiswould give a floating point
470 // exception during error calculation ... To solve...
471 TF1 * gauss = new TF1("gauss", "gaus",
472 EMCAL()->GetRawFormatTimePeak(),
473 EMCAL()->GetRawFormatTimeMax() ) ;
476 Bool_t hgflag = kFALSE ;
478 TClonesArray * digits = Digits() ;
482 while ( in.Next() ) { // EMCAL entries loop
484 if ( in.IsNewId() ) {
486 hLowGain.Fit(gauss, "QRON") ;
487 Int_t ampL = static_cast<Int_t>(gauss->Eval(gauss->GetParameter(2)) + 0.5) ;
488 Double_t timeL = EMCAL()->GetRawFormatTimePeak() - gauss->GetParameter(2) ;
489 if (timeL < 0 ) // happens with noise
490 timeL = EMCAL()->GetRawFormatTimePeak() ;
492 hHighGain.Fit(gauss, "QRON") ;
493 Int_t ampH = static_cast<Int_t>(gauss->Eval(gauss->GetParameter(2)) + 0.5) ;
494 Double_t timeH = EMCAL()->GetRawFormatTimePeak() - gauss->GetParameter(2) ;
495 if (timeH < 0 ) // happens with noise
496 timeH = EMCAL()->GetRawFormatTimePeak() ;
497 new((*digits)[idigit]) AliEMCALDigit( -1, -1, id+kHighGainIdOffset, ampH, timeH) ;
501 new((*digits)[idigit]) AliEMCALDigit( -1, -1, id, ampL, timeL) ;
509 if (id > 9999 ) { // fixme
516 in.GetTime() * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(),
517 in. GetSignal() * EMCAL()->GetRawFormatHighGainFactor() ) ;
520 in.GetTime() * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(),
522 } // EMCAL entries loop
526 return Digits()->GetEntriesFast() ;
529 //____________________________________________________________________________
530 Int_t AliEMCALGetter::ReadTreeD()
534 EmcalLoader()->CleanDigits() ;
535 // gets TreeD from the root file (EMCAL.Digits.root)
536 //if ( !IsLoaded("D") ) {
537 EmcalLoader()->LoadDigits("UPDATE") ;
538 EmcalLoader()->LoadDigitizer("UPDATE") ;
541 return Digits()->GetEntries() ;
544 //____________________________________________________________________________
545 Int_t AliEMCALGetter::ReadTreeH()
548 EmcalLoader()->CleanHits() ;
549 // gets TreeH from the root file (EMCAL.Hit.root)
550 //if ( !IsLoaded("H") ) {
551 EmcalLoader()->LoadHits("READ") ;
554 return Hits()->GetEntries() ;
557 //____________________________________________________________________________
558 Int_t AliEMCALGetter::ReadTreeR()
560 // Read the RecPoints
562 EmcalLoader()->CleanRecPoints() ;
563 // gets TreeR from the root file (EMCAL.RecPoints.root)
564 //if ( !IsLoaded("R") ) {
565 EmcalLoader()->LoadRecPoints("UPDATE") ;
566 EmcalLoader()->LoadClusterizer("UPDATE") ;
570 return ECARecPoints()->GetEntries() ;
573 //____________________________________________________________________________
574 Int_t AliEMCALGetter::ReadTreeT()
576 // Read the TrackSegments
578 EmcalLoader()->CleanTracks() ;
579 // gets TreeT from the root file (EMCAL.TrackSegments.root)
580 //if ( !IsLoaded("T") ) {
581 EmcalLoader()->LoadTracks("UPDATE") ;
582 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
586 return TrackSegments()->GetEntries() ;
588 //____________________________________________________________________________
589 Int_t AliEMCALGetter::ReadTreeP()
591 // Read the RecParticles
593 EmcalLoader()->CleanRecParticles() ;
594 // gets TreeP from the root file (EMCAL.RecParticles.root)
595 // if ( !IsLoaded("P") ) {
596 EmcalLoader()->LoadRecParticles("UPDATE") ;
597 EmcalLoader()->LoadPID("UPDATE") ;
601 return RecParticles()->GetEntries() ;
603 //____________________________________________________________________________
604 Int_t AliEMCALGetter::ReadTreeS()
608 // EmcalLoader()->CleanSDigits() ;
609 // gets TreeS from the root file (EMCAL.SDigits.root)
610 // if ( !IsLoaded("S") ) {
611 EmcalLoader()->LoadSDigits("READ") ;
612 EmcalLoader()->LoadSDigitizer("READ") ;
616 return SDigits()->GetEntries() ;
619 //____________________________________________________________________________
620 TClonesArray * AliEMCALGetter::SDigits() const
622 // asks the Loader to return the Digits container
624 TClonesArray * rv = 0 ;
626 rv = EmcalLoader()->SDigits() ;
628 EmcalLoader()->MakeSDigitsArray() ;
629 rv = EmcalLoader()->SDigits() ;
634 //____________________________________________________________________________
635 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
637 // Return pointer to SDigitizer task
638 AliEMCALSDigitizer * rv ;
639 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
642 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
647 //____________________________________________________________________________
648 TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
650 // Return first (index=1) or second (index=2) secondary particle of primary particle p
658 Int_t daughterIndex = p->GetDaughter(index-1) ;
659 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
660 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
666 //____________________________________________________________________________
667 void AliEMCALGetter::Track(Int_t itrack)
669 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
671 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
673 if( !TreeH() ) // load treeH the first time
676 // first time create the container
677 TClonesArray * hits = Hits() ;
681 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
682 emcalbranch->SetAddress(&hits) ;
683 emcalbranch->GetEntry(itrack) ;
686 //____________________________________________________________________________
687 TTree * AliEMCALGetter::TreeD() const
689 // return pointer to Digits Tree
691 rv = EmcalLoader()->TreeD() ;
693 EmcalLoader()->MakeTree("D");
694 rv = EmcalLoader()->TreeD() ;
700 //____________________________________________________________________________
701 TTree * AliEMCALGetter::TreeH() const
703 // return pointer to Hits Tree
705 rv = EmcalLoader()->TreeH() ;
707 EmcalLoader()->MakeTree("H");
708 rv = EmcalLoader()->TreeH() ;
714 //____________________________________________________________________________
715 TTree * AliEMCALGetter::TreeR() const
717 // return pointer to RecPoints Tree
720 rv = EmcalLoader()->TreeR() ;
722 EmcalLoader()->MakeTree("R");
723 rv = EmcalLoader()->TreeR() ;
729 //____________________________________________________________________________
730 TTree * AliEMCALGetter::TreeT() const
732 // return pointer to TrackSegments Tree
734 rv = EmcalLoader()->TreeT() ;
736 EmcalLoader()->MakeTree("T");
737 rv = EmcalLoader()->TreeT() ;
742 //____________________________________________________________________________
743 TTree * AliEMCALGetter::TreeP() const
745 // return pointer to RecParticles Tree
747 rv = EmcalLoader()->TreeP() ;
749 EmcalLoader()->MakeTree("P");
750 rv = EmcalLoader()->TreeP() ;
756 //____________________________________________________________________________
757 TTree * AliEMCALGetter::TreeS() const
759 // return pointer to SDigits Tree
761 rv = EmcalLoader()->TreeS() ;
763 EmcalLoader()->MakeTree("S");
764 rv = EmcalLoader()->TreeS() ;
770 //____________________________________________________________________________
771 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
773 // checks if the version with the present name already exists in the same directory
777 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
778 TString version( rl->GetEventFolder()->GetName() ) ;
782 if ( opt == "sdigits") {
783 // add the version name to the root file name
784 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
785 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
786 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
787 if ( !(gSystem->AccessPathName(fileName)) ) {
788 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
791 EmcalLoader()->SetSDigitsFileName(fileName) ;
794 if ( opt == "digits") {
795 // add the version name to the root file name
796 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
797 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
798 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
799 if ( !(gSystem->AccessPathName(fileName)) ) {
800 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
809 //____________________________________________________________________________
810 UShort_t AliEMCALGetter::EventPattern(void) const
812 // Return the pattern (trigger bit register) of the beam-test event
814 // return fBTE->GetPattern() ;
818 //____________________________________________________________________________
819 Float_t AliEMCALGetter::BeamEnergy(void) const
821 // Return the beam energy of the beam-test event
823 // return fBTE->GetBeamEnergy() ;