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