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