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