New dependancy introduced into libAliHLTUtil.so
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
CommitLineData
61e0abb5 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
16/* $Id$ */
17
18//_________________________________________________________________________
ffa6d63b 19//
61e0abb5 20//////////////////////////////////////////////////////////////////////////////
ab6a174f 21// Class performs digitization of Summable digits from simulated data
ffa6d63b 22//
61e0abb5 23// In addition it performs mixing of summable digits from different events.
24//
25// For each event two branches are created in TreeD:
26// "EMCAL" - list of digits
27// "AliEMCALDigitizer" - AliEMCALDigitizer with all parameters used in digitization
28//
29// Note, that one cset title for new digits branch, and repeat digitization with
30// another set of parameters.
31//
32// Examples of use:
33// root[0] AliEMCALDigitizer * d = new AliEMCALDigitizer() ;
34// root[1] d->ExecuteTask()
35// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
36// //Digitizes SDigitis in all events found in file galice.root
37//
38// root[2] AliEMCALDigitizer * d1 = new AliEMCALDigitizer("galice1.root") ;
39// // Will read sdigits from galice1.root
40// root[3] d1->MixWith("galice2.root")
41// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
42// // Reads another portion of sdigits from galice2.root
43// root[3] d1->MixWith("galice3.root")
44// // Reads another portion of sdigits from galice3.root
45// root[4] d->ExecuteTask("deb timing")
46// // Reads SDigits from files galice1.root, galice2.root ....
47// // mixes them and stores produced Digits in file galice1.root
48// // deb - prints number of produced digits
49// // deb all - prints list of produced digits
50// // timing - prints time used for digitization
ffa6d63b 51////////////////////////////////////////////////////////////////////////////////////
61e0abb5 52//
ffa6d63b 53//*-- Author: Sahal Yacoob (LBL)
814ad4bf 54// based on : AliEMCALDigitizer
05a92d59 55// Modif:
56// August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
57// of new IO (à la PHOS)
1963b290 58// November 2003 Aleksei Pavlinov : adopted for Shish-Kebab geometry
59//_________________________________________________________________________________
61e0abb5 60
61// --- ROOT system ---
e939a978 62#include <TROOT.h>
63#include <TTree.h>
64#include <TSystem.h>
65#include <TBenchmark.h>
e939a978 66#include <TBrowser.h>
67#include <TObjectTable.h>
68#include <TRandom.h>
916f1e76 69#include <TF1.h>
21e7df44 70#include <cassert>
61e0abb5 71
72// --- AliRoot header files ---
b42d4197 73#include "AliLog.h"
e4dcc484 74#include "AliRun.h"
ea5f3389 75#include "AliRunDigitizer.h"
5dee926e 76#include "AliRunLoader.h"
53f1c378 77#include "AliCDBManager.h"
78#include "AliCDBEntry.h"
61e0abb5 79#include "AliEMCALDigit.h"
05a92d59 80#include "AliEMCAL.h"
5dee926e 81#include "AliEMCALLoader.h"
61e0abb5 82#include "AliEMCALDigitizer.h"
83#include "AliEMCALSDigitizer.h"
84#include "AliEMCALGeometry.h"
6b527f8f 85//#include "AliEMCALTick.h"
a435f763 86#include "AliEMCALCalibData.h"
33a52e55 87#include "AliEMCALSimParam.h"
916f1e76 88#include "AliEMCALRawDigit.h"
89
90namespace
91{
92 Double_t HeavisideTheta(Double_t x)
93 {
94 Double_t signal = 0.;
95
96 if (x > 0.) signal = 1.;
97
98 return signal;
99 }
100
101 Double_t AnalogFastORFunction(Double_t *x, Double_t *par)
102 {
103 Double_t v0 = par[0];
104 Double_t t0 = par[1];
105 Double_t tr = par[2];
106
107 Double_t R1 = 1000.;
108 Double_t C1 = 33e-12;
109 Double_t R2 = 1800;
110 Double_t C2 = 22e-12;
111
112 Double_t t = x[0];
113
114 return (((0.8*(-((TMath::Power(C1,2)*C2*TMath::Power(TMath::E(),(-t + t0)/(C1*R1))*
115 TMath::Power(R1,2)*R2)/(C1*R1 - C2*R2)) +
116 C1*C2*R1*R2*(1 - (C2*TMath::Power(TMath::E(),(-t + t0)/(C2*R2))*R2)/(-(C1*R1) + C2*R2)))*v0*
117 HeavisideTheta(t - t0))/tr
118 - (0.8*(C1*C2*R1*R2 -
119 (TMath::Power(C1,2)*C2*TMath::Power(TMath::E(),(-1.*t + t0 + 1.25*tr)/(C1*R1))*
120 TMath::Power(R1,2)*R2)/(C1*R1 - C2*R2) +
121 (C1*TMath::Power(C2,2)*TMath::Power(TMath::E(),(-1.*t + t0 + 1.25*tr)/(C2*R2))*
122 R1*TMath::Power(R2,2))/(C1*R1 - C2*R2))*v0*
123 HeavisideTheta(t - t0 - 1.25*tr))/tr)/(C2*R1));
124 }
125}
05a92d59 126
61e0abb5 127ClassImp(AliEMCALDigitizer)
128
129
130//____________________________________________________________________________
18a21c7c 131AliEMCALDigitizer::AliEMCALDigitizer()
132 : AliDigitizer("",""),
133 fDefaultInit(kTRUE),
134 fDigitsInRun(0),
135 fInit(0),
136 fInput(0),
137 fInputFileNames(0x0),
138 fEventNames(0x0),
139 fDigitThreshold(0),
140 fMeanPhotonElectron(0),
33a52e55 141// fPedestal(0), //Not used, remove?
142// fSlope(0), //Not used, remove?
18a21c7c 143 fPinNoise(0),
f0a6dc6f 144 fTimeDelay(0),
18a21c7c 145 fTimeResolution(0),
33a52e55 146// fTimeThreshold(0), //Not used, remove?
147// fTimeSignalLength(0), //Not used, remove?
18a21c7c 148 fADCchannelEC(0),
149 fADCpedestalEC(0),
150 fNADCEC(0),
151 fEventFolderName(""),
152 fFirstEvent(0),
153 fLastEvent(0),
7ea6391b 154 fCalibData(0x0)
61e0abb5 155{
156 // ctor
88cb7938 157 InitParameters() ;
ab6a174f 158 fManager = 0 ; // We work in the standalone mode
839828a6 159}
61e0abb5 160
839828a6 161//____________________________________________________________________________
18a21c7c 162AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolderName)
163 : AliDigitizer("EMCAL"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
164 fDefaultInit(kFALSE),
165 fDigitsInRun(0),
166 fInit(0),
167 fInput(0),
168 fInputFileNames(0),
169 fEventNames(0),
170 fDigitThreshold(0),
171 fMeanPhotonElectron(0),
33a52e55 172// fPedestal(0),//Not used, remove?
173// fSlope(0), //Not used, remove?
18a21c7c 174 fPinNoise(0),
f0a6dc6f 175 fTimeDelay(0),
18a21c7c 176 fTimeResolution(0),
33a52e55 177// fTimeThreshold(0), //Not used, remove?
178// fTimeSignalLength(0), //Not used, remove?
18a21c7c 179 fADCchannelEC(0),
180 fADCpedestalEC(0),
181 fNADCEC(0),
182 fEventFolderName(eventFolderName),
183 fFirstEvent(0),
184 fLastEvent(0),
7ea6391b 185 fCalibData(0x0)
839828a6 186{
05a92d59 187 // ctor
a9485c37 188 InitParameters() ;
88cb7938 189 Init() ;
ab6a174f 190 fManager = 0 ; // We work in the standalone mode
61e0abb5 191}
839828a6 192
61e0abb5 193//____________________________________________________________________________
18a21c7c 194AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d)
195 : AliDigitizer(d.GetName(),d.GetTitle()),
196 fDefaultInit(d.fDefaultInit),
197 fDigitsInRun(d.fDigitsInRun),
198 fInit(d.fInit),
199 fInput(d.fInput),
200 fInputFileNames(d.fInputFileNames),
201 fEventNames(d.fEventNames),
202 fDigitThreshold(d.fDigitThreshold),
203 fMeanPhotonElectron(d.fMeanPhotonElectron),
33a52e55 204// fPedestal(d.fPedestal), //Not used, remove?
205// fSlope(d.fSlope), //Not used, remove?
18a21c7c 206 fPinNoise(d.fPinNoise),
f0a6dc6f 207 fTimeDelay(d.fTimeDelay),
18a21c7c 208 fTimeResolution(d.fTimeResolution),
33a52e55 209// fTimeThreshold(d.fTimeThreshold), //Not used, remove?
210// fTimeSignalLength(d.fTimeSignalLength), //Not used, remove?
18a21c7c 211 fADCchannelEC(d.fADCchannelEC),
212 fADCpedestalEC(d.fADCpedestalEC),
213 fNADCEC(d.fNADCEC),
214 fEventFolderName(d.fEventFolderName),
215 fFirstEvent(d.fFirstEvent),
216 fLastEvent(d.fLastEvent),
7ea6391b 217 fCalibData(d.fCalibData)
88cb7938 218{
219 // copyy ctor
88cb7938 220 }
221
222//____________________________________________________________________________
18a21c7c 223AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd)
224 : AliDigitizer(rd,"EMCAL"+AliConfig::Instance()->GetDigitizerTaskName()),
225 fDefaultInit(kFALSE),
226 fDigitsInRun(0),
227 fInit(0),
228 fInput(0),
229 fInputFileNames(0),
230 fEventNames(0),
da509d54 231 fDigitThreshold(0),
18a21c7c 232 fMeanPhotonElectron(0),
33a52e55 233// fPedestal(0), //Not used, remove?
234// fSlope(0.), //Not used, remove?
da509d54 235 fPinNoise(0.),
f0a6dc6f 236 fTimeDelay(0.),
18a21c7c 237 fTimeResolution(0.),
33a52e55 238// fTimeThreshold(0), //Not used, remove?
239// fTimeSignalLength(0), //Not used, remove?
18a21c7c 240 fADCchannelEC(0),
241 fADCpedestalEC(0),
242 fNADCEC(0),
243 fEventFolderName(0),
244 fFirstEvent(0),
245 fLastEvent(0),
7ea6391b 246 fCalibData(0x0)
61e0abb5 247{
45fa49ca 248 // ctor Init() is called by RunDigitizer
88cb7938 249 fManager = rd ;
e0e18b6d 250 fEventFolderName = fManager->GetInputFolderName(0) ;
88cb7938 251 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
05a92d59 252 InitParameters() ;
839828a6 253}
814ad4bf 254
839828a6 255//____________________________________________________________________________
256 AliEMCALDigitizer::~AliEMCALDigitizer()
257{
14ce0a6e 258 //dtor
33c3c91a 259 if (AliRunLoader::Instance()) {
5dee926e 260 AliLoader *emcalLoader=0;
33c3c91a 261 if ((emcalLoader = AliRunLoader::Instance()->GetDetectorLoader("EMCAL")))
5dee926e 262 emcalLoader->CleanDigitizer();
263 }
264 else
265 AliDebug(1," no runloader present");
f5f384f4 266 delete [] fInputFileNames ;
267 delete [] fEventNames ;
64942713 268
61e0abb5 269}
270
271//____________________________________________________________________________
09884213 272void AliEMCALDigitizer::Digitize(Int_t event)
05a92d59 273{
61e0abb5 274
275 // Makes the digitization of the collected summable digits
276 // for this it first creates the array of all EMCAL modules
ab6a174f 277 // filled with noise and after that adds contributions from
278 // SDigits. This design helps to avoid scanning over the
279 // list of digits to add contribution of any new SDigit.
280 //
281 // JLK 26-Jun-2008
282 // Note that SDigit energy info is stored as an amplitude, so we
283 // must call the Calibrate() method of the SDigitizer to convert it
284 // back to an energy in GeV before adding it to the Digit
285 //
1963b290 286 static int nEMC=0; //max number of digits possible
61e0abb5 287
33c3c91a 288 AliRunLoader *rl = AliRunLoader::Instance();
5dee926e 289 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
14ce0a6e 290 Int_t readEvent = event ;
1963b290 291 // fManager is data member from AliDigitizer
45fa49ca 292 if (fManager)
14ce0a6e 293 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
cf24bdc4 294 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
14ce0a6e 295 readEvent, GetTitle(), fEventFolderName.Data())) ;
296 rl->GetEvent(readEvent);
5dee926e 297
298 TClonesArray * digits = emcalLoader->Digits() ;
ab6a174f 299 digits->Delete() ; //correct way to clear array when memory is
300 //allocated by objects stored in array
61e0abb5 301
e4dcc484 302 // Load Geometry
30bc5594 303 AliEMCALGeometry *geom = 0;
304 if (rl->GetAliRun()) {
305 AliEMCAL * emcal = (AliEMCAL*)rl->GetAliRun()->GetDetector("EMCAL");
306 geom = emcal->GetGeometry();
307 }
308 else
309 AliFatal("Could not get AliRun from runLoader");
e4dcc484 310
fe93d365 311 nEMC = geom->GetNCells();
312 AliDebug(1,Form("nEMC %i (number cells in EMCAL) | %s \n", nEMC, geom->GetName()));
313
53e430a3 314 Int_t absID = -1 ;
61e0abb5 315
88cb7938 316 digits->Expand(nEMC) ;
05a92d59 317
88cb7938 318 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
5dee926e 319 if ( !emcalLoader->SDigitizer() )
320 emcalLoader->LoadSDigitizer();
321 AliEMCALSDigitizer * sDigitizer = dynamic_cast<AliEMCALSDigitizer*>(emcalLoader->SDigitizer());
88cb7938 322
323 if ( !sDigitizer )
324 Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ;
325
326 //take all the inputs to add together and load the SDigits
327 TObjArray * sdigArray = new TObjArray(fInput) ;
5dee926e 328 sdigArray->AddAt(emcalLoader->SDigits(), 0) ;
53e430a3 329
88cb7938 330 Int_t i ;
331 for(i = 1 ; i < fInput ; i++){
332 TString tempo(fEventNames[i]) ;
333 tempo += i ;
3880b0fb 334
335 AliRunLoader * rl2 = AliRunLoader::GetRunLoader(tempo) ;
336
337 if (rl2==0)
338 rl2 = AliRunLoader::Open(fInputFileNames[i], tempo) ;
339
45fa49ca 340 if (fManager)
14ce0a6e 341 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
342 Info("Digitize", "Adding event %d from input stream %d %s %s", readEvent, i, fInputFileNames[i].Data(), tempo.Data()) ;
3880b0fb 343 rl2->LoadSDigits();
14ce0a6e 344 rl2->GetEvent(readEvent);
3880b0fb 345 AliEMCALLoader *emcalLoader2 = dynamic_cast<AliEMCALLoader*>(rl2->GetDetectorLoader("EMCAL"));
346 sdigArray->AddAt(emcalLoader2->SDigits(), i) ;
0c219753 347 }
5dee926e 348
d968cee0 349 //Find the first tower with signal
a9485c37 350 Int_t nextSig = nEMC + 1 ;
88cb7938 351 TClonesArray * sdigits ;
352 for(i = 0 ; i < fInput ; i++){
353 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
814ad4bf 354 if ( !sdigits->GetEntriesFast() )
355 continue ;
88cb7938 356 Int_t curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(0))->GetId() ;
814ad4bf 357 if(curNext < nextSig)
358 nextSig = curNext ;
cf24bdc4 359 AliDebug(1,Form("input %i : #sdigits %i \n",
360 i, sdigits->GetEntriesFast()));
814ad4bf 361 }
cf24bdc4 362 AliDebug(1,Form("FIRST tower with signal %i \n", nextSig));
61e0abb5 363
88cb7938 364 TArrayI index(fInput) ;
814ad4bf 365 index.Reset() ; //Set all indexes to zero
61e0abb5 366
05a92d59 367 AliEMCALDigit * digit ;
368 AliEMCALDigit * curSDigit ;
ffa6d63b 369
9517d886 370 // TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
ffa6d63b 371
5dee926e 372 //Put Noise contribution
d25f2c54 373 for(absID = 0; absID < nEMC; absID++){ // Nov 30, 2006 by PAI; was from 1 to nEMC
ab6a174f 374 Float_t energy = 0 ;
a9485c37 375 // amplitude set to zero, noise will be added later
829ba234 376 new((*digits)[absID]) AliEMCALDigit( -1, -1, absID, 0., TimeOfNoise(),kFALSE); // absID-1->absID
814ad4bf 377 //look if we have to add signal?
d25f2c54 378 digit = dynamic_cast<AliEMCALDigit *>(digits->At(absID)); // absID-1->absID
88cb7938 379
814ad4bf 380 if(absID==nextSig){
54cbf5a6 381 //Add SDigits from all inputs
9517d886 382 // ticks->Clear() ;
383 //Int_t contrib = 0 ;
384
385 //Follow PHOS and comment out this timing model til a better one
386 //can be developed - JLK 28-Apr-2008
387
829ba234 388 //Float_t a = digit->GetAmplitude() ;
9517d886 389 //Float_t b = TMath::Abs( a /fTimeSignalLength) ;
88cb7938 390 //Mark the beginning of the signal
9517d886 391 //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
fdebddeb 392 //Mark the end of the signal
9517d886 393 //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
394
395 // Calculate time as time of the largest digit
396 Float_t time = digit->GetTime() ;
829ba234 397 Float_t aTime= digit->GetAmplitude() ;
814ad4bf 398
88cb7938 399 // loop over input
400 for(i = 0; i< fInput ; i++){ //loop over (possible) merge sources
401 if(dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
402 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
814ad4bf 403 else
404 curSDigit = 0 ;
405 //May be several digits will contribute from the same input
fdebddeb 406 while(curSDigit && (curSDigit->GetId() == absID)){
814ad4bf 407 //Shift primary to separate primaries belonging different inputs
408 Int_t primaryoffset ;
409 if(fManager)
410 primaryoffset = fManager->GetMask(i) ;
411 else
412 primaryoffset = i ;
413 curSDigit->ShiftPrimary(primaryoffset) ;
9517d886 414
415 //Remove old timing model - JLK 28-April-2008
829ba234 416 //a = curSDigit->GetAmplitude() ;
9517d886 417 //b = a /fTimeSignalLength ;
418 //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
419 //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
829ba234 420 if(curSDigit->GetAmplitude()>aTime) {
421 aTime = curSDigit->GetAmplitude();
9517d886 422 time = curSDigit->GetTime();
423 }
814ad4bf 424
ab6a174f 425 *digit = *digit + *curSDigit ; //adds amplitudes of each digit
814ad4bf 426
427 index[i]++ ;
88cb7938 428 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
1963b290 429 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
814ad4bf 430 else
431 curSDigit = 0 ;
432 }
433 }
ab6a174f 434 //Here we convert the summed amplitude to an energy in GeV
829ba234 435 energy = sDigitizer->Calibrate(digit->GetAmplitude()) ; // GeV
a9485c37 436 // add fluctuations for photo-electron creation
ab6a174f 437 energy *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
88cb7938 438
05a92d59 439 //calculate and set time
9517d886 440 //New timing model needed - JLK 28-April-2008
441 //Float_t time = FrontEdgeTime(ticks) ;
814ad4bf 442 digit->SetTime(time) ;
443
444 //Find next signal module
a9485c37 445 nextSig = nEMC + 1 ;
88cb7938 446 for(i = 0 ; i < fInput ; i++){
53e430a3 447 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
448 Int_t curNext = nextSig ;
449 if(sdigits->GetEntriesFast() > index[i] ){
450 curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]))->GetId() ;
451 }
452 if(curNext < nextSig) nextSig = curNext ;
814ad4bf 453 }
454 }
a9485c37 455 // add the noise now
ab6a174f 456 energy += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
457 // JLK 26-June-2008
458 //Now digitize the energy according to the sDigitizer method,
459 //which merely converts the energy to an integer. Later we will
460 //check that the stored value matches our allowed dynamic ranges
829ba234 461 digit->SetAmplitude(sDigitizer->Digitize(energy)) ;
ab6a174f 462 AliDebug(10,Form(" absID %5i energy %f nextSig %5i\n",
463 absID, energy, nextSig));
464 } // for(absID = 0; absID < nEMC; absID++)
814ad4bf 465
9517d886 466 //ticks->Delete() ;
467 //delete ticks ;
61e0abb5 468
ab6a174f 469 //JLK is it better to call Clear() here?
05a92d59 470 delete sdigArray ; //We should not delete its contents
61e0abb5 471
814ad4bf 472 //remove digits below thresholds
4354827d 473 // until 10-02-2010 remove digits with energy smaller than fDigitThreshold 3*fPinNoise
474 // now, remove digits with Digitized ADC smaller than fDigitThreshold = 3
475 Float_t energy=0;
88cb7938 476 for(i = 0 ; i < nEMC ; i++){
477 digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
4354827d 478 //First get the energy in GeV units.
829ba234 479 energy = sDigitizer->Calibrate(digit->GetAmplitude()) ;
4354827d 480 //Then digitize using the calibration constants of the ocdb
829ba234 481 Float_t ampADC = DigitizeEnergy(energy, digit->GetId()) ;
482 //if(ampADC>2)printf("Digit energy %f, amp %d, amp cal %d, threshold %d\n",energy,digit->GetAmplitude(),ampADC,fDigitThreshold);
4354827d 483 if(ampADC < fDigitThreshold)
88cb7938 484 digits->RemoveAt(i) ;
485 else
814ad4bf 486 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
a9485c37 487 }
61e0abb5 488
814ad4bf 489 digits->Compress() ;
61e0abb5 490
05a92d59 491 Int_t ndigits = digits->GetEntriesFast() ;
4354827d 492
ab6a174f 493 //JLK 26-June-2008
494 //After we have done the summing and digitizing to create the
495 //digits, now we want to calibrate the resulting amplitude to match
496 //the dynamic range of our real data.
05a92d59 497 for (i = 0 ; i < ndigits ; i++) {
498 digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
814ad4bf 499 digit->SetIndexInList(i) ;
829ba234 500 energy = sDigitizer->Calibrate(digit->GetAmplitude()) ;
501 digit->SetAmplitude(DigitizeEnergy(energy, digit->GetId()) ) ;
f0a6dc6f 502 //Add delay to time
503 digit->SetTime(digit->GetTime()+fTimeDelay) ;
829ba234 504 // printf("digit amplitude set at end: i %d, amp %f\n",i,digit->GetAmplitude());
61e0abb5 505 }
ab6a174f 506
814ad4bf 507}
61e0abb5 508
d62a891a 509// //_____________________________________________________________________
829ba234 510Float_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t AbsId)
814ad4bf 511{
ab6a174f 512 // JLK 26-June-2008
e4dcc484 513 // Returns digitized value of the energy in a cell absId
ab6a174f 514 // using the calibration constants stored in the OCDB
515 // or default values if no CalibData object is found.
516 // This effectively converts everything to match the dynamic range
517 // of the real data we will collect
518 //
53f1c378 519 // Load Geometry
520 const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
e4dcc484 521
522 if (geom==0)
d25f2c54 523 AliFatal("Did not get geometry from EMCALLoader");
e4dcc484 524
525 Int_t iSupMod = -1;
2bb3725c 526 Int_t nModule = -1;
e4dcc484 527 Int_t nIphi = -1;
528 Int_t nIeta = -1;
529 Int_t iphi = -1;
530 Int_t ieta = -1;
829ba234 531 Float_t channel = -999;
e4dcc484 532
2bb3725c 533 Bool_t bCell = geom->GetCellIndex(AbsId, iSupMod, nModule, nIphi, nIeta) ;
e4dcc484 534 if(!bCell)
d25f2c54 535 Error("DigitizeEnergy","Wrong cell id number : AbsId %i ", AbsId) ;
2bb3725c 536 geom->GetCellPhiEtaIndexInSModule(iSupMod,nModule,nIphi, nIeta,iphi,ieta);
d62a891a 537
53f1c378 538 if(fCalibData) {
539 fADCpedestalEC = fCalibData->GetADCpedestal(iSupMod,ieta,iphi);
540 fADCchannelEC = fCalibData->GetADCchannel(iSupMod,ieta,iphi);
e4dcc484 541 }
5eb74a51 542
829ba234 543 //channel = static_cast<Int_t> (TMath::Floor( (energy + fADCpedestalEC)/fADCchannelEC )) ;
544 channel = (energy + fADCpedestalEC)/fADCchannelEC ;
545
fdebddeb 546 if(channel > fNADCEC )
7d74eaca 547 channel = fNADCEC ;
814ad4bf 548 return channel ;
d62a891a 549
61e0abb5 550}
551
552//____________________________________________________________________________
05a92d59 553void AliEMCALDigitizer::Exec(Option_t *option)
554{
45fa49ca 555 // Steering method to process digitization for events
556 // in the range from fFirstEvent to fLastEvent.
557 // This range is optionally set by SetEventRange().
558 // if fLastEvent=-1, then process events until the end.
559 // by default fLastEvent = fFirstEvent (process only one event)
05a92d59 560
88cb7938 561 if (!fInit) { // to prevent overwrite existing file
562 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
563 return ;
564 }
565
814ad4bf 566 if (strstr(option,"print")) {
b42d4197 567
88cb7938 568 Print();
814ad4bf 569 return ;
570 }
571
61e0abb5 572 if(strstr(option,"tim"))
573 gBenchmark->Start("EMCALDigitizer");
5dee926e 574
33c3c91a 575 AliRunLoader *rl = AliRunLoader::Instance();
5dee926e 576 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
577
5b4d2c50 578 // Post Digitizer to the white board
5dee926e 579 emcalLoader->PostDigitizer(this) ;
5b4d2c50 580
30bc5594 581 if (fLastEvent == -1) {
5dee926e 582 fLastEvent = rl->GetNumberOfEvents() - 1 ;
30bc5594 583 }
396a348e 584 else if (fManager)
1963b290 585 fLastEvent = fFirstEvent ; // what is this ??
396a348e 586
53e430a3 587 Int_t nEvents = fLastEvent - fFirstEvent + 1;
588 Int_t ievent = -1;
cf24bdc4 589
916f1e76 590 TClonesArray* digitsTRG = new TClonesArray("AliEMCALRawDigit", 32 * 96);
591 TClonesArray* digitsTMP = new TClonesArray("AliEMCALDigit", 32 * 96);
5dee926e 592 rl->LoadSDigits("EMCAL");
cf24bdc4 593 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
64942713 594
5dee926e 595 rl->GetEvent(ievent);
05a92d59 596
814ad4bf 597 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 598
9e5d2067 599 WriteDigits() ;
916f1e76 600
601 //Trigger Digits
602 //-------------------------------------
603 Digits2FastOR(digitsTMP, digitsTRG);
604
605 WriteDigits(digitsTRG);
606
ee3df32e 607 (emcalLoader->TreeD())->Fill();
608
916f1e76 609 emcalLoader->WriteDigits( "OVERWRITE");
610 emcalLoader->WriteDigitizer("OVERWRITE");
611
612 Unload();
613
e0dc3f7d 614 digitsTRG->Clear("C");
615 digitsTMP->Clear("C");
916f1e76 616 //-------------------------------------
88cb7938 617
61e0abb5 618 if(strstr(option,"deb"))
619 PrintDigits(option);
1963b290 620 if(strstr(option,"table")) gObjectTable->Print();
88cb7938 621
814ad4bf 622 //increment the total number of Digits per run
5dee926e 623 fDigitsInRun += emcalLoader->Digits()->GetEntriesFast() ;
61e0abb5 624 }
64942713 625
5dee926e 626 emcalLoader->CleanDigitizer() ;
5b4d2c50 627
61e0abb5 628 if(strstr(option,"tim")){
629 gBenchmark->Stop("EMCALDigitizer");
b42d4197 630 AliInfo(Form("Exec: took %f seconds for Digitizing %f seconds per event",
631 gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nEvents )) ;
88cb7938 632 }
61e0abb5 633}
634
05a92d59 635//____________________________________________________________________________
916f1e76 636void AliEMCALDigitizer::Digits2FastOR(TClonesArray* digitsTMP, TClonesArray* digitsTRG)
637{
638 // FEE digits afterburner to produce TRG digits
639 // we are only interested in the FEE digit deposited energy
640 // to be converted later into a voltage value
641
642 // push the FEE digit to its associated FastOR (numbered from 0:95)
643 // TRU is in charge of summing module digits
644
645 AliRunLoader *runLoader = AliRunLoader::Instance();
646
647 AliRun* run = runLoader->GetAliRun();
648
649 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(runLoader->GetDetectorLoader("EMCAL"));
650
651 AliEMCALGeometry* geom = dynamic_cast<AliEMCAL*>(run->GetDetector("EMCAL"))->GetGeometry();
652
653 // build FOR from simulated digits
654 // and xfer to the corresponding TRU input (mapping)
655
656 TClonesArray* digits = emcalLoader->Digits();
657
658 TIter NextDigit(digits);
659 while (AliEMCALDigit* digit = (AliEMCALDigit*)NextDigit())
660 {
661 Int_t id = digit->GetId();
662
663 Int_t iSupMod, nModule, nIphi, nIeta, iphi, ieta, iphim, ietam;
664
665 geom->GetCellIndex( id, iSupMod, nModule, nIphi, nIeta );
666 geom->GetModulePhiEtaIndexInSModule( iSupMod, nModule, iphim, ietam );
667 geom->GetCellPhiEtaIndexInSModule( iSupMod, nModule, nIphi, nIeta, iphi, ieta);
668
669 // identify to which TRU this FEE digit belong
52b045b9 670 //Int_t itru = (iSupMod < 11) ? iphim / 4 + 3 * iSupMod : 31;
671 Int_t itru = -1;
672 if (iSupMod < 11)
673 itru = (iSupMod % 2) ? (2 - int(iphim / 4)) + 3 * iSupMod : iphim / 4 + 3 * iSupMod;
674 else
675 itru = 31;
916f1e76 676
677 //---------
678 //
679 // FIXME: bad numbering solution to deal w/ the last 2 SM which have only 1 TRU each
680 // using the AliEMCALGeometry official numbering
681 // only 1 TRU/SM in SM 10 & SM 11
682 //
683 //---------
684 if ((itru == 31 && iphim < 2) || (itru == 30 && iphim > 5)) continue;
685
686 // to be compliant with %4 per TRU
687 if (itru == 31) iphim -= 2;
688
53e430a3 689 Int_t trgid = 0;
916f1e76 690 Bool_t isOK = geom->GetAbsFastORIndexFromPositionInTRU(itru, ietam, iphim % 4, trgid);
691
692 AliDebug(2,Form("trigger digit id: %d itru: %d isOK: %d\n",trgid,itru,isOK));
693
694 if (isOK)
695 {
696 AliEMCALDigit* d = static_cast<AliEMCALDigit*>(digitsTMP->At(trgid));
697
698 if (!d)
699 {
700 new((*digitsTMP)[trgid]) AliEMCALDigit(*digit);
701 d = (AliEMCALDigit*)digitsTMP->At(trgid);
702 d->SetId(trgid);
703 }
704 else
705 {
706 *d = *d + *digit;
707 }
708 }
709 }
710
711 Int_t nSamples = 32;
da509d54 712 Int_t *timeSamples = new Int_t[nSamples];
916f1e76 713
714 NextDigit = TIter(digitsTMP);
715 while (AliEMCALDigit* digit = (AliEMCALDigit*)NextDigit())
716 {
717 if (digit)
718 {
719 Int_t id = digit->GetId();
720 Float_t time = digit->GetTime();
721
722 Double_t depositedEnergy = 0.;
723 for (Int_t j = 1; j <= digit->GetNprimary(); j++) depositedEnergy += digit->GetDEPrimary(j);
724
725 // FIXME: Check digit time!
726 if (depositedEnergy)
727 {
728 DigitalFastOR(time, depositedEnergy, timeSamples, nSamples);
729
730 for (Int_t j=0;j<nSamples;j++)
731 {
732 timeSamples[j] = ((j << 12) & 0xFF000) | (timeSamples[j] & 0xFFF);
733 }
734
735 new((*digitsTRG)[digitsTRG->GetEntriesFast()]) AliEMCALRawDigit(id, timeSamples, nSamples);
736 }
737 }
738 }
84f6f119 739
740 delete [] timeSamples;
916f1e76 741}
742
743//____________________________________________________________________________
744void AliEMCALDigitizer::DigitalFastOR( Double_t time, Double_t dE, Int_t timeSamples[], Int_t nSamples )
745{
746 // parameters:
747 // id: 0..95
748 const Int_t reso = 11; // 11-bit resolution ADC
749 const Double_t vFSR = 1; // Full scale input voltage range
750 const Double_t Ne = 125; // signal of the APD per MeV of energy deposit in a tower: 125 photo-e-/MeV @ M=30
751 const Double_t vA = .136e-6; // CSP output range: 0.136uV/e-
752 const Double_t rise = 40e-9; // rise time (10-90%) of the FastOR signal before shaping
753
754 const Double_t kTimeBinWidth = 25E-9; // sampling frequency (40MHz)
755
756 Double_t vV = 1000. * dE * Ne * vA; // GeV 2 MeV
757
758 TF1 signalF("signal", AnalogFastORFunction, 0, nSamples * kTimeBinWidth, 3);
759 signalF.SetParameter( 0, vV );
760 signalF.SetParameter( 1, time ); // FIXME: when does the signal arrive? Might account for cable lengths
761 signalF.SetParameter( 2, rise );
762
763 for (Int_t iTime=0; iTime<nSamples; iTime++)
764 {
765 // FIXME: add noise (probably not simply Gaussian) according to DA measurements
766 // probably plan an access to OCDB
767
768 timeSamples[iTime] = int((TMath::Power(2, reso) / vFSR) * signalF.Eval(iTime * kTimeBinWidth) + 0.5);
769 }
770}
771
772
773//____________________________________________________________________________
33a52e55 774//Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
775//{
776// // Returns the shortest time among all time ticks
777//
778// ticks->Sort() ; //Sort in accordance with times of ticks
779// TIter it(ticks) ;
780// AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
781// Float_t time = ctick->CrossingTime(fTimeThreshold) ;
782//
783// AliEMCALTick * t ;
784// while((t=(AliEMCALTick*) it.Next())){
785// if(t->GetTime() < time) //This tick starts before crossing
786// *ctick+=*t ;
787// else
788// return time ;
789//
790// time = ctick->CrossingTime(fTimeThreshold) ;
791// }
792// return time ;
793//}
794//
05a92d59 795
796//____________________________________________________________________________
797Bool_t AliEMCALDigitizer::Init()
798{
799 // Makes all memory allocations
88cb7938 800 fInit = kTRUE ;
33c3c91a 801 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
5dee926e 802
803 if ( emcalLoader == 0 ) {
804 Fatal("Init", "Could not obtain the AliEMCALLoader");
05a92d59 805 return kFALSE;
806 }
05a92d59 807
45fa49ca 808 fFirstEvent = 0 ;
809 fLastEvent = fFirstEvent ;
810
88cb7938 811 if(fManager)
812 fInput = fManager->GetNinputs() ;
813 else
814 fInput = 1 ;
815
816 fInputFileNames = new TString[fInput] ;
817 fEventNames = new TString[fInput] ;
818 fInputFileNames[0] = GetTitle() ;
819 fEventNames[0] = fEventFolderName.Data() ;
820 Int_t index ;
821 for (index = 1 ; index < fInput ; index++) {
822 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
823 TString tempo = fManager->GetInputFolderName(index) ;
824 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager
05a92d59 825 }
826
88cb7938 827 //to prevent cleaning of this object while GetEvent is called
5dee926e 828 emcalLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
e52475ed 829
53f1c378 830 //Calibration instance
831 fCalibData = emcalLoader->CalibData();
88cb7938 832 return fInit ;
05a92d59 833}
834
835//____________________________________________________________________________
836void AliEMCALDigitizer::InitParameters()
14ce0a6e 837{
29b5d492 838 // Parameter initialization for digitizer
6569f329 839
840 // Get the parameters from the OCDB via the loader
841 AliRunLoader *rl = AliRunLoader::Instance();
842 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
843 AliEMCALSimParam * simParam = 0x0;
844 if(emcalLoader) simParam = emcalLoader->SimulationParameters();
845
846 if(!simParam){
847 simParam = AliEMCALSimParam::GetInstance();
848 AliWarning("Simulation Parameters not available in OCDB?");
849 }
850
851 fMeanPhotonElectron = simParam->GetMeanPhotonElectron();//4400; // electrons per GeV
852 fPinNoise = simParam->GetPinNoise();//0.012; // pin noise in GeV from analysis test beam data
33a52e55 853 if (fPinNoise < 0.0001 )
88cb7938 854 Warning("InitParameters", "No noise added\n") ;
6569f329 855 fDigitThreshold = simParam->GetDigitThreshold(); //fPinNoise * 3; // 3 * sigma
f0a6dc6f 856 fTimeResolution = simParam->GetTimeResolution(); //0.6e-9 ; // 600 pc
857 fTimeDelay = simParam->GetTimeDelay(); //600e-9 ; // 600 ns
05a92d59 858
97075cd8 859 // These defaults are normally not used.
860 // Values are read from calibration database instead
33a52e55 861 fADCchannelEC = 0.0153; // Update 24 Apr 2007: 250./16/1024 - width of one ADC channel in GeV
862 fADCpedestalEC = 0.0 ; // GeV
863
6569f329 864 fNADCEC = simParam->GetNADCEC();//(Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC - 65536
33a52e55 865
29b7e56e 866 AliDebug(2,Form("Mean Photon Electron %d, Noise %f, Digit Threshold %d,Time Resolution %g,NADCEC %d",
33a52e55 867 fMeanPhotonElectron,fPinNoise,fDigitThreshold,fTimeResolution,fNADCEC));
a9485c37 868
33a52e55 869 // Not used anymore, remove?
870 // fTimeSignalLength = 1.0e-9 ;
871 // fTimeThreshold = 0.001*10000000 ; // Means 1 MeV in terms of SDigits amplitude ??
ab6a174f 872
05a92d59 873}
61e0abb5 874
61e0abb5 875//__________________________________________________________________
09884213 876void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
05a92d59 877{
878 // Allows to produce digits by superimposing background and signal event.
61e0abb5 879 // It is assumed, that headers file with SIGNAL events is opened in
05a92d59 880 // the constructor.
881 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
882 // Thus we avoid writing (changing) huge and expensive
61e0abb5 883 // backgound files: all output will be writen into SIGNAL, i.e.
884 // opened in constructor file.
885 //
05a92d59 886 // One can open as many files to mix with as one needs.
887 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
888 // can be mixed.
61e0abb5 889
05a92d59 890 if( strcmp(GetName(), "") == 0 )
61e0abb5 891 Init() ;
814ad4bf 892
05a92d59 893 if(fManager){
9859bfc0 894 Error("MixWith", "Cannot use this method under AliRunDigitizer") ;
61e0abb5 895 return ;
05a92d59 896 }
88cb7938 897 // looking for file which contains AliRun
898 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
899 Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
900 return ;
61e0abb5 901 }
88cb7938 902 // looking for the file which contains SDigits
33c3c91a 903 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
5dee926e 904 TString fileName( emcalLoader->GetSDigitsFileName() ) ;
e191bb57 905 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 906 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
907 if ( (gSystem->AccessPathName(fileName)) ) {
908 Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
909 return ;
814ad4bf 910 }
88cb7938 911 // need to increase the arrays
30bc5594 912 // MvL: This code only works when fInput == 1, I think.
88cb7938 913 TString tempo = fInputFileNames[fInput-1] ;
914 delete [] fInputFileNames ;
915 fInputFileNames = new TString[fInput+1] ;
916 fInputFileNames[fInput-1] = tempo ;
917
918 tempo = fEventNames[fInput-1] ;
919 delete [] fEventNames ;
920 fEventNames = new TString[fInput+1] ;
921 fEventNames[fInput-1] = tempo ;
922
923 fInputFileNames[fInput] = alirunFileName ;
924 fEventNames[fInput] = eventFolderName ;
925 fInput++ ;
926}
1963b290 927
fe93d365 928//__________________________________________________________________
1963b290 929void AliEMCALDigitizer::Print1(Option_t * option)
930{ // 19-nov-04 - just for convinience
931 Print();
932 PrintDigits(option);
933}
934
61e0abb5 935//__________________________________________________________________
eb0b1051 936void AliEMCALDigitizer::Print(Option_t*)const
88cb7938 937{
938 // Print Digitizer's parameters
fdebddeb 939 printf("Print: \n------------------- %s -------------", GetName() ) ;
88cb7938 940 if( strcmp(fEventFolderName.Data(), "") != 0 ){
941 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
942
943 Int_t nStreams ;
944 if (fManager)
945 nStreams = GetNInputStreams() ;
946 else
947 nStreams = fInput ;
53e430a3 948
949 AliRunLoader *rl=0;
88cb7938 950
951 Int_t index = 0 ;
952 for (index = 0 ; index < nStreams ; index++) {
953 TString tempo(fEventNames[index]) ;
954 tempo += index ;
5dee926e 955 if ((rl = AliRunLoader::GetRunLoader(tempo)) == 0)
956 rl = AliRunLoader::Open(fInputFileNames[index], tempo) ;
957 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
958 TString fileName( emcalLoader->GetSDigitsFileName() ) ;
e191bb57 959 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 960 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
961 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
962 }
5dee926e 963
33c3c91a 964 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
5dee926e 965
966 printf("\nWriting digits to %s", emcalLoader->GetDigitsFileName().Data()) ;
88cb7938 967
968 printf("\nWith following parameters:\n") ;
969
970 printf(" Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise) ;
4354827d 971 printf(" Threshold in Tower (fDigitThreshold) = %d\n", fDigitThreshold) ;
88cb7938 972 printf("---------------------------------------------------\n") ;
ea5f3389 973 }
974 else
fdebddeb 975 printf("Print: AliEMCALDigitizer not initialized") ;
61e0abb5 976}
814ad4bf 977
61e0abb5 978//__________________________________________________________________
14ce0a6e 979void AliEMCALDigitizer::PrintDigits(Option_t * option)
980{
981 //utility method for printing digit information
982
33c3c91a 983 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
5dee926e 984 TClonesArray * digits = emcalLoader->Digits() ;
985 TClonesArray * sdigits = emcalLoader->SDigits() ;
88cb7938 986
1963b290 987 printf("\n #Digits: %d : sdigits %d ", digits->GetEntriesFast(), sdigits->GetEntriesFast()) ;
5dee926e 988 printf("\n event %d", emcalLoader->GetRunLoader()->GetEventNumber());
88cb7938 989
990 if(strstr(option,"all")){
61e0abb5 991 //loop over digits
992 AliEMCALDigit * digit;
88cb7938 993 printf("\nEMC digits (with primaries):\n") ;
994 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
61e0abb5 995 Int_t index ;
88cb7938 996 for (index = 0 ; index < digits->GetEntries() ; index++) {
997 digit = dynamic_cast<AliEMCALDigit *>(digits->At(index)) ;
829ba234 998 printf("\n%6d %8f %6.5e %4d %2d : ",
999 digit->GetId(), digit->GetAmplitude(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
61e0abb5 1000 Int_t iprimary;
9859bfc0 1001 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 1002 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
9859bfc0 1003 }
1004 }
61e0abb5 1005 }
1963b290 1006 printf("\n");
61e0abb5 1007}
05a92d59 1008
1009//__________________________________________________________________
1010Float_t AliEMCALDigitizer::TimeOfNoise(void)
04f0bda3 1011{
1012 // Calculates the time signal generated by noise
26a2ef9d 1013 //PH Info("TimeOfNoise", "Change me") ;
04f0bda3 1014 return gRandom->Rndm() * 1.28E-5;
05a92d59 1015}
1016
88cb7938 1017//__________________________________________________________________
1018void AliEMCALDigitizer::Unload()
1019{
fdebddeb 1020 // Unloads the SDigits and Digits
5dee926e 1021 AliRunLoader *rl=0;
1022
88cb7938 1023 Int_t i ;
1024 for(i = 1 ; i < fInput ; i++){
1025 TString tempo(fEventNames[i]) ;
5dee926e 1026 tempo += i;
1027 if ((rl = AliRunLoader::GetRunLoader(tempo)))
1028 rl->GetDetectorLoader("EMCAL")->UnloadSDigits() ;
88cb7938 1029 }
33c3c91a 1030 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
5dee926e 1031 emcalLoader->UnloadDigits() ;
88cb7938 1032}
1033
814ad4bf 1034//_________________________________________________________________________________________
9e5d2067 1035void AliEMCALDigitizer::WriteDigits()
814ad4bf 1036{
61e0abb5 1037
814ad4bf 1038 // Makes TreeD in the output file.
1039 // Check if branch already exists:
1040 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
1041 // already existing branches.
1042 // else creates branch with Digits, named "EMCAL", title "...",
1043 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
1044 // and names of files, from which digits are made.
61e0abb5 1045
33c3c91a 1046 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
cf24bdc4 1047
5dee926e 1048 const TClonesArray * digits = emcalLoader->Digits() ;
1049 TTree * treeD = emcalLoader->TreeD();
1050 if ( !treeD ) {
1051 emcalLoader->MakeDigitsContainer();
1052 treeD = emcalLoader->TreeD();
1053 }
88cb7938 1054
1055 // -- create Digits branch
1056 Int_t bufferSize = 32000 ;
5dee926e 1057 TBranch * digitsBranch = 0;
30bc5594 1058 if ((digitsBranch = treeD->GetBranch("EMCAL"))) {
5dee926e 1059 digitsBranch->SetAddress(&digits);
30bc5594 1060 AliWarning("Digits Branch already exists. Not all digits will be visible");
1061 }
5dee926e 1062 else
1063 treeD->Branch("EMCAL","TClonesArray",&digits,bufferSize);
1064 //digitsBranch->SetTitle(fEventFolderName);
ee3df32e 1065
1066// treeD->Fill() ;
916f1e76 1067/*
5dee926e 1068 emcalLoader->WriteDigits("OVERWRITE");
1069 emcalLoader->WriteDigitizer("OVERWRITE");
88cb7938 1070
1071 Unload() ;
916f1e76 1072*/
1073}
88cb7938 1074
916f1e76 1075//__________________________________________________________________
1076void AliEMCALDigitizer::WriteDigits(TClonesArray* digits, const char* branchName)
1077{
1078 //
1079 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
1080
1081 TTree* treeD = emcalLoader->TreeD();
1082 if (!treeD)
1083 {
1084 emcalLoader->MakeDigitsContainer();
1085 treeD = emcalLoader->TreeD();
1086 }
1087
1088 // -- create Digits branch
1089 Int_t bufferSize = 32000;
1090
1091 if (TBranch* triggerBranch = treeD->GetBranch(branchName))
1092 {
1093 triggerBranch->SetAddress(&digits);
1094 }
1095 else
1096 {
1097 treeD->Branch(branchName,"TClonesArray",&digits,bufferSize);
1098 }
1099
ee3df32e 1100// treeD->Fill();
814ad4bf 1101}
61e0abb5 1102
fe93d365 1103//__________________________________________________________________
1963b290 1104void AliEMCALDigitizer::Browse(TBrowser* b)
1105{
1963b290 1106 TTask::Browse(b);
1107}