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