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