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