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