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