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