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