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