AliPhysics  4e47bdd (4e47bdd)
 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 
24  AliEmcalCorrectionComponent("AliEmcalCorrectionCellEnergy")
25  ,fUseAutomaticRecalib(1)
26  ,fUseAutomaticRunDepRecalib(1)
27  ,fCellEnergyDistBefore(0)
28  ,fCellEnergyDistAfter(0)
29 {
30 }
31 
36 {
37 }
38 
43 {
44  // Initialization
46 
47  AliWarning("Init EMCAL cell recalibration");
48 
49  GetProperty("createHistos", fCreateHisto);
50 
51  if(fFilepass.Contains("LHC14a1a")) fUseAutomaticRecalib = kTRUE;
52 
53  if (!fRecoUtils)
54  fRecoUtils = new AliEMCALRecoUtils;
55 
56  fRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
57 
58  return kTRUE;
59 }
60 
65 {
67 
68  if (fCreateHisto){
69  fCellEnergyDistBefore = new TH1F("hCellEnergyDistBefore","hCellEnergyDistBefore;E_cell",1000,0,10);
71  fCellEnergyDistAfter = new TH1F("hCellEnergyDistAfter","hCellEnergyDistAfter;E_cell",1000,0,10);
73  }
74 }
75 
80 {
82 
83  if (!fEvent) {
84  AliError("Event ptr = 0, returning");
85  return kFALSE;
86  }
87 
89 
90  // CONFIGURE THE RECO UTILS -------------------------------------------------
91  fRecoUtils->SwitchOnRecalibration();
92 
93  // START PROCESSING ---------------------------------------------------------
94  // Test if cells present
95  if (fCaloCells->GetNumberOfCells()<=0)
96  {
97  AliDebug(2, Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
98  return kFALSE;
99  }
100 
101  // mark the cells not recalibrated
102  fRecoUtils->ResetCellsCalibrated();
103 
104 
105  if(fCreateHisto)
106  FillCellQA(fCellEnergyDistBefore); // "before" QA
107 
108  // CELL RECALIBRATION -------------------------------------------------------
109  // update cell objects
110  UpdateCells();
111 
112  if(fCreateHisto)
113  FillCellQA(fCellEnergyDistAfter); // "after" QA
114 
115  // switch off recalibrations so those are not done multiple times
116  // this is just for safety, the recalibrated flag of cell object
117  // should not allow for farther processing anyways
118  fRecoUtils->SwitchOffRecalibration();
119 
120  return kTRUE;
121 }
122 
127 {
128  if (!fEvent)
129  return 0;
130 
131  AliInfo("Initialising recalibration factors");
132 
133  // init default maps first
134  if (!fRecoUtils->GetEMCALRecalibrationFactorsArray())
135  fRecoUtils->InitEMCALRecalibrationFactors() ;
136 
137  Int_t runRC = fEvent->GetRunNumber();
138 
139  AliOADBContainer *contRF=new AliOADBContainer("");
140  if (fBasePath!="")
141  { //if fBasePath specified
142  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
143 
144  TFile *fRecalib= new TFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"read");
145  if (!fRecalib || fRecalib->IsZombie())
146  {
147  AliFatal(Form("EMCALRecalib.root not found in %s",fBasePath.Data()));
148  return 0;
149  }
150 
151  if (fRecalib) delete fRecalib;
152 
153  contRF->InitFromFile(Form("%s/EMCALRecalib.root",fBasePath.Data()),"AliEMCALRecalib");
154  }
155  else
156  { // Else choose the one in the $ALICE_PHYSICS directory
157  AliInfo("Loading Recalib OADB from $ALICE_PHYSICS/OADB/EMCAL");
158 
159  TFile *fRecalib= new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALRecalib.root","read");
160  if (!fRecalib || fRecalib->IsZombie())
161  {
162  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALRecalib.root was not found");
163  return 0;
164  }
165 
166  if (fRecalib) delete fRecalib;
167 
168  contRF->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALRecalib.root","AliEMCALRecalib");
169  }
170 
171  TObjArray *recal=(TObjArray*)contRF->GetObject(runRC);
172  if (!recal)
173  {
174  AliError(Form("No Objects for run: %d",runRC));
175  delete contRF;
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  delete contRF;
184  return 2;
185  }
186 
187  TObjArray *recalib=(TObjArray*)recalpass->FindObject("Recalib");
188  if (!recalib)
189  {
190  AliError(Form("No Recalib histos found for %d - %s",runRC,fFilepass.Data()));
191  delete contRF;
192  return 2;
193  }
194 
195  //AliDebug(1, recalib->Print());
196 
197  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
198  for (Int_t i=0; i<sms; ++i)
199  {
200  TH2F *h = fRecoUtils->GetEMCALChannelRecalibrationFactors(i);
201  if (h)
202  delete h;
203  h = (TH2F*)recalib->FindObject(Form("EMCALRecalFactors_SM%d",i));
204  if (!h)
205  {
206  AliError(Form("Could not load EMCALRecalFactors_SM%d",i));
207  continue;
208  }
209  h->SetDirectory(0);
210  fRecoUtils->SetEMCALChannelRecalibrationFactors(i,h);
211  }
212 
213  delete contRF;
214 
215  return 1;
216 }
217 
222 {
223  if (!fEvent)
224  return 0;
225 
226  AliInfo("Initialising recalibration factors");
227 
228  // init default maps first
229  if (!fRecoUtils->GetEMCALRecalibrationFactorsArray())
230  fRecoUtils->InitEMCALRecalibrationFactors() ;
231 
232  Int_t runRC = fEvent->GetRunNumber();
233 
234  AliOADBContainer *contRF=new AliOADBContainer("");
235  if (fBasePath!="")
236  { //if fBasePath specified in the ->SetBasePath()
237  AliInfo(Form("Loading Recalib OADB from given path %s",fBasePath.Data()));
238 
239  TFile *fRunDepRecalib= new TFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"read");
240  if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
241  {
242  AliFatal(Form("EMCALTemperatureCorrCalib.root not found in %s",fBasePath.Data()));
243  return 0;
244  }
245 
246  if (fRunDepRecalib) delete fRunDepRecalib;
247 
248  contRF->InitFromFile(Form("%s/EMCALTemperatureCorrCalib.root",fBasePath.Data()),"AliEMCALRunDepTempCalibCorrections");
249  }
250  else
251  { // Else choose the one in the $ALICE_PHYSICS directory
252  AliInfo("Loading Recalib OADB from $ALICE_PHYSICS/OADB/EMCAL");
253 
254  TFile *fRunDepRecalib= new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTemperatureCorrCalib.root","read");
255  if (!fRunDepRecalib || fRunDepRecalib->IsZombie())
256  {
257  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTemperatureCorrCalib.root was not found");
258  return 0;
259  }
260 
261  if (fRunDepRecalib) delete fRunDepRecalib;
262 
263  contRF->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTemperatureCorrCalib.root","AliEMCALRunDepTempCalibCorrections");
264  }
265 
266  TH1S *rundeprecal=(TH1S*)contRF->GetObject(runRC);
267 
268  if (!rundeprecal)
269  {
270  AliWarning(Form("No TemperatureCorrCalib Objects for run: %d",runRC));
271  // let's get the closest runnumber instead then..
272  Int_t lower = 0;
273  Int_t ic = 0;
274  Int_t maxEntry = contRF->GetNumberOfEntries();
275 
276  while ((ic < maxEntry) && (contRF->UpperLimit(ic) < runRC)) {
277  lower = ic;
278  ic++;
279  }
280 
281  Int_t closest = lower;
282  if ((ic<maxEntry) &&
283  (contRF->LowerLimit(ic)-runRC) < (runRC - contRF->UpperLimit(lower))) {
284  closest = ic;
285  }
286 
287  AliWarning(Form("TemperatureCorrCalib Objects found closest id %d from run: %d", closest, contRF->LowerLimit(closest)));
288  rundeprecal = (TH1S*) contRF->GetObjectByIndex(closest);
289  }
290 
291  Int_t nSM = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
292  Int_t nbins = rundeprecal->GetNbinsX();
293 
294  // Avoid use of Run1 param for Run2
295  if(nSM > 12 && nbins < 12288)
296  {
297  AliError(Form("Total SM is %d but T corrections available for %d channels, skip Init of T recalibration factors",nSM,nbins));
298 
299  delete contRF;
300 
301  return 2;
302  }
303 
304  //AliDebug(1, rundeprecal->Print());
305 
306  for (Int_t ism=0; ism<nSM; ++ism)
307  {
308  for (Int_t icol=0; icol<48; ++icol)
309  {
310  for (Int_t irow=0; irow<24; ++irow)
311  {
312  Float_t factor = fRecoUtils->GetEMCALChannelRecalibrationFactor(ism,icol,irow);
313 
314  Int_t absID = fGeom->GetAbsCellIdFromCellIndexes(ism, irow, icol); // original calibration factor
315  factor *= rundeprecal->GetBinContent(absID) / 10000. ; // correction dependent on T
316 
317  fRecoUtils->SetEMCALChannelRecalibrationFactor(ism,icol,irow,factor);
318  } // columns
319  } // rows
320  } // SM loop
321 
322  delete contRF;
323 
324  return 1;
325 }
326 
332 {
334 
335  if (runChanged) {
336  // init recalibration factors
338  {
339  Int_t fInitRecalib = InitRecalib();
340  if (fInitRecalib==0) {
341  AliError("InitRecalib returned false, returning");
342  }
343  if (fInitRecalib==1) {
344  AliWarning("InitRecalib OK");
345  }
346  if (fInitRecalib>1) {
347  AliWarning(Form("No recalibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
348  }
349  }
350 
352  {
353  Int_t fInitRunDepRecalib = InitRunDepRecalib();
354  if (fInitRunDepRecalib==0) {
355  AliError("InitrunDepRecalib returned false, returning");
356  }
357  if (fInitRunDepRecalib==1) {
358  AliWarning("InitRecalib OK");
359  }
360  if (fInitRunDepRecalib>1) {
361  AliWarning(Form("No Temperature recalibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
362  }
363  }
364  }
365  return runChanged;
366 }
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.