]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSGetter.cxx
Removed the QA checker mechanism
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.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 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) ;
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 AliPHOSIndexToObject 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 <TParticle.h>
47 #include <TF1.h>
48 #include <TGraph.h>
49 //#include <TCanvas.h>
50 //#include <TFrame.h>
51
52 // --- Standard library ---
53
54 // --- AliRoot header files ---
55 #include "AliESD.h"
56 #include "AliHeader.h"  
57 #include "AliMC.h"
58 #include "AliPHOS.h"
59 #include "AliPHOSBeamTestEvent.h"
60 #include "AliPHOSGetter.h"
61 #include "AliPHOSLoader.h"
62 #include "AliRunLoader.h"
63 #include "AliStack.h"  
64 #include "AliPHOSRawStream.h"
65 #include "AliRawReaderFile.h"
66 #include "AliLog.h"
67
68 ClassImp(AliPHOSGetter)
69   
70 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ; 
71 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
72 Int_t AliPHOSGetter::fgDebug = 0;
73
74 //  TFile * AliPHOSGetter::fgFile = 0 ; 
75
76 //____________________________________________________________________________ 
77 AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
78 {
79   // ctor only called by Instance()
80
81   AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ; 
82   if (!rl) {
83     rl = AliRunLoader::Open(headerFile, version, openingOption);
84     if (!rl) {
85       Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ; 
86       return ;
87     } 
88     if (rl->GetAliRun() == 0x0) {
89       rl->LoadgAlice();
90       gAlice = rl->GetAliRun(); // should be removed
91     }
92   }
93   fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
94   if ( !fgPhosLoader ) 
95     Error("AliPHOSGetter", "Could not find PHOSLoader") ; 
96   else 
97     fgPhosLoader->SetTitle(version);
98   
99   // initialize data members
100   SetDebug(0) ; 
101   fBTE = 0 ; 
102   fPrimaries = 0 ; 
103   fLoadingStatus = "" ; 
104  
105   fESDFileName = rl->GetFileName()  ; // this should be the galice.root file
106   fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;  
107   fESDFile = 0 ; 
108   fESD = 0 ; 
109   fESDTree = 0 ; 
110   fRawDigits = kFALSE ;
111 }
112
113 //____________________________________________________________________________ 
114 AliPHOSGetter::~AliPHOSGetter()
115 {
116   // dtor
117   if(fgPhosLoader){
118     delete fgPhosLoader ;
119     fgPhosLoader = 0 ;
120   }
121   if(fBTE){
122     delete fBTE ; 
123     fBTE = 0 ;
124   } 
125   if(fPrimaries){
126     fPrimaries->Delete() ; 
127     delete fPrimaries ;
128   } 
129   if (fESD) 
130     delete fESD ; 
131   if (fESDTree) 
132     delete fESDTree ;
133  
134   //  fgObjGetter = 0;
135 }
136
137 //____________________________________________________________________________ 
138 void AliPHOSGetter::Reset()
139 {
140   // resets things in case the getter is called consecutively with different files
141   // the PHOS Loader is already deleted by the Run Loader
142
143   if (fPrimaries) { 
144     fPrimaries->Delete() ; 
145     delete fPrimaries ;
146   } 
147   fgPhosLoader = 0; 
148   fgObjGetter = 0; 
149 }
150
151 //____________________________________________________________________________ 
152 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
153
154   // Returns pointer to the Clusterizer task 
155   AliPHOSClusterizer * rv ; 
156   rv =  dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
157   if (!rv) {
158     Event(0, "R") ; 
159     rv =  dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
160   }
161   return rv ; 
162 }
163
164 //____________________________________________________________________________ 
165 TObjArray * AliPHOSGetter::CpvRecPoints() 
166 {
167   // asks the Loader to return the CPV RecPoints container 
168
169   TObjArray * rv = 0 ; 
170   
171   rv = PhosLoader()->CpvRecPoints() ; 
172   if (!rv) {
173     PhosLoader()->MakeRecPointsArray() ;
174     rv = PhosLoader()->CpvRecPoints() ; 
175   }
176   return rv ; 
177 }
178
179 //____________________________________________________________________________ 
180 TClonesArray * AliPHOSGetter::Digits() 
181 {
182   // asks the Loader to return the Digits container 
183
184   TClonesArray * rv = 0 ; 
185   rv = PhosLoader()->Digits() ; 
186
187   if( !rv ) {
188     PhosLoader()->MakeDigitsArray() ; 
189     rv = PhosLoader()->Digits() ;
190   }
191   return rv ; 
192 }
193
194 //____________________________________________________________________________ 
195 AliPHOSDigitizer * AliPHOSGetter::Digitizer() 
196
197   // Returns pointer to the Digitizer task 
198   AliPHOSDigitizer * rv ; 
199   rv =  dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
200   if (!rv) {
201     Event(0, "D") ; 
202     rv =  dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
203   }
204   return rv ; 
205 }
206
207
208 //____________________________________________________________________________ 
209 TObjArray * AliPHOSGetter::EmcRecPoints() 
210 {
211   // asks the Loader to return the EMC RecPoints container 
212
213   TObjArray * rv = 0 ; 
214   
215   rv = PhosLoader()->EmcRecPoints() ; 
216   if (!rv) {
217     PhosLoader()->MakeRecPointsArray() ;
218     rv = PhosLoader()->EmcRecPoints() ; 
219   }
220   return rv ; 
221 }
222
223 //____________________________________________________________________________ 
224 TClonesArray * AliPHOSGetter::TrackSegments() 
225 {
226   // asks the Loader to return the TrackSegments container 
227
228   TClonesArray * rv = 0 ; 
229   
230   rv = PhosLoader()->TrackSegments() ; 
231   if (!rv) {
232     PhosLoader()->MakeTrackSegmentsArray() ;
233     rv = PhosLoader()->TrackSegments() ; 
234   }
235   return rv ; 
236 }
237
238 //____________________________________________________________________________ 
239 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
240
241   // Returns pointer to the TrackSegmentMaker task 
242   AliPHOSTrackSegmentMaker * rv ; 
243   rv =  dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
244   if (!rv) {
245     Event(0, "T") ; 
246     rv =  dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
247   }
248   return rv ; 
249 }
250
251 //____________________________________________________________________________ 
252 TClonesArray * AliPHOSGetter::RecParticles() 
253 {
254   // asks the Loader to return the TrackSegments container 
255
256   TClonesArray * rv = 0 ; 
257   
258   rv = PhosLoader()->RecParticles() ; 
259   if (!rv) {
260     PhosLoader()->MakeRecParticlesArray() ;
261     rv = PhosLoader()->RecParticles() ; 
262   }
263   return rv ; 
264 }
265 //____________________________________________________________________________ 
266 void AliPHOSGetter::Event(Int_t event, const char* opt) 
267 {
268   // Reads the content of all Tree's S, D and R
269
270 //   if ( event >= MaxEvent() ) {
271 //     Error("Event", "%d not found in TreeE !", event) ; 
272 //     return ; 
273 //   }
274
275   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
276
277 //   // checks if we are dealing with test-beam data
278 //   TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
279 //   if(btb){
280 //     if(!fBTE)
281 //       fBTE = new AliPHOSBeamTestEvent() ;
282 //     btb->SetAddress(&fBTE) ;
283 //     btb->GetEntry(event) ;
284 //   }
285 //   else{
286 //     if(fBTE){
287 //       delete fBTE ;
288 //       fBTE = 0 ;
289 //     }
290 //   }
291
292   // Loads the type of object(s) requested
293   
294   rl->GetEvent(event) ;
295
296   if(strstr(opt,"X") || (strcmp(opt,"")==0)){
297     ReadPrimaries() ;
298   }
299   
300   if(strstr(opt,"H")  ){
301     ReadTreeH();
302   }
303   
304   if(strstr(opt,"S")  ){
305     ReadTreeS() ;
306   }
307   
308   if(strstr(opt,"D") ){
309     ReadTreeD() ;
310   }
311   
312   if(strstr(opt,"R") ){
313     ReadTreeR() ;
314   }
315
316   if( strstr(opt,"T") ){
317     ReadTreeT() ;
318   }    
319
320   if( strstr(opt,"P") ){
321     ReadTreeP() ;
322   }    
323
324   if( strstr(opt,"E") ){
325     ReadTreeE(event) ;
326   }    
327
328 if( strstr(opt,"W")  ){
329     ReadRaw(event) ;
330   }    
331  
332 }
333
334
335 //____________________________________________________________________________ 
336 Int_t AliPHOSGetter::EventNumber() const
337   {
338   // return the current event number
339   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
340   return static_cast<Int_t>(rl->GetEventNumber()) ;   
341 }
342
343 //____________________________________________________________________________ 
344   TClonesArray * AliPHOSGetter::Hits()  
345 {
346   // asks the loader to return  the Hits container 
347   
348   TClonesArray * rv = 0 ; 
349   
350   rv = PhosLoader()->Hits() ; 
351   if ( !rv ) {
352     PhosLoader()->LoadHits("read"); 
353     rv = PhosLoader()->Hits() ; 
354   }
355   return rv ; 
356 }
357
358 //____________________________________________________________________________ 
359 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption) 
360 {
361   // Creates and returns the pointer of the unique instance
362   // Must be called only when the environment has changed
363   
364   //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
365   
366   if(!fgObjGetter){ // first time the getter is called 
367     fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
368   }
369   else { // the getter has been called previously
370     AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
371     if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
372       // check if the file is already open
373       TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ; 
374       
375       if ( !galiceFile ) 
376         fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
377       
378       else {  // the file is already open check the version name
379         TString currentVersionName = rl->GetEventFolder()->GetName() ; 
380         TString newVersionName(version) ; 
381         if (currentVersionName == newVersionName) 
382           if(fgDebug)
383             ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;  
384         else {
385           fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;      
386         }
387       }
388     }
389     else {
390       AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ; 
391       if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
392         delete rl ; 
393       fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;      
394     }
395   }
396   if (!fgObjGetter) 
397     ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
398   else 
399     if (fgDebug)
400       Print() ;
401   
402   return fgObjGetter ;
403 }
404
405 //____________________________________________________________________________ 
406 AliPHOSGetter *  AliPHOSGetter::Instance()
407 {
408   // Returns the pointer of the unique instance already defined
409   
410   if(!fgObjGetter && fgDebug)
411      ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
412
413    return fgObjGetter ;
414            
415 }
416
417 //____________________________________________________________________________ 
418 Int_t AliPHOSGetter::MaxEvent() const 
419 {
420   // returns the number of events in the run (from TE)
421
422   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
423   return static_cast<Int_t>(rl->GetNumberOfEvents()) ; 
424 }
425
426 //____________________________________________________________________________ 
427 TParticle * AliPHOSGetter::Primary(Int_t index) const
428 {
429   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
430   return rl->Stack()->Particle(index) ; 
431
432
433 //____________________________________________________________________________ 
434 AliPHOS * AliPHOSGetter:: PHOS() const  
435 {
436   // returns the PHOS object 
437   AliPHOSLoader *    loader = 0;
438   static AliPHOSLoader * oldloader = 0;
439   static AliPHOS * phos = 0;
440
441   loader = PhosLoader();
442
443   if ( loader != oldloader) {
444     phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
445     oldloader = loader;
446   }
447   if (!phos) 
448     if (fgDebug)
449       Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ; 
450   return phos ; 
451 }  
452
453
454
455 //____________________________________________________________________________ 
456 AliPHOSPID * AliPHOSGetter::PID()
457
458   // Returns pointer to the PID task 
459   AliPHOSPID * rv ; 
460   rv =  dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
461   if (!rv) {
462     Event(0, "P") ; 
463     rv =  dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
464   }
465   return rv ; 
466 }
467
468 //____________________________________________________________________________ 
469 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const 
470 {
471   // Returns PHOS geometry
472
473   AliPHOSGeometry * rv = 0 ; 
474   if (PHOS() )
475     rv =  PHOS()->GetGeometry() ;
476   return rv ; 
477
478
479 //____________________________________________________________________________ 
480 TClonesArray * AliPHOSGetter::Primaries()  
481 {
482   // creates the Primaries container if needed
483   if ( !fPrimaries ) {
484     if (fgDebug) 
485       Info("Primaries", "Creating a new TClonesArray for primaries") ; 
486     fPrimaries = new TClonesArray("TParticle", 1000) ;
487   } 
488   return fPrimaries ; 
489 }
490
491 //____________________________________________________________________________ 
492 void  AliPHOSGetter::Print() 
493 {
494   // Print usefull information about the getter
495     
496   AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
497   ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ; 
498 }
499
500 //____________________________________________________________________________ 
501 void AliPHOSGetter::ReadPrimaries()  
502 {
503   // Read Primaries from Kinematics.root
504   
505   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
506   
507   // gets kine tree from the root file (Kinematics.root)
508   if ( ! rl->TreeK() ) { // load treeK the first time
509     rl->LoadKinematics() ;
510   }
511   
512   fNPrimaries = (rl->GetHeader())->GetNtrack(); 
513   if (fgDebug) 
514     Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ; 
515
516
517   // first time creates the container
518   if ( Primaries() ) 
519     fPrimaries->Clear() ; 
520   
521   Int_t index = 0 ; 
522   for (index = 0 ; index < fNPrimaries; index++) { 
523     new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
524   }
525 }
526
527 //____________________________________________________________________________ 
528 Bool_t AliPHOSGetter::OpenESDFile() 
529 {
530   //Open the ESD file    
531   Bool_t rv = kTRUE ; 
532   if (!fESDFile) {
533     fESDFile = TFile::Open(fESDFileName) ;
534     if (!fESDFile ) 
535       return kFALSE ; 
536   }
537   else if (fESDFile->IsOpen()) {
538     fESDFile->Close() ; 
539     fESDFile = TFile::Open(fESDFileName) ;
540   }
541   if (!fESDFile->IsOpen())
542     rv = kFALSE ; 
543   return rv ; 
544 }
545
546 //____________________________________________________________________________ 
547 Int_t AliPHOSGetter::ReadRaw(Int_t event)
548 {
549   // reads the raw format data, converts it into digits format and store digits in Digits()
550   // container.
551
552   AliRawReaderFile rawReader(event) ; 
553   AliPHOSRawStream in(&rawReader);
554  
555   TClonesArray * digits = Digits() ;
556   digits->Clear() ; 
557   Int_t idigit = 0 ; 
558
559   while ( in.Next() ) { // PHOS entries loop 
560  
561     Int_t amp = in.GetSignal() ; 
562     Double_t time = in.GetTime() ; 
563     Int_t relId[4], id ;
564
565     relId[0] = in.GetModule() ;
566     if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) { 
567       relId[0] -=  PHOS()->GetRawFormatLowGainOffset() ; 
568     }
569     relId[1] = 0 ; 
570     relId[2] = in.GetRow() ; 
571     relId[3] = in.GetColumn() ; 
572     PHOSGeometry()->RelToAbsNumbering(relId, id) ;      
573     
574     if (amp > 0 && id >=0 ) {
575       new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ; 
576       idigit++ ; 
577     }
578     
579   } // PHOS entries loop
580   
581   digits->Sort() ; 
582   
583   return digits->GetEntriesFast() ; 
584 }
585 //____________________________________________________________________________ 
586 Int_t AliPHOSGetter::ReadTreeD()
587 {
588   // Read the Digits
589   
590   PhosLoader()->CleanDigits() ;    
591   PhosLoader()->LoadDigits("UPDATE") ;
592   PhosLoader()->LoadDigitizer("UPDATE") ;
593   return Digits()->GetEntries() ; 
594 }
595
596 //____________________________________________________________________________ 
597 Int_t AliPHOSGetter::ReadTreeH()
598 {
599   // Read the Hits
600   PhosLoader()->CleanHits() ;
601   // gets TreeH from the root file (PHOS.Hit.root)
602   //if ( !IsLoaded("H") ) {
603     PhosLoader()->LoadHits("UPDATE") ;
604   //  SetLoaded("H") ; 
605   //}  
606   return Hits()->GetEntries() ; 
607 }
608
609 //____________________________________________________________________________ 
610 Int_t AliPHOSGetter::ReadTreeR()
611 {
612   // Read the RecPoints
613   
614   PhosLoader()->CleanRecPoints() ;
615   // gets TreeR from the root file (PHOS.RecPoints.root)
616   //if ( !IsLoaded("R") ) {
617     PhosLoader()->LoadRecPoints("UPDATE") ;
618     PhosLoader()->LoadClusterizer("UPDATE") ;
619     //  SetLoaded("R") ; 
620     //}
621
622   return EmcRecPoints()->GetEntries() ; 
623 }
624
625 //____________________________________________________________________________ 
626 Int_t AliPHOSGetter::ReadTreeT()
627 {
628   // Read the TrackSegments
629   
630   PhosLoader()->CleanTracks() ; 
631   // gets TreeT from the root file (PHOS.TrackSegments.root)
632   //if ( !IsLoaded("T") ) {
633     PhosLoader()->LoadTracks("UPDATE") ;
634     PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
635     //    SetLoaded("T") ; 
636     //}
637
638   return TrackSegments()->GetEntries() ; 
639 }
640 //____________________________________________________________________________ 
641 Int_t AliPHOSGetter::ReadTreeP()
642 {
643   // Read the RecParticles
644   
645   PhosLoader()->CleanRecParticles() ; 
646
647   // gets TreeT from the root file (PHOS.TrackSegments.root)
648   //  if ( !IsLoaded("P") ) {
649     PhosLoader()->LoadRecParticles("UPDATE") ;
650     PhosLoader()->LoadPID("UPDATE") ;
651     //  SetLoaded("P") ; 
652     //}
653
654   return RecParticles()->GetEntries() ; 
655 }
656 //____________________________________________________________________________ 
657 Int_t AliPHOSGetter::ReadTreeS()
658 {
659   // Read the SDigits
660   
661   PhosLoader()->CleanSDigits() ; 
662   // gets TreeS from the root file (PHOS.SDigits.root)
663   //if ( !IsLoaded("S") ) {
664     PhosLoader()->LoadSDigits("READ") ;
665     PhosLoader()->LoadSDigitizer("READ") ;
666     //  SetLoaded("S") ; 
667     //}
668
669   return SDigits()->GetEntries() ; 
670 }
671
672 //____________________________________________________________________________ 
673 Int_t AliPHOSGetter::ReadTreeE(Int_t event)
674 {
675   // Read the ESD
676   
677   // gets esdTree from the root file (AliESDs.root)
678   if (!fESDFile)
679     if ( !OpenESDFile() ) 
680       return -1 ; 
681
682   fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ; 
683   fESD = new AliESD;
684    if (!fESDTree) {
685
686      Error("ReadTreeE", "no ESD tree found");
687      return -1;
688    }
689    fESDTree->SetBranchAddress("ESD", &fESD);
690    fESDTree->GetEvent(event);
691
692    return event ; 
693 }
694
695 //____________________________________________________________________________ 
696 TClonesArray * AliPHOSGetter::SDigits() 
697 {
698   // asks the Loader to return the Digits container 
699
700   TClonesArray * rv = 0 ; 
701   
702   rv = PhosLoader()->SDigits() ; 
703   if (!rv) {
704     PhosLoader()->MakeSDigitsArray() ;
705     rv = PhosLoader()->SDigits() ; 
706   }
707   return rv ; 
708 }
709
710 //____________________________________________________________________________ 
711 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
712
713   // Returns pointer to the SDigitizer task 
714   AliPHOSSDigitizer * rv ; 
715   rv =  dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
716   if (!rv) {
717     Event(0, "S") ; 
718     rv =  dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
719   }
720   return rv ; 
721 }
722
723 //____________________________________________________________________________ 
724 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
725 {
726   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
727
728   if(index <= 0) 
729     return 0 ;
730   if(index > 2)
731     return 0 ;
732
733   if(p) {
734   Int_t daughterIndex = p->GetDaughter(index-1) ; 
735   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
736   return  rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ; 
737   }
738   else
739     return 0 ;
740 }
741
742 //____________________________________________________________________________ 
743 void AliPHOSGetter::Track(Int_t itrack) 
744 {
745   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
746  
747  AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
748
749   if( !TreeH() ) // load treeH the first time
750     rl->LoadHits() ;
751
752   // first time create the container
753   TClonesArray * hits = Hits() ; 
754   if ( hits ) 
755     hits->Clear() ; 
756
757   TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ; 
758   phosbranch->SetAddress(&hits) ;
759   phosbranch->GetEntry(itrack) ;
760 }
761
762 //____________________________________________________________________________ 
763 TTree * AliPHOSGetter::TreeD() const 
764 {
765   // Returns pointer to the Digits Tree
766   TTree * rv = 0 ; 
767   rv = PhosLoader()->TreeD() ; 
768   if ( !rv ) {
769     PhosLoader()->MakeTree("D");
770     rv = PhosLoader()->TreeD() ;
771   } 
772   
773   return rv ; 
774 }
775
776 //____________________________________________________________________________ 
777 TTree * AliPHOSGetter::TreeH() const 
778 {
779   // Returns pointer to the Hits Tree
780   TTree * rv = 0 ; 
781   rv = PhosLoader()->TreeH() ; 
782   if ( !rv ) {
783     PhosLoader()->MakeTree("H");
784     rv = PhosLoader()->TreeH() ;
785   } 
786   
787   return rv ; 
788 }
789
790 //____________________________________________________________________________ 
791 TTree * AliPHOSGetter::TreeR() const 
792 {
793   // Returns pointer to the RecPoints Tree
794   TTree * rv = 0 ; 
795   rv = PhosLoader()->TreeR() ; 
796   if ( !rv ) {
797     PhosLoader()->MakeTree("R");
798     rv = PhosLoader()->TreeR() ;
799   } 
800   
801   return rv ; 
802 }
803
804 //____________________________________________________________________________ 
805 TTree * AliPHOSGetter::TreeT() const 
806 {
807   // Returns pointer to the TrackSegments Tree
808   TTree * rv = 0 ; 
809   rv = PhosLoader()->TreeT() ; 
810   if ( !rv ) {
811     PhosLoader()->MakeTree("T");
812     rv = PhosLoader()->TreeT() ;
813   } 
814   
815   return rv ; 
816 }
817 //____________________________________________________________________________ 
818 TTree * AliPHOSGetter::TreeP() const 
819 {
820   // Returns pointer to the RecParticles  Tree
821   TTree * rv = 0 ; 
822   rv = PhosLoader()->TreeP() ; 
823   if ( !rv ) {
824     PhosLoader()->MakeTree("P");
825     rv = PhosLoader()->TreeP() ;
826   } 
827   
828   return rv ; 
829 }
830
831 //____________________________________________________________________________ 
832 TTree * AliPHOSGetter::TreeS() const 
833
834  // Returns pointer to the SDigits Tree
835   TTree * rv = 0 ; 
836   rv = PhosLoader()->TreeS() ; 
837   if ( !rv ) {
838     PhosLoader()->MakeTree("S");
839     rv = PhosLoader()->TreeS() ;
840   } 
841   
842   return rv ; 
843 }
844
845 //____________________________________________________________________________ 
846 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
847 {
848   // checks if the version with the present name already exists in the same directory
849
850   Bool_t rv = kFALSE ;
851  
852   AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
853   TString version( rl->GetEventFolder()->GetName() ) ; 
854
855   opt.ToLower() ; 
856   
857   if ( opt == "sdigits") {
858     // add the version name to the root file name
859     TString fileName( PhosLoader()->GetSDigitsFileName() ) ; 
860     if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
861       fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
862     if ( !(gSystem->AccessPathName(fileName)) ) { 
863       Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
864       rv = kTRUE ; 
865     }
866     PhosLoader()->SetSDigitsFileName(fileName) ;
867   }
868
869   if ( opt == "digits") {
870     // add the version name to the root file name
871     TString fileName( PhosLoader()->GetDigitsFileName() ) ; 
872     if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
873       fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
874     if ( !(gSystem->AccessPathName(fileName)) ) {
875       Warning("VersionExists", "The file %s already exists", fileName.Data()) ;  
876       rv = kTRUE ; 
877     }
878   }
879
880   return rv ;
881
882 }
883
884 //____________________________________________________________________________ 
885 UShort_t AliPHOSGetter::EventPattern(void) const
886 {
887   // Return the pattern (trigger bit register) of the beam-test event
888   if(fBTE)
889     return fBTE->GetPattern() ;
890   else
891     return 0 ;
892 }
893 //____________________________________________________________________________ 
894 Float_t AliPHOSGetter::BeamEnergy(void) const
895 {
896   // Return the beam energy of the beam-test event
897   if(fBTE)
898     return fBTE->GetBeamEnergy() ;
899   else
900     return 0 ;
901 }