]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigitizer.cxx
Pass min E cut to unfolding class
[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 ;
97e75f77 247 SetTitle(static_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){
97e75f77 259 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
6ba1dd81 260
261 if(phosLoader)
262 phosLoader->CleanDigitizer() ;
f898e0f3 263 }
6ba1dd81 264
88cb7938 265 delete [] fInputFileNames ;
266 delete [] fEventNames ;
ddd1a39c 267
54ac223e 268 delete fPulse;
269 delete [] fADCValuesLG;
270 delete [] fADCValuesHG;
271
f898e0f3 272 if(fcdb){ delete fcdb ; fcdb=0;}
ddd1a39c 273
990119d6 274}
275
276//____________________________________________________________________________
fc7e2f43 277void AliPHOSDigitizer::Digitize(Int_t event)
a4e98857 278{
279
280 // Makes the digitization of the collected summable digits.
281 // It first creates the array of all PHOS modules
dc986a1d 282 // filled with noise (different for EMC, and CPV) and
a4e98857 283 // then adds contributions from SDigits.
284 // This design avoids scanning over the list of digits to add
285 // contribution to new SDigits only.
990119d6 286
f898e0f3 287 Bool_t toMakeNoise = kTRUE ; //Do not create noisy digits if merge with real data
288
289 //First stream
290 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
97e75f77 291 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 292
293 Int_t readEvent = event ;
45fa49ca 294 if (fManager)
97e75f77 295 readEvent = static_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
d6e8d7d3 296 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
f898e0f3 297 readEvent, GetTitle(), fEventFolderName.Data())) ;
298 rl->GetEvent(readEvent) ;
299 phosLoader->CleanSDigits() ;
300 phosLoader->LoadSDigits("READ") ;
301
302 //Prepare Output
303 TClonesArray * digits = phosLoader->Digits() ;
304 if( !digits ) {
305 phosLoader->MakeDigitsArray() ;
306 digits = phosLoader->Digits() ;
307 }
308
7b7c1533 309 digits->Clear() ;
990119d6 310
f898e0f3 311 //
312 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
990119d6 313 //Making digits with noise, first EMC
e250de8f 314 //Check which PHOS modules are present
315 Bool_t isPresent[5] ;
316 TString volpath ;
317 Int_t nmod=0 ;
318 for(Int_t i=0; i<5; i++){
319 volpath = "/ALIC_1/PHOS_";
320 volpath += i+1;
321 if (gGeoManager->CheckPath(volpath.Data())) {
322 isPresent[i]=1 ;
323 nmod++ ;
324 }
325 else{
326 isPresent[i]=0 ;
327 }
328 }
329
330 Int_t nEMC = nmod*geom->GetNPhi()*geom->GetNZ();
990119d6 331
332 Int_t nCPV ;
990119d6 333 Int_t absID ;
990119d6 334
e250de8f 335 //check if CPV exists
336 Bool_t isCPVpresent=0 ;
337 for(Int_t i=1; i<=5 && !isCPVpresent; i++){
338 volpath = "/ALIC_1/PHOS_";
339 volpath += i;
340 volpath += "/PCPV_1";
341 if (gGeoManager->CheckPath(volpath.Data()))
342 isCPVpresent=1 ;
343 }
88cb7938 344
e250de8f 345 if(isCPVpresent){
346 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * nmod ;
347 }
348 else{
349 nCPV = nEMC ;
350 }
351
9688c1dd 352 digits->Expand(nCPV) ;
8cb3533f 353
88cb7938 354 //take all the inputs to add together and load the SDigits
355 TObjArray * sdigArray = new TObjArray(fInput) ;
f898e0f3 356 sdigArray->AddAt(phosLoader->SDigits(), 0) ;
357
358 for(Int_t i = 1 ; i < fInput ; i++){
88cb7938 359 TString tempo(fEventNames[i]) ;
360 tempo += i ;
f898e0f3 361 AliRunLoader* rl2 = AliRunLoader::GetRunLoader(tempo) ;
362 if(!rl2){
363 rl2 = AliRunLoader::Open(fInputFileNames[i], tempo) ;
364 if (!rl2) {
365 Fatal("AliPHOSDigitizer", "Could not find the Run Loader for %s - %s",fInputFileNames[i].Data(), tempo.Data()) ;
366 return ;
367 }
368 rl2->LoadHeader();
369 }
97e75f77 370 AliPHOSLoader * phosLoader2 = static_cast<AliPHOSLoader*>(rl2->GetLoader("PHOSLoader"));
f898e0f3 371
372 if(fManager){
97e75f77 373 readEvent = static_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
f898e0f3 374 }
375 TClonesArray * digs ;
376 if(AliPHOSSimParam::GetInstance()->IsStreamDigits(i)){ //This is Digits Stream
377 AliInfo(Form("Adding event %d from input stream %d %s %s",
378 readEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
379 rl2->GetEvent(readEvent) ;
380 phosLoader2->CleanDigits() ;
381 phosLoader2->LoadDigits("READ") ;
382 digs = phosLoader2->Digits() ;
383 toMakeNoise=0 ; //Do not add noise, it is already in stream
384 }
385 else{
386 AliInfo(Form("Adding event %d (SDigits) from input stream %d %s %s",
387 readEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
388 rl2->GetEvent(readEvent) ;
389 phosLoader2->CleanSDigits() ;
390 phosLoader2->LoadSDigits("READ") ;
391 digs = phosLoader2->SDigits() ;
392 }
393 sdigArray->AddAt(digs, i) ;
38bb0fd5 394 }
9688c1dd 395
27a73a5d 396 //Find the first crystal with signal
9688c1dd 397 Int_t nextSig = 200000 ;
88cb7938 398 TClonesArray * sdigits ;
f898e0f3 399 for(Int_t i = 0 ; i < fInput ; i++){
97e75f77 400 sdigits = static_cast<TClonesArray *>(sdigArray->At(i)) ;
a6eedfad 401 if ( !sdigits->GetEntriesFast() )
7a9d98f9 402 continue ;
97e75f77 403 Int_t curNext = static_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
88cb7938 404 if(curNext < nextSig)
405 nextSig = curNext ;
9688c1dd 406 }
88cb7938 407
408 TArrayI index(fInput) ;
9688c1dd 409 index.Reset() ; //Set all indexes to zero
88cb7938 410
9688c1dd 411 AliPHOSDigit * digit ;
412 AliPHOSDigit * curSDigit ;
88cb7938 413
f898e0f3 414// TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
88cb7938 415
9688c1dd 416 //Put Noise contribution
f898e0f3 417 Double_t apdNoise = 0. ;
418 if(toMakeNoise)
419 apdNoise = AliPHOSSimParam::GetInstance()->GetAPDNoise() ;
420
e250de8f 421 Int_t emcpermod=geom->GetNPhi()*geom->GetNZ();
422 Int_t idigit= 0;
423 for(Int_t imod=0; imod<5; imod++){
424 if(!isPresent[imod])
425 continue ;
426 Int_t firstAbsId=imod*emcpermod+1 ;
427 Int_t lastAbsId =(imod+1)*emcpermod ;
428 for(absID = firstAbsId ; absID <= lastAbsId ; absID++){
429 Float_t noise = gRandom->Gaus(0.,apdNoise) ;
430 new((*digits)[idigit]) AliPHOSDigit( -1, absID, noise, TimeOfNoise() ) ;
431 //look if we have to add signal?
97e75f77 432 digit = static_cast<AliPHOSDigit *>(digits->At(idigit)) ;
e250de8f 433 idigit++ ;
88cb7938 434
e250de8f 435 if(absID==nextSig){
9688c1dd 436 //Add SDigits from all inputs
f898e0f3 437// ticks->Clear() ;
438// Int_t contrib = 0 ;
439
440//New Timing model is necessary
441// Float_t a = digit->GetEnergy() ;
442// Float_t b = TMath::Abs( a / fTimeSignalLength) ;
443// //Mark the beginning of the signal
444// new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
445// //Mark the end of the signal
446// new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
447
448// Calculate time as time of the largest digit
e250de8f 449 Float_t time = digit->GetTime() ;
450 Float_t eTime= digit->GetEnergy() ;
88cb7938 451
e250de8f 452 //loop over inputs
453 for(Int_t i = 0 ; i < fInput ; i++){
97e75f77 454 if( static_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] ){
455 curSDigit = static_cast<AliPHOSDigit*>(static_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
737c795f 456 if(AliPHOSSimParam::GetInstance()->IsStreamDigits(i)){ //This is Digits Stream
457 curSDigit->SetEnergy(Calibrate(curSDigit->GetEnergy(),curSDigit->GetId())) ;
6f47f50d 458 curSDigit->SetTime(CalibrateT(curSDigit->GetTime(),curSDigit->GetId())) ;
737c795f 459 }
460 }
9688c1dd 461 else
e250de8f 462 curSDigit = 0 ;
463 //May be several digits will contribute from the same input
464 while(curSDigit && curSDigit->GetId() == absID){
465 //Shift primary to separate primaries belonging different inputs
466 Int_t primaryoffset ;
467 if(fManager)
468 primaryoffset = fManager->GetMask(i) ;
469 else
470 primaryoffset = 10000000*i ;
471 curSDigit->ShiftPrimary(primaryoffset) ;
7437a0f7 472
f898e0f3 473//New Timing model is necessary
474// a = curSDigit->GetEnergy() ;
475// b = a /fTimeSignalLength ;
476// new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
477// new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
478 if(curSDigit->GetEnergy()>eTime){
479 eTime=curSDigit->GetEnergy() ;
480 time=curSDigit->GetTime() ;
481 }
e250de8f 482 *digit += *curSDigit ; //add energies
483
484 index[i]++ ;
97e75f77 485 if( static_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
486 curSDigit = static_cast<AliPHOSDigit*>(static_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
e250de8f 487 else
488 curSDigit = 0 ;
489 }
490 }
88cb7938 491
e250de8f 492 //calculate and set time
f898e0f3 493//New Timing model is necessary
494// Float_t time = FrontEdgeTime(ticks) ;
e250de8f 495 digit->SetTime(time) ;
88cb7938 496
e250de8f 497 //Find next signal module
498 nextSig = 200000 ;
499 for(Int_t i = 0 ; i < fInput ; i++){
97e75f77 500 sdigits = static_cast<TClonesArray *>(sdigArray->At(i)) ;
e250de8f 501 Int_t curNext = nextSig ;
502 if(sdigits->GetEntriesFast() > index[i] ){
97e75f77 503 curNext = static_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
e250de8f 504 }
505 if(curNext < nextSig) nextSig = curNext ;
506 }
7b7c1533 507 }
508 }
990119d6 509 }
f898e0f3 510
dde7e19f 511
512 //Apply non-linearity
513 if(AliPHOSSimParam::GetInstance()->IsCellNonlinearityOn()){ //Apply non-lineairyt on cell level
514 const Double_t aNL = AliPHOSSimParam::GetInstance()->GetCellNonLineairyA() ;
515 const Double_t bNL = AliPHOSSimParam::GetInstance()->GetCellNonLineairyB() ;
516 for(Int_t i = 0 ; i < nEMC ; i++){
517 digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
518 Double_t e= digit->GetEnergy() ;
519 // version(1) digit->SetEnergy(e*(1+a*TMath::Exp(-e/b))) ;
520 digit->SetEnergy(e*(1.+aNL*TMath::Exp(-e*e/2./bNL/bNL))) ; //Better agreement with data...
521 }
522 }
523
524
f898e0f3 525 //distretize energy if necessary
526 if(AliPHOSSimParam::GetInstance()->IsEDigitizationOn()){
527 Float_t adcW=AliPHOSSimParam::GetInstance()->GetADCchannelW() ;
528 for(Int_t i = 0 ; i < nEMC ; i++){
97e75f77 529 digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
f898e0f3 530 digit->SetEnergy(adcW*ceil(digit->GetEnergy()/adcW)) ;
531 }
532 }
dde7e19f 533
737c795f 534 //Apply decalibration if necessary
535 for(Int_t i = 0 ; i < nEMC ; i++){
97e75f77 536 digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
737c795f 537 Decalibrate(digit) ;
167d2780 538 }
3f81a70b 539
f898e0f3 540// ticks->Delete() ;
541// delete ticks ;
88cb7938 542
9688c1dd 543 //Now CPV digits (different noise and no timing)
e250de8f 544 Int_t cpvpermod = geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() ;
545 Int_t nEMCtotal=emcpermod*5 ;
f898e0f3 546 Float_t cpvNoise = AliPHOSSimParam::GetInstance()->GetCPVNoise() ;
e250de8f 547 if(isCPVpresent){ //CPV is present in current geometry
548 for(Int_t imod=0; imod<5; imod++){ //module is present in current geometry
549 if(!isPresent[imod])
550 continue ;
551 Int_t firstAbsId=nEMCtotal+imod*cpvpermod+1 ;
552 Int_t lastAbsId =nEMCtotal+(imod+1)*cpvpermod ;
553 for(absID = firstAbsId; absID <= lastAbsId; absID++){
554 Float_t noise = gRandom->Gaus(0., cpvNoise) ;
555 new((*digits)[idigit]) AliPHOSDigit( -1,absID,noise, TimeOfNoise() ) ;
556 idigit++ ;
557 //look if we have to add signal?
558 if(absID==nextSig){
97e75f77 559 digit = static_cast<AliPHOSDigit *>(digits->At(idigit-1)) ;
e250de8f 560 //Add SDigits from all inputs
561 for(Int_t i = 0 ; i < fInput ; i++){
97e75f77 562 if( static_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
563 curSDigit = static_cast<AliPHOSDigit*>( static_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
e250de8f 564 else
565 curSDigit = 0 ;
566
567 //May be several digits will contribute from the same input
568 while(curSDigit && curSDigit->GetId() == absID){
569 //Shift primary to separate primaries belonging different inputs
570 Int_t primaryoffset ;
571 if(fManager)
572 primaryoffset = fManager->GetMask(i) ;
573 else
574 primaryoffset = 10000000*i ;
575 curSDigit->ShiftPrimary(primaryoffset) ;
576
577 //add energies
578 *digit += *curSDigit ;
579 index[i]++ ;
97e75f77 580 if( static_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
581 curSDigit = static_cast<AliPHOSDigit*>( static_cast<TClonesArray *>(sdigArray->At(i))->At(index[i]) ) ;
e250de8f 582 else
583 curSDigit = 0 ;
584 }
585 }
a6eedfad 586
e250de8f 587 //Find next signal module
588 nextSig = 200000 ;
589 for(Int_t i = 0 ; i < fInput ; i++){
97e75f77 590 sdigits = static_cast<TClonesArray *>(sdigArray->At(i)) ;
e250de8f 591 Int_t curNext = nextSig ;
592 if(sdigits->GetEntriesFast() > index[i] )
97e75f77 593 curNext = static_cast<AliPHOSDigit *>( sdigits->At(index[i]) )->GetId() ;
e250de8f 594 if(curNext < nextSig) nextSig = curNext ;
595 }
9688c1dd 596
e250de8f 597 }
598 }
9688c1dd 599 }
600 }
88cb7938 601
602 delete sdigArray ; //We should not delete its contents
9688c1dd 603
1dfe0f3c 604 Int_t relId[4];
605
606 //set amplitudes in bad channels to zero
f898e0f3 607
65fd5dc1 608 for(Int_t i = 0 ; i <digits->GetEntriesFast(); i++){
97e75f77 609 digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
f898e0f3 610 geom->AbsToRelNumbering(digit->GetId(),relId);
1dfe0f3c 611 if(relId[1] == 0) // Emc
f898e0f3 612 if(fcdb->IsBadChannelEmc(relId[0],relId[3],relId[2])) digit->SetEnergy(0.);
1dfe0f3c 613 }
614
990119d6 615 //remove digits below thresholds
f898e0f3 616 Float_t emcThreshold = AliPHOSSimParam::GetInstance()->GetEmcDigitsThreshold() ;
617 for(Int_t i = 0 ; i < nEMC ; i++){
97e75f77 618 digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
a28333c5 619
f898e0f3 620 if(digit->GetEnergy() < emcThreshold){
a6eedfad 621 digits->RemoveAt(i) ;
f898e0f3 622 continue ;
623 }
6f47f50d 624
54ac223e 625 geom->AbsToRelNumbering(digit->GetId(),relId);
626
dde7e19f 627// digit->SetEnergy(TMath::Ceil(digit->GetEnergy())-0.9999) ;
6f47f50d 628
f898e0f3 629 Float_t tres = TimeResolution(digit->GetEnergy()) ;
630 digit->SetTime(gRandom->Gaus(digit->GetTime(), tres) ) ;
54ac223e 631
632 fPulse->Reset();
633 fPulse->SetAmplitude(digit->GetEnergy()/
634 fcdb->GetADCchannelEmc(relId[0],relId[3],relId[2]));
635 fPulse->SetTZero(digit->GetTimeR());
636 fPulse->MakeSamples();
637 fPulse->GetSamples(fADCValuesHG, fADCValuesLG) ;
638 Int_t nSamples = fPulse->GetRawFormatTimeBins();
639 digit->SetALTROSamplesHG(nSamples,fADCValuesHG);
640 digit->SetALTROSamplesLG(nSamples,fADCValuesLG);
aaf8a71c 641 }
642
f898e0f3 643 Float_t cpvDigitThreshold = AliPHOSSimParam::GetInstance()->GetCpvDigitsThreshold() ;
644 for(Int_t i = nEMC; i < nCPV ; i++){
97e75f77 645 if( static_cast<AliPHOSDigit*>(digits->At(i))->GetEnergy() < cpvDigitThreshold )
a6eedfad 646 digits->RemoveAt(i) ;
f898e0f3 647 }
9688c1dd 648
7b7c1533 649 digits->Compress() ;
7b7c1533 650 Int_t ndigits = digits->GetEntriesFast() ;
a91822a8 651
3758d9fc 652 //Set indexes in list of digits and make true digitization of the energy
f898e0f3 653 for (Int_t i = 0 ; i < ndigits ; i++) {
97e75f77 654 digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
990119d6 655 digit->SetIndexInList(i) ;
27a73a5d 656 if(digit->GetId() > fEmcCrystals){ //digitize CPV only
877695e7 657 digit->SetAmp(DigitizeCPV(digit->GetEnergy(),digit->GetId()) ) ;
27a73a5d 658 }
990119d6 659 }
f898e0f3 660
7b7c1533 661}
737c795f 662//____________________________________________________________________________
663Float_t AliPHOSDigitizer::Calibrate(Float_t amp,Int_t absId){
664 //Apply calibration
665 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
548f0134 666
737c795f 667 //Determine rel.position of the cell absolute ID
668 Int_t relId[4];
669 geom->AbsToRelNumbering(absId,relId);
670 Int_t module=relId[0];
671 Int_t row =relId[2];
672 Int_t column=relId[3];
673 if(relId[1]==0){ //This Is EMC
674 Float_t calibration = fcdb->GetADCchannelEmc(module,column,row);
675 return amp*calibration ;
676 }
677 return 0 ;
678}
3758d9fc 679//____________________________________________________________________________
737c795f 680void AliPHOSDigitizer::Decalibrate(AliPHOSDigit *digit)
3758d9fc 681{
877695e7 682 // Decalibrate EMC digit, i.e. change its energy by a factor read from CDB
683
f898e0f3 684 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
877695e7 685
686 //Determine rel.position of the cell absolute ID
687 Int_t relId[4];
f898e0f3 688 geom->AbsToRelNumbering(digit->GetId(),relId);
877695e7 689 Int_t module=relId[0];
690 Int_t row =relId[2];
691 Int_t column=relId[3];
737c795f 692 if(relId[1]==0){ //This Is EMC
b30d19db 693 Float_t decalib = fcdb->GetADCchannelEmcDecalib(module,column,row); // O(1)
694 Float_t calibration = fcdb->GetADCchannelEmc(module,column,row)*decalib;
737c795f 695 Float_t energy = digit->GetEnergy()/calibration;
696 digit->SetEnergy(energy); //Now digit measures E in ADC counts
6f47f50d 697 Float_t time = digit->GetTime() ;
698 time-=fcdb->GetTimeShiftEmc(module,column,row);
699 digit->SetTime(time) ;
737c795f 700 }
877695e7 701}
702//____________________________________________________________________________
6f47f50d 703Float_t AliPHOSDigitizer::CalibrateT(Float_t time,Int_t absId){
704 //Apply time calibration
705 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
706
707 //Determine rel.position of the cell absolute ID
708 Int_t relId[4];
709 geom->AbsToRelNumbering(absId,relId);
710 Int_t module=relId[0];
711 Int_t row =relId[2];
712 Int_t column=relId[3];
713 time += fcdb->GetTimeShiftEmc(module,column,row);
714 return time ;
715}
716//____________________________________________________________________________
877695e7 717Int_t AliPHOSDigitizer::DigitizeCPV(Float_t charge, Int_t absId)
718{
719 // Returns digitized value of the CPV charge in a pad absId
0bc3b8ed 720
f898e0f3 721 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
fc6706cb 722
a8ec0771 723 //Determine rel.position of the cell absId
724 Int_t relId[4];
f898e0f3 725 geom->AbsToRelNumbering(absId,relId);
a8ec0771 726 Int_t module=relId[0];
27a73a5d 727 Int_t row =relId[2];
a8ec0771 728 Int_t column=relId[3];
729
877695e7 730 Int_t channel = 0;
a8ec0771 731
877695e7 732 if(absId > fEmcCrystals){ //digitize CPV only
a8ec0771 733
734 //reading calibration data for cell absId.
f898e0f3 735 Float_t adcPedestalCpv = fcdb->GetADCpedestalCpv(module,column,row);
736 Float_t adcChanelCpv = fcdb->GetADCchannelCpv( module,column,row);
a8ec0771 737
f898e0f3 738 channel = (Int_t) TMath::Ceil((charge - adcPedestalCpv)/adcChanelCpv) ;
739 Int_t nMax = AliPHOSSimParam::GetInstance()->GetNADCcpv() ;
740 if(channel > nMax ) channel = nMax ;
3758d9fc 741 }
877695e7 742 return channel ;
3758d9fc 743}
548f0134 744
7b7c1533 745//____________________________________________________________________________
746void AliPHOSDigitizer::Exec(Option_t *option)
747{
212d1c0f 748 // Steering method to process digitization for events
749 // in the range from fFirstEvent to fLastEvent.
750 // This range is optionally set by SetEventRange().
45fa49ca 751 // if fLastEvent=-1, then process events until the end.
752 // by default fLastEvent = fFirstEvent (process only one event)
88cb7938 753
754 if (!fInit) { // to prevent overwrite existing file
351dd634 755 AliError(Form("Give a version name different from %s",
756 fEventFolderName.Data() )) ;
88cb7938 757 return ;
758 }
990119d6 759
7b7c1533 760 if (strstr(option,"print")) {
88cb7938 761 Print();
7b7c1533 762 return ;
8cb3533f 763 }
990119d6 764
8661738e 765 if(strstr(option,"tim"))
766 gBenchmark->Start("PHOSDigitizer");
3f81a70b 767
f898e0f3 768 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
97e75f77 769 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
88cb7938 770
5b4d2c50 771 // Post Digitizer to the white board
f898e0f3 772 phosLoader->PostDigitizer(this) ;
5b4d2c50 773
212d1c0f 774 if (fLastEvent == -1)
f898e0f3 775 fLastEvent = rl->GetNumberOfEvents() - 1 ;
396a348e 776 else if (fManager)
777 fLastEvent = fFirstEvent ;
45fa49ca 778
212d1c0f 779 Int_t nEvents = fLastEvent - fFirstEvent + 1;
780
7b7c1533 781 Int_t ievent ;
88cb7938 782
212d1c0f 783 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
ddd1a39c 784 fEventCounter++ ;
b22e4735 785
7b7c1533 786 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 787
90cceaf6 788 WriteDigits() ;
88cb7938 789
01a599c9 790 if(strstr(option,"deb"))
791 PrintDigits(option);
94de8339 792
793 //increment the total number of Digits per run
f898e0f3 794 fDigitsInRun += phosLoader->Digits()->GetEntriesFast() ;
88cb7938 795 }
ddd1a39c 796
f898e0f3 797 phosLoader->CleanDigitizer();
5b4d2c50 798
8cb3533f 799 if(strstr(option,"tim")){
800 gBenchmark->Stop("PHOSDigitizer");
21cd0c07 801 TString message ;
802 message = " took %f seconds for Digitizing %f seconds per event\n" ;
351dd634 803 AliInfo(Form( message.Data(),
21cd0c07 804 gBenchmark->GetCpuTime("PHOSDigitizer"),
351dd634 805 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ));
21cd0c07 806 }
990119d6 807}
9688c1dd 808//____________________________________________________________________________
f898e0f3 809Float_t AliPHOSDigitizer::TimeResolution(Float_t e){
810 //calculate TOF resolution using beam-test resutls
811 Float_t a=AliPHOSSimParam::GetInstance()->GetTOFa() ;
812 Float_t b=AliPHOSSimParam::GetInstance()->GetTOFb() ;
813 return TMath::Sqrt(a*a+b*b/e) ;
9688c1dd 814}
8d0f3f77 815
f898e0f3 816////____________________________________________________________________________
817//Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
818//{
819// // Returns the shortest time among all time ticks
820//
821// ticks->Sort() ; //Sort in accordance with times of ticks
822// TIter it(ticks) ;
823// AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
824// Float_t time = ctick->CrossingTime(fTimeThreshold) ;
825//
826// AliPHOSTick * t ;
827// while((t=(AliPHOSTick*) it.Next())){
828// if(t->GetTime() < time) //This tick starts before crossing
829// *ctick+=*t ;
830// else
831// return time ;
832//
833// time = ctick->CrossingTime(fTimeThreshold) ;
834// }
835// return time ;
836//}
837
7b7c1533 838//____________________________________________________________________________
3f81a70b 839Bool_t AliPHOSDigitizer::Init()
8d0f3f77 840{
fbf811ec 841 // Makes all memory allocations
88cb7938 842 fInit = kTRUE ;
f898e0f3 843
bfae5a5d 844 AliPHOSGeometry *geom;
845 if (!(geom = AliPHOSGeometry::GetInstance()))
846 geom = AliPHOSGeometry::GetInstance("IHEP","");
847// const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
b22e4735 848
88cb7938 849 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
8d0f3f77 850
45fa49ca 851 fFirstEvent = 0 ;
852 fLastEvent = fFirstEvent ;
88cb7938 853 if (fManager)
854 fInput = fManager->GetNinputs() ;
855 else
856 fInput = 1 ;
857
858 fInputFileNames = new TString[fInput] ;
859 fEventNames = new TString[fInput] ;
860 fInputFileNames[0] = GetTitle() ;
861 fEventNames[0] = fEventFolderName.Data() ;
862 Int_t index ;
863 for (index = 1 ; index < fInput ; index++) {
97e75f77 864 fInputFileNames[index] = static_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
88cb7938 865 TString tempo = fManager->GetInputFolderName(index) ;
45fa49ca 866 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
8d0f3f77 867 }
88cb7938 868
869 //to prevent cleaning of this object while GetEvent is called
f898e0f3 870 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
871 if(!rl){
872 rl = AliRunLoader::Open(GetTitle(), fEventFolderName) ;
873 }
97e75f77 874 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 875 phosLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
88cb7938 876
877 return fInit ;
8d0f3f77 878}
879
880//____________________________________________________________________________
881void AliPHOSDigitizer::InitParameters()
a4e98857 882{
45fa49ca 883 // Set initial parameters Digitizer
0bc3b8ed 884
3758d9fc 885 fDigitsInRun = 0 ;
212d1c0f 886 SetEventRange(0,-1) ;
54ac223e 887 fPulse = new AliPHOSPulseGenerator();
888 fADCValuesLG = new Int_t[fPulse->GetRawFormatTimeBins()];
889 fADCValuesHG = new Int_t[fPulse->GetRawFormatTimeBins()];
8cb3533f 890
990119d6 891}
7b7c1533 892
990119d6 893//__________________________________________________________________
702ab87e 894void AliPHOSDigitizer::Print(const Option_t *)const
21cd0c07 895{
dd5c4038 896 // Print Digitizer's parameters
351dd634 897 AliInfo(Form("\n------------------- %s -------------", GetName() )) ;
88cb7938 898 if( strcmp(fEventFolderName.Data(), "") != 0 ){
899 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
900
901 Int_t nStreams ;
902 if (fManager)
903 nStreams = GetNInputStreams() ;
904 else
905 nStreams = fInput ;
906
907 Int_t index = 0 ;
908 for (index = 0 ; index < nStreams ; index++) {
909 TString tempo(fEventNames[index]) ;
910 tempo += index ;
f898e0f3 911 printf ("Adding SDigits from %s \n", fInputFileNames[index].Data()) ;
88cb7938 912 }
88cb7938 913
f898e0f3 914 // printf("\nWith following parameters:\n") ;
915 // printf(" Electronics noise in EMC (fPinNoise) = %f GeV\n", fPinNoise ) ;
916 // printf(" Threshold in EMC (fEMCDigitThreshold) = %f GeV\n", fEMCDigitThreshold ) ;
917 // printf(" Noise in CPV (fCPVNoise) = %f aux units\n", fCPVNoise ) ;
918 // printf(" Threshold in CPV (fCPVDigitThreshold) = %f aux units\n",fCPVDigitThreshold ) ;
88cb7938 919 printf(" ---------------------------------------------------\n") ;
990119d6 920 }
8cb3533f 921 else
351dd634 922 AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
8cb3533f 923
924}
88cb7938 925
8cb3533f 926//__________________________________________________________________
21cd0c07 927 void AliPHOSDigitizer::PrintDigits(Option_t * option)
928{
3bf72d32 929 // Print a table of digits
21cd0c07 930
f898e0f3 931
932 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
97e75f77 933 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 934 TClonesArray * digits = phosLoader->Digits() ;
935 const AliPHOSGeometry *geom = AliPHOSGeometry::GetInstance() ;
3bf72d32 936
351dd634 937 AliInfo(Form("%d", digits->GetEntriesFast())) ;
88cb7938 938 printf("\nevent %d", gAlice->GetEvNumber()) ;
939 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
940
11f9c5ff 941
3bf72d32 942 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 943 //loop over digits
944 AliPHOSDigit * digit;
88cb7938 945 printf("\nEMC digits (with primaries):\n") ;
946 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
f898e0f3 947 Int_t maxEmc = geom->GetNModules()*geom->GetNCristalsInModule() ;
8cb3533f 948 Int_t index ;
a6eedfad 949 for (index = 0 ; (index < digits->GetEntriesFast()) &&
97e75f77 950 (static_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 951 digit = (AliPHOSDigit * ) digits->At(index) ;
21cd0c07 952 if(digit->GetNprimary() == 0)
953 continue;
27a73a5d 954// printf("%6d %8d %6.5e %4d %2d :",
955// digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ; // YVK
956 printf("%6d %.4f %6.5e %4d %2d :",
957 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
8cb3533f 958 Int_t iprimary;
21cd0c07 959 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 960 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 961 }
81d5f731 962 printf("\n") ;
21cd0c07 963 }
9688c1dd 964 }
3bf72d32 965
9688c1dd 966 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 967
9688c1dd 968 //loop over CPV digits
969 AliPHOSDigit * digit;
88cb7938 970 printf("\nCPV digits (with primaries):\n") ;
971 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
f898e0f3 972 Int_t maxEmc = geom->GetNModules()*geom->GetNCristalsInModule() ;
9688c1dd 973 Int_t index ;
a6eedfad 974 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
9688c1dd 975 digit = (AliPHOSDigit * ) digits->At(index) ;
976 if(digit->GetId() > maxEmc){
81d5f731 977 printf("%6d %8d %4d %2d :",
11f9c5ff 978 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
9688c1dd 979 Int_t iprimary;
21cd0c07 980 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 981 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 982 }
81d5f731 983 printf("\n") ;
21cd0c07 984 }
9688c1dd 985 }
8cb3533f 986 }
88cb7938 987
8cb3533f 988}
7b7c1533 989
9688c1dd 990//__________________________________________________________________
0bc3b8ed 991Float_t AliPHOSDigitizer::TimeOfNoise(void) const
9688c1dd 992{ // Calculates the time signal generated by noise
26a2ef9d 993 //PH Info("TimeOfNoise", "Change me") ;
04f0bda3 994 return gRandom->Rndm() * 1.28E-5;
8cb3533f 995}
7b7c1533 996
88cb7938 997//__________________________________________________________________
998void AliPHOSDigitizer::Unload()
999{
1000
1001 Int_t i ;
1002 for(i = 1 ; i < fInput ; i++){
1003 TString tempo(fEventNames[i]) ;
1004 tempo += i ;
f898e0f3 1005 AliRunLoader* rl = AliRunLoader::GetRunLoader(tempo) ;
97e75f77 1006 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 1007 phosLoader->UnloadSDigits() ;
88cb7938 1008 }
1009
f898e0f3 1010 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
97e75f77 1011 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 1012 phosLoader->UnloadDigits() ;
88cb7938 1013}
1014
7b7c1533 1015//____________________________________________________________________________
90cceaf6 1016void AliPHOSDigitizer::WriteDigits()
7b7c1533 1017{
1018
1019 // Makes TreeD in the output file.
1020 // Check if branch already exists:
1021 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
1022 // already existing branches.
1023 // else creates branch with Digits, named "PHOS", title "...",
1024 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
1025 // and names of files, from which digits are made.
1026
f898e0f3 1027 AliRunLoader* rl = AliRunLoader::GetRunLoader(fEventFolderName) ;
97e75f77 1028 AliPHOSLoader * phosLoader = static_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
f898e0f3 1029
1030 const TClonesArray * digits = phosLoader->Digits() ;
1031 TTree * treeD = phosLoader->TreeD();
1032 if(!treeD){
1033 phosLoader->MakeTree("D");
1034 treeD = phosLoader->TreeD();
1035 }
1036
7b7c1533 1037 // -- create Digits branch
1038 Int_t bufferSize = 32000 ;
2524c56f 1039 TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
88cb7938 1040 digitsBranch->SetTitle(fEventFolderName);
1041 digitsBranch->Fill() ;
fbf811ec 1042
f898e0f3 1043 phosLoader->WriteDigits("OVERWRITE");
1044 phosLoader->WriteDigitizer("OVERWRITE");
88cb7938 1045
1046 Unload() ;
b3690abb 1047
7b7c1533 1048}