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