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