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