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