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