OpengAliceFile method removed, loaders data members set in the constructor, loading...
[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 = "" ;
d2713783 97
98 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
99 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
95635748 100 fESDFile = 0 ;
4ae78bb1 101}
fbf811ec 102
4ae78bb1 103//____________________________________________________________________________
0bc3b8ed 104AliPHOSGetter::~AliPHOSGetter()
105{
106 // dtor
88cb7938 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;
65549808 128}
4ae78bb1 129
130//____________________________________________________________________________
88cb7938 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()) ;
0c87da39 139 }
88cb7938 140 return rv ;
0c87da39 141}
142
143//____________________________________________________________________________
88cb7938 144TObjArray * AliPHOSGetter::CpvRecPoints()
4ae78bb1 145{
88cb7938 146 // asks the Loader to return the CPV RecPoints container
147
148 TObjArray * rv = 0 ;
4ae78bb1 149
88cb7938 150 rv = PhosLoader()->CpvRecPoints() ;
151 if (!rv) {
152 PhosLoader()->MakeRecPointsArray() ;
153 rv = PhosLoader()->CpvRecPoints() ;
b134c32f 154 }
88cb7938 155 return rv ;
4ae78bb1 156}
157
158//____________________________________________________________________________
88cb7938 159TClonesArray * AliPHOSGetter::Digits()
4ae78bb1 160{
88cb7938 161 // asks the Loader to return the Digits container
df25f7dd 162
88cb7938 163 TClonesArray * rv = 0 ;
164 rv = PhosLoader()->Digits() ;
7bb289a7 165
88cb7938 166 if( !rv ) {
167 PhosLoader()->MakeDigitsArray() ;
168 rv = PhosLoader()->Digits() ;
fbf811ec 169 }
88cb7938 170 return rv ;
fbf811ec 171}
d489fb96 172
fbf811ec 173//____________________________________________________________________________
88cb7938 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()) ;
48f12df6 182 }
88cb7938 183 return rv ;
4ae78bb1 184}
185
88cb7938 186
4ae78bb1 187//____________________________________________________________________________
88cb7938 188TObjArray * AliPHOSGetter::EmcRecPoints()
6ad0e528 189{
88cb7938 190 // asks the Loader to return the EMC RecPoints container
6ad0e528 191
88cb7938 192 TObjArray * rv = 0 ;
fbf811ec 193
88cb7938 194 rv = PhosLoader()->EmcRecPoints() ;
195 if (!rv) {
196 PhosLoader()->MakeRecPointsArray() ;
197 rv = PhosLoader()->EmcRecPoints() ;
198 }
199 return rv ;
6ad0e528 200}
201
202//____________________________________________________________________________
88cb7938 203TClonesArray * AliPHOSGetter::TrackSegments()
6ad0e528 204{
88cb7938 205 // asks the Loader to return the TrackSegments container
0bc3b8ed 206
88cb7938 207 TClonesArray * rv = 0 ;
6ad0e528 208
88cb7938 209 rv = PhosLoader()->TrackSegments() ;
210 if (!rv) {
211 PhosLoader()->MakeTrackSegmentsArray() ;
212 rv = PhosLoader()->TrackSegments() ;
6ad0e528 213 }
88cb7938 214 return rv ;
6ad0e528 215}
216
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()) ;
226 }
7a9d98f9 227 return rv ;
88cb7938 228}
cb34a1fa 229
230//____________________________________________________________________________
88cb7938 231TClonesArray * AliPHOSGetter::RecParticles()
232{
233 // asks the Loader to return the TrackSegments container
cb34a1fa 234
88cb7938 235 TClonesArray * rv = 0 ;
cb34a1fa 236
88cb7938 237 rv = PhosLoader()->RecParticles() ;
238 if (!rv) {
239 PhosLoader()->MakeRecParticlesArray() ;
240 rv = PhosLoader()->RecParticles() ;
cb34a1fa 241 }
88cb7938 242 return rv ;
cb34a1fa 243}
cb34a1fa 244//____________________________________________________________________________
fc7e2f43 245void AliPHOSGetter::Event(Int_t event, const char* opt)
88cb7938 246{
247 // Reads the content of all Tree's S, D and R
dbad285c 248
88cb7938 249 if ( event >= MaxEvent() ) {
250 Error("Event", "%d not found in TreeE !", event) ;
251 return ;
252 }
7a9d98f9 253
88cb7938 254 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 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) ;
7a9d98f9 263 }
88cb7938 264 else{
265 if(fBTE){
266 delete fBTE ;
267 fBTE = 0 ;
268 }
7a9d98f9 269 }
f1611b7c 270
88cb7938 271 // Loads the type of object(s) requested
7a9d98f9 272
88cb7938 273 rl->GetEvent(event) ;
fbf811ec 274
88cb7938 275 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
276 ReadPrimaries() ;
fbf811ec 277
88cb7938 278 if(strstr(opt,"H") )
279 ReadTreeH();
7a9d98f9 280
88cb7938 281 if(strstr(opt,"S") )
282 ReadTreeS() ;
7a9d98f9 283
88cb7938 284 if( strstr(opt,"D") )
285 ReadTreeD() ;
407ae4df 286
88cb7938 287 if( strstr(opt,"R") )
288 ReadTreeR() ;
b0bba0af 289
88cb7938 290 if( strstr(opt,"T") )
291 ReadTreeT() ;
f1611b7c 292
88cb7938 293 if( strstr(opt,"P") )
294 ReadTreeP() ;
95635748 295
88cb7938 296// if( strstr(opt,"Q") )
297// ReadTreeQA() ;
298
b0bba0af 299}
300
7a9d98f9 301
b0bba0af 302//____________________________________________________________________________
88cb7938 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()) ;
b0bba0af 308}
309
b0bba0af 310//____________________________________________________________________________
88cb7938 311 TClonesArray * AliPHOSGetter::Hits()
312{
313 // asks the loader to return the Hits container
314
315 TClonesArray * rv = 0 ;
b0bba0af 316
88cb7938 317 rv = PhosLoader()->Hits() ;
318 if ( !rv ) {
319 PhosLoader()->LoadHits("read");
320 rv = PhosLoader()->Hits() ;
321 }
322 return rv ;
b0bba0af 323}
548f0134 324
b0bba0af 325//____________________________________________________________________________
88cb7938 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
330
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) ;
335 }
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 }
7a9d98f9 355 }
7fba1747 356 else {
357 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
e191bb57 358 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
1c221c70 359 delete rl ;
88cb7938 360 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
7fba1747 361 }
b0bba0af 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() ;
368
369 return fgObjGetter ;
b0bba0af 370}
7a9d98f9 371
b0bba0af 372//____________________________________________________________________________
88cb7938 373AliPHOSGetter * AliPHOSGetter::Instance()
0bc3b8ed 374{
88cb7938 375 // Returns the pointer of the unique instance already defined
b0bba0af 376
95635748 377 if(!fgObjGetter && fgDebug)
378 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
b0bba0af 379
88cb7938 380 return fgObjGetter ;
381
b0bba0af 382}
383
b0bba0af 384//____________________________________________________________________________
88cb7938 385Int_t AliPHOSGetter::MaxEvent() const
0bc3b8ed 386{
88cb7938 387 // returns the number of events in the run (from TE)
7a9d98f9 388
88cb7938 389 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
390 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
391}
7a9d98f9 392
b0bba0af 393//____________________________________________________________________________
88cb7938 394TParticle * AliPHOSGetter::Primary(Int_t index) const
0bc3b8ed 395{
88cb7938 396 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
397 return rl->Stack()->Particle(index) ;
7a9d98f9 398}
b0bba0af 399
b0bba0af 400//____________________________________________________________________________
88cb7938 401AliPHOS * AliPHOSGetter:: PHOS() const
402{
403 // returns the PHOS object
404 AliPHOS * phos = dynamic_cast<AliPHOS*>(PhosLoader()->GetModulesFolder()->FindObject("PHOS")) ;
405 if (!phos)
406 if (fgDebug)
407 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
408 return phos ;
409}
b0bba0af 410
b0bba0af 411
b0bba0af 412
b0bba0af 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()) ;
b0bba0af 422 }
88cb7938 423 return rv ;
b0bba0af 424}
425
426//____________________________________________________________________________
88cb7938 427AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
428{
429 // Returns PHOS geometry
7a9d98f9 430
88cb7938 431 AliPHOSGeometry * rv = 0 ;
432 if (PHOS() )
433 rv = PHOS()->GetGeometry() ;
434 return rv ;
7a9d98f9 435}
b0bba0af 436
437//____________________________________________________________________________
88cb7938 438TClonesArray * AliPHOSGetter::Primaries()
0bc3b8ed 439{
88cb7938 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 ;
b0bba0af 447}
448
449//____________________________________________________________________________
88cb7938 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() ) ;
b0bba0af 456}
7a9d98f9 457
b0bba0af 458//____________________________________________________________________________
88cb7938 459void AliPHOSGetter::ReadPrimaries()
460{
461 // Read Primaries from Kinematics.root
b0bba0af 462
88cb7938 463 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
7a9d98f9 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 }
7a9d98f9 469
7fba1747 470 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 471 if (fgDebug)
472 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
7a9d98f9 473
7a9d98f9 474
88cb7938 475 // first time creates the container
476 if ( Primaries() )
477 fPrimaries->Clear() ;
b0bba0af 478
88cb7938 479 Int_t index = 0 ;
480 for (index = 0 ; index < fNPrimaries; index++) {
481 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
b0bba0af 482 }
88cb7938 483}
7a9d98f9 484
b0bba0af 485//____________________________________________________________________________
95635748 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
520//____________________________________________________________________________
88cb7938 521Int_t AliPHOSGetter::ReadTreeD()
522{
523 // Read the Digits
7a9d98f9 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") ;
b0bba0af 531 }
88cb7938 532 return Digits()->GetEntries() ;
533}
7a9d98f9 534
b0bba0af 535//____________________________________________________________________________
88cb7938 536Int_t AliPHOSGetter::ReadTreeH()
0bc3b8ed 537{
88cb7938 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}
b0bba0af 547
548//____________________________________________________________________________
88cb7938 549Int_t AliPHOSGetter::ReadTreeR()
550{
551 // Read the RecPoints
b0bba0af 552
b0bba0af 553
88cb7938 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") ;
b0bba0af 559 }
7a9d98f9 560
88cb7938 561 return EmcRecPoints()->GetEntries() ;
7bb289a7 562}
88cb7938 563
7bb289a7 564//____________________________________________________________________________
88cb7938 565Int_t AliPHOSGetter::ReadTreeT()
0bc3b8ed 566{
88cb7938 567 // Read the TrackSegments
7a9d98f9 568
b0bba0af 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") ;
b0bba0af 575 }
7a9d98f9 576
88cb7938 577 return TrackSegments()->GetEntries() ;
578}
b0bba0af 579//____________________________________________________________________________
88cb7938 580Int_t AliPHOSGetter::ReadTreeP()
0bc3b8ed 581{
88cb7938 582 // Read the TrackSegments
7a9d98f9 583
b0bba0af 584
88cb7938 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") ;
479975d9 590 }
b0bba0af 591
88cb7938 592 return RecParticles()->GetEntries() ;
4ae78bb1 593}
4ae78bb1 594//____________________________________________________________________________
88cb7938 595Int_t AliPHOSGetter::ReadTreeS()
596{
597 // Read the SDigits
7a9d98f9 598
88cb7938 599
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 }
7a9d98f9 606
88cb7938 607 return SDigits()->GetEntries() ;
9bd3caba 608}
609
610//____________________________________________________________________________
88cb7938 611TClonesArray * AliPHOSGetter::SDigits()
9bd3caba 612{
88cb7938 613 // asks the Loader to return the Digits container
9bd3caba 614
88cb7938 615 TClonesArray * rv = 0 ;
9bd3caba 616
88cb7938 617 rv = PhosLoader()->SDigits() ;
618 if (!rv) {
619 PhosLoader()->MakeSDigitsArray() ;
620 rv = PhosLoader()->SDigits() ;
9bd3caba 621 }
88cb7938 622 return rv ;
9bd3caba 623}
624
7a9d98f9 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()) ;
9bd3caba 634 }
88cb7938 635 return rv ;
4ae78bb1 636}
637
638//____________________________________________________________________________
fc7e2f43 639TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
cb34a1fa 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 ;
647
648 if(p) {
649 Int_t daughterIndex = p->GetDaughter(index-1) ;
88cb7938 650 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 651 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
cb34a1fa 652 }
653 else
654 return 0 ;
655}
656
657//____________________________________________________________________________
fc7e2f43 658void AliPHOSGetter::Track(Int_t itrack)
b0bba0af 659{
660 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
7a9d98f9 661
88cb7938 662 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 663
88cb7938 664 if( !TreeH() ) // load treeH the first time
665 rl->LoadHits() ;
59b46416 666
88cb7938 667 // first time create the container
668 TClonesArray * hits = Hits() ;
669 if ( hits )
670 hits->Clear() ;
fbf811ec 671
88cb7938 672 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
673 phosbranch->SetAddress(&hits) ;
674 phosbranch->GetEntry(itrack) ;
4ae78bb1 675}
676
677//____________________________________________________________________________
88cb7938 678TTree * AliPHOSGetter::TreeD() const
4ae78bb1 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() ;
686 }
b0bba0af 687
88cb7938 688 return rv ;
b0bba0af 689}
548f0134 690
b0bba0af 691//____________________________________________________________________________
88cb7938 692TTree * AliPHOSGetter::TreeH() const
0bc3b8ed 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() ;
7a9d98f9 700 }
4ae78bb1 701
88cb7938 702 return rv ;
4ae78bb1 703}
704
705//____________________________________________________________________________
88cb7938 706TTree * AliPHOSGetter::TreeR() const
4ae78bb1 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 ;
4ae78bb1 717}
65549808 718
719//____________________________________________________________________________
88cb7938 720TTree * AliPHOSGetter::TreeT() const
65549808 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 }
b134c32f 729
88cb7938 730 return rv ;
65549808 731}
65549808 732//____________________________________________________________________________
88cb7938 733TTree * AliPHOSGetter::TreeP() const
65549808 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 }
65549808 742
88cb7938 743 return rv ;
65549808 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() ;
755 }
65549808 756
88cb7938 757 return rv ;
65549808 758}
fbf811ec 759
760//____________________________________________________________________________
88cb7938 761Bool_t AliPHOSGetter::VersionExists(TString & opt) const
0bc3b8ed 762{
88cb7938 763 // checks if the version with the present name already exists in the same directory
fbf811ec 764
88cb7938 765 Bool_t rv = kFALSE ;
766
767 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
768 TString version( rl->GetEventFolder()->GetName() ) ;
fbf811ec 769
88cb7938 770 opt.ToLower() ;
fbf811ec 771
88cb7938 772 if ( opt == "sdigits") {
773 // add the version name to the root file name
774 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 775 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 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 ;
fbf811ec 780 }
88cb7938 781 PhosLoader()->SetSDigitsFileName(fileName) ;
fbf811ec 782 }
fbf811ec 783
88cb7938 784 if ( opt == "digits") {
785 // add the version name to the root file name
786 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 787 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 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 ;
fbf811ec 792 }
793 }
794
88cb7938 795 return rv ;
fbf811ec 796
797}
88cb7938 798
fbf811ec 799//____________________________________________________________________________
88cb7938 800UShort_t AliPHOSGetter::EventPattern(void) const
fbf811ec 801{
88cb7938 802 // Return the pattern (trigger bit register) of the beam-test event
803 if(fBTE)
804 return fBTE->GetPattern() ;
805 else
806 return 0 ;
fbf811ec 807}
808//____________________________________________________________________________
88cb7938 809Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 810{
88cb7938 811 // Return the beam energy of the beam-test event
812 if(fBTE)
813 return fBTE->GetBeamEnergy() ;
814 else
815 return 0 ;
fbf811ec 816}