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