AliPhysics  1811c8f (1811c8f)
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)
54 
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 -------------------------------------------------
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
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
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
135 
136  Int_t runRC = fEventManager.InputEvent()->GetRunNumber();
137 
138  std::unique_ptr<AliOADBContainer> contRF;
139  std::unique_ptr<TFile> recalibFile;
140  if (fBasePath!="")
141  { //if fBasePath specified
142  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
143 
144  recalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read"));
145  if (!recalibFile || recalibFile->IsZombie())
146  {
147  AliFatal(Form("EMCALRecalib.root not found in %s",fBasePath.Data()));
148  return 0;
149  }
150 
151  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(recalibFile->Get("AliEMCALRecalib")));
152  }
153  else
154  { // Else choose the one in the $ALICE_PHYSICS directory
155  AliInfo("Loading Recalib OADB from OADB/EMCAL");
156 
157  recalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALRecalib.root").data(),"read"));
158  if (!recalibFile || recalibFile->IsZombie())
159  {
160  AliFatal("OADB/EMCAL/EMCALRecalib.root was not found");
161  return 0;
162  }
163 
164  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(recalibFile->Get("AliEMCALRecalib")));
165  }
166  if(!contRF) {
167  AliError("No OADB container found");
168  return 0;
169  }
170  contRF->SetOwner(true);
171 
172  TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
173  if (!recal)
174  {
175  AliError(Form("No Objects for run: %d",runRC));
176  return 2;
177  }
178 
179  TObjArray *recalpass=(TObjArray*)recal->FindObject(fFilepass);
180  if (!recalpass)
181  {
182  AliError(Form("No Objects for run: %d - %s",runRC,fFilepass.Data()));
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  return 2;
191  }
192 
193  //AliDebug(1, recalib->Print());
194 
195  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
196  for (Int_t i=0; i<sms; ++i)
197  {
199  if (h)
200  delete h;
201  h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
202  if (!h)
203  {
204  AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
205  continue;
206  }
207  h->SetDirectory(0);
209  }
210 
211  return 1;
212 }
213 
218 {
219  if (!fEventManager.InputEvent())
220  return 0;
221 
222  AliInfo("Initialising recalibration factors");
223 
224  // init default maps first
227 
228  Int_t runRC = fEventManager.InputEvent()->GetRunNumber();
229 
230  std::unique_ptr<AliOADBContainer> contRF;
231  std::unique_ptr<TFile> runDepRecalibFile;
232  if (fBasePath!="")
233  { //if fBasePath specified in the ->SetBasePath()
234  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
235 
236  runDepRecalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read"));
237  if (!runDepRecalibFile || runDepRecalibFile->IsZombie())
238  {
239  AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
240  return 0;
241  }
242 
243  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepRecalibFile->Get("AliEMCALRunDepTempCalibCorrections")));
244  }
245  else
246  { // Else choose the one in the $ALICE_PHYSICS directory
247  AliInfo("Loading Recalib OADB from OADB/EMCAL");
248 
249  runDepRecalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTemperatureCorrCalib.root").data(),"read"));
250  if (!runDepRecalibFile || runDepRecalibFile->IsZombie())
251  {
252  AliFatal("OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
253  return 0;
254  }
255 
256  contRF = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(runDepRecalibFile->Get("AliEMCALRunDepTempCalibCorrections")));
257  }
258  if(!contRF) {
259  AliError("No OADB container found");
260  return 0;
261  }
262  contRF->SetOwner(true);
263 
264  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
265 
266  if (!rundeprecal)
267  {
268  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
269  // let's get the closest runnumber instead then..
270  Int_t lower = 0;
271  Int_t ic = 0;
272  Int_t maxEntry = contRF->GetNumberOfEntries();
273 
274  while ((ic < maxEntry) && (contRF->UpperLimit(ic) < runRC)) {
275  lower = ic;
276  ic++;
277  }
278 
279  Int_t closest = lower;
280  if ((ic<maxEntry) &&
281  (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower))) {
282  closest = ic;
283  }
284 
285  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
286  rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);
287  }
288 
289  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
290  Int_t nbins = rundeprecal->GetNbinsX();
291 
292  // Avoid use of Run1 param for Run2
293  if(nSM > 12 && nbins < 12288)
294  {
295  AliError(Form("Total SM is %d but T corrections available for %d channels, skip Init of T recalibration factors",nSM,nbins));
296 
297  return 2;
298  }
299 
300  //AliDebug(1, rundeprecal->Print());
301 
302  for (Int_t ism=0; ism<nSM; ++ism)
303  {
304  for (Int_t icol=0; icol<48; ++icol)
305  {
306  for (Int_t irow=0; irow<24; ++irow)
307  {
308  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
309 
310  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
311  factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
312 
313  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
314  } // columns
315  } // rows
316  } // SM loop
317 
318  return 1;
319 }
320 
326 {
328 
329  if (runChanged) {
330  // init recalibration factors
332  {
333  Int_t fInitRecalib = InitRecalib();
334  if (fInitRecalib==0) {
335  AliError("InitRecalib returned false, returning");
336  }
337  if (fInitRecalib==1) {
338  AliWarning("InitRecalib OK");
339  }
340  if (fInitRecalib>1) {
341  AliWarning(Form("No recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
342  }
343  }
344 
346  {
347  Int_t fInitRunDepRecalib = InitRunDepRecalib();
348  if (fInitRunDepRecalib==0) {
349  AliError("InitrunDepRecalib returned false, returning");
350  }
351  if (fInitRunDepRecalib==1) {
352  AliWarning("InitRecalib OK");
353  }
354  if (fInitRunDepRecalib>1) {
355  AliWarning(Form("No Temperature recalibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
356  }
357  }
358  }
359  return runChanged;
360 }
Energy calibration correction component in the EMCal correction framework.
AliEMCALGeometry * fGeom
! Geometry object
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
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.
const Int_t nbins
bool Bool_t
Definition: External.C:53
void SetEMCALChannelRecalibrationFactors(const TObjArray *map)
TString fFilepass
Input data pass number.