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