AliPhysics  db95e02 (db95e02)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
12 
16 
17 // Actually registers the class with the base class
19 
20 //________________________________________________________________________
22  AliEmcalCorrectionComponent("AliEmcalCorrectionCellEnergy")
23  ,fUseAutomaticRecalib(1)
24  ,fUseAutomaticRunDepRecalib(1)
25  ,fCellEnergyDistBefore(0)
26  ,fCellEnergyDistAfter(0)
27 {
28  // Default constructor
29  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
30 }
31 
32 //________________________________________________________________________
34 {
35  // Destructor
36 }
37 
38 //________________________________________________________________________
40 {
41  // Initialization
42  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
44  // Do base class initializations and if it fails -> bail out
45  //AliAnalysisTaskEmcal::ExecOnce();
46  //if (!fInitialized) return;
47 
48  AliWarning("Init EMCAL cell recalibration");
49 
50  GetProperty("createHistos", fCreateHisto);
51 
52  if(fFilepass.Contains("LHC14a1a")) fUseAutomaticRecalib = kTRUE;
53 
54  if (!fRecoUtils)
55  fRecoUtils = new AliEMCALRecoUtils;
56 
57  // missalignment function -- TODO: not sure if we need this or not
58  fRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
59 
60  return kTRUE;
61 }
62 
63 //________________________________________________________________________
65 {
66  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
68 
69  if (fCreateHisto){
70  fCellEnergyDistBefore = new TH1F("hCellEnergyDistBefore","hCellEnergyDistBefore;E_cell",1000,0,10);
72  fCellEnergyDistAfter = new TH1F("hCellEnergyDistAfter","hCellEnergyDistAfter;E_cell",1000,0,10);
74  }
75 }
76 
77 //________________________________________________________________________
79 {
80  // Run
81  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
83 
84  if (!fEvent) {
85  AliError("Event ptr = 0, returning");
86  return kFALSE;
87  }
88 
89  // Initialising parameters once per run number
90 
91  if (RunChanged())
92  {
93  fRun = fEvent->GetRunNumber();
94  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
95  if (dynamic_cast<AliAODEvent*>(fEvent)) {
96  AliWarning("=============================================================");
97  AliWarning("=== Running on AOD is not equivalent to running on ESD! ===");
98  AliWarning("=============================================================");
99  }
100 
101  // init geometry if not already done
102  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
103 
104  if (!fGeom)
105  {
106  AliFatal("Can not create geometry");
107  return kFALSE;
108  }
109 
110  // init recalibration factors
112  {
113  Int_t fInitRecalib = InitRecalib();
114  if (fInitRecalib==0)
115  AliError("InitRecalib returned false, returning");
116  if (fInitRecalib==1)
117  AliWarning("InitRecalib OK");
118  if (fInitRecalib>1)
119  AliWarning(Form("No recalibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
120  }
121 
123  {
124  Int_t fInitRunDepRecalib = InitRunDepRecalib();
125  if (fInitRunDepRecalib==0)
126  AliError("InitrunDepRecalib returned false, returning");
127  if (fInitRunDepRecalib==1)
128  AliWarning("InitRecalib OK");
129  if (fInitRunDepRecalib>1)
130  AliWarning(Form("No Temperature recalibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
131  }
132 
133  //AliDebug(2, Form("%s", fRecoUtils->Print("")));
134  }
135 
136  // CONFIGURE THE RECO UTILS -------------------------------------------------
137  fRecoUtils->SwitchOnRecalibration();
138 
139  // START PROCESSING ---------------------------------------------------------
140  // Test if cells present
141  if (fCaloCells->GetNumberOfCells()<=0)
142  {
143  AliDebug(2, Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
144  return kTRUE;
145  }
146 
147  // mark the cells not recalibrated
148  fRecoUtils->ResetCellsCalibrated();
149 
150 
151  if(fCreateHisto)
152  FillCellQA(fCellEnergyDistBefore); // "before" QA
153 
154  // CELL RECALIBRATION -------------------------------------------------------
155  // update cell objects
156  UpdateCells();
157 
158  if(fCreateHisto)
159  FillCellQA(fCellEnergyDistAfter); // "after" QA
160 
161  // switch off recalibrations so those are not done multiple times
162  // this is just for safety, the recalibrated flag of cell object
163  // should not allow for farther processing anyways
164  fRecoUtils->SwitchOffRecalibration();
165 
166  return kTRUE;
167 }
168 
169 //_____________________________________________________
171 {
172  // Initialising recalibration factors.
173 
174  if (!fEvent)
175  return 0;
176 
177  AliInfo("Initialising recalibration factors");
178 
179  // init default maps first
180  if (!fRecoUtils->GetEMCALRecalibrationFactorsArray())
181  fRecoUtils->InitEMCALRecalibrationFactors() ;
182 
183  Int_t runRC = fEvent->GetRunNumber();
184 
185  AliOADBContainer *contRF=new AliOADBContainer("");
186  if (fBasePath!="")
187  { //if fBasePath specified
188  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
189 
190  TFile *fRecalib= new TFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read");
191  if (!fRecalib || fRecalib->IsZombie())
192  {
193  AliFatal(Form("EMCALRecalib.root not found in %s",fBasePath.Data()));
194  return 0;
195  }
196 
197  if (fRecalib) delete fRecalib;
198 
199  contRF->InitFromFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"AliEMCALRecalib");
200  }
201  else
202  { // Else choose the one in the $ALICE_PHYSICS directory
203  AliInfo("Loading Recalib OADB from $ALICE_PHYSICS/OADB/EMCAL");
204 
205  TFile *fRecalib= new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALRecalib.root","read");
206  if (!fRecalib || fRecalib->IsZombie())
207  {
208  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALRecalib.root was not found");
209  return 0;
210  }
211 
212  if (fRecalib) delete fRecalib;
213 
214  contRF->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALRecalib.root","AliEMCALRecalib");
215  }
216 
217  TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
218  if (!recal)
219  {
220  AliError(Form("No Objects for run: %d",runRC));
221  delete contRF;
222  return 2;
223  }
224 
225  TObjArray *recalpass=(TObjArray*)recal->FindObject(fFilepass);
226  if (!recalpass)
227  {
228  AliError(Form("No Objects for run: %d - %s",runRC,fFilepass.Data()));
229  delete contRF;
230  return 2;
231  }
232 
233  TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
234  if (!recalib)
235  {
236  AliError(Form("No Recalib histos found for %d - %s",runRC,fFilepass.Data()));
237  delete contRF;
238  return 2;
239  }
240 
241  //AliDebug(1, recalib->Print());
242 
243  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
244  for (Int_t i=0; i<sms; ++i)
245  {
246  TH2F *h = fRecoUtils->GetEMCALChannelRecalibrationFactors(i);
247  if (h)
248  delete h;
249  h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
250  if (!h)
251  {
252  AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
253  continue;
254  }
255  h->SetDirectory(0);
256  fRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
257  }
258 
259  delete contRF;
260 
261  return 1;
262 }
263 
264 //_____________________________________________________
266 {
267  // Initialising recalibration factors.
268 
269  if (!fEvent)
270  return 0;
271 
272  AliInfo("Initialising recalibration factors");
273 
274  // init default maps first
275  if (!fRecoUtils->GetEMCALRecalibrationFactorsArray())
276  fRecoUtils->InitEMCALRecalibrationFactors() ;
277 
278  Int_t runRC = fEvent->GetRunNumber();
279 
280  AliOADBContainer *contRF=new AliOADBContainer("");
281  if (fBasePath!="")
282  { //if fBasePath specified in the ->SetBasePath()
283  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
284 
285  TFile *fRunDepRecalib= new TFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read");
286  if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
287  {
288  AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
289  return 0;
290  }
291 
292  if (fRunDepRecalib) delete fRunDepRecalib;
293 
294  contRF->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"AliEMCALRunDepTempCalibCorrections");
295  }
296  else
297  { // Else choose the one in the $ALICE_PHYSICS directory
298  AliInfo("Loading Recalib OADB from $ALICE_PHYSICS/OADB/EMCAL");
299 
300  TFile *fRunDepRecalib= new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTemperatureCorrCalib.root","read");
301  if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
302  {
303  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
304  return 0;
305  }
306 
307  if (fRunDepRecalib) delete fRunDepRecalib;
308 
309  contRF->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTemperatureCorrCalib.root","AliEMCALRunDepTempCalibCorrections");
310  }
311 
312  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
313 
314  if (!rundeprecal)
315  {
316  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
317  // let's get the closest runnumber instead then..
318  Int_t lower = 0;
319  Int_t ic = 0;
320  Int_t maxEntry = contRF->GetNumberOfEntries();
321 
322  while ((ic < maxEntry) && (contRF->UpperLimit(ic) < runRC)) {
323  lower = ic;
324  ic++;
325  }
326 
327  Int_t closest = lower;
328  if ((ic<maxEntry) &&
329  (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower))) {
330  closest = ic;
331  }
332 
333  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
334  rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);
335  }
336 
337  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
338  Int_t nbins = rundeprecal->GetNbinsX();
339 
340  // Avoid use of Run1 param for Run2
341  if(nSM > 12 && nbins < 12288)
342  {
343  AliError(Form("Total SM is %d but T corrections available for %d channels, skip Init of T recalibration factors",nSM,nbins));
344 
345  delete contRF;
346 
347  return 2;
348  }
349 
350  //AliDebug(1, rundeprecal->Print());
351 
352  for (Int_t ism=0; ism<nSM; ++ism)
353  {
354  for (Int_t icol=0; icol<48; ++icol)
355  {
356  for (Int_t irow=0; irow<24; ++irow)
357  {
358  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
359 
360  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
361  factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
362 
363  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
364  } // columns
365  } // rows
366  } // SM loop
367 
368  delete contRF;
369 
370  return 1;
371 }
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.
AliVEvent * fEvent
! Pointer to event
TList * fOutput
! List of output histograms
Bool_t fCreateHisto
Flag to make some basic histograms.
TH1F * fCellEnergyDistBefore
! cell energy distribution, before energy calibration
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
const Int_t nbins
bool Bool_t
Definition: External.C:53
TString fFilepass
Input data pass number.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.