AliPhysics  71e3bc7 (71e3bc7)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
12 
16 
17 // Actually registers the class with the base class
19 
24  AliEmcalCorrectionComponent("AliEmcalCorrectionCellTimeCalib")
25  ,fCalibrateTime(kFALSE)
26  ,fCalibrateTimeL1Phase(kFALSE)
27  ,fUseAutomaticTimeCalib(1)
28  ,fCellTimeDistBefore(0)
29  ,fCellTimeDistAfter(0)
30 {
31 }
32 
37 {
38 }
39 
44 {
45  // Initialization
47 
48  AliWarning("Init EMCAL time calibration");
49 
50  GetProperty("createHistos", fCreateHisto);
51 
52  fCalibrateTime = kTRUE;
53 
54  // init reco utils
55  if (!fRecoUtils)
56  fRecoUtils = new AliEMCALRecoUtils;
57 
58  fRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
59 
60  return kTRUE;
61 }
62 
67 {
69 
70  if (fCreateHisto){
71  fCellTimeDistBefore = new TH1F("hCellTimeDistBefore","hCellTimeDistBefore;t_cell",1000,-10e-6,10e-6);
73  fCellTimeDistAfter = new TH1F("hCellTimeDistAfter","hCellTimeDistAfter;t_cell",1000,-10e-6,10e-6);
75  }
76 }
77 
82 {
84 
85  if (!fEvent) {
86  AliError("Event ptr = 0, returning");
87  return kFALSE;
88  }
89 
91 
92  // CONFIGURE THE RECO UTILS -------------------------------------------------
93 
94  // allows time calibration
95  if (fCalibrateTime)
96  fRecoUtils->SwitchOnTimeRecalibration();
97  else
98  fRecoUtils->SwitchOffTimeRecalibration();
99 
100  // allows time calibration with L1 phase
102  fRecoUtils->SwitchOnL1PhaseInTimeRecalibration();
103  else
104  fRecoUtils->SwitchOffL1PhaseInTimeRecalibration();
105 
106  // START PROCESSING ---------------------------------------------------------
107  // Test if cells present
108  if (fCaloCells->GetNumberOfCells()<=0)
109  {
110  AliWarning(Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
111  return kFALSE;
112  }
113 
114  // mark the cells not recalibrated
115  fRecoUtils->ResetCellsCalibrated();
116 
117  if(fCreateHisto)
118  FillCellQA(fCellTimeDistBefore); // "before" QA
119 
120  // CELL RECALIBRATION -------------------------------------------------------
121  // cell objects will be updated
122  UpdateCells();
123 
124  if(fCreateHisto)
125  FillCellQA(fCellTimeDistAfter); // "after" QA
126 
127  return kTRUE;
128 }
129 
134 {
135  // Initialising bad channel maps
136 
137  if (!fEvent)
138  return 0;
139 
140  AliInfo("Initialising time calibration map");
141 
142  // init default maps first
143  if (!fRecoUtils->GetEMCALTimeRecalibrationFactorsArray())
144  fRecoUtils->InitEMCALTimeRecalibrationFactors() ;
145 
146  Int_t runBC = fEvent->GetRunNumber();
147 
148  AliOADBContainer *contBC = new AliOADBContainer("");
149  if (fBasePath!="")
150  { //if fBasePath specified in the ->SetBasePath()
151  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
152 
153  TFile *fbad=new TFile(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"read");
154  if (!fbad || fbad->IsZombie())
155  {
156  AliFatal(Form("EMCALTimeCalib.root was not found in the path provided: %s",fBasePath.Data()));
157  return 0;
158  }
159 
160  if (fbad) delete fbad;
161 
162  contBC->InitFromFile(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"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  TFile *fbad=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeCalib.root","read");
169  if (!fbad || fbad->IsZombie())
170  {
171  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeCalib.root was not found");
172  return 0;
173  }
174 
175  if (fbad) delete fbad;
176 
177  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeCalib.root","AliEMCALTimeCalib");
178  }
179 
180  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
181  if (!arrayBC)
182  {
183  AliError(Form("No external time calibration set for run number: %d", runBC));
184  delete contBC;
185  return 2;
186  }
187 
188  // The calibration object is accessed by specifying a pass
189  // For run 1, the actual pass is used (fFilepass, as determined in AliEmcalCorrectionComponent::GetPass())
190  // For run 2, the pass is always set to pass1 (as a convention)
191  // Other exceptions are hard-coded below
192 
193  TString pass = fFilepass;
194  if (fFilepass=="spc_calo") pass = "pass3";
195  if (fRun > 209121) pass = "pass1";
196 
197  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
198  if (!arrayBCpass)
199  {
200  AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
201  delete contBC;
202  return 2;
203  }
204 
205  arrayBCpass->Print();
206 
207  for(Int_t i = 0; i < 4; i++)
208  {
209  TH1F *h = fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(i);
210  if (h)
211  delete h;
212 
213  h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
214 
215  if (!h)
216  {
217  AliError(Form("Can not get hAllTimeAvBC%d",i));
218  continue;
219  }
220  h->SetDirectory(0);
221  fRecoUtils->SetEMCALChannelTimeRecalibrationFactors(i,h);
222  }
223 
224  delete contBC;
225 
226  return 1;
227 }
228 
233 {
234  // Initialising run-by-run L1 phase in time calibration maps
235 
236  if (!fEvent)
237  return 0;
238 
239  AliInfo("Initialising run-by-run L1 phase in time calibration map");
240 
241  // init default maps first
242  if (!fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationArray())
243  fRecoUtils->InitEMCALL1PhaseInTimeRecalibration() ;
244 
245  Int_t runBC = fEvent->GetRunNumber();
246 
247  AliOADBContainer *contBC = new AliOADBContainer("");
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  TFile *timeFile=new TFile(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  if (timeFile) delete timeFile;
260 
261  contBC->InitFromFile(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"AliEMCALTimeL1PhaseCalib");
262  }
263  else
264  { // Else choose the one in the $ALICE_PHYSICS directory
265  AliInfo("Loading L1 phase in time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
266 
267  TFile *timeFile=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root","read");
268  if (!timeFile || timeFile->IsZombie())
269  {
270  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root was not found");
271  return 0;
272  }
273 
274  if (timeFile) delete timeFile;
275 
276  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root","AliEMCALTimeL1PhaseCalib");
277  }
278 
279  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
280  if (!arrayBC)
281  {
282  AliError(Form("No external L1 phase in time calibration set for run number: %d", runBC));
283  delete contBC;
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  delete contBC;
301  return 2;
302  }
303 
304  arrayBCpass->Print();
305 
306 
307  TH1C *h = fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationForAllSM();
308  if (h) delete h;
309 
310  h = (TH1C*)arrayBCpass->FindObject(Form("h%d",runBC));
311 
312  if (!h) {
313  AliFatal(Form("There is no calibration histogram h%d for this run",runBC));
314  }
315  h->SetDirectory(0);
316  fRecoUtils->SetEMCALL1PhaseInTimeRecalibrationForAllSM(h);
317 
318  delete contBC;
319 
320  return 1;
321 }
322 
328 {
330 
331  if (runChanged) {
332 
333  // define what recalib parameters are needed for various switches
334  // this is based on implementation in AliEMCALRecoUtils
335  Bool_t needTimecalib = fCalibrateTime;
336  if(fRun>209121) fCalibrateTimeL1Phase = kTRUE;
337  Bool_t needTimecalibL1Phase = fCalibrateTime & fCalibrateTimeL1Phase;
338 
339  // init time calibration
340  if (needTimecalib && fUseAutomaticTimeCalib) {
341  Int_t initTC = InitTimeCalibration();
342  if (!initTC) {
343  AliError("InitTimeCalibration returned false, returning");
344  }
345  if (initTC==1) {
346  AliWarning("InitTimeCalib OK");
347  }
348  if (initTC > 1) {
349  AliWarning(Form("No external time calibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
350  }
351  }
352 
353  // init time calibration with L1 phase
354  if (needTimecalibL1Phase && fUseAutomaticTimeCalib) {
355  Int_t initTCL1Phase = InitTimeCalibrationL1Phase();
356  if (!initTCL1Phase) {
357  AliError("InitTimeCalibrationL1Phase returned false, returning");
358  }
359  if (initTCL1Phase==1) {
360  AliWarning("InitTimeCalibL1Phase OK");
361  }
362  if (initTCL1Phase > 1) {
363  AliWarning(Form("No external time calibration L1 phase available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
364  }
365  }
366  }
367  return runChanged;
368 }
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.
AliVEvent * fEvent
! Pointer to event
TList * fOutput
! List of output histograms
Bool_t fCreateHisto
Flag to make some basic histograms.
Time calibration correction component in the EMCal correction framework.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
Bool_t fCalibrateTime
flag cell time calibration
static RegisterCorrectionComponent< AliEmcalCorrectionCellTimeCalib > reg
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.