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