]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSDigitizer.cxx
Compilation warnings fixed
[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 ---
8cb3533f 59#include "TFile.h"
990119d6 60#include "TTree.h"
61#include "TSystem.h"
8cb3533f 62#include "TROOT.h"
63#include "TFolder.h"
64#include "TObjString.h"
b3690abb 65#include "TGeometry.h"
8cb3533f 66#include "TBenchmark.h"
ba54256b 67
990119d6 68// --- Standard library ---
69
70// --- AliRoot header files ---
8cb3533f 71#include "AliRun.h"
b3690abb 72#include "AliHeader.h"
ea5f3389 73#include "AliStream.h"
3f81a70b 74#include "AliRunDigitizer.h"
990119d6 75#include "AliPHOSDigit.h"
dd5c4038 76#include "AliPHOS.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//____________________________________________________________________________
88cb7938 100AliPHOSDigitizer::AliPHOSDigitizer(const TString alirunFileName, const TString eventFolderName):
101 AliDigitizer("PHOS"+AliConfig::fgkDigitizerTaskName, alirunFileName),
102 fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
3f81a70b 103{
104 // ctor
ea5f3389 105
8d0f3f77 106 InitParameters() ;
3f81a70b 107 Init() ;
92f521a9 108 fDefaultInit = kFALSE ;
88cb7938 109 fManager = 0 ; // We work in the standalong mode
110}
111
112//____________________________________________________________________________
113AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d)
a8c47ab6 114 : AliDigitizer(d)
88cb7938 115{
116 // copyy ctor
117
118 SetName(d.GetName()) ;
119 SetTitle(d.GetTitle()) ;
120 fPinNoise = d.fPinNoise ;
121 fEMCDigitThreshold = d.fEMCDigitThreshold ;
122 fCPVNoise = d.fCPVNoise ;
123 fCPVDigitThreshold = d.fCPVDigitThreshold ;
124 fTimeResolution = d.fTimeResolution ;
125 fTimeThreshold = d.fTimeThreshold ;
126 fTimeSignalLength = d.fTimeSignalLength ;
127 fADCchanelEmc = d.fADCchanelEmc ;
128 fADCpedestalEmc = d.fADCpedestalEmc ;
129 fNADCemc = d.fNADCemc ;
130 fADCchanelCpv = d.fADCchanelCpv ;
131 fADCpedestalCpv = d.fADCpedestalCpv ;
132 fNADCcpv = d.fNADCcpv ;
133 fEventFolderName = d.fEventFolderName;
990119d6 134}
135
990119d6 136//____________________________________________________________________________
88cb7938 137AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd):
138 AliDigitizer(rd,"PHOS"+AliConfig::fgkDigitizerTaskName),
139 fEventFolderName(0)
990119d6 140{
141 // ctor
88cb7938 142 fManager = rd ;
143 SetName(fManager->GetInputFolderName(0)) ;
144 // take title as name of stream 0
145 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
b22e4735 146 InitParameters() ;
88cb7938 147 Init() ;
fbf811ec 148 fDefaultInit = kFALSE ;
990119d6 149}
150
151//____________________________________________________________________________
152 AliPHOSDigitizer::~AliPHOSDigitizer()
153{
154 // dtor
88cb7938 155 delete [] fInputFileNames ;
156 delete [] fEventNames ;
157
990119d6 158}
159
160//____________________________________________________________________________
7b7c1533 161void AliPHOSDigitizer::Digitize(const Int_t event)
a4e98857 162{
163
164 // Makes the digitization of the collected summable digits.
165 // It first creates the array of all PHOS modules
166 // filled with noise (different for EMC, CPV and PPSD) and
167 // then adds contributions from SDigits.
168 // This design avoids scanning over the list of digits to add
169 // contribution to new SDigits only.
990119d6 170
88cb7938 171 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
172 TClonesArray * digits = gime->Digits() ;
7b7c1533 173 digits->Clear() ;
990119d6 174
7b7c1533 175 const AliPHOSGeometry *geom = gime->PHOSGeometry() ;
990119d6 176 //Making digits with noise, first EMC
177 Int_t nEMC = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ();
178
179 Int_t nCPV ;
990119d6 180 Int_t absID ;
990119d6 181
88cb7938 182 nCPV = nEMC + geom->GetNumberOfCPVPadsZ() * geom->GetNumberOfCPVPadsPhi() * geom->GetNModules() ;
183
9688c1dd 184 digits->Expand(nCPV) ;
8cb3533f 185
88cb7938 186 // get first the sdigitizer from the tasks list
187 if ( !gime->SDigitizer() )
188 gime->LoadSDigitizer();
189 AliPHOSSDigitizer * sDigitizer = gime->SDigitizer();
190
191 if ( !sDigitizer )
192 Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ;
193
194 //take all the inputs to add together and load the SDigits
195 TObjArray * sdigArray = new TObjArray(fInput) ;
196 sdigArray->AddAt(gime->SDigits(), 0) ;
197 Int_t i ;
198 for(i = 1 ; i < fInput ; i++){
199 TString tempo(fEventNames[i]) ;
200 tempo += i ;
201 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
202 gime->Event(event,"S");
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{
88cb7938 392 // Does the job
393
394 if (!fInit) { // to prevent overwrite existing file
395 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
396 return ;
397 }
990119d6 398
7b7c1533 399 if (strstr(option,"print")) {
88cb7938 400 Print();
7b7c1533 401 return ;
8cb3533f 402 }
990119d6 403
7b7c1533 404 if(strstr(option,"tim"))
405 gBenchmark->Start("PHOSDigitizer");
3f81a70b 406
88cb7938 407 if (fManager)
408 fInput = fManager->GetNinputs() ;
3f81a70b 409
88cb7938 410 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
411
412 Int_t nevents = gime->MaxEvent() ;
8cb3533f 413
7b7c1533 414 Int_t ievent ;
88cb7938 415
7b7c1533 416 for(ievent = 0; ievent < nevents; ievent++){
88cb7938 417
418 gime->Event(ievent,"S") ;
b22e4735 419
7b7c1533 420 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 421
90cceaf6 422 WriteDigits() ;
88cb7938 423
01a599c9 424 if(strstr(option,"deb"))
425 PrintDigits(option);
94de8339 426
427 //increment the total number of Digits per run
428 fDigitsInRun += gime->Digits()->GetEntriesFast() ;
88cb7938 429 }
430
8cb3533f 431 if(strstr(option,"tim")){
432 gBenchmark->Stop("PHOSDigitizer");
21cd0c07 433 TString message ;
434 message = " took %f seconds for Digitizing %f seconds per event\n" ;
435 Info("Exec", message.Data(),
436 gBenchmark->GetCpuTime("PHOSDigitizer"),
437 gBenchmark->GetCpuTime("PHOSDigitizer")/nevents );
438 }
990119d6 439}
440
9688c1dd 441//____________________________________________________________________________
0bc3b8ed 442Float_t AliPHOSDigitizer::FrontEdgeTime(TClonesArray * ticks) const
443{
444 // Returns the shortest time among all time ticks
445
7437a0f7 446 ticks->Sort() ; //Sort in accordance with times of ticks
447 TIter it(ticks) ;
448 AliPHOSTick * ctick = (AliPHOSTick *) it.Next() ;
449 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
450
451 AliPHOSTick * t ;
452 while((t=(AliPHOSTick*) it.Next())){
453 if(t->GetTime() < time) //This tick starts before crossing
454 *ctick+=*t ;
455 else
456 return time ;
457
458 time = ctick->CrossingTime(fTimeThreshold) ;
9688c1dd 459 }
460 return time ;
9688c1dd 461}
8d0f3f77 462
7b7c1533 463//____________________________________________________________________________
3f81a70b 464Bool_t AliPHOSDigitizer::Init()
8d0f3f77 465{
fbf811ec 466 // Makes all memory allocations
88cb7938 467 fInit = kTRUE ;
468 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
8d0f3f77 469 if ( gime == 0 ) {
88cb7938 470 Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;
8d0f3f77 471 return kFALSE;
472 }
473
474 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
b22e4735 475
88cb7938 476 fEmcCrystals = geom->GetNModules() * geom->GetNCristalsInModule() ;
8d0f3f77 477
88cb7938 478 TString opt("Digits") ;
479 if(gime->VersionExists(opt) ) {
480 Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
481 fInit = kFALSE ;
482 }
483
8d0f3f77 484 // Post Digitizer to the white board
485 gime->PostDigitizer(this) ;
486
88cb7938 487 if (fManager)
488 fInput = fManager->GetNinputs() ;
489 else
490 fInput = 1 ;
491
492 fInputFileNames = new TString[fInput] ;
493 fEventNames = new TString[fInput] ;
494 fInputFileNames[0] = GetTitle() ;
495 fEventNames[0] = fEventFolderName.Data() ;
496 Int_t index ;
497 for (index = 1 ; index < fInput ; index++) {
498 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
499 TString tempo = fManager->GetInputFolderName(index) ;
500 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager
8d0f3f77 501 }
88cb7938 502
503 //to prevent cleaning of this object while GetEvent is called
504 gime->PhosLoader()->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
505
506 return fInit ;
8d0f3f77 507}
508
509//____________________________________________________________________________
510void AliPHOSDigitizer::InitParameters()
a4e98857 511{
0bc3b8ed 512 // Set initial parameters for Digitizer
513
c74936f1 514 fPinNoise = 0.004 ;
515 fEMCDigitThreshold = 0.012 ;
3758d9fc 516 fCPVNoise = 0.01;
517 fCPVDigitThreshold = 0.09 ;
aaf8a71c 518 fTimeResolution = 0.5e-9 ;
3758d9fc 519 fTimeSignalLength = 1.0e-9 ;
520 fDigitsInRun = 0 ;
521 fADCchanelEmc = 0.0015; // width of one ADC channel in GeV
522 fADCpedestalEmc = 0.005 ; //
523 fNADCemc = (Int_t) TMath::Power(2,16) ; // number of channels in EMC ADC
524
525 fADCchanelCpv = 0.0012 ; // width of one ADC channel in CPV 'popugais'
526 fADCpedestalCpv = 0.012 ; //
527 fNADCcpv = (Int_t) TMath::Power(2,12); // number of channels in CPV ADC
528
529 fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
8cb3533f 530
990119d6 531}
7b7c1533 532
990119d6 533//__________________________________________________________________
88cb7938 534void AliPHOSDigitizer::MixWith(const TString alirunFileName, const TString eventFolderName)
a4e98857 535{
ba54256b 536 // Allows to produce digits by superimposing background and signal event.
bca3b32a 537 // It is assumed, that headers file with SIGNAL events is opened in
a4e98857 538 // the constructor.
539 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
540 // Thus we avoid writing (changing) huge and expensive
bca3b32a 541 // backgound files: all output will be writen into SIGNAL, i.e.
542 // opened in constructor file.
543 //
a4e98857 544 // One can open as many files to mix with as one needs.
7b7c1533 545 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
546 // can be mixed.
bca3b32a 547
88cb7938 548 if( strcmp(fEventFolderName, "") == 0 )
8cb3533f 549 Init() ;
550
9891b76e 551 if(fManager){
88cb7938 552 Warning("MixWith", "Cannot use this method with AliRunDigitizer\n" ) ;
3f81a70b 553 return ;
554 }
88cb7938 555 // looking for file which contains AliRun
556 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
557 Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
558 return ;
990119d6 559 }
88cb7938 560 // looking for the file which contains SDigits
561 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
562 TString fileName( gime->GetSDigitsFileName() ) ;
563 if ( eventFolderName != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
564 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
565 if ( (gSystem->AccessPathName(fileName)) ) {
566 Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
567 return ;
7b7c1533 568 }
88cb7938 569 // need to increase the arrays
570 TString tempo = fInputFileNames[fInput-1] ;
571 delete [] fInputFileNames ;
572 fInputFileNames = new TString[fInput+1] ;
573 fInputFileNames[fInput-1] = tempo ;
574
575 tempo = fEventNames[fInput-1] ;
576 delete [] fEventNames ;
577 fEventNames = new TString[fInput+1] ;
578 fEventNames[fInput-1] = tempo ;
579
580 fInputFileNames[fInput] = alirunFileName ;
581 fEventNames[fInput] = eventFolderName ;
582 fInput++ ;
990119d6 583}
7b7c1533 584
990119d6 585//__________________________________________________________________
88cb7938 586void AliPHOSDigitizer::Print()const
21cd0c07 587{
dd5c4038 588 // Print Digitizer's parameters
88cb7938 589 Info("Print", "\n------------------- %s -------------", GetName() ) ;
590 if( strcmp(fEventFolderName.Data(), "") != 0 ){
591 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
592
593 Int_t nStreams ;
594 if (fManager)
595 nStreams = GetNInputStreams() ;
596 else
597 nStreams = fInput ;
598
599 Int_t index = 0 ;
600 for (index = 0 ; index < nStreams ; index++) {
601 TString tempo(fEventNames[index]) ;
602 tempo += index ;
603 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[index], tempo) ;
604 TString fileName( gime->GetSDigitsFileName() ) ;
605 if ( fEventNames[index] != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
606 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
607 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
608 }
609 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
610 printf("\nWriting digits to %s", gime->GetDigitsFileName().Data()) ;
611
612 printf("\nWith following parameters:\n") ;
613 printf(" Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise ) ;
614 printf(" Threshold in EMC (fEMCDigitThreshold) = %f\n", fEMCDigitThreshold ) ;
615 printf(" Noise in CPV (fCPVNoise) = %f\n", fCPVNoise ) ;
616 printf(" Threshold in CPV (fCPVDigitThreshold) = %f\n",fCPVDigitThreshold ) ;
617 printf(" ---------------------------------------------------\n") ;
990119d6 618 }
8cb3533f 619 else
88cb7938 620 Info("Print", "AliPHOSDigitizer not initialized" ) ;
8cb3533f 621
622}
88cb7938 623
8cb3533f 624//__________________________________________________________________
21cd0c07 625 void AliPHOSDigitizer::PrintDigits(Option_t * option)
626{
3bf72d32 627 // Print a table of digits
21cd0c07 628
88cb7938 629 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
3bf72d32 630 TClonesArray * digits = gime->Digits() ;
631
88cb7938 632 Info("PrintDigits", "%d", digits->GetEntriesFast()) ;
633 printf("\nevent %d", gAlice->GetEvNumber()) ;
634 printf("\n Number of entries in Digits list %d", digits->GetEntriesFast() ) ;
635
11f9c5ff 636
3bf72d32 637 if(strstr(option,"all")||strstr(option,"EMC")){
8cb3533f 638 //loop over digits
639 AliPHOSDigit * digit;
88cb7938 640 printf("\nEMC digits (with primaries):\n") ;
641 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
9688c1dd 642 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
8cb3533f 643 Int_t index ;
a6eedfad 644 for (index = 0 ; (index < digits->GetEntriesFast()) &&
88cb7938 645 (dynamic_cast<AliPHOSDigit *>(digits->At(index))->GetId() <= maxEmc) ; index++) {
7b7c1533 646 digit = (AliPHOSDigit * ) digits->At(index) ;
21cd0c07 647 if(digit->GetNprimary() == 0)
648 continue;
81d5f731 649 printf("%6d %8d %6.5e %4d %2d :",
11f9c5ff 650 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
8cb3533f 651 Int_t iprimary;
21cd0c07 652 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 653 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 654 }
81d5f731 655 printf("\n") ;
21cd0c07 656 }
9688c1dd 657 }
3bf72d32 658
9688c1dd 659 if(strstr(option,"all")||strstr(option,"CPV")){
8cb3533f 660
9688c1dd 661 //loop over CPV digits
662 AliPHOSDigit * digit;
88cb7938 663 printf("\nCPV digits (with primaries):\n") ;
664 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
9688c1dd 665 Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ;
666 Int_t index ;
a6eedfad 667 for (index = 0 ; index < digits->GetEntriesFast(); index++) {
9688c1dd 668 digit = (AliPHOSDigit * ) digits->At(index) ;
669 if(digit->GetId() > maxEmc){
81d5f731 670 printf("%6d %8d %4d %2d :",
11f9c5ff 671 digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;
9688c1dd 672 Int_t iprimary;
21cd0c07 673 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 674 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
21cd0c07 675 }
81d5f731 676 printf("\n") ;
21cd0c07 677 }
9688c1dd 678 }
8cb3533f 679 }
88cb7938 680
8cb3533f 681}
7b7c1533 682
9688c1dd 683//__________________________________________________________________
0bc3b8ed 684Float_t AliPHOSDigitizer::TimeOfNoise(void) const
9688c1dd 685{ // Calculates the time signal generated by noise
686 //to be rewritten, now returns just big number
687 return 1. ;
688
8cb3533f 689}
7b7c1533 690
88cb7938 691//__________________________________________________________________
692void AliPHOSDigitizer::Unload()
693{
694
695 Int_t i ;
696 for(i = 1 ; i < fInput ; i++){
697 TString tempo(fEventNames[i]) ;
698 tempo += i ;
699 AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
700 gime->PhosLoader()->UnloadSDigits() ;
701 }
702
703 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
704 gime->PhosLoader()->UnloadDigits() ;
705}
706
7b7c1533 707//____________________________________________________________________________
90cceaf6 708void AliPHOSDigitizer::WriteDigits()
7b7c1533 709{
710
711 // Makes TreeD in the output file.
712 // Check if branch already exists:
713 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
714 // already existing branches.
715 // else creates branch with Digits, named "PHOS", title "...",
716 // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
717 // and names of files, from which digits are made.
718
88cb7938 719 AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ;
720 const TClonesArray * digits = gime->Digits() ;
721 TTree * treeD = gime->TreeD();
722
7b7c1533 723 // -- create Digits branch
724 Int_t bufferSize = 32000 ;
ba54256b 725 TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
88cb7938 726 digitsBranch->SetTitle(fEventFolderName);
727 digitsBranch->Fill() ;
fbf811ec 728
88cb7938 729 gime->WriteDigits("OVERWRITE");
730 gime->WriteDigitizer("OVERWRITE");
731
732 Unload() ;
b3690abb 733
7b7c1533 734}