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