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