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