AliPhysics  master (3d17d9d)
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  ,fDoMergedBCs(kFALSE)
33  ,fDoCalibrateLowGain(kFALSE)
34  ,fDoCalibMergedLG(kFALSE)
35  ,fUseAutomaticTimeCalib(1)
36 {
37 }
38 
43 {
44 }
45 
50 {
51  // Initialization
53 
54  AliWarning("Init EMCAL time calibration");
55 
56  fCalibrateTime = kTRUE;
57 
58  // init reco utils
59  if (!fRecoUtils)
61 
62  GetProperty("doMergedBCs", fDoMergedBCs);
63 
64  if (fDoMergedBCs)
66 
67  GetProperty("doCalibrateLowGain", fDoCalibrateLowGain);
68 
69  GetProperty("doCalibMergedLG", fDoCalibMergedLG);
70 
73  else
75 
77 
78  return kTRUE;
79 }
80 
85 {
87 
88  if (fCreateHisto){
89  fCellTimeDistBefore = new TH1F("hCellTimeDistBefore","hCellTimeDistBefore;t_{cell} (s)",1000,-10e-6,10e-6);
91  fCellTimeDistAfter = new TH1F("hCellTimeDistAfter","hCellTimeDistAfter;t_{cell} (s)",1000,-10e-6,10e-6);
93  }
94 }
95 
100 {
102 
103  if (!fEventManager.InputEvent()) {
104  AliError("Event ptr = 0, returning");
105  return kFALSE;
106  }
107 
109 
110  // CONFIGURE THE RECO UTILS -------------------------------------------------
111 
112  // allows time calibration
113  if (fCalibrateTime)
115  else
117 
118  // allows time calibration with L1 phase
121  else
123 
124  // START PROCESSING ---------------------------------------------------------
125  // Test if cells present
126  if (fCaloCells->GetNumberOfCells()<=0)
127  {
128  AliWarning(Form("Number of EMCAL cells = %d, returning", fCaloCells->GetNumberOfCells()));
129  return kFALSE;
130  }
131 
132  // mark the cells not recalibrated
134 
135  if(fCreateHisto)
136  FillCellQA(fCellTimeDistBefore); // "before" QA
137 
138  // CELL RECALIBRATION -------------------------------------------------------
139  // cell objects will be updated
140  UpdateCells();
141 
142  if(fCreateHisto)
143  FillCellQA(fCellTimeDistAfter); // "after" QA
144 
145  return kTRUE;
146 }
147 
152 {
153  // Initialising bad channel maps
154 
155  if (!fEventManager.InputEvent())
156  return 0;
157 
158  AliInfo("Initialising time calibration map");
159 
160  // init default maps first
163 
164  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
165 
166  std::unique_ptr<AliOADBContainer> contTimeCalib;
167  std::unique_ptr<TFile> timeCalibFile;
168  if (fBasePath!="")
169  { //if fBasePath specified in the ->SetBasePath()
170  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
171 
172  timeCalibFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTimeCalib%s.root",fBasePath.Data(), fDoMergedBCs ? "MergedBCs" : "" ),"read"));
173  if (!timeCalibFile || timeCalibFile->IsZombie())
174  {
175  AliFatal(Form("EMCALTimeCalib%s.root was not found in the path provided: %s", fDoMergedBCs ? "MergedBCs" : "" ,fBasePath.Data()));
176  return 0;
177  }
178 
179  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeCalibFile->Get("AliEMCALTimeCalib")));
180  }
181  else
182  { // Else choose the one in the $ALICE_PHYSICS directory
183  AliInfo("Loading time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
184 
185  timeCalibFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB(Form("EMCAL/EMCALTimeCalib%s.root", fDoMergedBCs ? "MergedBCs" : "")).data(),"read"));
186  if (!timeCalibFile || timeCalibFile->IsZombie())
187  {
188  AliFatal(Form("OADB/EMCAL/EMCALTimeCalib%s.root was not found", fDoMergedBCs ? "MergedBCs" : ""));
189  return 0;
190  }
191 
192  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeCalibFile->Get("AliEMCALTimeCalib")));
193  }
194  if(!contTimeCalib){
195  AliError("No OADB container found");
196  return 0;
197  }
198  contTimeCalib->SetOwner(true);
199 
200  TObjArray *arrayBC=(TObjArray*)contTimeCalib->GetObject(runBC);
201  if (!arrayBC)
202  {
203  AliError(Form("No external time calibration set for run number: %d", runBC));
204  return 2;
205  }
206 
207  // The calibration object is accessed by specifying a pass
208  // For run 1, the actual pass is used (fFilepass, as determined in AliEmcalCorrectionComponent::GetPass())
209  // For run 2, the pass is always set to pass1 (as a convention)
210  // Other exceptions are hard-coded below
211 
212  TString pass = fFilepass;
213  if (fFilepass=="spc_calo") pass = "pass3";
214  if (fRun > 209121) pass = "pass1";
215 
216  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
217  if (!arrayBCpass)
218  {
219  AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
220  return 2;
221  }
222 
223  arrayBCpass->Print();
224 
225  if(!fDoMergedBCs){
226  for(Int_t i = 0; i < 4; i++)
227  {
229  if (h)
230  delete h;
231 
232  h = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvBC%d",i));
233 
234  if (!h)
235  {
236  AliError(Form("Can not get hAllTimeAvBC%d",i));
237  continue;
238  }
239 
240  // Shift parameters for bc0 and bc1 in this pass
241  if ( pass=="spc_calo" && (i==0 || i==1) )
242  {
243  for(Int_t icell = 0; icell < h->GetNbinsX(); icell++)
244  h->SetBinContent(icell,h->GetBinContent(icell)-100);
245  }
246 
247  h->SetDirectory(0);
249 
251  TH1F *hLG = (TH1F*)fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(i+4);
252  if (hLG)
253  delete hLG;
254 
255  hLG = (TH1F*)arrayBCpass->FindObject(Form("hAllTimeAvLGBC%d",i));
256 
257  if (!hLG)
258  {
259  AliError(Form("Can not get hAllTimeAvLGBC%d",i));
260  continue;
261  }
262 
263  // Shift parameters for bc0 and bc1 in this pass
264  if ( pass=="spc_calo" && (i==0 || i==1) )
265  {
266  for(Int_t icell = 0; icell < hLG->GetNbinsX(); icell++)
267  hLG->SetBinContent(icell,hLG->GetBinContent(icell)-100);
268  }
269 
270  hLG->SetDirectory(0);
272  }
273  }
274  }else{
275 
276  TH1S *h = (TH1S*)fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(0);//HG cells
277  if (h)
278  delete h;
279 
280  h = (TH1S*)arrayBCpass->FindObject("hAllTimeAv");
281 
282  if (!h)
283  AliError("Can not get hAllTimeAv");
284 
285  h->SetDirectory(0);
287 
289  TH1S *hLG = (TH1S*)fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(1);//LG cells
290  if (hLG)
291  delete hLG;
292 
293  hLG = (TH1S*)arrayBCpass->FindObject("hAllTimeAvLG");
294 
295  if (!hLG)
296  AliError("Can not get hAllTimeAvLG");
297 
298  hLG->SetDirectory(0);
300  }
301  }
302 
303  if(fDoCalibMergedLG){
304 
305  std::unique_ptr<AliOADBContainer> contTimeCalibLG;
306  std::unique_ptr<TFile> timeCalibFileLG;
307  if (fBasePath!="")
308  { //if fBasePath specified in the ->SetBasePath()
309  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
310 
311  timeCalibFileLG = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTimeCalibMergedBCsLG.root",fBasePath.Data()),"read"));
312  if (!timeCalibFileLG || timeCalibFileLG->IsZombie())
313  {
314  AliFatal(Form("EMCALTimeCalibMergedBCsLG.root was not found in the path provided: %s",fBasePath.Data()));
315  return 0;
316  }
317 
318  contTimeCalibLG = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeCalibFileLG->Get("AliEMCALTimeCalib")));
319  }
320  else
321  { // Else choose the one in the $ALICE_PHYSICS directory
322  AliInfo("Loading time calibration OADB from $ALICE_PHYSICS/OADB/EMCAL");
323 
324  timeCalibFileLG = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTimeCalibMergedBCsLG.root").data(),"read"));
325  if (!timeCalibFileLG || timeCalibFileLG->IsZombie())
326  {
327  AliFatal("OADB/EMCAL/EMCALTimeCalibMergedBCsLG.root was not found");
328  return 0;
329  }
330 
331  contTimeCalibLG = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeCalibFileLG->Get("AliEMCALTimeCalib")));
332  }
333  if(!contTimeCalibLG){
334  AliError("No OADB container found");
335  return 0;
336  }
337  contTimeCalibLG->SetOwner(true);
338 
339  TObjArray *arrayBCLG=(TObjArray*)contTimeCalibLG->GetObject(runBC);
340  if (!arrayBCLG)
341  {
342  AliError(Form("No external time calibration set for run number: %d", runBC));
343  return 2;
344  }
345 
346  TObjArray *arrayBCpassLG=(TObjArray*)arrayBCLG->FindObject(pass);
347  if (!arrayBCpassLG)
348  {
349  AliError(Form("No external time calibration set for: %d -%s", runBC,pass.Data()));
350  return 2;
351  }
352 
353  arrayBCpassLG->Print();
354 
355  TH1S *hLG = (TH1S*)fRecoUtils->GetEMCALChannelTimeRecalibrationFactors(1);//LG cells
356  if (hLG)
357  delete hLG;
358 
359  hLG = (TH1S*)arrayBCpassLG->FindObject("hAllTimeAvLG");
360 
361  if (!hLG)
362  AliError("Can not get hAllTimeAvLG");
363 
364  hLG->SetDirectory(0);
366 
367  }
368 
369  return 1;
370 }
371 
376 {
377  // Initialising run-by-run L1 phase in time calibration maps
378 
379  if (!fEventManager.InputEvent())
380  return 0;
381 
382  AliInfo("Initialising run-by-run L1 phase in time calibration map");
383 
384  // init default maps first
387 
388  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
389 
390  std::unique_ptr<AliOADBContainer> contTimeCalib;
391  std::unique_ptr<TFile> timeFile;
392  if (fBasePath!="")
393  { //if fBasePath specified in the ->SetBasePath()
394  AliInfo(Form("Loading time calibration OADB from given path %s",fBasePath.Data()));
395 
396  timeFile = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALTimeL1PhaseCalib.root",fBasePath.Data()),"read"));
397  if (!timeFile || timeFile->IsZombie())
398  {
399  AliFatal(Form("EMCALTimeL1PhaseCalib.root was not found in the path provided: %s",fBasePath.Data()));
400  return 0;
401  }
402 
403  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeFile->Get("AliEMCALTimeL1PhaseCalib")));
404  }
405  else
406  { // Else choose the one in the $ALICE_PHYSICS directory
407  AliInfo("Loading L1 phase in time calibration OADB from OADB/EMCAL");
408 
409  timeFile = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALTimeL1PhaseCalib.root").data(),"read"));
410  if (!timeFile || timeFile->IsZombie())
411  {
412  AliFatal("OADB/EMCAL/EMCALTimeL1PhaseCalib.root was not found");
413  return 0;
414  }
415 
416  contTimeCalib = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(timeFile->Get("AliEMCALTimeL1PhaseCalib")));
417  }
418  if(!contTimeCalib){
419  AliError("No OADB container found");
420  return 0;
421  }
422  contTimeCalib->SetOwner(true);
423 
424  TObjArray *arrayBC=(TObjArray*)contTimeCalib->GetObject(runBC);
425  if (!arrayBC)
426  {
427  AliError(Form("No external L1 phase in time calibration set for run number: %d", runBC));
428  return 2;
429  }
430 
431  // The calibration object is accessed by specifying a pass
432  // For run 2 (which is the only time L1-phase is implemented), the pass is always set to pass1 (as a convention)
433  // Other exceptions are hard-coded below
434 
435  TString pass = "pass1";
436 
437  if ( fFilepass=="muon_calo_pass1" && fRun > 209121 && fRun < 244284 )
438  pass = "pass0";//period LHC15a-m
439 
440  TObjArray *arrayBCpass=(TObjArray*)arrayBC->FindObject(pass);
441  if (!arrayBCpass)
442  {
443  AliError(Form("No external L1 phase in time calibration set for: %d -%s", runBC,pass.Data()));
444  return 2;
445  }
446 
447  arrayBCpass->Print();
448 
449 
451  if (h) delete h;
452 
453  h = (TH1C*)arrayBCpass->FindObject(Form("h%d",runBC));
454 
455  if (!h) {
456  AliFatal(Form("There is no calibration histogram h%d for this run",runBC));
457  }
458  h->SetDirectory(0);
460 
461  //Now special case for PAR runs
463  //access tree from OADB file
464  TTree *tGID = (TTree*)arrayBCpass->FindObject(Form("h%d_GID",runBC));
465  if(tGID){//check whether present = PAR run
467  //access tree branch with PARs
468  ULong64_t parGlobalBCs;
469  tGID->SetBranchAddress("GID",&parGlobalBCs);
470  //set number of PARs in run
471  Short_t nPars = (Short_t) tGID->GetEntries();
472  fRecoUtils->SetNPars((Short_t)nPars);
473  //set global ID for each PAR
474  for (Short_t iParNumber = 0; iParNumber < nPars; ++iParNumber) {
475  tGID->GetEntry(iParNumber);
476  fRecoUtils->SetGlobalIDPar(parGlobalBCs,iParNumber);
477  }//loop over entries
478 
479  //access GlobalID hiostograms for each PAR
480  for(Short_t iParNumber=1; iParNumber< fRecoUtils->GetNPars()+1;iParNumber++){
481  TH1C *hPar = (TH1C*)arrayBCpass->FindObject( Form("h%d_%llu",runBC,fRecoUtils->GetGlobalIDPar(iParNumber-1) ) );
482  if (!hPar) AliError( Form("Could not load h%d_%llu",runBC,fRecoUtils->GetGlobalIDPar(iParNumber-1) ) );
483  hPar->SetDirectory(0);
485  }//loop over PARs
486  }//end if tGID present
487 
488  return 1;
489 }
490 
496 {
498 
499  if (runChanged) {
500 
501  // define what recalib parameters are needed for various switches
502  // this is based on implementation in AliEMCALRecoUtils
503  Bool_t needTimecalib = fCalibrateTime;
504  if(fRun>209121) fCalibrateTimeL1Phase = kTRUE;
505 
506  if(fRun<225000 && fCalibrateTime && fDoMergedBCs){
507  AliWarning("The merged BC histograms don't exist for Run1, falling back to the 4 BC histograms. For question contact constantin.loizides@cern.ch");
508  fDoMergedBCs=kFALSE;
511  AliWarning("The merged BC LG histograms don't exist for Run1, using the all period merged LG histograms");
512  fDoCalibMergedLG=kTRUE;
513  }
514  }
515 
516  Bool_t needTimecalibL1Phase = fCalibrateTime & fCalibrateTimeL1Phase;
517 
518  // init time calibration
519  if (needTimecalib && fUseAutomaticTimeCalib) {
520  Int_t initTC = InitTimeCalibration();
521  if (!initTC) {
522  AliError("InitTimeCalibration returned false, returning");
523  }
524  if (initTC==1) {
525  AliWarning("InitTimeCalib OK");
526  }
527  if (initTC > 1) {
528  AliWarning(Form("No external time calibration available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
529  }
530  }
531 
532  // init time calibration with L1 phase
533  if (needTimecalibL1Phase && fUseAutomaticTimeCalib) {
534  Int_t initTCL1Phase = InitTimeCalibrationL1Phase();
535  if (!initTCL1Phase) {
536  AliError("InitTimeCalibrationL1Phase returned false, returning");
537  }
538  if (initTCL1Phase==1) {
539  AliWarning("InitTimeCalibL1Phase OK");
540  }
541  if (initTCL1Phase > 1) {
542  AliWarning(Form("No external time calibration L1 phase available: %d - %s", fEventManager.InputEvent()->GetRunNumber(), fFilepass.Data()));
543  }
544  }
545  }
546  return runChanged;
547 }
TH1F * fCellTimeDistAfter
! cell energy distribution, after time calibration
TH1F * fCellTimeDistBefore
! cell energy distribution, before time calibration
void InitEMCALL1PhaseInTimeRecalibration()
ULong64_t GetGlobalIDPar(Short_t par)
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
void SetUseOneHistForAllBCs(Bool_t useOneHist)
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
void SwitchOnL1PhaseInTimeRecalibration()
int Int_t
Definition: External.C:63
TH1 * GetEMCALChannelTimeRecalibrationFactors(Int_t bc) const
Bool_t fCalibrateTimeL1Phase
flag cell time calibration with L1phase shift
Bool_t fDoCalibrateLowGain
flag to calibrate the low gain cells
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
short Short_t
Definition: External.C:23
Bool_t fDoCalibMergedLG
flag to calibrate the low gain cells using a period merged histogram for LG calibration ...
Bool_t fCreateHisto
Flag to make some basic histograms.
void InitEMCALTimeRecalibrationFactors()
Time calibration correction component in the EMCal correction framework.
TH1C * GetEMCALL1PhaseInTimeRecalibrationForAllSM(Short_t par=0) const
Bool_t fDoMergedBCs
flag to use one histogram for all BCs
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
void SetNPars(Short_t npars)
void SetGlobalIDPar(ULong64_t glob, Short_t par)
TString fFilepass
Input data pass number.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.