]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGetter.cxx
class is now linked to the central trigger classes in STEER
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
CommitLineData
4ae78bb1 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
803d1ab0 16/* $Id$ */
4ae78bb1 17
18//_________________________________________________________________________
19// A singleton. This class should be used in the analysis stage to get
20// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21// instead of directly reading them from galice.root file. This container
22// ensures, that one reads Digits, made of these particular digits, RecPoints,
23// made of these particular RecPoints, TrackSegments and RecParticles.
24// This becomes non trivial if there are several identical branches, produced with
25// different set of parameters.
26//
27// An example of how to use (see also class AliPHOSAnalyser):
28// AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ;
29// for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
30// AliPHOSRecParticle * part = gime->RecParticle(1) ;
31// ................
2a657981 32// gime->Event(event) ; // reads new event from galice.root
4ae78bb1 33//
2a657981 34//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35//*-- Completely redesigned by Dmitri Peressounko March 2001
4ae78bb1 36//
37//*-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
38//*-- systematic usage of TFolders without changing the interface
39//////////////////////////////////////////////////////////////////////////////
40
4ae78bb1 41// --- ROOT system ---
88cb7938 42
d7b234dd 43#include <TFile.h>
44#include <TROOT.h>
45#include <TSystem.h>
46#include <TParticle.h>
a43c51c3 47#include <TF1.h>
e4d04cf1 48#include <TGraph.h>
ff808dc7 49//#include <TCanvas.h>
351dd634 50//#include <TFrame.h>
4ae78bb1 51
52// --- Standard library ---
4ae78bb1 53
54// --- AliRoot header files ---
024a7e64 55#include "AliESD.h"
56#include "AliHeader.h"
57#include "AliMC.h"
e957fea8 58#include "AliPHOS.h"
024a7e64 59#include "AliPHOSBeamTestEvent.h"
60#include "AliPHOSGetter.h"
61#include "AliPHOSLoader.h"
88cb7938 62#include "AliRunLoader.h"
63#include "AliStack.h"
a43c51c3 64#include "AliPHOSRawStream.h"
65#include "AliRawReaderFile.h"
e4d04cf1 66#include "AliLog.h"
7ca0684e 67#include "AliCDBLocal.h"
68#include "AliCDBStorage.h"
9e1ceb13 69#include "AliCDBManager.h"
88cb7938 70
4ae78bb1 71ClassImp(AliPHOSGetter)
72
88cb7938 73AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
74AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
75Int_t AliPHOSGetter::fgDebug = 0;
7ca0684e 76AliPHOSCalibData* AliPHOSGetter::fCalibData = 0;
88cb7938 77
78// TFile * AliPHOSGetter::fgFile = 0 ;
4ae78bb1 79
80//____________________________________________________________________________
88cb7938 81AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
4ae78bb1 82{
88cb7938 83 // ctor only called by Instance()
4ae78bb1 84
88cb7938 85 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
86 if (!rl) {
87 rl = AliRunLoader::Open(headerFile, version, openingOption);
88 if (!rl) {
89 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
90 return ;
91 }
92 if (rl->GetAliRun() == 0x0) {
93 rl->LoadgAlice();
94 gAlice = rl->GetAliRun(); // should be removed
12a7cec1 95 rl->LoadHeader();
88cb7938 96 }
fbf811ec 97 }
88cb7938 98 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
99 if ( !fgPhosLoader )
100 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
101 else
102 fgPhosLoader->SetTitle(version);
103
88cb7938 104 // initialize data members
105 SetDebug(0) ;
106 fBTE = 0 ;
107 fPrimaries = 0 ;
108 fLoadingStatus = "" ;
d2713783 109
110 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
111 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
95635748 112 fESDFile = 0 ;
677c8a30 113 fESD = 0 ;
114 fESDTree = 0 ;
66f895c8 115 fRawDigits = kFALSE ;
7ca0684e 116
88cb7938 117}
9bd3caba 118
88cb7938 119//____________________________________________________________________________
120AliPHOSGetter::~AliPHOSGetter()
121{
122 // dtor
66f895c8 123 if(fgPhosLoader){
124 delete fgPhosLoader ;
125 fgPhosLoader = 0 ;
126 }
127 if(fBTE){
128 delete fBTE ;
129 fBTE = 0 ;
130 }
131 if(fPrimaries){
132 fPrimaries->Delete() ;
133 delete fPrimaries ;
134 }
677c8a30 135 if (fESD)
136 delete fESD ;
137 if (fESDTree)
66f895c8 138 delete fESDTree ;
139
7c193632 140 fgObjGetter = 0;
0ef40383 141}
142
143//____________________________________________________________________________
144void AliPHOSGetter::Reset()
145{
146 // resets things in case the getter is called consecutively with different files
147 // the PHOS Loader is already deleted by the Run Loader
148
149 if (fPrimaries) {
150 fPrimaries->Delete() ;
151 delete fPrimaries ;
152 }
153 fgPhosLoader = 0;
154 fgObjGetter = 0;
88cb7938 155}
fbf811ec 156
88cb7938 157//____________________________________________________________________________
158AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
159{
e957fea8 160 // Returns pointer to the Clusterizer task
88cb7938 161 AliPHOSClusterizer * rv ;
162 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
163 if (!rv) {
164 Event(0, "R") ;
165 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
166 }
167 return rv ;
168}
4ae78bb1 169
88cb7938 170//____________________________________________________________________________
171TObjArray * AliPHOSGetter::CpvRecPoints()
172{
173 // asks the Loader to return the CPV RecPoints container
4ae78bb1 174
88cb7938 175 TObjArray * rv = 0 ;
176
177 rv = PhosLoader()->CpvRecPoints() ;
178 if (!rv) {
179 PhosLoader()->MakeRecPointsArray() ;
180 rv = PhosLoader()->CpvRecPoints() ;
181 }
182 return rv ;
183}
dca3a7c4 184
88cb7938 185//____________________________________________________________________________
186TClonesArray * AliPHOSGetter::Digits()
187{
188 // asks the Loader to return the Digits container
7bb289a7 189
88cb7938 190 TClonesArray * rv = 0 ;
191 rv = PhosLoader()->Digits() ;
7bb289a7 192
88cb7938 193 if( !rv ) {
194 PhosLoader()->MakeDigitsArray() ;
195 rv = PhosLoader()->Digits() ;
4ae78bb1 196 }
88cb7938 197 return rv ;
198}
4b808d52 199
88cb7938 200//____________________________________________________________________________
201AliPHOSDigitizer * AliPHOSGetter::Digitizer()
202{
e957fea8 203 // Returns pointer to the Digitizer task
88cb7938 204 AliPHOSDigitizer * rv ;
205 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
206 if (!rv) {
207 Event(0, "D") ;
208 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
209 }
210 return rv ;
4ae78bb1 211}
fbf811ec 212
88cb7938 213
4ae78bb1 214//____________________________________________________________________________
88cb7938 215TObjArray * AliPHOSGetter::EmcRecPoints()
0bc3b8ed 216{
88cb7938 217 // asks the Loader to return the EMC RecPoints container
d489fb96 218
88cb7938 219 TObjArray * rv = 0 ;
65549808 220
88cb7938 221 rv = PhosLoader()->EmcRecPoints() ;
222 if (!rv) {
223 PhosLoader()->MakeRecPointsArray() ;
224 rv = PhosLoader()->EmcRecPoints() ;
89165262 225 }
88cb7938 226 return rv ;
81bb1a45 227}
7a9d98f9 228
65549808 229//____________________________________________________________________________
88cb7938 230TClonesArray * AliPHOSGetter::TrackSegments()
65549808 231{
88cb7938 232 // asks the Loader to return the TrackSegments container
233
234 TClonesArray * rv = 0 ;
235
236 rv = PhosLoader()->TrackSegments() ;
237 if (!rv) {
238 PhosLoader()->MakeTrackSegmentsArray() ;
239 rv = PhosLoader()->TrackSegments() ;
240 }
241 return rv ;
65549808 242}
4ae78bb1 243
0c87da39 244//____________________________________________________________________________
e957fea8 245AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
88cb7938 246{
e957fea8 247 // Returns pointer to the TrackSegmentMaker task
88cb7938 248 AliPHOSTrackSegmentMaker * rv ;
249 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
250 if (!rv) {
251 Event(0, "T") ;
252 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
0c87da39 253 }
88cb7938 254 return rv ;
0c87da39 255}
256
4ae78bb1 257//____________________________________________________________________________
88cb7938 258TClonesArray * AliPHOSGetter::RecParticles()
4ae78bb1 259{
88cb7938 260 // asks the Loader to return the TrackSegments container
261
262 TClonesArray * rv = 0 ;
4ae78bb1 263
88cb7938 264 rv = PhosLoader()->RecParticles() ;
265 if (!rv) {
266 PhosLoader()->MakeRecParticlesArray() ;
267 rv = PhosLoader()->RecParticles() ;
b134c32f 268 }
88cb7938 269 return rv ;
4ae78bb1 270}
4ae78bb1 271//____________________________________________________________________________
fc7e2f43 272void AliPHOSGetter::Event(Int_t event, const char* opt)
4ae78bb1 273{
88cb7938 274 // Reads the content of all Tree's S, D and R
548f0134 275
66f895c8 276// if ( event >= MaxEvent() ) {
277// Error("Event", "%d not found in TreeE !", event) ;
278// return ;
279// }
4ae78bb1 280
88cb7938 281 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
df25f7dd 282
66f895c8 283// // checks if we are dealing with test-beam data
284// TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
285// if(btb){
286// if(!fBTE)
287// fBTE = new AliPHOSBeamTestEvent() ;
288// btb->SetAddress(&fBTE) ;
289// btb->GetEntry(event) ;
290// }
291// else{
292// if(fBTE){
293// delete fBTE ;
294// fBTE = 0 ;
295// }
296// }
88cb7938 297
298 // Loads the type of object(s) requested
b134c32f 299
88cb7938 300 rl->GetEvent(event) ;
301
66f895c8 302 if(strstr(opt,"X") || (strcmp(opt,"")==0)){
88cb7938 303 ReadPrimaries() ;
66f895c8 304 }
305
306 if(strstr(opt,"H") ){
88cb7938 307 ReadTreeH();
66f895c8 308 }
309
310 if(strstr(opt,"S") ){
88cb7938 311 ReadTreeS() ;
66f895c8 312 }
313
314 if(strstr(opt,"D") ){
88cb7938 315 ReadTreeD() ;
66f895c8 316 }
317
318 if(strstr(opt,"R") ){
88cb7938 319 ReadTreeR() ;
66f895c8 320 }
88cb7938 321
66f895c8 322 if( strstr(opt,"T") ){
88cb7938 323 ReadTreeT() ;
66f895c8 324 }
88cb7938 325
66f895c8 326 if( strstr(opt,"P") ){
88cb7938 327 ReadTreeP() ;
66f895c8 328 }
677c8a30 329
66f895c8 330 if( strstr(opt,"E") ){
677c8a30 331 ReadTreeE(event) ;
3cf4f75f 332 }
333
334}
335
336
337//____________________________________________________________________________
338void AliPHOSGetter::Event(AliRawReader *rawReader, const char* opt)
339{
340 // Reads the raw event from rawReader
a43c51c3 341
f88e2313 342 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
343
3cf4f75f 344 if( strstr(opt,"W") ){
f88e2313 345 rawReader->NextEvent();
346 Int_t iEvent = rl->GetEventNumber();
347 rl->GetEvent(iEvent);
3cf4f75f 348 ReadRaw(rawReader) ;
f88e2313 349 rl->SetEventNumber(++iEvent);
66f895c8 350 }
95635748 351
88cb7938 352}
353
354
355//____________________________________________________________________________
356Int_t AliPHOSGetter::EventNumber() const
357 {
358 // return the current event number
359 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
360 return static_cast<Int_t>(rl->GetEventNumber()) ;
fbf811ec 361}
d489fb96 362
fbf811ec 363//____________________________________________________________________________
88cb7938 364 TClonesArray * AliPHOSGetter::Hits()
fbf811ec 365{
88cb7938 366 // asks the loader to return the Hits container
367
368 TClonesArray * rv = 0 ;
369
370 rv = PhosLoader()->Hits() ;
371 if ( !rv ) {
372 PhosLoader()->LoadHits("read");
373 rv = PhosLoader()->Hits() ;
fbf811ec 374 }
88cb7938 375 return rv ;
376}
fbf811ec 377
88cb7938 378//____________________________________________________________________________
379AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
380{
381 // Creates and returns the pointer of the unique instance
382 // Must be called only when the environment has changed
d489fb96 383
88cb7938 384 if(!fgObjGetter){ // first time the getter is called
385 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
fbf811ec 386 }
88cb7938 387 else { // the getter has been called previously
388 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
389 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
390 // check if the file is already open
391 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
392
393 if ( !galiceFile )
394 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
395
396 else { // the file is already open check the version name
397 TString currentVersionName = rl->GetEventFolder()->GetName() ;
398 TString newVersionName(version) ;
399 if (currentVersionName == newVersionName)
400 if(fgDebug)
401 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
402 else {
403 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
404 }
405 }
406 }
7fba1747 407 else {
408 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
e191bb57 409 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
1c221c70 410 delete rl ;
88cb7938 411 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
7fba1747 412 }
48f12df6 413 }
88cb7938 414 if (!fgObjGetter)
95635748 415 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
88cb7938 416 else
417 if (fgDebug)
418 Print() ;
4ae78bb1 419
88cb7938 420 return fgObjGetter ;
4ae78bb1 421}
422
6ad0e528 423//____________________________________________________________________________
88cb7938 424AliPHOSGetter * AliPHOSGetter::Instance()
6ad0e528 425{
88cb7938 426 // Returns the pointer of the unique instance already defined
fbf811ec 427
95635748 428 if(!fgObjGetter && fgDebug)
429 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
6ad0e528 430
88cb7938 431 return fgObjGetter ;
432
6ad0e528 433}
434
435//____________________________________________________________________________
88cb7938 436Int_t AliPHOSGetter::MaxEvent() const
6ad0e528 437{
88cb7938 438 // returns the number of events in the run (from TE)
0bc3b8ed 439
88cb7938 440 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
441 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
6ad0e528 442}
443
444//____________________________________________________________________________
88cb7938 445TParticle * AliPHOSGetter::Primary(Int_t index) const
6ad0e528 446{
88cb7938 447 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
448 return rl->Stack()->Particle(index) ;
449}
6ad0e528 450
4ae78bb1 451//____________________________________________________________________________
88cb7938 452AliPHOS * AliPHOSGetter:: PHOS() const
4ae78bb1 453{
454 // returns the PHOS object
5c4bcd63 455 AliPHOSLoader * loader = 0;
456 static AliPHOSLoader * oldloader = 0;
457 static AliPHOS * phos = 0;
458
459 loader = PhosLoader();
460
461 if ( loader != oldloader) {
462 phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
463 oldloader = loader;
464 }
7a9d98f9 465 if (!phos)
88cb7938 466 if (fgDebug)
467 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
7a9d98f9 468 return phos ;
4ae78bb1 469}
470
88cb7938 471
472
473//____________________________________________________________________________
e957fea8 474AliPHOSPID * AliPHOSGetter::PID()
88cb7938 475{
e957fea8 476 // Returns pointer to the PID task
88cb7938 477 AliPHOSPID * rv ;
478 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
479 if (!rv) {
480 Event(0, "P") ;
481 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
482 }
483 return rv ;
484}
485
4ae78bb1 486//____________________________________________________________________________
88cb7938 487AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
4ae78bb1 488{
0bc3b8ed 489 // Returns PHOS geometry
490
7a9d98f9 491 AliPHOSGeometry * rv = 0 ;
492 if (PHOS() )
493 rv = PHOS()->GetGeometry() ;
494 return rv ;
495}
4ae78bb1 496
cb34a1fa 497//____________________________________________________________________________
88cb7938 498TClonesArray * AliPHOSGetter::Primaries()
499{
500 // creates the Primaries container if needed
501 if ( !fPrimaries ) {
502 if (fgDebug)
503 Info("Primaries", "Creating a new TClonesArray for primaries") ;
504 fPrimaries = new TClonesArray("TParticle", 1000) ;
505 }
506 return fPrimaries ;
507}
508
509//____________________________________________________________________________
510void AliPHOSGetter::Print()
511{
512 // Print usefull information about the getter
513
514 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
515 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
516}
cb34a1fa 517
88cb7938 518//____________________________________________________________________________
519void AliPHOSGetter::ReadPrimaries()
520{
521 // Read Primaries from Kinematics.root
cb34a1fa 522
88cb7938 523 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
cb34a1fa 524
88cb7938 525 // gets kine tree from the root file (Kinematics.root)
7fba1747 526 if ( ! rl->TreeK() ) { // load treeK the first time
88cb7938 527 rl->LoadKinematics() ;
7fba1747 528 }
88cb7938 529
7fba1747 530 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 531 if (fgDebug)
532 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
cb34a1fa 533
cb34a1fa 534
88cb7938 535 // first time creates the container
536 if ( Primaries() )
537 fPrimaries->Clear() ;
cb34a1fa 538
88cb7938 539 Int_t index = 0 ;
540 for (index = 0 ; index < fNPrimaries; index++) {
541 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
cb34a1fa 542 }
cb34a1fa 543}
544
95635748 545//____________________________________________________________________________
d2713783 546Bool_t AliPHOSGetter::OpenESDFile()
95635748 547{
d2713783 548 //Open the ESD file
95635748 549 Bool_t rv = kTRUE ;
d2713783 550 if (!fESDFile) {
551 fESDFile = TFile::Open(fESDFileName) ;
552 if (!fESDFile )
553 return kFALSE ;
554 }
95635748 555 else if (fESDFile->IsOpen()) {
556 fESDFile->Close() ;
557 fESDFile = TFile::Open(fESDFileName) ;
558 }
559 if (!fESDFile->IsOpen())
560 rv = kFALSE ;
561 return rv ;
562}
563
45c1ce6f 564//____________________________________________________________________________
44ae287e 565void AliPHOSGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Double_t & energy, Double_t & time)
45c1ce6f 566{
567 // Fits the raw signal time distribution
568
569 const Int_t kNoiseThreshold = 0 ;
570 Double_t timezero1 = 0., timezero2 = 0., timemax = 0. ;
571 Double_t signal = 0., signalmax = 0. ;
44ae287e 572 time = 0. ;
573 energy = 0. ;
45c1ce6f 574
575 if (lowGainFlag) {
576 timezero1 = timezero2 = signalmax = timemax = 0. ;
577 signalF->FixParameter(0, PHOS()->GetRawFormatLowCharge()) ;
578 signalF->FixParameter(1, PHOS()->GetRawFormatLowGain()) ;
579 Int_t index ;
580 for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
581 gLowGain->GetPoint(index, time, signal) ;
582 if (signal > kNoiseThreshold && timezero1 == 0.)
583 timezero1 = time ;
584 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
585 timezero2 = time ;
586 if (signal > signalmax) {
587 signalmax = signal ;
588 timemax = time ;
589 }
590 }
591 signalmax /= PHOS()->RawResponseFunctionMax(PHOS()->GetRawFormatLowCharge(),
592 PHOS()->GetRawFormatLowGain()) ;
593 if ( timezero1 + PHOS()->GetRawFormatTimePeak() < PHOS()->GetRawFormatTimeMax() * 0.4 ) { // else its noise
594 signalF->SetParameter(2, signalmax) ;
595 signalF->SetParameter(3, timezero1) ;
596 gLowGain->Fit(signalF, "QRON", "", 0., timezero2); //, "QRON") ;
597 energy = signalF->GetParameter(2) ;
598 time = signalF->GetMaximumX() - PHOS()->GetRawFormatTimePeak() - PHOS()->GetRawFormatTimeTrigger() ;
599 }
600 } else {
601 timezero1 = timezero2 = signalmax = timemax = 0. ;
602 signalF->FixParameter(0, PHOS()->GetRawFormatHighCharge()) ;
603 signalF->FixParameter(1, PHOS()->GetRawFormatHighGain()) ;
604 Int_t index ;
605 for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
606 gHighGain->GetPoint(index, time, signal) ;
607 if (signal > kNoiseThreshold && timezero1 == 0.)
608 timezero1 = time ;
609 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
610 timezero2 = time ;
611 if (signal > signalmax) {
612 signalmax = signal ;
613 timemax = time ;
614 }
615 }
616 signalmax /= PHOS()->RawResponseFunctionMax(PHOS()->GetRawFormatHighCharge(),
617 PHOS()->GetRawFormatHighGain()) ;;
618 if ( timezero1 + PHOS()->GetRawFormatTimePeak() < PHOS()->GetRawFormatTimeMax() * 0.4 ) { // else its noise
619 signalF->SetParameter(2, signalmax) ;
620 signalF->SetParameter(3, timezero1) ;
621 gHighGain->Fit(signalF, "QRON", "", 0., timezero2) ;
622 energy = signalF->GetParameter(2) ;
623 time = signalF->GetMaximumX() - PHOS()->GetRawFormatTimePeak() - PHOS()->GetRawFormatTimeTrigger() ;
624 }
625 }
44ae287e 626 if (time == 0) energy = 0 ;
45c1ce6f 627}
628
44ae287e 629//____________________________________________________________________________
630Int_t AliPHOSGetter::CalibrateRaw(Double_t energy, Int_t *relId)
631{
632 // Convert energy into digitized amplitude for a cell relId
633 // It is a user responsilibity to open CDB and set
634 // AliPHOSCalibData object by the following operators:
635 //
636 // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
637 // AliPHOSCalibData* clb = (AliPHOSCalibData*)AliCDBStorage::Instance()
638 // ->Get(path_to_calibdata,run_number);
639 // AliPHOSGetter* gime = AliPHOSGetter::Instance("galice.root");
640 // gime->SetCalibData(clb);
641
642 if (CalibData() == 0)
f88e2313 643 Warning("CalibrateRaw","Calibration DB is not initiated!");
44ae287e 644
645 Int_t module = relId[0];
f88e2313 646 Int_t column = relId[3];
647 Int_t row = relId[2];
648
649 Float_t gainFactor = 0.0015; // width of one Emc ADC channel in GeV
650 Float_t pedestal = 0.005; // Emc pedestals
651
652 if(CalibData()) {
653 gainFactor = CalibData()->GetADCchannelEmc (module,column,row);
654 pedestal = CalibData()->GetADCpedestalEmc(module,column,row);
655 }
656
44ae287e 657 Int_t amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ;
658 return amp;
659}
a43c51c3 660//____________________________________________________________________________
3cf4f75f 661Int_t AliPHOSGetter::ReadRaw(AliRawReader *rawReader)
a43c51c3 662{
663 // reads the raw format data, converts it into digits format and store digits in Digits()
664 // container.
665
3cf4f75f 666 AliPHOSRawStream in(rawReader);
a43c51c3 667
45c1ce6f 668 Bool_t first = kTRUE ;
669
670 TF1 * signalF = new TF1("signal", AliPHOS::RawResponseFunction, 0, PHOS()->GetRawFormatTimeMax(), 4);
671 signalF->SetParNames("Charge", "Gain", "Amplitude", "TimeZero") ;
672
44ae287e 673 Int_t relId[4], id =0;
45c1ce6f 674 Bool_t lowGainFlag = kFALSE ;
675
a43c51c3 676 TClonesArray * digits = Digits() ;
677 digits->Clear() ;
678 Int_t idigit = 0 ;
44ae287e 679 Int_t amp = 0 ;
680 Double_t energy = 0. ;
681 Double_t time = 0. ;
ff808dc7 682
45c1ce6f 683 TGraph * gLowGain = new TGraph(PHOS()->GetRawFormatTimeBins()) ;
684 TGraph * gHighGain= new TGraph(PHOS()->GetRawFormatTimeBins()) ;
e4d04cf1 685
45c1ce6f 686 while ( in.Next() ) { // PHOS entries loop
687 if ( (in.IsNewRow() || in.IsNewColumn() || in.IsNewModule()) ) {
44ae287e 688 relId[0] = in.GetModule() ;
689 if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
690 relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
691 lowGainFlag = kTRUE ;
692 } else
693 lowGainFlag = kFALSE ;
694 relId[1] = 0 ;
695 relId[2] = in.GetRow() ;
696 relId[3] = in.GetColumn() ;
697 PHOSGeometry()->RelToAbsNumbering(relId, id) ;
45c1ce6f 698 if (!first) {
44ae287e 699 FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, energy, time) ;
f88e2313 700 amp = CalibrateRaw(energy,relId);
45c1ce6f 701 if (amp > 0) {
702 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
703 idigit++ ;
704 }
705 Int_t index ;
706 for (index = 0; index < PHOS()->GetRawFormatTimeBins(); index++) {
707 gLowGain->SetPoint(index, index * PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(), 0) ;
708 gHighGain->SetPoint(index, index * PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(), 0) ;
709 }
710 }
711 first = kFALSE ;
66f895c8 712 }
45c1ce6f 713 if (lowGainFlag)
714 gLowGain->SetPoint(in.GetTime(),
715 in.GetTime()* PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(),
716 in.GetSignal()) ;
717 else
718 gHighGain->SetPoint(in.GetTime(),
719 in.GetTime() * PHOS()->GetRawFormatTimeMax() / PHOS()->GetRawFormatTimeBins(),
720 in.GetSignal() ) ;
721
a43c51c3 722 } // PHOS entries loop
45c1ce6f 723
44ae287e 724 FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, energy, time) ;
725 amp = CalibrateRaw(energy,relId);
726 if (amp > 0 ) {
727 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
728 idigit++ ;
729 }
ff808dc7 730 digits->Sort() ;
45c1ce6f 731
732 delete signalF ;
29167ac3 733 delete gLowGain;
734 delete gHighGain ;
a43c51c3 735
f88e2313 736// AliInfo(Form("Event %d, digits: %d\n", EventNumber(),digits->GetEntries())); //bvp
e4d04cf1 737 return digits->GetEntriesFast() ;
a43c51c3 738}
45c1ce6f 739
740// TClonesArray * digits = Digits() ;
741// digits->Clear() ;
742// Int_t idigit = 0 ;
743
744// while ( in.Next() ) { // PHOS entries loop
745
746// Int_t amp = in.GetSignal() ;
747// Double_t time = in.GetTime() ;
748// Int_t relId[4], id ;
749
750// relId[0] = in.GetModule() ;
751// if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
752// relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
753// }
754// relId[1] = 0 ;
755// relId[2] = in.GetRow() ;
756// relId[3] = in.GetColumn() ;
757// PHOSGeometry()->RelToAbsNumbering(relId, id) ;
758
759// if (amp > 0 && id >=0 ) {
760// new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
761// idigit++ ;
762// }
763
764// } // PHOS entries loop
765
766// digits->Sort() ;
767
768// return digits->GetEntriesFast() ;
769// }
b0bba0af 770//____________________________________________________________________________
88cb7938 771Int_t AliPHOSGetter::ReadTreeD()
772{
773 // Read the Digits
b0bba0af 774
41c29fde 775 PhosLoader()->CleanDigits() ;
ff808dc7 776 PhosLoader()->LoadDigits("UPDATE") ;
777 PhosLoader()->LoadDigitizer("UPDATE") ;
88cb7938 778 return Digits()->GetEntries() ;
779}
7a9d98f9 780
b0bba0af 781//____________________________________________________________________________
88cb7938 782Int_t AliPHOSGetter::ReadTreeH()
783{
784 // Read the Hits
41c29fde 785 PhosLoader()->CleanHits() ;
88cb7938 786 // gets TreeH from the root file (PHOS.Hit.root)
41c29fde 787 //if ( !IsLoaded("H") ) {
88cb7938 788 PhosLoader()->LoadHits("UPDATE") ;
41c29fde 789 // SetLoaded("H") ;
790 //}
88cb7938 791 return Hits()->GetEntries() ;
792}
4ae78bb1 793
88cb7938 794//____________________________________________________________________________
795Int_t AliPHOSGetter::ReadTreeR()
796{
797 // Read the RecPoints
b0bba0af 798
41c29fde 799 PhosLoader()->CleanRecPoints() ;
88cb7938 800 // gets TreeR from the root file (PHOS.RecPoints.root)
41c29fde 801 //if ( !IsLoaded("R") ) {
88cb7938 802 PhosLoader()->LoadRecPoints("UPDATE") ;
803 PhosLoader()->LoadClusterizer("UPDATE") ;
41c29fde 804 // SetLoaded("R") ;
805 //}
f1611b7c 806
88cb7938 807 return EmcRecPoints()->GetEntries() ;
b0bba0af 808}
7a9d98f9 809
b0bba0af 810//____________________________________________________________________________
88cb7938 811Int_t AliPHOSGetter::ReadTreeT()
812{
813 // Read the TrackSegments
7a9d98f9 814
41c29fde 815 PhosLoader()->CleanTracks() ;
88cb7938 816 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 817 //if ( !IsLoaded("T") ) {
88cb7938 818 PhosLoader()->LoadTracks("UPDATE") ;
819 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
41c29fde 820 // SetLoaded("T") ;
821 //}
fbf811ec 822
88cb7938 823 return TrackSegments()->GetEntries() ;
824}
b0bba0af 825//____________________________________________________________________________
88cb7938 826Int_t AliPHOSGetter::ReadTreeP()
827{
41c29fde 828 // Read the RecParticles
88cb7938 829
41c29fde 830 PhosLoader()->CleanRecParticles() ;
831
88cb7938 832 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 833 // if ( !IsLoaded("P") ) {
88cb7938 834 PhosLoader()->LoadRecParticles("UPDATE") ;
835 PhosLoader()->LoadPID("UPDATE") ;
41c29fde 836 // SetLoaded("P") ;
837 //}
7a9d98f9 838
88cb7938 839 return RecParticles()->GetEntries() ;
840}
841//____________________________________________________________________________
842Int_t AliPHOSGetter::ReadTreeS()
843{
844 // Read the SDigits
845
41c29fde 846 PhosLoader()->CleanSDigits() ;
88cb7938 847 // gets TreeS from the root file (PHOS.SDigits.root)
41c29fde 848 //if ( !IsLoaded("S") ) {
7b4c1168 849 PhosLoader()->LoadSDigits("READ") ;
850 PhosLoader()->LoadSDigitizer("READ") ;
41c29fde 851 // SetLoaded("S") ;
852 //}
b0bba0af 853
88cb7938 854 return SDigits()->GetEntries() ;
855}
f1611b7c 856
677c8a30 857//____________________________________________________________________________
858Int_t AliPHOSGetter::ReadTreeE(Int_t event)
859{
860 // Read the ESD
861
862 // gets esdTree from the root file (AliESDs.root)
863 if (!fESDFile)
864 if ( !OpenESDFile() )
865 return -1 ;
866
867 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
868 fESD = new AliESD;
869 if (!fESDTree) {
870
871 Error("ReadTreeE", "no ESD tree found");
872 return -1;
873 }
874 fESDTree->SetBranchAddress("ESD", &fESD);
875 fESDTree->GetEvent(event);
876
877 return event ;
878}
879
88cb7938 880//____________________________________________________________________________
881TClonesArray * AliPHOSGetter::SDigits()
882{
883 // asks the Loader to return the Digits container
b0bba0af 884
88cb7938 885 TClonesArray * rv = 0 ;
886
887 rv = PhosLoader()->SDigits() ;
888 if (!rv) {
889 PhosLoader()->MakeSDigitsArray() ;
890 rv = PhosLoader()->SDigits() ;
891 }
892 return rv ;
b0bba0af 893}
894
895//____________________________________________________________________________
e957fea8 896AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 897{
e957fea8 898 // Returns pointer to the SDigitizer task
88cb7938 899 AliPHOSSDigitizer * rv ;
900 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
901 if (!rv) {
902 Event(0, "S") ;
903 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
b0bba0af 904 }
88cb7938 905 return rv ;
b0bba0af 906}
7a9d98f9 907
b0bba0af 908//____________________________________________________________________________
fc7e2f43 909TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
88cb7938 910{
911 // Return first (index=1) or second (index=2) secondary particle of primary particle p
912
913 if(index <= 0)
914 return 0 ;
915 if(index > 2)
916 return 0 ;
b0bba0af 917
88cb7938 918 if(p) {
919 Int_t daughterIndex = p->GetDaughter(index-1) ;
920 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 921 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
88cb7938 922 }
923 else
924 return 0 ;
925}
4ae78bb1 926
88cb7938 927//____________________________________________________________________________
fc7e2f43 928void AliPHOSGetter::Track(Int_t itrack)
88cb7938 929{
930 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
931
932 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
b0bba0af 933
88cb7938 934 if( !TreeH() ) // load treeH the first time
935 rl->LoadHits() ;
b0bba0af 936
88cb7938 937 // first time create the container
938 TClonesArray * hits = Hits() ;
939 if ( hits )
940 hits->Clear() ;
b0bba0af 941
88cb7938 942 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
943 phosbranch->SetAddress(&hits) ;
944 phosbranch->GetEntry(itrack) ;
b0bba0af 945}
946
b0bba0af 947//____________________________________________________________________________
88cb7938 948TTree * AliPHOSGetter::TreeD() const
949{
e957fea8 950 // Returns pointer to the Digits Tree
88cb7938 951 TTree * rv = 0 ;
952 rv = PhosLoader()->TreeD() ;
953 if ( !rv ) {
954 PhosLoader()->MakeTree("D");
955 rv = PhosLoader()->TreeD() ;
b0bba0af 956 }
b0bba0af 957
88cb7938 958 return rv ;
b0bba0af 959}
548f0134 960
b0bba0af 961//____________________________________________________________________________
88cb7938 962TTree * AliPHOSGetter::TreeH() const
963{
e957fea8 964 // Returns pointer to the Hits Tree
88cb7938 965 TTree * rv = 0 ;
966 rv = PhosLoader()->TreeH() ;
967 if ( !rv ) {
968 PhosLoader()->MakeTree("H");
969 rv = PhosLoader()->TreeH() ;
970 }
971
972 return rv ;
b0bba0af 973}
7a9d98f9 974
b0bba0af 975//____________________________________________________________________________
88cb7938 976TTree * AliPHOSGetter::TreeR() const
0bc3b8ed 977{
e957fea8 978 // Returns pointer to the RecPoints Tree
88cb7938 979 TTree * rv = 0 ;
980 rv = PhosLoader()->TreeR() ;
981 if ( !rv ) {
982 PhosLoader()->MakeTree("R");
983 rv = PhosLoader()->TreeR() ;
984 }
b0bba0af 985
88cb7938 986 return rv ;
b0bba0af 987}
988
b0bba0af 989//____________________________________________________________________________
88cb7938 990TTree * AliPHOSGetter::TreeT() const
0bc3b8ed 991{
e957fea8 992 // Returns pointer to the TrackSegments Tree
88cb7938 993 TTree * rv = 0 ;
994 rv = PhosLoader()->TreeT() ;
995 if ( !rv ) {
996 PhosLoader()->MakeTree("T");
997 rv = PhosLoader()->TreeT() ;
998 }
b0bba0af 999
88cb7938 1000 return rv ;
b0bba0af 1001}
b0bba0af 1002//____________________________________________________________________________
88cb7938 1003TTree * AliPHOSGetter::TreeP() const
0bc3b8ed 1004{
e957fea8 1005 // Returns pointer to the RecParticles Tree
88cb7938 1006 TTree * rv = 0 ;
1007 rv = PhosLoader()->TreeP() ;
1008 if ( !rv ) {
1009 PhosLoader()->MakeTree("P");
1010 rv = PhosLoader()->TreeP() ;
1011 }
4ae78bb1 1012
88cb7938 1013 return rv ;
b0bba0af 1014}
1015
1016//____________________________________________________________________________
88cb7938 1017TTree * AliPHOSGetter::TreeS() const
e957fea8 1018{
1019 // Returns pointer to the SDigits Tree
88cb7938 1020 TTree * rv = 0 ;
1021 rv = PhosLoader()->TreeS() ;
1022 if ( !rv ) {
1023 PhosLoader()->MakeTree("S");
1024 rv = PhosLoader()->TreeS() ;
b0bba0af 1025 }
b0bba0af 1026
88cb7938 1027 return rv ;
b0bba0af 1028}
7a9d98f9 1029
b0bba0af 1030//____________________________________________________________________________
88cb7938 1031Bool_t AliPHOSGetter::VersionExists(TString & opt) const
1032{
1033 // checks if the version with the present name already exists in the same directory
7a9d98f9 1034
88cb7938 1035 Bool_t rv = kFALSE ;
1036
1037 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
1038 TString version( rl->GetEventFolder()->GetName() ) ;
7a9d98f9 1039
88cb7938 1040 opt.ToLower() ;
b0bba0af 1041
88cb7938 1042 if ( opt == "sdigits") {
1043 // add the version name to the root file name
1044 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 1045 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1046 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1047 if ( !(gSystem->AccessPathName(fileName)) ) {
1048 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1049 rv = kTRUE ;
4ae78bb1 1050 }
88cb7938 1051 PhosLoader()->SetSDigitsFileName(fileName) ;
b0bba0af 1052 }
7a9d98f9 1053
88cb7938 1054 if ( opt == "digits") {
1055 // add the version name to the root file name
1056 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 1057 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1058 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1059 if ( !(gSystem->AccessPathName(fileName)) ) {
1060 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1061 rv = kTRUE ;
7a9d98f9 1062 }
b0bba0af 1063 }
7a9d98f9 1064
88cb7938 1065 return rv ;
7a9d98f9 1066
b0bba0af 1067}
88cb7938 1068
7bb289a7 1069//____________________________________________________________________________
88cb7938 1070UShort_t AliPHOSGetter::EventPattern(void) const
0bc3b8ed 1071{
1072 // Return the pattern (trigger bit register) of the beam-test event
7bb289a7 1073 if(fBTE)
1074 return fBTE->GetPattern() ;
1075 else
1076 return 0 ;
1077}
1078//____________________________________________________________________________
88cb7938 1079Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 1080{
1081 // Return the beam energy of the beam-test event
7bb289a7 1082 if(fBTE)
1083 return fBTE->GetBeamEnergy() ;
1084 else
1085 return 0 ;
1086}
7ca0684e 1087//____________________________________________________________________________
1088
1089AliPHOSCalibData* AliPHOSGetter::CalibData()
1090{
1091
9e1ceb13 1092 if( !(AliCDBManager::Instance()->IsDefaultStorageSet()) ) {
7ca0684e 1093 fCalibData=0x0;
1094 Warning("CalibData","Calibration DB is not initiated!");
1095 return fCalibData;
1096 }
1097
1098 return fCalibData;
1099
1100
1101}