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