]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALDigitizer.cxx
Introduced a new time information (fastest track making the digit) to be used to...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
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 //_________________________________________________________________________
19 // 
20 //////////////////////////////////////////////////////////////////////////////
21 // Class performs digitization of Summable digits 
22 //  
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
51 ////////////////////////////////////////////////////////////////////////////////////
52 //
53 //*-- Author: Sahal Yacoob (LBL)
54 // based on : AliEMCALDigitizer
55 // Modif: 
56 //  August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
57 //                           of new  IO (à la PHOS)
58 ///_________________________________________________________________________________
59
60 // --- ROOT system ---
61 #include "TTree.h"
62 #include "TSystem.h"
63 #include "TBenchmark.h"
64
65 // --- Standard library ---
66
67 // --- AliRoot header files ---
68 #include "AliRunDigitizer.h"
69 #include "AliEMCALDigit.h"
70 #include "AliEMCAL.h"
71 #include "AliEMCALGetter.h"
72 #include "AliEMCALDigitizer.h"
73 #include "AliEMCALSDigitizer.h"
74 #include "AliEMCALGeometry.h"
75 #include "AliEMCALTick.h"
76
77 ClassImp(AliEMCALDigitizer)
78
79
80 //____________________________________________________________________________ 
81   AliEMCALDigitizer::AliEMCALDigitizer():AliDigitizer("",""),
82                                        fInput(0),
83                                        fInputFileNames(0x0),
84                                        fEventNames(0x0)
85 {
86   // ctor
87   InitParameters() ; 
88   fDefaultInit = kTRUE ; 
89   fManager = 0 ;                     // We work in the standalong mode
90   fEventFolderName = "" ; 
91 }
92
93 //____________________________________________________________________________ 
94 AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolderName):
95   AliDigitizer("EMCAL"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
96   fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
97 {
98   // ctor
99
100   InitParameters() ; 
101   Init() ;
102   fDefaultInit = kFALSE ; 
103   fManager = 0 ;                     // We work in the standalong mode
104 }
105
106 //____________________________________________________________________________ 
107 AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d) : AliDigitizer(d)
108 {
109   // copyy ctor 
110
111   SetName(d.GetName()) ; 
112   SetTitle(d.GetTitle()) ; 
113   fDigitThreshold = d.fDigitThreshold ; 
114   fMeanPhotonElectron = d.fMeanPhotonElectron ; 
115   fPedestal           = d.fPedestal ; 
116   fSlope              = d.fSlope ; 
117   fPinNoise           = d.fPinNoise ; 
118   fTimeResolution     = d.fTimeResolution ; 
119   fTimeThreshold      = d.fTimeThreshold ; 
120   fTimeSignalLength   = d.fTimeSignalLength ; 
121   fADCchannelEC       = d.fADCchannelEC ; 
122   fADCpedestalEC      = d.fADCpedestalEC ; 
123   fNADCEC             = d.fNADCEC ;
124   fEventFolderName    = d.fEventFolderName;
125  }
126
127 //____________________________________________________________________________ 
128 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd):
129  AliDigitizer(rd,"EMCAL"+AliConfig::Instance()->GetDigitizerTaskName()),
130  fEventFolderName(0)
131 {
132   // ctor Init() is called by RunDigitizer
133   fManager = rd ; 
134   fEventFolderName = fManager->GetInputFolderName(0) ;
135   SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
136   InitParameters() ; 
137   fDefaultInit = kFALSE ; 
138 }
139
140 //____________________________________________________________________________ 
141   AliEMCALDigitizer::~AliEMCALDigitizer()
142 {
143   AliEMCALGetter * gime =AliEMCALGetter::Instance(GetTitle(),fEventFolderName);
144   gime->EmcalLoader()->CleanDigitizer();
145
146 }
147
148 //____________________________________________________________________________
149 void AliEMCALDigitizer::Digitize(Int_t event) 
150
151
152   // Makes the digitization of the collected summable digits
153   // for this it first creates the array of all EMCAL modules
154   // filled with noise (different for EMC, CPV and PPSD) and
155   // after that adds contributions from SDigits. This design 
156   // helps to avoid scanning over the list of digits to add 
157   // contribution of any new SDigit.
158
159   AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
160   Int_t ReadEvent = event ; 
161   if (fManager) 
162     ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ; 
163   Info("Digitize", "Adding event %d from input stream 0 %s %s", ReadEvent, GetTitle(), fEventFolderName.Data()) ; 
164   gime->Event(ReadEvent, "S") ;
165   TClonesArray * digits = gime->Digits() ; 
166   digits->Clear() ;
167
168   const AliEMCALGeometry *geom = gime->EMCALGeometry() ; 
169
170   Int_t nEMC = geom->GetNPhi()*geom->GetNZ(); //max number of digits possible
171   
172   Int_t absID ;
173
174   digits->Expand(nEMC) ;
175
176   // get first the sdigitizer from the tasks list (must have same name as the digitizer)
177   if ( !gime->SDigitizer() ) 
178     gime->LoadSDigitizer();
179   AliEMCALSDigitizer * sDigitizer = gime->SDigitizer(); 
180   
181   if ( !sDigitizer )
182     Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ; 
183
184   //take all the inputs to add together and load the SDigits
185   TObjArray * sdigArray = new TObjArray(fInput) ;
186   sdigArray->AddAt(gime->SDigits(), 0) ;
187   Int_t i ;
188   for(i = 1 ; i < fInput ; i++){
189     TString tempo(fEventNames[i]) ; 
190     tempo += i ;
191     AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[i], tempo) ; 
192     if (fManager) 
193       ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ; 
194     Info("Digitize", "Adding event %d from input stream %d %s %s", ReadEvent, i, fInputFileNames[i].Data(), tempo.Data()) ; 
195     gime->Event(ReadEvent,"S");
196     sdigArray->AddAt(gime->SDigits(), i) ;
197   }
198   
199   //Find the first tower with signal
200   Int_t nextSig = nEMC + 1 ; 
201   TClonesArray * sdigits ;  
202   for(i = 0 ; i < fInput ; i++){
203     sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
204     if ( !sdigits->GetEntriesFast() )
205       continue ; 
206     Int_t curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(0))->GetId() ;
207      if(curNext < nextSig) 
208        nextSig = curNext ;
209   }
210
211   TArrayI index(fInput) ;
212   index.Reset() ;  //Set all indexes to zero
213
214   AliEMCALDigit * digit ;
215   AliEMCALDigit * curSDigit ;
216
217   TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
218
219   //Put Noise contribution
220   for(absID = 1; absID <= nEMC; absID++){
221     Float_t amp = 0 ;
222     // amplitude set to zero, noise will be added later
223     new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID, 0, TimeOfNoise() ) ;
224     //look if we have to add signal?
225     digit = dynamic_cast<AliEMCALDigit *>(digits->At(absID-1)) ;
226     
227     if(absID==nextSig){
228       //Add SDigits from all inputs    
229       ticks->Clear() ;
230       Int_t contrib = 0 ;
231       Float_t a = digit->GetAmp() ;
232       Float_t b = TMath::Abs( a /fTimeSignalLength) ;
233       //Mark the beginning of the signal
234       new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);  
235       //Mark the end of the signal     
236       new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
237       
238       // loop over input
239       for(i = 0; i< fInput ; i++){  //loop over (possible) merge sources
240         if(dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
241           curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;      
242         else
243           curSDigit = 0 ;
244         //May be several digits will contribute from the same input
245         while(curSDigit && (curSDigit->GetId() == absID)){         
246           //Shift primary to separate primaries belonging different inputs
247           Int_t primaryoffset ;
248           if(fManager)
249             primaryoffset = fManager->GetMask(i) ; 
250           else
251             primaryoffset = i ;
252           curSDigit->ShiftPrimary(primaryoffset) ;
253           
254           a = curSDigit->GetAmp() ;
255           b = a /fTimeSignalLength ;
256           new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);  
257           new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b); 
258
259           *digit = *digit + *curSDigit ;  //add energies
260
261           index[i]++ ;
262           if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
263             curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;            
264           else
265             curSDigit = 0 ;
266         }
267       }
268       // add fluctuations for photo-electron creation
269       amp = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
270       amp *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
271   
272       //calculate and set time
273       Float_t time = FrontEdgeTime(ticks) ;
274       digit->SetTime(time) ;
275
276       //Find next signal module
277       nextSig = nEMC + 1 ;
278       for(i = 0 ; i < fInput ; i++){
279         sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
280         Int_t curNext = nextSig ;
281         if(sdigits->GetEntriesFast() > index[i] ){
282           curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]))->GetId() ;       
283         }
284         if(curNext < nextSig) nextSig = curNext ;
285       }
286     }
287     // add the noise now
288     amp += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
289     digit->SetAmp(sDigitizer->Digitize(amp)) ;  
290   }
291   
292   ticks->Delete() ;
293   delete ticks ;
294
295   delete sdigArray ; //We should not delete its contents
296
297   //remove digits below thresholds
298   for(i = 0 ; i < nEMC ; i++){
299     digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
300     Float_t threshold = fDigitThreshold ; 
301     if(sDigitizer->Calibrate( digit->GetAmp() ) < threshold)
302       digits->RemoveAt(i) ;
303     else 
304       digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
305   }
306   
307   digits->Compress() ;  
308   
309   Int_t ndigits = digits->GetEntriesFast() ; 
310   digits->Expand(ndigits) ;
311   
312   //Set indexes in list of digits
313   for (i = 0 ; i < ndigits ; i++) { 
314     digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ; 
315     digit->SetIndexInList(i) ; 
316     Float_t energy = sDigitizer->Calibrate(digit->GetAmp()) ;
317     digit->SetAmp(DigitizeEnergy(energy) ) ;
318   }
319 }
320
321 //____________________________________________________________________________
322
323 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy)
324
325   Int_t channel = -999; 
326   channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC ))  ;
327   if(channel > fNADCEC ) 
328     channel =  fNADCEC ; 
329   return channel ;
330 }
331
332 //____________________________________________________________________________
333 void AliEMCALDigitizer::Exec(Option_t *option) 
334
335   // Steering method to process digitization for events
336   // in the range from fFirstEvent to fLastEvent.
337   // This range is optionally set by SetEventRange().
338   // if fLastEvent=-1, then process events until the end.
339   // by default fLastEvent = fFirstEvent (process only one event)
340
341   if (!fInit) { // to prevent overwrite existing file
342     Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
343     return ;
344   } 
345
346   if (strstr(option,"print")) {
347     Print();
348     return ; 
349   }
350   
351   if(strstr(option,"tim"))
352     gBenchmark->Start("EMCALDigitizer");
353   
354   AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle()) ;
355    
356   if (fLastEvent == -1) 
357     fLastEvent = gime->MaxEvent() - 1 ;
358   else if (fManager) 
359     fLastEvent = fFirstEvent ; 
360
361   Int_t nEvents   = fLastEvent - fFirstEvent + 1;
362   
363   Int_t ievent ;
364
365   for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
366   
367     gime->Event(ievent,"S") ; 
368
369     Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
370
371     WriteDigits() ;
372
373     if(strstr(option,"deb"))
374       PrintDigits(option);
375
376     //increment the total number of Digits per run 
377     fDigitsInRun += gime->Digits()->GetEntriesFast() ;  
378   }
379   
380   if(strstr(option,"tim")){
381     gBenchmark->Stop("EMCALDigitizer");
382     printf("Exec: took %f seconds for Digitizing %f seconds per event", 
383          gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nEvents ) ;
384   } 
385 }
386
387 //____________________________________________________________________________ 
388 Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks) 
389
390   //  Returns the shortest time among all time ticks
391
392   ticks->Sort() ; //Sort in accordance with times of ticks
393   TIter it(ticks) ;
394   AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
395   Float_t time = ctick->CrossingTime(fTimeThreshold) ;    
396   
397   AliEMCALTick * t ;  
398   while((t=(AliEMCALTick*) it.Next())){
399     if(t->GetTime() < time)  //This tick starts before crossing
400       *ctick+=*t ;
401     else
402       return time ;
403     
404     time = ctick->CrossingTime(fTimeThreshold) ;    
405   }
406   return time ;
407 }
408
409 //____________________________________________________________________________ 
410 Bool_t AliEMCALDigitizer::Init()
411 {
412   // Makes all memory allocations
413   fInit = kTRUE ; 
414   AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ;  
415   if ( gime == 0 ) {
416     Error("Init", "Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;   
417     return kFALSE;
418   } 
419   TString opt("Digits") ; 
420   if(gime->VersionExists(opt) ) { 
421     Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
422     fInit = kFALSE ; 
423   }
424
425   // Post Digitizer to the white board
426   gime->PostDigitizer(this) ;
427   
428   fFirstEvent = 0 ; 
429   fLastEvent = fFirstEvent ; 
430   
431   if(fManager)
432     fInput = fManager->GetNinputs() ; 
433   else 
434     fInput           = 1 ;
435
436   fInputFileNames  = new TString[fInput] ; 
437   fEventNames      = new TString[fInput] ; 
438   fInputFileNames[0] = GetTitle() ; 
439   fEventNames[0]     = fEventFolderName.Data() ; 
440   Int_t index ; 
441   for (index = 1 ; index < fInput ; index++) {
442     fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0); 
443     TString tempo = fManager->GetInputFolderName(index) ;
444     fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager 
445   }
446   
447   //to prevent cleaning of this object while GetEvent is called
448   gime->EmcalLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
449   
450   return fInit ;    
451 }
452
453 //____________________________________________________________________________ 
454 void AliEMCALDigitizer::InitParameters()
455 {
456   fMeanPhotonElectron = 18200 ; // electrons per GeV
457   fPinNoise           = 0.003 ; // noise equivalent GeV (random choice)
458   if (fPinNoise == 0. ) 
459     Warning("InitParameters", "No noise added\n") ; 
460   fDigitThreshold     = fPinNoise * 3; //2 sigma
461   fTimeResolution     = 1.0e-9 ;
462   fTimeSignalLength   = 1.0e-9 ;
463
464   fADCchannelEC    = 0.00305;                     // width of one ADC channel in GeV - HG fix so that we see 200 GeV gammas
465   fADCpedestalEC   = 0.005 ;                       // GeV
466   fNADCEC          = (Int_t) TMath::Power(2,16) ;  // number of channels in Tower ADC
467
468   fTimeThreshold      = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
469  
470 }
471
472 //__________________________________________________________________
473 void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
474 {
475   // Allows to produce digits by superimposing background and signal event.
476   // It is assumed, that headers file with SIGNAL events is opened in 
477   // the constructor. 
478   // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed 
479   // Thus we avoid writing (changing) huge and expensive 
480   // backgound files: all output will be writen into SIGNAL, i.e. 
481   // opened in constructor file. 
482   //
483   // One can open as many files to mix with as one needs.
484   // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
485   // can be mixed.
486
487   if( strcmp(GetName(), "") == 0 )
488     Init() ;
489   
490   if(fManager){
491     Error("MixWith", "Cannot use this method under AliRunDigitizer") ;
492     return ;
493   } 
494   // looking for file which contains AliRun
495   if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
496     Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
497     return ; 
498   }
499   // looking for the file which contains SDigits
500   AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
501   TString fileName( gime->GetSDigitsFileName() ) ; 
502     if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
503       fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
504     if ( (gSystem->AccessPathName(fileName)) ) { 
505       Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
506       return ;
507     }
508     // need to increase the arrays
509     TString tempo = fInputFileNames[fInput-1] ; 
510     delete [] fInputFileNames ; 
511     fInputFileNames = new TString[fInput+1] ; 
512     fInputFileNames[fInput-1] = tempo ; 
513  
514     tempo = fEventNames[fInput-1] ; 
515     delete [] fEventNames ; 
516     fEventNames = new TString[fInput+1] ; 
517     fEventNames[fInput-1] = tempo ; 
518
519     fInputFileNames[fInput] = alirunFileName ; 
520     fEventNames[fInput]     = eventFolderName ;
521     fInput++ ;
522 }  
523  
524 //__________________________________________________________________
525 void AliEMCALDigitizer::Print()const 
526 {
527   // Print Digitizer's parameters
528   printf("Print: \n------------------- %s -------------", GetName() ) ; 
529   if( strcmp(fEventFolderName.Data(), "") != 0 ){
530     printf(" Writing Digits to branch with title  %s\n", fEventFolderName.Data()) ;
531     
532     Int_t nStreams ; 
533     if (fManager) 
534       nStreams =  GetNInputStreams() ;
535     else 
536       nStreams = fInput ; 
537     
538     Int_t index = 0 ;  
539     for (index = 0 ; index < nStreams ; index++) {  
540       TString tempo(fEventNames[index]) ; 
541       tempo += index ;
542       AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[index], tempo) ; 
543       TString fileName( gime->GetSDigitsFileName() ) ; 
544       if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
545         fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index]  + ".root" ;
546       printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ; 
547     }
548     AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
549     printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
550     
551     printf("\nWith following parameters:\n") ;
552     
553     printf("    Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise) ;
554     printf("    Threshold  in EMC  (fDigitThreshold) = %f\n", fDigitThreshold)  ;
555     printf("---------------------------------------------------\n")  ;
556   }
557   else
558     printf("Print: AliEMCALDigitizer not initialized") ; 
559 }
560
561 //__________________________________________________________________
562 void AliEMCALDigitizer::PrintDigits(Option_t * option){
563     
564   AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
565   TClonesArray * digits = gime->Digits() ;
566   
567   printf("PrintDigits: %d", digits->GetEntriesFast()) ; 
568   printf("\nevent %d", gAlice->GetEvNumber()) ;
569   printf("\n       Number of entries in Digits list %d", digits->GetEntriesFast() )  ;  
570   
571   if(strstr(option,"all")){  
572     //loop over digits
573     AliEMCALDigit * digit;
574     printf("\nEMC digits (with primaries):\n")  ;
575     printf("\n   Id  Amplitude    Time          Index Nprim: Primaries list \n") ;    
576     Int_t index ;
577     for (index = 0 ; index < digits->GetEntries() ; index++) {
578       digit = dynamic_cast<AliEMCALDigit *>(digits->At(index)) ;
579       printf("\n%6d  %8d    %6.5e %4d      %2d : ",
580               digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;  
581       Int_t iprimary;
582       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
583         printf("%d ",digit->GetPrimary(iprimary+1) ) ; 
584       }
585     }   
586   }
587 }
588
589 //__________________________________________________________________
590 Float_t AliEMCALDigitizer::TimeOfNoise(void)
591 {  
592   // Calculates the time signal generated by noise
593   Info("TimeOfNoise", "Change me") ; 
594   return gRandom->Rndm() * 1.28E-5;
595 }
596
597 //__________________________________________________________________
598 void AliEMCALDigitizer::Unload() 
599 {  
600   // Unloads the SDigits and Digits
601   Int_t i ; 
602   for(i = 1 ; i < fInput ; i++){
603     TString tempo(fEventNames[i]) ; 
604     tempo += i ;
605     AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[i], tempo) ; 
606     gime->EmcalLoader()->UnloadSDigits() ; 
607   }
608   
609   AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
610   gime->EmcalLoader()->UnloadDigits() ; 
611 }
612
613 //_________________________________________________________________________________________
614 void AliEMCALDigitizer::WriteDigits()
615 {
616
617   // Makes TreeD in the output file. 
618   // Check if branch already exists: 
619   //   if yes, exit without writing: ROOT TTree does not support overwriting/updating of 
620   //      already existing branches. 
621   //   else creates branch with Digits, named "EMCAL", title "...",
622   //      and branch "AliEMCALDigitizer", with the same title to keep all the parameters
623   //      and names of files, from which digits are made.
624
625   AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
626   const TClonesArray * digits = gime->Digits() ; 
627   TTree * treeD = gime->TreeD(); 
628
629   // -- create Digits branch
630   Int_t bufferSize = 32000 ;    
631   TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
632   digitsBranch->SetTitle(fEventFolderName);
633   digitsBranch->Fill() ;
634   
635   gime->WriteDigits("OVERWRITE");
636   gime->WriteDigitizer("OVERWRITE");
637
638   Unload() ; 
639
640 }
641