Transition to NewIO
[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//////////////////////////////////////////////////////////////////////////////
ffa6d63b 21// Class performs digitization of Summable digits
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)
58///_________________________________________________________________________________
61e0abb5 59
60// --- ROOT system ---
61#include "TFile.h"
62#include "TTree.h"
63#include "TSystem.h"
64#include "TROOT.h"
65#include "TFolder.h"
66#include "TObjString.h"
54cbf5a6 67#include "TGeometry.h"
61e0abb5 68#include "TBenchmark.h"
05a92d59 69
61e0abb5 70// --- Standard library ---
61e0abb5 71
72// --- AliRoot header files ---
61e0abb5 73#include "AliRun.h"
54cbf5a6 74#include "AliHeader.h"
ea5f3389 75#include "AliStream.h"
76#include "AliRunDigitizer.h"
61e0abb5 77#include "AliEMCALDigit.h"
05a92d59 78#include "AliEMCAL.h"
79#include "AliEMCALGetter.h"
61e0abb5 80#include "AliEMCALDigitizer.h"
81#include "AliEMCALSDigitizer.h"
82#include "AliEMCALGeometry.h"
05a92d59 83#include "AliEMCALTick.h"
84
61e0abb5 85ClassImp(AliEMCALDigitizer)
86
87
88//____________________________________________________________________________
88cb7938 89 AliEMCALDigitizer::AliEMCALDigitizer():AliDigitizer("",""),
90 fInput(0),
91 fInputFileNames(0x0),
92 fEventNames(0x0)
61e0abb5 93{
94 // ctor
88cb7938 95 InitParameters() ;
92f521a9 96 fDefaultInit = kTRUE ;
05a92d59 97 fManager = 0 ; // We work in the standalong mode
88cb7938 98 fEventFolderName = "" ;
839828a6 99}
61e0abb5 100
839828a6 101//____________________________________________________________________________
88cb7938 102AliEMCALDigitizer::AliEMCALDigitizer(const TString alirunFileName, const TString eventFolderName):
103 AliDigitizer("EMCAL"+AliConfig::fgkDigitizerTaskName, alirunFileName),
104 fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
839828a6 105{
05a92d59 106 // ctor
107
a9485c37 108 InitParameters() ;
88cb7938 109 Init() ;
92f521a9 110 fDefaultInit = kFALSE ;
88cb7938 111 fManager = 0 ; // We work in the standalong mode
61e0abb5 112}
839828a6 113
61e0abb5 114//____________________________________________________________________________
88cb7938 115AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d)
116{
117 // copyy ctor
118
119 SetName(d.GetName()) ;
120 SetTitle(d.GetTitle()) ;
121 fDigitThreshold = d.fDigitThreshold ;
122 fMeanPhotonElectron = d.fMeanPhotonElectron ;
123 fPedestal = d.fPedestal ;
124 fSlope = d.fSlope ;
125 fPinNoise = d.fPinNoise ;
126 fTimeResolution = d.fTimeResolution ;
127 fTimeThreshold = d.fTimeThreshold ;
128 fTimeSignalLength = d.fTimeSignalLength ;
129 fADCchannelEC = d.fADCchannelEC ;
130 fADCpedestalEC = d.fADCpedestalEC ;
131 fNADCEC = d.fNADCEC ;
132 fADCchannelHC = d.fADCchannelHC ;
133 fADCpedestalHC = d.fADCpedestalHC ;
134 fNADCHC = d.fNADCHC ;
135 fADCchannelPRE = d.fADCchannelPRE ;
136 fADCpedestalPRE = d.fADCpedestalPRE ;
137 fNADCPRE = d.fNADCPRE ;
138 fEventFolderName = d.fEventFolderName;
139 }
140
141//____________________________________________________________________________
142AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd):
143 AliDigitizer(rd,"EMCAL"+AliConfig::fgkDigitizerTaskName),
144 fEventFolderName(0)
61e0abb5 145{
839828a6 146 // ctor
88cb7938 147 fManager = rd ;
148 SetName(fManager->GetInputFolderName(0)) ;
149 // take title as name of stream 0
150 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
05a92d59 151 InitParameters() ;
88cb7938 152 Init() ;
dafd64d0 153 fDefaultInit = kFALSE ;
839828a6 154}
814ad4bf 155
839828a6 156//____________________________________________________________________________
157 AliEMCALDigitizer::~AliEMCALDigitizer()
158{
159 // dtor
88cb7938 160 delete [] fInputFileNames ;
161 delete [] fEventNames ;
839828a6 162
61e0abb5 163}
164
165//____________________________________________________________________________
05a92d59 166void AliEMCALDigitizer::Digitize(const Int_t event)
167{
61e0abb5 168
169 // Makes the digitization of the collected summable digits
170 // for this it first creates the array of all EMCAL modules
171 // filled with noise (different for EMC, CPV and PPSD) and
172 // after that adds contributions from SDigits. This design
173 // helps to avoid scanning over the list of digits to add
174 // contribution of any new SDigit.
175
88cb7938 176 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;
177 TClonesArray * digits = gime->Digits() ;
814ad4bf 178 digits->Clear() ;
61e0abb5 179
05a92d59 180 const AliEMCALGeometry *geom = gime->EMCALGeometry() ;
61e0abb5 181 //Making digits with noise, first EMC
a9485c37 182 Int_t nEMC = 0 ;
183 if (geom->GetNHCLayers() > 0 )
184 nEMC = 3*geom->GetNPhi()*geom->GetNZ(); //max number of digits possible (Preshower, ECAL, HCAL)
185 else
186 nEMC = 2*geom->GetNPhi()*geom->GetNZ(); //max number of digits possible (Preshower, ECAL)
88cb7938 187
188 Int_t absID ;
61e0abb5 189
88cb7938 190 digits->Expand(nEMC) ;
05a92d59 191
88cb7938 192 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
193 if ( !gime->SDigitizer() )
194 gime->LoadSDigitizer();
195 AliEMCALSDigitizer * sDigitizer = gime->SDigitizer();
196
197 if ( !sDigitizer )
198 Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ;
199
200 //take all the inputs to add together and load the SDigits
201 TObjArray * sdigArray = new TObjArray(fInput) ;
202 sdigArray->AddAt(gime->SDigits(), 0) ;
203 Int_t i ;
204 for(i = 1 ; i < fInput ; i++){
205 TString tempo(fEventNames[i]) ;
206 tempo += i ;
207 AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[i], tempo) ;
208 gime->Event(event,"S");
209 sdigArray->AddAt(gime->SDigits(), i) ;
0c219753 210 }
88cb7938 211
d968cee0 212 //Find the first tower with signal
a9485c37 213 Int_t nextSig = nEMC + 1 ;
88cb7938 214 TClonesArray * sdigits ;
215 for(i = 0 ; i < fInput ; i++){
216 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
814ad4bf 217 if ( !sdigits->GetEntriesFast() )
218 continue ;
88cb7938 219 Int_t curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(0))->GetId() ;
814ad4bf 220 if(curNext < nextSig)
221 nextSig = curNext ;
222 }
61e0abb5 223
88cb7938 224 TArrayI index(fInput) ;
814ad4bf 225 index.Reset() ; //Set all indexes to zero
61e0abb5 226
05a92d59 227 AliEMCALDigit * digit ;
228 AliEMCALDigit * curSDigit ;
ffa6d63b 229
814ad4bf 230 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
ffa6d63b 231
814ad4bf 232 //Put Noise contribution
233 for(absID = 1; absID <= nEMC; absID++){
88cb7938 234 Float_t amp = 0 ;
a9485c37 235 // amplitude set to zero, noise will be added later
236 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID, 0, TimeOfNoise() ) ;
814ad4bf 237 //look if we have to add signal?
88cb7938 238 digit = dynamic_cast<AliEMCALDigit *>(digits->At(absID-1)) ;
239
814ad4bf 240 if(absID==nextSig){
54cbf5a6 241 //Add SDigits from all inputs
814ad4bf 242 ticks->Clear() ;
243 Int_t contrib = 0 ;
244 Float_t a = digit->GetAmp() ;
245 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
88cb7938 246 //Mark the beginning of the signal
814ad4bf 247 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
248 //Mark the end of the ignal
249 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
250
88cb7938 251 // loop over input
252 for(i = 0; i< fInput ; i++){ //loop over (possible) merge sources
253 if(dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
254 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
814ad4bf 255 else
256 curSDigit = 0 ;
257 //May be several digits will contribute from the same input
258 while(curSDigit && curSDigit->GetId() == absID){
259 //Shift primary to separate primaries belonging different inputs
260 Int_t primaryoffset ;
261 if(fManager)
262 primaryoffset = fManager->GetMask(i) ;
263 else
264 primaryoffset = i ;
265 curSDigit->ShiftPrimary(primaryoffset) ;
266
267 a = curSDigit->GetAmp() ;
268 b = a /fTimeSignalLength ;
269 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
270 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
271
272 *digit = *digit + *curSDigit ; //add energies
273
274 index[i]++ ;
88cb7938 275 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
276 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
814ad4bf 277 else
278 curSDigit = 0 ;
279 }
280 }
a9485c37 281 // add fluctuations for photo-electron creation
282 amp = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
a9485c37 283 amp *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
88cb7938 284
05a92d59 285 //calculate and set time
814ad4bf 286 Float_t time = FrontEdgeTime(ticks) ;
287 digit->SetTime(time) ;
288
289 //Find next signal module
a9485c37 290 nextSig = nEMC + 1 ;
88cb7938 291 for(i = 0 ; i < fInput ; i++){
292 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
814ad4bf 293 Int_t curNext = nextSig ;
294 if(sdigits->GetEntriesFast() > index[i] ){
88cb7938 295 curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]))->GetId() ;
814ad4bf 296 }
297 if(curNext < nextSig) nextSig = curNext ;
298 }
299 }
a9485c37 300 // add the noise now
301
88cb7938 302 if (geom->IsInECA(digit->GetId()))
a9485c37 303 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
304 else if (geom->IsInPRE(digit->GetId()))
305 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise/100.)) ; // arbitrarely divide by 100, assuming that the gain of APD will be higher
88cb7938 306 else if (geom->IsInHCA(digit->GetId()))
a9485c37 307 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise/10.)) ; // arbitrarely divide by 10, assuming that the gain of APD will be higher
a9485c37 308 digit->SetAmp(sDigitizer->Digitize(amp)) ;
814ad4bf 309 }
310
311 ticks->Delete() ;
312 delete ticks ;
61e0abb5 313
05a92d59 314 delete sdigArray ; //We should not delete its contents
61e0abb5 315
814ad4bf 316 //remove digits below thresholds
88cb7938 317 for(i = 0 ; i < nEMC ; i++){
318 digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
a9485c37 319 Float_t threshold = 0 ;
320
88cb7938 321 if (geom->IsInECA(digit->GetId()))
a9485c37 322 threshold = fDigitThreshold ;
323 else if (geom->IsInPRE(digit->GetId()))
324 threshold = fDigitThreshold / 100. ; // arbitrary see before when noise is added
88cb7938 325 else if (geom->IsInHCA(digit->GetId()))
a9485c37 326 threshold = fDigitThreshold / 10. ; // arbitrary see before when noise is added
327
88cb7938 328 if(sDigitizer->Calibrate( digit->GetAmp() ) < threshold)
329 digits->RemoveAt(i) ;
330 else
814ad4bf 331 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
a9485c37 332 }
61e0abb5 333
814ad4bf 334 digits->Compress() ;
61e0abb5 335
05a92d59 336 Int_t ndigits = digits->GetEntriesFast() ;
88cb7938 337 digits->Expand(ndigits) ;
61e0abb5 338
814ad4bf 339 //Set indexes in list of digits
05a92d59 340 for (i = 0 ; i < ndigits ; i++) {
341 digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
814ad4bf 342 digit->SetIndexInList(i) ;
343 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
344 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
61e0abb5 345 }
814ad4bf 346}
61e0abb5 347
814ad4bf 348//____________________________________________________________________________
61e0abb5 349
814ad4bf 350Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
351{
352 Int_t channel = -999;
88cb7938 353 AliEMCALGeometry * geom = AliEMCALGetter::Instance()->EMCALGeometry() ;
814ad4bf 354
a9485c37 355 if(geom->IsInPRE(absId)){ //digitize as PRE section
356 channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPRE)/fADCchannelPRE )) ;
357 if(channel > fNADCPRE )
358 channel = fNADCPRE ;
359 }
88cb7938 360 else if(geom->IsInECA(absId)){ //digitize as ECAL section
a9485c37 361 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC )) ;
362 if(channel > fNADCEC )
363 channel = fNADCEC ;
364 }
88cb7938 365 else if(geom->IsInHCA(absId)){ //digitize as HCAL section
a9485c37 366 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalHC)/fADCchannelHC )) ;
367 if(channel > fNADCHC )
368 channel = fNADCHC ;
ec803232 369 }
814ad4bf 370
371 return channel ;
61e0abb5 372}
373
374//____________________________________________________________________________
05a92d59 375void AliEMCALDigitizer::Exec(Option_t *option)
376{
61e0abb5 377 // Managing method
05a92d59 378
88cb7938 379 if (!fInit) { // to prevent overwrite existing file
380 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
381 return ;
382 }
383
814ad4bf 384 if (strstr(option,"print")) {
88cb7938 385 Print();
814ad4bf 386 return ;
387 }
388
61e0abb5 389 if(strstr(option,"tim"))
390 gBenchmark->Start("EMCALDigitizer");
391
88cb7938 392 if (fManager)
393 fInput = fManager->GetNinputs() ;
814ad4bf 394
88cb7938 395 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
814ad4bf 396
88cb7938 397 Int_t nevents = gime->MaxEvent() ;;
05a92d59 398
814ad4bf 399 Int_t ievent ;
400
401 for(ievent = 0; ievent < nevents; ievent++){
402
88cb7938 403 gime->Event(ievent,"S") ;
05a92d59 404
814ad4bf 405 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 406
814ad4bf 407 WriteDigits(ievent) ;
88cb7938 408
61e0abb5 409 if(strstr(option,"deb"))
410 PrintDigits(option);
88cb7938 411
814ad4bf 412 //increment the total number of Digits per run
413 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
61e0abb5 414 }
814ad4bf 415
61e0abb5 416 if(strstr(option,"tim")){
417 gBenchmark->Stop("EMCALDigitizer");
9859bfc0 418 Info("Exec", "took %f seconds for Digitizing %f seconds per event",
419 gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nevents ) ;
88cb7938 420 }
61e0abb5 421}
422
05a92d59 423//____________________________________________________________________________
424Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
88cb7938 425{
426 // Returns the shortest time among all time ticks
427
05a92d59 428 ticks->Sort() ; //Sort in accordance with times of ticks
429 TIter it(ticks) ;
430 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
431 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
432
433 AliEMCALTick * t ;
434 while((t=(AliEMCALTick*) it.Next())){
435 if(t->GetTime() < time) //This tick starts before crossing
436 *ctick+=*t ;
437 else
438 return time ;
439
440 time = ctick->CrossingTime(fTimeThreshold) ;
441 }
442 return time ;
443}
444
445//____________________________________________________________________________
446Bool_t AliEMCALDigitizer::Init()
447{
448 // Makes all memory allocations
88cb7938 449 fInit = kTRUE ;
450 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;
05a92d59 451 if ( gime == 0 ) {
88cb7938 452 Error("Init", "Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
05a92d59 453 return kFALSE;
454 }
455
88cb7938 456 TString opt("Digits") ;
457 if(gime->VersionExists(opt) ) {
458 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
459 fInit = kFALSE ;
460 }
05a92d59 461
05a92d59 462 // Post Digitizer to the white board
463 gime->PostDigitizer(this) ;
464
88cb7938 465 if(fManager)
466 fInput = fManager->GetNinputs() ;
467 else
468 fInput = 1 ;
469
470 fInputFileNames = new TString[fInput] ;
471 fEventNames = new TString[fInput] ;
472 fInputFileNames[0] = GetTitle() ;
473 fEventNames[0] = fEventFolderName.Data() ;
474 Int_t index ;
475 for (index = 1 ; index < fInput ; index++) {
476 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
477 TString tempo = fManager->GetInputFolderName(index) ;
478 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager
05a92d59 479 }
480
88cb7938 481 //to prevent cleaning of this object while GetEvent is called
482 gime->EmcalLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
483
484 return fInit ;
05a92d59 485}
486
487//____________________________________________________________________________
488void AliEMCALDigitizer::InitParameters()
489{
a9485c37 490 fMeanPhotonElectron = 1250 ; // electrons per GeV
88cb7938 491 fPinNoise = 0.001 ; // noise equivalent GeV (random choice)
492 if (fPinNoise == 0. )
493 Warning("InitParameters", "No noise added\n") ;
a9485c37 494 fDigitThreshold = fPinNoise * 3; //2 sigma
05a92d59 495 fTimeResolution = 0.5e-9 ;
496 fTimeSignalLength = 1.0e-9 ;
05a92d59 497
a9485c37 498 fADCchannelEC = 0.000220; // width of one ADC channel in GeV
499 fADCpedestalEC = 0.005 ; // GeV
500 fNADCEC = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
501
502 fADCchannelHC = 0.000220; // width of one ADC channel in GeV
503 fADCpedestalHC = 0.005 ; // GeV
504 fNADCHC = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
505
506 fADCchannelPRE = 0.0000300; // width of one ADC channel in Pre Shower
507 fADCpedestalPRE = 0.005 ; // GeV
508 fNADCPRE = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC
61e0abb5 509
a9485c37 510 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
05a92d59 511
512}
61e0abb5 513
61e0abb5 514//__________________________________________________________________
88cb7938 515void AliEMCALDigitizer::MixWith(const TString alirunFileName, const TString eventFolderName)
05a92d59 516{
517 // Allows to produce digits by superimposing background and signal event.
61e0abb5 518 // It is assumed, that headers file with SIGNAL events is opened in
05a92d59 519 // the constructor.
520 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
521 // Thus we avoid writing (changing) huge and expensive
61e0abb5 522 // backgound files: all output will be writen into SIGNAL, i.e.
523 // opened in constructor file.
524 //
05a92d59 525 // One can open as many files to mix with as one needs.
526 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
527 // can be mixed.
61e0abb5 528
05a92d59 529 if( strcmp(GetName(), "") == 0 )
61e0abb5 530 Init() ;
814ad4bf 531
05a92d59 532 if(fManager){
9859bfc0 533 Error("MixWith", "Cannot use this method under AliRunDigitizer") ;
61e0abb5 534 return ;
05a92d59 535 }
88cb7938 536 // looking for file which contains AliRun
537 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
538 Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
539 return ;
61e0abb5 540 }
88cb7938 541 // looking for the file which contains SDigits
542 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
543 TString fileName( gime->GetSDigitsFileName() ) ;
544 if ( eventFolderName != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
545 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
546 if ( (gSystem->AccessPathName(fileName)) ) {
547 Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
548 return ;
814ad4bf 549 }
88cb7938 550 // need to increase the arrays
551 TString tempo = fInputFileNames[fInput-1] ;
552 delete [] fInputFileNames ;
553 fInputFileNames = new TString[fInput+1] ;
554 fInputFileNames[fInput-1] = tempo ;
555
556 tempo = fEventNames[fInput-1] ;
557 delete [] fEventNames ;
558 fEventNames = new TString[fInput+1] ;
559 fEventNames[fInput-1] = tempo ;
560
561 fInputFileNames[fInput] = alirunFileName ;
562 fEventNames[fInput] = eventFolderName ;
563 fInput++ ;
564}
565
61e0abb5 566//__________________________________________________________________
88cb7938 567void AliEMCALDigitizer::Print()const
568{
569 // Print Digitizer's parameters
570 Info("Print", "\n------------------- %s -------------", GetName() ) ;
571 if( strcmp(fEventFolderName.Data(), "") != 0 ){
572 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
573
574 Int_t nStreams ;
575 if (fManager)
576 nStreams = GetNInputStreams() ;
577 else
578 nStreams = fInput ;
579
580 Int_t index = 0 ;
581 for (index = 0 ; index < nStreams ; index++) {
582 TString tempo(fEventNames[index]) ;
583 tempo += index ;
584 AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[index], tempo) ;
585 TString fileName( gime->GetSDigitsFileName() ) ;
586 if ( fEventNames[index] != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
587 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
588 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
589 }
590 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;
591 printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
592
593 printf("\nWith following parameters:\n") ;
594
595 printf(" Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise) ;
596 printf(" Threshold in EMC (fDigitThreshold) = %f\n", fDigitThreshold) ;
597 printf("---------------------------------------------------\n") ;
ea5f3389 598 }
599 else
88cb7938 600 Info("Print", "AliEMCALDigitizer not initialized") ;
61e0abb5 601}
814ad4bf 602
61e0abb5 603//__________________________________________________________________
604void AliEMCALDigitizer::PrintDigits(Option_t * option){
605
88cb7938 606 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;
607 TClonesArray * digits = gime->Digits() ;
608
609 Info("PrintDigits", "%d", digits->GetEntriesFast()) ;
610 printf("\nevent %d", gAlice->GetEvNumber()) ;
611 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
612
613 if(strstr(option,"all")){
61e0abb5 614 //loop over digits
615 AliEMCALDigit * digit;
88cb7938 616 printf("\nEMC digits (with primaries):\n") ;
617 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
61e0abb5 618 Int_t index ;
88cb7938 619 for (index = 0 ; index < digits->GetEntries() ; index++) {
620 digit = dynamic_cast<AliEMCALDigit *>(digits->At(index)) ;
621 printf("\n%6d %8d %6.5e %4d %2d : ",
11f9c5ff 622 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
61e0abb5 623 Int_t iprimary;
9859bfc0 624 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 625 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
9859bfc0 626 }
627 }
61e0abb5 628 }
629}
05a92d59 630
631//__________________________________________________________________
632Float_t AliEMCALDigitizer::TimeOfNoise(void)
633{ // Calculates the time signal generated by noise
634 //to be rewritten, now returns just big number
635 return 1. ;
636
637}
638
88cb7938 639//__________________________________________________________________
640void AliEMCALDigitizer::Unload()
641{
642
643 Int_t i ;
644 for(i = 1 ; i < fInput ; i++){
645 TString tempo(fEventNames[i]) ;
646 tempo += i ;
647 AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[i], tempo) ;
648 gime->EmcalLoader()->UnloadSDigits() ;
649 }
650
651 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;
652 gime->EmcalLoader()->UnloadDigits() ;
653}
654
814ad4bf 655//_________________________________________________________________________________________
656void AliEMCALDigitizer::WriteDigits(Int_t event)
657{
61e0abb5 658
814ad4bf 659 // Makes TreeD in the output file.
660 // Check if branch already exists:
661 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
662 // already existing branches.
663 // else creates branch with Digits, named "EMCAL", title "...",
664 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
665 // and names of files, from which digits are made.
61e0abb5 666
88cb7938 667 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;
668 const TClonesArray * digits = gime->Digits() ;
669 TTree * treeD = gime->TreeD();
670
671 // -- create Digits branch
672 Int_t bufferSize = 32000 ;
673 TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
674 digitsBranch->SetTitle(fEventFolderName);
675 digitsBranch->Fill() ;
676
677 gime->WriteDigits("OVERWRITE");
678 gime->WriteDigitizer("OVERWRITE");
679
680 Unload() ;
681
814ad4bf 682}
61e0abb5 683