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