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