AliPhysics  cd965e1 (cd965e1)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalCorrectionComponent.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionComponent
2 //
3 
5 
6 #include <TFile.h>
7 #include <TH1.h>
8 
9 #include "AliEmcalList.h"
10 #include "AliEMCALRecoUtils.h"
11 #include "AliAnalysisManager.h"
12 #include "AliVEvent.h"
13 #include "AliClusterContainer.h"
14 #include "AliTrackContainer.h"
15 #include "AliParticleContainer.h"
16 #include "AliMCParticleContainer.h"
17 #include "AliOADBContainer.h"
18 
22 
23 // Must create an instance of the map, since it is static
25 
30  TNamed("AliEmcalCorrectionComponent", "AliEmcalCorrectionComponent"),
31  fYAMLConfig(),
32  fCreateHisto(kTRUE),
33  fRun(-1),
34  fFilepass(""),
35  fGetPassFromFileName(kTRUE),
36  fEventManager(),
37  fEsdMode(0),
38  fMCEvent(0),
39  fCent(0),
40  fNcentBins(4),
41  fCentBin(0),
42  fNbins(250),
43  fMinBinPt(0),
44  fMaxBinPt(250),
45  fGeom(0),
46  fIsEmbedded(kFALSE),
47  fMinMCLabel(0),
48  fClusterCollArray(),
49  fParticleCollArray(),
50  fCaloCells(0),
51  fRecoUtils(0),
52  fOutput(0),
53  fBasePath("")
54 
55 {
56  fVertex[0] = 0;
57  fVertex[1] = 0;
58  fVertex[2] = 0;
59 }
60 
65  TNamed(name, name),
66  fYAMLConfig(),
67  fCreateHisto(kTRUE),
68  fRun(-1),
69  fFilepass(""),
70  fGetPassFromFileName(kTRUE),
71  fEventManager(),
72  fEsdMode(0),
73  fMCEvent(0),
74  fCent(0),
75  fNcentBins(4),
76  fCentBin(0),
77  fNbins(250),
78  fMinBinPt(0),
79  fMaxBinPt(250),
80  fGeom(0),
81  fIsEmbedded(kFALSE),
82  fMinMCLabel(0),
83  fClusterCollArray(),
84  fParticleCollArray(),
85  fCaloCells(0),
86  fRecoUtils(0),
87  fOutput(0),
88  fBasePath("")
89 {
90  fVertex[0] = 0;
91  fVertex[1] = 0;
92  fVertex[2] = 0;
93 }
94 
99 {
100 }
101 
106 {
107  // Read in pass. If it is empty, set flag to automatically find the pass from the filename.
108  std::string tempString = "";
109  // Cannot use usual helper function because "pass" is not inside of a component, but rather at the top level.
110  fYAMLConfig.GetProperty("pass", tempString, true);
111  fFilepass = tempString.c_str();
112  if (fFilepass != "") {
113  fGetPassFromFileName = kFALSE;
114  // Handle the "default" value used in MC
115  if (fFilepass == "default") {
116  AliError("Received \"default\" as pass value. Defaulting to \"pass1\"! In the case of MC, the user should set the proper pass value in their configuration file! For data, empty quotes should be set so that the pass is automatically set.");
117  fFilepass = "pass1";
118  }
119  }
120 
121  return kTRUE;
122 }
123 
129 {
130  // Setup Output
131  fOutput = new AliEmcalList();
132  fOutput->SetOwner();
133 }
134 
140 {
141 }
142 
148 {
149  AliDebugStream(3) << ": fEventManager.UseEmbeddingEvent(): " << fEventManager.UseEmbeddingEvent() << ", "
150  << "fEventManager.InputEvent(): " << fEventManager.InputEvent() << ", "
151  << "fEventManager address: " << &fEventManager << "\n";
153  GetPass();
154 
155  return kTRUE;
156 }
157 
163 {
164  return kTRUE;
165 }
166 
175 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
176 {
177  phidiff = 999;
178  etadiff = 999;
179 
180  if (!t||!v) return;
181 
182  Double_t veta = t->GetTrackEtaOnEMCal();
183  Double_t vphi = t->GetTrackPhiOnEMCal();
184 
185  Float_t pos[3] = {0};
186  v->GetPosition(pos);
187  TVector3 cpos(pos);
188  Double_t ceta = cpos.Eta();
189  Double_t cphi = cpos.Phi();
190  etadiff=veta-ceta;
191  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
192 }
193 
199 {
200 
201  if (!fEventManager.InputEvent()) return ;
202 
203  Int_t bunchCrossNo = fEventManager.InputEvent()->GetBunchCrossNumber();
204 
205  if (fRecoUtils)
206  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
207 
208  fCaloCells->Sort();
209 }
210 
215 {
216  // Get run number.
217  Bool_t runChanged = fRun != fEventManager.InputEvent()->GetRunNumber();
218 
219  if (runChanged) {
220  fRun = fEventManager.InputEvent()->GetRunNumber();
221  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
222 
223  // init geometry if not already done
224  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
225  if (!fGeom)
226  {
227  AliFatal("Can not create geometry");
228  return kFALSE;
229  }
230  }
231  return runChanged;
232 }
233 
238 {
239  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
240  TTree *inputTree = mgr->GetTree();
241 
242  if (!inputTree)
243  {
244  AliError("Pointer to tree = 0, returning");
245  return;
246  }
247 
248  TFile *inputFile = inputTree->GetCurrentFile();
249  if (!inputFile) {
250  AliError("Null pointer input file, returning");
251  return;
252  }
253 
254  TString fname(inputFile->GetName());
255  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
256  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
257  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
258  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
259  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
260  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
261  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
262  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
263  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
264  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
265  {
266  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
267  fFilepass = TString("pass1");
268  }
269  else if (fname.Contains("LHC14a1a"))
270  {
271  AliInfo("Energy calibration activated for this MC production!");
272  fFilepass = TString("LHC14a1a");
273  }
274  else
275  {
276  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
277  return;
278  }
279 }
280 
285  TString name = h->GetName();
286 
287  Short_t absId =-1;
288  Double_t ecell = 0;
289  Double_t tcell = 0;
290  Double_t efrac = 0;
291  Int_t mclabel = -1;
292 
293  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
294 
295  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
296  if(name.Contains("Energy")){
297  h->Fill(ecell);
298  }
299  else if(name.Contains("Time")){
300  h->Fill(tcell);
301  }
302 
303  }
304 
305 }
306 
311 {
312  if (!fEventManager.InputEvent())
313  return 0;
314 
315  AliInfo("Initialising Bad channel map");
316 
317  // init default maps first
318  if (!fRecoUtils->GetEMCALBadChannelStatusMapArray())
319  fRecoUtils->InitEMCALBadChannelStatusMap() ;
320 
321  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
322 
323  AliOADBContainer *contBC = new AliOADBContainer("");
324  if (fBasePath!="")
325  { //if fBasePath specified in the ->SetBasePath()
326  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
327 
328  TFile *fbad=new TFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read");
329  if (!fbad || fbad->IsZombie())
330  {
331  AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
332  return 0;
333  }
334 
335  if (fbad) delete fbad;
336 
337  contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
338  }
339  else
340  { // Else choose the one in the $ALICE_PHYSICS directory
341  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
342 
343  TFile *fbad=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","read");
344  if (!fbad || fbad->IsZombie())
345  {
346  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root was not found");
347  return 0;
348  }
349 
350  if (fbad) delete fbad;
351 
352  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","AliEMCALBadChannels");
353  }
354 
355  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
356  if (!arrayBC)
357  {
358  AliError(Form("No external hot channel set for run number: %d", runBC));
359  delete contBC;
360  return 2;
361  }
362 
363  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
364  for (Int_t i=0; i<sms; ++i)
365  {
366  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
367  if (h)
368  delete h;
369  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
370 
371  if (!h)
372  {
373  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
374  continue;
375  }
376  h->SetDirectory(0);
377  fRecoUtils->SetEMCALChannelStatusMap(i,h);
378  }
379 
380  delete contBC;
381 
382  return 1;
383 }
384 
AliEMCALGeometry * fGeom
! Geometry object
double Double_t
Definition: External.C:58
bool GetProperty(std::vector< std::string > propertyPath, const std::string &propertyName, T &property, const bool requiredProperty) const
bool UseEmbeddingEvent() const
True if the embedding event should be used.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Base class for correction components in the EMCal correction framework.
static map_type * componentMap
Contains the map to all of the components.
std::map< std::string, AliEmcalCorrectionComponent *(*)()> map_type
Double_t fVertex[3]
! Event vertex
TString fBasePath
Base folder path to get root files.
TList * fOutput
! List of output histograms
short Short_t
Definition: External.C:23
Enhanced TList-derived class that implements correct merging for pt_hard binned production.
Definition: AliEmcalList.h:25
Bool_t fGetPassFromFileName
Get fFilepass from file name.
AliEmcalCorrectionEventManager fEventManager
Minimal task which inherits from AliAnalysisTaskSE and manages access to the event.
PWG::Tools::AliYAMLConfiguration fYAMLConfig
Contains the YAML configuration used to configure the component.
void GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
bool Bool_t
Definition: External.C:53
TString fFilepass
Input data pass number.