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