AliPhysics  251aa1e (251aa1e)
 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 
20 //________________________________________________________________________
22  AliEmcalCorrectionComponent("AliEmcalCorrectionCellTimeCalib")
23  ,fCalibrateTime(kFALSE)
24  ,fCalibrateTimeL1Phase(kFALSE)
25  ,fUseAutomaticTimeCalib(1)
26  ,fCellTimeDistBefore(0)
27  ,fCellTimeDistAfter(0)
28 {
29  // Default constructor
30  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
31 }
32 
33 //________________________________________________________________________
35 {
36  // Destructor
37 }
38 
39 //________________________________________________________________________
41 {
42  // Initialization
43  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
45  // Do base class initializations and if it fails -> bail out
46  //AliAnalysisTaskEmcal::ExecOnce();
47  //if (!fInitialized) return;
48 
49  AliWarning("Init EMCAL time calibration");
50 
51  GetProperty("createHistos", fCreateHisto);
52 
53  fCalibrateTime = kTRUE;
54 
55  // init reco utils
56  if (!fRecoUtils)
57  fRecoUtils = new AliEMCALRecoUtils;
58 
59  // missalignment function -- TODO: do we need this?
60  fRecoUtils->SetPositionAlgorithm(AliEMCALRecoUtils::kPosTowerGlobal);
61 
62  return kTRUE;
63 }
64 
65 //________________________________________________________________________
67 {
68  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
70 
71  if (fCreateHisto){
72  fCellTimeDistBefore = new TH1F("hCellTimeDistBefore","hCellTimeDistBefore;t_cell",1000,-10e-6,10e-6);
74  fCellTimeDistAfter = new TH1F("hCellTimeDistAfter","hCellTimeDistAfter;t_cell",1000,-10e-6,10e-6);
76  }
77 }
78 
79 //________________________________________________________________________
81 {
82  // Run
83  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
85 
86  if (!fEvent) {
87  AliError("Event ptr = 0, returning");
88  return kFALSE;
89  }
90 
91  // Initialising parameters once per run number
92 
93  if (RunChanged())
94  {
95  fRun = fEvent->GetRunNumber();
96  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
97  if (dynamic_cast<AliAODEvent*>(fEvent)) {
98  AliWarning("=============================================================");
99  AliWarning("=== Running on AOD is not equivalent to running on ESD! ===");
100  AliWarning("=============================================================");
101  }
102 
103  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
104  if (!fGeom)
105  {
106  AliFatal("Can not create geometry");
107  return kFALSE;
108  }
109 
110  // define what recalib parameters are needed for various switches
111  // this is based on implementation in AliEMCALRecoUtils
112  Bool_t needTimecalib = fCalibrateTime;
113  if(fRun>209121) fCalibrateTimeL1Phase = kTRUE;
114  Bool_t needTimecalibL1Phase = fCalibrateTime & fCalibrateTimeL1Phase;
115 
116  // init time calibration
117  if (needTimecalib && fUseAutomaticTimeCalib) {
118  Int_t initTC = InitTimeCalibration();
119  if (!initTC)
120  AliError("InitTimeCalibration returned false, returning");
121  if (initTC==1) {
122  AliWarning("InitTimeCalib OK");
123  }
124  if (initTC > 1)
125  AliWarning(Form("No external time calibration available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
126  }
127 
128  // init time calibration with L1 phase
129  if (needTimecalibL1Phase && fUseAutomaticTimeCalib) {
130  Int_t initTCL1Phase = InitTimeCalibrationL1Phase();
131  if (!initTCL1Phase)
132  AliError("InitTimeCalibrationL1Phase returned false, returning");
133  if (initTCL1Phase==1) {
134  AliWarning("InitTimeCalibL1Phase OK");
135  }
136  if (initTCL1Phase > 1)
137  AliWarning(Form("No external time calibration L1 phase available: %d - %s", fEvent->GetRunNumber(), fFilepass.Data()));
138  }
139 
140  //AliDebug(2, fRecoUtils->Print(""));
141  }
142 
143  // CONFIGURE THE RECO UTILS -------------------------------------------------
144  // configure the reco utils
145 
146  // allows time calibration
147  if (fCalibrateTime)
148  fRecoUtils->SwitchOnTimeRecalibration();
149  else
150  fRecoUtils->SwitchOffTimeRecalibration();
151 
152  // allows time calibration with L1 phase
154  fRecoUtils->SwitchOnL1PhaseInTimeRecalibration();
155  else
156  fRecoUtils->SwitchOffL1PhaseInTimeRecalibration();
157 
158  // START PROCESSING ---------------------------------------------------------
159  // Test if cells present
160  if (fCaloCells->GetNumberOfCells()<=0)
161  {
162  AliWarning(Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
163  return kFALSE;
164  }
165 
166  // mark the cells not recalibrated
167  fRecoUtils->ResetCellsCalibrated();
168 
169  if(fCreateHisto)
170  FillCellQA(fCellTimeDistBefore); // "before" QA
171 
172  // CELL RECALIBRATION -------------------------------------------------------
173  // cell objects will be updated
174  UpdateCells();
175 
176  if(fCreateHisto)
177  FillCellQA(fCellTimeDistAfter); // "after" QA
178 
179  return kTRUE;
180 }
181 
182 //_____________________________________________________
184 {
185  // Initialising bad channel maps
186 
187  if (!fEvent)
188  return 0;
189 
190  AliInfo("Initialising time calibration map");
191 
192  // init default maps first
193  if (!fRecoUtils->GetEMCALTimeRecalibrationFactorsArray())
194  fRecoUtils->InitEMCALTimeRecalibrationFactors() ;
195 
196  Int_t runBC = fEvent->GetRunNumber();
197 
198  AliOADBContainer *contBC = new AliOADBContainer("");
199  if (fBasePath!="")
200  { //if fBasePath specified in the ->SetBasePath()
201  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
202 
203  TFile *fbad=new TFile(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"read");
204  if (!fbad || fbad->IsZombie())
205  {
206  AliFatal(Form("EMCALTimeCalib.root was not found in the path provided: %s",fBasePath.Data()));
207  return 0;
208  }
209 
210  if (fbad) delete fbad;
211 
212  contBC->InitFromFile(Form("%s/EMCALTimeCalib.root",fBasePath.Data()),"AliEMCALTimeCalib");
213  }
214  else
215  { // Else choose the one in the $ALICE_PHYSICS directory
216  AliInfo("Loading time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
217 
218  TFile *fbad=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeCalib.root","read");
219  if (!fbad || fbad->IsZombie())
220  {
221  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeCalib.root was not found");
222  return 0;
223  }
224 
225  if (fbad) delete fbad;
226 
227  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeCalib.root","AliEMCALTimeCalib");
228  }
229 
230  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
231  if (!arrayBC)
232  {
233  AliError(Form("No external time calibration set for run number: %d", runBC));
234  delete contBC;
235  return 2;
236  }
237 
238  // Here, it looks for a specific pass
239  TString pass = fFilepass;
240  if (fFilepass=="calo_spc") pass ="pass1";
241  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
242  if (!arrayBCpass)
243  {
244  AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
245  delete contBC;
246  return 2;
247  }
248 
249  arrayBCpass->Print();
250 
251  for(Int_t i = 0; i < 4; i++)
252  {
253  TH1F *h = fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(i);
254  if (h)
255  delete h;
256 
257  h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
258 
259  if (!h)
260  {
261  AliError(Form("Can not get hAllTimeAvBC%d",i));
262  continue;
263  }
264  h->SetDirectory(0);
265  fRecoUtils->SetEMCALChannelTimeRecalibrationFactors(i,h);
266  }
267 
268  delete contBC;
269 
270  return 1;
271 }
272 
273 //_____________________________________________________
275 {
276  // Initialising run-by-run L1 phase in time calibration maps
277 
278  if (!fEvent)
279  return 0;
280 
281  AliInfo("Initialising run-by-run L1 phase in time calibration map");
282 
283  // init default maps first
284  if (!fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationArray())
285  fRecoUtils->InitEMCALL1PhaseInTimeRecalibration() ;
286 
287  Int_t runBC = fEvent->GetRunNumber();
288 
289  AliOADBContainer *contBC = new AliOADBContainer("");
290  if (fBasePath!="")
291  { //if fBasePath specified in the ->SetBasePath()
292  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
293 
294  TFile *timeFile=new TFile(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"read");
295  if (!timeFile || timeFile->IsZombie())
296  {
297  AliFatal(Form("EMCALTimeL1PhaseCalib.root was not found in the path provided: %s",fBasePath.Data()));
298  return 0;
299  }
300 
301  if (timeFile) delete timeFile;
302 
303  contBC->InitFromFile(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"AliEMCALTimeL1PhaseCalib");
304  }
305  else
306  { // Else choose the one in the $ALICE_PHYSICS directory
307  AliInfo("Loading L1 phase in time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
308 
309  TFile *timeFile=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root","read");
310  if (!timeFile || timeFile->IsZombie())
311  {
312  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root was not found");
313  return 0;
314  }
315 
316  if (timeFile) delete timeFile;
317 
318  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALTimeL1PhaseCalib.root","AliEMCALTimeL1PhaseCalib");
319  }
320 
321  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
322  if (!arrayBC)
323  {
324  AliError(Form("No external L1 phase in time calibration set for run number: %d", runBC));
325  delete contBC;
326  return 2;
327  }
328 
329  // Only 1 L1 phase correction possible, except special cases
330  TString pass = "pass1";
331 
332  if ( fFilepass=="muon_calo_pass1" && fRun > 209121 && fRun < 244284 )
333  pass = "pass0";//period LHC15a-m
334 
335  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
336  if (!arrayBCpass)
337  {
338  AliError(Form("No external L1 phase in time calibration set for: %d -%s", runBC,pass.Data()));
339  delete contBC;
340  return 2;
341  }
342 
343  arrayBCpass->Print();
344 
345 
346  TH1C *h = fRecoUtils->GetEMCALL1PhaseInTimeRecalibrationForAllSM();
347  if (h) delete h;
348 
349  h = (TH1C*)arrayBCpass->FindObject(Form("h%d",runBC));
350 
351  if (!h) {
352  AliFatal(Form("There is no calibration histogram h%d for this run",runBC));
353  }
354  h->SetDirectory(0);
355  fRecoUtils->SetEMCALL1PhaseInTimeRecalibrationForAllSM(h);
356 
357  delete contBC;
358 
359  return 1;
360 }
TH1F * fCellTimeDistAfter
! cell energy distribution, after time calibration
AliEMCALGeometry * fGeom
! Geometry object
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
Default YAML configuration.
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.