]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSDigitizer.cxx
A lot of changes here:
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigitizer.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 //*-- Author :  Dmitri Peressounko (SUBATECH & Kurchatov Institute) 
20 //////////////////////////////////////////////////////////////////////////////
21 // This TTask performs digitization of Summable digits (in the PHOS case it is just
22 // the sum of contributions from all primary particles into a given cell). 
23 // In addition it performs mixing of summable digits from different events.
24 // The name of the TTask is also the title of the branch that will contain 
25 // the created SDigits
26 // The title of the TTAsk is the name of the file that contains the hits from
27 // which the SDigits are created
28 //
29 // For each event two branches are created in TreeD:
30 //   "PHOS" - list of digits
31 //   "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
32 //
33 // Note, that one can set a title for new digits branch, and repeat digitization with
34 // another set of parameters.
35 //
36 // Use case:
37 // root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
38 // root[1] d->ExecuteTask()             
39 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
40 //                       //Digitizes SDigitis in all events found in file galice.root 
41 //
42 // root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;  
43 //                       // Will read sdigits from galice1.root
44 // root[3] d1->MixWith("galice2.root")       
45 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
46 //                       // Reads another set of sdigits from galice2.root
47 // root[3] d1->MixWith("galice3.root")       
48 //                       // Reads another set of sdigits from galice3.root
49 // root[4] d->ExecuteTask("deb timing")    
50 //                       // Reads SDigits from files galice1.root, galice2.root ....
51 //                       // mixes them and stores produced Digits in file galice1.root          
52 //                       // deb - prints number of produced digits
53 //                       // deb all - prints list of produced digits
54 //                       // timing  - prints time used for digitization
55 //
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"
64 #include "TBenchmark.h"
65 // --- Standard library ---
66 #include <iomanip.h>
67
68 // --- AliRoot header files ---
69
70 #include "AliRun.h"
71 #include "AliPHOSDigit.h"
72 #include "AliPHOS.h"
73 #include "AliPHOSGetter.h"
74 #include "AliPHOSDigitizer.h"
75 #include "AliPHOSSDigitizer.h"
76 #include "AliPHOSGeometry.h"
77
78 ClassImp(AliPHOSDigitizer)
79
80
81 //____________________________________________________________________________ 
82   AliPHOSDigitizer::AliPHOSDigitizer():TTask("","") 
83 {
84   // ctor
85
86   fPinNoise           = 0.01 ;
87   fEMCDigitThreshold  = 0.01 ;
88   fCPVNoise           = 0.01;
89   fCPVDigitThreshold  = 0.09 ;
90   fPPSDNoise          = 0.0000001;
91   fPPSDDigitThreshold = 0.0000002 ;  
92
93 }
94
95 //____________________________________________________________________________ 
96 AliPHOSDigitizer::AliPHOSDigitizer(const char *headerFile,const char * name):
97   TTask(name, headerFile)
98 {
99   // ctor
100    
101   fPinNoise           = 0.01 ;
102   fEMCDigitThreshold  = 0.01 ;
103   fCPVNoise           = 0.01;
104   fCPVDigitThreshold  = 0.09 ;
105   fPPSDNoise          = 0.0000001;
106   fPPSDDigitThreshold = 0.0000002 ;  
107
108   Init() ;
109   
110 }
111
112 //____________________________________________________________________________ 
113   AliPHOSDigitizer::~AliPHOSDigitizer()
114 {
115   // dtor
116
117
118 }
119
120 //____________________________________________________________________________
121 void AliPHOSDigitizer::Digitize(const Int_t event) 
122
123   
124   // Makes the digitization of the collected summable digits.
125   //  It first creates the array of all PHOS modules
126   //  filled with noise (different for EMC, CPV and PPSD) and
127   //  then adds contributions from SDigits. 
128   // This design avoids scanning over the list of digits to add 
129   // contribution to new SDigits only.
130
131   if( strcmp(GetName(), "") == 0 )
132     Init() ;
133
134   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
135   TClonesArray * digits = gime->Digits() ; 
136
137   digits->Clear() ;
138
139   const AliPHOSGeometry *geom = gime->PHOSGeometry() ; 
140
141   //Making digits with noise, first EMC
142   Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
143   
144   Int_t nCPV ;
145   Int_t nPPSD ;
146   Int_t absID ;
147   TString name      =  geom->GetName() ;
148   
149   if ( name == "IHEP" || name == "MIXT" )    
150     nCPV =nEMC + geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*
151       geom->GetNCPVModules()*geom->GetNumberOfCPVLayers() ;
152   else
153     nCPV = nEMC; 
154   
155   if ( name == "GPS2" || name == "MIXT" )    
156     nPPSD =nCPV+2*geom->GetNPPSDModules()*geom->GetNumberOfModulesPhi()*geom->GetNumberOfModulesZ()*
157       geom->GetNumberOfPadsPhi()*geom->GetNumberOfPadsZ() ;
158   else
159     nPPSD = nCPV; 
160
161
162   digits->Expand(nPPSD) ;
163
164
165   // sdigitize random gaussian noise and add it to all cells (EMCA+CPV+PPSD) 
166   // get first the sdigitizer from the tasks list (must have same name as the digitizer)
167   const AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(GetName()); 
168   if ( !sDigitizer) {
169     cerr << "ERROR: AliPHOSDigitizer::Digitize -> SDigitizer with name " << GetName() << " not found " << endl ; 
170     abort() ; 
171   }
172   for(absID = 1; absID <= nEMC; absID++){
173     Float_t noise = gRandom->Gaus(0., fPinNoise) ; 
174     new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
175   }
176   
177   for(absID = nEMC+1; absID <= nCPV; absID++){
178     Float_t noise = gRandom->Gaus(0., fCPVNoise) ; 
179     new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
180   }
181   
182   for(absID = nCPV+1; absID <= nPPSD; absID++){
183     Float_t noise = gRandom->Gaus(0., fPPSDNoise) ; 
184     new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise) ) ;
185   }
186   
187   // loop through the sdigits posted to the White Board and add them to the noise
188   TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ; 
189   TIter next(folderslist) ; 
190   TFolder * folder = 0 ; 
191   TClonesArray * sdigits = 0 ;  
192   TString eventS ; 
193   eventS += event ;
194   while ( (folder = (TFolder*)next()) ) {
195    if ( (strcmp(folder->GetTitle(), eventS.Data()) == 0) || (strcmp(folder->GetTitle(), "") == 0) ) {
196       Int_t numberoffiles = 0 ; 
197       if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
198         cout << "INFO: AliPHOSDigitizer::Exec -> Adding SDigits " << GetName() << " from " << folder->GetName() << endl ; 
199         numberoffiles++ ; 
200         Int_t index ; 
201         AliPHOSDigit * curSDigit ; 
202         AliPHOSDigit * digit ; 
203         for ( index = 0 ; index < sdigits->GetEntriesFast(); index++) { 
204           curSDigit = (AliPHOSDigit*)sdigits->At(index) ; 
205           curSDigit->ShiftPrimary(numberoffiles) ;
206           digit = (AliPHOSDigit*)digits->At(curSDigit->GetId() - 1 ) ; 
207           *digit = *digit + *curSDigit ; 
208         }
209       }
210     }
211   }
212   //remove digits below thresholds
213   for(absID = 0; absID < nEMC ; absID++)
214     if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fEMCDigitThreshold)
215       digits->RemoveAt(absID) ;
216   
217   for(absID = nEMC; absID < nCPV ; absID++)
218     if(sDigitizer->Calibrate(((AliPHOSDigit*)digits->At(absID))->GetAmp()) < fCPVDigitThreshold)
219       digits->RemoveAt(absID) ;
220   
221   for(absID = nCPV; absID < nPPSD ; absID++)
222     if(sDigitizer->Calibrate(((AliPHOSDigit *)digits->At(absID))->GetAmp()) < fPPSDDigitThreshold)
223       digits->RemoveAt(absID) ;
224   
225   digits->Compress() ;  
226   
227   Int_t ndigits = digits->GetEntriesFast() ;
228
229   digits->Expand(ndigits) ;
230
231
232   //Set indexes in list of digits
233   Int_t i ;
234   for (i = 0 ; i < ndigits ; i++) { 
235     AliPHOSDigit * digit = (AliPHOSDigit *) digits->At(i) ; 
236     digit->SetIndexInList(i) ;     
237   }
238
239 }
240
241 //____________________________________________________________________________
242 void AliPHOSDigitizer::Exec(Option_t *option) 
243
244   // Managing method
245
246   if( strcmp(GetName(), "") == 0 )    
247     Init() ;
248   
249   if (strstr(option,"print")) {
250     Print("");
251     return ; 
252   }
253   
254   if(strstr(option,"tim"))
255     gBenchmark->Start("PHOSDigitizer");
256
257   //Check, if this branch already exits
258   TObjArray * lob = (TObjArray*)gAlice->TreeD()->GetListOfBranches() ;
259   TIter next(lob) ; 
260   TBranch * branch = 0 ;  
261   Bool_t phosfound = kFALSE, digitizerfound = kFALSE ; 
262   
263   while ( (branch = (TBranch*)next()) && (!phosfound || !digitizerfound) ) {
264     if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
265       phosfound = kTRUE ;
266     
267     else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
268       digitizerfound = kTRUE ; 
269   }
270
271   if ( phosfound || digitizerfound ) {
272     cerr << "WARNING: AliPHOSDigitizer::WriteDigits -> Digits and/or Digitizer branch with name " << GetName() 
273          << " already exits" << endl ;
274     return ; 
275   }   
276
277   Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
278   Int_t ievent ;
279
280   for(ievent = 0; ievent < nevents; ievent++){
281
282     if(!ReadSDigits(ievent)) //read sdigits event(s) evaluated by Combinator() from file(s)
283       return ;    
284     
285     Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
286     
287     WriteDigits(ievent) ;
288   }
289    
290   if(strstr(option,"deb"))
291     PrintDigits(option);
292   
293
294   if(strstr(option,"tim")){
295     gBenchmark->Stop("PHOSDigitizer");
296     cout << "AliPHOSDigitizer:" << endl ;
297     cout << "  took " << gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds for SDigitizing " 
298          <<  gBenchmark->GetCpuTime("PHOSDigitizer") << " seconds per event " << endl ;
299     //   <<  gBenchmark->GetCpuTime("PHOSDigitizer")/(fIeventMax->At(0)) << " seconds per event " << endl ;
300     cout << endl ;
301   }
302   
303 }
304
305 //____________________________________________________________________________ 
306 void AliPHOSDigitizer::Init()
307 {
308   // Makes all memory allocations
309   // Adds Digitizer task to the folder of PHOS tasks
310    //============================================================= YS
311   //  The initialisation is now done by AliPHOSGetter
312     
313   if( strcmp(GetTitle(), "") == 0 )
314     SetTitle("galice.root") ;
315   
316    
317   // the SDigits name is stored by AliPHOSGetter as the name of the TClones Array 
318   // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/branchname and has branchTitle as title.    
319     
320   AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName()) ; 
321   if ( gime == 0 ) {
322     cerr << "ERROR: AliPHOSDigitizer::Init -> Could not obtain the Getter object !" << endl ; 
323     return ;
324   } 
325    
326 //   fIevent    = new TArrayI(1) ;
327 //   fIevent->AddAt(-1,0 ) ; 
328 //   fIeventMax = new TArrayI(1) ;
329   
330 //   fIeventMax->AddAt((Int_t) gAlice->TreeE()->GetEntries(), 0 );
331   
332   //add Task to //YSAlice/tasks/Digitizer/PHOS
333   TTask * aliceSD  = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/Digitizer") ; 
334   TTask * phosSD   = (TTask*)aliceSD->GetListOfTasks()->FindObject("PHOS") ;
335   phosSD->Add(this) ; 
336   // create a folder on the white board //YSAlice/WhiteBoard/Digits/PHOS/headerFile/digitsTitle
337   gime->Post(GetTitle(), "D",  GetName() ) ;   
338
339 }
340
341 //__________________________________________________________________
342 void AliPHOSDigitizer::MixWith(const char* headerFile)
343 {
344   // Alows to produce digits by superimposing background and signal event.
345   // It is assumed, that headers file with SIGNAL events is opened in 
346   // the constructor. 
347   // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed 
348   // Thus we avoid writing (changing) huge and expensive 
349   // backgound files: all output will be writen into SIGNAL, i.e. 
350   // opened in constructor file. 
351   //
352   // One can open as many files to mix with as one needs.
353   // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
354   // can be mixed.
355
356   if( strcmp(GetName(), "") == 0 )
357     Init() ;
358
359   const char* sDigitsTitle = GetName() ; 
360   
361   // check if the specified SDigits do not already exist on the White Board:
362   // //YSAlice/WhiteBoard/SDigits/PHOS/headerFile/sDigitsTitle
363
364   TString path = "YSAlice/WhiteBoard/SDigits/PHOS/" ; 
365   path += headerFile ; 
366   path += "/" ; 
367   path += sDigitsTitle ;
368   if ( gROOT->FindObjectAny(path.Data()) ) {
369     cerr << "WARNING: AliPHOSDigitizer::MixWith -> Entry already exists, do not add" << endl ;
370     return;
371   }
372   // check if the requested file is already open or exist and if SDigits Branch exist
373   TFile * file = (TFile*)gROOT->FindObject(headerFile); 
374   if ( !file ) { 
375     file = new TFile(headerFile, "READ") ; 
376     if (!file) { 
377       cerr << "ERROR: AliPHOSDigitizer::MixWith -> File " << headerFile << " does not exist!" << endl ; 
378       return ; 
379     }
380   }
381   Int_t nevent = (Int_t)((TTree*)file->Get("TE"))->GetEntries() ;
382   Int_t ievent ; 
383   for (ievent = 0; ievent < nevent; ievent++) {
384     TString tsname("TreeS") ; 
385     tsname += ievent ; 
386     TTree * ts = (TTree*)file->Get(tsname.Data()) ;
387     if ( !ts ) {
388       cerr << "ERROR: AliPHOSDigitizer::MixWith -> TreeS0 " << " does not exist in " << headerFile << endl ; 
389       return ;
390     }
391     
392     TObjArray * lob = (TObjArray*)ts->GetListOfBranches() ;
393     TIter next(lob) ; 
394     TBranch * branch = 0 ; 
395     TBranch * sdigitsbranch = 0 ; 
396     TBranch * sdigitizerbranch = 0 ; 
397     Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
398     
399     while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
400       if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), sDigitsTitle)==0) ) {
401         sdigitsbranch = branch ; 
402         phosfound = kTRUE ;
403       }
404       else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), sDigitsTitle)==0) ) {
405         sdigitizerbranch = branch ; 
406         sdigitizerfound = kTRUE ; 
407       }
408     }
409     
410     if ( !phosfound || !sdigitizerfound ) {
411       cerr << "WARNING: AliPHOSDigitizer::MixWith -> Cannot find SDigits and/or SDigitizer with name " << sDigitsTitle << endl ;
412       return ; 
413     }   
414     
415     // post the new SDigits to the White Board
416     AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
417     gime->Post(headerFile, "S", sDigitsTitle, ievent ) ; 
418     TClonesArray * sdigits = gime->SDigits(sDigitsTitle, headerFile) ;  
419     sdigitsbranch->SetAddress(&sdigits) ;
420     sdigitsbranch->GetEvent(0) ;
421   }
422 }
423
424 //__________________________________________________________________
425 void AliPHOSDigitizer::Print(Option_t* option)const {
426   // Print Digitizer's parameters
427   if( strcmp(GetName(), "") != 0 ){
428     
429     cout << "------------------- "<< GetName() << " -------------" << endl ;
430     cout << "Digitizing sDigits from file(s): " <<endl ;
431     
432      TCollection * folderslist = ((TFolder*)gROOT->FindObjectAny("YSAlice/WhiteBoard/SDigits/PHOS"))->GetListOfFolders() ; 
433     TIter next(folderslist) ; 
434     TFolder * folder = 0 ; 
435     
436     while ( (folder = (TFolder*)next()) ) {
437       if ( folder->FindObject(GetName())  ) 
438         cout << "Adding SDigits " << GetName() << " from " << folder->GetName() << endl ; 
439     }
440     cout << endl ;
441     cout << "Writing digits to " << GetTitle() << endl ;
442     
443     cout << endl ;
444     cout << "With following parameters: " << endl ;
445     cout << "     Electronics noise in EMC (fPinNoise) = " << fPinNoise << endl ;
446     cout << "  Threshold  in EMC  (fEMCDigitThreshold) = " << fEMCDigitThreshold  << endl ; ;
447     cout << "                 Noise in CPV (fCPVNoise) = " << fCPVNoise << endl ; 
448     cout << "    Threshold in CPV (fCPVDigitThreshold) = " << fCPVDigitThreshold << endl ; 
449     cout << "               Noise in PPSD (fPPSDNoise) = " << fPPSDNoise << endl ;
450     cout << "  Threshold in PPSD (fPPSDDigitThreshold) = " << fPPSDDigitThreshold << endl ;
451     cout << "---------------------------------------------------" << endl ;
452   }
453   else
454     cout << "AliPHOSDigitizer not initialized " << endl ;
455   
456 }
457 //__________________________________________________________________
458 void AliPHOSDigitizer::PrintDigits(Option_t * option){
459   // Print a table of digits
460
461   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
462   TClonesArray * digits = gime->Digits() ; 
463
464   cout << "AliPHOSDigitiser:"<< endl ;
465   cout << "       Number of entries in Digits list " << digits->GetEntriesFast() << endl ;
466   cout << endl ;
467   if(strstr(option,"all")){
468     
469     //loop over digits
470     AliPHOSDigit * digit;
471     cout << "Digit Id " << " Amplitude " <<  " Index "  <<  " Nprim " << " Primaries list " <<  endl;      
472     Int_t index ;
473     for (index = 0 ; index < digits->GetEntries() ; index++) {
474       digit = (AliPHOSDigit * )  digits->At(index) ;
475       cout << setw(8)  <<  digit->GetId() << " "  <<    setw(3)  <<  digit->GetAmp() <<   "  "  
476            << setw(6)  <<  digit->GetIndexInList() << "  "   
477            << setw(5)  <<  digit->GetNprimary() <<"  ";
478       
479       Int_t iprimary;
480       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
481         cout << setw(5)  <<  digit->GetPrimary(iprimary+1) << " ";
482       cout << endl;      
483     }
484     
485   }
486 }
487
488 //__________________________________________________________________
489 void AliPHOSDigitizer::SetSDigitsBranch(const char* title)
490 {
491   // we set title (comment) of the SDigits branch in the first! header file
492   if( strcmp(GetName(), "") == 0 )
493     Init() ;
494
495   AliPHOSGetter::GetInstance()->SDigits()->SetName(title) ; 
496  
497 }
498
499 //__________________________________________________________________
500 Bool_t AliPHOSDigitizer::ReadSDigits(Int_t event)
501 {
502   // Reads summable digits from the opened files for the particular set of events given by fIevent
503
504   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
505   
506   TFile * file = (TFile*)gROOT->GetFile(GetTitle()); 
507   file->cd() ;
508
509 // Get SDigits Tree header from file
510   TString treeName("TreeS") ;
511   treeName += event ; 
512   TTree * treeS = (TTree*)file->Get(treeName.Data());
513    
514   if(treeS==0){
515     cerr << "ERROR: AliPHOSDigitizer::ReadSDigits There is no SDigit Tree" << endl;
516     return kFALSE;
517   }
518  
519   //set address of the SDigits and SDigitizer
520   TBranch * sdigitsBranch = 0;
521   TBranch * sdigitizerBranch = 0;
522   TObjArray * lob = (TObjArray*)gAlice->TreeS()->GetListOfBranches() ;
523   TIter next(lob) ; 
524   TBranch * branch = 0 ;  
525   Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
526   
527   while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
528    if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) {
529       phosfound = kTRUE ;
530       sdigitsBranch = branch ; 
531     }
532     
533     else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) {
534       sdigitizerfound = kTRUE ; 
535       sdigitizerBranch = branch ;
536     }
537   }
538   if ( !phosfound || !sdigitizerfound ) {
539     cerr << "WARNING: AliPHOSDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName() 
540          << " not found" << endl ;
541     return kFALSE ; 
542   }   
543   
544   
545   TClonesArray * sdigits = gime->SDigits() ; 
546   sdigitsBranch->SetAddress(&sdigits) ;
547   
548   AliPHOSSDigitizer * sdigitizer = gime->SDigitizer() ; 
549   sdigitizerBranch->SetAddress(&sdigitizer) ;
550
551   sdigitsBranch->GetEntry(0) ;
552   sdigitizerBranch->GetEntry(0) ;
553  
554   fPedestal = sdigitizer->GetPedestalParameter() ;
555   fSlope    = sdigitizer->GetCalibrationParameter() ;
556   
557    return kTRUE ;
558
559 }
560
561 //____________________________________________________________________________
562 void AliPHOSDigitizer::Reset() 
563
564   // sets current event number to the first simulated event
565
566   if( strcmp(GetName(), "") == 0 )
567     Init() ;
568
569  //  Int_t inputs ;
570 //   for(inputs = 0; inputs < fNinputs ;inputs++)
571 //       fIevent->AddAt(-1, inputs ) ;
572   
573 }
574
575 //____________________________________________________________________________
576 void AliPHOSDigitizer::WriteDigits(Int_t event)
577 {
578
579   // Makes TreeD in the output file. 
580   // Check if branch already exists: 
581   //   if yes, exit without writing: ROOT TTree does not support overwriting/updating of 
582   //      already existing branches. 
583   //   else creates branch with Digits, named "PHOS", title "...",
584   //      and branch "AliPHOSDigitizer", with the same title to keep all the parameters
585   //      and names of files, from which digits are made.
586
587   AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; 
588   TClonesArray * digits = gime->Digits() ; 
589
590
591   gAlice->GetEvent(event) ; 
592   if(gAlice->TreeD()==0)
593     gAlice->MakeTree("D") ;  
594
595   // create new branches
596   // -- generate file name if necessary
597   char * file =0;
598   if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
599     file = new char[strlen(gAlice->GetBaseFile())+20] ;
600     sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
601   }
602
603   TDirectory *cwd = gDirectory;
604   
605   // -- create Digits branch
606   Int_t bufferSize = 32000 ;    
607   TBranch * digitsBranch = gAlice->TreeD()->Branch("PHOS",&digits,bufferSize);
608   digitsBranch->SetTitle(GetName());
609   if (file) {
610     digitsBranch->SetFile(file);
611     TIter next( digitsBranch->GetListOfBranches());
612     TBranch * sbr ;
613     while ((sbr=(TBranch*)next())) {
614       sbr->SetFile(file);
615     }   
616     cwd->cd();
617   } 
618     
619   // -- Create Digitizer branch
620   Int_t splitlevel = 0 ;
621   AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
622   TBranch * digitizerBranch = gAlice->TreeD()->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel); 
623   digitizerBranch->SetTitle(GetName());
624   if (file) {
625     digitizerBranch->SetFile(file);
626     TIter next( digitizerBranch->GetListOfBranches());
627     TBranch * sbr;
628     while ((sbr=(TBranch*)next())) {
629       sbr->SetFile(file);
630     }   
631     cwd->cd();
632   }
633
634
635   digitsBranch->Fill() ;      
636   digitizerBranch->Fill() ;
637
638   gAlice->TreeD()->Write(0,kOverwrite) ;  
639
640 }
641
642