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