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