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