AliPhysics  64bcec2 (64bcec2)
AliEmcalCorrectionCellEnergy.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionCellEnergy
2 //
3 
4 #include <TObjArray.h>
5 #include <TFile.h>
6 #include "AliEMCALGeometry.h"
7 #include "AliOADBContainer.h"
8 #include "AliEMCALRecoUtils.h"
9 #include "AliAODEvent.h"
10 #include "AliDataFile.h"
11 
13 
17 
18 // Actually registers the class with the base class
20 
25  AliEmcalCorrectionComponent("AliEmcalCorrectionCellEnergy")
26  ,fCellEnergyDistBefore(0)
27  ,fCellEnergyDistAfter(0)
28  ,fUseAutomaticRecalib(1)
29  ,fUseAutomaticRunDepRecalib(1)
30 {
31 }
32 
37 {
38 }
39 
44 {
45  // Initialization
47 
48  AliWarning("Init EMCAL cell recalibration");
49 
50  if(fFilepass.Contains("LHC14a1a")) fUseAutomaticRecalib = kTRUE;
51 
52  if (!fRecoUtils)
53  fRecoUtils = new AliEMCALRecoUtils;
54 
55  fRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
56 
57  return kTRUE;
58 }
59 
64 {
66 
67  if (fCreateHisto){
68  fCellEnergyDistBefore = new TH1F("hCellEnergyDistBefore","hCellEnergyDistBefore;E_{cell} (GeV)",1000,0,10);
70  fCellEnergyDistAfter = new TH1F("hCellEnergyDistAfter","hCellEnergyDistAfter;E_{cell} (GeV)",1000,0,10);
72  }
73 }
74 
79 {
81 
82  if (!fEventManager.InputEvent()) {
83  AliError("Event ptr = 0, returning");
84  return kFALSE;
85  }
86 
88 
89  // CONFIGURE THE RECO UTILS -------------------------------------------------
90  fRecoUtils->SwitchOnRecalibration();
91 
92  // START PROCESSING ---------------------------------------------------------
93  // Test if cells present
94  if (fCaloCells->GetNumberOfCells()<=0)
95  {
96  AliDebug(2, Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
97  return kFALSE;
98  }
99 
100  // mark the cells not recalibrated
101  fRecoUtils->ResetCellsCalibrated();
102 
103 
104  if(fCreateHisto)
105  FillCellQA(fCellEnergyDistBefore); // "before" QA
106 
107  // CELL RECALIBRATION -------------------------------------------------------
108  // update cell objects
109  UpdateCells();
110 
111  if(fCreateHisto)
112  FillCellQA(fCellEnergyDistAfter); // "after" QA
113 
114  // switch off recalibrations so those are not done multiple times
115  // this is just for safety, the recalibrated flag of cell object
116  // should not allow for farther processing anyways
117  fRecoUtils->SwitchOffRecalibration();
118 
119  return kTRUE;
120 }
121 
126 {
127  if (!fEventManager.InputEvent())
128  return 0;
129 
130  AliInfo("Initialising recalibration factors");
131 
132  // init default maps first
133  if (!fRecoUtils->GetEMCALRecalibrationFactorsArray())
134  fRecoUtils->InitEMCALRecalibrationFactors() ;
135 
136  Int_t runRC = fEventManager.InputEvent()->GetRunNumber();
137 
138  AliOADBContainer *contRF=new AliOADBContainer("");
139  if (fBasePath!="")
140  { //if fBasePath specified
141  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
142 
143  TFile *fRecalib= new TFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read");
144  if (!fRecalib || fRecalib->IsZombie())
145  {
146  AliFatal(Form("EMCALRecalib.root not found in %s",fBasePath.Data()));
147  return 0;
148  }
149 
150  if (fRecalib) delete fRecalib;
151 
152  contRF->InitFromFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"AliEMCALRecalib");
153  }
154  else
155  { // Else choose the one in the $ALICE_PHYSICS directory
156  AliInfo("Loading Recalib OADB from OADB/EMCAL");
157 
158  TFile *fRecalib= new TFile(AliDataFile::GetFileNameOADB("EMCAL/EMCALRecalib.root").data(),"read");
159  if (!fRecalib || fRecalib->IsZombie())
160  {
161  AliFatal("OADB/EMCAL/EMCALRecalib.root was not found");
162  return 0;
163  }
164 
165  if (fRecalib) delete fRecalib;
166 
167  contRF->InitFromFile(AliDataFile::GetFileNameOADB("EMCAL/EMCALRecalib.root").data(),"AliEMCALRecalib");
168  }
169 
170  TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
171  if (!recal)
172  {
173  AliError(Form("No Objects for run: %d",runRC));
174  delete contRF;
175  return 2;
176  }
177 
178  TObjArray *recalpass=(TObjArray*)recal->FindObject(fFilepass);
179  if (!recalpass)
180  {
181  AliError(Form("No Objects for run: %d - %s",runRC,fFilepass.Data()));
182  delete contRF;
183  return 2;
184  }
185 
186  TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
187  if (!recalib)
188  {
189  AliError(Form("No Recalib histos found for %d - %s",runRC,fFilepass.Data()));
190  delete contRF;
191  return 2;
192  }
193 
194  //AliDebug(1, recalib->Print());
195 
196  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
197  for (Int_t i=0; i<sms; ++i)
198  {
199  TH2F *h = fRecoUtils->GetEMCALChannelRecalibrationFactors(i);
200  if (h)
201  delete h;
202  h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
203  if (!h)
204  {
205  AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
206  continue;
207  }
208  h->SetDirectory(0);
209  fRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
210  }
211 
212  delete contRF;
213 
214  return 1;
215 }
216 
221 {
222  if (!fEventManager.InputEvent())
223  return 0;
224 
225  // MF Disable temperature calibration for run2 for the moment
226  // A memory leak in the AliOADBContainer was observed when the
227  // container is deleted. As consequence when processing multiple
228  // runs the correction task leaks ~100 MB per run included in the
229  // job, where 70% of the memory leak comes from the temperature
230  // calibration. Untill a fix is provided the temperature calibration
231  // has to be disabled for run2 runs. Disabling has to be done before
232  // opening the OADB container
233  //
234  // For more information see https://alice.its.cern.ch/jira/browse/EMCAL-135
235  if(fEventManager.InputEvent()->GetRunNumber() > 197692){
236  AliError("Temperature recalibration disabled for run2");
237  return 0;
238  }
239 
240  AliInfo("Initialising recalibration factors");
241 
242  // init default maps first
243  if (!fRecoUtils->GetEMCALRecalibrationFactorsArray())
244  fRecoUtils->InitEMCALRecalibrationFactors() ;
245 
246  Int_t runRC = fEventManager.InputEvent()->GetRunNumber();
247 
248  AliOADBContainer *contRF=new AliOADBContainer("");
249  if (fBasePath!="")
250  { //if fBasePath specified in the ->SetBasePath()
251  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
252 
253  TFile *fRunDepRecalib= new TFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read");
254  if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
255  {
256  AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
257  return 0;
258  }
259 
260  if (fRunDepRecalib) delete fRunDepRecalib;
261 
262  contRF->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"AliEMCALRunDepTempCalibCorrections");
263  }
264  else
265  { // Else choose the one in the $ALICE_PHYSICS directory
266  AliInfo("Loading Recalib OADB from OADB/EMCAL");
267 
268  TFile *fRunDepRecalib= new TFile(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCorrCalib.root").data(),"read");
269  if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
270  {
271  AliFatal("OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
272  return 0;
273  }
274 
275  if (fRunDepRecalib) delete fRunDepRecalib;
276 
277  contRF->InitFromFile(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCorrCalib.root").data(),"AliEMCALRunDepTempCalibCorrections");
278  }
279 
280  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
281 
282  if (!rundeprecal)
283  {
284  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
285  // let's get the closest runnumber instead then..
286  Int_t lower = 0;
287  Int_t ic = 0;
288  Int_t maxEntry = contRF->GetNumberOfEntries();
289 
290  while ((ic < maxEntry) && (contRF->UpperLimit(ic) < runRC)) {
291  lower = ic;
292  ic++;
293  }
294 
295  Int_t closest = lower;
296  if ((ic<maxEntry) &&
297  (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower))) {
298  closest = ic;
299  }
300 
301  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
302  rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);
303  }
304 
305  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
306  Int_t nbins = rundeprecal->GetNbinsX();
307 
308  // Avoid use of Run1 param for Run2
309  if(nSM > 12 && nbins < 12288)
310  {
311  AliError(Form("Total SM is %d but T corrections available for %d channels, skip Init of T recalibration factors",nSM,nbins));
312 
313  delete contRF;
314 
315  return 2;
316  }
317 
318  //AliDebug(1, rundeprecal->Print());
319 
320  for (Int_t ism=0; ism<nSM; ++ism)
321  {
322  for (Int_t icol=0; icol<48; ++icol)
323  {
324  for (Int_t irow=0; irow<24; ++irow)
325  {
326  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
327 
328  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
329  factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
330 
331  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
332  } // columns
333  } // rows
334  } // SM loop
335 
336  delete contRF;
337 
338  return 1;
339 }
340 
346 {
348 
349  if (runChanged) {
350  // init recalibration factors
352  {
353  Int_t fInitRecalib = InitRecalib();
354  if (fInitRecalib==0) {
355  AliError("InitRecalib returned false, returning");
356  }
357  if (fInitRecalib==1) {
358  AliWarning("InitRecalib OK");
359  }
360  if (fInitRecalib>1) {
361  AliWarning(Form("No recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
362  }
363  }
364 
366  {
367  Int_t fInitRunDepRecalib = InitRunDepRecalib();
368  if (fInitRunDepRecalib==0) {
369  AliError("InitrunDepRecalib returned false, returning");
370  }
371  if (fInitRunDepRecalib==1) {
372  AliWarning("InitRecalib OK");
373  }
374  if (fInitRunDepRecalib>1) {
375  AliWarning(Form("No Temperature recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
376  }
377  }
378  }
379  return runChanged;
380 }
Energy calibration correction component in the EMCal correction framework.
AliEMCALGeometry * fGeom
! Geometry object
TH1F * fCellEnergyDistAfter
! cell energy distribution, after energy calibration
Definition: External.C:236
Bool_t fUseAutomaticRunDepRecalib
On by default the check in the OADB of the run dependent energy recalibration.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Bool_t fUseAutomaticRecalib
On by default the check in the OADB of the energy recalibration.
Base class for correction components in the EMCal correction framework.
static RegisterCorrectionComponent< AliEmcalCorrectionCellEnergy > reg
TString fBasePath
Base folder path to get root files.
TList * fOutput
! List of output histograms
Bool_t fCreateHisto
Flag to make some basic histograms.
TH1F * fCellEnergyDistBefore
! cell energy distribution, before energy calibration
AliEmcalCorrectionEventManager fEventManager
Minimal task which inherits from AliAnalysisTaskSE and manages access to the event.
const Int_t nbins
bool Bool_t
Definition: External.C:53
TString fFilepass
Input data pass number.