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