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