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