]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
Introduced a new time information (fastest track making the digit) to be used to...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
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. 
26 //
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) ;
31 //     ................
32 //  gime->Event(event) ;    // reads new event from galice.root
33 //                  
34 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35 //*--         Completely redesigned by Dmitri Peressounko March 2001  
36 //
37 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
38 //*--         systematic usage of TFolders without changing the interface        
39 //////////////////////////////////////////////////////////////////////////////
40
41 // --- ROOT system ---
42
43 #include <TFile.h>
44 #include <TROOT.h>
45 #include <TSystem.h>
46 #include <TH1D.h>
47 #include <TF1.h>
48
49 // --- Standard library ---
50
51 // --- AliRoot header files ---
52
53 #include "AliEMCAL.h"
54 #include "AliEMCALGetter.h"
55 #include "AliEMCALLoader.h"
56 #include "AliHeader.h"  
57 #include "AliMC.h"
58 #include "AliRunLoader.h"
59 #include "AliStack.h"  
60 #include "AliEMCALRawStream.h"
61 #include "AliRawReaderFile.h"
62
63 ClassImp(AliEMCALGetter)
64   
65 AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ; 
66 AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
67 Int_t AliEMCALGetter::fgDebug = 0;
68 TString AliEMCALGetter::fVersion = "";
69
70 //  TFile * AliEMCALGetter::fgFile = 0 ; 
71
72 //____________________________________________________________________________ 
73 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption) 
74 {
75   // ctor only called by Instance()
76
77   // initialize data members
78   SetDebug(0) ; 
79   //fBTE = 0 ; 
80   
81   fLoadingStatus = "" ; 
82
83   fgObjGetter=this;
84   
85   OpenFile(headerFile,version,openingOption);
86 }
87
88
89 //____________________________________________________________________________ 
90 AliEMCALGetter::~AliEMCALGetter()
91 {
92   AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
93   delete rl;
94   fgEmcalLoader = 0 ;
95   fgObjGetter = 0; 
96   fVersion = "";
97 }
98
99 //____________________________________________________________________________ 
100 void AliEMCALGetter::OpenFile(const char* headerFile, const char* version, Option_t * openingOption) {
101   fVersion = version;
102   AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ; 
103   if (!rl) {
104     rl = AliRunLoader::Open(headerFile, version, openingOption);
105     if (!rl) {
106       Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ; 
107       return ;
108     } 
109     if (rl->GetAliRun() == 0x0) {
110       rl->LoadgAlice();
111       gAlice = rl->GetAliRun(); // should be removed
112     }
113   } 
114   fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
115   if ( !fgEmcalLoader ) 
116     Error("AliEMCALGetter", "Could not find EMCALLoader") ; 
117   else 
118     fgEmcalLoader->SetTitle(version);
119 }
120
121 //____________________________________________________________________________ 
122 void AliEMCALGetter::Reset()
123 {
124   // resets things in case the getter is called consecutively with different files
125   // the EMCAL Loader is already deleted by the Run Loader
126
127 }
128
129 //____________________________________________________________________________ 
130 AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
131
132   // return pointer to Clusterizer Tree
133   AliEMCALClusterizer * rv ; 
134   rv =  dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
135   if (!rv) {
136     Event(0, "R") ; 
137     rv =  dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
138   }
139   return rv ; 
140 }
141
142
143 //____________________________________________________________________________ 
144 TClonesArray * AliEMCALGetter::Digits() const  
145 {
146   // asks the Loader to return the Digits container 
147
148   TClonesArray * rv = 0 ; 
149   rv = EmcalLoader()->Digits() ; 
150
151   if( !rv ) {
152     EmcalLoader()->MakeDigitsArray() ; 
153     rv = EmcalLoader()->Digits() ;
154   }
155   return rv ; 
156 }
157
158 //____________________________________________________________________________ 
159 AliEMCALDigitizer * AliEMCALGetter::Digitizer() 
160
161   // return pointer to Digitizer Tree
162   AliEMCALDigitizer * rv ; 
163   rv =  dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
164   if (!rv) {
165     Event(0, "D") ; 
166     rv =  dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
167   }
168   return rv ; 
169 }
170
171 //____________________________________________________________________________ 
172 TObjArray * AliEMCALGetter::ECARecPoints() const 
173 {
174   // asks the Loader to return the EMC RecPoints container 
175
176   TObjArray * rv = 0 ; 
177   
178   rv = EmcalLoader()->ECARecPoints() ; 
179   if (!rv) {
180     EmcalLoader()->MakeRecPointsArray() ;
181     rv = EmcalLoader()->ECARecPoints() ; 
182   }
183   return rv ; 
184 }
185
186 //____________________________________________________________________________ 
187 TClonesArray * AliEMCALGetter::TrackSegments() const 
188 {
189   // asks the Loader to return the TrackSegments container 
190
191   TClonesArray * rv = 0 ; 
192   
193   rv = EmcalLoader()->TrackSegments() ; 
194   if (!rv) {
195     EmcalLoader()->MakeTrackSegmentsArray() ;
196     rv = EmcalLoader()->TrackSegments() ; 
197   }
198   return rv ; 
199 }
200
201 //____________________________________________________________________________ 
202 AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker() 
203
204   // return pointer to TrackSegmentMaker Tree
205   AliEMCALTrackSegmentMaker * rv ; 
206   rv =  dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
207   if (!rv) {
208     Event(0, "T") ; 
209     rv =  dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
210   }
211   return rv ; 
212 }
213
214 //____________________________________________________________________________ 
215 TClonesArray * AliEMCALGetter::RecParticles() const  
216 {
217   // asks the Loader to return the TrackSegments container 
218
219   TClonesArray * rv = 0 ; 
220   
221   rv = EmcalLoader()->RecParticles() ; 
222   if (!rv) {
223     EmcalLoader()->MakeRecParticlesArray() ;
224     rv = EmcalLoader()->RecParticles() ; 
225   }
226   return rv ; 
227 }
228 //____________________________________________________________________________ 
229 void AliEMCALGetter::Event(Int_t event, const char* opt) 
230 {
231   // Reads the content of all Tree's S, D and R
232
233   if ( event >= MaxEvent() ) {
234     Error("Event", "%d not found in TreeE !", event) ; 
235     return ; 
236   }
237
238   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
239   // checks if we are dealing with test-beam data
240 //   TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
241 //   if(btb){
242 //     if(!fBTE)
243 //       fBTE = new AliEMCALBeamTestEvent() ;
244 //     btb->SetAddress(&fBTE) ;
245 //     btb->GetEntry(event) ;
246 //   }
247 //   else{
248 //     if(fBTE){
249 //       delete fBTE ;
250 //       fBTE = 0 ;
251 //     }
252 //   }
253
254   // Loads the type of object(s) requested
255   
256   rl->GetEvent(event) ;
257
258   if( strstr(opt,"X") || (strcmp(opt,"")==0) )
259     ReadPrimaries() ;
260
261   if(strstr(opt,"H") )
262     ReadTreeH();
263
264   if(strstr(opt,"S") )
265     ReadTreeS() ;
266
267   if( strstr(opt,"D") )
268     ReadTreeD() ;
269
270   if( strstr(opt,"R") )
271     ReadTreeR() ;
272
273   if( strstr(opt,"T") )
274     ReadTreeT() ;
275
276   if( strstr(opt,"P") )
277     ReadTreeP() ;
278
279   if( strstr(opt,"W") )
280     ReadRaw(event) ;
281   
282 }
283
284
285 //____________________________________________________________________________ 
286 Int_t AliEMCALGetter::EventNumber() const
287   {
288   // return the current event number
289   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
290   return static_cast<Int_t>(rl->GetEventNumber()) ;   
291 }
292
293 //____________________________________________________________________________ 
294   TClonesArray * AliEMCALGetter::Hits() const   
295 {
296   // asks the loader to return  the Hits container 
297   
298   TClonesArray * rv = 0 ; 
299   
300   rv = EmcalLoader()->Hits() ; 
301   if ( !rv ) {
302     EmcalLoader()->LoadHits("read"); 
303     rv = EmcalLoader()->Hits() ; 
304   }
305   return rv ; 
306 }
307
308 //____________________________________________________________________________ 
309 AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption) 
310 {
311   // Creates and returns the pointer of the unique instance
312   // Must be called only when the environment has changed
313
314   if(!fgObjGetter){ // first time the getter is called 
315     fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
316   }
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()) ) ; 
323       
324       if ( !galiceFile ) 
325         fgObjGetter->OpenFile(alirunFileName, version, openingOption);
326       
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) 
331           if(fgDebug)
332             ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;  
333         else {    
334           fgEmcalLoader->SetTitle(version); fVersion = version;
335         }
336       }
337     }
338     else { 
339       AliRunLoader * rl = AliRunLoader::GetRunLoader(fVersion);
340       if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
341         delete rl ; 
342       fgObjGetter->OpenFile(alirunFileName, version, openingOption) ;      
343     }
344   }
345   if (!fgObjGetter) 
346     ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
347   else 
348     if (fgDebug)
349       Print() ;
350
351   return fgObjGetter ;
352 }
353
354 //____________________________________________________________________________ 
355 AliEMCALGetter *  AliEMCALGetter::Instance()
356 {
357   // Returns the pointer of the unique instance already defined
358   
359   if(!fgObjGetter && fgDebug)
360      ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
361
362    return fgObjGetter ;
363            
364 }
365
366 //____________________________________________________________________________ 
367 Int_t AliEMCALGetter::MaxEvent() const 
368 {
369   // returns the number of events in the run (from TE)
370
371   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
372   return static_cast<Int_t>(rl->GetNumberOfEvents()) ; 
373 }
374
375 //____________________________________________________________________________ 
376 TParticle * AliEMCALGetter::Primary(Int_t index) const
377 {
378   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
379   return rl->Stack()->Particle(index) ; 
380
381
382 //____________________________________________________________________________ 
383 Int_t AliEMCALGetter::NPrimaries() const
384 {
385   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
386   return (rl->GetHeader())->GetNtrack(); 
387
388
389 //____________________________________________________________________________ 
390 AliEMCAL * AliEMCALGetter:: EMCAL() const  
391 {
392   // returns the EMCAL object 
393   AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;  
394   if (!emcal) 
395     if (fgDebug)
396       Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ; 
397   return emcal ; 
398 }  
399
400
401
402 //____________________________________________________________________________ 
403 AliEMCALPID * AliEMCALGetter::PID() 
404
405   // return pointer to PID Tree
406   AliEMCALPID * rv ; 
407   rv =  dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
408   if (!rv) {
409     Event(0, "P") ; 
410     rv =  dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
411   }
412   return rv ; 
413 }
414
415 //____________________________________________________________________________ 
416 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const 
417 {
418   // Returns EMCAL geometry
419
420   AliEMCALGeometry * rv = 0 ; 
421   if (EMCAL() )
422     rv =  EMCAL()->GetGeometry() ;
423   return rv ; 
424
425
426 //____________________________________________________________________________ 
427 void  AliEMCALGetter::Print() 
428 {
429   // Print usefull information about the getter
430     
431   AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
432   ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ; 
433 }
434
435 //____________________________________________________________________________ 
436 void AliEMCALGetter::ReadPrimaries()  
437 {
438   // Read Primaries from Kinematics.root
439   
440   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
441   
442   // gets kine tree from the root file (Kinematics.root)
443   if ( ! rl->TreeK() )  // load treeK the first time
444     rl->LoadKinematics() ;
445   
446   if (fgDebug) 
447     Info("ReadTreeK", "Found %d particles in event # %d", NPrimaries(), EventNumber() ) ; 
448 }
449
450 //____________________________________________________________________________ 
451 Int_t AliEMCALGetter::ReadRaw(Int_t event)
452 {
453   // reads the raw format data, converts it into digits format and store digits in Digits()
454   // container.
455   
456   AliRawReaderFile rawReader(event) ; 
457   AliEMCALRawStream in(&rawReader);
458   
459   const Int_t kHighGainIdOffset = EMCALGeometry()->GetNTowers()
460     * EMCALGeometry()->GetNPhi()
461     * EMCALGeometry()->GetNZ() 
462     * 2 ;
463   
464   Bool_t first = kTRUE ;
465   
466   TH1D hLowGain("hLowGain", "Low Gain", 1000, 0., EMCAL()->GetRawFormatTimeMax()) ; 
467   TH1D hHighGain("hHighGain", "High Gain", 1000, 0., EMCAL()->GetRawFormatTimeMax()) ; 
468   
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() ) ;   
474   
475   Int_t id = -1;
476   Bool_t hgflag = kFALSE ; 
477   
478   TClonesArray * digits = Digits() ;
479   digits->Clear() ; 
480   Int_t idigit = 0 ; 
481   
482   while ( in.Next() ) { // EMCAL entries loop 
483     
484     if ( in.IsNewId() ) {
485       if (!first) {
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() ;  
491         if (hgflag) {
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) ;
498           idigit++ ; 
499         }
500         else {
501           new((*digits)[idigit]) AliEMCALDigit( -1, -1, id, ampL, timeL) ;
502           idigit++ ; 
503         }
504       }
505       first = kFALSE ; 
506       hLowGain.Reset() ; 
507       hHighGain.Reset() ; 
508       id = in.GetId() ; 
509       if (id > 9999 ) { // fixme 
510         hgflag = kTRUE ; 
511       } else 
512         hgflag = kFALSE ; 
513     }
514     if (hgflag)
515       hHighGain.Fill(
516                      in.GetTime() * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(), 
517                      in. GetSignal() * EMCAL()->GetRawFormatHighGainFactor() ) ;
518     else 
519       hLowGain.Fill(
520                     in.GetTime() * EMCAL()->GetRawFormatTimeMax() / EMCAL()->GetRawFormatTimeBins(), 
521                     in. GetSignal() ) ;
522   } // EMCAL entries loop
523   
524   delete gauss ; 
525   
526   return Digits()->GetEntriesFast() ; 
527 }
528   
529   //____________________________________________________________________________ 
530 Int_t AliEMCALGetter::ReadTreeD()
531 {
532   // Read the Digits
533   
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") ;
539     //  SetLoaded("D") ; 
540     //} 
541   return Digits()->GetEntries() ; 
542 }
543
544 //____________________________________________________________________________ 
545 Int_t AliEMCALGetter::ReadTreeH()
546 {
547   // Read the Hits
548   EmcalLoader()->CleanHits() ; 
549   // gets TreeH from the root file (EMCAL.Hit.root)
550   //if ( !IsLoaded("H") ) {
551     EmcalLoader()->LoadHits("READ") ;
552     SetLoaded("H") ; 
553     //}  
554   return Hits()->GetEntries() ; 
555 }
556
557 //____________________________________________________________________________ 
558 Int_t AliEMCALGetter::ReadTreeR()
559 {
560   // Read the RecPoints
561
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") ;
567     //  SetLoaded("R") ; 
568     //}
569
570   return ECARecPoints()->GetEntries() ; 
571 }
572
573 //____________________________________________________________________________ 
574 Int_t AliEMCALGetter::ReadTreeT()
575 {
576   // Read the TrackSegments
577   
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") ;
583     //  SetLoaded("T") ; 
584     //}
585
586   return TrackSegments()->GetEntries() ; 
587 }
588 //____________________________________________________________________________ 
589 Int_t AliEMCALGetter::ReadTreeP()
590 {
591   // Read the RecParticles
592   
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") ;
598     //  SetLoaded("P") ; 
599     // }
600
601   return RecParticles()->GetEntries() ; 
602 }
603 //____________________________________________________________________________ 
604 Int_t AliEMCALGetter::ReadTreeS()
605 {
606   // Read the SDigits
607   
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") ;
613     //  SetLoaded("S") ; 
614     //}
615
616   return SDigits()->GetEntries() ; 
617 }
618
619 //____________________________________________________________________________ 
620 TClonesArray * AliEMCALGetter::SDigits() const  
621 {
622   // asks the Loader to return the Digits container 
623
624   TClonesArray * rv = 0 ; 
625   
626   rv = EmcalLoader()->SDigits() ; 
627   if (!rv) {
628     EmcalLoader()->MakeSDigitsArray() ;
629     rv = EmcalLoader()->SDigits() ; 
630   }
631   return rv ; 
632 }
633
634 //____________________________________________________________________________ 
635 AliEMCALSDigitizer * AliEMCALGetter::SDigitizer() 
636
637   // Return pointer to SDigitizer task
638   AliEMCALSDigitizer * rv ; 
639   rv =  dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
640   if (!rv) {
641     Event(0, "S") ; 
642     rv =  dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
643   }
644   return rv ; 
645 }
646
647 //____________________________________________________________________________ 
648 TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
649 {
650   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
651
652   if(index <= 0) 
653     return 0 ;
654   if(index > 2)
655     return 0 ;
656
657   if(p) {
658   Int_t daughterIndex = p->GetDaughter(index-1) ; 
659   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
660   return  rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ; 
661   }
662   else
663     return 0 ;
664 }
665
666 //____________________________________________________________________________ 
667 void AliEMCALGetter::Track(Int_t itrack) 
668 {
669   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
670  
671  AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
672
673   if( !TreeH() ) // load treeH the first time
674     rl->LoadHits() ;
675
676   // first time create the container
677   TClonesArray * hits = Hits() ; 
678   if ( hits ) 
679     hits->Clear() ; 
680
681   TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ; 
682   emcalbranch->SetAddress(&hits) ;
683   emcalbranch->GetEntry(itrack) ;
684 }
685
686 //____________________________________________________________________________ 
687 TTree * AliEMCALGetter::TreeD() const 
688 {
689   // return pointer to Digits Tree
690   TTree * rv = 0 ; 
691   rv = EmcalLoader()->TreeD() ; 
692   if ( !rv ) {
693     EmcalLoader()->MakeTree("D");
694     rv = EmcalLoader()->TreeD() ;
695   } 
696   
697   return rv ; 
698 }
699
700 //____________________________________________________________________________ 
701 TTree * AliEMCALGetter::TreeH() const 
702 {
703   // return pointer to Hits Tree
704   TTree * rv = 0 ; 
705   rv = EmcalLoader()->TreeH() ; 
706   if ( !rv ) {
707     EmcalLoader()->MakeTree("H");
708     rv = EmcalLoader()->TreeH() ;
709   } 
710   
711   return rv ; 
712 }
713
714 //____________________________________________________________________________ 
715 TTree * AliEMCALGetter::TreeR() const 
716 {
717   // return pointer to RecPoints Tree
718
719   TTree * rv = 0 ; 
720   rv = EmcalLoader()->TreeR() ; 
721   if ( !rv ) {
722     EmcalLoader()->MakeTree("R");
723     rv = EmcalLoader()->TreeR() ;
724   } 
725   
726   return rv ; 
727 }
728
729 //____________________________________________________________________________ 
730 TTree * AliEMCALGetter::TreeT() const 
731 {  
732   // return pointer to TrackSegments Tree
733   TTree * rv = 0 ; 
734   rv = EmcalLoader()->TreeT() ; 
735   if ( !rv ) {
736     EmcalLoader()->MakeTree("T");
737     rv = EmcalLoader()->TreeT() ;
738   } 
739   
740   return rv ; 
741 }
742 //____________________________________________________________________________ 
743 TTree * AliEMCALGetter::TreeP() const 
744 {
745   // return pointer to RecParticles Tree
746   TTree * rv = 0 ; 
747   rv = EmcalLoader()->TreeP() ; 
748   if ( !rv ) {
749     EmcalLoader()->MakeTree("P");
750     rv = EmcalLoader()->TreeP() ;
751   } 
752   
753   return rv ; 
754 }
755
756 //____________________________________________________________________________ 
757 TTree * AliEMCALGetter::TreeS() const 
758 {
759   // return pointer to SDigits Tree
760   TTree * rv = 0 ; 
761   rv = EmcalLoader()->TreeS() ; 
762   if ( !rv ) {
763     EmcalLoader()->MakeTree("S");
764     rv = EmcalLoader()->TreeS() ;
765   } 
766   
767   return rv ; 
768 }
769
770 //____________________________________________________________________________ 
771 Bool_t AliEMCALGetter::VersionExists(TString & opt) const
772 {
773   // checks if the version with the present name already exists in the same directory
774
775   Bool_t rv = kFALSE ;
776  
777   AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
778   TString version( rl->GetEventFolder()->GetName() ) ; 
779
780   opt.ToLower() ; 
781   
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()) ;
789       rv = kTRUE ; 
790     }
791     EmcalLoader()->SetSDigitsFileName(fileName) ;
792   }
793
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()) ;  
801       rv = kTRUE ; 
802     }
803   }
804
805   return rv ;
806
807 }
808
809 //____________________________________________________________________________ 
810 UShort_t AliEMCALGetter::EventPattern(void) const
811 {
812   // Return the pattern (trigger bit register) of the beam-test event
813 //   if(fBTE)
814 //     return fBTE->GetPattern() ;
815 //   else
816     return 0 ;
817 }
818 //____________________________________________________________________________ 
819 Float_t AliEMCALGetter::BeamEnergy(void) const
820 {
821   // Return the beam energy of the beam-test event
822 //   if(fBTE)
823 //     return fBTE->GetBeamEnergy() ;
824 //   else
825     return 0 ;
826 }