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