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