Removed the QA checker mechanism
[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()
dca3a7c4 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
7bb289a7 91 }
93aeb834 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);
85290134 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 ;
4ae78bb1 111}
fbf811ec 112
4ae78bb1 113//____________________________________________________________________________
0bc3b8ed 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;
65549808 149}
4ae78bb1 150
151//____________________________________________________________________________
88cb7938 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()) ;
0c87da39 160 }
88cb7938 161 return rv ;
0c87da39 162}
163
164//____________________________________________________________________________
88cb7938 165TObjArray * AliPHOSGetter::CpvRecPoints()
4ae78bb1 166{
88cb7938 167 // asks the Loader to return the CPV RecPoints container
168
169 TObjArray * rv = 0 ;
4ae78bb1 170
88cb7938 171 rv = PhosLoader()->CpvRecPoints() ;
172 if (!rv) {
173 PhosLoader()->MakeRecPointsArray() ;
174 rv = PhosLoader()->CpvRecPoints() ;
b134c32f 175 }
88cb7938 176 return rv ;
4ae78bb1 177}
178
179//____________________________________________________________________________
88cb7938 180TClonesArray * AliPHOSGetter::Digits()
4ae78bb1 181{
88cb7938 182 // asks the Loader to return the Digits container
df25f7dd 183
88cb7938 184 TClonesArray * rv = 0 ;
185 rv = PhosLoader()->Digits() ;
7bb289a7 186
88cb7938 187 if( !rv ) {
188 PhosLoader()->MakeDigitsArray() ;
189 rv = PhosLoader()->Digits() ;
fbf811ec 190 }
88cb7938 191 return rv ;
fbf811ec 192}
d489fb96 193
fbf811ec 194//____________________________________________________________________________
88cb7938 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()) ;
48f12df6 203 }
88cb7938 204 return rv ;
4ae78bb1 205}
206
88cb7938 207
4ae78bb1 208//____________________________________________________________________________
88cb7938 209TObjArray * AliPHOSGetter::EmcRecPoints()
6ad0e528 210{
88cb7938 211 // asks the Loader to return the EMC RecPoints container
6ad0e528 212
88cb7938 213 TObjArray * rv = 0 ;
fbf811ec 214
88cb7938 215 rv = PhosLoader()->EmcRecPoints() ;
216 if (!rv) {
217 PhosLoader()->MakeRecPointsArray() ;
218 rv = PhosLoader()->EmcRecPoints() ;
219 }
220 return rv ;
6ad0e528 221}
222
223//____________________________________________________________________________
88cb7938 224TClonesArray * AliPHOSGetter::TrackSegments()
6ad0e528 225{
88cb7938 226 // asks the Loader to return the TrackSegments container
0bc3b8ed 227
88cb7938 228 TClonesArray * rv = 0 ;
6ad0e528 229
88cb7938 230 rv = PhosLoader()->TrackSegments() ;
231 if (!rv) {
232 PhosLoader()->MakeTrackSegmentsArray() ;
233 rv = PhosLoader()->TrackSegments() ;
6ad0e528 234 }
88cb7938 235 return rv ;
6ad0e528 236}
237
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()) ;
247 }
7a9d98f9 248 return rv ;
88cb7938 249}
cb34a1fa 250
251//____________________________________________________________________________
88cb7938 252TClonesArray * AliPHOSGetter::RecParticles()
253{
254 // asks the Loader to return the TrackSegments container
cb34a1fa 255
88cb7938 256 TClonesArray * rv = 0 ;
cb34a1fa 257
88cb7938 258 rv = PhosLoader()->RecParticles() ;
259 if (!rv) {
260 PhosLoader()->MakeRecParticlesArray() ;
261 rv = PhosLoader()->RecParticles() ;
cb34a1fa 262 }
88cb7938 263 return rv ;
cb34a1fa 264}
cb34a1fa 265//____________________________________________________________________________
fc7e2f43 266void AliPHOSGetter::Event(Int_t event, const char* opt)
88cb7938 267{
268 // Reads the content of all Tree's S, D and R
dbad285c 269
66f895c8 270// if ( event >= MaxEvent() ) {
271// Error("Event", "%d not found in TreeE !", event) ;
272// return ;
273// }
7a9d98f9 274
88cb7938 275 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 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// }
f1611b7c 291
88cb7938 292 // Loads the type of object(s) requested
7a9d98f9 293
88cb7938 294 rl->GetEvent(event) ;
fbf811ec 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 }
b0bba0af 315
66f895c8 316 if( strstr(opt,"T") ){
88cb7938 317 ReadTreeT() ;
66f895c8 318 }
f1611b7c 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
b0bba0af 332}
333
7a9d98f9 334
b0bba0af 335//____________________________________________________________________________
88cb7938 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()) ;
b0bba0af 341}
342
b0bba0af 343//____________________________________________________________________________
88cb7938 344 TClonesArray * AliPHOSGetter::Hits()
345{
346 // asks the loader to return the Hits container
347
348 TClonesArray * rv = 0 ;
b0bba0af 349
88cb7938 350 rv = PhosLoader()->Hits() ;
351 if ( !rv ) {
352 PhosLoader()->LoadHits("read");
353 rv = PhosLoader()->Hits() ;
354 }
355 return rv ;
b0bba0af 356}
548f0134 357
b0bba0af 358//____________________________________________________________________________
88cb7938 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
363
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) ;
368 }
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 }
7a9d98f9 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 }
b0bba0af 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() ;
401
402 return fgObjGetter ;
b0bba0af 403}
7a9d98f9 404
b0bba0af 405//____________________________________________________________________________
88cb7938 406AliPHOSGetter * AliPHOSGetter::Instance()
0bc3b8ed 407{
88cb7938 408 // Returns the pointer of the unique instance already defined
b0bba0af 409
95635748 410 if(!fgObjGetter && fgDebug)
411 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
b0bba0af 412
88cb7938 413 return fgObjGetter ;
414
b0bba0af 415}
416
b0bba0af 417//____________________________________________________________________________
88cb7938 418Int_t AliPHOSGetter::MaxEvent() const
0bc3b8ed 419{
88cb7938 420 // returns the number of events in the run (from TE)
7a9d98f9 421
88cb7938 422 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
423 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
424}
7a9d98f9 425
b0bba0af 426//____________________________________________________________________________
88cb7938 427TParticle * AliPHOSGetter::Primary(Int_t index) const
0bc3b8ed 428{
88cb7938 429 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
430 return rl->Stack()->Particle(index) ;
7a9d98f9 431}
b0bba0af 432
b0bba0af 433//____________________________________________________________________________
88cb7938 434AliPHOS * AliPHOSGetter:: PHOS() const
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 }
88cb7938 447 if (!phos)
448 if (fgDebug)
449 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
450 return phos ;
451}
b0bba0af 452
b0bba0af 453
b0bba0af 454
b0bba0af 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()) ;
b0bba0af 464 }
88cb7938 465 return rv ;
b0bba0af 466}
467
468//____________________________________________________________________________
88cb7938 469AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
470{
471 // Returns PHOS geometry
7a9d98f9 472
88cb7938 473 AliPHOSGeometry * rv = 0 ;
474 if (PHOS() )
475 rv = PHOS()->GetGeometry() ;
476 return rv ;
7a9d98f9 477}
b0bba0af 478
479//____________________________________________________________________________
88cb7938 480TClonesArray * AliPHOSGetter::Primaries()
0bc3b8ed 481{
88cb7938 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 ;
b0bba0af 489}
490
491//____________________________________________________________________________
88cb7938 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() ) ;
b0bba0af 498}
7a9d98f9 499
b0bba0af 500//____________________________________________________________________________
88cb7938 501void AliPHOSGetter::ReadPrimaries()
502{
503 // Read Primaries from Kinematics.root
b0bba0af 504
88cb7938 505 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
7a9d98f9 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 }
7a9d98f9 511
7fba1747 512 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 513 if (fgDebug)
514 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
7a9d98f9 515
7a9d98f9 516
88cb7938 517 // first time creates the container
518 if ( Primaries() )
519 fPrimaries->Clear() ;
b0bba0af 520
88cb7938 521 Int_t index = 0 ;
522 for (index = 0 ; index < fNPrimaries; index++) {
523 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
b0bba0af 524 }
88cb7938 525}
7a9d98f9 526
b0bba0af 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
546//____________________________________________________________________________
a43c51c3 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}
a43c51c3 585//____________________________________________________________________________
88cb7938 586Int_t AliPHOSGetter::ReadTreeD()
587{
588 // Read the Digits
7a9d98f9 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()
0bc3b8ed 598{
88cb7938 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}
b0bba0af 608
609//____________________________________________________________________________
88cb7938 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 //}
7a9d98f9 621
88cb7938 622 return EmcRecPoints()->GetEntries() ;
7bb289a7 623}
88cb7938 624
7bb289a7 625//____________________________________________________________________________
88cb7938 626Int_t AliPHOSGetter::ReadTreeT()
0bc3b8ed 627{
88cb7938 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 //}
7a9d98f9 637
88cb7938 638 return TrackSegments()->GetEntries() ;
639}
b0bba0af 640//____________________________________________________________________________
88cb7938 641Int_t AliPHOSGetter::ReadTreeP()
0bc3b8ed 642{
41c29fde 643 // Read the RecParticles
b0bba0af 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 //}
b0bba0af 653
88cb7938 654 return RecParticles()->GetEntries() ;
4ae78bb1 655}
4ae78bb1 656//____________________________________________________________________________
88cb7938 657Int_t AliPHOSGetter::ReadTreeS()
658{
659 // Read the SDigits
7a9d98f9 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 //}
7a9d98f9 668
88cb7938 669 return SDigits()->GetEntries() ;
9bd3caba 670}
671
672//____________________________________________________________________________
677c8a30 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
695//____________________________________________________________________________
88cb7938 696TClonesArray * AliPHOSGetter::SDigits()
9bd3caba 697{
88cb7938 698 // asks the Loader to return the Digits container
9bd3caba 699
88cb7938 700 TClonesArray * rv = 0 ;
9bd3caba 701
88cb7938 702 rv = PhosLoader()->SDigits() ;
703 if (!rv) {
704 PhosLoader()->MakeSDigitsArray() ;
705 rv = PhosLoader()->SDigits() ;
9bd3caba 706 }
88cb7938 707 return rv ;
9bd3caba 708}
709
7a9d98f9 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()) ;
9bd3caba 719 }
88cb7938 720 return rv ;
4ae78bb1 721}
722
723//____________________________________________________________________________
fc7e2f43 724TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
cb34a1fa 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 ;
732
733 if(p) {
734 Int_t daughterIndex = p->GetDaughter(index-1) ;
88cb7938 735 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 736 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
cb34a1fa 737 }
738 else
739 return 0 ;
740}
741
742//____________________________________________________________________________
fc7e2f43 743void AliPHOSGetter::Track(Int_t itrack)
b0bba0af 744{
745 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
7a9d98f9 746
88cb7938 747 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 748
88cb7938 749 if( !TreeH() ) // load treeH the first time
750 rl->LoadHits() ;
59b46416 751
88cb7938 752 // first time create the container
753 TClonesArray * hits = Hits() ;
754 if ( hits )
755 hits->Clear() ;
fbf811ec 756
88cb7938 757 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
758 phosbranch->SetAddress(&hits) ;
759 phosbranch->GetEntry(itrack) ;
4ae78bb1 760}
761
762//____________________________________________________________________________
88cb7938 763TTree * AliPHOSGetter::TreeD() const
4ae78bb1 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() ;
771 }
b0bba0af 772
88cb7938 773 return rv ;
b0bba0af 774}
548f0134 775
b0bba0af 776//____________________________________________________________________________
88cb7938 777TTree * AliPHOSGetter::TreeH() const
0bc3b8ed 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() ;
7a9d98f9 785 }
4ae78bb1 786
88cb7938 787 return rv ;
4ae78bb1 788}
789
790//____________________________________________________________________________
88cb7938 791TTree * AliPHOSGetter::TreeR() const
4ae78bb1 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 ;
4ae78bb1 802}
65549808 803
804//____________________________________________________________________________
88cb7938 805TTree * AliPHOSGetter::TreeT() const
65549808 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 }
b134c32f 814
88cb7938 815 return rv ;
65549808 816}
65549808 817//____________________________________________________________________________
88cb7938 818TTree * AliPHOSGetter::TreeP() const
65549808 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 }
65549808 827
88cb7938 828 return rv ;
65549808 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() ;
840 }
65549808 841
88cb7938 842 return rv ;
65549808 843}
fbf811ec 844
845//____________________________________________________________________________
88cb7938 846Bool_t AliPHOSGetter::VersionExists(TString & opt) const
0bc3b8ed 847{
88cb7938 848 // checks if the version with the present name already exists in the same directory
fbf811ec 849
88cb7938 850 Bool_t rv = kFALSE ;
851
852 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
853 TString version( rl->GetEventFolder()->GetName() ) ;
fbf811ec 854
88cb7938 855 opt.ToLower() ;
fbf811ec 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 ;
fbf811ec 865 }
88cb7938 866 PhosLoader()->SetSDigitsFileName(fileName) ;
fbf811ec 867 }
fbf811ec 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 ;
fbf811ec 877 }
878 }
879
88cb7938 880 return rv ;
fbf811ec 881
882}
88cb7938 883
fbf811ec 884//____________________________________________________________________________
88cb7938 885UShort_t AliPHOSGetter::EventPattern(void) const
fbf811ec 886{
88cb7938 887 // Return the pattern (trigger bit register) of the beam-test event
888 if(fBTE)
889 return fBTE->GetPattern() ;
890 else
891 return 0 ;
fbf811ec 892}
893//____________________________________________________________________________
88cb7938 894Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 895{
88cb7938 896 // Return the beam energy of the beam-test event
897 if(fBTE)
898 return fBTE->GetBeamEnergy() ;
899 else
900 return 0 ;
fbf811ec 901}