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