AliPhysics  9b6b435 (9b6b435)
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  ,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("enableNewTempCalib",fUseNewRunDepTempCalib);
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 new temp. calibration differently. Loading of two OADB objects required for calibration
250  // Calibration can be turned on or off via: enableNewTempCalib: true in the YAML configuration
252  AliInfo("Initialising New recalibration factors");
253 
254  // two files and two OADB containers are needed for the correction factor
255  std::unique_ptr<AliOADBContainer> contTemperature;
256  std::unique_ptr<AliOADBContainer> contParams;
257  std::unique_ptr<TFile> runDepTemperatureFile;
258  std::unique_ptr<TFile> temperatureCalibParamFile;
259 
260  if (fBasePath!="")
261  { //if fBasePath specified in the ->SetBasePath()
262  runDepTemperatureFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCalibSM.root",fBasePath.Data()),"read"));
263  if (!runDepTemperatureFile || runDepTemperatureFile->IsZombie()) {
264  AliFatal(Form("EMCALTemperatureCalibSM.root not found in %s",fBasePath.Data()));
265  return 0;
266  }
267 
268  temperatureCalibParamFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCalibParam.root",fBasePath.Data()),"read"));
269  if (!temperatureCalibParamFile || temperatureCalibParamFile->IsZombie()) {
270  AliFatal(Form("EMCALTemperatureCalibParam.root not found in %s",fBasePath.Data()));
271  return 0;
272  }
273 
274  contTemperature = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepTemperatureFile->Get("AliEMCALTemperatureCalibSM")));
275  contParams = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(temperatureCalibParamFile->Get("AliEMCALTemperatureCalibParam")));
276  }
277  else
278  { // Else choose the one in the $ALICE_PHYSICS directory or on EOS via the wrapper function
279  runDepTemperatureFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCalibSM.root").data(),"read"));
280  if (!runDepTemperatureFile || runDepTemperatureFile->IsZombie()) {
281  AliFatal("OADB/EMCAL/EMCALTemperatureCalibSM.root was not found");
282  return 0;
283  }
284 
285  temperatureCalibParamFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCalibParam.root").data(),"read"));
286  if (!temperatureCalibParamFile || temperatureCalibParamFile->IsZombie()) {
287  AliFatal("OADB/EMCAL/EMCALTemperatureCalibParam.root was not found");
288  return 0;
289  }
290 
291  contTemperature = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepTemperatureFile->Get("AliEMCALTemperatureCalibSM")));
292  contParams = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(temperatureCalibParamFile->Get("AliEMCALTemperatureCalibParam")));
293  }
294 
295  if(!contTemperature || !contParams) {
296  AliError("Temperature or parametrization OADB container not found");
297  return 0;
298  }
299  contTemperature->SetOwner(true);
300  contParams->SetOwner(true);
301 
302  TObjArray *arrayParams=(TObjArray*)contParams->GetObject(runRC);
303  if (!arrayParams)
304  {
305  AliError(Form("No temperature calibration parameters can be found for run number: %d", runRC));
306  return 0;
307  }
308  TH1D *hRundepTemp = (TH1D*)contTemperature->GetObject(runRC);
309  TH1F *hSlopeParam = (TH1F*)arrayParams->FindObject("hParamSlope");
310  TH1F *hA0Param = (TH1F*)arrayParams->FindObject("hParamA0");
311 
312  if (!hRundepTemp || !hSlopeParam || !hA0Param)
313  {
314  AliError(Form("Histogram missing for Run2 temperature calibration for run number: %d", runRC));
315  return 0;
316  }
317 
318  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
319  for (Int_t ism=0; ism<nSM; ++ism)
320  {
321  Double_t temperature = hRundepTemp->GetBinContent(ism+1);
322  for (Int_t icol=0; icol<48; ++icol)
323  {
324  for (Int_t irow=0; irow<24; ++irow)
325  {
326  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
327  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
328  Float_t slope = 0;
329  Float_t offset = 0;
330  slope = hSlopeParam->GetBinContent(absID+1);
331  offset = hA0Param->GetBinContent(absID+1);
332  // Correction is the inverse of the calculated factor
333  if(slope || offset)
334  factor *= 1 / (offset + (slope * temperature) ); // correction dependent on T
335  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
336  } // columns
337  } // rows
338  } // SM loop
339 
340  return 1;
341 
342  // standard treatment of Run1 data
343  } else {
344  if(runRC > 197692){
345  AliInfo("Temperature calibration could not be loaded. Please use enableNewTempCalib: true in your configuration file for Run2 data!");
346  return 0;
347  }
348  AliInfo("Initialising Run1 recalibration factors");
349 
350  std::unique_ptr<AliOADBContainer> contRF;
351  std::unique_ptr<TFile> runDepRecalibFile;
352  if (fBasePath!="")
353  { //if fBasePath specified in the ->SetBasePath()
354  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
355 
356  runDepRecalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read"));
357  if (!runDepRecalibFile || runDepRecalibFile->IsZombie())
358  {
359  AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
360  return 0;
361  }
362 
363  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepRecalibFile->Get("AliEMCALRunDepTempCalibCorrections")));
364  }
365  else
366  { // Else choose the one in the $ALICE_PHYSICS directory or on EOS via the wrapper function
367  AliInfo("Loading Recalib OADB from OADB/EMCAL");
368 
369  runDepRecalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCorrCalib.root").data(),"read"));
370  if (!runDepRecalibFile || runDepRecalibFile->IsZombie())
371  {
372  AliFatal("OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
373  return 0;
374  }
375 
376  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepRecalibFile->Get("AliEMCALRunDepTempCalibCorrections")));
377  }
378  if(!contRF) {
379  AliError("No OADB container found");
380  return 0;
381  }
382  contRF->SetOwner(true);
383 
384  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
385 
386  if (!rundeprecal)
387  {
388  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
389  // let's get the closest runnumber instead then..
390  Int_t lower = 0;
391  Int_t ic = 0;
392  Int_t maxEntry = contRF->GetNumberOfEntries();
393 
394  while ((ic < maxEntry) && (contRF->UpperLimit(ic) < runRC)) {
395  lower = ic;
396  ic++;
397  }
398 
399  Int_t closest = lower;
400  if ((ic<maxEntry) &&
401  (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower))) {
402  closest = ic;
403  }
404 
405  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
406  rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);
407  }
408 
409  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
410 
411  //AliDebug(1, rundeprecal->Print());
412 
413  for (Int_t ism=0; ism<nSM; ++ism)
414  {
415  for (Int_t icol=0; icol<48; ++icol)
416  {
417  for (Int_t irow=0; irow<24; ++irow)
418  {
419  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
420 
421  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
422  factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
423 
424  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
425  } // columns
426  } // rows
427  } // SM loop
428 
429  return 1;
430  }
431 }
432 
438 {
440 
441  if (runChanged) {
442  // init recalibration factors
444  {
445  Int_t fInitRecalib = InitRecalib();
446  if (fInitRecalib==0) {
447  AliError("InitRecalib returned false, returning");
448  }
449  if (fInitRecalib==1) {
450  AliWarning("InitRecalib OK");
451  }
452  if (fInitRecalib>1) {
453  AliWarning(Form("No recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
454  }
455  }
456 
458  {
459  Int_t fInitRunDepRecalib = InitRunDepRecalib();
460  if (fInitRunDepRecalib==0) {
461  AliError("InitrunDepRecalib returned false, returning");
462  }
463  if (fInitRunDepRecalib==1) {
464  AliWarning("InitRecalib OK");
465  }
466  if (fInitRunDepRecalib>1) {
467  AliWarning(Form("No Temperature recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
468  }
469  }
470  }
471  return runChanged;
472 }
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)
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_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.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.