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