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