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