]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALSDigitizer.cxx
deleting unused class AliEMCALCalibHistoProducer and adding new class AliEMCALCalibTe...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALSDigitizer.cxx
CommitLineData
ffa6d63b 1/*************************************************************************
61e0abb5 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
16/* $Id$ */
17
18//_________________________________________________________________________
19// This is a TTask that makes SDigits out of Hits
20// A Summable Digits is the sum of all hits originating
ffa6d63b 21// from one in one tower of the EMCAL
61e0abb5 22// A threshold for assignment of the primary to SDigit is applied
ab6a174f 23//
24// JLK 26-Jun-2008 Added explanation:
25// SDigits need to hold the energy sum of the hits, but AliEMCALDigit
26// can (should) only store amplitude. Therefore, the SDigit energy is
27// "digitized" before being stored and must be "calibrated" back to an
28// energy before SDigits are summed to form true Digits
29//
61e0abb5 30// SDigits are written to TreeS, branch "EMCAL"
31// AliEMCALSDigitizer with all current parameters is written
32// to TreeS branch "AliEMCALSDigitizer".
33// Both branches have the same title. If necessary one can produce
34// another set of SDigits with different parameters. Two versions
35// can be distunguished using titles of the branches.
36// User case:
37// root [0] AliEMCALSDigitizer * s = new AliEMCALSDigitizer("galice.root")
38// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
39// root [1] s->ExecuteTask()
40// // Makes SDigitis for all events stored in galice.root
41// root [2] s->SetPedestalParameter(0.001)
42// // One can change parameters of digitization
43// root [3] s->SetSDigitsBranch("Redestal 0.001")
44// // and write them into the new branch
45// root [4] s->ExeciteTask("deb all tim")
46// // available parameters:
47// deb - print # of produced SDigitis
48// deb all - print # and list of produced SDigits
49// tim - print benchmarking information
50//
ffa6d63b 51//*-- Author : Sahal Yacoob (LBL)
52// based on : AliPHOSSDigitzer
61e0abb5 53//////////////////////////////////////////////////////////////////////////////
54
61e0abb5 55// --- ROOT system ---
bda7cf56 56#include <TBenchmark.h>
bda7cf56 57#include <TBrowser.h>
d804d556 58//#include <Riostream.h>
bda7cf56 59#include <TMath.h>
a1e17193 60#include <TROOT.h>
05a92d59 61
61e0abb5 62// --- Standard library ---
d64c959b 63#include "stdlib.h"
61e0abb5 64
65// --- AliRoot header files ---
13e1db42 66#include "AliLog.h"
5dee926e 67#include "AliRunLoader.h"
68#include "AliStack.h"
61e0abb5 69#include "AliEMCALDigit.h"
5dee926e 70#include "AliEMCALLoader.h"
05a92d59 71#include "AliEMCALHit.h"
72#include "AliEMCALSDigitizer.h"
88cb7938 73#include "AliEMCALGeometry.h"
33a52e55 74#include "AliEMCALSimParam.h"
61e0abb5 75
76ClassImp(AliEMCALSDigitizer)
61e0abb5 77
78//____________________________________________________________________________
18a21c7c 79AliEMCALSDigitizer::AliEMCALSDigitizer()
80 : TTask("",""),
81 fA(0.),fB(0.),fECPrimThreshold(0.),
82 fDefaultInit(kTRUE),
83 fEventFolderName(0),
84 fInit(0),
85 fSDigitsInRun(0),
86 fFirstEvent(0),
87 fLastEvent(0),
e44d51bd 88 fSampling(0.),
89 fHits(0)
61e0abb5 90{
91 // ctor
0a4cb131 92 InitParameters();
61e0abb5 93}
94
95//____________________________________________________________________________
e191bb57 96AliEMCALSDigitizer::AliEMCALSDigitizer(const char * alirunFileName,
18a21c7c 97 const char * eventFolderName)
98 : TTask("EMCAL"+AliConfig::Instance()->GetSDigitizerTaskName(), alirunFileName),
99 fA(0.),fB(0.),fECPrimThreshold(0.),
100 fDefaultInit(kFALSE),
101 fEventFolderName(eventFolderName),
102 fInit(0),
103 fSDigitsInRun(0),
104 fFirstEvent(0),
105 fLastEvent(0),
e44d51bd 106 fSampling(0.),
107 fHits(0)
61e0abb5 108{
109 // ctor
814ad4bf 110 Init();
62741b41 111 InitParameters() ;
7ea6391b 112
61e0abb5 113}
114
88cb7938 115
61e0abb5 116//____________________________________________________________________________
18a21c7c 117AliEMCALSDigitizer::AliEMCALSDigitizer(const AliEMCALSDigitizer & sd)
118 : TTask(sd.GetName(),sd.GetTitle()),
119 fA(sd.fA),
120 fB(sd.fB),
121 fECPrimThreshold(sd.fECPrimThreshold),
122 fDefaultInit(sd.fDefaultInit),
123 fEventFolderName(sd.fEventFolderName),
124 fInit(sd.fInit),
125 fSDigitsInRun(sd.fSDigitsInRun),
126 fFirstEvent(sd.fFirstEvent),
127 fLastEvent(sd.fLastEvent),
e44d51bd 128 fSampling(sd.fSampling),
129 fHits(0)
18a21c7c 130{
88cb7938 131 //cpy ctor
61e0abb5 132}
36657114 133
88cb7938 134
797e311f 135//____________________________________________________________________________
136AliEMCALSDigitizer::~AliEMCALSDigitizer() {
14ce0a6e 137 //dtor
5dee926e 138 AliLoader *emcalLoader=0;
33c3c91a 139 if ((emcalLoader = AliRunLoader::Instance()->GetDetectorLoader("EMCAL")))
5dee926e 140 emcalLoader->CleanSDigitizer();
e44d51bd 141
142 if(fHits){
143 fHits->Clear();
144 delete fHits;
145 }
797e311f 146}
147
61e0abb5 148//____________________________________________________________________________
149void AliEMCALSDigitizer::Init(){
814ad4bf 150 // Initialization: open root-file, allocate arrays for hits and sdigits,
36657114 151 // attach task SDigitizer to the list of EMCAL tasks
814ad4bf 152 //
153 // Initialization can not be done in the default constructor
154 //============================================================= YS
155 // The initialisation is now done by the getter
61e0abb5 156
dc7da436 157 fInit = kTRUE;
afa0c708 158
33c3c91a 159 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
5dee926e 160
161 if ( emcalLoader == 0 ) {
162 Fatal("Init", "Could not obtain the AliEMCALLoader");
814ad4bf 163 return ;
164 }
165
5dee926e 166 emcalLoader->PostSDigitizer(this);
167 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
88cb7938 168
839828a6 169}
170
171//____________________________________________________________________________
afa0c708 172void AliEMCALSDigitizer::InitParameters()
173{
14ce0a6e 174 //initialize parameters for sdigitization
175
5dee926e 176 const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
62741b41 177 if (geom->GetSampling() == 0.) {
5082063d 178 Fatal("InitParameters", "Sampling factor not set !") ;
62741b41 179 }
ab6a174f 180
6569f329 181 // Get the parameters from the OCDB via the loader
182 AliRunLoader *rl = AliRunLoader::Instance();
183 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
184 AliEMCALSimParam * simParam = 0x0;
185 if(emcalLoader) simParam = emcalLoader->SimulationParameters();
186
187 if(!simParam){
188 simParam = AliEMCALSimParam::GetInstance();
189 AliWarning("Simulation Parameters not available in OCDB?");
190 }
191
ab6a174f 192 //
193 //JLK 26-Jun-2008 THIS SHOULD HAVE BEEN EXPLAINED AGES AGO:
194 //
195 //In order to be able to store SDigit Energy info into
196 //AliEMCALDigit, we need to convert it temporarily to an ADC amplitude
197 //and later when summing SDigits to form digits, convert it back to
198 //energy. These fA and fB parameters accomplish this through the
199 //Digitize() and Calibrate() methods
200 //
1963b290 201 // Initializes parameters
6569f329 202 fA = simParam->GetA(); //0;
203 fB = simParam->GetB(); //1.e+6; // Changed 24 Apr 2007. Dynamic range now 2 TeV
1963b290 204 fSampling = geom->GetSampling();
205
ff98b189 206 // threshold for deposit energy of hit
6569f329 207 fECPrimThreshold = simParam->GetECPrimaryThreshold();//0.05;// GeV // 22-may-07 was 0// 24-nov-04 - was 1.e-6;
ff98b189 208
b42d4197 209 AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
210 AliDebug(2,Form(" fInit %i\n", int(fInit)));
211 AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
212 AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
213 AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
214 AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
215 AliDebug(2,Form(" B = %f\n", fB));
216 AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
217 AliDebug(2,Form(" Sampling = %f\n", fSampling));
218 AliDebug(2,Form("---------------------------------------------------\n"));
219
839828a6 220}
221
61e0abb5 222//____________________________________________________________________________
afa0c708 223void AliEMCALSDigitizer::Exec(Option_t *option)
224{
e44d51bd 225 // Collects all hit of the same tower into digits
226 TString o(option); o.ToUpper();
227 if (strstr(option, "print") ) {
228
229 AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
230 AliDebug(2,Form(" fInit %i\n", int(fInit)));
231 AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
232 AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
233 AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
234 AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
235 AliDebug(2,Form(" B = %f\n", fB));
236 AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
237 AliDebug(2,Form(" Sampling = %f\n", fSampling));
238 AliDebug(2,Form("---------------------------------------------------\n"));
239
240 return ;
afa0c708 241 }
e44d51bd 242
243
244 if(strstr(option,"tim"))
245 gBenchmark->Start("EMCALSDigitizer");
246
247 AliRunLoader *rl = AliRunLoader::Instance();
248 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
249
250 //switch off reloading of this task while getting event
251 if (!fInit) { // to prevent overwrite existing file
252 AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
253 return ;
7e1d9a9b 254 }
e44d51bd 255
256 if (fLastEvent == -1)
257 fLastEvent = rl->GetNumberOfEvents() - 1 ;
258 else {
259 fLastEvent = TMath::Min(fLastEvent, rl->GetNumberOfEvents()-1);
260 }
261 Int_t nEvents = fLastEvent - fFirstEvent + 1;
262
e44d51bd 263 Float_t energy=0.; // de * fSampling - 23-nov-04
264 rl->LoadKinematics();
265 rl->LoadHits("EMCAL");
53e430a3 266
267 Int_t ievent;
e44d51bd 268 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
269 rl->GetEvent(ievent);
270 TTree * treeS = emcalLoader->TreeS();
271 if ( !treeS ) {
272 emcalLoader->MakeSDigitsContainer();
273 treeS = emcalLoader->TreeS();
274 }
7e1d9a9b 275
e44d51bd 276 TClonesArray * sdigits = emcalLoader->SDigits() ;
e0dc3f7d 277 sdigits->Clear("C");
e44d51bd 278
279 Int_t nSdigits = 0 ;
280 Int_t iHit, iTrack, iSDigit;
281
282 AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
283
284 TTree *treeH = emcalLoader->TreeH();
285 if (treeH) {
286 Int_t nTrack = treeH->GetEntries(); // TreeH has array of hits for every primary
287 TBranch * branchH = treeH->GetBranch("EMCAL");
288 //if(fHits)fHits->Clear();
289 branchH->SetAddress(&fHits);
290 for (iTrack = 0; iTrack < nTrack; iTrack++) {
7e1d9a9b 291 branchH->GetEntry(iTrack);
292
293 if(fHits){
294
295 Int_t nHit = fHits->GetEntriesFast();
296 for(iHit = 0; iHit< nHit;iHit++){
297
298 AliEMCALHit * hit = dynamic_cast<AliEMCALHit*>(fHits->At(iHit)) ;
299 AliEMCALDigit * curSDigit = 0 ;
300 AliEMCALDigit * sdigit = 0 ;
301 Bool_t newsdigit = kTRUE;
302
303 // hit->GetId() - Absolute Id number EMCAL segment
304 if(hit){
305 if(geom->CheckAbsCellId(hit->GetId())) { // was IsInECA(hit->GetId())
306 energy = hit->GetEnergy() * fSampling; // 23-nov-04
307 if(energy > fECPrimThreshold )
308 // Assign primary number only if deposited energy is significant
309 curSDigit = new AliEMCALDigit(hit->GetPrimary(),
310 hit->GetIparent(), hit->GetId(),
311 Digitize(energy), hit->GetTime(),kFALSE,
312 -1, 0,0,energy ) ;
313 else
314 curSDigit = new AliEMCALDigit(-1,
315 -1,
316 hit->GetId(),
317 Digitize(energy), hit->GetTime(),kFALSE,
318 -1, 0,0,energy ) ;
319 } else {
320 Warning("Exec"," abs id %i is bad \n", hit->GetId());
321 newsdigit = kFALSE;
322 curSDigit = 0;
323 }
324
325 if(curSDigit != 0){
326 for(Int_t check= 0; check < nSdigits ; check++) {
327 sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(check)) ;
328
329 if( sdigit->GetId() == curSDigit->GetId()) { // Are we in the same ECAL tower ?
330 *sdigit = *sdigit + *curSDigit;
331 newsdigit = kFALSE;
332 }
333 }
334 }
335 if (newsdigit) {
336 new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
337 nSdigits++ ;
338 }
339 delete curSDigit ;
340
341 }// hit exists
342 else AliFatal("Hit is NULL!");
343
344 } // loop over all hits (hit = deposited energy/entering particle)
345
346 }//fHits is not NULL
347 else AliFatal("fHit is NULL!");
348
e44d51bd 349 sdigits->Sort() ;
350
351 nSdigits = sdigits->GetEntriesFast() ;
352 fSDigitsInRun += nSdigits ;
353
354 for (iSDigit = 0 ; iSDigit < sdigits->GetEntriesFast() ; iSDigit++) {
355 AliEMCALDigit * sdigit = dynamic_cast<AliEMCALDigit *>(sdigits->At(iSDigit)) ;
7e1d9a9b 356 if(sdigit)sdigit->SetIndexInList(iSDigit) ;
357 else AliFatal("sdigit is NULL!");
e44d51bd 358 }
359 if(fHits)fHits->Clear();
360 }//track loop
361 }// tree exists
362
363 // Now write SDigits
364
365 Int_t bufferSize = 32000 ;
366 TBranch * sdigitsBranch = treeS->GetBranch("EMCAL");
367 if (sdigitsBranch)
368 sdigitsBranch->SetAddress(&sdigits);
369 else
370 treeS->Branch("EMCAL",&sdigits,bufferSize);
371
372 treeS->Fill();
373
374 emcalLoader->WriteSDigits("OVERWRITE");
375
376 //NEXT - SDigitizer
377 emcalLoader->WriteSDigitizer("OVERWRITE"); // why in event cycle ?
378
379 if(strstr(option,"deb"))
380 PrintSDigits(option) ;
381 }
382
383 Unload();
384
385 emcalLoader->GetSDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
386
387 if(strstr(option,"tim")){
388 gBenchmark->Stop("EMCALSDigitizer");
389 printf("\n Exec: took %f seconds for SDigitizing %f seconds per event\n",
7e1d9a9b 390 gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer")/nEvents ) ;
e44d51bd 391 }
61e0abb5 392}
05a92d59 393
bda7cf56 394//__________________________________________________________________
829ba234 395Float_t AliEMCALSDigitizer::Digitize(Float_t energy)const {
bda7cf56 396 // Digitize the energy
ab6a174f 397 //
398 //JLK 26-Jun-2008 EXPLANATION LONG OVERDUE:
399 //
400 //We have to digitize the SDigit energy so that it can be stored in
401 //AliEMCALDigit, which has only an ADC amplitude member and
402 //(rightly) no energy member. This method converts the energy to an
403 //integer which can be re-converted back to an energy with the
404 //Calibrate(energy) method when it is time to create Digits from SDigits
405 //
406 Double_t aSignal = fA + energy*fB;
407 if (TMath::Abs(aSignal)>2147483647.0) {
408 //PH 2147483647 is the max. integer
409 //PH This apparently is a problem which needs investigation
410 AliWarning(Form("Too big or too small energy %f",aSignal));
411 aSignal = TMath::Sign((Double_t)2147483647,aSignal);
bda7cf56 412 }
829ba234 413
414 return (Float_t ) aSignal;
ab6a174f 415}
bda7cf56 416
417//__________________________________________________________________
829ba234 418Float_t AliEMCALSDigitizer::Calibrate(Float_t amp)const {
ab6a174f 419 //
420 // Convert the amplitude back to energy in GeV
421 //
422 //JLK 26-Jun-2008 EXPLANATION LONG OVERDUE:
423 //
424 //We have to digitize the SDigit energy with the method Digitize()
425 //so that it can be stored in AliEMCALDigit, which has only an ADC
426 //amplitude member and (rightly) no energy member. This method is
427 //just the reverse of Digitize(): it converts the stored amplitude
428 //back to an energy value in GeV so that the SDigit energies can be
429 //summed before adding noise and creating digits out of them
430 //
431 return (Float_t)(amp - fA)/fB;
432
433}
434
106fc2fa 435
ab6a174f 436//__________________________________________________________________
1963b290 437void AliEMCALSDigitizer::Print1(Option_t * option)
438{
439 Print();
440 PrintSDigits(option);
441}
442
61e0abb5 443//__________________________________________________________________
5dee926e 444void AliEMCALSDigitizer::Print(Option_t *option) const
05a92d59 445{
446 // Prints parameters of SDigitizer
e52475ed 447 printf("Print: \n------------------- %s ------------- option %s\n", GetName() , option) ;
1963b290 448 printf(" fInit %i\n", int(fInit));
449 printf(" fFirstEvent %i\n", fFirstEvent);
450 printf(" fLastEvent %i\n", fLastEvent);
88cb7938 451 printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
1963b290 452 printf(" with digitization parameters A = %f\n", fA) ;
453 printf(" B = %f\n", fB) ;
454 printf(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold) ;
455 printf(" Sampling = %f\n", fSampling);
88cb7938 456 printf("---------------------------------------------------\n") ;
61e0abb5 457}
05a92d59 458
61e0abb5 459//__________________________________________________________________
05a92d59 460Bool_t AliEMCALSDigitizer::operator==( AliEMCALSDigitizer const &sd )const
461{
462 // Equal operator.
463 // SDititizers are equal if their pedestal, slope and threshold are equal
89e103bd 464 if( (fA==sd.fA)&&(fB==sd.fB)&&
fdebddeb 465 (fECPrimThreshold==sd.fECPrimThreshold))
61e0abb5 466 return kTRUE ;
467 else
468 return kFALSE ;
469}
173558f2 470
61e0abb5 471//__________________________________________________________________
d64c959b 472void AliEMCALSDigitizer::PrintSDigits(Option_t * option)
473{
61e0abb5 474 //Prints list of digits produced at the current pass of AliEMCALDigitizer
61e0abb5 475
7e1d9a9b 476 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
477 if(rl){
478 const TClonesArray * sdigits = rl->SDigits() ;
9859bfc0 479
7e1d9a9b 480 printf("\n") ;
481 printf("event %i", rl->GetRunLoader()->GetEventNumber());
482 printf(" Number of entries in SDigits list %i", sdigits->GetEntriesFast());
483 if(strstr(option,"all")||strstr(option,"EMC")){
61e0abb5 484
7e1d9a9b 485 //loop over digits
486 AliEMCALDigit * digit;
487 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
488 Int_t index = 0;
489 Float_t isum = 0.;
490 const Int_t bufferSize = 8192;
491 char * tempo = new char[bufferSize];
492 for (index = 0 ; index < sdigits->GetEntries() ; index++) {
493 digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
494 if(digit){
495 snprintf(tempo, bufferSize,"\n%6d %8f %6.5e %4d %2d :",
496 digit->GetId(), digit->GetAmplitude(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
497 printf("%s",tempo);
498 isum += digit->GetAmplitude();
499
500 Int_t iprimary;
501 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
502 snprintf(tempo,bufferSize, "%d ",digit->GetPrimary(iprimary+1) ) ;
503 printf("%s",tempo);
504 }
505 } //sdigit exists
506 else AliFatal("SDigit is NULL!");
507 }//loop
508 delete [] tempo ;
509 printf("\n** Sum %2.3f : %10.3f GeV/c **\n ", isum, Calibrate(isum));
510 } else printf("\n");
511 }
512 else AliFatal("EMCALLoader is NULL!");
61e0abb5 513}
05a92d59 514
05a92d59 515//____________________________________________________________________________
88cb7938 516void AliEMCALSDigitizer::Unload() const
05a92d59 517{
d64c959b 518 // Unload Hits and SDigits from the folder
33c3c91a 519 AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
7e1d9a9b 520 if(rl){
521 rl->UnloadHits() ;
522 rl->UnloadSDigits() ;
523 }
524 else AliFatal("EMCALLoader is NULL!");
05a92d59 525}
1963b290 526
fe93d365 527//____________________________________________________________________________
1963b290 528void AliEMCALSDigitizer::Browse(TBrowser* b)
529{
1963b290 530 TTask::Browse(b);
531}