AliPhysics  ec7afe5 (ec7afe5)
 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  // Here, it looks for a specific pass
189  TString pass = fFilepass;
190  if (fFilepass=="calo_spc") pass ="pass1";
191  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
192  if (!arrayBCpass)
193  {
194  AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
195  delete contBC;
196  return 2;
197  }
198 
199  arrayBCpass->Print();
200 
201  for(Int_t i = 0; i < 4; i++)
202  {
203  TH1F *h = fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(i);
204  if (h)
205  delete h;
206 
207  h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
208 
209  if (!h)
210  {
211  AliError(Form("Can not get hAllTimeAvBC%d",i));
212  continue;
213  }
214  h->SetDirectory(0);
215  fRecoUtils->SetEMCALChannelTimeRecalibrationFactors(i,h);
216  }
217 
218  delete contBC;
219 
220  return 1;
221 }
222 
227 {
228  // Initialising run-by-run L1 phase in time calibration maps
229 
230  if (!fEvent)
231  return 0;
232 
233  AliInfo("Initialising run-by-run L1 phase in time calibration map");
234 
235  // init default maps first
236  if (!fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationArray())
237  fRecoUtils->InitEMCALL1PhaseInTimeRecalibration() ;
238 
239  Int_t runBC = fEvent->GetRunNumber();
240 
241  AliOADBContainer *contBC = new AliOADBContainer("");
242  if (fBasePath!="")
243  { //if fBasePath specified in the ->SetBasePath()
244  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
245 
246  TFile *timeFile=new TFile(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"read");
247  if (!timeFile || timeFile->IsZombie())
248  {
249  AliFatal(Form("EMCALTimeL1PhaseCalib.root was not found in the path provided: %s",fBasePath.Data()));
250  return 0;
251  }
252 
253  if (timeFile) delete timeFile;
254 
255  contBC->InitFromFile(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"AliEMCALTimeL1PhaseCalib");
256  }
257  else
258  { // Else choose the one in the $ALICE_PHYSICS directory
259  AliInfo("Loading L1 phase in time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
260 
261  TFile *timeFile=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root","read");
262  if (!timeFile || timeFile->IsZombie())
263  {
264  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root was not found");
265  return 0;
266  }
267 
268  if (timeFile) delete timeFile;
269 
270  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root","AliEMCALTimeL1PhaseCalib");
271  }
272 
273  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
274  if (!arrayBC)
275  {
276  AliError(Form("No external L1 phase in time calibration set for run number: %d", runBC));
277  delete contBC;
278  return 2;
279  }
280 
281  // Only 1 L1 phase correction possible, except special cases
282  TString pass = "pass1";
283 
284  if ( fFilepass=="muon_calo_pass1" && fRun > 209121 && fRun < 244284 )
285  pass = "pass0";//period LHC15a-m
286 
287  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
288  if (!arrayBCpass)
289  {
290  AliError(Form("No external L1 phase in time calibration set for: %d -%s", runBC,pass.Data()));
291  delete contBC;
292  return 2;
293  }
294 
295  arrayBCpass->Print();
296 
297 
298  TH1C *h = fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationForAllSM();
299  if (h) delete h;
300 
301  h = (TH1C*)arrayBCpass->FindObject(Form("h%d",runBC));
302 
303  if (!h) {
304  AliFatal(Form("There is no calibration histogram h%d for this run",runBC));
305  }
306  h->SetDirectory(0);
307  fRecoUtils->SetEMCALL1PhaseInTimeRecalibrationForAllSM(h);
308 
309  delete contBC;
310 
311  return 1;
312 }
313 
319 {
321 
322  if (runChanged) {
323 
324  // define what recalib parameters are needed for various switches
325  // this is based on implementation in AliEMCALRecoUtils
326  Bool_t needTimecalib = fCalibrateTime;
327  if(fRun>209121) fCalibrateTimeL1Phase = kTRUE;
328  Bool_t needTimecalibL1Phase = fCalibrateTime & fCalibrateTimeL1Phase;
329 
330  // init time calibration
331  if (needTimecalib && fUseAutomaticTimeCalib) {
332  Int_t initTC = InitTimeCalibration();
333  if (!initTC) {
334  AliError("InitTimeCalibration returned false, returning");
335  }
336  if (initTC==1) {
337  AliWarning("InitTimeCalib OK");
338  }
339  if (initTC > 1) {
340  AliWarning(Form("No external time calibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
341  }
342  }
343 
344  // init time calibration with L1 phase
345  if (needTimecalibL1Phase && fUseAutomaticTimeCalib) {
346  Int_t initTCL1Phase = InitTimeCalibrationL1Phase();
347  if (!initTCL1Phase) {
348  AliError("InitTimeCalibrationL1Phase returned false, returning");
349  }
350  if (initTCL1Phase==1) {
351  AliWarning("InitTimeCalibL1Phase OK");
352  }
353  if (initTCL1Phase > 1) {
354  AliWarning(Form("No external time calibration L1 phase available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
355  }
356  }
357  }
358  return runChanged;
359 }
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.