AliPhysics  ff07904 (ff07904)
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  ,fUseRunDepTempCalibRun2(0)
31 {
32 }
33 
38 {
39 }
40 
45 {
46  // Initialization
48 
49  AliWarning("Init EMCAL cell recalibration");
50 
51  if(fFilepass.Contains("LHC14a1a")) fUseAutomaticRecalib = kTRUE;
52 
53  // check the YAML configuration if the Run2 calibration is requested (default is false)
54  GetProperty("enableRun2TempCalib",fUseRunDepTempCalibRun2);
55 
56  if (!fRecoUtils)
58 
60 
61  return kTRUE;
62 }
63 
68 {
70 
71  if (fCreateHisto){
72  fCellEnergyDistBefore = new TH1F("hCellEnergyDistBefore","hCellEnergyDistBefore;E_{cell} (GeV)",1000,0,10);
74  fCellEnergyDistAfter = new TH1F("hCellEnergyDistAfter","hCellEnergyDistAfter;E_{cell} (GeV)",1000,0,10);
76  }
77 }
78 
83 {
85 
86  if (!fEventManager.InputEvent()) {
87  AliError("Event ptr = 0, returning");
88  return kFALSE;
89  }
90 
92 
93  // CONFIGURE THE RECO UTILS -------------------------------------------------
95 
96  // START PROCESSING ---------------------------------------------------------
97  // Test if cells present
98  if (fCaloCells->GetNumberOfCells()<=0)
99  {
100  AliDebug(2, Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
101  return kFALSE;
102  }
103 
104  // mark the cells not recalibrated
106 
107 
108  if(fCreateHisto)
109  FillCellQA(fCellEnergyDistBefore); // "before" QA
110 
111  // CELL RECALIBRATION -------------------------------------------------------
112  // update cell objects
113  UpdateCells();
114 
115  if(fCreateHisto)
116  FillCellQA(fCellEnergyDistAfter); // "after" QA
117 
118  // switch off recalibrations so those are not done multiple times
119  // this is just for safety, the recalibrated flag of cell object
120  // should not allow for farther processing anyways
122 
123  return kTRUE;
124 }
125 
130 {
131  if (!fEventManager.InputEvent())
132  return 0;
133 
134  AliInfo("Initialising recalibration factors");
135 
136  // init default maps first
139 
140  Int_t runRC = fEventManager.InputEvent()->GetRunNumber();
141 
142  std::unique_ptr<AliOADBContainer> contRF;
143  std::unique_ptr<TFile> recalibFile;
144  if (fBasePath!="")
145  { //if fBasePath specified
146  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
147 
148  recalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read"));
149  if (!recalibFile || recalibFile->IsZombie())
150  {
151  AliFatal(Form("EMCALRecalib.root not found in %s",fBasePath.Data()));
152  return 0;
153  }
154 
155  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(recalibFile->Get("AliEMCALRecalib")));
156  }
157  else
158  { // Else choose the one in the $ALICE_PHYSICS directory
159  AliInfo("Loading Recalib OADB from OADB/EMCAL");
160 
161  recalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALRecalib.root").data(),"read"));
162  if (!recalibFile || recalibFile->IsZombie())
163  {
164  AliFatal("OADB/EMCAL/EMCALRecalib.root was not found");
165  return 0;
166  }
167 
168  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(recalibFile->Get("AliEMCALRecalib")));
169  }
170  if(!contRF) {
171  AliError("No OADB container found");
172  return 0;
173  }
174  contRF->SetOwner(true);
175 
176  TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
177  if (!recal)
178  {
179  AliError(Form("No Objects for run: %d",runRC));
180  return 2;
181  }
182 
183  TObjArray *recalpass=(TObjArray*)recal->FindObject(fFilepass);
184  if (!recalpass)
185  {
186  AliError(Form("No Objects for run: %d - %s",runRC,fFilepass.Data()));
187  return 2;
188  }
189 
190  TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
191  if (!recalib)
192  {
193  AliError(Form("No Recalib histos found for %d - %s",runRC,fFilepass.Data()));
194  return 2;
195  }
196 
197  //AliDebug(1, recalib->Print());
198 
199  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
200  for (Int_t i=0; i<sms; ++i)
201  {
203  if (h)
204  delete h;
205  h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
206  if (!h)
207  {
208  AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
209  continue;
210  }
211  h->SetDirectory(0);
213  }
214 
215  return 1;
216 }
217 
222 {
223  if (!fEventManager.InputEvent())
224  return 0;
225 
226  Int_t runRC = fEventManager.InputEvent()->GetRunNumber();
227 
228  // init default maps first
231 
232  // Treat Run2 calibration differently. Loading of two OADB objects required for calibration
233  // Calibration can be turned on or off via: enableRun2TempCalib: true in the YAML configuration
234  if(runRC > 197692){
235 
236  AliInfo("Initialising Run2 recalibration factors");
237 
239  AliInfo("Temperature calibration for Run2 not requested");
240  return 0;
241  }
242 
243  // two files and two OADB containers are needed for the correction factor
244  std::unique_ptr<AliOADBContainer> contTemperature;
245  std::unique_ptr<AliOADBContainer> contParams;
246  std::unique_ptr<TFile> runDepTemperatureFile;
247  std::unique_ptr<TFile> temperatureCalibParamFile;
248 
249  if (fBasePath!="")
250  { //if fBasePath specified in the ->SetBasePath()
251  runDepTemperatureFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCalibSM.root",fBasePath.Data()),"read"));
252  if (!runDepTemperatureFile || runDepTemperatureFile->IsZombie()) {
253  AliFatal(Form("EMCALTemperatureCalibSM.root not found in %s",fBasePath.Data()));
254  return 0;
255  }
256 
257  temperatureCalibParamFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCalibParam.root",fBasePath.Data()),"read"));
258  if (!temperatureCalibParamFile || temperatureCalibParamFile->IsZombie()) {
259  AliFatal(Form("EMCALTemperatureCalibParam.root not found in %s",fBasePath.Data()));
260  return 0;
261  }
262 
263  contTemperature = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepTemperatureFile->Get("AliEMCALTemperatureCalibSM")));
264  contParams = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(temperatureCalibParamFile->Get("AliEMCALTemperatureCalibParam")));
265  }
266  else
267  { // Else choose the one in the $ALICE_PHYSICS directory or on EOS via the wrapper function
268  runDepTemperatureFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCalibSM.root").data(),"read"));
269  if (!runDepTemperatureFile || runDepTemperatureFile->IsZombie()) {
270  AliFatal("OADB/EMCAL/EMCALTemperatureCalibSM.root was not found");
271  return 0;
272  }
273 
274  temperatureCalibParamFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCalibParam.root").data(),"read"));
275  if (!temperatureCalibParamFile || temperatureCalibParamFile->IsZombie()) {
276  AliFatal("OADB/EMCAL/EMCALTemperatureCalibParam.root was not found");
277  return 0;
278  }
279 
280  contTemperature = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepTemperatureFile->Get("AliEMCALTemperatureCalibSM")));
281  contParams = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(temperatureCalibParamFile->Get("AliEMCALTemperatureCalibParam")));
282  }
283 
284  if(!contTemperature || !contParams) {
285  AliError("Temperature or parametrization OADB container not found");
286  return 0;
287  }
288  contTemperature->SetOwner(true);
289  contParams->SetOwner(true);
290 
291  TObjArray *arrayParams=(TObjArray*)contParams->GetObject(runRC);
292  if (!arrayParams)
293  {
294  AliError(Form("No temperature calibration parameters can be found for run number: %d", runRC));
295  return 0;
296  }
297  TH1D *hRundepTemp = (TH1D*)contTemperature->GetObject(runRC);
298  TH1F *hSlopeParam = (TH1F*)arrayParams->FindObject("hParamSlope");
299  TH1F *hA0Param = (TH1F*)arrayParams->FindObject("hParamA0");
300 
301  if (!hRundepTemp || !hSlopeParam || !hA0Param)
302  {
303  AliError(Form("Histogram missing for Run2 temperature calibration for run number: %d", runRC));
304  return 0;
305  }
306 
307  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
308  for (Int_t ism=0; ism<nSM; ++ism)
309  {
310  Double_t temperature = hRundepTemp->GetBinContent(ism+1);
311  for (Int_t icol=0; icol<48; ++icol)
312  {
313  for (Int_t irow=0; irow<24; ++irow)
314  {
315  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
316  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
317  Float_t slope = 0;
318  Float_t offset = 0;
319  slope = hSlopeParam->GetBinContent(absID+1);
320  offset = hA0Param->GetBinContent(absID+1);
321  // Correction is the inverse of the calculated factor
322  if(slope || offset)
323  factor *= 1 / (offset + (slope * temperature) ); // correction dependent on T
324  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
325  } // columns
326  } // rows
327  } // SM loop
328 
329  return 1;
330 
331  // standard treatment of Run1 data
332  } else {
333 
334  AliInfo("Initialising recalibration factors");
335 
336  std::unique_ptr<AliOADBContainer> contRF;
337  std::unique_ptr<TFile> runDepRecalibFile;
338  if (fBasePath!="")
339  { //if fBasePath specified in the ->SetBasePath()
340  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
341 
342  runDepRecalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read"));
343  if (!runDepRecalibFile || runDepRecalibFile->IsZombie())
344  {
345  AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
346  return 0;
347  }
348 
349  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepRecalibFile->Get("AliEMCALRunDepTempCalibCorrections")));
350  }
351  else
352  { // Else choose the one in the $ALICE_PHYSICS directory or on EOS via the wrapper function
353  AliInfo("Loading Recalib OADB from OADB/EMCAL");
354 
355  runDepRecalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCorrCalib.root").data(),"read"));
356  if (!runDepRecalibFile || runDepRecalibFile->IsZombie())
357  {
358  AliFatal("OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
359  return 0;
360  }
361 
362  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepRecalibFile->Get("AliEMCALRunDepTempCalibCorrections")));
363  }
364  if(!contRF) {
365  AliError("No OADB container found");
366  return 0;
367  }
368  contRF->SetOwner(true);
369 
370  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
371 
372  if (!rundeprecal)
373  {
374  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
375  // let's get the closest runnumber instead then..
376  Int_t lower = 0;
377  Int_t ic = 0;
378  Int_t maxEntry = contRF->GetNumberOfEntries();
379 
380  while ((ic < maxEntry) && (contRF->UpperLimit(ic) < runRC)) {
381  lower = ic;
382  ic++;
383  }
384 
385  Int_t closest = lower;
386  if ((ic<maxEntry) &&
387  (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower))) {
388  closest = ic;
389  }
390 
391  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
392  rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);
393  }
394 
395  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
396 
397  //AliDebug(1, rundeprecal->Print());
398 
399  for (Int_t ism=0; ism<nSM; ++ism)
400  {
401  for (Int_t icol=0; icol<48; ++icol)
402  {
403  for (Int_t irow=0; irow<24; ++irow)
404  {
405  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
406 
407  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
408  factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
409 
410  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
411  } // columns
412  } // rows
413  } // SM loop
414 
415  return 1;
416  }
417 }
418 
424 {
426 
427  if (runChanged) {
428  // init recalibration factors
430  {
431  Int_t fInitRecalib = InitRecalib();
432  if (fInitRecalib==0) {
433  AliError("InitRecalib returned false, returning");
434  }
435  if (fInitRecalib==1) {
436  AliWarning("InitRecalib OK");
437  }
438  if (fInitRecalib>1) {
439  AliWarning(Form("No recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
440  }
441  }
442 
444  {
445  Int_t fInitRunDepRecalib = InitRunDepRecalib();
446  if (fInitRunDepRecalib==0) {
447  AliError("InitrunDepRecalib returned false, returning");
448  }
449  if (fInitRunDepRecalib==1) {
450  AliWarning("InitRecalib OK");
451  }
452  if (fInitRunDepRecalib>1) {
453  AliWarning(Form("No Temperature recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
454  }
455  }
456  }
457  return runChanged;
458 }
Energy calibration correction component in the EMCal correction framework.
AliEMCALGeometry * fGeom
! Geometry object
double Double_t
Definition: External.C:58
TObjArray * GetEMCALRecalibrationFactorsArray() const
TH1F * fCellEnergyDistAfter
! cell energy distribution, after energy calibration
TH2F * GetEMCALChannelRecalibrationFactors(Int_t iSM) const
Definition: External.C:236
Bool_t fUseAutomaticRunDepRecalib
On by default the check in the OADB of the run dependent energy recalibration.
void SetEMCALChannelRecalibrationFactor(Int_t iSM, Int_t iCol, Int_t iRow, Double_t c=1)
Bool_t fUseRunDepTempCalibRun2
Off by default the check in the OADB of the run dependent temp calib Run2.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
Some utilities for cluster and cell treatment.
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
Float_t GetEMCALChannelRecalibrationFactor(Int_t iSM, Int_t iCol, Int_t iRow) const
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
Definition: External.C:212
TString fBasePath
Base folder path to get root files.
void SetPositionAlgorithm(Int_t alg)
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.
bool Bool_t
Definition: External.C:53
void SetEMCALChannelRecalibrationFactors(const TObjArray *map)
TString fFilepass
Input data pass number.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.