AliPhysics  ced2227 (ced2227)
AliEmcalCorrectionCellTimeCalib.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionCellTimeCalib
2 //
3 
4 #include <memory>
5 
6 #include <TObjArray.h>
7 #include <TFile.h>
8 #include "AliEMCALGeometry.h"
9 #include "AliOADBContainer.h"
10 #include "AliEMCALRecoUtils.h"
11 #include "AliAODEvent.h"
12 #include "AliDataFile.h"
13 
15 
19 
20 // Actually registers the class with the base class
22 
27  AliEmcalCorrectionComponent("AliEmcalCorrectionCellTimeCalib")
28  ,fCellTimeDistBefore(0)
29  ,fCellTimeDistAfter(0)
30  ,fCalibrateTime(kFALSE)
31  ,fCalibrateTimeL1Phase(kFALSE)
32  ,fUseAutomaticTimeCalib(1)
33 {
34 }
35 
40 {
41 }
42 
47 {
48  // Initialization
50 
51  AliWarning("Init EMCAL time calibration");
52 
53  fCalibrateTime = kTRUE;
54 
55  // init reco utils
56  if (!fRecoUtils)
58 
60 
61  return kTRUE;
62 }
63 
68 {
70 
71  if (fCreateHisto){
72  fCellTimeDistBefore = new TH1F("hCellTimeDistBefore","hCellTimeDistBefore;t_{cell} (s)",1000,-10e-6,10e-6);
74  fCellTimeDistAfter = new TH1F("hCellTimeDistAfter","hCellTimeDistAfter;t_{cell} (s)",1000,-10e-6,10e-6);
76  }
77 }
78 
83 {
85 
86  if (!fEventManager.InputEvent()) {
87  AliError("Event ptr = 0, returning");
88  return kFALSE;
89  }
90 
92 
93  // CONFIGURE THE RECO UTILS -------------------------------------------------
94 
95  // allows time calibration
96  if (fCalibrateTime)
98  else
100 
101  // allows time calibration with L1 phase
104  else
106 
107  // START PROCESSING ---------------------------------------------------------
108  // Test if cells present
109  if (fCaloCells->GetNumberOfCells()<=0)
110  {
111  AliWarning(Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
112  return kFALSE;
113  }
114 
115  // mark the cells not recalibrated
117 
118  if(fCreateHisto)
119  FillCellQA(fCellTimeDistBefore); // "before" QA
120 
121  // CELL RECALIBRATION -------------------------------------------------------
122  // cell objects will be updated
123  UpdateCells();
124 
125  if(fCreateHisto)
126  FillCellQA(fCellTimeDistAfter); // "after" QA
127 
128  return kTRUE;
129 }
130 
135 {
136  // Initialising bad channel maps
137 
138  if (!fEventManager.InputEvent())
139  return 0;
140 
141  AliInfo("Initialising time calibration map");
142 
143  // init default maps first
146 
147  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
148 
149  std::unique_ptr<AliOADBContainer> contTimeCalib;
150  std::unique_ptr<TFile> timeCalibFile;
151  if (fBasePath!="")
152  { //if fBasePath specified in the ->SetBasePath()
153  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
154 
155  timeCalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"read"));
156  if (!timeCalibFile || timeCalibFile->IsZombie())
157  {
158  AliFatal(Form("EMCALTimeCalib.root was not found in the path provided: %s",fBasePath.Data()));
159  return 0;
160  }
161 
162  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeCalibFile->Get("AliEMCALTimeCalib")));
163  }
164  else
165  { // Else choose the one in the $ALICE_PHYSICS directory
166  AliInfo("Loading time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
167 
168  timeCalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTimeCalib.root").data(),"read"));
169  if (!timeCalibFile || timeCalibFile->IsZombie())
170  {
171  AliFatal("OADB/EMCAL/EMCALTimeCalib.root was not found");
172  return 0;
173  }
174 
175  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeCalibFile->Get("AliEMCALTimeCalib")));
176  }
177  if(!contTimeCalib){
178  AliError("No OADB container found");
179  return 0;
180  }
181  contTimeCalib->SetOwner(true);
182 
183  TObjArray *arrayBC=(TObjArray*)contTimeCalib->GetObject(runBC);
184  if (!arrayBC)
185  {
186  AliError(Form("No external time calibration set for run number: %d", runBC));
187  return 2;
188  }
189 
190  // The calibration object is accessed by specifying a pass
191  // For run 1, the actual pass is used (fFilepass, as determined in AliEmcalCorrectionComponent::GetPass())
192  // For run 2, the pass is always set to pass1 (as a convention)
193  // Other exceptions are hard-coded below
194 
195  TString pass = fFilepass;
196  if (fFilepass=="spc_calo") pass = "pass3";
197  if (fRun > 209121) pass = "pass1";
198 
199  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
200  if (!arrayBCpass)
201  {
202  AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
203  return 2;
204  }
205 
206  arrayBCpass->Print();
207 
208  for(Int_t i = 0; i < 4; i++)
209  {
211  if (h)
212  delete h;
213 
214  h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
215 
216  if (!h)
217  {
218  AliError(Form("Can not get hAllTimeAvBC%d",i));
219  continue;
220  }
221  h->SetDirectory(0);
223  }
224 
225  return 1;
226 }
227 
232 {
233  // Initialising run-by-run L1 phase in time calibration maps
234 
235  if (!fEventManager.InputEvent())
236  return 0;
237 
238  AliInfo("Initialising run-by-run L1 phase in time calibration map");
239 
240  // init default maps first
243 
244  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
245 
246  std::unique_ptr<AliOADBContainer> contTimeCalib;
247  std::unique_ptr<TFile> timeFile;
248  if (fBasePath!="")
249  { //if fBasePath specified in the ->SetBasePath()
250  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
251 
252  timeFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"read"));
253  if (!timeFile || timeFile->IsZombie())
254  {
255  AliFatal(Form("EMCALTimeL1PhaseCalib.root was not found in the path provided: %s",fBasePath.Data()));
256  return 0;
257  }
258 
259  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeFile->Get("AliEMCALTimeL1PhaseCalib")));
260  }
261  else
262  { // Else choose the one in the $ALICE_PHYSICS directory
263  AliInfo("Loading L1 phase in time calibration OADB from OADB/EMCAL");
264 
265  timeFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTimeL1PhaseCalib.root").data(),"read"));
266  if (!timeFile || timeFile->IsZombie())
267  {
268  AliFatal("OADB/EMCAL/EMCALTimeL1PhaseCalib.root was not found");
269  return 0;
270  }
271 
272  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeFile->Get("AliEMCALTimeL1PhaseCalib")));
273  }
274  if(!contTimeCalib){
275  AliError("No OADB container found");
276  return 0;
277  }
278  contTimeCalib->SetOwner(true);
279 
280  TObjArray *arrayBC=(TObjArray*)contTimeCalib->GetObject(runBC);
281  if (!arrayBC)
282  {
283  AliError(Form("No external L1 phase in time calibration set for run number: %d", runBC));
284  return 2;
285  }
286 
287  // The calibration object is accessed by specifying a pass
288  // For run 2 (which is the only time L1-phase is implemented), the pass is always set to pass1 (as a convention)
289  // Other exceptions are hard-coded below
290 
291  TString pass = "pass1";
292 
293  if ( fFilepass=="muon_calo_pass1" && fRun > 209121 && fRun < 244284 )
294  pass = "pass0";//period LHC15a-m
295 
296  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
297  if (!arrayBCpass)
298  {
299  AliError(Form("No external L1 phase in time calibration set for: %d -%s", runBC,pass.Data()));
300  return 2;
301  }
302 
303  arrayBCpass->Print();
304 
305 
307  if (h) delete h;
308 
309  h = (TH1C*)arrayBCpass->FindObject(Form("h%d",runBC));
310 
311  if (!h) {
312  AliFatal(Form("There is no calibration histogram h%d for this run",runBC));
313  }
314  h->SetDirectory(0);
316 
317  return 1;
318 }
319 
325 {
327 
328  if (runChanged) {
329 
330  // define what recalib parameters are needed for various switches
331  // this is based on implementation in AliEMCALRecoUtils
332  Bool_t needTimecalib = fCalibrateTime;
333  if(fRun>209121) fCalibrateTimeL1Phase = kTRUE;
334  Bool_t needTimecalibL1Phase = fCalibrateTime & fCalibrateTimeL1Phase;
335 
336  // init time calibration
337  if (needTimecalib && fUseAutomaticTimeCalib) {
338  Int_t initTC = InitTimeCalibration();
339  if (!initTC) {
340  AliError("InitTimeCalibration returned false, returning");
341  }
342  if (initTC==1) {
343  AliWarning("InitTimeCalib OK");
344  }
345  if (initTC > 1) {
346  AliWarning(Form("No external time calibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
347  }
348  }
349 
350  // init time calibration with L1 phase
351  if (needTimecalibL1Phase && fUseAutomaticTimeCalib) {
352  Int_t initTCL1Phase = InitTimeCalibrationL1Phase();
353  if (!initTCL1Phase) {
354  AliError("InitTimeCalibrationL1Phase returned false, returning");
355  }
356  if (initTCL1Phase==1) {
357  AliWarning("InitTimeCalibL1Phase OK");
358  }
359  if (initTCL1Phase > 1) {
360  AliWarning(Form("No external time calibration L1 phase available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
361  }
362  }
363  }
364  return runChanged;
365 }
TH1F * fCellTimeDistAfter
! cell energy distribution, after time calibration
TH1F * GetEMCALChannelTimeRecalibrationFactors(Int_t bc) const
TH1F * fCellTimeDistBefore
! cell energy distribution, before time calibration
void InitEMCALL1PhaseInTimeRecalibration()
TH1C * GetEMCALL1PhaseInTimeRecalibrationForAllSM() const
Bool_t fUseAutomaticTimeCalib
On by default the check in the OADB of the time recalibration.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
Some utilities for cluster and cell treatment.
TObjArray * GetEMCALL1PhaseInTimeRecalibrationArray() const
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
void SwitchOnL1PhaseInTimeRecalibration()
int Int_t
Definition: External.C:63
Bool_t fCalibrateTimeL1Phase
flag cell time calibration with L1phase shift
Base class for correction components in the EMCal correction framework.
TString fBasePath
Base folder path to get root files.
void SetPositionAlgorithm(Int_t alg)
void SwitchOffL1PhaseInTimeRecalibration()
TList * fOutput
! List of output histograms
Bool_t fCreateHisto
Flag to make some basic histograms.
void InitEMCALTimeRecalibrationFactors()
Time calibration correction component in the EMCal correction framework.
void SetEMCALL1PhaseInTimeRecalibrationForAllSM(const TObjArray *map)
AliEmcalCorrectionEventManager fEventManager
Minimal task which inherits from AliAnalysisTaskSE and manages access to the event.
Bool_t fCalibrateTime
flag cell time calibration
TObjArray * GetEMCALTimeRecalibrationFactorsArray() const
static RegisterCorrectionComponent< AliEmcalCorrectionCellTimeCalib > reg
void SetEMCALChannelTimeRecalibrationFactors(const TObjArray *map)
bool Bool_t
Definition: External.C:53
TString fFilepass
Input data pass number.