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