Control-M removed
[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
ffa6d63b 55//_________________________________________________________________________________
61e0abb5 56
57// --- ROOT system ---
58#include "TFile.h"
59#include "TTree.h"
60#include "TSystem.h"
61#include "TROOT.h"
62#include "TFolder.h"
63#include "TObjString.h"
64#include "TBenchmark.h"
65// --- Standard library ---
66#include <iomanip.h>
67
68// --- AliRoot header files ---
69
70#include "AliRun.h"
71#include "AliEMCALDigit.h"
72#include "AliEMCALHit.h"
814ad4bf 73#include "AliEMCALTick.h"
61e0abb5 74#include "AliEMCALv1.h"
75#include "AliEMCALDigitizer.h"
76#include "AliEMCALSDigitizer.h"
77#include "AliEMCALGeometry.h"
814ad4bf 78#include "AliEMCALGetter.h"
79#include "AliRunDigitizer.h"
61e0abb5 80ClassImp(AliEMCALDigitizer)
81
82
83//____________________________________________________________________________
814ad4bf 84 AliEMCALDigitizer::AliEMCALDigitizer()
61e0abb5 85{
86 // ctor
87
88 fSDigitizer = 0 ;
556fa06b 89 fNinputs = 0 ;
556fa06b 90 fPinNoise = 0.0 ;
556fa06b 91 fTowerDigitThreshold = 0.0 ;
556fa06b 92 fTimeResolution = 0. ;
556fa06b 93 fTimeSignalLength = 0. ;
556fa06b 94 fPreShowerDigitThreshold = 0. ;
556fa06b 95 fADCchannelTower = 0.0; // width of one ADC channel in GeV
556fa06b 96 fADCpedestalTower = 0. ; // pedestal of ADC
556fa06b 97 fNADCTower = 0; // number of channels in Tower ADC
98
556fa06b 99 fADCchannelPreSho = 0.0; // width of one ADC channel in Pre Shower
556fa06b 100 fADCpedestalPreSho = 0.0 ; // pedestal of ADC
556fa06b 101 fNADCPreSho = 0; // number of channels in Pre Shower ADC
556fa06b 102 fTimeThreshold = 0.0; //Means 1 MeV in terms of SDigits amplitude
814ad4bf 103 fManager = 0 ;
61e0abb5 104
61e0abb5 105
61e0abb5 106
61e0abb5 107}
61e0abb5 108//____________________________________________________________________________
814ad4bf 109Bool_t AliEMCALDigitizer::Init()
61e0abb5 110{
814ad4bf 111 // Makes all memory allocations
112
113 fSDigitizer = 0 ;
114 fNinputs = 1 ;
d968cee0 115 fPinNoise = 0.00001 ;
116 fTowerDigitThreshold = 0.001 ;
814ad4bf 117 fTimeResolution = 0.5e-9 ;
118 fTimeSignalLength = 1.0e-9 ;
d968cee0 119 fPreShowerDigitThreshold = fTowerDigitThreshold/25. ;
814ad4bf 120 fInitialized = kFALSE ;
b66c1acf 121 fADCchannelTower = 0.000220; // width of one ADC channel in GeV
d968cee0 122 fADCpedestalTower = 0.005 ; // GeV
814ad4bf 123 fNADCTower = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC
124
556fa06b 125 fADCchannelPreSho = 0.0000300; // width of one ADC channel in Pre Shower
814ad4bf 126 fADCpedestalPreSho = 0.005 ; //
d968cee0 127 fNADCPreSho = (Int_t) TMath::Power(2,12); // number of channels in Pre ShowerADC
814ad4bf 128
e41b8233 129 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
130
556fa06b 131
132
814ad4bf 133if(fManager)
134 SetTitle("aliroot") ;
135 else if (strcmp(GetTitle(),"")==0)
136 SetTitle("galice.root") ;
137
138 if( strcmp(GetName(), "") == 0 )
139 SetName("Default") ;
61e0abb5 140
814ad4bf 141 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(), GetName(), "update") ;
142 if ( gime == 0 ) {
143 cerr << "ERROR: AliEMCALDigitizer::Init -> Could not obtain the Getter object !" << endl ;
144 return kFALSE;
145 }
61e0abb5 146
814ad4bf 147 //const AliEMCALGeometry * geom = gime->EMCALGeometry() ;
148 //fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
61e0abb5 149
814ad4bf 150 // Post Digits to the white board
151 gime->PostDigits(GetName() ) ;
61e0abb5 152
814ad4bf 153 // Post Digitizer to the white board
154 gime->PostDigitizer(this) ;
61e0abb5 155
814ad4bf 156 //Mark that we will use current header file
157 if(!fManager){
158 gime->PostSDigits(GetName(),GetTitle()) ;
159 gime->PostSDigitizer(GetName(),GetTitle()) ;
160 }
161 return kTRUE ;
61e0abb5 162
814ad4bf 163
61e0abb5 164
814ad4bf 165}
166
167//____________________________________________________________________________
168AliEMCALDigitizer::AliEMCALDigitizer(const char *headerFile,const char *name)
169{
170 SetName(name) ;
171 SetTitle(headerFile) ;
172 fManager = 0 ; // We work in the standalong mode
173 Init() ;
61e0abb5 174
814ad4bf 175
61e0abb5 176
814ad4bf 177}
178//____________________________________________________________________________
179AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * ard):AliDigitizer(ard)
180{
181 // ctor
182 SetName(""); //Will call init in the digitizing
183 SetTitle("aliroot") ;
61e0abb5 184}
185
186//____________________________________________________________________________
187 AliEMCALDigitizer::~AliEMCALDigitizer()
188{
189 // dtor
190
61e0abb5 191}
192//____________________________________________________________________________
193void AliEMCALDigitizer::Reset() {
194 //sets current event number to the first simulated event
814ad4bf 195if( strcmp(GetName(), "") == 0 )
196 Init() ;
61e0abb5 197
814ad4bf 198 // Int_t inputs ;
199 // for(inputs = 0; inputs < fNinputs ;inputs++)
200 // fIevent->AddAt(-1, inputs ) ;
61e0abb5 201
202}
203
204//____________________________________________________________________________
814ad4bf 205void AliEMCALDigitizer::Digitize(const Int_t event) {
61e0abb5 206
207 // Makes the digitization of the collected summable digits
208 // for this it first creates the array of all EMCAL modules
209 // filled with noise (different for EMC, CPV and PPSD) and
210 // after that adds contributions from SDigits. This design
211 // helps to avoid scanning over the list of digits to add
212 // contribution of any new SDigit.
213
814ad4bf 214 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
215 TClonesArray * digits = gime->Digits(GetName()) ;
216
217 digits->Clear() ;
61e0abb5 218
814ad4bf 219 const AliEMCALGeometry *geom = gime->EMCALGeometry() ;
61e0abb5 220
61e0abb5 221
222 //Making digits with noise, first EMC
ffa6d63b 223 Int_t nEMC = 2*geom->GetNPhi()*geom->GetNZ();
61e0abb5 224 Int_t absID ;
225 TString name = geom->GetName() ;
61e0abb5 226
814ad4bf 227 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
228 const AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(GetName());
229 if ( !sDigitizer) {
230 cerr << "ERROR: AliEMCALDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ;
231 abort() ;
61e0abb5 232 }
233
814ad4bf 234// loop through the sdigits posted to the White Board and add them to the noise
235 TCollection * folderslist = gime->SDigitsFolder()->GetListOfFolders() ;
236 TIter next(folderslist) ;
237 TFolder * folder = 0 ;
238 TClonesArray * sdigits = 0 ;
239 Int_t input = 0 ;
240 TObjArray * sdigArray = new TObjArray(2) ;
241 while ( (folder = (TFolder*)next()) )
242 if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
243 cout << "INFO: AliEMCALDigitizer::Digitize -> Adding SDigits "
244 << GetName() << " from " << folder->GetName() << endl ;
245 sdigArray->AddAt(sdigits, input) ;
246 input++ ;
247 }
61e0abb5 248
d968cee0 249 //Find the first tower with signal
814ad4bf 250 Int_t nextSig = 200000 ;
251 Int_t i;
252 for(i=0; i<input; i++){
253 sdigits = (TClonesArray *)sdigArray->At(i) ;
254 if ( !sdigits->GetEntriesFast() )
255 continue ;
256 Int_t curNext = ((AliEMCALDigit *)sdigits->At(0))->GetId() ;
257 if(curNext < nextSig)
258 nextSig = curNext ;
259 }
61e0abb5 260
814ad4bf 261 TArrayI index(input) ;
262 index.Reset() ; //Set all indexes to zero
61e0abb5 263
814ad4bf 264 AliEMCALDigit * digit = 0 ;
265 AliEMCALDigit * curSDigit = 0 ;
ffa6d63b 266
814ad4bf 267 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
ffa6d63b 268
814ad4bf 269 //Put Noise contribution
270 for(absID = 1; absID <= nEMC; absID++){
d968cee0 271 Float_t noise = gRandom->Gaus(0., fPinNoise);
814ad4bf 272 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
273 //look if we have to add signal?
274 if(absID==nextSig){
275 //Add SDigits from all inputs
276 digit = (AliEMCALDigit *) digits->At(absID-1) ;
277
278 ticks->Clear() ;
279 Int_t contrib = 0 ;
280 Float_t a = digit->GetAmp() ;
281 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
282 //Mark the beginnign of the signal
283 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
284 //Mark the end of the ignal
285 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
286
287 // loop over input
288
289 for(i = 0; i< input ; i++){ //loop over (possible) merge sources
290 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
291 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
292 else
293 curSDigit = 0 ;
294 //May be several digits will contribute from the same input
295 while(curSDigit && curSDigit->GetId() == absID){
296 //Shift primary to separate primaries belonging different inputs
297 Int_t primaryoffset ;
298 if(fManager)
299 primaryoffset = fManager->GetMask(i) ;
300 else
301 primaryoffset = i ;
302 curSDigit->ShiftPrimary(primaryoffset) ;
303
304 a = curSDigit->GetAmp() ;
305 b = a /fTimeSignalLength ;
306 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
307 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
308
309 *digit = *digit + *curSDigit ; //add energies
310
311 index[i]++ ;
312 if(((TClonesArray *)sdigArray->At(i))->GetEntriesFast() > index[i] )
313 curSDigit = (AliEMCALDigit*)((TClonesArray *)sdigArray->At(i))->At(index[i]) ;
314 else
315 curSDigit = 0 ;
e41b8233 316 }
317 }
556fa06b 318
814ad4bf 319//calculate and set time
320 Float_t time = FrontEdgeTime(ticks) ;
321 digit->SetTime(time) ;
322
323 //Find next signal module
324 nextSig = 200000 ;
325 for(i=0; i<input; i++){
326 sdigits = ((TClonesArray *)sdigArray->At(i)) ;
327 Int_t curNext = nextSig ;
328 if(sdigits->GetEntriesFast() > index[i] ){
329 curNext = ((AliEMCALDigit *) sdigits->At(index[i]))->GetId() ;
330
331 }
332 if(curNext < nextSig) nextSig = curNext ;
333 }
334 }
335 }
336
337 ticks->Delete() ;
338 delete ticks ;
61e0abb5 339
61e0abb5 340
61e0abb5 341
61e0abb5 342
814ad4bf 343 //remove digits below thresholds
344 for(absID = 0; absID < nEMC/2 ; absID++){
d968cee0 345 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fTowerDigitThreshold)
814ad4bf 346 digits->RemoveAt(absID) ;
347 else
348 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
349 }
61e0abb5 350
814ad4bf 351 for(absID = nEMC/2; absID < nEMC ; absID++){
352 if(sDigitizer->Calibrate(((AliEMCALDigit*)digits->At(absID))->GetAmp()) < fPreShowerDigitThreshold)
353 digits->RemoveAt(absID) ;
354 else
355 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
61e0abb5 356 }
357
814ad4bf 358 digits->Compress() ;
61e0abb5 359
814ad4bf 360 Int_t ndigits = digits->GetEntriesFast() ;
61e0abb5 361
814ad4bf 362 digits->Expand(ndigits) ;
61e0abb5 363
61e0abb5 364
814ad4bf 365 //Set indexes in list of digits
366 //Int_t i ;
ec803232 367 for (i = 0 ; i < ndigits ; i++) {
814ad4bf 368 AliEMCALDigit * digit = (AliEMCALDigit *) digits->At(i) ;
369 digit->SetIndexInList(i) ;
370 Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
371 digit->SetAmp(DigitizeEnergy(energy,digit->GetId()) ) ;
61e0abb5 372 }
814ad4bf 373}
61e0abb5 374
814ad4bf 375//____________________________________________________________________________
61e0abb5 376
814ad4bf 377Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
378{
379 Int_t channel = -999;
380 Int_t nphi = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNPhi() ;
381 Int_t nz = AliEMCALGetter::GetInstance()->EMCALGeometry()->GetNZ() ;
382
ec803232 383 if(absId <= nphi*nz){ //digitize as tower
384 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalTower)/fADCchannelTower )) ;
385 if(channel > fNADCTower )
386 channel = fNADCTower ;
387 } else {
388 channel = static_cast<Int_t>(TMath::Ceil( (energy + fADCpedestalPreSho)/fADCchannelPreSho )) ;
389 if(channel > fNADCPreSho )
390 channel = fNADCPreSho ;
391 }
814ad4bf 392
393 return channel ;
61e0abb5 394}
395
396//____________________________________________________________________________
397void AliEMCALDigitizer::Exec(Option_t *option) {
398 // Managing method
814ad4bf 399if(strcmp(GetName(), "") == 0 )
400 Init() ;
401
402 if (strstr(option,"print")) {
403 Print("");
404 return ;
405 }
406
61e0abb5 407 if(strstr(option,"tim"))
408 gBenchmark->Start("EMCALDigitizer");
409
814ad4bf 410 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
411
412 Int_t nevents ;
413
414 TTree * treeD ;
415
416 if(fManager){
417 treeD = fManager->GetTreeD() ;
418 nevents = 1 ; // Will process only one event
419 }
420 else {
421 gAlice->GetEvent(0) ;
422 nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
423 treeD=gAlice->TreeD() ;
424 }
425 if(treeD == 0 ){
426 cerr << " AliEMCALDigitizer :: Can not find TreeD " << endl ;
427 return ;
428 }
429
430 //Check, if this branch already exits
431 TObjArray * lob = (TObjArray*)treeD->GetListOfBranches() ;
432 TIter next(lob) ;
433 TBranch * branch = 0 ;
434 Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ;
61e0abb5 435
814ad4bf 436 while ( (branch = (TBranch*)next()) && (!emcalfound || !digitizerfound) ) {
437 if ( (strcmp(branch->GetName(), "EMCAL")==0) &&
438 (strcmp(branch->GetTitle(), GetName())==0) )
439 emcalfound = kTRUE ;
440
441 else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) &&
442 (strcmp(branch->GetTitle(), GetName())==0) )
443 digitizerfound = kTRUE ;
444 }
445
446 if ( emcalfound ) {
447 cerr << "WARNING: AliEMCALDigitizer -> Digits branch with name " << GetName()
448 << " already exits" << endl ;
449 return ;
450 }
451 if ( digitizerfound ) {
452 cerr << "WARNING: AliEMCALDigitizer -> Digitizer branch with name " << GetName()
453 << " already exits" << endl ;
454 return ;
455 }
456
457 Int_t ievent ;
458
459 for(ievent = 0; ievent < nevents; ievent++){
460
461 if(fManager){
462 Int_t input ;
463 for(input = 0 ; input < fManager->GetNinputs(); input ++){
464 TTree * treeS = fManager->GetInputTreeS(input) ;
465 if(!treeS){
466 cerr << "AliEMCALDigitizer -> No Input " << endl ;
467 return ;
468 }
469 gime->ReadTreeS(treeS,input) ;
470 }
471 }
472 else
473 gime->Event(ievent,"S") ;
61e0abb5 474
814ad4bf 475 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
61e0abb5 476
814ad4bf 477 WriteDigits(ievent) ;
61e0abb5 478
479 if(strstr(option,"deb"))
480 PrintDigits(option);
814ad4bf 481
482 //increment the total number of Digits per run
483 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
61e0abb5 484 }
814ad4bf 485
61e0abb5 486 if(strstr(option,"tim")){
487 gBenchmark->Stop("EMCALDigitizer");
488 cout << "AliEMCALDigitizer:" << endl ;
814ad4bf 489 cout << " took " << gBenchmark->GetCpuTime("EMCALDigitizer") << " seconds for Digitizing "
490 << gBenchmark->GetCpuTime("EMCALDigitizer")/nevents << " seconds per event " << endl ;
61e0abb5 491 cout << endl ;
492 }
493
494}
495
61e0abb5 496
61e0abb5 497
61e0abb5 498//__________________________________________________________________
814ad4bf 499void AliEMCALDigitizer::MixWith(char* headerFile){
61e0abb5 500 // Alows produce digits by superimposing background and signal event.
501 // It is assumed, that headers file with SIGNAL events is opened in
502 // constructor, and now we set the BACKGROUND event, with which we
503 // will mix. Thus we avoid writing (changing) huge and expencive
504 // backgound files: all output will be writen into SIGNAL, i.e.
505 // opened in constructor file.
506 //
507 // One can open as many files to mix with as one wants.
508
814ad4bf 509if( strcmp(GetName(), "") == 0 )
61e0abb5 510 Init() ;
814ad4bf 511
512 if(fManager){
513 cout << "Can not use this method under AliRunDigitizer " << endl ;
61e0abb5 514 return ;
814ad4bf 515 } // check if the specified SDigits do not already exist on the White Board:
516 // //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
517
518 TString path = "Folders/RunMC/Event/Data/EMCAL/SDigits" ;
519 path += headerFile ;
520 path += "/" ;
521 path += GetName() ;
522 if ( gROOT->FindObjectAny(path.Data()) ) {
523 cerr << "WARNING: AliEMCALDigitizer::MixWith -> Entry already exists, do not add" << endl ;
524 return;
61e0abb5 525 }
814ad4bf 526
527 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
528 gime->PostSDigits(GetName(),headerFile) ;
61e0abb5 529
814ad4bf 530 // check if the requested file is already open or exist and if SDigits Branch exist
531 TFile * file = (TFile*)gROOT->FindObject(headerFile);
532 if ( !file ) {
533 file = new TFile(headerFile, "READ") ;
534 if (!file) {
535 cerr << "ERROR: AliEMCALDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ;
536 return ;
537 }
538 }
61e0abb5 539
540}
814ad4bf 541
61e0abb5 542//__________________________________________________________________
543void AliEMCALDigitizer::Print(Option_t* option)const {
814ad4bf 544 if( strcmp(GetName(), "") != 0) {
61e0abb5 545
546 cout << "------------------- "<< GetName() << " -------------" << endl ;
547 cout << "Digitizing sDigits from file(s): " <<endl ;
61e0abb5 548
814ad4bf 549 TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("Folders/RunMC/Event/Data/EMCAL/SDigits"))->GetListOfFolders() ;
550 TIter next(folderslist) ;
551 TFolder * folder = 0 ;
552 while ( (folder = (TFolder*)next()) )
553 if ( folder->FindObject(GetName()) )
554 {
555 cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ;
556 cout << endl ;
557 cout << "Writing digits to " << GetTitle() << endl ;
558
559 cout << endl ;
560 cout << "With following parameters: " << endl ;
561 cout << " Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
d968cee0 562 cout << " Threshold in EMC (fTowerDigitThreshold) = " << fTowerDigitThreshold << endl;
814ad4bf 563 cout << " Threshold in PreShower (fPreShowerDigitThreshold) = " << fPreShowerDigitThreshold << endl ; ;
564 cout << "---------------------------------------------------" << endl ;
565 }
566 else
567 cout << "AliEMCALDigitizer not initialized " << endl ;
568 }
61e0abb5 569}
814ad4bf 570
e41b8233 571//__________________________________________________________________
572void AliEMCALDigitizer::PrintDigits(Option_t * option){
61e0abb5 573
814ad4bf 574 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
575 TClonesArray * fDigits = gime->Digits() ;
576
61e0abb5 577 cout << "AliEMCALDigitiser:"<< endl ;
578 cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
579 cout << endl ;
580 if(strstr(option,"all")){
581
582 //loop over digits
583 AliEMCALDigit * digit;
584 cout << "Digit Id " << " Amplitude " << " Index " << " Nprim " << " Primaries list " << endl;
585 Int_t index ;
586 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
587 digit = (AliEMCALDigit * ) fDigits->At(index) ;
588 cout << setw(8) << digit->GetId() << " " << setw(3) << digit->GetAmp() << " "
589 << setw(6) << digit->GetIndexInList() << " "
590 << setw(5) << digit->GetNprimary() <<" ";
591
592 Int_t iprimary;
593 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
594 cout << setw(5) << digit->GetPrimary(iprimary+1) << " ";
595 cout << endl;
596 }
597
598 }
599}
814ad4bf 600//_________________________________________________________________________________________
601void AliEMCALDigitizer::WriteDigits(Int_t event)
602{
61e0abb5 603
814ad4bf 604 // Makes TreeD in the output file.
605 // Check if branch already exists:
606 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
607 // already existing branches.
608 // else creates branch with Digits, named "EMCAL", title "...",
609 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
610 // and names of files, from which digits are made.
61e0abb5 611
814ad4bf 612 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
613 const TClonesArray * digits = gime->Digits(GetName()) ;
614 TTree * treeD ;
615
616 if(fManager)
617 treeD = fManager->GetTreeD() ;
618 else
619 treeD = gAlice->TreeD();
61e0abb5 620
814ad4bf 621 // create new branches
622 // -- generate file name if necessary
623 char * file =0;
624 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
625 file = new char[strlen(gAlice->GetBaseFile())+20] ;
626 sprintf(file,"%s/EMCAL.Digits.root",gAlice->GetBaseFile()) ;
627 }
628
629 TDirectory *cwd = gDirectory;
630 // -- create Digits branch
631 Int_t bufferSize = 32000 ;
632 TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
633 digitsBranch->SetTitle(GetName());
634 if (file) {
635 digitsBranch->SetFile(file);
636 TIter next( digitsBranch->GetListOfBranches());
637 TBranch * sbr ;
638 while ((sbr=(TBranch*)next())) {
639 sbr->SetFile(file);
640 }
641 cwd->cd();
642 }
643
644 // -- Create Digitizer branch
645 Int_t splitlevel = 0 ;
646 AliEMCALDigitizer * d = gime->Digitizer(GetName()) ;
647 TBranch * digitizerBranch = treeD->Branch("AliEMCALDigitizer", "AliEMCALDigitizer", &d,bufferSize,splitlevel);
648 digitizerBranch->SetTitle(GetName());
649 if (file) {
650 digitizerBranch->SetFile(file);
651 TIter next( digitizerBranch->GetListOfBranches());
652 TBranch * sbr;
653 while ((sbr=(TBranch*)next())) {
654 sbr->SetFile(file);
655 }
656 cwd->cd();
657 }
658
659 digitsBranch->Fill() ;
660 digitizerBranch->Fill() ;
661
662 treeD->Write(0,kOverwrite) ;
663
664}
665//____________________________________________________________________________
666Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
667{ //
668 ticks->Sort() ; //Sort in accordance with times of ticks
669 TIter it(ticks) ;
670 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
671 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
672
673 AliEMCALTick * t ;
674 while((t=(AliEMCALTick*) it.Next())){
675 if(t->GetTime() < time) //This tick starts before crossing
676 *ctick+=*t ;
677 else
678 return time ;
679
680 time = ctick->CrossingTime(fTimeThreshold) ;
681 }
682 return time ;
683}
684//____________________________________________________________________________
685Float_t AliEMCALDigitizer::TimeOfNoise(void)
686{ // Calculates the time signal generated by noise
687 //to be rewritten, now returns just big number
688 return 1. ;
689
690}
691//____________________________________________________________________________
692void AliEMCALDigitizer::SetSDigitsBranch(const char* title)
693{
694 // we set title (comment) of the SDigits branch in the first! header file
695 if( strcmp(GetName(), "") == 0 )
696 Init() ;
61e0abb5 697
814ad4bf 698 AliEMCALGetter::GetInstance()->SDigits()->SetName(title) ;
61e0abb5 699}