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