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