AliPhysics  4a7363b (4a7363b)
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  fCustomBadChannelFilePath("")
55 
56 {
57  fVertex[0] = 0;
58  fVertex[1] = 0;
59  fVertex[2] = 0;
60 }
61 
66  TNamed(name, name),
67  fYAMLConfig(),
68  fCreateHisto(kTRUE),
69  fRun(-1),
70  fFilepass(""),
71  fGetPassFromFileName(kTRUE),
72  fEventManager(),
73  fEsdMode(0),
74  fMCEvent(0),
75  fCent(0),
76  fNcentBins(4),
77  fCentBin(0),
78  fNbins(250),
79  fMinBinPt(0),
80  fMaxBinPt(250),
81  fGeom(0),
82  fMinMCLabel(0),
85  fCaloCells(0),
86  fRecoUtils(0),
87  fOutput(0),
88  fBasePath(""),
90 {
91  fVertex[0] = 0;
92  fVertex[1] = 0;
93  fVertex[2] = 0;
94 }
95 
100 {
101 }
102 
107 {
108  // Read in pass. If it is empty, set flag to automatically find the pass from the filename.
109  std::string tempString = "";
110  // Cannot use usual helper function because "pass" is not inside of a component, but rather at the top level.
111  fYAMLConfig.GetProperty("pass", tempString, true);
112  fFilepass = tempString.c_str();
113  if (fFilepass != "") {
114  fGetPassFromFileName = kFALSE;
115  // Handle the "default" value used in MC
116  if (fFilepass == "default" || fFilepass == "usedefault") {
117  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.");
118  fFilepass = "pass1";
119  }
120  }
121 
122  // Handle create histos, as this is universal for every component
123  GetProperty("createHistos", fCreateHisto);
124 
125  return kTRUE;
126 }
127 
133 {
134  // Setup Output
135  fOutput = new AliEmcalList();
136  fOutput->SetOwner();
137 }
138 
144 {
145 }
146 
152 {
153  AliDebugStream(3) << ": fEventManager.UseEmbeddingEvent(): " << fEventManager.UseEmbeddingEvent() << ", "
154  << "fEventManager.InputEvent(): " << fEventManager.InputEvent() << ", "
155  << "fEventManager address: " << &fEventManager << "\n";
157  GetPass();
158 
159  return kTRUE;
160 }
161 
167 {
168  return kTRUE;
169 }
170 
179 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
180 {
181  phidiff = 999;
182  etadiff = 999;
183 
184  if (!t||!v) return;
185 
186  Double_t veta = t->GetTrackEtaOnEMCal();
187  Double_t vphi = t->GetTrackPhiOnEMCal();
188 
189  Float_t pos[3] = {0};
190  v->GetPosition(pos);
191  TVector3 cpos(pos);
192  Double_t ceta = cpos.Eta();
193  Double_t cphi = cpos.Phi();
194  etadiff=veta-ceta;
195  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
196 }
197 
203 {
204 
205  if (!fEventManager.InputEvent()) return ;
206 
207  Int_t bunchCrossNo = fEventManager.InputEvent()->GetBunchCrossNumber();
208 
209  if (fRecoUtils)
210  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
211 
212  fCaloCells->Sort();
213 }
214 
219 {
220  // Get run number.
221  Bool_t runChanged = fRun != fEventManager.InputEvent()->GetRunNumber();
222 
223  if (runChanged) {
224  fRun = fEventManager.InputEvent()->GetRunNumber();
225  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
226 
227  // init geometry if not already done
228  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
229  if (!fGeom)
230  {
231  AliFatal("Can not create geometry");
232  return kFALSE;
233  }
234  }
235  return runChanged;
236 }
237 
242 {
243  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
244  TTree *inputTree = mgr->GetTree();
245 
246  if (!inputTree)
247  {
248  AliError("Pointer to tree = 0, returning");
249  return;
250  }
251 
252  TFile *inputFile = inputTree->GetCurrentFile();
253  if (!inputFile) {
254  AliError("Null pointer input file, returning");
255  return;
256  }
257 
258  TString fname(inputFile->GetName());
259  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
260  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
261  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
262  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
263  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
264  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
265  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
266  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
267  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
268  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
269  {
270  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
271  fFilepass = TString("pass1");
272  }
273  else if (fname.Contains("LHC14a1a"))
274  {
275  AliInfo("Energy calibration activated for this MC production!");
276  fFilepass = TString("LHC14a1a");
277  }
278  else
279  {
280  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
281  return;
282  }
283 }
284 
289  TString name = h->GetName();
290 
291  Short_t absId =-1;
292  Double_t ecell = 0;
293  Double_t tcell = 0;
294  Double_t efrac = 0;
295  Int_t mclabel = -1;
296 
297  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
298 
299  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
300  if(name.Contains("Energy")){
301  h->Fill(ecell);
302  }
303  else if(name.Contains("Time")){
304  h->Fill(tcell);
305  }
306 
307  }
308 
309 }
310 
315 {
316  if (!fEventManager.InputEvent())
317  return 0;
318 
319  AliInfo("Initialising Bad channel map");
320 
321  // init default maps first
324 
325  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
326 
327  std::unique_ptr<AliOADBContainer> contBC(nullptr);
328  std::unique_ptr<TFile> fbad;
329  if (fBasePath!="")
330  { //if fBasePath specified in the ->SetBasePath()
331  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
332 
333  fbad = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"read"));
334  if (!fbad || fbad->IsZombie())
335  {
336  AliFatal(Form("EMCALBadChannels.root was not found in the path provided: %s",fBasePath.Data()));
337  return 0;
338  }
339 
340  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
341  }
342  else if (fCustomBadChannelFilePath!="")
343  { //if fCustomBadChannelFilePath specified in the configuration for custom bad channel maps
344  AliInfo(Form("Loading custom Bad Channels OADB from given path %s",fCustomBadChannelFilePath.Data()));
345 
346  fbad = std::unique_ptr<TFile>(TFile::Open(Form("%s",fCustomBadChannelFilePath.Data()),"read"));
347  if (!fbad || fbad->IsZombie())
348  {
349  AliFatal(Form("No valid Bad channel OADB object was not found in the path provided: %s",fCustomBadChannelFilePath.Data()));
350  return 0;
351  }
352 
353  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
354  }
355  else
356  { // Else choose the one in the $ALICE_PHYSICS directory
357  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
358 
359  fbad = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB("EMCAL/EMCALBadChannels.root").data(),"read"));
360  if (!fbad || fbad->IsZombie())
361  {
362  AliFatal("OADB/EMCAL/EMCALBadChannels.root was not found");
363  return 0;
364  }
365 
366  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
367  }
368  if(!contBC){
369  AliError("No OADB container found");
370  return 0;
371  }
372  contBC->SetOwner(true);
373 
374  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
375  if (!arrayBC)
376  {
377  AliError(Form("No external hot channel set for run number: %d", runBC));
378  return 2;
379  }
380 
381  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
382  for (Int_t i=0; i<sms; ++i)
383  {
384  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
385  if (h)
386  delete h;
387  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
388 
389  if (!h)
390  {
391  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
392  continue;
393  }
394  h->SetDirectory(0);
396  }
397 
398  return 1;
399 }
400 
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
TString fCustomBadChannelFilePath
Custom path to bad channel map OADB file.
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.