AliPhysics  b555aef (b555aef)
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  fMinMCLabel(0),
47  fClusterCollArray(),
48  fParticleCollArray(),
49  fCaloCells(0),
50  fRecoUtils(0),
51  fOutput(0),
52  fBasePath("")
53 
54 {
55  fVertex[0] = 0;
56  fVertex[1] = 0;
57  fVertex[2] = 0;
58 }
59 
64  TNamed(name, name),
65  fYAMLConfig(),
66  fCreateHisto(kTRUE),
67  fRun(-1),
68  fFilepass(""),
69  fGetPassFromFileName(kTRUE),
70  fEventManager(),
71  fEsdMode(0),
72  fMCEvent(0),
73  fCent(0),
74  fNcentBins(4),
75  fCentBin(0),
76  fNbins(250),
77  fMinBinPt(0),
78  fMaxBinPt(250),
79  fGeom(0),
80  fMinMCLabel(0),
83  fCaloCells(0),
84  fRecoUtils(0),
85  fOutput(0),
86  fBasePath("")
87 {
88  fVertex[0] = 0;
89  fVertex[1] = 0;
90  fVertex[2] = 0;
91 }
92 
97 {
98 }
99 
104 {
105  // Read in pass. If it is empty, set flag to automatically find the pass from the filename.
106  std::string tempString = "";
107  // Cannot use usual helper function because "pass" is not inside of a component, but rather at the top level.
108  fYAMLConfig.GetProperty("pass", tempString, true);
109  fFilepass = tempString.c_str();
110  if (fFilepass != "") {
111  fGetPassFromFileName = kFALSE;
112  // Handle the "default" value used in MC
113  if (fFilepass == "default" || fFilepass == "usedefault") {
114  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.");
115  fFilepass = "pass1";
116  }
117  }
118 
119  return kTRUE;
120 }
121 
127 {
128  // Setup Output
129  fOutput = new AliEmcalList();
130  fOutput->SetOwner();
131 }
132 
138 {
139 }
140 
146 {
147  AliDebugStream(3) << ": fEventManager.UseEmbeddingEvent(): " << fEventManager.UseEmbeddingEvent() << ", "
148  << "fEventManager.InputEvent(): " << fEventManager.InputEvent() << ", "
149  << "fEventManager address: " << &fEventManager << "\n";
151  GetPass();
152 
153  return kTRUE;
154 }
155 
161 {
162  return kTRUE;
163 }
164 
173 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
174 {
175  phidiff = 999;
176  etadiff = 999;
177 
178  if (!t||!v) return;
179 
180  Double_t veta = t->GetTrackEtaOnEMCal();
181  Double_t vphi = t->GetTrackPhiOnEMCal();
182 
183  Float_t pos[3] = {0};
184  v->GetPosition(pos);
185  TVector3 cpos(pos);
186  Double_t ceta = cpos.Eta();
187  Double_t cphi = cpos.Phi();
188  etadiff=veta-ceta;
189  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
190 }
191 
197 {
198 
199  if (!fEventManager.InputEvent()) return ;
200 
201  Int_t bunchCrossNo = fEventManager.InputEvent()->GetBunchCrossNumber();
202 
203  if (fRecoUtils)
204  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
205 
206  fCaloCells->Sort();
207 }
208 
213 {
214  // Get run number.
215  Bool_t runChanged = fRun != fEventManager.InputEvent()->GetRunNumber();
216 
217  if (runChanged) {
218  fRun = fEventManager.InputEvent()->GetRunNumber();
219  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
220 
221  // init geometry if not already done
222  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
223  if (!fGeom)
224  {
225  AliFatal("Can not create geometry");
226  return kFALSE;
227  }
228  }
229  return runChanged;
230 }
231 
236 {
237  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
238  TTree *inputTree = mgr->GetTree();
239 
240  if (!inputTree)
241  {
242  AliError("Pointer to tree = 0, returning");
243  return;
244  }
245 
246  TFile *inputFile = inputTree->GetCurrentFile();
247  if (!inputFile) {
248  AliError("Null pointer input file, returning");
249  return;
250  }
251 
252  TString fname(inputFile->GetName());
253  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
254  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
255  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
256  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
257  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
258  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
259  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
260  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
261  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
262  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
263  {
264  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
265  fFilepass = TString("pass1");
266  }
267  else if (fname.Contains("LHC14a1a"))
268  {
269  AliInfo("Energy calibration activated for this MC production!");
270  fFilepass = TString("LHC14a1a");
271  }
272  else
273  {
274  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
275  return;
276  }
277 }
278 
283  TString name = h->GetName();
284 
285  Short_t absId =-1;
286  Double_t ecell = 0;
287  Double_t tcell = 0;
288  Double_t efrac = 0;
289  Int_t mclabel = -1;
290 
291  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
292 
293  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
294  if(name.Contains("Energy")){
295  h->Fill(ecell);
296  }
297  else if(name.Contains("Time")){
298  h->Fill(tcell);
299  }
300 
301  }
302 
303 }
304 
309 {
310  if (!fEventManager.InputEvent())
311  return 0;
312 
313  AliInfo("Initialising Bad channel map");
314 
315  // init default maps first
316  if (!fRecoUtils->GetEMCALBadChannelStatusMapArray())
317  fRecoUtils->InitEMCALBadChannelStatusMap() ;
318 
319  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
320 
321  AliOADBContainer *contBC = new AliOADBContainer("");
322  if (fBasePath!="")
323  { //if fBasePath specified in the ->SetBasePath()
324  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
325 
326  TFile *fbad=new TFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read");
327  if (!fbad || fbad->IsZombie())
328  {
329  AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
330  return 0;
331  }
332 
333  if (fbad) delete fbad;
334 
335  contBC->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
336  }
337  else
338  { // Else choose the one in the $ALICE_PHYSICS directory
339  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
340 
341  TFile *fbad=new TFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","read");
342  if (!fbad || fbad->IsZombie())
343  {
344  AliFatal("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root was not found");
345  return 0;
346  }
347 
348  if (fbad) delete fbad;
349 
350  contBC->InitFromFile("$ALICE_PHYSICS/OADB/EMCAL/EMCALBadChannels.root","AliEMCALBadChannels");
351  }
352 
353  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
354  if (!arrayBC)
355  {
356  AliError(Form("No external hot channel set for run number: %d", runBC));
357  delete contBC;
358  return 2;
359  }
360 
361  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
362  for (Int_t i=0; i<sms; ++i)
363  {
364  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
365  if (h)
366  delete h;
367  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
368 
369  if (!h)
370  {
371  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
372  continue;
373  }
374  h->SetDirectory(0);
375  fRecoUtils->SetEMCALChannelStatusMap(i,h);
376  }
377 
378  delete contBC;
379 
380  return 1;
381 }
382 
Int_t fNcentBins
How many centrality bins (this member copied from AliAnalysisTaskEmcal)
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.
Int_t fCentBin
! Event centrality bin
AliVCaloCells * fCaloCells
! Pointer to CaloCells
TObjArray fParticleCollArray
Particle/track collection array.
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
TObjArray fClusterCollArray
Cluster collection array.
int Int_t
Definition: External.C:63
float Float_t
Definition: External.C:68
Base class for correction components in the EMCal correction framework.
Int_t fMinMCLabel
Minimum MC label value for the tracks/clusters being considered MC particles.
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.
Double_t fMaxBinPt
Max pt in histograms.
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 fCreateHisto
Flag to make some basic histograms.
Bool_t fGetPassFromFileName
Get fFilepass from file name.
Double_t fCent
! Event centrality
Double_t fMinBinPt
Min pt in histograms.
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.