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