AliPhysics  master (3d17d9d)
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  fLoad1DBadChMap(kFALSE),
35  fRun(-1),
36  fFilepass(""),
37  fGetPassFromFileName(kTRUE),
38  fEventManager(),
39  fEsdMode(0),
40  fMCEvent(0),
41  fCent(0),
42  fNcentBins(4),
43  fCentBin(0),
44  fNbins(250),
45  fMinBinPt(0),
46  fMaxBinPt(250),
47  fGeom(0),
48  fMinMCLabel(0),
49  fClusterCollArray(),
50  fParticleCollArray(),
51  fCaloCells(0),
52  fRecoUtils(0),
53  fOutput(0),
54  fBasePath(""),
55  fCustomBadChannelFilePath("")
56 
57 {
58  fVertex[0] = 0;
59  fVertex[1] = 0;
60  fVertex[2] = 0;
61 }
62 
67  TNamed(name, name),
68  fYAMLConfig(),
69  fCreateHisto(kTRUE),
70  fLoad1DBadChMap(kFALSE),
71  fRun(-1),
72  fFilepass(""),
73  fGetPassFromFileName(kTRUE),
74  fEventManager(),
75  fEsdMode(0),
76  fMCEvent(0),
77  fCent(0),
78  fNcentBins(4),
79  fCentBin(0),
80  fNbins(250),
81  fMinBinPt(0),
82  fMaxBinPt(250),
83  fGeom(0),
84  fMinMCLabel(0),
87  fCaloCells(0),
88  fRecoUtils(0),
89  fOutput(0),
90  fBasePath(""),
92 {
93  fVertex[0] = 0;
94  fVertex[1] = 0;
95  fVertex[2] = 0;
96 }
97 
102 {
103 }
104 
109 {
110  // Read in pass. If it is empty, set flag to automatically find the pass from the filename.
111  std::string tempString = "";
112  // Cannot use usual helper function because "pass" is not inside of a component, but rather at the top level.
113  fYAMLConfig.GetProperty("pass", tempString, true);
114  fFilepass = tempString.c_str();
115  if (fFilepass != "") {
116  fGetPassFromFileName = kFALSE;
117  // Handle the "default" value used in MC
118  if (fFilepass == "default" || fFilepass == "usedefault") {
119  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.");
120  fFilepass = "pass1";
121  }
122  }
123 
124  // Handle create histos, as this is universal for every component
125  GetProperty("createHistos", fCreateHisto);
126 
127  return kTRUE;
128 }
129 
135 {
136  // Setup Output
137  fOutput = new AliEmcalList();
138  fOutput->SetOwner();
139 }
140 
146 {
147 }
148 
154 {
155  AliDebugStream(3) << ": fEventManager.UseEmbeddingEvent(): " << fEventManager.UseEmbeddingEvent() << ", "
156  << "fEventManager.InputEvent(): " << fEventManager.InputEvent() << ", "
157  << "fEventManager address: " << &fEventManager << "\n";
159  GetPass();
160 
161  return kTRUE;
162 }
163 
169 {
170  return kTRUE;
171 }
172 
181 void AliEmcalCorrectionComponent::GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
182 {
183  phidiff = 999;
184  etadiff = 999;
185 
186  if (!t||!v) return;
187 
188  Double_t veta = t->GetTrackEtaOnEMCal();
189  Double_t vphi = t->GetTrackPhiOnEMCal();
190 
191  Float_t pos[3] = {0};
192  v->GetPosition(pos);
193  TVector3 cpos(pos);
194  Double_t ceta = cpos.Eta();
195  Double_t cphi = cpos.Phi();
196  etadiff=veta-ceta;
197  phidiff=TVector2::Phi_mpi_pi(vphi-cphi);
198 }
199 
205 {
206 
207  if (!fEventManager.InputEvent()) return ;
208 
209  Int_t bunchCrossNo = fEventManager.InputEvent()->GetBunchCrossNumber();
210 
211  if (fRecoUtils){
212  //In case of PAR run check global event ID
213  if(fRecoUtils->IsParRun()){
214  Short_t currentParIndex = 0;
215  ULong64_t globalEventID = (ULong64_t)bunchCrossNo + (ULong64_t)fEventManager.InputEvent()->GetOrbitNumber() * (ULong64_t)3564 + (ULong64_t)fEventManager.InputEvent()->GetPeriodNumber() * (ULong64_t)59793994260;
216  for(Short_t ipar=0;ipar<fRecoUtils->GetNPars();ipar++){
217  if(globalEventID >= fRecoUtils->GetGlobalIDPar(ipar)) {
218  currentParIndex++;
219  }
220  }
221  fRecoUtils->SetCurrentParNumber(currentParIndex);
222  }
223  //end of PAR run settings
224 
225  fRecoUtils->RecalibrateCells(fCaloCells, bunchCrossNo);
226  }
227  fCaloCells->Sort();
228 }
229 
234 {
235  // Get run number.
236  Bool_t runChanged = fRun != fEventManager.InputEvent()->GetRunNumber();
237 
238  if (runChanged) {
239  fRun = fEventManager.InputEvent()->GetRunNumber();
240  AliWarning(Form("Run changed, initializing parameters for %d", fRun));
241 
242  // init geometry if not already done
243  fGeom = AliEMCALGeometry::GetInstanceFromRunNumber(fRun);
244  if (!fGeom)
245  {
246  AliFatal("Can not create geometry");
247  return kFALSE;
248  }
249  }
250  return runChanged;
251 }
252 
257 {
258  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
259  TTree *inputTree = mgr->GetTree();
260 
261  if (!inputTree)
262  {
263  AliError("Pointer to tree = 0, returning");
264  return;
265  }
266 
267  TFile *inputFile = inputTree->GetCurrentFile();
268  if (!inputFile) {
269  AliError("Null pointer input file, returning");
270  return;
271  }
272 
273  TString fname(inputFile->GetName());
274  if (fname.Contains("pass1_pidfix")) fFilepass = TString("pass1_pidfix");
275  else if (fname.Contains("pass3_lowIR_pidfix")) fFilepass = TString("pass3_lowIR_pidfix");
276  else if (fname.Contains("pass4_lowIR_pidfix_cookdedx")) fFilepass = TString("pass4_lowIR_pidfix_cookdedx");
277  else if (fname.Contains("pass1")) fFilepass = TString("pass1");
278  else if (fname.Contains("pass2")) fFilepass = TString("pass2");
279  else if (fname.Contains("pass3")) fFilepass = TString("pass3");
280  else if (fname.Contains("pass4")) fFilepass = TString("pass4");
281  else if (fname.Contains("pass5")) fFilepass = TString("pass5");
282  else if (fname.Contains("LHC11c") && fname.Contains("spc_calo")) fFilepass = TString("spc_calo");
283  else if (fname.Contains("calo") || fname.Contains("high_lumi"))
284  {
285  Printf("%s: Path contains <calo> or <high-lumi>, set as <pass1>", GetName());
286  fFilepass = TString("pass1");
287  }
288  else if (fname.Contains("LHC14a1a"))
289  {
290  AliInfo("Energy calibration activated for this MC production!");
291  fFilepass = TString("LHC14a1a");
292  }
293  else
294  {
295  AliFatal(Form("Pass number string not found: %s. Please set the pass number in the configuration!", fname.Data()));
296  return;
297  }
298 }
299 
304  TString name = h->GetName();
305 
306  Short_t absId =-1;
307  Double_t ecell = 0;
308  Double_t tcell = 0;
309  Double_t efrac = 0;
310  Int_t mclabel = -1;
311 
312  for (Int_t iCell = 0; iCell < fCaloCells->GetNumberOfCells(); iCell++){
313 
314  fCaloCells->GetCell(iCell, absId, ecell, tcell, mclabel, efrac);
315  if(name.Contains("Energy")){
316  h->Fill(ecell);
317  }
318  else if(name.Contains("Time")){
319  h->Fill(tcell);
320  }
321 
322  }
323 
324 }
325 
330 {
331  if (!fEventManager.InputEvent())
332  return 0;
333 
334  AliInfo("Initialising Bad channel map");
335 
336  // init default maps first
339 
340  Int_t runBC = fEventManager.InputEvent()->GetRunNumber();
341 
342  std::unique_ptr<AliOADBContainer> contBC(nullptr);
343  std::unique_ptr<TFile> fbad;
344  if (fBasePath!="")
345  { //if fBasePath specified in the ->SetBasePath()
346  AliInfo(Form("Loading Bad Channels OADB from given path %s",fBasePath.Data()));
347 
348  fbad = std::unique_ptr<TFile>(TFile::Open(Form("%s/EMCALBadChannels%s.root",fBasePath.Data(), fLoad1DBadChMap ? "_1D" : ""),"read"));
349  if (!fbad || fbad->IsZombie())
350  {
351  AliFatal(Form("EMCALBadChannels%s.root was not found in the path provided: %s", fLoad1DBadChMap ? "_1D" : "", fBasePath.Data()));
352  return 0;
353  }
354 
355  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
356  }
357  else if (fCustomBadChannelFilePath!="")
358  { //if fCustomBadChannelFilePath specified in the configuration for custom bad channel maps
359  AliInfo(Form("Loading custom Bad Channels OADB from given path %s",fCustomBadChannelFilePath.Data()));
360 
361  fbad = std::unique_ptr<TFile>(TFile::Open(Form("%s",fCustomBadChannelFilePath.Data()),"read"));
362  if (!fbad || fbad->IsZombie())
363  {
364  AliFatal(Form("No valid Bad channel OADB object was not found in the path provided: %s",fCustomBadChannelFilePath.Data()));
365  return 0;
366  }
367 
368  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
369  }
370  else
371  { // Else choose the one in the $ALICE_PHYSICS directory
372  AliInfo("Loading Bad Channels OADB from $ALICE_PHYSICS/OADB/EMCAL");
373 
374  fbad = std::unique_ptr<TFile>(TFile::Open(AliDataFile::GetFileNameOADB(Form("EMCAL/EMCALBadChannels%s.root", fLoad1DBadChMap ? "_1D" : "")).data(),"read"));
375  if (!fbad || fbad->IsZombie())
376  {
377  AliFatal(Form("OADB/EMCAL/EMCALBadChannels%s.root was not found", fLoad1DBadChMap ? "_1D" : ""));
378  return 0;
379  }
380 
381  contBC = std::unique_ptr<AliOADBContainer>(static_cast<AliOADBContainer *>(fbad->Get("AliEMCALBadChannels")));
382  }
383  if(!contBC){
384  AliError("No OADB container found");
385  return 0;
386  }
387  contBC->SetOwner(true);
388 
389  TObjArray *arrayBC=(TObjArray*)contBC->GetObject(runBC);
390  if (!arrayBC)
391  {
392  AliError(Form("No external hot channel set for run number: %d", runBC));
393  return 2;
394  }
395 
396  if(fLoad1DBadChMap){
398  if (h)
399  delete h;
400  h=(TH1C*)arrayBC->FindObject("EMCALBadChannelMap");
401 
402  if (!h)
403  {
404  AliError("Can not get EMCALBadChannelMap");
405  }
406  h->SetDirectory(0);
408  }else{
409  Int_t sms = fGeom->GetEMCGeometry()->GetNumberOfSuperModules();
410  for (Int_t i=0; i<sms; ++i)
411  {
412  TH2I *h = fRecoUtils->GetEMCALChannelStatusMap(i);
413  if (h)
414  delete h;
415  h=(TH2I*)arrayBC->FindObject(Form("EMCALBadChannelMap_Mod%d",i));
416 
417  if (!h)
418  {
419  AliError(Form("Can not get EMCALBadChannelMap_Mod%d",i));
420  continue;
421  }
422  h->SetDirectory(0);
424  }
425  }
426 
427  return 1;
428 }
429 
Int_t fNcentBins
How many centrality bins (this member copied from AliAnalysisTaskEmcal)
void SetEMCALChannelStatusMap1D(const TH1C *h)
AliEMCALGeometry * fGeom
! Geometry object
double Double_t
Definition: External.C:58
TH2I * GetEMCALChannelStatusMap(Int_t iSM) const
TH1C * GetEMCALChannelStatusMap1D() const
ULong64_t GetGlobalIDPar(Short_t par)
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.
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 SetCurrentParNumber(Short_t par)
void GetEtaPhiDiff(const AliVTrack *t, const AliVCluster *v, Double_t &phidiff, Double_t &etadiff)
bool Bool_t
Definition: External.C:53
Bool_t fLoad1DBadChMap
Flag to load 1D bad channel map.
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.