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