Put a Warning under the control of gDebug
[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 "TROOT.h"
88cb7938 45
4ae78bb1 46
47// --- Standard library ---
4ae78bb1 48
49// --- AliRoot header files ---
4ae78bb1 50#include "AliPHOSGetter.h"
e957fea8 51#include "AliPHOS.h"
88cb7938 52#include "AliRunLoader.h"
53#include "AliStack.h"
54#include "AliPHOSLoader.h"
7bb289a7 55#include "AliPHOSBeamTestEvent.h"
5d12ce38 56#include "AliMC.h"
88cb7938 57
4ae78bb1 58ClassImp(AliPHOSGetter)
59
88cb7938 60AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
61AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
62Int_t AliPHOSGetter::fgDebug = 0;
63
64// TFile * AliPHOSGetter::fgFile = 0 ;
4ae78bb1 65
66//____________________________________________________________________________
88cb7938 67AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
4ae78bb1 68{
88cb7938 69 // ctor only called by Instance()
dca3a7c4 70
88cb7938 71 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
72 if (!rl) {
73 rl = AliRunLoader::Open(headerFile, version, openingOption);
74 if (!rl) {
75 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
76 return ;
77 }
78 if (rl->GetAliRun() == 0x0) {
79 rl->LoadgAlice();
80 gAlice = rl->GetAliRun(); // should be removed
7bb289a7 81 }
93aeb834 82 }
88cb7938 83 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
84 if ( !fgPhosLoader )
85 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
86 else
87 fgPhosLoader->SetTitle(version);
85290134 88
88cb7938 89
90 // initialize data members
91 SetDebug(0) ;
92 fBTE = 0 ;
93 fPrimaries = 0 ;
94 fLoadingStatus = "" ;
4ae78bb1 95}
fbf811ec 96
4ae78bb1 97//____________________________________________________________________________
0bc3b8ed 98AliPHOSGetter::~AliPHOSGetter()
99{
100 // dtor
88cb7938 101 delete fgPhosLoader ;
102 fgPhosLoader = 0 ;
103 delete fBTE ;
104 fBTE = 0 ;
105 fPrimaries->Delete() ;
106 delete fPrimaries ;
65549808 107}
4ae78bb1 108
109//____________________________________________________________________________
88cb7938 110AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
111{
e957fea8 112 // Returns pointer to the Clusterizer task
88cb7938 113 AliPHOSClusterizer * rv ;
114 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
115 if (!rv) {
116 Event(0, "R") ;
117 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
0c87da39 118 }
88cb7938 119 return rv ;
0c87da39 120}
121
122//____________________________________________________________________________
88cb7938 123TObjArray * AliPHOSGetter::CpvRecPoints()
4ae78bb1 124{
88cb7938 125 // asks the Loader to return the CPV RecPoints container
126
127 TObjArray * rv = 0 ;
4ae78bb1 128
88cb7938 129 rv = PhosLoader()->CpvRecPoints() ;
130 if (!rv) {
131 PhosLoader()->MakeRecPointsArray() ;
132 rv = PhosLoader()->CpvRecPoints() ;
b134c32f 133 }
88cb7938 134 return rv ;
4ae78bb1 135}
136
137//____________________________________________________________________________
88cb7938 138TClonesArray * AliPHOSGetter::Digits()
4ae78bb1 139{
88cb7938 140 // asks the Loader to return the Digits container
df25f7dd 141
88cb7938 142 TClonesArray * rv = 0 ;
143 rv = PhosLoader()->Digits() ;
7bb289a7 144
88cb7938 145 if( !rv ) {
146 PhosLoader()->MakeDigitsArray() ;
147 rv = PhosLoader()->Digits() ;
fbf811ec 148 }
88cb7938 149 return rv ;
fbf811ec 150}
d489fb96 151
fbf811ec 152//____________________________________________________________________________
88cb7938 153AliPHOSDigitizer * AliPHOSGetter::Digitizer()
154{
e957fea8 155 // Returns pointer to the Digitizer task
88cb7938 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//____________________________________________________________________________
e957fea8 197AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
88cb7938 198{
e957fea8 199 // Returns pointer to the TrackSegmentMaker task
88cb7938 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//____________________________________________________________________________
e957fea8 389AliPHOSPID * AliPHOSGetter::PID()
88cb7938 390{
e957fea8 391 // Returns pointer to the PID task
88cb7938 392 AliPHOSPID * rv ;
393 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
394 if (!rv) {
395 Event(0, "P") ;
396 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
b0bba0af 397 }
88cb7938 398 return rv ;
b0bba0af 399}
400
401//____________________________________________________________________________
88cb7938 402AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
403{
404 // Returns PHOS geometry
7a9d98f9 405
88cb7938 406 AliPHOSGeometry * rv = 0 ;
407 if (PHOS() )
408 rv = PHOS()->GetGeometry() ;
409 return rv ;
7a9d98f9 410}
b0bba0af 411
412//____________________________________________________________________________
88cb7938 413TClonesArray * AliPHOSGetter::Primaries()
0bc3b8ed 414{
88cb7938 415 // creates the Primaries container if needed
416 if ( !fPrimaries ) {
417 if (fgDebug)
418 Info("Primaries", "Creating a new TClonesArray for primaries") ;
419 fPrimaries = new TClonesArray("TParticle", 1000) ;
420 }
421 return fPrimaries ;
b0bba0af 422}
423
424//____________________________________________________________________________
88cb7938 425void AliPHOSGetter::Print()
426{
427 // Print usefull information about the getter
428
429 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
430 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
b0bba0af 431}
7a9d98f9 432
b0bba0af 433//____________________________________________________________________________
88cb7938 434void AliPHOSGetter::ReadPrimaries()
435{
436 // Read Primaries from Kinematics.root
b0bba0af 437
88cb7938 438 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
7a9d98f9 439
88cb7938 440 // gets kine tree from the root file (Kinematics.root)
441 if ( ! rl->TreeK() ) // load treeK the first time
442 rl->LoadKinematics() ;
7a9d98f9 443
88cb7938 444 fNPrimaries = rl->Stack()->GetNtrack() ;
b0bba0af 445
88cb7938 446 if (fgDebug)
447 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
7a9d98f9 448
7a9d98f9 449
88cb7938 450 // first time creates the container
451 if ( Primaries() )
452 fPrimaries->Clear() ;
b0bba0af 453
88cb7938 454 Int_t index = 0 ;
455 for (index = 0 ; index < fNPrimaries; index++) {
456 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
b0bba0af 457 }
88cb7938 458}
7a9d98f9 459
b0bba0af 460//____________________________________________________________________________
88cb7938 461Int_t AliPHOSGetter::ReadTreeD()
462{
463 // Read the Digits
7a9d98f9 464
7a9d98f9 465
88cb7938 466 // gets TreeD from the root file (PHOS.SDigits.root)
467 if ( !IsLoaded("D") ) {
468 PhosLoader()->LoadDigits("UPDATE") ;
469 PhosLoader()->LoadDigitizer("UPDATE") ;
470 SetLoaded("D") ;
b0bba0af 471 }
88cb7938 472 return Digits()->GetEntries() ;
473}
7a9d98f9 474
b0bba0af 475//____________________________________________________________________________
88cb7938 476Int_t AliPHOSGetter::ReadTreeH()
0bc3b8ed 477{
88cb7938 478 // Read the Hits
479
480 // gets TreeH from the root file (PHOS.Hit.root)
481 if ( !IsLoaded("H") ) {
482 PhosLoader()->LoadHits("UPDATE") ;
483 SetLoaded("H") ;
484 }
485 return Hits()->GetEntries() ;
486}
b0bba0af 487
488//____________________________________________________________________________
88cb7938 489Int_t AliPHOSGetter::ReadTreeR()
490{
491 // Read the RecPoints
b0bba0af 492
b0bba0af 493
88cb7938 494 // gets TreeR from the root file (PHOS.RecPoints.root)
495 if ( !IsLoaded("R") ) {
496 PhosLoader()->LoadRecPoints("UPDATE") ;
497 PhosLoader()->LoadClusterizer("UPDATE") ;
498 SetLoaded("R") ;
b0bba0af 499 }
7a9d98f9 500
88cb7938 501 return EmcRecPoints()->GetEntries() ;
7bb289a7 502}
88cb7938 503
7bb289a7 504//____________________________________________________________________________
88cb7938 505Int_t AliPHOSGetter::ReadTreeT()
0bc3b8ed 506{
88cb7938 507 // Read the TrackSegments
7a9d98f9 508
b0bba0af 509
88cb7938 510 // gets TreeT from the root file (PHOS.TrackSegments.root)
511 if ( !IsLoaded("T") ) {
512 PhosLoader()->LoadTracks("UPDATE") ;
513 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
514 SetLoaded("T") ;
b0bba0af 515 }
7a9d98f9 516
88cb7938 517 return TrackSegments()->GetEntries() ;
518}
b0bba0af 519//____________________________________________________________________________
88cb7938 520Int_t AliPHOSGetter::ReadTreeP()
0bc3b8ed 521{
88cb7938 522 // Read the TrackSegments
7a9d98f9 523
b0bba0af 524
88cb7938 525 // gets TreeT from the root file (PHOS.TrackSegments.root)
526 if ( !IsLoaded("P") ) {
527 PhosLoader()->LoadRecParticles("UPDATE") ;
528 PhosLoader()->LoadPID("UPDATE") ;
529 SetLoaded("P") ;
479975d9 530 }
b0bba0af 531
88cb7938 532 return RecParticles()->GetEntries() ;
4ae78bb1 533}
4ae78bb1 534//____________________________________________________________________________
88cb7938 535Int_t AliPHOSGetter::ReadTreeS()
536{
537 // Read the SDigits
7a9d98f9 538
88cb7938 539
540 // gets TreeS from the root file (PHOS.SDigits.root)
541 if ( !IsLoaded("S") ) {
542 PhosLoader()->LoadSDigits("UPDATE") ;
543 PhosLoader()->LoadSDigitizer("UPDATE") ;
544 SetLoaded("S") ;
7a9d98f9 545 }
7a9d98f9 546
88cb7938 547 return SDigits()->GetEntries() ;
9bd3caba 548}
549
550//____________________________________________________________________________
88cb7938 551TClonesArray * AliPHOSGetter::SDigits()
9bd3caba 552{
88cb7938 553 // asks the Loader to return the Digits container
9bd3caba 554
88cb7938 555 TClonesArray * rv = 0 ;
9bd3caba 556
88cb7938 557 rv = PhosLoader()->SDigits() ;
558 if (!rv) {
559 PhosLoader()->MakeSDigitsArray() ;
560 rv = PhosLoader()->SDigits() ;
9bd3caba 561 }
88cb7938 562 return rv ;
9bd3caba 563}
564
7a9d98f9 565//____________________________________________________________________________
e957fea8 566AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 567{
e957fea8 568 // Returns pointer to the SDigitizer task
88cb7938 569 AliPHOSSDigitizer * rv ;
570 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
571 if (!rv) {
572 Event(0, "S") ;
573 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
9bd3caba 574 }
88cb7938 575 return rv ;
4ae78bb1 576}
577
578//____________________________________________________________________________
88cb7938 579TParticle * AliPHOSGetter::Secondary(const TParticle* p, const Int_t index) const
cb34a1fa 580{
581 // Return first (index=1) or second (index=2) secondary particle of primary particle p
582
583 if(index <= 0)
584 return 0 ;
585 if(index > 2)
586 return 0 ;
587
588 if(p) {
589 Int_t daughterIndex = p->GetDaughter(index-1) ;
88cb7938 590 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 591 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
cb34a1fa 592 }
593 else
594 return 0 ;
595}
596
597//____________________________________________________________________________
21cd0c07 598void AliPHOSGetter::Track(const Int_t itrack)
b0bba0af 599{
600 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
7a9d98f9 601
88cb7938 602 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 603
88cb7938 604 if( !TreeH() ) // load treeH the first time
605 rl->LoadHits() ;
59b46416 606
88cb7938 607 // first time create the container
608 TClonesArray * hits = Hits() ;
609 if ( hits )
610 hits->Clear() ;
fbf811ec 611
88cb7938 612 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
613 phosbranch->SetAddress(&hits) ;
614 phosbranch->GetEntry(itrack) ;
4ae78bb1 615}
616
617//____________________________________________________________________________
88cb7938 618TTree * AliPHOSGetter::TreeD() const
4ae78bb1 619{
e957fea8 620 // Returns pointer to the Digits Tree
88cb7938 621 TTree * rv = 0 ;
622 rv = PhosLoader()->TreeD() ;
623 if ( !rv ) {
624 PhosLoader()->MakeTree("D");
625 rv = PhosLoader()->TreeD() ;
626 }
b0bba0af 627
88cb7938 628 return rv ;
b0bba0af 629}
548f0134 630
b0bba0af 631//____________________________________________________________________________
88cb7938 632TTree * AliPHOSGetter::TreeH() const
0bc3b8ed 633{
e957fea8 634 // Returns pointer to the Hits Tree
88cb7938 635 TTree * rv = 0 ;
636 rv = PhosLoader()->TreeH() ;
637 if ( !rv ) {
638 PhosLoader()->MakeTree("H");
639 rv = PhosLoader()->TreeH() ;
7a9d98f9 640 }
4ae78bb1 641
88cb7938 642 return rv ;
4ae78bb1 643}
644
645//____________________________________________________________________________
88cb7938 646TTree * AliPHOSGetter::TreeR() const
4ae78bb1 647{
e957fea8 648 // Returns pointer to the RecPoints Tree
88cb7938 649 TTree * rv = 0 ;
650 rv = PhosLoader()->TreeR() ;
651 if ( !rv ) {
652 PhosLoader()->MakeTree("R");
653 rv = PhosLoader()->TreeR() ;
654 }
b0bba0af 655
88cb7938 656 return rv ;
4ae78bb1 657}
65549808 658
659//____________________________________________________________________________
88cb7938 660TTree * AliPHOSGetter::TreeT() const
65549808 661{
e957fea8 662 // Returns pointer to the TrackSegments Tree
88cb7938 663 TTree * rv = 0 ;
664 rv = PhosLoader()->TreeT() ;
665 if ( !rv ) {
666 PhosLoader()->MakeTree("T");
667 rv = PhosLoader()->TreeT() ;
668 }
b134c32f 669
88cb7938 670 return rv ;
65549808 671}
65549808 672//____________________________________________________________________________
88cb7938 673TTree * AliPHOSGetter::TreeP() const
65549808 674{
e957fea8 675 // Returns pointer to the RecParticles Tree
88cb7938 676 TTree * rv = 0 ;
677 rv = PhosLoader()->TreeP() ;
678 if ( !rv ) {
679 PhosLoader()->MakeTree("P");
680 rv = PhosLoader()->TreeP() ;
681 }
65549808 682
88cb7938 683 return rv ;
65549808 684}
685
686//____________________________________________________________________________
88cb7938 687TTree * AliPHOSGetter::TreeS() const
e957fea8 688{
689 // Returns pointer to the SDigits Tree
88cb7938 690 TTree * rv = 0 ;
691 rv = PhosLoader()->TreeS() ;
692 if ( !rv ) {
693 PhosLoader()->MakeTree("S");
694 rv = PhosLoader()->TreeS() ;
695 }
65549808 696
88cb7938 697 return rv ;
65549808 698}
fbf811ec 699
700//____________________________________________________________________________
88cb7938 701Bool_t AliPHOSGetter::VersionExists(TString & opt) const
0bc3b8ed 702{
88cb7938 703 // checks if the version with the present name already exists in the same directory
fbf811ec 704
88cb7938 705 Bool_t rv = kFALSE ;
706
707 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
708 TString version( rl->GetEventFolder()->GetName() ) ;
fbf811ec 709
88cb7938 710 opt.ToLower() ;
fbf811ec 711
88cb7938 712 if ( opt == "sdigits") {
713 // add the version name to the root file name
714 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
715 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
716 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
717 if ( !(gSystem->AccessPathName(fileName)) ) {
718 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
719 rv = kTRUE ;
fbf811ec 720 }
88cb7938 721 PhosLoader()->SetSDigitsFileName(fileName) ;
fbf811ec 722 }
fbf811ec 723
88cb7938 724 if ( opt == "digits") {
725 // add the version name to the root file name
726 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
727 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
728 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
729 if ( !(gSystem->AccessPathName(fileName)) ) {
730 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
731 rv = kTRUE ;
fbf811ec 732 }
88cb7938 733 PhosLoader()->SetDigitsFileName(fileName) ;
fbf811ec 734 }
735
88cb7938 736 return rv ;
fbf811ec 737
738}
88cb7938 739
fbf811ec 740//____________________________________________________________________________
88cb7938 741UShort_t AliPHOSGetter::EventPattern(void) const
fbf811ec 742{
88cb7938 743 // Return the pattern (trigger bit register) of the beam-test event
744 if(fBTE)
745 return fBTE->GetPattern() ;
746 else
747 return 0 ;
fbf811ec 748}
749//____________________________________________________________________________
88cb7938 750Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 751{
88cb7938 752 // Return the beam energy of the beam-test event
753 if(fBTE)
754 return fBTE->GetBeamEnergy() ;
755 else
756 return 0 ;
fbf811ec 757}