]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.h
eb2f38bf099760c7b267143fd12caf1fef534cf0
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.h
1 #ifndef ALIEMCALGETTER_H
2 #define ALIEMCALGETTER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5 /* $Id$ */
6 //________________________________________________________________________
7 //  A singleton that returns various objects 
8 //  Should be used on the analysis stage to avoid confusing between different
9 //  branches of reconstruction tree: e.g. reading RecPoints and TS made from 
10 //  another set of RecPoints.
11 // 
12 //  The objects are retrived from folders.  
13 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
14 //    
15
16 // Modif: 
17 //  August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
18 //                           of new  IO (à la PHOS)
19  
20 // --- ROOT system ---
21 #include "TClonesArray.h"
22 #include "TFolder.h"  
23 #include "TTree.h"
24 #include "TFile.h"
25 class TString ;
26 class TParticle ;
27 class TTask ;
28
29 // --- Standard library ---
30 #include <stdlib.h>
31
32 // --- AliRoot header files ---
33 #include "AliRun.h"
34 #include "AliEMCAL.h" 
35 #include "AliEMCALHit.h" 
36 #include "AliEMCALDigit.h" 
37 #include "AliEMCALTowerRecPoint.h"
38 class AliEMCALGeometry ;
39 #include "AliEMCALDigitizer.h" 
40 #include "AliEMCALSDigitizer.h"
41 class AliEMCALClusterizer ;
42 #include "AliEMCALTrackSegment.h" 
43 class AliEMCALTrackSegmentMaker ;
44 #include "AliEMCALRecParticle.h" 
45 class AliEMCALPID ;
46
47 class AliEMCALGetter : public TObject {
48   
49  public:
50   
51   AliEMCALGetter(){  // ctor: this is a singleton, the ctor should never be called but cint needs it as public
52     Fatal("ctor", "singleton: default ctor not callable") ;
53   } 
54   AliEMCALGetter(const AliEMCALGetter & obj) {
55     // cpy ctor requested by Coding Convention 
56     // but not yet needed
57     Fatal("cpy ctor", "not implemented") ;  
58   } 
59   
60   AliEMCALGetter & operator = (const AliEMCALGetter & ) {
61     // assignement operator requested by coding convention, but not needed
62     Fatal("operator =", "not implemented") ;  
63     return *this ; 
64   }
65   virtual ~AliEMCALGetter() ; 
66   
67   //=========== Instantiators ================  
68   static AliEMCALGetter * GetInstance(const char* headerFile,
69                                       const char* branchTitle = "Default", 
70                                       const Bool_t toSplit = kFALSE ) ; 
71   static AliEMCALGetter * GetInstance() ; 
72  
73   //=========== General information about run ============== 
74   const Int_t  MaxEvent() const    { return static_cast<Int_t>(gAlice->TreeE()->GetEntries()) ; }
75   const Int_t  EventNumber() const { return static_cast<Int_t>(gAlice->GetEvNumber()) ; }
76   const Bool_t BranchExists(const TString recName) const ;
77
78   //========== EMCALGeometry and EMCAL ============= 
79   const AliEMCAL *   EMCAL() ;  
80   AliEMCALGeometry * EMCALGeometry() ; 
81
82   //========== Methods to read somethig from file ==========
83   void   Event(const Int_t event, const char * opt = "HSDRP") ;    
84   void   Track(const Int_t itrack) ;
85   void   ReadTreeS(TTree * treeS,Int_t input) ; //Method to be used when 
86                                                 //digitizing is under the conytrol of AliRunDigitizer, 
87                                                 //which opens all files etc.
88   //-----------------now getter's data--------------------------------------
89
90   //=========== Primaries ============
91   TTree *           TreeK(TString filename="") ; 
92   TClonesArray *    Primaries(void) const { return dynamic_cast<TClonesArray*>(ReturnO("Primaries")) ; }
93   const TParticle * Primary(Int_t index) const;
94   const Int_t       NPrimaries()const { return fNPrimaries; }
95   const TParticle * Secondary(TParticle * p, Int_t index=1) const ;  
96
97   //=========== Hits =================
98   TTree *               TreeH(TString filename="") ; 
99   const TClonesArray *  Hits(void) { return dynamic_cast<const TClonesArray*>(ReturnO("Hits")) ; }
100   const AliEMCALHit *   Hit(Int_t index) { return dynamic_cast<const AliEMCALHit*>(Hits()->At(index) );}
101
102   //=========== SDigits ==============
103   TTree *         TreeS(TString filename="") ; 
104   TClonesArray *  SDigits(const char * name = 0, const char * file=0) { 
105     return dynamic_cast<TClonesArray*>(ReturnO("SDigits", name, file)) ; }
106   const AliEMCALDigit *  SDigit(Int_t index) { return static_cast<const AliEMCALDigit*>(SDigits()->At(index)) ;}
107   const AliEMCALSDigitizer *  SDigitizer(const char * name =0) const { 
108     return (const AliEMCALSDigitizer*)(ReturnT("SDigitizer", name)) ; // here static or dynamic cast does not work ! why ?
109   }
110
111   //========== Digits ================
112   TTree *         TreeD(TString filename="") ; 
113   TClonesArray *  Digits(const char * name = 0)const  { 
114     return dynamic_cast<TClonesArray*>(ReturnO("Digits", name)) ; }
115   const AliEMCALDigit *  Digit(Int_t index) { return static_cast<const AliEMCALDigit *>(Digits()->At(index)) ;}
116   const AliEMCALDigitizer *  Digitizer(const char * name =0) const { 
117     return (const AliEMCALDigitizer*)(ReturnT("Digitizer", name)) ; }
118       
119   //========== RecPoints =============
120   TObjArray * PRERecPoints(const char * name = 0) const { 
121     return (dynamic_cast<TObjArray*>(ReturnO("PRERecPoints", name))) ; }
122   const AliEMCALRecPoint *  PRERecPoint(Int_t index) { return static_cast<const AliEMCALRecPoint *>(PRERecPoints()->At(index)) ;}
123   TObjArray * ECALRecPoints(const char * name = 0) const { 
124     return (dynamic_cast<TObjArray*>(ReturnO("ECALRecPoints", name))) ; }
125   const AliEMCALTowerRecPoint *  ECALRecPoint(Int_t index) { return static_cast<const AliEMCALTowerRecPoint *>(ECALRecPoints()->At(index)) ;}
126   TObjArray * HCALRecPoints(const char * name = 0) const { 
127     return (dynamic_cast<TObjArray*>(ReturnO("HCALRecPoints", name))) ; }
128   const AliEMCALTowerRecPoint *  HCALRecPoint(Int_t index) { return static_cast<const AliEMCALTowerRecPoint *>(HCALRecPoints()->At(index)) ;}
129
130   const AliEMCALClusterizer * Clusterizer (const char * name =0) const { 
131     return (const AliEMCALClusterizer*)(ReturnT("Clusterizer", name)) ;// here static or dynamic cast does not work ! why ?
132   }
133
134   //========== TrackSegments =============
135   TClonesArray * TrackSegments(const char * name = 0) const { 
136     return static_cast<TClonesArray*>(ReturnO("TrackSegments", name)) ; }
137   const AliEMCALTrackSegment *  TrackSegment(Int_t index) { return static_cast<const AliEMCALTrackSegment *>(TrackSegments()->At(index)) ;}
138
139   const AliEMCALTrackSegmentMaker * TrackSegmentMaker (const char * name =0) const { 
140     return (const AliEMCALTrackSegmentMaker*)(ReturnT("TrackSegmentMaker", name)) ;// here static or dynamic cast does not work ! why ?
141   }
142
143   //========== RecParticles ===========
144   TClonesArray * RecParticles(const char * name = 0) { 
145     return static_cast<TClonesArray*>(ReturnO("RecParticles", name)) ;   }
146   const AliEMCALPID * PID(const char * name =0) const { 
147     return (const AliEMCALPID*)(ReturnT("PID", name)) ; } // here static or dynamic cast does not work ! why ? 
148
149   //-----------------Auxiliary methods: cleaners-----------------
150   void RemoveTask(TString opt, TString name) const ;
151   void RemoveObjects(TString opt, TString name) const ; 
152   void RemoveSDigits() const ; 
153
154  //-----------------Auxiliary methods: miscellana-----------------
155   void CloseFile() ;  
156   const TFolder * Folder(const TString what) const ;
157   const Bool_t HasFailed(void) const {return fFailed ;} 
158   void ListBranches(Int_t event=0) const ;
159   void NewBranch(TString name, Int_t event = 0) ; 
160   Bool_t NewFile(TString name) ;
161   TFolder * SDigitsFolder() { return dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; }
162   void SetDebug(Int_t level) {fDebug = level;} // Set debug level
163   void SetRecParticlesTitle(const TString title) { fRecParticlesTitle = title ; }
164
165   //------------Auxiliary methods: Posters--------------------
166   const Bool_t PostPrimaries(void ) const ;  
167   const Bool_t PostHits(void ) const ;  
168   const Bool_t PostSDigits(      const char * name,  const char * file = 0) const ;  
169   const Bool_t PostDigits(       const char * name ) const ;  
170   const Bool_t PostRecPoints(    const char * name ) const ;  
171   const Bool_t PostTrackSegments(const char * name) const ;  
172   const Bool_t PostRecParticles( const char * name) const ;  
173   const Bool_t PostClusterizer( const char * name) const ;  
174   const Bool_t PostClusterizer(AliEMCALClusterizer * clu) const ;  
175   const Bool_t PostSDigitizer (AliEMCALSDigitizer * sdigitizer) const ;  
176   const Bool_t PostSDigitizer ( const char * name, const char * file ) const ;  
177   const Bool_t PostDigitizer (AliEMCALDigitizer * digitizer) const ;  
178   const Bool_t PostDigitizer  ( const char * name) const ;  
179   const Bool_t PostTrackSegmentMaker(AliEMCALTrackSegmentMaker * tsm) const ;  
180   const Bool_t PostTrackSegmentMaker(const char * name ) const ;  
181   const Bool_t PostPID  (AliEMCALPID * pid) const ;  
182   const Bool_t PostPID  (const char * name ) const ;  
183
184 private:
185
186   AliEMCALGetter(const char* headerFile, const char* branchTitle ="Default", const Bool_t toSplit = kFALSE) ; 
187   TObject * ReturnO(TString what, TString name=0, TString file=0) const ; 
188   const TTask * ReturnT(TString what,TString name=0) const ; 
189   void DefineBranchTitles(char* branch, char* branchTitle) ;
190   Int_t ReadTreeD(const Int_t event) ;
191   Int_t ReadTreeH(void) ;
192   Int_t ReadTreeR(const Int_t event) ;
193   Int_t ReadTreeS(const Int_t event) ;
194   void ReadTreeQA(void) ;
195   void ReadPrimaries(void) ;
196   void CleanWhiteBoard(void) ;
197   void CloseSplitFiles(void) ;
198   void SetTitle(const char * title) ;
199
200   TObject ** PrimariesRef(void) const ;
201   TObject ** HitsRef(void) const ;
202   TObject ** SDigitsRef(const char * name, const char * file = 0 ) const;
203   TObject ** DigitsRef (const char * name)   const ;
204   TObject ** ECRecPointsRef (const char * name) const ;
205   TObject ** HCRecPointsRef (const char * name) const ;
206   TObject ** PRERecPointsRef (const char * name) const ;
207   TObject ** TrackSegmentsRef(const char * name)   const ;
208   TObject ** RecParticlesRef (const char * name)   const ;
209   TObject ** SDigitizerRef (const char * name) const ; 
210   TObject ** DigitizerRef  (const char * name) const ; 
211   TObject ** ClusterizerRef(const char * name) const ; 
212   TObject ** TSMakerRef    (const char * name) const ; 
213   TObject ** PIDRef        (const char * name) const ; 
214
215  private:
216
217   static TFile * fFile ;              //!
218   Bool_t         fToSplit ;           //! Do we work in the split mode
219   TString        fHeaderFile ;        //! File in which gAlice lives
220   TString        fBranchTitle ;       //!
221   TString        fTrackSegmentsTitle ;//! 
222   TString        fTrackSegmentsFileName ;//! 
223   TString        fRecPointsTitle ;    //!
224   TString        fRecPointsFileName ;    //!
225   TString        fRecParticlesTitle ; //!
226   TString        fRecParticlesFileName ; //!
227   TString        fDigitsTitle ;       //!TDirectory tempo(gDirectory) 
228   TString        fDigitsFileName ;    //! TDirectory tempo(gDirectory)  
229   TString        fSDigitsTitle ;      //!
230   TString        fSDigitsFileName ;      //!
231   Bool_t         fFailed ;            //! true if file is not opened and/or galice not found
232   Int_t          fDebug ;             // Debug level
233   AliRun *       fAlice ;             //! needed to read TreeK if in an other file than fHeaderFile
234   Int_t          fNPrimaries ;        //! # of primaries 
235   TObjArray *    fPrimaries ;         //! list of lists of primaries-for the case of mixing
236   TFolder *      fModuleFolder ;      //!Folder that contains the modules 
237   TFolder *      fPrimariesFolder ;   //!Folder that contains the Primary Particles 
238   TFolder *      fHitsFolder ;        //!Folder that contains the Hits 
239   TFolder *      fSDigitsFolder ;     //!Folder that contains the SDigits 
240   TFolder *      fDigitsFolder ;      //!Folder that contains the Digits 
241   TFolder *      fRecoFolder ;        //!Folder that contains the reconstructed objects (RecPoints, TrackSegments, RecParticles) 
242   TFolder *      fQAFolder ;          //!Folder that contains the QA objects  
243   TFolder *      fTasksFolder ;       //!Folder that contains the Tasks (sdigitizer, digitizer, reconstructioner)
244  
245   static AliEMCALGetter * fgObjGetter; // pointer to the unique instance of the singleton 
246
247   ClassDef(AliEMCALGetter,1)  // Algorithm class that provides methods to retrieve objects from a list knowing the index 
248
249 };
250
251 #endif // AliEMCALGETTER_H
252