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