AliRoot Core  edcc906 (edcc906)
AliEMCALSDigitizer.cxx
Go to the documentation of this file.
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 // --- ROOT system ---
17 #include <TBenchmark.h>
18 #include <TBrowser.h>
19 #include <TMath.h>
20 #include <TROOT.h>
21 
22 // --- Standard library ---
23 #include "stdlib.h"
24 
25 // --- AliRoot header files ---
26 #include "AliLog.h"
27 #include "AliRunLoader.h"
28 #include "AliStack.h"
29 #include "AliEMCALDigit.h"
30 #include "AliEMCALLoader.h"
31 #include "AliEMCALHit.h"
32 #include "AliEMCALSDigitizer.h"
33 #include "AliEMCALGeometry.h"
34 #include "AliEMCALSimParam.h"
35 #include "AliSort.h"
36 
38 ClassImp(AliEMCALSDigitizer) ;
40 
43 //____________________________________________________________________________
45  : TNamed("",""),
46  fA(0.),fB(0.),fECPrimThreshold(0.),
47  fDefaultInit(kTRUE),
48  fEventFolderName(0),
49  fInit(0),
50  fSDigitsInRun(0),
51  fFirstEvent(0),
52  fLastEvent(0),
53  fSampling(0.),
54  fHits(0)
55 {
57 }
58 
61 //____________________________________________________________________________
62 AliEMCALSDigitizer::AliEMCALSDigitizer(const char * alirunFileName,
63  const char * eventFolderName)
64  : TNamed("EMCALSDigitizer", alirunFileName),
65  fA(0.),fB(0.),fECPrimThreshold(0.),
66  fDefaultInit(kFALSE),
67  fEventFolderName(eventFolderName),
68  fInit(0),
69  fSDigitsInRun(0),
70  fFirstEvent(0),
71  fLastEvent(0),
72  fSampling(0.),
73  fHits(0)
74 {
75  Init();
76  InitParameters() ;
77 }
78 
81 //____________________________________________________________________________
83  : TNamed(sd.GetName(),sd.GetTitle()),
84  fA(sd.fA),
85  fB(sd.fB),
89  fInit(sd.fInit),
93  fSampling(sd.fSampling),
94  fHits(0)
95 { }
96 
99 //_____________________________________________________________________
101 {
102  if (&source == this) return *this;
103 
104  new (this) AliEMCALSDigitizer(source);
105  return *this;
106 }
107 
110 //____________________________________________________________________________
112 {
113  if(fHits)
114  {
115  fHits->Clear();
116  delete fHits;
117  }
118 }
119 
124 //____________________________________________________________________________
126 {
127  fInit = kTRUE;
128 
129  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
130 
131  if ( emcalLoader == 0 )
132  {
133  AliFatal("Could not obtain the AliEMCALLoader");
134  return ;
135  }
136 }
137 
140 //____________________________________________________________________________
142 {
144  if (geom->GetSampling() == 0.)
145  AliFatal("Sampling factor not set!") ;
146 
147 
148  // Get the parameters from the OCDB via the loader
150  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
151  AliEMCALSimParam * simParam = 0x0;
152  if(emcalLoader) simParam = emcalLoader->SimulationParameters();
153 
154  if(!simParam)
155  {
156  simParam = AliEMCALSimParam::GetInstance();
157  AliWarning("Simulation Parameters not available in OCDB?");
158  }
159 
160  //
161  //JLK 26-Jun-2008 THIS SHOULD HAVE BEEN EXPLAINED AGES AGO:
162  //
163  //In order to be able to store SDigit Energy info into
164  //AliEMCALDigit, we need to convert it temporarily to an ADC amplitude
165  //and later when summing SDigits to form digits, convert it back to
166  //energy. These fA and fB parameters accomplish this through the
167  //Digitize() and Calibrate() methods
168  //
169  // Initializes parameters
170  fA = simParam->GetA(); //0;
171  fB = simParam->GetB(); //1.e+6; // Changed 24 Apr 2007. Dynamic range now 2 TeV
172  fSampling = geom->GetSampling();
173 
174  // threshold for deposit energy of hit
175  fECPrimThreshold = simParam->GetECPrimaryThreshold();//0.05;// GeV // 22-may-07 was 0// 24-nov-04 - was 1.e-6;
176 
177  AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
178  AliDebug(2,Form(" fInit %i\n", int(fInit)));
179  AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
180  AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
181  AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
182  AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
183  AliDebug(2,Form(" B = %f\n", fB));
184  AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
185  AliDebug(2,Form(" Sampling = %f\n", fSampling));
186  AliDebug(2,Form("---------------------------------------------------\n"));
187 }
188 
191 //____________________________________________________________________________
192 void AliEMCALSDigitizer::Digitize(Option_t *option)
193 {
194  TString o(option); o.ToUpper();
195  if (strstr(option, "print") )
196  {
197  AliDebug(2,Form("Print: \n------------------- %s -------------\n",GetName()));
198  AliDebug(2,Form(" fInit %i\n", int(fInit)));
199  AliDebug(2,Form(" fFirstEvent %i\n", fFirstEvent));
200  AliDebug(2,Form(" fLastEvent %i\n", fLastEvent));
201  AliDebug(2,Form(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()));
202  AliDebug(2,Form(" with digitization parameters A = %f\n", fA));
203  AliDebug(2,Form(" B = %f\n", fB));
204  AliDebug(2,Form(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold));
205  AliDebug(2,Form(" Sampling = %f\n", fSampling));
206  AliDebug(2,Form("---------------------------------------------------\n"));
207 
208  return ;
209  }
210 
211  if(strstr(option,"tim"))
212  gBenchmark->Start("EMCALSDigitizer");
213 
215  AliEMCALLoader *emcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
216 
217  if (!fInit)
218  {
219  // to prevent overwrite existing file
220  AliError( Form("Give a version name different from %s", fEventFolderName.Data()) ) ;
221  return ;
222  }
223 
224  if (fLastEvent == -1)
225  fLastEvent = rl->GetNumberOfEvents() - 1 ;
226  else
227  fLastEvent = TMath::Min(fLastEvent, rl->GetNumberOfEvents()-1);
228 
229  Int_t nEvents = fLastEvent - fFirstEvent + 1;
230 
231  Float_t energy=0.; // de * fSampling - 23-nov-04
232  rl->LoadKinematics();
233  rl->LoadHits("EMCAL");
234 
235  Int_t ievent;
236  for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++)
237  {
238  rl->GetEvent(ievent);
239 
240  TTree * treeS = emcalLoader->TreeS();
241  if ( !treeS )
242  {
243  emcalLoader->MakeSDigitsContainer();
244  treeS = emcalLoader->TreeS();
245  }
246 
247  TClonesArray * sdigits = emcalLoader->SDigits() ;
248  sdigits->Clear("C");
249 
250  Int_t nSdigits = 0 ;
251  Int_t iHit, iTrack, iSDigit;
252 
254 
255  TTree *treeH = emcalLoader->TreeH();
256  if (treeH)
257  {
258  Int_t nTrack = treeH->GetEntries(); // TreeH has array of hits for every primary
259  TBranch * branchH = treeH->GetBranch("EMCAL");
260  //if(fHits)fHits->Clear();
261  branchH->SetAddress(&fHits);
262  for (iTrack = 0; iTrack < nTrack; iTrack++)
263  {
264  branchH->GetEntry(iTrack);
265 
266  if(fHits)
267  {
268  Int_t nHit = fHits->GetEntriesFast();
269  for(iHit = 0; iHit< nHit;iHit++)
270  {
271  AliEMCALHit * hit = static_cast<AliEMCALHit*>(fHits->UncheckedAt(iHit)) ;
272  AliEMCALDigit * curSDigit = 0 ;
273  AliEMCALDigit * sdigit = 0 ;
274  Bool_t newsdigit = kTRUE;
275 
276  // hit->GetId() - Absolute Id number EMCAL segment
277  if(hit)
278  {
279  if(geom->CheckAbsCellId(hit->GetId())) { // was IsInECA(hit->GetId())
280  energy = hit->GetEnergy() * fSampling; // 23-nov-04
281  if(energy > fECPrimThreshold )
282  // Assign primary number only if deposited energy is significant
283  curSDigit = new AliEMCALDigit(hit->GetPrimary(),
284  hit->GetIparent(), hit->GetId(),
285  Digitize(energy), hit->GetTime(),kFALSE,
286  -1, 0,0,energy ) ;
287  else
288  curSDigit = new AliEMCALDigit(-1,
289  -1,
290  hit->GetId(),
291  Digitize(energy), hit->GetTime(),kFALSE,
292  -1, 0,0,energy ) ;
293  }
294  else
295  {
296  Warning("Digitize"," abs id %i is bad \n", hit->GetId());
297  newsdigit = kFALSE;
298  curSDigit = 0;
299  }
300 
301  if(curSDigit != 0)
302  {
303  for(Int_t check= 0; check < nSdigits ; check++)
304  {
305  sdigit = static_cast<AliEMCALDigit *>(sdigits->UncheckedAt(check)) ;
306 
307  if(sdigit)
308  {
309  if( sdigit->GetId() == curSDigit->GetId())
310  { // Are we in the same ECAL tower ?
311  *sdigit = *sdigit + *curSDigit;
312  newsdigit = kFALSE;
313  }
314  }// sdigit exists
315  else
316  {
317  AliWarning("Sdigit do not exist");
318  newsdigit = kFALSE;
319  }// sdigit does not exist
320  }//sdigit loop
321  }// currsdigit exists
322 
323  if (newsdigit)
324  {
325  new((*sdigits)[nSdigits]) AliEMCALDigit(*curSDigit);
326  nSdigits++ ;
327  }
328 
329  delete curSDigit ;
330 
331  }// hit exists
332  else AliFatal("Hit is NULL!");
333 
334  } // loop over all hits (hit = deposited energy/entering particle)
335 
336  }//fHits is not NULL
337  else AliFatal("fHit is NULL!");
338 
339  // sdigits->Sort() ;
340  AliSort::TClonesArraySort<AliEMCALDigit>(sdigits);
341 
342  nSdigits = sdigits->GetEntriesFast() ;
343  fSDigitsInRun += nSdigits ;
344 
345  for (iSDigit = 0 ; iSDigit < sdigits->GetEntriesFast() ; iSDigit++)
346  {
347  AliEMCALDigit * sdigit = static_cast<AliEMCALDigit *>(sdigits->UncheckedAt(iSDigit)) ;
348 
349  if ( sdigit ) sdigit->SetIndexInList(iSDigit) ;
350  else AliFatal("sdigit is NULL!");
351  }
352 
353  if(fHits)fHits->Clear();
354 
355  }//track loop
356  }// tree exists
357 
358  // Now write SDigits
359 
360  Int_t bufferSize = 32000 ;
361  TBranch * sdigitsBranch = treeS->GetBranch("EMCAL");
362  if (sdigitsBranch)
363  sdigitsBranch->SetAddress(&sdigits);
364  else
365  treeS->Branch("EMCAL",&sdigits,bufferSize);
366 
367  treeS->Fill();
368 
369  emcalLoader->WriteSDigits("OVERWRITE");
370 
371  //NEXT - SDigitizer
372  //emcalLoader->WriteSDigitizer("OVERWRITE"); // why in event cycle ?
373 
374  if(strstr(option,"deb"))
375  PrintSDigits(option) ;
376  }
377 
378  Unload();
379 
380  if(strstr(option,"tim"))
381  {
382  gBenchmark->Stop("EMCALSDigitizer");
383  printf("\n Digitize: took %f seconds for SDigitizing %f seconds per event\n",
384  gBenchmark->GetCpuTime("EMCALSDigitizer"), gBenchmark->GetCpuTime("EMCALSDigitizer")/nEvents ) ;
385  }
386 }
387 
390 //
392 //
400 //__________________________________________________________________
401 Float_t AliEMCALSDigitizer::Digitize(Float_t energy) const
402 {
403  Double_t aSignal = fA + energy*fB;
404  if (TMath::Abs(aSignal)>2147483647.0)
405  {
406  //PH 2147483647 is the max. integer
407  //PH This apparently is a problem which needs investigation
408  AliWarning(Form("Too big or too small energy %f",aSignal));
409 
410  aSignal = TMath::Sign((Double_t)2147483647,aSignal);
411  }
412 
413  return (Float_t ) aSignal;
414 }
415 
418 //
420 //
429 //__________________________________________________________________
430 Float_t AliEMCALSDigitizer::Calibrate(Float_t amp) const
431 {
432  return (Float_t)(amp - fA)/fB;
433 }
434 
437 //__________________________________________________________________
438 void AliEMCALSDigitizer::Print1(Option_t * option)
439 {
440  Print();
441  PrintSDigits(option);
442 }
443 
446 //__________________________________________________________________
447 void AliEMCALSDigitizer::Print(Option_t *option) const
448 {
449  printf("Print: \n------------------- %s ------------- option %s\n", GetName() , option) ;
450  printf(" fInit %i\n", int(fInit));
451  printf(" fFirstEvent %i\n", fFirstEvent);
452  printf(" fLastEvent %i\n", fLastEvent);
453  printf(" Writing SDigits to branch with title %s\n", fEventFolderName.Data()) ;
454  printf(" with digitization parameters A = %f\n", fA) ;
455  printf(" B = %f\n", fB) ;
456  printf(" Threshold for EC Primary assignment = %f\n", fECPrimThreshold) ;
457  printf(" Sampling = %f\n", fSampling);
458  printf("---------------------------------------------------\n") ;
459 }
460 
463 //__________________________________________________________________
465 {
466  if( (fA==sd.fA)&&(fB==sd.fB)&&
468  return kTRUE ;
469  else
470  return kFALSE ;
471 }
472 
475 //__________________________________________________________________
476 void AliEMCALSDigitizer::PrintSDigits(Option_t * option)
477 {
478  AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
479 
480  if(rl)
481  {
482  const TClonesArray * sdigits = rl->SDigits() ;
483 
484  printf("\n") ;
485  printf("event %i", rl->GetRunLoader()->GetEventNumber());
486  printf(" Number of entries in SDigits list %i", sdigits->GetEntriesFast());
487 
488  if(strstr(option,"all")||strstr(option,"EMC"))
489  {
490  // loop over digits
491  AliEMCALDigit * digit;
492  printf("\n Id Amplitude Time Index Nprim: Primaries list \n") ;
493  Int_t index = 0;
494  Float_t isum = 0.;
495  const Int_t bufferSize = 8192;
496  char * tempo = new char[bufferSize];
497 
498  for (index = 0 ; index < sdigits->GetEntries() ; index++)
499  {
500  digit = dynamic_cast<AliEMCALDigit *>( sdigits->At(index) ) ;
501  if(digit)
502  {
503  snprintf(tempo, bufferSize,"\n%6d %8f %6.5e %4d %2d :",
504  digit->GetId(), digit->GetAmplitude(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;
505  printf("%s",tempo);
506  isum += digit->GetAmplitude();
507 
508  Int_t iprimary;
509  for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++)
510  {
511  snprintf(tempo,bufferSize, "%d ",digit->GetPrimary(iprimary+1) ) ;
512  printf("%s",tempo);
513  }
514  } //sdigit exists
515  else AliFatal("SDigit is NULL!");
516  }//loop
517 
518  delete [] tempo ;
519  printf("\n** Sum %2.3f : %10.3f GeV/c **\n ", isum, Calibrate(isum));
520  } else printf("\n");
521  }
522  else AliFatal("EMCALLoader is NULL!");
523 }
524 
527 //____________________________________________________________________________
529 {
530  AliEMCALLoader *rl = dynamic_cast<AliEMCALLoader*>(AliRunLoader::Instance()->GetDetectorLoader("EMCAL"));
531 
532  if(rl)
533  {
534  rl->UnloadHits() ;
535  rl->UnloadSDigits() ;
536  }
537  else AliFatal("EMCALLoader is NULL!");
538 }
539 
542 //____________________________________________________________________________
544 {
545  TNamed::Browse(b);
546 }
Bool_t CheckAbsCellId(Int_t absId) const
virtual ~AliEMCALSDigitizer()
Destructor.
TBrowser b
Definition: RunAnaESD.C:12
Float_t fB
Slope Digitizition parameters.
static AliRunLoader * Instance()
Definition: AliRunLoader.h:176
Int_t GetEventNumber() const
Definition: AliRunLoader.h:59
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
Int_t fLastEvent
Last event to process.
Bool_t operator==(const AliEMCALSDigitizer &sd) const
Float_t GetTime(void) const
Definition: AliEMCALDigit.h:64
Float_t GetB() const
void Print1(Option_t *option="all")
Print info, call all prints.
TBenchmark * gBenchmark
Int_t fFirstEvent
First event to process.
void Unload() const
Unload Hits and SDigits from the folder.
TString fEventFolderName
Event folder name.
TClonesArray * SDigits()
virtual void Browse(TBrowser *b)
Browse (obsolete?)
AliEMCALSimParam * SimulationParameters()
AliLoader * GetDetectorLoader(const char *detname)
TTree * TreeS() const
Definition: AliLoader.h:85
Float_t Calibrate(Float_t amp) const
Convert the amplitude back to energy in GeV.
Int_t fSDigitsInRun
! Total number of sdigits in one run
static AliEMCALSimParam * GetInstance()
Get Instance.
Float_t GetA() const
Float_t Digitize(Float_t energy) const
Digitize the energy.
EMCal digits object.
Definition: AliEMCALDigit.h:30
Int_t GetId(void) const
Definition: AliEMCALHit.h:44
#define AliWarning(message)
Definition: AliLog.h:541
Give access to hits, digits, recpoints arrays and OCDB.
Float_t fSampling
See AliEMCALGeometry.
Float_t fECPrimThreshold
To store primary if EC Shower Elos > threshold.
void InitParameters()
Initialize parameters for sdigitization.
virtual void MakeSDigitsContainer() const
Definition: AliLoader.h:74
virtual Int_t WriteSDigits(Option_t *opt="") const
Definition: AliLoader.cxx:380
EMCal hits object.
Definition: AliEMCALHit.h:24
Int_t GetNprimary() const
Definition: AliEMCALDigit.h:57
AliRunLoader * GetRunLoader()
Definition: AliLoader.cxx:495
Container of simulation parameters.
Float_t GetECPrimaryThreshold() const
Int_t GetIndexInList() const
Definition: AliDigitNew.h:24
EMCal summable digits maker.
Int_t GetNumberOfEvents()
void SetIndexInList(Int_t val)
Definition: AliDigitNew.h:25
#define AliFatal(message)
Definition: AliLog.h:640
Bool_t fInit
! Tells if initialisation went OK, will revent exec if not
Int_t GetEvent(Int_t evno)
Bool_t fDefaultInit
! Says if the object was created by defaut ctor (only parameters are initialized) ...
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
Float_t GetSampling(void) const
Int_t GetPrimary(Int_t index) const
void UnloadHits() const
Definition: AliLoader.h:129
virtual void Print(Option_t *option="") const
Prints parameters of SDigitizer.
TTree * TreeH() const
Definition: AliLoader.h:83
Int_t LoadHits(Option_t *detectors="all", Option_t *opt="READ")
Int_t GetId() const
Definition: AliDigitNew.h:23
AliEMCALSDigitizer()
Default Constructor.
void PrintSDigits(Option_t *option)
Prints list of digits produced at the current pass of AliEMCALDigitizer.
AliEMCALSDigitizer & operator=(const AliEMCALSDigitizer &source)
Assignment operator; use copy constructor.
void UnloadSDigits() const
Definition: AliLoader.h:130
Int_t GetIparent(void) const
Definition: AliEMCALHit.h:47
Int_t GetPrimary(void) const
Definition: AliEMCALHit.h:51
#define AliError(message)
Definition: AliLog.h:591
Float_t GetEnergy(void) const
Definition: AliEMCALHit.h:41
static AliEMCALGeometry * GetInstance()
TEveGeoShape * geom
Definition: tpc_tracks.C:10
Float_t GetTime(void) const
Definition: AliEMCALHit.h:54
TClonesArray * fHits
Temporal array with hits.
Float_t GetAmplitude() const
Definition: AliEMCALDigit.h:55
EMCal geometry, singleton.
Float_t fA
Pedestal parameter.
Int_t LoadKinematics(Option_t *option="READ")