removing jetfinder classes from main body of EMCAL code to subdirectory
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
CommitLineData
61e0abb5 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
18//_________________________________________________________________________
ffa6d63b 19//
61e0abb5 20//////////////////////////////////////////////////////////////////////////////
ffa6d63b 21// Class performs digitization of Summable digits
22//
61e0abb5 23// In addition it performs mixing of summable digits from different events.
24//
25// For each event two branches are created in TreeD:
26// "EMCAL" - list of digits
27// "AliEMCALDigitizer" - AliEMCALDigitizer with all parameters used in digitization
28//
29// Note, that one cset title for new digits branch, and repeat digitization with
30// another set of parameters.
31//
32// Examples of use:
33// root[0] AliEMCALDigitizer * d = new AliEMCALDigitizer() ;
34// root[1] d->ExecuteTask()
35// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
36// //Digitizes SDigitis in all events found in file galice.root
37//
38// root[2] AliEMCALDigitizer * d1 = new AliEMCALDigitizer("galice1.root") ;
39// // Will read sdigits from galice1.root
40// root[3] d1->MixWith("galice2.root")
41// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
42// // Reads another portion of sdigits from galice2.root
43// root[3] d1->MixWith("galice3.root")
44// // Reads another portion of sdigits from galice3.root
45// root[4] d->ExecuteTask("deb timing")
46// // Reads SDigits from files galice1.root, galice2.root ....
47// // mixes them and stores produced Digits in file galice1.root
48// // deb - prints number of produced digits
49// // deb all - prints list of produced digits
50// // timing - prints time used for digitization
ffa6d63b 51////////////////////////////////////////////////////////////////////////////////////
61e0abb5 52//
ffa6d63b 53//*-- Author: Sahal Yacoob (LBL)
814ad4bf 54// based on : AliEMCALDigitizer
05a92d59 55// Modif:
56// August 2002 Yves Schutz: clone PHOS as closely as possible and intoduction
57// of new IO (à la PHOS)
1963b290 58// November 2003 Aleksei Pavlinov : adopted for Shish-Kebab geometry
59//_________________________________________________________________________________
61e0abb5 60
61// --- ROOT system ---
1963b290 62#include "TROOT.h"
61e0abb5 63#include "TTree.h"
64#include "TSystem.h"
61e0abb5 65#include "TBenchmark.h"
1963b290 66#include "TList.h"
67#include "TH1.h"
68#include "TBrowser.h"
69#include "TObjectTable.h"
61e0abb5 70
71// --- AliRoot header files ---
ea5f3389 72#include "AliRunDigitizer.h"
5dee926e 73#include "AliRunLoader.h"
61e0abb5 74#include "AliEMCALDigit.h"
05a92d59 75#include "AliEMCAL.h"
5dee926e 76#include "AliEMCALLoader.h"
61e0abb5 77#include "AliEMCALDigitizer.h"
78#include "AliEMCALSDigitizer.h"
79#include "AliEMCALGeometry.h"
05a92d59 80#include "AliEMCALTick.h"
1963b290 81#include "AliEMCALJetMicroDst.h"
05a92d59 82
61e0abb5 83ClassImp(AliEMCALDigitizer)
84
85
86//____________________________________________________________________________
88cb7938 87 AliEMCALDigitizer::AliEMCALDigitizer():AliDigitizer("",""),
88 fInput(0),
89 fInputFileNames(0x0),
90 fEventNames(0x0)
61e0abb5 91{
92 // ctor
88cb7938 93 InitParameters() ;
92f521a9 94 fDefaultInit = kTRUE ;
05a92d59 95 fManager = 0 ; // We work in the standalong mode
88cb7938 96 fEventFolderName = "" ;
839828a6 97}
61e0abb5 98
839828a6 99//____________________________________________________________________________
09884213 100AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolderName):
e191bb57 101 AliDigitizer("EMCAL"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
88cb7938 102 fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
839828a6 103{
05a92d59 104 // ctor
105
a9485c37 106 InitParameters() ;
88cb7938 107 Init() ;
92f521a9 108 fDefaultInit = kFALSE ;
88cb7938 109 fManager = 0 ; // We work in the standalong mode
61e0abb5 110}
839828a6 111
61e0abb5 112//____________________________________________________________________________
9e5d2067 113AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d) : AliDigitizer(d)
88cb7938 114{
115 // copyy ctor
116
117 SetName(d.GetName()) ;
118 SetTitle(d.GetTitle()) ;
119 fDigitThreshold = d.fDigitThreshold ;
120 fMeanPhotonElectron = d.fMeanPhotonElectron ;
121 fPedestal = d.fPedestal ;
122 fSlope = d.fSlope ;
123 fPinNoise = d.fPinNoise ;
124 fTimeResolution = d.fTimeResolution ;
125 fTimeThreshold = d.fTimeThreshold ;
126 fTimeSignalLength = d.fTimeSignalLength ;
127 fADCchannelEC = d.fADCchannelEC ;
128 fADCpedestalEC = d.fADCpedestalEC ;
129 fNADCEC = d.fNADCEC ;
88cb7938 130 fEventFolderName = d.fEventFolderName;
131 }
132
133//____________________________________________________________________________
134AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd):
e191bb57 135 AliDigitizer(rd,"EMCAL"+AliConfig::Instance()->GetDigitizerTaskName()),
88cb7938 136 fEventFolderName(0)
61e0abb5 137{
45fa49ca 138 // ctor Init() is called by RunDigitizer
88cb7938 139 fManager = rd ;
e0e18b6d 140 fEventFolderName = fManager->GetInputFolderName(0) ;
88cb7938 141 SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
05a92d59 142 InitParameters() ;
dafd64d0 143 fDefaultInit = kFALSE ;
839828a6 144}
814ad4bf 145
839828a6 146//____________________________________________________________________________
147 AliEMCALDigitizer::~AliEMCALDigitizer()
148{
5dee926e 149 if (AliRunLoader::GetRunLoader()) {
150 AliLoader *emcalLoader=0;
151 if ((emcalLoader = AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL")))
152 emcalLoader->CleanDigitizer();
153 }
154 else
155 AliDebug(1," no runloader present");
f5f384f4 156 delete [] fInputFileNames ;
157 delete [] fEventNames ;
61e0abb5 158}
159
160//____________________________________________________________________________
09884213 161void AliEMCALDigitizer::Digitize(Int_t event)
05a92d59 162{
61e0abb5 163
164 // Makes the digitization of the collected summable digits
165 // for this it first creates the array of all EMCAL modules
166 // filled with noise (different for EMC, CPV and PPSD) and
167 // after that adds contributions from SDigits. This design
168 // helps to avoid scanning over the list of digits to add
169 // contribution of any new SDigit.
1963b290 170 static int isTrd1Geom = -1; // -1 - mean undefined
171 static int nEMC=0; //max number of digits possible
61e0abb5 172
5dee926e 173 AliRunLoader *rl = AliRunLoader::GetRunLoader();
174 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
45fa49ca 175 Int_t ReadEvent = event ;
1963b290 176 // fManager is data member from AliDigitizer
45fa49ca 177 if (fManager)
178 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ;
cf24bdc4 179 AliDebug(1,Form("Adding event %d from input stream 0 %s %s",
180 ReadEvent, GetTitle(), fEventFolderName.Data())) ;
5dee926e 181 rl->GetEvent(ReadEvent);
182
183 TClonesArray * digits = emcalLoader->Digits() ;
814ad4bf 184 digits->Clear() ;
61e0abb5 185
5dee926e 186 const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
1963b290 187 if(isTrd1Geom < 0) {
188 TString ng(geom->GetName());
189 isTrd1Geom = 0;
190 if(ng.Contains("SHISH") && ng.Contains("TRD1")) isTrd1Geom = 1;
fdebddeb 191
1963b290 192 if(isTrd1Geom == 0) nEMC = geom->GetNPhi()*geom->GetNZ();
193 else nEMC = geom->GetNCells();
5dee926e 194 AliDebug(1,Form("nEMC %i (number cells in EMCAL) | %s | isTrd1Geom %i\n", nEMC, geom->GetName(), isTrd1Geom));
1963b290 195 }
88cb7938 196 Int_t absID ;
61e0abb5 197
88cb7938 198 digits->Expand(nEMC) ;
05a92d59 199
88cb7938 200 // get first the sdigitizer from the tasks list (must have same name as the digitizer)
5dee926e 201 if ( !emcalLoader->SDigitizer() )
202 emcalLoader->LoadSDigitizer();
203 AliEMCALSDigitizer * sDigitizer = dynamic_cast<AliEMCALSDigitizer*>(emcalLoader->SDigitizer());
88cb7938 204
205 if ( !sDigitizer )
206 Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ;
207
208 //take all the inputs to add together and load the SDigits
209 TObjArray * sdigArray = new TObjArray(fInput) ;
5dee926e 210 sdigArray->AddAt(emcalLoader->SDigits(), 0) ;
88cb7938 211 Int_t i ;
5dee926e 212
88cb7938 213 for(i = 1 ; i < fInput ; i++){
214 TString tempo(fEventNames[i]) ;
215 tempo += i ;
5dee926e 216 rl = AliRunLoader::Open(fInputFileNames[i], tempo) ;
45fa49ca 217 if (fManager)
218 ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ;
b67f6b2d 219 Info("Digitize", "Adding event %d from input stream %d %s %s", ReadEvent, i, fInputFileNames[i].Data(), tempo.Data()) ;
5dee926e 220 rl->LoadSDigits();
221 rl->GetEvent(ReadEvent);
222 sdigArray->AddAt(emcalLoader->SDigits(), i) ;
0c219753 223 }
5dee926e 224
d968cee0 225 //Find the first tower with signal
a9485c37 226 Int_t nextSig = nEMC + 1 ;
88cb7938 227 TClonesArray * sdigits ;
228 for(i = 0 ; i < fInput ; i++){
229 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
814ad4bf 230 if ( !sdigits->GetEntriesFast() )
231 continue ;
88cb7938 232 Int_t curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(0))->GetId() ;
814ad4bf 233 if(curNext < nextSig)
234 nextSig = curNext ;
cf24bdc4 235 AliDebug(1,Form("input %i : #sdigits %i \n",
236 i, sdigits->GetEntriesFast()));
814ad4bf 237 }
cf24bdc4 238 AliDebug(1,Form("FIRST tower with signal %i \n", nextSig));
61e0abb5 239
88cb7938 240 TArrayI index(fInput) ;
814ad4bf 241 index.Reset() ; //Set all indexes to zero
61e0abb5 242
05a92d59 243 AliEMCALDigit * digit ;
244 AliEMCALDigit * curSDigit ;
ffa6d63b 245
814ad4bf 246 TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
ffa6d63b 247
5dee926e 248 //Put Noise contribution
814ad4bf 249 for(absID = 1; absID <= nEMC; absID++){
88cb7938 250 Float_t amp = 0 ;
a9485c37 251 // amplitude set to zero, noise will be added later
252 new((*digits)[absID-1]) AliEMCALDigit( -1, -1, absID, 0, TimeOfNoise() ) ;
814ad4bf 253 //look if we have to add signal?
88cb7938 254 digit = dynamic_cast<AliEMCALDigit *>(digits->At(absID-1)) ;
255
814ad4bf 256 if(absID==nextSig){
54cbf5a6 257 //Add SDigits from all inputs
814ad4bf 258 ticks->Clear() ;
259 Int_t contrib = 0 ;
260 Float_t a = digit->GetAmp() ;
261 Float_t b = TMath::Abs( a /fTimeSignalLength) ;
88cb7938 262 //Mark the beginning of the signal
814ad4bf 263 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);
fdebddeb 264 //Mark the end of the signal
814ad4bf 265 new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
266
88cb7938 267 // loop over input
268 for(i = 0; i< fInput ; i++){ //loop over (possible) merge sources
269 if(dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
270 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
814ad4bf 271 else
272 curSDigit = 0 ;
273 //May be several digits will contribute from the same input
fdebddeb 274 while(curSDigit && (curSDigit->GetId() == absID)){
814ad4bf 275 //Shift primary to separate primaries belonging different inputs
276 Int_t primaryoffset ;
277 if(fManager)
278 primaryoffset = fManager->GetMask(i) ;
279 else
280 primaryoffset = i ;
281 curSDigit->ShiftPrimary(primaryoffset) ;
282
283 a = curSDigit->GetAmp() ;
284 b = a /fTimeSignalLength ;
285 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);
286 new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b);
287
288 *digit = *digit + *curSDigit ; //add energies
289
290 index[i]++ ;
88cb7938 291 if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
1963b290 292 curSDigit = dynamic_cast<AliEMCALDigit*>(dynamic_cast<TClonesArray *>(sdigArray->At(i))->At(index[i])) ;
814ad4bf 293 else
294 curSDigit = 0 ;
295 }
296 }
a9485c37 297 // add fluctuations for photo-electron creation
298 amp = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
a9485c37 299 amp *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
88cb7938 300
05a92d59 301 //calculate and set time
814ad4bf 302 Float_t time = FrontEdgeTime(ticks) ;
303 digit->SetTime(time) ;
304
305 //Find next signal module
a9485c37 306 nextSig = nEMC + 1 ;
88cb7938 307 for(i = 0 ; i < fInput ; i++){
308 sdigits = dynamic_cast<TClonesArray *>(sdigArray->At(i)) ;
814ad4bf 309 Int_t curNext = nextSig ;
310 if(sdigits->GetEntriesFast() > index[i] ){
88cb7938 311 curNext = dynamic_cast<AliEMCALDigit *>(sdigits->At(index[i]))->GetId() ;
814ad4bf 312 }
313 if(curNext < nextSig) nextSig = curNext ;
314 }
315 }
a9485c37 316 // add the noise now
fdebddeb 317 amp += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
a9485c37 318 digit->SetAmp(sDigitizer->Digitize(amp)) ;
cf24bdc4 319 AliDebug(10,Form(" absID %5i amp %f nextSig %5i\n",
320 absID, amp, nextSig));
1963b290 321 } // for(absID = 1; absID <= nEMC; absID++)
814ad4bf 322
323 ticks->Delete() ;
324 delete ticks ;
61e0abb5 325
05a92d59 326 delete sdigArray ; //We should not delete its contents
61e0abb5 327
814ad4bf 328 //remove digits below thresholds
88cb7938 329 for(i = 0 ; i < nEMC ; i++){
330 digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
fdebddeb 331 Float_t threshold = fDigitThreshold ;
88cb7938 332 if(sDigitizer->Calibrate( digit->GetAmp() ) < threshold)
333 digits->RemoveAt(i) ;
334 else
814ad4bf 335 digit->SetTime(gRandom->Gaus(digit->GetTime(),fTimeResolution) ) ;
a9485c37 336 }
61e0abb5 337
814ad4bf 338 digits->Compress() ;
61e0abb5 339
05a92d59 340 Int_t ndigits = digits->GetEntriesFast() ;
88cb7938 341 digits->Expand(ndigits) ;
61e0abb5 342
1963b290 343 //Set indexes in list of digits and fill hists.
344 sv::FillH1(fHists, 0, Double_t(ndigits));
345 Float_t energy=0., esum=0.;
05a92d59 346 for (i = 0 ; i < ndigits ; i++) {
347 digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ;
814ad4bf 348 digit->SetIndexInList(i) ;
1963b290 349 energy = sDigitizer->Calibrate(digit->GetAmp()) ;
350 esum += energy;
351 digit->SetAmp(DigitizeEnergy(energy) ) ; // for what ??
352 sv::FillH1(fHists, 2, double(digit->GetAmp()));
353 sv::FillH1(fHists, 3, double(energy));
354 sv::FillH1(fHists, 4, double(digit->GetId()));
61e0abb5 355 }
1963b290 356 sv::FillH1(fHists, 1, esum);
814ad4bf 357}
61e0abb5 358
814ad4bf 359//____________________________________________________________________________
61e0abb5 360
fdebddeb 361Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy)
814ad4bf 362{
fdebddeb 363 Int_t channel = -999;
364 channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC )) ;
365 if(channel > fNADCEC )
7d74eaca 366 channel = fNADCEC ;
814ad4bf 367 return channel ;
61e0abb5 368}
369
370//____________________________________________________________________________
05a92d59 371void AliEMCALDigitizer::Exec(Option_t *option)
372{
45fa49ca 373 // Steering method to process digitization for events
374 // in the range from fFirstEvent to fLastEvent.
375 // This range is optionally set by SetEventRange().
376 // if fLastEvent=-1, then process events until the end.
377 // by default fLastEvent = fFirstEvent (process only one event)
05a92d59 378
88cb7938 379 if (!fInit) { // to prevent overwrite existing file
380 Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
381 return ;
382 }
383
814ad4bf 384 if (strstr(option,"print")) {
88cb7938 385 Print();
814ad4bf 386 return ;
387 }
388
61e0abb5 389 if(strstr(option,"tim"))
390 gBenchmark->Start("EMCALDigitizer");
5dee926e 391
392 AliRunLoader *rl = AliRunLoader::GetRunLoader();
393 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
394
5b4d2c50 395 // Post Digitizer to the white board
5dee926e 396 emcalLoader->PostDigitizer(this) ;
5b4d2c50 397
45fa49ca 398 if (fLastEvent == -1)
5dee926e 399 fLastEvent = rl->GetNumberOfEvents() - 1 ;
396a348e 400 else if (fManager)
1963b290 401 fLastEvent = fFirstEvent ; // what is this ??
396a348e 402
45fa49ca 403 Int_t nEvents = fLastEvent - fFirstEvent + 1;
cf24bdc4 404 Int_t ievent;
405
5dee926e 406 rl->LoadSDigits("EMCAL");
cf24bdc4 407 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
5dee926e 408 //gime->Event(ievent,"S") ;
409 rl->GetEvent(ievent);
05a92d59 410
814ad4bf 411 Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
88cb7938 412
9e5d2067 413 WriteDigits() ;
88cb7938 414
61e0abb5 415 if(strstr(option,"deb"))
416 PrintDigits(option);
1963b290 417 if(strstr(option,"table")) gObjectTable->Print();
88cb7938 418
814ad4bf 419 //increment the total number of Digits per run
5dee926e 420 fDigitsInRun += emcalLoader->Digits()->GetEntriesFast() ;
61e0abb5 421 }
1963b290 422 // gime->WriteDigitizer("OVERWRITE");
423
5dee926e 424 emcalLoader->CleanDigitizer() ;
5b4d2c50 425
61e0abb5 426 if(strstr(option,"tim")){
427 gBenchmark->Stop("EMCALDigitizer");
fdebddeb 428 printf("Exec: took %f seconds for Digitizing %f seconds per event",
45fa49ca 429 gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nEvents ) ;
88cb7938 430 }
61e0abb5 431}
432
05a92d59 433//____________________________________________________________________________
434Float_t AliEMCALDigitizer::FrontEdgeTime(TClonesArray * ticks)
88cb7938 435{
436 // Returns the shortest time among all time ticks
437
05a92d59 438 ticks->Sort() ; //Sort in accordance with times of ticks
439 TIter it(ticks) ;
440 AliEMCALTick * ctick = (AliEMCALTick *) it.Next() ;
441 Float_t time = ctick->CrossingTime(fTimeThreshold) ;
442
443 AliEMCALTick * t ;
444 while((t=(AliEMCALTick*) it.Next())){
445 if(t->GetTime() < time) //This tick starts before crossing
446 *ctick+=*t ;
447 else
448 return time ;
449
450 time = ctick->CrossingTime(fTimeThreshold) ;
451 }
452 return time ;
453}
454
455//____________________________________________________________________________
456Bool_t AliEMCALDigitizer::Init()
457{
458 // Makes all memory allocations
88cb7938 459 fInit = kTRUE ;
5dee926e 460 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
461
462 if ( emcalLoader == 0 ) {
463 Fatal("Init", "Could not obtain the AliEMCALLoader");
05a92d59 464 return kFALSE;
465 }
05a92d59 466
45fa49ca 467 fFirstEvent = 0 ;
468 fLastEvent = fFirstEvent ;
469
88cb7938 470 if(fManager)
471 fInput = fManager->GetNinputs() ;
472 else
473 fInput = 1 ;
474
475 fInputFileNames = new TString[fInput] ;
476 fEventNames = new TString[fInput] ;
477 fInputFileNames[0] = GetTitle() ;
478 fEventNames[0] = fEventFolderName.Data() ;
479 Int_t index ;
480 for (index = 1 ; index < fInput ; index++) {
481 fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0);
482 TString tempo = fManager->GetInputFolderName(index) ;
483 fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager
05a92d59 484 }
485
88cb7938 486 //to prevent cleaning of this object while GetEvent is called
5dee926e 487 emcalLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
88cb7938 488
489 return fInit ;
05a92d59 490}
491
492//____________________________________________________________________________
493void AliEMCALDigitizer::InitParameters()
1963b290 494{ // Tune parameters - 24-nov-04
495
496 fMeanPhotonElectron = 3300 ; // electrons per GeV
497 fPinNoise = 0.004;
88cb7938 498 if (fPinNoise == 0. )
499 Warning("InitParameters", "No noise added\n") ;
1963b290 500 fDigitThreshold = fPinNoise * 3; // 3 * sigma
501 fTimeResolution = 0.3e-9 ; // 300 psc
05a92d59 502 fTimeSignalLength = 1.0e-9 ;
05a92d59 503
1963b290 504 fADCchannelEC = 0.00305; // 200./65536 - width of one ADC channel in GeV
505 fADCpedestalEC = 0.009 ; // GeV
506 fNADCEC = (Int_t) TMath::Power(2,16) ; // number of channels in Tower ADC - 65536
a9485c37 507
1963b290 508 fTimeThreshold = 0.001*10000000 ; // Means 1 MeV in terms of SDigits amplitude ??
509 // hists. for control; no hists on default
510 fControlHists = 0;
511 fHists = 0;
05a92d59 512}
61e0abb5 513
61e0abb5 514//__________________________________________________________________
09884213 515void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
05a92d59 516{
517 // Allows to produce digits by superimposing background and signal event.
61e0abb5 518 // It is assumed, that headers file with SIGNAL events is opened in
05a92d59 519 // the constructor.
520 // Sets the BACKGROUND event, with which the SIGNAL event is to be mixed
521 // Thus we avoid writing (changing) huge and expensive
61e0abb5 522 // backgound files: all output will be writen into SIGNAL, i.e.
523 // opened in constructor file.
524 //
05a92d59 525 // One can open as many files to mix with as one needs.
526 // However only Sdigits with the same name (i.e. constructed with the same SDigitizer)
527 // can be mixed.
61e0abb5 528
05a92d59 529 if( strcmp(GetName(), "") == 0 )
61e0abb5 530 Init() ;
814ad4bf 531
05a92d59 532 if(fManager){
9859bfc0 533 Error("MixWith", "Cannot use this method under AliRunDigitizer") ;
61e0abb5 534 return ;
05a92d59 535 }
88cb7938 536 // looking for file which contains AliRun
537 if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
538 Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
539 return ;
61e0abb5 540 }
88cb7938 541 // looking for the file which contains SDigits
5dee926e 542 //AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
543 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
544 TString fileName( emcalLoader->GetSDigitsFileName() ) ;
e191bb57 545 if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 546 fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
547 if ( (gSystem->AccessPathName(fileName)) ) {
548 Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
549 return ;
814ad4bf 550 }
88cb7938 551 // need to increase the arrays
552 TString tempo = fInputFileNames[fInput-1] ;
553 delete [] fInputFileNames ;
554 fInputFileNames = new TString[fInput+1] ;
555 fInputFileNames[fInput-1] = tempo ;
556
557 tempo = fEventNames[fInput-1] ;
558 delete [] fEventNames ;
559 fEventNames = new TString[fInput+1] ;
560 fEventNames[fInput-1] = tempo ;
561
562 fInputFileNames[fInput] = alirunFileName ;
563 fEventNames[fInput] = eventFolderName ;
564 fInput++ ;
565}
1963b290 566
567void AliEMCALDigitizer::Print1(Option_t * option)
568{ // 19-nov-04 - just for convinience
569 Print();
570 PrintDigits(option);
571}
572
61e0abb5 573//__________________________________________________________________
eb0b1051 574void AliEMCALDigitizer::Print(Option_t*)const
88cb7938 575{
576 // Print Digitizer's parameters
fdebddeb 577 printf("Print: \n------------------- %s -------------", GetName() ) ;
88cb7938 578 if( strcmp(fEventFolderName.Data(), "") != 0 ){
579 printf(" Writing Digits to branch with title %s\n", fEventFolderName.Data()) ;
580
581 Int_t nStreams ;
582 if (fManager)
583 nStreams = GetNInputStreams() ;
584 else
585 nStreams = fInput ;
586
587 Int_t index = 0 ;
5dee926e 588
589 AliRunLoader *rl=0;
590
88cb7938 591 for (index = 0 ; index < nStreams ; index++) {
592 TString tempo(fEventNames[index]) ;
593 tempo += index ;
5dee926e 594 if ((rl = AliRunLoader::GetRunLoader(tempo)) == 0)
595 rl = AliRunLoader::Open(fInputFileNames[index], tempo) ;
596 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
597 TString fileName( emcalLoader->GetSDigitsFileName() ) ;
e191bb57 598 if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 599 fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index] + ".root" ;
600 printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ;
601 }
5dee926e 602
603 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
604
605 printf("\nWriting digits to %s", emcalLoader->GetDigitsFileName().Data()) ;
88cb7938 606
607 printf("\nWith following parameters:\n") ;
608
609 printf(" Electronics noise in EMC (fPinNoise) = %f\n", fPinNoise) ;
610 printf(" Threshold in EMC (fDigitThreshold) = %f\n", fDigitThreshold) ;
611 printf("---------------------------------------------------\n") ;
ea5f3389 612 }
613 else
fdebddeb 614 printf("Print: AliEMCALDigitizer not initialized") ;
61e0abb5 615}
814ad4bf 616
61e0abb5 617//__________________________________________________________________
618void AliEMCALDigitizer::PrintDigits(Option_t * option){
5dee926e 619 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
620 TClonesArray * digits = emcalLoader->Digits() ;
621 TClonesArray * sdigits = emcalLoader->SDigits() ;
88cb7938 622
1963b290 623 printf("\n #Digits: %d : sdigits %d ", digits->GetEntriesFast(), sdigits->GetEntriesFast()) ;
5dee926e 624 printf("\n event %d", emcalLoader->GetRunLoader()->GetEventNumber());
88cb7938 625
626 if(strstr(option,"all")){
61e0abb5 627 //loop over digits
628 AliEMCALDigit * digit;
88cb7938 629 printf("\nEMC digits (with primaries):\n") ;
630 printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
61e0abb5 631 Int_t index ;
88cb7938 632 for (index = 0 ; index < digits->GetEntries() ; index++) {
633 digit = dynamic_cast<AliEMCALDigit *>(digits->At(index)) ;
634 printf("\n%6d %8d %6.5e %4d %2d : ",
11f9c5ff 635 digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
61e0abb5 636 Int_t iprimary;
9859bfc0 637 for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
88cb7938 638 printf("%d ",digit->GetPrimary(iprimary+1) ) ;
9859bfc0 639 }
640 }
61e0abb5 641 }
1963b290 642 printf("\n");
61e0abb5 643}
05a92d59 644
645//__________________________________________________________________
646Float_t AliEMCALDigitizer::TimeOfNoise(void)
04f0bda3 647{
648 // Calculates the time signal generated by noise
26a2ef9d 649 //PH Info("TimeOfNoise", "Change me") ;
04f0bda3 650 return gRandom->Rndm() * 1.28E-5;
05a92d59 651}
652
88cb7938 653//__________________________________________________________________
654void AliEMCALDigitizer::Unload()
655{
fdebddeb 656 // Unloads the SDigits and Digits
5dee926e 657 AliRunLoader *rl=0;
658
88cb7938 659 Int_t i ;
660 for(i = 1 ; i < fInput ; i++){
661 TString tempo(fEventNames[i]) ;
5dee926e 662 tempo += i;
663 if ((rl = AliRunLoader::GetRunLoader(tempo)))
664 rl->GetDetectorLoader("EMCAL")->UnloadSDigits() ;
88cb7938 665 }
5dee926e 666 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
667 emcalLoader->UnloadDigits() ;
88cb7938 668}
669
814ad4bf 670//_________________________________________________________________________________________
9e5d2067 671void AliEMCALDigitizer::WriteDigits()
814ad4bf 672{
61e0abb5 673
814ad4bf 674 // Makes TreeD in the output file.
675 // Check if branch already exists:
676 // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
677 // already existing branches.
678 // else creates branch with Digits, named "EMCAL", title "...",
679 // and branch "AliEMCALDigitizer", with the same title to keep all the parameters
680 // and names of files, from which digits are made.
61e0abb5 681
5dee926e 682 AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::GetRunLoader()->GetDetectorLoader("EMCAL"));
cf24bdc4 683
5dee926e 684 const TClonesArray * digits = emcalLoader->Digits() ;
685 TTree * treeD = emcalLoader->TreeD();
686 if ( !treeD ) {
687 emcalLoader->MakeDigitsContainer();
688 treeD = emcalLoader->TreeD();
689 }
88cb7938 690
691 // -- create Digits branch
692 Int_t bufferSize = 32000 ;
5dee926e 693 TBranch * digitsBranch = 0;
694 if ((digitsBranch = treeD->GetBranch("EMCAL")))
695 digitsBranch->SetAddress(&digits);
696 else
697 treeD->Branch("EMCAL","TClonesArray",&digits,bufferSize);
698 //digitsBranch->SetTitle(fEventFolderName);
699 treeD->Fill() ;
88cb7938 700
5dee926e 701 emcalLoader->WriteDigits("OVERWRITE");
702 emcalLoader->WriteDigitizer("OVERWRITE");
88cb7938 703
704 Unload() ;
705
814ad4bf 706}
61e0abb5 707
1963b290 708void AliEMCALDigitizer::Browse(TBrowser* b)
709{
710 if(fHists) b->Add(fHists);
711 TTask::Browse(b);
712}
713
eb0b1051 714TList *AliEMCALDigitizer::BookControlHists(int var)
1963b290 715{ // 22-nov-04
716 Info("BookControlHists"," started ");
717 gROOT->cd();
5dee926e 718 const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
1963b290 719 if(var>=1){
720 new TH1F("hDigiN", "#EMCAL digits with fAmp > fDigitThreshold",
721 fNADCEC+1, -0.5, Double_t(fNADCEC));
5dee926e 722 new TH1F("HDigiSumEnergy","Sum.EMCAL energy from digi", 1000, 0.0, 200.);
1963b290 723 new TH1F("hDigiAmp", "EMCAL digital amplitude", fNADCEC+1, -0.5, Double_t(fNADCEC));
724 new TH1F("hDigiEnergy","EMCAL cell energy", 2000, 0.0, 200.);
725 new TH1F("hDigiAbsId","EMCAL absId cells with fAmp > fDigitThreshold ",
726 geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
727 }
728 fHists = sv::MoveHistsToList("EmcalDigiControlHists", kFALSE);
5dee926e 729 fHists = 0;
1963b290 730 return fHists;
731}
732
733void AliEMCALDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
734{
735 sv::SaveListOfHists(fHists, name, kSingleKey, opt);
736}