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