]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigitizer.cxx
Fixes for macosx
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigitizer.cxx
CommitLineData
990119d6 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
702ab87e 18/* History of cvs commits:
19 *
a28333c5 20 * $Log: AliPHOSDigitizer.cxx,v $
21 * Revision 1.104 2007/12/18 09:08:18 hristov
22 * Splitting of the QA maker into simulation and reconstruction dependent parts (Yves)
23 *
04236e67 24 * Revision 1.103 2007/11/07 11:25:06 schutz
25 * Comment out the QA checking before starting digitization
26 *
18c3b8c2 27 * Revision 1.102 2007/10/19 18:04:29 schutz
28 * The standalone QA data maker is called from AliSimulation and AliReconstruction outside the event loop; i.e. re-reading the data. The QA data making in the event loop has been commented out.
29 *
c65c502a 30 * Revision 1.101 2007/10/14 21:08:10 schutz
31 * Introduced the checking of QA results from previous step before entering the event loop
32 *
8661738e 33 * Revision 1.100 2007/10/10 09:05:10 schutz
34 * Changing name QualAss to QA
35 *
b8274834 36 * Revision 1.99 2007/09/30 17:08:20 schutz
37 * Introducing the notion of QA data acquisition cycle (needed by online)
38 *
5b188f2f 39 * Revision 1.98 2007/09/26 14:22:17 cvetan
40 * Important changes to the reconstructor classes. Complete elimination of the run-loaders, which are now steered only from AliReconstruction. Removal of the corresponding Reconstruct() and FillESD() methods.
41 *
d76c31f4 42 * Revision 1.97 2007/08/07 14:12:03 kharlov
43 * Quality assurance added (Yves Schutz)
44 *
ddd1a39c 45 * Revision 1.96 2007/04/28 10:43:36 policheh
46 * Dead channels simulation: digit energy sets to 0.
47 *
1c6a163f 48 * Revision 1.95 2007/04/10 07:20:52 kharlov
49 * Decalibration should use the same CDB as calibration in AliPHOSClusterizerv1
50 *
1a197b77 51 * Revision 1.94 2007/02/01 10:34:47 hristov
52 * Removing warnings on Solaris x86
53 *
ad4aeaf4 54 * Revision 1.93 2006/10/17 13:17:01 kharlov
55 * Replace AliInfo by AliDebug
56 *
d6e8d7d3 57 * Revision 1.92 2006/08/28 10:01:56 kharlov
58 * Effective C++ warnings fixed (Timur Pocheptsov)
59 *
3663622c 60 * Revision 1.91 2006/04/29 20:25:30 hristov
61 * Decalibration is implemented (Yu.Kharlov)
62 *
877695e7 63 * Revision 1.90 2006/04/22 10:30:17 hristov
64 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
65 *
27a73a5d 66 * Revision 1.89 2006/04/11 15:22:59 hristov
67 * run number in query set to -1: forces AliCDBManager to use its run number (A.Colla)
68 *
28871337 69 * Revision 1.88 2006/03/13 14:05:43 kharlov
70 * Calibration objects for EMC and CPV
71 *
fc6706cb 72 * Revision 1.87 2005/08/24 15:33:49 kharlov
73 * Calibration data for raw digits
74 *
a8ec0771 75 * Revision 1.86 2005/07/12 20:07:35 hristov
76 * Changes needed to run simulation and reconstrruction in the same AliRoot session
77 *
7c193632 78 * Revision 1.85 2005/05/28 14:19:04 schutz
79 * Compilation warnings fixed by T.P.
80 *
702ab87e 81 */
88cb7938 82
990119d6 83//_________________________________________________________________________
990119d6 84//*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
85//////////////////////////////////////////////////////////////////////////////
a4e98857 86// This TTask performs digitization of Summable digits (in the PHOS case it is just
87// the sum of contributions from all primary particles into a given cell).
990119d6 88// In addition it performs mixing of summable digits from different events.
7b7c1533 89// The name of the TTask is also the title of the branch that will contain
90// the created SDigits
91// The title of the TTAsk is the name of the file that contains the hits from
92// which the SDigits are created
bca3b32a 93//
94// For each event two branches are created in TreeD:
95// "PHOS" - list of digits
96// "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
97//
a4e98857 98// Note, that one can set a title for new digits branch, and repeat digitization with
bca3b32a 99// another set of parameters.
100//
a4e98857 101// Use case:
990119d6 102// root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
103// root[1] d->ExecuteTask()
104// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
105// //Digitizes SDigitis in all events found in file galice.root
bca3b32a 106//
8cb3533f 107// root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
108// // Will read sdigits from galice1.root
109// root[3] d1->MixWith("galice2.root")
990119d6 110// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
a4e98857 111// // Reads another set of sdigits from galice2.root
8cb3533f 112// root[3] d1->MixWith("galice3.root")
a4e98857 113// // Reads another set of sdigits from galice3.root
8cb3533f 114// root[4] d->ExecuteTask("deb timing")
115// // Reads SDigits from files galice1.root, galice2.root ....
116// // mixes them and stores produced Digits in file galice1.root
117// // deb - prints number of produced digits
118// // deb all - prints list of produced digits
119// // timing - prints time used for digitization
990119d6 120//
990119d6 121
122// --- ROOT system ---
990119d6 123#include "TTree.h"
124#include "TSystem.h"
8cb3533f 125#include "TBenchmark.h"
e957fea8 126#include "TRandom.h"
f898e0f3 127#include "TMath.h"
ba54256b 128
990119d6 129// --- Standard library ---
130
131// --- AliRoot header files ---
e250de8f 132#include <TGeoManager.h>
351dd634 133#include "AliLog.h"
3f81a70b 134#include "AliRunDigitizer.h"
990119d6 135#include "AliPHOSDigit.h"
990119d6 136#include "AliPHOSDigitizer.h"
8cb3533f 137#include "AliPHOSGeometry.h"
7437a0f7 138#include "AliPHOSTick.h"
f898e0f3 139#include "AliPHOSSimParam.h"
140#include "AliPHOSCalibData.h"
141#include "AliRunLoader.h"
142#include "AliPHOSLoader.h"
54ac223e 143#include "AliPHOSPulseGenerator.h"
990119d6 144
145ClassImp(AliPHOSDigitizer)
146
147
148//____________________________________________________________________________
3663622c 149AliPHOSDigitizer::AliPHOSDigitizer() :
150 AliDigitizer("",""),
151 fDefaultInit(kTRUE),
152 fDigitsInRun(0),
153 fInit(kFALSE),
154 fInput(0),
155 fInputFileNames(0x0),
156 fEventNames(0x0),
157 fEmcCrystals(0),
3663622c 158 fEventFolderName(""),
159 fFirstEvent(0),
ddd1a39c 160 fLastEvent(0),
f898e0f3 161 fcdb(0x0),
54ac223e 162 fEventCounter(0),
163 fPulse(0),
164 fADCValuesLG(0),
165 fADCValuesHG(0)
990119d6 166{
167 // ctor
8d0f3f77 168 InitParameters() ;
fbf811ec 169 fManager = 0 ; // We work in the standalong mode
88cb7938 170}
3f81a70b 171
172//____________________________________________________________________________
e191bb57 173AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName,
174 TString eventFolderName):
3663622c 175 AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
176 fDefaultInit(kFALSE),
177 fDigitsInRun(0),
178 fInit(kFALSE),
179 fInput(0),
180 fInputFileNames(0x0),
181 fEventNames(0x0),
182 fEmcCrystals(0),
3663622c 183 fEventFolderName(eventFolderName),
184 fFirstEvent(0),
ddd1a39c 185 fLastEvent(0),
f898e0f3 186 fcdb(0x0),
54ac223e 187 fEventCounter(0),
188 fPulse(0),
189 fADCValuesLG(0),
190 fADCValuesHG(0)
3f81a70b 191{
192 // ctor
8d0f3f77 193 InitParameters() ;
3f81a70b 194 Init() ;
92f521a9 195 fDefaultInit = kFALSE ;
54ac223e 196 fManager = 0 ; // We work in the standalone mode
f898e0f3 197 fcdb = new AliPHOSCalibData(-1);
88cb7938 198}
199
200//____________________________________________________________________________
3663622c 201AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d) :
202 AliDigitizer(d),
203 fDefaultInit(d.fDefaultInit),
204 fDigitsInRun(d.fDigitsInRun),
205 fInit(d.fInit),
206 fInput(d.fInput),
207 fInputFileNames(0x0),//?
208 fEventNames(0x0),//?
209 fEmcCrystals(d.fEmcCrystals),
3663622c 210 fEventFolderName(d.fEventFolderName),
211 fFirstEvent(d.fFirstEvent),
ddd1a39c 212 fLastEvent(d.fLastEvent),
f898e0f3 213 fcdb (0x0),
54ac223e 214 fEventCounter(0),
215 fPulse(0),
216 fADCValuesLG(0),
217 fADCValuesHG(0)
88cb7938 218{
219 // copyy ctor
88cb7938 220 SetName(d.GetName()) ;
221 SetTitle(d.GetTitle()) ;
f898e0f3 222 fcdb = new AliPHOSCalibData(-1);
990119d6 223}
224
990119d6 225//____________________________________________________________________________
3663622c 226AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd) :
227 AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
228 fDefaultInit(kFALSE),
229 fDigitsInRun(0),
230 fInit(kFALSE),
231 fInput(0),
232 fInputFileNames(0x0),
233 fEventNames(0x0),
234 fEmcCrystals(0),
3663622c 235 fEventFolderName(fManager->GetInputFolderName(0)),
236 fFirstEvent(0),
ddd1a39c 237 fLastEvent(0),
f898e0f3 238 fcdb (0x0),
54ac223e 239 fEventCounter(0),
240 fPulse(0),
241 fADCValuesLG(0),
242 fADCValuesHG(0)
ddd1a39c 243
990119d6 244{
45fa49ca 245 // ctor Init() is called by RunDigitizer
88cb7938 246 fManager = rd ;
88cb7938 247 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
b22e4735 248 InitParameters() ;
fbf811ec 249 fDefaultInit = kFALSE ;
f898e0f3 250 fcdb = new AliPHOSCalibData(-1);
990119d6 251}
252
253//____________________________________________________________________________
254 AliPHOSDigitizer::~AliPHOSDigitizer()
255{
256 // dtor
f898e0f3 257 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
258 if(rl){
259 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
260 phosLoader->CleanDigitizer() ;
261 }
262
88cb7938 263 delete [] fInputFileNames ;
264 delete [] fEventNames ;
ddd1a39c 265
54ac223e 266 delete fPulse;
267 delete [] fADCValuesLG;
268 delete [] fADCValuesHG;
269
f898e0f3 270 if(fcdb){ delete fcdb ; fcdb=0;}
ddd1a39c 271
990119d6 272}
273
274//____________________________________________________________________________
fc7e2f43 275void AliPHOSDigitizer::Digitize(Int_t event)
a4e98857 276{
277
278 // Makes the digitization of the collected summable digits.
279 // It first creates the array of all PHOS modules
dc986a1d 280 // filled with noise (different for EMC, and CPV) and
a4e98857 281 // then adds contributions from SDigits.
282 // This design avoids scanning over the list of digits to add
283 // contribution to new SDigits only.
990119d6 284
f898e0f3 285 Bool_t toMakeNoise = kTRUE ; //Do not create noisy digits if merge with real data
286
287 //First stream
288 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
54ac223e 289 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 290
291 Int_t readEvent = event ;
45fa49ca 292 if (fManager)
f898e0f3 293 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
d6e8d7d3 294 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
f898e0f3 295 readEvent, GetTitle(), fEventFolderName.Data())) ;
296 rl->GetEvent(readEvent) ;
297 phosLoader->CleanSDigits() ;
298 phosLoader->LoadSDigits("READ") ;
299
300 //Prepare Output
301 TClonesArray * digits = phosLoader->Digits() ;
302 if( !digits ) {
303 phosLoader->MakeDigitsArray() ;
304 digits = phosLoader->Digits() ;
305 }
306
7b7c1533 307 digits->Clear() ;
990119d6 308
f898e0f3 309 //
310 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
990119d6 311 //Making digits with noise, first EMC
e250de8f 312 //Check which PHOS modules are present
313 Bool_t isPresent[5] ;
314 TString volpath ;
315 Int_t nmod=0 ;
316 for(Int_t i=0; i<5; i++){
317 volpath = "/ALIC_1/PHOS_";
318 volpath += i+1;
319 if (gGeoManager->CheckPath(volpath.Data())) {
320 isPresent[i]=1 ;
321 nmod++ ;
322 }
323 else{
324 isPresent[i]=0 ;
325 }
326 }
327
328 Int_t nEMC = nmod*geom->GetNPhi()*geom->GetNZ();
990119d6 329
330 Int_t nCPV ;
990119d6 331 Int_t absID ;
990119d6 332
e250de8f 333 //check if CPV exists
334 Bool_t isCPVpresent=0 ;
335 for(Int_t i=1; i<=5 && !isCPVpresent; i++){
336 volpath = "/ALIC_1/PHOS_";
337 volpath += i;
338 volpath += "/PCPV_1";
339 if (gGeoManager->CheckPath(volpath.Data()))
340 isCPVpresent=1 ;
341 }
88cb7938 342
e250de8f 343 if(isCPVpresent){
344 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * nmod ;
345 }
346 else{
347 nCPV = nEMC ;
348 }
349
9688c1dd 350 digits->Expand(nCPV) ;
8cb3533f 351
88cb7938 352 //take all the inputs to add together and load the SDigits
353 TObjArray * sdigArray = new TObjArray(fInput) ;
f898e0f3 354 sdigArray->AddAt(phosLoader->SDigits(), 0) ;
355
356 for(Int_t i = 1 ; i < fInput ; i++){
88cb7938 357 TString tempo(fEventNames[i]) ;
358 tempo += i ;
f898e0f3 359 AliRunLoader* rl2 = AliRunLoader::GetRunLoader(tempo) ;
360 if(!rl2){
361 rl2 = AliRunLoader::Open(fInputFileNames[i], tempo) ;
362 if (!rl2) {
363 Fatal("AliPHOSDigitizer", "Could not find the Run Loader for %s - %s",fInputFileNames[i].Data(), tempo.Data()) ;
364 return ;
365 }
366 rl2->LoadHeader();
367 }
368 AliPHOSLoader * phosLoader2 = dynamic_cast<AliPHOSLoader*>(rl2->GetLoader("PHOSLoader"));
369
370 if(fManager){
371 readEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
372 }
373 TClonesArray * digs ;
374 if(AliPHOSSimParam::GetInstance()->IsStreamDigits(i)){ //This is Digits Stream
375 AliInfo(Form("Adding event %d from input stream %d %s %s",
376 readEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
377 rl2->GetEvent(readEvent) ;
378 phosLoader2->CleanDigits() ;
379 phosLoader2->LoadDigits("READ") ;
380 digs = phosLoader2->Digits() ;
381 toMakeNoise=0 ; //Do not add noise, it is already in stream
382 }
383 else{
384 AliInfo(Form("Adding event %d (SDigits) from input stream %d %s %s",
385 readEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
386 rl2->GetEvent(readEvent) ;
387 phosLoader2->CleanSDigits() ;
388 phosLoader2->LoadSDigits("READ") ;
389 digs = phosLoader2->SDigits() ;
390 }
391 sdigArray->AddAt(digs, i) ;
38bb0fd5 392 }
9688c1dd 393
27a73a5d 394 //Find the first crystal with signal
9688c1dd 395 Int_t nextSig = 200000 ;
88cb7938 396 TClonesArray * sdigits ;
f898e0f3 397 for(Int_t i = 0 ; i < fInput ; i++){
88cb7938 398 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
a6eedfad 399 if ( !sdigits->GetEntriesFast() )
7a9d98f9 400 continue ;
88cb7938 401 Int_t curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
402 if(curNext < nextSig)
403 nextSig = curNext ;
9688c1dd 404 }
88cb7938 405
406 TArrayI index(fInput) ;
9688c1dd 407 index.Reset() ; //Set all indexes to zero
88cb7938 408
9688c1dd 409 AliPHOSDigit * digit ;
410 AliPHOSDigit * curSDigit ;
88cb7938 411
f898e0f3 412// TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
88cb7938 413
9688c1dd 414 //Put Noise contribution
f898e0f3 415 Double_t apdNoise = 0. ;
416 if(toMakeNoise)
417 apdNoise = AliPHOSSimParam::GetInstance()->GetAPDNoise() ;
418
e250de8f 419 Int_t emcpermod=geom->GetNPhi()*geom->GetNZ();
420 Int_t idigit= 0;
421 for(Int_t imod=0; imod<5; imod++){
422 if(!isPresent[imod])
423 continue ;
424 Int_t firstAbsId=imod*emcpermod+1 ;
425 Int_t lastAbsId =(imod+1)*emcpermod ;
426 for(absID = firstAbsId ; absID <= lastAbsId ; absID++){
427 Float_t noise = gRandom->Gaus(0.,apdNoise) ;
428 new((*digits)[idigit]) AliPHOSDigit( -1, absID, noise, TimeOfNoise() ) ;
429 //look if we have to add signal?
430 digit = dynamic_cast<AliPHOSDigit *>(digits->At(idigit)) ;
431 idigit++ ;
88cb7938 432
e250de8f 433 if(absID==nextSig){
9688c1dd 434 //Add SDigits from all inputs
f898e0f3 435// ticks->Clear() ;
436// Int_t contrib = 0 ;
437
438//New Timing model is necessary
439// Float_t a = digit->GetEnergy() ;
440// Float_t b = TMath::Abs( a / fTimeSignalLength) ;
441// //Mark the beginning of the signal
442// new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
443// //Mark the end of the signal
444// new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
445
446// Calculate time as time of the largest digit
e250de8f 447 Float_t time = digit->GetTime() ;
448 Float_t eTime= digit->GetEnergy() ;
88cb7938 449
e250de8f 450 //loop over inputs
451 for(Int_t i = 0 ; i < fInput ; i++){
737c795f 452 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] ){
e250de8f 453 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
737c795f 454 if(AliPHOSSimParam::GetInstance()->IsStreamDigits(i)){ //This is Digits Stream
455 curSDigit->SetEnergy(Calibrate(curSDigit->GetEnergy(),curSDigit->GetId())) ;
6f47f50d 456 curSDigit->SetTime(CalibrateT(curSDigit->GetTime(),curSDigit->GetId())) ;
737c795f 457 }
458 }
9688c1dd 459 else
e250de8f 460 curSDigit = 0 ;
461 //May be several digits will contribute from the same input
462 while(curSDigit && curSDigit->GetId() == absID){
463 //Shift primary to separate primaries belonging different inputs
464 Int_t primaryoffset ;
465 if(fManager)
466 primaryoffset = fManager->GetMask(i) ;
467 else
468 primaryoffset = 10000000*i ;
469 curSDigit->ShiftPrimary(primaryoffset) ;
7437a0f7 470
f898e0f3 471//New Timing model is necessary
472// a = curSDigit->GetEnergy() ;
473// b = a /fTimeSignalLength ;
474// new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
475// new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
476 if(curSDigit->GetEnergy()>eTime){
477 eTime=curSDigit->GetEnergy() ;
478 time=curSDigit->GetTime() ;
479 }
e250de8f 480 *digit += *curSDigit ; //add energies
481
482 index[i]++ ;
483 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
484 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
485 else
486 curSDigit = 0 ;
487 }
488 }
88cb7938 489
e250de8f 490 //calculate and set time
f898e0f3 491//New Timing model is necessary
492// Float_t time = FrontEdgeTime(ticks) ;
e250de8f 493 digit->SetTime(time) ;
88cb7938 494
e250de8f 495 //Find next signal module
496 nextSig = 200000 ;
497 for(Int_t i = 0 ; i < fInput ; i++){
498 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
499 Int_t curNext = nextSig ;
500 if(sdigits->GetEntriesFast() > index[i] ){
501 curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
502 }
503 if(curNext < nextSig) nextSig = curNext ;
504 }
7b7c1533 505 }
506 }
990119d6 507 }
f898e0f3 508
509 //distretize energy if necessary
510 if(AliPHOSSimParam::GetInstance()->IsEDigitizationOn()){
511 Float_t adcW=AliPHOSSimParam::GetInstance()->GetADCchannelW() ;
512 for(Int_t i = 0 ; i < nEMC ; i++){
513 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
514 digit->SetEnergy(adcW*ceil(digit->GetEnergy()/adcW)) ;
515 }
516 }
737c795f 517 //Apply decalibration if necessary
518 for(Int_t i = 0 ; i < nEMC ; i++){
519 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
520 Decalibrate(digit) ;
167d2780 521 }
522
3f81a70b 523
f898e0f3 524// ticks->Delete() ;
525// delete ticks ;
88cb7938 526
9688c1dd 527 //Now CPV digits (different noise and no timing)
e250de8f 528 Int_t cpvpermod = geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() ;
529 Int_t nEMCtotal=emcpermod*5 ;
f898e0f3 530 Float_t cpvNoise = AliPHOSSimParam::GetInstance()->GetCPVNoise() ;
e250de8f 531 if(isCPVpresent){ //CPV is present in current geometry
532 for(Int_t imod=0; imod<5; imod++){ //module is present in current geometry
533 if(!isPresent[imod])
534 continue ;
535 Int_t firstAbsId=nEMCtotal+imod*cpvpermod+1 ;
536 Int_t lastAbsId =nEMCtotal+(imod+1)*cpvpermod ;
537 for(absID = firstAbsId; absID <= lastAbsId; absID++){
538 Float_t noise = gRandom->Gaus(0., cpvNoise) ;
539 new((*digits)[idigit]) AliPHOSDigit( -1,absID,noise, TimeOfNoise() ) ;
540 idigit++ ;
541 //look if we have to add signal?
542 if(absID==nextSig){
543 digit = dynamic_cast<AliPHOSDigit *>(digits->At(idigit-1)) ;
544 //Add SDigits from all inputs
545 for(Int_t i = 0 ; i < fInput ; i++){
546 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
547 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
548 else
549 curSDigit = 0 ;
550
551 //May be several digits will contribute from the same input
552 while(curSDigit && curSDigit->GetId() == absID){
553 //Shift primary to separate primaries belonging different inputs
554 Int_t primaryoffset ;
555 if(fManager)
556 primaryoffset = fManager->GetMask(i) ;
557 else
558 primaryoffset = 10000000*i ;
559 curSDigit->ShiftPrimary(primaryoffset) ;
560
561 //add energies
562 *digit += *curSDigit ;
563 index[i]++ ;
564 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
565 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i]) ) ;
566 else
567 curSDigit = 0 ;
568 }
569 }
a6eedfad 570
e250de8f 571 //Find next signal module
572 nextSig = 200000 ;
573 for(Int_t i = 0 ; i < fInput ; i++){
574 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
575 Int_t curNext = nextSig ;
576 if(sdigits->GetEntriesFast() > index[i] )
577 curNext = dynamic_cast<AliPHOSDigit *>( sdigits->At(index[i]) )->GetId() ;
578 if(curNext < nextSig) nextSig = curNext ;
579 }
9688c1dd 580
e250de8f 581 }
582 }
9688c1dd 583 }
584 }
88cb7938 585
586 delete sdigArray ; //We should not delete its contents
9688c1dd 587
1dfe0f3c 588 Int_t relId[4];
589
590 //set amplitudes in bad channels to zero
f898e0f3 591
65fd5dc1 592 for(Int_t i = 0 ; i <digits->GetEntriesFast(); i++){
1dfe0f3c 593 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
f898e0f3 594 geom->AbsToRelNumbering(digit->GetId(),relId);
1dfe0f3c 595 if(relId[1] == 0) // Emc
f898e0f3 596 if(fcdb->IsBadChannelEmc(relId[0],relId[3],relId[2])) digit->SetEnergy(0.);
1dfe0f3c 597 }
598
990119d6 599 //remove digits below thresholds
f898e0f3 600 Float_t emcThreshold = AliPHOSSimParam::GetInstance()->GetEmcDigitsThreshold() ;
601 for(Int_t i = 0 ; i < nEMC ; i++){
548f0134 602 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
a28333c5 603
f898e0f3 604 if(digit->GetEnergy() < emcThreshold){
a6eedfad 605 digits->RemoveAt(i) ;
f898e0f3 606 continue ;
607 }
6f47f50d 608
54ac223e 609 geom->AbsToRelNumbering(digit->GetId(),relId);
610
6f47f50d 611 digit->SetEnergy(TMath::Ceil(digit->GetEnergy())-0.9999) ;
612
f898e0f3 613 Float_t tres = TimeResolution(digit->GetEnergy()) ;
614 digit->SetTime(gRandom->Gaus(digit->GetTime(), tres) ) ;
54ac223e 615
616 fPulse->Reset();
617 fPulse->SetAmplitude(digit->GetEnergy()/
618 fcdb->GetADCchannelEmc(relId[0],relId[3],relId[2]));
619 fPulse->SetTZero(digit->GetTimeR());
620 fPulse->MakeSamples();
621 fPulse->GetSamples(fADCValuesHG, fADCValuesLG) ;
622 Int_t nSamples = fPulse->GetRawFormatTimeBins();
623 digit->SetALTROSamplesHG(nSamples,fADCValuesHG);
624 digit->SetALTROSamplesLG(nSamples,fADCValuesLG);
aaf8a71c 625 }
626
f898e0f3 627 Float_t cpvDigitThreshold = AliPHOSSimParam::GetInstance()->GetCpvDigitsThreshold() ;
628 for(Int_t i = nEMC; i < nCPV ; i++){
629 if( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetEnergy() < cpvDigitThreshold )
a6eedfad 630 digits->RemoveAt(i) ;
f898e0f3 631 }
9688c1dd 632
7b7c1533 633 digits->Compress() ;
7b7c1533 634 Int_t ndigits = digits->GetEntriesFast() ;
a91822a8 635
3758d9fc 636 //Set indexes in list of digits and make true digitization of the energy
f898e0f3 637 for (Int_t i = 0 ; i < ndigits ; i++) {
548f0134 638 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
990119d6 639 digit->SetIndexInList(i) ;
27a73a5d 640 if(digit->GetId() > fEmcCrystals){ //digitize CPV only
877695e7 641 digit->SetAmp(DigitizeCPV(digit->GetEnergy(),digit->GetId()) ) ;
27a73a5d 642 }
990119d6 643 }
f898e0f3 644
7b7c1533 645}
737c795f 646//____________________________________________________________________________
647Float_t AliPHOSDigitizer::Calibrate(Float_t amp,Int_t absId){
648 //Apply calibration
649 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
548f0134 650
737c795f 651 //Determine rel.position of the cell absolute ID
652 Int_t relId[4];
653 geom->AbsToRelNumbering(absId,relId);
654 Int_t module=relId[0];
655 Int_t row =relId[2];
656 Int_t column=relId[3];
657 if(relId[1]==0){ //This Is EMC
658 Float_t calibration = fcdb->GetADCchannelEmc(module,column,row);
659 return amp*calibration ;
660 }
661 return 0 ;
662}
3758d9fc 663//____________________________________________________________________________
737c795f 664void AliPHOSDigitizer::Decalibrate(AliPHOSDigit *digit)
3758d9fc 665{
877695e7 666 // Decalibrate EMC digit, i.e. change its energy by a factor read from CDB
667
f898e0f3 668 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
877695e7 669
670 //Determine rel.position of the cell absolute ID
671 Int_t relId[4];
f898e0f3 672 geom->AbsToRelNumbering(digit->GetId(),relId);
877695e7 673 Int_t module=relId[0];
674 Int_t row =relId[2];
675 Int_t column=relId[3];
737c795f 676 if(relId[1]==0){ //This Is EMC
677 Float_t calibration = fcdb->GetADCchannelEmc(module,column,row);
678 Float_t energy = digit->GetEnergy()/calibration;
679 digit->SetEnergy(energy); //Now digit measures E in ADC counts
6f47f50d 680 Float_t time = digit->GetTime() ;
681 time-=fcdb->GetTimeShiftEmc(module,column,row);
682 digit->SetTime(time) ;
737c795f 683 }
877695e7 684}
685//____________________________________________________________________________
6f47f50d 686Float_t AliPHOSDigitizer::CalibrateT(Float_t time,Int_t absId){
687 //Apply time calibration
688 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
689
690 //Determine rel.position of the cell absolute ID
691 Int_t relId[4];
692 geom->AbsToRelNumbering(absId,relId);
693 Int_t module=relId[0];
694 Int_t row =relId[2];
695 Int_t column=relId[3];
696 time += fcdb->GetTimeShiftEmc(module,column,row);
697 return time ;
698}
699//____________________________________________________________________________
877695e7 700Int_t AliPHOSDigitizer::DigitizeCPV(Float_t charge, Int_t absId)
701{
702 // Returns digitized value of the CPV charge in a pad absId
0bc3b8ed 703
f898e0f3 704 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
fc6706cb 705
a8ec0771 706 //Determine rel.position of the cell absId
707 Int_t relId[4];
f898e0f3 708 geom->AbsToRelNumbering(absId,relId);
a8ec0771 709 Int_t module=relId[0];
27a73a5d 710 Int_t row =relId[2];
a8ec0771 711 Int_t column=relId[3];
712
877695e7 713 Int_t channel = 0;
a8ec0771 714
877695e7 715 if(absId > fEmcCrystals){ //digitize CPV only
a8ec0771 716
717 //reading calibration data for cell absId.
f898e0f3 718 Float_t adcPedestalCpv = fcdb->GetADCpedestalCpv(module,column,row);
719 Float_t adcChanelCpv = fcdb->GetADCchannelCpv( module,column,row);
a8ec0771 720
f898e0f3 721 channel = (Int_t) TMath::Ceil((charge - adcPedestalCpv)/adcChanelCpv) ;
722 Int_t nMax = AliPHOSSimParam::GetInstance()->GetNADCcpv() ;
723 if(channel > nMax ) channel = nMax ;
3758d9fc 724 }
877695e7 725 return channel ;
3758d9fc 726}
548f0134 727
7b7c1533 728//____________________________________________________________________________
729void AliPHOSDigitizer::Exec(Option_t *option)
730{
212d1c0f 731 // Steering method to process digitization for events
732 // in the range from fFirstEvent to fLastEvent.
733 // This range is optionally set by SetEventRange().
45fa49ca 734 // if fLastEvent=-1, then process events until the end.
735 // by default fLastEvent = fFirstEvent (process only one event)
88cb7938 736
737 if (!fInit) { // to prevent overwrite existing file
351dd634 738 AliError(Form("Give a version name different from %s",
739 fEventFolderName.Data() )) ;
88cb7938 740 return ;
741 }
990119d6 742
7b7c1533 743 if (strstr(option,"print")) {
88cb7938 744 Print();
7b7c1533 745 return ;
8cb3533f 746 }
990119d6 747
8661738e 748 if(strstr(option,"tim"))
749 gBenchmark->Start("PHOSDigitizer");
3f81a70b 750
f898e0f3 751 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
752 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
88cb7938 753
5b4d2c50 754 // Post Digitizer to the white board
f898e0f3 755 phosLoader->PostDigitizer(this) ;
5b4d2c50 756
212d1c0f 757 if (fLastEvent == -1)
f898e0f3 758 fLastEvent = rl->GetNumberOfEvents() - 1 ;
396a348e 759 else if (fManager)
760 fLastEvent = fFirstEvent ;
45fa49ca 761
212d1c0f 762 Int_t nEvents = fLastEvent - fFirstEvent + 1;
763
7b7c1533 764 Int_t ievent ;
88cb7938 765
212d1c0f 766 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
ddd1a39c 767 fEventCounter++ ;
b22e4735 768
7b7c1533 769 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 770
90cceaf6 771 WriteDigits() ;
88cb7938 772
01a599c9 773 if(strstr(option,"deb"))
774 PrintDigits(option);
94de8339 775
776 //increment the total number of Digits per run
f898e0f3 777 fDigitsInRun += phosLoader->Digits()->GetEntriesFast() ;
88cb7938 778 }
ddd1a39c 779
f898e0f3 780 phosLoader->CleanDigitizer();
5b4d2c50 781
8cb3533f 782 if(strstr(option,"tim")){
783 gBenchmark->Stop("PHOSDigitizer");
21cd0c07 784 TString message ;
785 message = " took %f seconds for Digitizing %f seconds per event\n" ;
351dd634 786 AliInfo(Form( message.Data(),
21cd0c07 787 gBenchmark->GetCpuTime("PHOSDigitizer"),
351dd634 788 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ));
21cd0c07 789 }
990119d6 790}
9688c1dd 791//____________________________________________________________________________
f898e0f3 792Float_t AliPHOSDigitizer::TimeResolution(Float_t e){
793 //calculate TOF resolution using beam-test resutls
794 Float_t a=AliPHOSSimParam::GetInstance()->GetTOFa() ;
795 Float_t b=AliPHOSSimParam::GetInstance()->GetTOFb() ;
796 return TMath::Sqrt(a*a+b*b/e) ;
9688c1dd 797}
8d0f3f77 798
f898e0f3 799////____________________________________________________________________________
800//Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
801//{
802// // Returns the shortest time among all time ticks
803//
804// ticks->Sort() ; //Sort in accordance with times of ticks
805// TIter it(ticks) ;
806// AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
807// Float_t time = ctick->CrossingTime(fTimeThreshold) ;
808//
809// AliPHOSTick * t ;
810// while((t=(AliPHOSTick*) it.Next())){
811// if(t->GetTime() < time) //This tick starts before crossing
812// *ctick+=*t ;
813// else
814// return time ;
815//
816// time = ctick->CrossingTime(fTimeThreshold) ;
817// }
818// return time ;
819//}
820
7b7c1533 821//____________________________________________________________________________
3f81a70b 822Bool_t AliPHOSDigitizer::Init()
8d0f3f77 823{
fbf811ec 824 // Makes all memory allocations
88cb7938 825 fInit = kTRUE ;
f898e0f3 826
bfae5a5d 827 AliPHOSGeometry *geom;
828 if (!(geom = AliPHOSGeometry::GetInstance()))
829 geom = AliPHOSGeometry::GetInstance("IHEP","");
830// const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
b22e4735 831
88cb7938 832 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
8d0f3f77 833
45fa49ca 834 fFirstEvent = 0 ;
835 fLastEvent = fFirstEvent ;
88cb7938 836 if (fManager)
837 fInput = fManager->GetNinputs() ;
838 else
839 fInput = 1 ;
840
841 fInputFileNames = new TString[fInput] ;
842 fEventNames = new TString[fInput] ;
843 fInputFileNames[0] = GetTitle() ;
844 fEventNames[0] = fEventFolderName.Data() ;
845 Int_t index ;
846 for (index = 1 ; index < fInput ; index++) {
847 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
848 TString tempo = fManager->GetInputFolderName(index) ;
45fa49ca 849 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
8d0f3f77 850 }
88cb7938 851
852 //to prevent cleaning of this object while GetEvent is called
f898e0f3 853 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
854 if(!rl){
855 rl = AliRunLoader::Open(GetTitle(), fEventFolderName) ;
856 }
857 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
858 phosLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
88cb7938 859
860 return fInit ;
8d0f3f77 861}
862
863//____________________________________________________________________________
864void AliPHOSDigitizer::InitParameters()
a4e98857 865{
45fa49ca 866 // Set initial parameters Digitizer
0bc3b8ed 867
3758d9fc 868 fDigitsInRun = 0 ;
212d1c0f 869 SetEventRange(0,-1) ;
54ac223e 870 fPulse = new AliPHOSPulseGenerator();
871 fADCValuesLG = new Int_t[fPulse->GetRawFormatTimeBins()];
872 fADCValuesHG = new Int_t[fPulse->GetRawFormatTimeBins()];
8cb3533f 873
990119d6 874}
7b7c1533 875
990119d6 876//__________________________________________________________________
702ab87e 877void AliPHOSDigitizer::Print(const Option_t *)const
21cd0c07 878{
dd5c4038 879 // Print Digitizer's parameters
351dd634 880 AliInfo(Form("\n------------------- %s -------------", GetName() )) ;
88cb7938 881 if( strcmp(fEventFolderName.Data(), "") != 0 ){
882 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
883
884 Int_t nStreams ;
885 if (fManager)
886 nStreams = GetNInputStreams() ;
887 else
888 nStreams = fInput ;
889
890 Int_t index = 0 ;
891 for (index = 0 ; index < nStreams ; index++) {
892 TString tempo(fEventNames[index]) ;
893 tempo += index ;
f898e0f3 894 printf ("Adding SDigits from %s \n", fInputFileNames[index].Data()) ;
88cb7938 895 }
88cb7938 896
f898e0f3 897 // printf("\nWith following parameters:\n") ;
898 // printf(" Electronics noise in EMC (fPinNoise) = %f GeV\n", fPinNoise ) ;
899 // printf(" Threshold in EMC (fEMCDigitThreshold) = %f GeV\n", fEMCDigitThreshold ) ;
900 // printf(" Noise in CPV (fCPVNoise) = %f aux units\n", fCPVNoise ) ;
901 // printf(" Threshold in CPV (fCPVDigitThreshold) = %f aux units\n",fCPVDigitThreshold ) ;
88cb7938 902 printf(" ---------------------------------------------------\n") ;
990119d6 903 }
8cb3533f 904 else
351dd634 905 AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
8cb3533f 906
907}
88cb7938 908
8cb3533f 909//__________________________________________________________________
21cd0c07 910 void AliPHOSDigitizer::PrintDigits(Option_t * option)
911{
3bf72d32 912 // Print a table of digits
21cd0c07 913
f898e0f3 914
915 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
916 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
917 TClonesArray * digits = phosLoader->Digits() ;
918 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
3bf72d32 919
351dd634 920 AliInfo(Form("%d", digits->GetEntriesFast())) ;
88cb7938 921 printf("\nevent %d", gAlice->GetEvNumber()) ;
922 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
923
11f9c5ff 924
3bf72d32 925 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 926 //loop over digits
927 AliPHOSDigit * digit;
88cb7938 928 printf("\nEMC digits (with primaries):\n") ;
929 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
f898e0f3 930 Int_t maxEmc = geom->GetNModules()*geom->GetNCristalsInModule() ;
8cb3533f 931 Int_t index ;
a6eedfad 932 for (index = 0 ; (index < digits->GetEntriesFast()) &&
88cb7938 933 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 934 digit = (AliPHOSDigit * ) digits->At(index) ;
21cd0c07 935 if(digit->GetNprimary() == 0)
936 continue;
27a73a5d 937// printf("%6d %8d %6.5e %4d %2d :",
938// digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ; // YVK
939 printf("%6d %.4f %6.5e %4d %2d :",
940 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
8cb3533f 941 Int_t iprimary;
21cd0c07 942 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 943 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 944 }
81d5f731 945 printf("\n") ;
21cd0c07 946 }
9688c1dd 947 }
3bf72d32 948
9688c1dd 949 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 950
9688c1dd 951 //loop over CPV digits
952 AliPHOSDigit * digit;
88cb7938 953 printf("\nCPV digits (with primaries):\n") ;
954 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
f898e0f3 955 Int_t maxEmc = geom->GetNModules()*geom->GetNCristalsInModule() ;
9688c1dd 956 Int_t index ;
a6eedfad 957 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
9688c1dd 958 digit = (AliPHOSDigit * ) digits->At(index) ;
959 if(digit->GetId() > maxEmc){
81d5f731 960 printf("%6d %8d %4d %2d :",
11f9c5ff 961 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
9688c1dd 962 Int_t iprimary;
21cd0c07 963 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 964 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 965 }
81d5f731 966 printf("\n") ;
21cd0c07 967 }
9688c1dd 968 }
8cb3533f 969 }
88cb7938 970
8cb3533f 971}
7b7c1533 972
9688c1dd 973//__________________________________________________________________
0bc3b8ed 974Float_t AliPHOSDigitizer::TimeOfNoise(void) const
9688c1dd 975{ // Calculates the time signal generated by noise
26a2ef9d 976 //PH Info("TimeOfNoise", "Change me") ;
04f0bda3 977 return gRandom->Rndm() * 1.28E-5;
8cb3533f 978}
7b7c1533 979
88cb7938 980//__________________________________________________________________
981void AliPHOSDigitizer::Unload()
982{
983
984 Int_t i ;
985 for(i = 1 ; i < fInput ; i++){
986 TString tempo(fEventNames[i]) ;
987 tempo += i ;
f898e0f3 988 AliRunLoader* rl = AliRunLoader::GetRunLoader(tempo) ;
989 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
990 phosLoader->UnloadSDigits() ;
88cb7938 991 }
992
f898e0f3 993 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
994 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
995 phosLoader->UnloadDigits() ;
88cb7938 996}
997
7b7c1533 998//____________________________________________________________________________
90cceaf6 999void AliPHOSDigitizer::WriteDigits()
7b7c1533 1000{
1001
1002 // Makes TreeD in the output file.
1003 // Check if branch already exists:
1004 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
1005 // already existing branches.
1006 // else creates branch with Digits, named "PHOS", title "...",
1007 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
1008 // and names of files, from which digits are made.
1009
f898e0f3 1010 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
1011 AliPHOSLoader * phosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
1012
1013 const TClonesArray * digits = phosLoader->Digits() ;
1014 TTree * treeD = phosLoader->TreeD();
1015 if(!treeD){
1016 phosLoader->MakeTree("D");
1017 treeD = phosLoader->TreeD();
1018 }
1019
7b7c1533 1020 // -- create Digits branch
1021 Int_t bufferSize = 32000 ;
2524c56f 1022 TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
88cb7938 1023 digitsBranch->SetTitle(fEventFolderName);
1024 digitsBranch->Fill() ;
fbf811ec 1025
f898e0f3 1026 phosLoader->WriteDigits("OVERWRITE");
1027 phosLoader->WriteDigitizer("OVERWRITE");
88cb7938 1028
1029 Unload() ;
b3690abb 1030
7b7c1533 1031}