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