AliPhysics  7f1bdba (7f1bdba)
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 <AliAnalysisManager.h>
10 #include <AliVEvent.h>
11 #include <AliEMCALRecoUtils.h>
12 #include <AliOADBContainer.h>
13 #include "AliEmcalList.h"
14 #include "AliClusterContainer.h"
15 #include "AliTrackContainer.h"
16 #include "AliParticleContainer.h"
17 #include "AliMCParticleContainer.h"
18 #include "AliDataFile.h"
19 
23 
24 // Must create an instance of the map, since it is static
26 
31  TNamed("AliEmcalCorrectionComponent", "AliEmcalCorrectionComponent"),
32  fYAMLConfig(),
33  fCreateHisto(kTRUE),
34  fRun(-1),
35  fFilepass(""),
36  fGetPassFromFileName(kTRUE),
37  fEventManager(),
38  fEsdMode(0),
39  fMCEvent(0),
40  fCent(0),
41  fNcentBins(4),
42  fCentBin(0),
43  fNbins(250),
44  fMinBinPt(0),
45  fMaxBinPt(250),
46  fGeom(0),
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  fMinMCLabel(0),
84  fCaloCells(0),
85  fRecoUtils(0),
86  fOutput(0),
87  fBasePath("")
88 {
89  fVertex[0] = 0;
90  fVertex[1] = 0;
91  fVertex[2] = 0;
92 }
93 
98 {
99 }
100 
105 {
106  // Read in pass. If it is empty, set flag to automatically find the pass from the filename.
107  std::string tempString = "";
108  // Cannot use usual helper function because "pass" is not inside of a component, but rather at the top level.
109  fYAMLConfig.GetProperty("pass", tempString, true);
110  fFilepass = tempString.c_str();
111  if (fFilepass != "") {
112  fGetPassFromFileName = kFALSE;
113  // Handle the "default" value used in MC
114  if (fFilepass == "default" || fFilepass == "usedefault") {
115  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.");
116  fFilepass = "pass1";
117  }
118  }
119 
120  // Handle create histos, as this is universal for every component
121  GetProperty("createHistos", fCreateHisto);
122 
123  return kTRUE;
124 }
125 
131 {
132  // Setup Output
133  fOutput = new AliEmcalList();
134  fOutput->SetOwner();
135 }
136 
142 {
143 }
144 
150 {
151  AliDebugStream(3) << ": fEventManager.UseEmbeddingEvent(): " << fEventManager.UseEmbeddingEvent() << ", "
152  << "fEventManager.InputEvent(): " << fEventManager.InputEvent() << ", "
153  << "fEventManager address: " << &fEventManager << "\n";
155  GetPass();
156 
157  return kTRUE;
158 }
159 
165 {
166  return kTRUE;
167 }
168 
177 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
178 {
179  phidiff = 999;
180  etadiff = 999;
181 
182  if (!t||!v) return;
183 
184  Double_t veta = t->GetTrackEtaOnEMCal();
185  Double_t vphi = t->GetTrackPhiOnEMCal();
186 
187  Float_t pos[3] = {0};
188  v->GetPosition(pos);
189  TVector3 cpos(pos);
190  Double_t ceta = cpos.Eta();
191  Double_t cphi = cpos.Phi();
192  etadiff=veta-ceta;
193  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
194 }
195 
201 {
202 
203  if (!fEventManager.InputEvent()) return ;
204 
205  Int_t bunchCrossNo = fEventManager.InputEvent()->GetBunchCrossNumber();
206 
207  if (fRecoUtils)
208  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
209 
210  fCaloCells->Sort();
211 }
212 
217 {
218  // Get run number.
219  Bool_t runChanged = fRun != fEventManager.InputEvent()->GetRunNumber();
220 
221  if (runChanged) {
222  fRun = fEventManager.InputEvent()->GetRunNumber();
223  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
224 
225  // init geometry if not already done
226  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
227  if (!fGeom)
228  {
229  AliFatal("Can not create geometry");
230  return kFALSE;
231  }
232  }
233  return runChanged;
234 }
235 
240 {
241  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
242  TTree *inputTree = mgr->GetTree();
243 
244  if (!inputTree)
245  {
246  AliError("Pointer to tree = 0, returning");
247  return;
248  }
249 
250  TFile *inputFile = inputTree->GetCurrentFile();
251  if (!inputFile) {
252  AliError("Null pointer input file, returning");
253  return;
254  }
255 
256  TString fname(inputFile->GetName());
257  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
258  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
259  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
260  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
261  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
262  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
263  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
264  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
265  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
266  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
267  {
268  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
269  fFilepass = TString("pass1");
270  }
271  else if (fname.Contains("LHC14a1a"))
272  {
273  AliInfo("Energy calibration activated for this MC production!");
274  fFilepass = TString("LHC14a1a");
275  }
276  else
277  {
278  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
279  return;
280  }
281 }
282 
287  TString name = h->GetName();
288 
289  Short_t absId =-1;
290  Double_t ecell = 0;
291  Double_t tcell = 0;
292  Double_t efrac = 0;
293  Int_t mclabel = -1;
294 
295  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
296 
297  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
298  if(name.Contains("Energy")){
299  h->Fill(ecell);
300  }
301  else if(name.Contains("Time")){
302  h->Fill(tcell);
303  }
304 
305  }
306 
307 }
308 
313 {
314  if (!fEventManager.InputEvent())
315  return 0;
316 
317  AliInfo("Initialising Bad channel map");
318 
319  // init default maps first
322 
323  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
324 
325  std::unique_ptr<AliOADBContainer> contBC(nullptr);
326  std::unique_ptr<TFile> fbad;
327  if (fBasePath!="")
328  { //if fBasePath specified in the ->SetBasePath()
329  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
330 
331  fbad = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read"));
332  if (!fbad || fbad->IsZombie())
333  {
334  AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
335  return 0;
336  }
337 
338  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
339  }
340  else
341  { // Else choose the one in the $ALICE_PHYSICS directory
342  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
343 
344  fbad = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALBadChannels.root").data(),"read"));
345  if (!fbad || fbad->IsZombie())
346  {
347  AliFatal("OADB/EMCAL/EMCALBadChannels.root was not found");
348  return 0;
349  }
350 
351  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
352  }
353  if(!contBC){
354  AliError("No OADB container found");
355  return 0;
356  }
357  contBC->SetOwner(true);
358 
359  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
360  if (!arrayBC)
361  {
362  AliError(Form("No external hot channel set for run number: %d", runBC));
363  return 2;
364  }
365 
366  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
367  for (Int_t i=0; i<sms; ++i)
368  {
369  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
370  if (h)
371  delete h;
372  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
373 
374  if (!h)
375  {
376  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
377  continue;
378  }
379  h->SetDirectory(0);
381  }
382 
383  return 1;
384 }
385 
Int_t fNcentBins
How many centrality bins (this member copied from AliAnalysisTaskEmcal)
AliEMCALGeometry * fGeom
! Geometry object
double Double_t
Definition: External.C:58
TObjArray * GetEMCALBadChannelStatusMapArray() const
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
void RecalibrateCells(AliVCaloCells *cells, Int_t bc)
AliVCaloCells * fCaloCells
! Pointer to CaloCells
TObjArray fParticleCollArray
Particle/track collection array.
AliEMCALRecoUtils * fRecoUtils
Pointer to RecoUtils.
TH2I * GetEMCALChannelStatusMap(Int_t iSM) const
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
void SetEMCALChannelStatusMap(const TObjArray *map)
TString fFilepass
Input data pass number.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.