AliRoot Core  edcc906 (edcc906)
AliEMCALClusterizerFixedWindow.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 ---
17 #include <TMath.h>
18 #include <TMinuit.h>
19 #include <TTree.h>
20 #include <TBenchmark.h>
21 #include <TBrowser.h>
22 #include <TROOT.h>
23 #include <TClonesArray.h>
24 #include <TH1I.h>
25 
26 // --- AliRoot ---
27 #include "AliLog.h"
28 #include "AliEMCALRecPoint.h"
29 #include "AliEMCALDigit.h"
30 #include "AliEMCALGeometry.h"
31 #include "AliCaloCalibPedestal.h"
32 #include "AliEMCALCalibData.h"
33 #include "AliEMCALCalibTime.h"
34 #include "AliESDCaloCluster.h"
35 #include "AliEMCALUnfolding.h"
36 
38 
42 
45 //__________________________________________________________________________________________
48  fNphi(4),
49  fNeta(4),
50  fShiftPhi(2),
51  fShiftEta(2),
52  fTRUshift(0),
53  fNEtaDigitsSupMod(0),
54  fNPhiDigitsSupMod(0),
55  fNTRUPhi(0),
56  fNTRUEta(0),
57  fNEtaDigits(0),
58  fNPhiDigits(0),
59  fMaxShiftPhi(0),
60  fMaxShiftEta(0),
61  fNDigitsCluster(0),
62  fNClusEtaNoShift(0),
63  fNClusPhiNoShift(0),
64  fNClusters(0),
65  fNTotalClus(0),
66  fClustersArray(0),
67  fInitialized(0)
68 { }
69 
74 //__________________________________________________________________________________________
76  AliEMCALClusterizer(geometry),
77  fNphi(4),
78  fNeta(4),
79  fShiftPhi(2),
80  fShiftEta(2),
81  fTRUshift(0),
84  fNTRUPhi(0),
85  fNTRUEta(0),
86  fNEtaDigits(0),
87  fNPhiDigits(0),
88  fMaxShiftPhi(0),
89  fMaxShiftEta(0),
90  fNDigitsCluster(0),
93  fNClusters(0),
94  fNTotalClus(0),
95  fClustersArray(0),
96  fInitialized(0)
97 { }
98 
106 //__________________________________________________________________________________________
108  AliEMCALCalibData * calib,
109  AliEMCALCalibTime * calibt,
110  AliCaloCalibPedestal * caloped) :
111  AliEMCALClusterizer(geometry, calib, calibt, caloped),
112  fNphi(4),
113  fNeta(4),
114  fShiftPhi(2),
115  fShiftEta(2),
116  fTRUshift(0),
119  fNTRUPhi(0),
120  fNTRUEta(0),
121  fNEtaDigits(0),
122  fNPhiDigits(0),
123  fMaxShiftPhi(0),
124  fMaxShiftEta(0),
125  fNDigitsCluster(0),
126  fNClusEtaNoShift(0),
127  fNClusPhiNoShift(0),
128  fNClusters(0),
129  fNTotalClus(0),
130  fClustersArray(0),
131  fInitialized(0)
132 { }
133 
136 //__________________________________________________________________________________________
138 {
139  if (fClustersArray)
140  {
141  for (Int_t i = 0; i < fNTotalClus; i++)
142  {
143  if (fClustersArray[i])
144  {
145  delete[] fClustersArray[i];
146  fClustersArray[i] = 0;
147  }
148  }
149  delete[] fClustersArray;
150  fClustersArray = 0;
151  }
152 }
153 
156 //__________________________________________________________________________________________
158 {
159  if (fInitialized != 0)
160  AliWarning("Clusterizer already initialized. Unable to change the parameters.");
161  else
162  fNphi = n;
163 }
164 
167 //__________________________________________________________________________________________
169 {
170  if (fInitialized != 0)
171  AliWarning("Clusterizer already initialized. Unable to change the parameters.");
172  else
173  fNeta = n;
174 }
175 
178 //__________________________________________________________________________________________
180 {
181  if (fInitialized != 0)
182  AliWarning("Clusterizer already initialized. Unable to change the parameters.");
183  else
184  fShiftPhi = s;
185 }
186 
189 //__________________________________________________________________________________________
191 {
192  if (fInitialized != 0)
193  AliWarning("Clusterizer already initialized. Unable to change the parameters.");
194  else
195  fShiftEta = s;
196 }
197 
200 //__________________________________________________________________________________________
202 {
203  if (fInitialized != 0)
204  AliWarning("Clusterizer already initialized. Unable to change the parameters.");
205  else
206  fTRUshift = b;
207 }
208 
211 //__________________________________________________________________________________________
213 {
214  static Float_t cputime = 0;
215  static Float_t realtime = 0;
216 
217  if (strstr(option,"tim"))
218  gBenchmark->Start("EMCALClusterizer");
219 
220  if (strstr(option,"print"))
221  Print("");
222 
223  // Get calibration parameters from file or digitizer default values.
225 
226  // Get dead channel map from file or digitizer default values.
228 
229  MakeClusters(); //only the real clusters
230 
231  if (fToUnfold)
232  {
235  }
236 
237  // Evaluate position, dispersion and other RecPoint properties for EC section
238  for (Int_t index = 0; index < fRecPoints->GetEntries(); index++)
239  {
240  AliEMCALRecPoint * rp = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index));
241  if (rp)
242  {
244 
245  AliDebug(5, Form("MAX INDEX %d ", rp->GetMaximalEnergyIndex()));
246 
247  // For each rec.point set the distance to the nearest bad crystal
248  if (fCaloPed)
250  }
251  }
252 
253  fRecPoints->Sort();
254 
255  for (Int_t index = 0; index < fRecPoints->GetEntries(); index++)
256  {
257  AliEMCALRecPoint *rp = dynamic_cast<AliEMCALRecPoint *>(fRecPoints->At(index));
258  if (rp)
259  {
260  rp->SetIndexInList(index);
261  }
262  else AliFatal("RecPoint NULL!!");
263  }
264 
265  if (fTreeR)
266  fTreeR->Fill();
267 
268  if (strstr(option,"deb") || strstr(option,"all"))
269  PrintRecPoints(option);
270 
271  AliDebug(1,Form("EMCAL Clusterizer found %d Rec Points",fRecPoints->GetEntriesFast()));
272 
273  if (strstr(option,"tim"))
274  {
275  gBenchmark->Stop("EMCALClusterizer");
276  Printf("Exec took %f CPU time (%f real time) for clusterizing",
277  gBenchmark->GetCpuTime("EMCALClusterizer")-cputime,gBenchmark->GetRealTime("EMCALClusterizer")-realtime);
278  cputime = gBenchmark->GetCpuTime("EMCALClusterizer");
279  realtime = gBenchmark->GetRealTime("EMCALClusterizer");
280  }
281 }
282 
285 //__________________________________________________________________________________________
287 {
288  fInitialized = -1;
289 
290  if (!fGeom)
291  {
292  AliError("Did not get geometry!");
293  return;
294  }
295 
296  // Defining geometry and clusterization parameter
297  fNEtaDigitsSupMod = fGeom->GetNEta() * fGeom->GetNETAdiv(); // always 48?;
298  fNPhiDigitsSupMod = fGeom->GetNPhi() * fGeom->GetNPHIdiv(); // always 24?;
299 
300  fNTRUPhi = 1;
301  fNTRUEta = 1;
302 
305 
306  if (fTRUshift)
307  {
312  }
313 
314  // Check if clusterizer parameter are compatible with calorimeter geometry
315  if (fNEtaDigits < fNeta)
316  {
317  AliError(Form("Error: fNeta = %d is greater than nEtaDigits = %d.",fNeta,fNEtaDigits));
318  return;
319  }
320 
321  if (fNPhiDigits < fNphi)
322  {
323  AliError(Form("Error: fNphi = %d is greater than nPhiDigits = %d.",fNphi,fNPhiDigits));
324  return;
325  }
326 
327  if (fNEtaDigits % fShiftEta != 0)
328  {
329  AliError(Form("Error: fShiftEta = %d is such that clusters cannot slide the whole calorimeter (nEtaDigits = %d).",fShiftEta,fNEtaDigits));
330  return;
331  }
332 
333  if (fNPhiDigits % fShiftPhi != 0)
334  {
335  AliError(Form("Error: fShiftPhi = %d is such that clusters cannot slide the whole calorimeter (nPhiDigits = %d).",fShiftPhi,fNPhiDigits));
336  return;
337  }
338 
339  if (fNeta % fShiftEta != 0)
340  {
341  AliError(Form("Error: fShiftEta = %d is not divisor of fNeta = %d.",fShiftEta,fNeta));
342  return;
343  }
344 
345  if (fNphi % fShiftPhi != 0)
346  {
347  AliError(Form("Error: fShiftPhi = %d is not divisor of fNphi = %d).",fShiftPhi,fNphi));
348  return;
349  }
350 
353 
356 
358 
360 
362 
363  if (fClustersArray)
364  {
365  for (Int_t i = 0; i < fNTotalClus; i++)
366  {
367  if (fClustersArray[i])
368  {
369  delete[] fClustersArray[i];
370  fClustersArray[i] = 0;
371  }
372  }
373  delete[] fClustersArray;
374  fClustersArray = 0;
375  }
376 
378  for (Int_t i = 0; i < fNTotalClus; i++)
379  {
381  for (Int_t j = 0; j < fNDigitsCluster; j++)
382  {
383  fClustersArray[i][j] = 0;
384  }
385  }
386 
387  AliDebug(1,Form("****ExecOnce*****\n"
388  "fNphi = %d, fNeta = %d, fShiftPhi = %d, fShiftEta = %d, fTRUshift = %d\n"
389  "fNEtaDigitsSupMod = %d, fNPhiDigitsSupMod = %d, fNTRUPhi = %d, fNTRUEta = %d, fNEtaDigits = %d, fNPhiDigits = %d\n"
390  "fMaxShiftPhi = %d, fMaxShiftEta = %d, fNDigitsCluster = %d, fNClusEtaNoShift = %d, fNClusPhiNoShift = %d\n"
391  "fNClusters = %d, fNTotalClus = %d\n",
395  fNClusters,fNTotalClus));
396 
397  fInitialized = 1;
398 }
399 
402 //__________________________________________________________________________________________
404 {
406  fRecPoints->Delete();
407 
408  if (fInitialized == 0)
409  ExecOnce();
410 
411  if (fInitialized == -1)
412  {
413  AliError(Form("%s: error initializing the clusterizer. No clusterization will be performed.",GetName()));
414  return;
415  }
416 
417  // Set up TObjArray with pointers to digits to work on calibrated digits
418  TObjArray *digitsC = new TObjArray();
419  AliEMCALDigit *digit;
420  Float_t dEnergyCalibrated = 0.0, ehs = 0.0, time = 0.0;
421 
422  TIter nextdigit(fDigitsArr);
423  while ((digit = dynamic_cast<AliEMCALDigit*>(nextdigit())))
424  { // calibrate and clean up digits
425  dEnergyCalibrated = digit->GetAmplitude();
426  time = digit->GetTime();
427 
428  Calibrate(dEnergyCalibrated, time, digit->GetId());
429 
430  digit->SetCalibAmp(dEnergyCalibrated);
431  digit->SetTime(time);
432 
433  if (dEnergyCalibrated < fMinECut || time > fTimeMax || time < fTimeMin)
434  {
435  continue;
436  }
437  else if (!fGeom->CheckAbsCellId(digit->GetId()))
438  {
439  continue;
440  }
441  else
442  {
443  ehs += dEnergyCalibrated;
444  digitsC->AddLast(digit);
445  }
446  }
447 
448  AliDebug(1,Form("MakeClusters: Number of digits %d -> (e %f), ehs %f\n",
449  fDigitsArr->GetEntries(),fMinECut,ehs));
450 
451  Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0;
452  Int_t iphi=0, ieta=0; // cell eta-phi indexes in SM
453 
454  for (Int_t ishiftPhi = 0; ishiftPhi < fMaxShiftPhi; ishiftPhi++)
455  {
456  Int_t nClusPhi = (fNPhiDigits - fShiftPhi * ishiftPhi) / fNphi;
457 
458  for (Int_t ishiftEta = 0; ishiftEta < fMaxShiftEta; ishiftEta++)
459  {
460  Int_t nClusEta = (fNEtaDigits - fShiftEta * ishiftEta) / fNeta;
461 
462  Int_t iTotalClus = fNClusters * (ishiftPhi * fMaxShiftEta + ishiftEta);
463 
464  TIter nextdigitC(digitsC);
465  while ((digit = dynamic_cast<AliEMCALDigit*>(nextdigitC())))
466  { // scan over the list of digitsC
467  fGeom->GetCellIndex (digit->GetId(), nSupMod, nModule, nIphi, nIeta);
468  fGeom->GetCellPhiEtaIndexInSModule (nSupMod, nModule, nIphi, nIeta, iphi, ieta);
469 
470  Int_t iphi_eff = iphi - fShiftPhi * ishiftPhi + fNPhiDigitsSupMod * (nSupMod / 2); // N supermodules along phi
471 
472  Int_t iTRUphi = iphi_eff / fNPhiDigits;
473 
474  iphi_eff -= iTRUphi * fNPhiDigits;
475 
476  Int_t iClusPhi = iphi_eff / fNphi;
477 
478  if (iphi_eff < 0 || iClusPhi >= nClusPhi)
479  continue;
480 
481  Int_t ieta_eff = ieta - fShiftEta * ishiftEta + fNEtaDigitsSupMod * (nSupMod % 2); // 2 supermodules along eta
482 
483  Int_t iTRUeta = ieta_eff / fNEtaDigits;
484 
485  ieta_eff -= iTRUeta * fNEtaDigits;
486 
487  Int_t iClusEta = ieta_eff / fNeta;
488 
489  if (ieta_eff < 0 || iClusEta >= nClusEta)
490  continue;
491 
492  iphi_eff += iTRUphi * fNPhiDigits;
493  iClusPhi = iphi_eff / fNphi;
494 
495  ieta_eff += iTRUeta * fNEtaDigits;
496  iClusEta = ieta_eff / fNeta;
497 
498  Int_t iCluster = iClusPhi + iClusEta * fNClusPhiNoShift * fNTRUPhi;
499  Int_t iDigit = iphi_eff % fNphi + (ieta_eff % fNeta) * fNphi;
500 
501  if (iCluster >= fNClusters)
502  {
503  AliError(Form("iCluster out of range! iCluster = %d, fNClusters = %d (should never happen...)", iCluster, fNClusters));
504  return;
505  }
506 
507  iCluster += iTotalClus;
508 
509  if (iCluster >= fNTotalClus)
510  {
511  AliError(Form("iCluster out of range! iCluster = %d, fNTotalClus = %d (should never happen...)", iCluster, fNTotalClus));
512  return;
513  }
514 
515  if (iDigit >= fNDigitsCluster)
516  {
517  AliError(Form("iDigit out of range! iDigit = %d, fNDigitsCluster = %d (should never happen...)", iDigit, fNDigitsCluster));
518  return;
519  }
520 
521  if (fClustersArray[iCluster][iDigit] != 0)
522  {
523  AliError("Digit already added! (should never happen...)");
524  return;
525  }
526 
527  fClustersArray[iCluster][iDigit] = digit;
528 
529  } // loop on digit
530 
531  } // loop on eta shift
532 
533  } // loop on phi shift
534 
535  AliEMCALRecPoint *recPoint = 0;
536  Bool_t recPointOk = kFALSE;
537  for (Int_t iCluster = 0; iCluster < fNTotalClus; iCluster++)
538  {
539  if (!recPoint)
540  {
541  if(fNumberOfECAClusters >= fRecPoints->GetSize()) fRecPoints->Expand(fNumberOfECAClusters*2+1);
542 
543  (*fRecPoints)[fNumberOfECAClusters] = new AliEMCALRecPoint("");
544  recPoint = static_cast<AliEMCALRecPoint*>(fRecPoints->At(fNumberOfECAClusters));
545  }
546 
547  if (recPoint)
548  {
550  recPoint->SetUniqueID(iCluster);
552 
553  for (Int_t iDigit = 0; iDigit < fNDigitsCluster; iDigit++)
554  {
555  if (fClustersArray[iCluster][iDigit] == 0) continue;
556 
557  digit = fClustersArray[iCluster][iDigit];
558  recPoint->AddDigit(*digit, digit->GetCalibAmp(), kFALSE); //Time or TimeR?
559  fClustersArray[iCluster][iDigit] = 0;
560  recPointOk = kTRUE;
561  }
562 
563  if (recPointOk)
564  { // unset the pointer so that a new rec point will be allocated in the next iteration
565  recPoint = 0;
566  recPointOk = kFALSE;
567  }
568  }
569  else
570  {
571  AliError("Error allocating rec points!");
572  break;
573  }
574  }
575 
576  if (!recPointOk)
577  {
578  fRecPoints->RemoveLast();
580  }
581 
582  delete digitsC;
583 
584  AliDebug(1, Form("MakeClusters: Number of digits %d -> (e %f)\n", fDigitsArr->GetEntries(),fMinECut));
585  AliDebug(1, Form("total no of clusters %d from %d digits", fNumberOfECAClusters, fDigitsArr->GetEntriesFast()));
586 }
Bool_t CheckAbsCellId(Int_t absId) const
void EvalDistanceToBadChannels(AliCaloCalibPedestal *caloped)
Int_t fNEtaDigits
! Total number of digits in eta
TBrowser b
Definition: RunAnaESD.C:12
Int_t fNumberOfECAClusters
number of clusters found in EC section
virtual void Calibrate(Float_t &amp, Float_t &time, const Int_t cellId)
AliEMCALDigit *** fClustersArray
! Temporary array that contains clusters
#define TObjArray
void SetShiftEta(Int_t s)
Set fShiftEta; if clusterizer already initialized gives a warning and does nothing.
Float_t GetTime(void) const
Definition: AliEMCALDigit.h:64
TObjArray * fRecPoints
array with EMCAL clusters
void SetCalibAmp(Float_t amp)
Int_t fShiftPhi
Shifting number of cells in phi direction.
Float_t fECAW0
logarithmic weight for the cluster center of gravity calculation
Int_t GetNPhiSuperModule(void) const
Int_t fNClusEtaNoShift
! Max number of clusters in eta
TBenchmark * gBenchmark
Int_t GetNETAdiv(void) const
virtual void SetInput(Int_t numberOfECAClusters, TObjArray *recPoints, TClonesArray *digitsArr)
Int_t GetNumberOfSuperModules(void) const
Cell energy calibration factors container class.
Int_t fNPhiDigits
! Total number of digits in phi
void SetTRUshift(Bool_t b)
Set fTRUshift; if clusterizer already initialized gives a warning and does nothing.
EMCal digits object.
Definition: AliEMCALDigit.h:30
Int_t GetNPhi(void) const
Int_t GetMaximalEnergyIndex(void) const
Finds the maximum energy in the cluster.
#define AliWarning(message)
Definition: AliLog.h:541
void GetCellPhiEtaIndexInSModule(Int_t nSupMod, Int_t nModule, Int_t nIphi, Int_t nIeta, Int_t &iphi, Int_t &ieta) const
void ExecOnce()
Execute clusterizer. Add description.
void SetTime(Float_t time)
Definition: AliEMCALDigit.h:74
Int_t fNphi
Fixed window number of cells in phi direction.
Int_t fNTRUEta
! Number of TRUs in eta
Bool_t fJustClusters
false for standard reco
virtual void GetCalibrationParameters(void)
Bool_t fToUnfold
says if unfolding should be performed
Int_t fNClusPhiNoShift
! Max number of clusters in phi
Int_t fMaxShiftEta
! Max shift index in eta
Bool_t GetCellIndex(Int_t absId, Int_t &nSupMod, Int_t &nModule, Int_t &nIphi, Int_t &nIeta) const
virtual void MakeUnfolding()
virtual void AddDigit(AliEMCALDigit &digit, const Float_t energy, const Bool_t shared)
Int_t fInitialized
! Initialized clusterizer
Int_t fNClusters
! fNClusEtaNoShift x fNClusPhiNoShift
Float_t fTimeMin
minimum time of physical signal in a cell/digit
EMCal rec_points object.
AliEMCALGeometry * fGeom
! pointer to geometry for utilities
Int_t GetNPHIdiv(void) const
Cell time shifts container class.
Int_t fNeta
Fixed window number of cells in eta direction.
Int_t fMaxShiftPhi
! Max shift index in phi
virtual void Digits2Clusters(Option_t *option)
Steering method to perform clusterization for the current event.
Double_t GetCalibAmp() const
pedestal/bad map monitoring and calibration tools
Float_t fTimeMax
maximum time of physical signal in a cell/digit
#define AliFatal(message)
Definition: AliLog.h:640
TClonesArray * fDigitsArr
array with EMCAL digits
void SetNphi(Int_t n)
Set fNphi; if clusterizer already initialized gives a warning and does nothing.
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
AliCaloCalibPedestal * fCaloPed
! tower status map if aval
Int_t GetNEta(void) const
Int_t fNPhiDigitsSupMod
! Number of digits per SM in phi
Bool_t fTRUshift
Allows shifting inside a TRU (true) of through the whole calorimeter (false)
Int_t GetId() const
Definition: AliDigitNew.h:23
virtual void GetCaloCalibPedestal(void)
AliEMCALUnfolding * fClusterUnfolding
! pointer to unfolding object
virtual void EvalAll(Float_t logWeight, TClonesArray *digits, const Bool_t justClusters)
Evaluates cluster parameters: position, shower shape, primaries ...
void MakeClusters()
Make clusters, add more explanation.
TTree * fTreeR
tree with output clusters
Int_t fShiftEta
Shifting number of cells in eta direction.
#define AliError(message)
Definition: AliLog.h:591
Int_t fNTotalClus
! Maximum total number of clusters
Int_t fNTRUPhi
! Number of TRUs in phi
virtual void SetClusterType(Int_t ver)
void SetIndexInList(Int_t val)
Float_t GetAmplitude() const
Definition: AliEMCALDigit.h:55
virtual void Print(Option_t *option) const
Print clusterizer parameters.
EMCal geometry, singleton.
Int_t fNEtaDigitsSupMod
! Number of digits per SM in eta
Float_t fMinECut
minimum energy for a digit to be a member of a cluster
Base class for the clusterization algorithm (pure abstract)
void SetShiftPhi(Int_t s)
Set fShiftPhi; if clusterizer already initialized gives a warning and does nothing.
virtual void PrintRecPoints(Option_t *option)
void SetNeta(Int_t n)
Set fNeta; if clusterizer already initialized gives a warning and does nothing.