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