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