]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigitizer.cxx
Runloader is updated when moving to next file (quick fix).
[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 *
20 * $Log$
1a197b77 21 * Revision 1.94 2007/02/01 10:34:47 hristov
22 * Removing warnings on Solaris x86
23 *
ad4aeaf4 24 * Revision 1.93 2006/10/17 13:17:01 kharlov
25 * Replace AliInfo by AliDebug
26 *
d6e8d7d3 27 * Revision 1.92 2006/08/28 10:01:56 kharlov
28 * Effective C++ warnings fixed (Timur Pocheptsov)
29 *
3663622c 30 * Revision 1.91 2006/04/29 20:25:30 hristov
31 * Decalibration is implemented (Yu.Kharlov)
32 *
877695e7 33 * Revision 1.90 2006/04/22 10:30:17 hristov
34 * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
35 *
27a73a5d 36 * Revision 1.89 2006/04/11 15:22:59 hristov
37 * run number in query set to -1: forces AliCDBManager to use its run number (A.Colla)
38 *
28871337 39 * Revision 1.88 2006/03/13 14:05:43 kharlov
40 * Calibration objects for EMC and CPV
41 *
fc6706cb 42 * Revision 1.87 2005/08/24 15:33:49 kharlov
43 * Calibration data for raw digits
44 *
a8ec0771 45 * Revision 1.86 2005/07/12 20:07:35 hristov
46 * Changes needed to run simulation and reconstrruction in the same AliRoot session
47 *
7c193632 48 * Revision 1.85 2005/05/28 14:19:04 schutz
49 * Compilation warnings fixed by T.P.
50 *
702ab87e 51 */
88cb7938 52
990119d6 53//_________________________________________________________________________
990119d6 54//*-- Author : Dmitri Peressounko (SUBATECH & Kurchatov Institute)
55//////////////////////////////////////////////////////////////////////////////
a4e98857 56// This TTask performs digitization of Summable digits (in the PHOS case it is just
57// the sum of contributions from all primary particles into a given cell).
990119d6 58// In addition it performs mixing of summable digits from different events.
7b7c1533 59// The name of the TTask is also the title of the branch that will contain
60// the created SDigits
61// The title of the TTAsk is the name of the file that contains the hits from
62// which the SDigits are created
bca3b32a 63//
64// For each event two branches are created in TreeD:
65// "PHOS" - list of digits
66// "AliPHOSDigitizer" - AliPHOSDigitizer with all parameters used in digitization
67//
a4e98857 68// Note, that one can set a title for new digits branch, and repeat digitization with
bca3b32a 69// another set of parameters.
70//
a4e98857 71// Use case:
990119d6 72// root[0] AliPHOSDigitizer * d = new AliPHOSDigitizer() ;
73// root[1] d->ExecuteTask()
74// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
75// //Digitizes SDigitis in all events found in file galice.root
bca3b32a 76//
8cb3533f 77// root[2] AliPHOSDigitizer * d1 = new AliPHOSDigitizer("galice1.root") ;
78// // Will read sdigits from galice1.root
79// root[3] d1->MixWith("galice2.root")
990119d6 80// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
a4e98857 81// // Reads another set of sdigits from galice2.root
8cb3533f 82// root[3] d1->MixWith("galice3.root")
a4e98857 83// // Reads another set of sdigits from galice3.root
8cb3533f 84// root[4] d->ExecuteTask("deb timing")
85// // Reads SDigits from files galice1.root, galice2.root ....
86// // mixes them and stores produced Digits in file galice1.root
87// // deb - prints number of produced digits
88// // deb all - prints list of produced digits
89// // timing - prints time used for digitization
990119d6 90//
990119d6 91
92// --- ROOT system ---
990119d6 93#include "TTree.h"
94#include "TSystem.h"
8cb3533f 95#include "TBenchmark.h"
e957fea8 96#include "TRandom.h"
ba54256b 97
990119d6 98// --- Standard library ---
99
100// --- AliRoot header files ---
351dd634 101#include "AliLog.h"
3f81a70b 102#include "AliRunDigitizer.h"
990119d6 103#include "AliPHOSDigit.h"
7b7c1533 104#include "AliPHOSGetter.h"
990119d6 105#include "AliPHOSDigitizer.h"
106#include "AliPHOSSDigitizer.h"
8cb3533f 107#include "AliPHOSGeometry.h"
7437a0f7 108#include "AliPHOSTick.h"
990119d6 109
110ClassImp(AliPHOSDigitizer)
111
112
113//____________________________________________________________________________
3663622c 114AliPHOSDigitizer::AliPHOSDigitizer() :
115 AliDigitizer("",""),
116 fDefaultInit(kTRUE),
117 fDigitsInRun(0),
118 fInit(kFALSE),
119 fInput(0),
120 fInputFileNames(0x0),
121 fEventNames(0x0),
122 fEmcCrystals(0),
123 fPinNoise(0.f),
124 fEMCDigitThreshold(0.f),
125 fCPVNoise(0.f),
126 fCPVDigitThreshold(0.f),
127 fTimeResolution(0.f),
128 fTimeThreshold(0.f),
129 fTimeSignalLength(0.f),
130 fADCchanelEmc(0.f),
131 fADCpedestalEmc(0.f),
132 fNADCemc(0),
133 fADCchanelCpv(0.f),
134 fADCpedestalCpv(0.f),
135 fNADCcpv(0),
136 fEventFolderName(""),
137 fFirstEvent(0),
138 fLastEvent(0)
990119d6 139{
140 // ctor
8d0f3f77 141 InitParameters() ;
fbf811ec 142 fManager = 0 ; // We work in the standalong mode
88cb7938 143}
3f81a70b 144
145//____________________________________________________________________________
e191bb57 146AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName,
147 TString eventFolderName):
3663622c 148 AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
149 fDefaultInit(kFALSE),
150 fDigitsInRun(0),
151 fInit(kFALSE),
152 fInput(0),
153 fInputFileNames(0x0),
154 fEventNames(0x0),
155 fEmcCrystals(0),
156 fPinNoise(0.f),
157 fEMCDigitThreshold(0.f),
158 fCPVNoise(0.f),
159 fCPVDigitThreshold(0.f),
160 fTimeResolution(0.f),
161 fTimeThreshold(0.f),
162 fTimeSignalLength(0.f),
163 fADCchanelEmc(0.f),
164 fADCpedestalEmc(0.f),
165 fNADCemc(0),
166 fADCchanelCpv(0.f),
167 fADCpedestalCpv(0.f),
168 fNADCcpv(0),
169 fEventFolderName(eventFolderName),
170 fFirstEvent(0),
171 fLastEvent(0)
3f81a70b 172{
173 // ctor
8d0f3f77 174 InitParameters() ;
3f81a70b 175 Init() ;
92f521a9 176 fDefaultInit = kFALSE ;
88cb7938 177 fManager = 0 ; // We work in the standalong mode
178}
179
180//____________________________________________________________________________
3663622c 181AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d) :
182 AliDigitizer(d),
183 fDefaultInit(d.fDefaultInit),
184 fDigitsInRun(d.fDigitsInRun),
185 fInit(d.fInit),
186 fInput(d.fInput),
187 fInputFileNames(0x0),//?
188 fEventNames(0x0),//?
189 fEmcCrystals(d.fEmcCrystals),
190 fPinNoise(d.fPinNoise),
191 fEMCDigitThreshold(d.fEMCDigitThreshold),
192 fCPVNoise(d.fCPVNoise),
193 fCPVDigitThreshold(d.fCPVDigitThreshold),
194 fTimeResolution(d.fTimeResolution),
195 fTimeThreshold(d.fTimeThreshold),
196 fTimeSignalLength(d.fTimeSignalLength),
197 fADCchanelEmc(d.fADCchanelEmc),
198 fADCpedestalEmc(d.fADCpedestalEmc),
199 fNADCemc(d.fNADCemc),
200 fADCchanelCpv(d.fADCchanelCpv),
201 fADCpedestalCpv(d.fADCpedestalCpv),
202 fNADCcpv(d.fNADCcpv),
203 fEventFolderName(d.fEventFolderName),
204 fFirstEvent(d.fFirstEvent),
205 fLastEvent(d.fLastEvent)
88cb7938 206{
207 // copyy ctor
88cb7938 208 SetName(d.GetName()) ;
209 SetTitle(d.GetTitle()) ;
990119d6 210}
211
990119d6 212//____________________________________________________________________________
3663622c 213AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd) :
214 AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
215 fDefaultInit(kFALSE),
216 fDigitsInRun(0),
217 fInit(kFALSE),
218 fInput(0),
219 fInputFileNames(0x0),
220 fEventNames(0x0),
221 fEmcCrystals(0),
222 fPinNoise(0.f),
223 fEMCDigitThreshold(0.f),
224 fCPVNoise(0.f),
225 fCPVDigitThreshold(0.f),
226 fTimeResolution(0.f),
227 fTimeThreshold(0.f),
228 fTimeSignalLength(0.f),
229 fADCchanelEmc(0.f),
230 fADCpedestalEmc(0.f),
231 fNADCemc(0),
232 fADCchanelCpv(0.f),
233 fADCpedestalCpv(0.f),
234 fNADCcpv(0),
235 fEventFolderName(fManager->GetInputFolderName(0)),
236 fFirstEvent(0),
237 fLastEvent(0)
990119d6 238{
45fa49ca 239 // ctor Init() is called by RunDigitizer
88cb7938 240 fManager = rd ;
88cb7938 241 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
b22e4735 242 InitParameters() ;
fbf811ec 243 fDefaultInit = kFALSE ;
990119d6 244}
245
246//____________________________________________________________________________
247 AliPHOSDigitizer::~AliPHOSDigitizer()
248{
7c193632 249 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
250
251 // Clean Digitizer from the white board
252 gime->PhosLoader()->CleanDigitizer() ;
990119d6 253 // dtor
88cb7938 254 delete [] fInputFileNames ;
255 delete [] fEventNames ;
256
990119d6 257}
258
259//____________________________________________________________________________
fc7e2f43 260void AliPHOSDigitizer::Digitize(Int_t event)
a4e98857 261{
262
263 // Makes the digitization of the collected summable digits.
264 // It first creates the array of all PHOS modules
dc986a1d 265 // filled with noise (different for EMC, and CPV) and
a4e98857 266 // then adds contributions from SDigits.
267 // This design avoids scanning over the list of digits to add
268 // contribution to new SDigits only.
990119d6 269
f98c06a1 270 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
45fa49ca 271 Int_t ReadEvent = event ;
272 if (fManager)
273 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
d6e8d7d3 274 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
275 ReadEvent, GetTitle(), fEventFolderName.Data())) ;
45fa49ca 276 gime->Event(ReadEvent, "S") ;
88cb7938 277 TClonesArray * digits = gime->Digits() ;
7b7c1533 278 digits->Clear() ;
990119d6 279
7b7c1533 280 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
990119d6 281 //Making digits with noise, first EMC
282 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
283
284 Int_t nCPV ;
990119d6 285 Int_t absID ;
990119d6 286
88cb7938 287 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * geom->GetNModules() ;
288
9688c1dd 289 digits->Expand(nCPV) ;
8cb3533f 290
88cb7938 291 // get first the sdigitizer from the tasks list
292 if ( !gime->SDigitizer() )
293 gime->LoadSDigitizer();
294 AliPHOSSDigitizer * sDigitizer = gime->SDigitizer();
295
296 if ( !sDigitizer )
351dd634 297 AliFatal(Form("SDigitizer with name %s %s not found",
298 GetTitle(), fEventFolderName.Data() )) ;
88cb7938 299
300 //take all the inputs to add together and load the SDigits
301 TObjArray * sdigArray = new TObjArray(fInput) ;
302 sdigArray->AddAt(gime->SDigits(), 0) ;
303 Int_t i ;
304 for(i = 1 ; i < fInput ; i++){
305 TString tempo(fEventNames[i]) ;
306 tempo += i ;
ad4aeaf4 307 AliPHOSGetter * gime1 = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
45fa49ca 308 if (fManager)
309 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
351dd634 310 AliInfo(Form("Adding event %d from input stream %d %s %s",
311 ReadEvent, i, fInputFileNames[i].Data(), tempo.Data())) ;
ad4aeaf4 312 gime1->Event(ReadEvent,"S");
313 sdigArray->AddAt(gime1->SDigits(), i) ;
38bb0fd5 314 }
9688c1dd 315
27a73a5d 316 //Find the first crystal with signal
9688c1dd 317 Int_t nextSig = 200000 ;
88cb7938 318 TClonesArray * sdigits ;
319 for(i = 0 ; i < fInput ; i++){
320 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
a6eedfad 321 if ( !sdigits->GetEntriesFast() )
7a9d98f9 322 continue ;
88cb7938 323 Int_t curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(0))->GetId() ;
324 if(curNext < nextSig)
325 nextSig = curNext ;
9688c1dd 326 }
88cb7938 327
328 TArrayI index(fInput) ;
9688c1dd 329 index.Reset() ; //Set all indexes to zero
88cb7938 330
9688c1dd 331 AliPHOSDigit * digit ;
332 AliPHOSDigit * curSDigit ;
88cb7938 333
7437a0f7 334 TClonesArray * ticks = new TClonesArray("AliPHOSTick",1000) ;
88cb7938 335
9688c1dd 336 //Put Noise contribution
88cb7938 337 for(absID = 1 ; absID <= nEMC ; absID++){
9688c1dd 338 Float_t noise = gRandom->Gaus(0., fPinNoise) ;
27a73a5d 339 // YVK: do not digitize amplitudes for EMC
340// new((*digits)[absID-1]) AliPHOSDigit( -1, absID, sDigitizer->Digitize(noise), TimeOfNoise() ) ;
341 new((*digits)[absID-1]) AliPHOSDigit( -1, absID, noise, TimeOfNoise() ) ;
9688c1dd 342 //look if we have to add signal?
88cb7938 343 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
344
9688c1dd 345 if(absID==nextSig){
346 //Add SDigits from all inputs
7437a0f7 347 ticks->Clear() ;
9688c1dd 348 Int_t contrib = 0 ;
27a73a5d 349 Float_t a = digit->GetEnergy() ;
88cb7938 350 Float_t b = TMath::Abs( a / fTimeSignalLength) ;
351 //Mark the beginning of the signal
7437a0f7 352 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime(),0, b);
27a73a5d 353 //Mark the end of the signal
7437a0f7 354 new((*ticks)[contrib++]) AliPHOSTick(digit->GetTime()+fTimeSignalLength, -a, -b);
88cb7938 355
9688c1dd 356 //loop over inputs
88cb7938 357 for(i = 0 ; i < fInput ; i++){
358 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
359 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
5c9dfca0 360 else
361 curSDigit = 0 ;
9688c1dd 362 //May be several digits will contribute from the same input
363 while(curSDigit && curSDigit->GetId() == absID){
364 //Shift primary to separate primaries belonging different inputs
365 Int_t primaryoffset ;
9891b76e 366 if(fManager)
367 primaryoffset = fManager->GetMask(i) ;
9688c1dd 368 else
21c293b7 369 primaryoffset = 10000000*i ;
370 curSDigit->ShiftPrimary(primaryoffset) ;
7437a0f7 371
27a73a5d 372 a = curSDigit->GetEnergy() ;
7437a0f7 373 b = a /fTimeSignalLength ;
374 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime(),0, b);
375 new((*ticks)[contrib++]) AliPHOSTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
88cb7938 376
3663622c 377 *digit += *curSDigit ; //add energies
27a73a5d 378
9688c1dd 379 index[i]++ ;
88cb7938 380 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
381 curSDigit = dynamic_cast<AliPHOSDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
5c9dfca0 382 else
383 curSDigit = 0 ;
9688c1dd 384 }
385 }
88cb7938 386
9688c1dd 387 //calculate and set time
7437a0f7 388 Float_t time = FrontEdgeTime(ticks) ;
9688c1dd 389 digit->SetTime(time) ;
88cb7938 390
9688c1dd 391 //Find next signal module
7437a0f7 392 nextSig = 200000 ;
88cb7938 393 for(i = 0 ; i < fInput ; i++){
394 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
5c9dfca0 395 Int_t curNext = nextSig ;
396 if(sdigits->GetEntriesFast() > index[i] ){
88cb7938 397 curNext = dynamic_cast<AliPHOSDigit *>(sdigits->At(index[i]))->GetId() ;
5c9dfca0 398 }
9688c1dd 399 if(curNext < nextSig) nextSig = curNext ;
7b7c1533 400 }
401 }
990119d6 402 }
3f81a70b 403
7437a0f7 404 ticks->Delete() ;
405 delete ticks ;
88cb7938 406
9688c1dd 407 //Now CPV digits (different noise and no timing)
408 for(absID = nEMC+1; absID <= nCPV; absID++){
409 Float_t noise = gRandom->Gaus(0., fCPVNoise) ;
410 new((*digits)[absID-1]) AliPHOSDigit( -1,absID,sDigitizer->Digitize(noise), TimeOfNoise() ) ;
411 //look if we have to add signal?
412 if(absID==nextSig){
88cb7938 413 digit = dynamic_cast<AliPHOSDigit *>(digits->At(absID-1)) ;
9688c1dd 414 //Add SDigits from all inputs
88cb7938 415 for(i = 0 ; i < fInput ; i++){
416 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
417 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
5c9dfca0 418 else
419 curSDigit = 0 ;
a6eedfad 420
9688c1dd 421 //May be several digits will contribute from the same input
422 while(curSDigit && curSDigit->GetId() == absID){
423 //Shift primary to separate primaries belonging different inputs
424 Int_t primaryoffset ;
9891b76e 425 if(fManager)
426 primaryoffset = fManager->GetMask(i) ;
9688c1dd 427 else
428 primaryoffset = 10000000*i ;
429 curSDigit->ShiftPrimary(primaryoffset) ;
430
431 //add energies
3663622c 432 *digit += *curSDigit ;
9688c1dd 433 index[i]++ ;
88cb7938 434 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
435 curSDigit = dynamic_cast<AliPHOSDigit*>( dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i]) ) ;
5c9dfca0 436 else
437 curSDigit = 0 ;
9688c1dd 438 }
439 }
a6eedfad 440
9688c1dd 441 //Find next signal module
a6eedfad 442 nextSig = 200000 ;
88cb7938 443 for(i = 0 ; i < fInput ; i++){
444 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
5c9dfca0 445 Int_t curNext = nextSig ;
446 if(sdigits->GetEntriesFast() > index[i] )
88cb7938 447 curNext = dynamic_cast<AliPHOSDigit *>( sdigits->At(index[i]) )->GetId() ;
9688c1dd 448 if(curNext < nextSig) nextSig = curNext ;
449 }
450
451 }
452 }
88cb7938 453
454 delete sdigArray ; //We should not delete its contents
9688c1dd 455
990119d6 456 //remove digits below thresholds
88cb7938 457 for(i = 0 ; i < nEMC ; i++){
548f0134 458 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
877695e7 459 DecalibrateEMC(digit);
27a73a5d 460 if(digit->GetEnergy() < fEMCDigitThreshold)
a6eedfad 461 digits->RemoveAt(i) ;
aaf8a71c 462 else
463 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
464 }
465
a6eedfad 466
467 for(i = nEMC; i < nCPV ; i++)
27a73a5d 468// if( sDigitizer->Calibrate( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetAmp() ) < fCPVDigitThreshold )
469 if( dynamic_cast<AliPHOSDigit*>(digits->At(i))->GetEnergy() < fCPVDigitThreshold )
a6eedfad 470 digits->RemoveAt(i) ;
9688c1dd 471
7b7c1533 472 digits->Compress() ;
990119d6 473
7b7c1533 474 Int_t ndigits = digits->GetEntriesFast() ;
7b7c1533 475 digits->Expand(ndigits) ;
990119d6 476
3758d9fc 477 //Set indexes in list of digits and make true digitization of the energy
990119d6 478 for (i = 0 ; i < ndigits ; i++) {
548f0134 479 digit = dynamic_cast<AliPHOSDigit*>( digits->At(i) ) ;
990119d6 480 digit->SetIndexInList(i) ;
27a73a5d 481 if(digit->GetId() > fEmcCrystals){ //digitize CPV only
877695e7 482 digit->SetAmp(DigitizeCPV(digit->GetEnergy(),digit->GetId()) ) ;
27a73a5d 483 }
990119d6 484 }
7b7c1533 485}
548f0134 486
3758d9fc 487//____________________________________________________________________________
877695e7 488void AliPHOSDigitizer::DecalibrateEMC(AliPHOSDigit *digit)
3758d9fc 489{
877695e7 490 // Decalibrate EMC digit, i.e. change its energy by a factor read from CDB
491
492 AliPHOSGetter* gime = AliPHOSGetter::Instance();
493
494 if(!gime->CalibData()) {
495 AliPHOSCalibData* cdb = new AliPHOSCalibData(-1);
496 gime->SetCalibData(cdb);
497 }
498
499 //Determine rel.position of the cell absolute ID
500 Int_t relId[4];
501 gime->PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
502 Int_t module=relId[0];
503 Int_t row =relId[2];
504 Int_t column=relId[3];
505 Float_t decalibration = gime->CalibData()->GetADCchannelEmc(module,column,row);
1a197b77 506 Float_t energy = digit->GetEnergy() / decalibration;
877695e7 507 digit->SetEnergy(energy);
508}
509//____________________________________________________________________________
510Int_t AliPHOSDigitizer::DigitizeCPV(Float_t charge, Int_t absId)
511{
512 // Returns digitized value of the CPV charge in a pad absId
0bc3b8ed 513
a8ec0771 514 AliPHOSGetter* gime = AliPHOSGetter::Instance();
515
fc6706cb 516 if(!gime->CalibData()) {
28871337 517 AliPHOSCalibData* cdb = new AliPHOSCalibData(-1); // use AliCDBManager's run number
fc6706cb 518 gime->SetCalibData(cdb);
519 }
520
a8ec0771 521 //Determine rel.position of the cell absId
522 Int_t relId[4];
523 gime->PHOSGeometry()->AbsToRelNumbering(absId,relId);
524 Int_t module=relId[0];
27a73a5d 525 Int_t row =relId[2];
a8ec0771 526 Int_t column=relId[3];
527
877695e7 528 Int_t channel = 0;
a8ec0771 529
877695e7 530 if(absId > fEmcCrystals){ //digitize CPV only
a8ec0771 531
532 //reading calibration data for cell absId.
533 //If no calibration DB found, accept default values.
534
fc6706cb 535 if(gime->CalibData()) {
27a73a5d 536 fADCpedestalCpv = gime->CalibData()->GetADCpedestalCpv(module,column,row);
877695e7 537 fADCchanelCpv = gime->CalibData()->GetADCchannelCpv( module,column,row);
fc6706cb 538 }
539
877695e7 540 channel = (Int_t) TMath::Ceil((charge - fADCpedestalCpv)/fADCchanelCpv) ;
541 if(channel > fNADCcpv ) channel = fNADCcpv ;
3758d9fc 542 }
877695e7 543 return channel ;
3758d9fc 544}
548f0134 545
7b7c1533 546//____________________________________________________________________________
547void AliPHOSDigitizer::Exec(Option_t *option)
548{
212d1c0f 549 // Steering method to process digitization for events
550 // in the range from fFirstEvent to fLastEvent.
551 // This range is optionally set by SetEventRange().
45fa49ca 552 // if fLastEvent=-1, then process events until the end.
553 // by default fLastEvent = fFirstEvent (process only one event)
88cb7938 554
555 if (!fInit) { // to prevent overwrite existing file
351dd634 556 AliError(Form("Give a version name different from %s",
557 fEventFolderName.Data() )) ;
88cb7938 558 return ;
559 }
990119d6 560
7b7c1533 561 if (strstr(option,"print")) {
88cb7938 562 Print();
7b7c1533 563 return ;
8cb3533f 564 }
990119d6 565
7b7c1533 566 if(strstr(option,"tim"))
567 gBenchmark->Start("PHOSDigitizer");
3f81a70b 568
fb43ada4 569 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
88cb7938 570
5b4d2c50 571 // Post Digitizer to the white board
572 gime->PostDigitizer(this) ;
573
212d1c0f 574 if (fLastEvent == -1)
575 fLastEvent = gime->MaxEvent() - 1 ;
396a348e 576 else if (fManager)
577 fLastEvent = fFirstEvent ;
45fa49ca 578
212d1c0f 579 Int_t nEvents = fLastEvent - fFirstEvent + 1;
580
7b7c1533 581 Int_t ievent ;
88cb7938 582
212d1c0f 583 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
88cb7938 584
585 gime->Event(ievent,"S") ;
b22e4735 586
7b7c1533 587 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 588
90cceaf6 589 WriteDigits() ;
88cb7938 590
01a599c9 591 if(strstr(option,"deb"))
592 PrintDigits(option);
94de8339 593
594 //increment the total number of Digits per run
595 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
88cb7938 596 }
597
5b4d2c50 598 gime->PhosLoader()->CleanDigitizer();
599
8cb3533f 600 if(strstr(option,"tim")){
601 gBenchmark->Stop("PHOSDigitizer");
21cd0c07 602 TString message ;
603 message = " took %f seconds for Digitizing %f seconds per event\n" ;
351dd634 604 AliInfo(Form( message.Data(),
21cd0c07 605 gBenchmark->GetCpuTime("PHOSDigitizer"),
351dd634 606 gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ));
21cd0c07 607 }
990119d6 608}
609
9688c1dd 610//____________________________________________________________________________
0bc3b8ed 611Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
612{
613 // Returns the shortest time among all time ticks
614
7437a0f7 615 ticks->Sort() ; //Sort in accordance with times of ticks
616 TIter it(ticks) ;
617 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
618 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
619
620 AliPHOSTick * t ;
621 while((t=(AliPHOSTick*) it.Next())){
622 if(t->GetTime() < time) //This tick starts before crossing
623 *ctick+=*t ;
624 else
625 return time ;
626
627 time = ctick->CrossingTime(fTimeThreshold) ;
9688c1dd 628 }
629 return time ;
9688c1dd 630}
8d0f3f77 631
7b7c1533 632//____________________________________________________________________________
3f81a70b 633Bool_t AliPHOSDigitizer::Init()
8d0f3f77 634{
fbf811ec 635 // Makes all memory allocations
88cb7938 636 fInit = kTRUE ;
637 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
8d0f3f77 638 if ( gime == 0 ) {
351dd634 639 AliFatal(Form("Could not obtain the Getter object for file %s and event %s !",
640 GetTitle(), fEventFolderName.Data()));
8d0f3f77 641 return kFALSE;
642 }
643
644 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
b22e4735 645
88cb7938 646 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
8d0f3f77 647
88cb7938 648 TString opt("Digits") ;
649 if(gime->VersionExists(opt) ) {
351dd634 650 AliError(Form("Give a version name different from %s",
651 fEventFolderName.Data() )) ;
88cb7938 652 fInit = kFALSE ;
653 }
654
45fa49ca 655 fFirstEvent = 0 ;
656 fLastEvent = fFirstEvent ;
88cb7938 657 if (fManager)
658 fInput = fManager->GetNinputs() ;
659 else
660 fInput = 1 ;
661
662 fInputFileNames = new TString[fInput] ;
663 fEventNames = new TString[fInput] ;
664 fInputFileNames[0] = GetTitle() ;
665 fEventNames[0] = fEventFolderName.Data() ;
666 Int_t index ;
667 for (index = 1 ; index < fInput ; index++) {
668 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
669 TString tempo = fManager->GetInputFolderName(index) ;
45fa49ca 670 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
8d0f3f77 671 }
88cb7938 672
673 //to prevent cleaning of this object while GetEvent is called
674 gime->PhosLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
675
676 return fInit ;
8d0f3f77 677}
678
679//____________________________________________________________________________
680void AliPHOSDigitizer::InitParameters()
a4e98857 681{
45fa49ca 682 // Set initial parameters Digitizer
0bc3b8ed 683
27a73a5d 684 fPinNoise = 0.004 ; // [GeV]
685 fEMCDigitThreshold = 0.012 ; // [GeV]
686 fCPVNoise = 0.01; // [aux units]
687 fCPVDigitThreshold = 0.09 ; // [aux units]
688 fTimeResolution = 0.5e-9 ; // [sec]
689 fTimeSignalLength = 1.0e-9 ; // [sec]
3758d9fc 690 fDigitsInRun = 0 ;
877695e7 691 fADCchanelEmc = 1.0; // Coefficient between real and measured energies in EMC
692 fADCpedestalEmc = 0. ; //
3758d9fc 693 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
694
695 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
696 fADCpedestalCpv = 0.012 ; //
697 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
698
27a73a5d 699// fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
700 fTimeThreshold = 0.001 ; // [GeV]
212d1c0f 701 SetEventRange(0,-1) ;
8cb3533f 702
990119d6 703}
7b7c1533 704
990119d6 705//__________________________________________________________________
fc7e2f43 706void AliPHOSDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
a4e98857 707{
ba54256b 708 // Allows to produce digits by superimposing background and signal event.
bca3b32a 709 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 710 // the constructor.
711 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
712 // Thus we avoid writing (changing) huge and expensive
bca3b32a 713 // backgound files: all output will be writen into SIGNAL, i.e.
714 // opened in constructor file.
715 //
a4e98857 716 // One can open as many files to mix with as one needs.
7b7c1533 717 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
718 // can be mixed.
bca3b32a 719
88cb7938 720 if( strcmp(fEventFolderName, "") == 0 )
8cb3533f 721 Init() ;
722
9891b76e 723 if(fManager){
88cb7938 724 Warning("MixWith", "Cannot use this method with AliRunDigitizer\n" ) ;
3f81a70b 725 return ;
726 }
88cb7938 727 // looking for file which contains AliRun
728 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
351dd634 729 AliError(Form("File %s does not exist!", alirunFileName.Data())) ;
88cb7938 730 return ;
990119d6 731 }
88cb7938 732 // looking for the file which contains SDigits
733 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
734 TString fileName( gime->GetSDigitsFileName() ) ;
e191bb57 735 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 736 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
737 if ( (gSystem->AccessPathName(fileName)) ) {
351dd634 738 AliError(Form("The file %s does not exist!", fileName.Data())) ;
88cb7938 739 return ;
7b7c1533 740 }
88cb7938 741 // need to increase the arrays
742 TString tempo = fInputFileNames[fInput-1] ;
743 delete [] fInputFileNames ;
744 fInputFileNames = new TString[fInput+1] ;
745 fInputFileNames[fInput-1] = tempo ;
746
747 tempo = fEventNames[fInput-1] ;
748 delete [] fEventNames ;
749 fEventNames = new TString[fInput+1] ;
750 fEventNames[fInput-1] = tempo ;
751
752 fInputFileNames[fInput] = alirunFileName ;
753 fEventNames[fInput] = eventFolderName ;
754 fInput++ ;
990119d6 755}
7b7c1533 756
990119d6 757//__________________________________________________________________
702ab87e 758void AliPHOSDigitizer::Print(const Option_t *)const
21cd0c07 759{
dd5c4038 760 // Print Digitizer's parameters
351dd634 761 AliInfo(Form("\n------------------- %s -------------", GetName() )) ;
88cb7938 762 if( strcmp(fEventFolderName.Data(), "") != 0 ){
763 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
764
765 Int_t nStreams ;
766 if (fManager)
767 nStreams = GetNInputStreams() ;
768 else
769 nStreams = fInput ;
770
771 Int_t index = 0 ;
772 for (index = 0 ; index < nStreams ; index++) {
773 TString tempo(fEventNames[index]) ;
774 tempo += index ;
775 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[index], tempo) ;
776 TString fileName( gime->GetSDigitsFileName() ) ;
e191bb57 777 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 778 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
779 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
780 }
781 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
782 printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
783
784 printf("\nWith following parameters:\n") ;
27a73a5d 785 printf(" Electronics noise in EMC (fPinNoise) = %f GeV\n", fPinNoise ) ;
786 printf(" Threshold in EMC (fEMCDigitThreshold) = %f GeV\n", fEMCDigitThreshold ) ;
787 printf(" Noise in CPV (fCPVNoise) = %f aux units\n", fCPVNoise ) ;
788 printf(" Threshold in CPV (fCPVDigitThreshold) = %f aux units\n",fCPVDigitThreshold ) ;
88cb7938 789 printf(" ---------------------------------------------------\n") ;
990119d6 790 }
8cb3533f 791 else
351dd634 792 AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
8cb3533f 793
794}
88cb7938 795
8cb3533f 796//__________________________________________________________________
21cd0c07 797 void AliPHOSDigitizer::PrintDigits(Option_t * option)
798{
3bf72d32 799 // Print a table of digits
21cd0c07 800
88cb7938 801 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
3bf72d32 802 TClonesArray * digits = gime->Digits() ;
803
351dd634 804 AliInfo(Form("%d", digits->GetEntriesFast())) ;
88cb7938 805 printf("\nevent %d", gAlice->GetEvNumber()) ;
806 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
807
11f9c5ff 808
3bf72d32 809 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 810 //loop over digits
811 AliPHOSDigit * digit;
88cb7938 812 printf("\nEMC digits (with primaries):\n") ;
813 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
9688c1dd 814 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
8cb3533f 815 Int_t index ;
a6eedfad 816 for (index = 0 ; (index < digits->GetEntriesFast()) &&
88cb7938 817 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 818 digit = (AliPHOSDigit * ) digits->At(index) ;
21cd0c07 819 if(digit->GetNprimary() == 0)
820 continue;
27a73a5d 821// printf("%6d %8d %6.5e %4d %2d :",
822// digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ; // YVK
823 printf("%6d %.4f %6.5e %4d %2d :",
824 digit->GetId(), digit->GetEnergy(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
8cb3533f 825 Int_t iprimary;
21cd0c07 826 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 827 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 828 }
81d5f731 829 printf("\n") ;
21cd0c07 830 }
9688c1dd 831 }
3bf72d32 832
9688c1dd 833 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 834
9688c1dd 835 //loop over CPV digits
836 AliPHOSDigit * digit;
88cb7938 837 printf("\nCPV digits (with primaries):\n") ;
838 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
9688c1dd 839 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
840 Int_t index ;
a6eedfad 841 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
9688c1dd 842 digit = (AliPHOSDigit * ) digits->At(index) ;
843 if(digit->GetId() > maxEmc){
81d5f731 844 printf("%6d %8d %4d %2d :",
11f9c5ff 845 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
9688c1dd 846 Int_t iprimary;
21cd0c07 847 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 848 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 849 }
81d5f731 850 printf("\n") ;
21cd0c07 851 }
9688c1dd 852 }
8cb3533f 853 }
88cb7938 854
8cb3533f 855}
7b7c1533 856
9688c1dd 857//__________________________________________________________________
0bc3b8ed 858Float_t AliPHOSDigitizer::TimeOfNoise(void) const
9688c1dd 859{ // Calculates the time signal generated by noise
26a2ef9d 860 //PH Info("TimeOfNoise", "Change me") ;
04f0bda3 861 return gRandom->Rndm() * 1.28E-5;
8cb3533f 862}
7b7c1533 863
88cb7938 864//__________________________________________________________________
865void AliPHOSDigitizer::Unload()
866{
867
868 Int_t i ;
869 for(i = 1 ; i < fInput ; i++){
870 TString tempo(fEventNames[i]) ;
871 tempo += i ;
872 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
873 gime->PhosLoader()->UnloadSDigits() ;
874 }
875
876 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
877 gime->PhosLoader()->UnloadDigits() ;
878}
879
7b7c1533 880//____________________________________________________________________________
90cceaf6 881void AliPHOSDigitizer::WriteDigits()
7b7c1533 882{
883
884 // Makes TreeD in the output file.
885 // Check if branch already exists:
886 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
887 // already existing branches.
888 // else creates branch with Digits, named "PHOS", title "...",
889 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
890 // and names of files, from which digits are made.
891
f98c06a1 892 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
88cb7938 893 const TClonesArray * digits = gime->Digits() ;
894 TTree * treeD = gime->TreeD();
895
7b7c1533 896 // -- create Digits branch
897 Int_t bufferSize = 32000 ;
2524c56f 898 TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
88cb7938 899 digitsBranch->SetTitle(fEventFolderName);
900 digitsBranch->Fill() ;
fbf811ec 901
88cb7938 902 gime->WriteDigits("OVERWRITE");
903 gime->WriteDigitizer("OVERWRITE");
904
905 Unload() ;
b3690abb 906
7b7c1533 907}