ATLAS Offline Software
CommonEfficiencyTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Framework include(s):
7 
8 // local include(s)
13 
14 // ROOT include(s)
15 #include "TF1.h"
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TH3.h"
19 #include "TROOT.h"
20 #include "TClass.h"
21 #include <utility>
22 
23 using namespace TauAnalysisTools;
24 
25 /*
26  This tool acts as a common tool to apply efficiency scale factors and
27  uncertainties. By default, only nominal scale factors without systematic
28  variations are applied. Unavailable systematic variations are ignored, meaning
29  that the tool only returns the nominal value. In case the one available
30  systematic is requested, the smeared scale factor is computed as:
31  - sf = sf_nominal +/- n * uncertainty
32 
33  where n is in general 1 (representing a 1 sigma smearing), but can be any
34  arbitrary value. In case multiple systematic variations are passed they are
35  added in quadrature. Note that it's currently only supported if all are up or
36  down systematics.
37 
38  The tool reads in root files including TH2 histograms which need to fullfil a
39  predefined structure:
40 
41  scale factors:
42  - sf_<workingpoint>_<prongness>p
43  uncertainties:
44  - <NP>_<up/down>_<workingpoint>_<prongness>p (for asymmetric uncertainties)
45  - <NP>_<workingpoint>_<prongness>p (for symmetric uncertainties)
46 
47  where the <workingpoint> (e.g. loose/medium/tight) fields may be
48  optional. <prongness> represents either 1 or 3, whereas 3 is currently used
49  for multiprong in general. The <NP> fields are names for the type of nuisance
50  parameter (e.g. STAT or SYST), note the tool decides whethe the NP is a
51  recommended or only an available systematic based on the first character:
52  - uppercase -> recommended
53  - lowercase -> available
54  This magic happens here:
55  - CommonEfficiencyTool::generateSystematicSets()
56 
57  In addition the root input file can also contain objects of type TF1 that can
58  be used to provide kind of unbinned scale factors or systematics. The major
59  usecase for now is the high-pt uncertainty for the tau ID and tau
60  reconstruction.
61 
62  The files may also include TNamed objects which is used to define how x and
63  y-axes should be treated. By default the x-axis is given in units of tau-pT in
64  GeV and the y-axis is given as tau-eta. If there is for example a TNamed
65  object with name "Yaxis" and title "|eta|" the y-axis is treated in units of
66  absolute tau eta. All this is done in:
67  - void CommonEfficiencyTool::ReadInputs(TFile* fFile)
68 
69  Other tools for scale factors may build up on this tool and overwrite or add
70  praticular functionality (one example is the TauEfficiencyTriggerTool).
71 */
72 
73 //______________________________________________________________________________
75  : asg::AsgTool( sName )
76  , m_mSF(nullptr)
77  , m_sSystematicSet(nullptr)
78  , m_fX(&finalTauPt)
79  , m_fY(&finalTauEta)
80  , m_sSFHistName("sf")
81  , m_bNoMultiprong(false)
82  , m_eCheckTruth(TauAnalysisTools::Unknown)
83  , m_bSFIsAvailable(false)
84  , m_bSFIsAvailableChecked(false)
85 {
86  declareProperty( "InputFilePath", m_sInputFilePath = "" );
87  declareProperty( "VarName", m_sVarName = "" );
88  declareProperty( "WP", m_sWP = "" );
89  declareProperty( "SkipTruthMatchCheck", m_bSkipTruthMatchCheck = false );
90  declareProperty( "JetIDLevel", m_iJetIDLevel = (int)JETIDNONE );
91  declareProperty( "EleIDLevel", m_iEleIDLevel = (int)ELEIDNONE );
92  declareProperty( "SplitMu", m_bSplitMu = false );
93  declareProperty( "UseTauSubstructure", m_bUseTauSubstructure = false);
94 }
95 
96 /*
97  need to clear the map of histograms cause we have the ownership, not ROOT
98 */
100 {
101  if (m_mSF)
102  for (auto mEntry : *m_mSF)
103  delete std::get<0>(mEntry.second);
104 }
105 
106 /*
107  - Find the root files with scale factor inputs on cvmfs using PathResolver
108  (more info here:
109  https://twiki.cern.ch/twiki/bin/viewauth/AtlasComputing/PathResolver)
110  - Call further functions to process and define NP strings and so on
111  - Configure to provide nominal scale factors by default
112 */
114 {
115  ATH_MSG_INFO( "Initializing CommonEfficiencyTool" );
116  // only read in histograms once
117  if (m_mSF==nullptr)
118  {
119  std::string sInputFilePath = PathResolverFindCalibFile(m_sInputFilePath);
120 
121  m_mSF = std::make_unique< tSFMAP >();
122  std::unique_ptr< TFile > fSF( TFile::Open( sInputFilePath.c_str(), "READ" ) );
123  if(!fSF)
124  {
125  ATH_MSG_FATAL("Could not open file " << sInputFilePath.c_str());
126  return StatusCode::FAILURE;
127  }
128  ReadInputs(*fSF);
129  fSF->Close();
130  }
131 
132  // needed later on in generateSystematicSets(), maybe move it there
133  std::vector<std::string> vInputFilePath;
134  split(m_sInputFilePath,'/',vInputFilePath);
135  m_sInputFileName = vInputFilePath.back();
136 
138 
139  if (!m_sWP.empty())
140  m_sSFHistName = "sf_"+m_sWP;
141 
142  // load empty systematic variation by default
143  if (applySystematicVariation(CP::SystematicSet()) != StatusCode::SUCCESS )
144  return StatusCode::FAILURE;
145 
146  return StatusCode::SUCCESS;
147 }
148 
149 /*
150  Retrieve the scale factors and if requested the values for the NP's and add
151  this stuff in quadrature. Finally return sf_nom +/- n*uncertainty
152 */
153 
154 //______________________________________________________________________________
156  double& dEfficiencyScaleFactor, unsigned int /*iRunNumber*/, unsigned int iMu)
157 {
158  // check which true state is requested
160  {
161  dEfficiencyScaleFactor = 1.;
162  return CP::CorrectionCode::Ok;
163  }
164 
165  // check if 1 prong
166  if (m_bNoMultiprong && xTau.nTracks() != 1)
167  {
168  dEfficiencyScaleFactor = 1.;
169  return CP::CorrectionCode::Ok;
170  }
171 
172  // get decay mode or prong extension for histogram name
173  std::string sMode;
175  {
176  int iDecayMode = -1;
178  sMode = ConvertDecayModeToString(iDecayMode);
179  if (sMode.empty())
180  {
181  ATH_MSG_WARNING("Found tau with unknown decay mode. Skip efficiency correction.");
183  }
184  }
185  else
186  {
187  // skip taus which are not 1 or 3 prong
188  if( xTau.nTracks() != 1 && xTau.nTracks() != 3) {
189  dEfficiencyScaleFactor = 1.;
190  return CP::CorrectionCode::Ok;
191  }
192 
193  sMode = ConvertProngToString(xTau.nTracks());
194  }
195 
196  std::string sMu = "";
197  std::string sMCCampaign = "";
198 
199  if (m_bSplitMu) sMu = ConvertMuToString(iMu);
200  std::string sHistName = m_sSFHistName + sMode + sMu;
201 
202  // get standard scale factor
203  CP::CorrectionCode tmpCorrectionCode = getValue(sHistName,
204  xTau,
205  dEfficiencyScaleFactor);
206  // return correction code if histogram is not available
207  if (tmpCorrectionCode != CP::CorrectionCode::Ok)
208  return tmpCorrectionCode;
209 
210  // skip further process if systematic set is empty
211  if (m_sSystematicSet->empty())
212  return CP::CorrectionCode::Ok;
213 
214  // get uncertainties summed in quadrature
215  double dTotalSystematic2 = 0.;
216  double dDirection = 0.;
217  for (auto syst : *m_sSystematicSet)
218  {
219  // check if systematic is available
220  auto it = m_mSystematicsHistNames.find(syst.basename());
221 
222  // get uncertainty value
223  double dUncertaintySyst = 0.;
224 
225  // needed for up/down decision
226  dDirection = syst.parameter();
227 
228  // build up histogram name
229  sHistName = it->second;
230  if (dDirection>0.) sHistName+="_up";
231  else sHistName+="_down";
232  if (!m_sWP.empty()) sHistName+="_"+m_sWP;
233  sHistName += sMode + sMu + sMCCampaign;
234 
235  // filter unwanted combinations
236  if( (sHistName.find("3P") != std::string::npos && sHistName.find("1p") != std::string::npos) ||
237  (sHistName.find("1P") != std::string::npos && sHistName.find("3p") != std::string::npos))
238  continue;
239 
240  // get the uncertainty from the histogram
241  tmpCorrectionCode = getValue(sHistName,
242  xTau,
243  dUncertaintySyst);
244 
245  // return correction code if histogram is not available
246  if (tmpCorrectionCode != CP::CorrectionCode::Ok)
247  return tmpCorrectionCode;
248 
249  // scale uncertainty with direction, i.e. +/- n*sigma
250  dUncertaintySyst *= dDirection;
251 
252  // square uncertainty and add to total uncertainty
253  dTotalSystematic2 += dUncertaintySyst * dUncertaintySyst;
254  }
255 
256  // now use dDirection to use up/down uncertainty
257  dDirection = (dDirection > 0.) ? 1. : -1.;
258 
259  // finally apply uncertainty (eff * ( 1 +/- \sum )
260  dEfficiencyScaleFactor *= 1. + dDirection * std::sqrt(dTotalSystematic2);
261 
262  return CP::CorrectionCode::Ok;
263 }
264 
265 /*
266  Get scale factor from getEfficiencyScaleFactor and decorate it to the
267  tau. Note that this can only be done if the variable name is not already used,
268  e.g. if the variable was already decorated on a previous step (enured by the
269  m_bSFIsAvailableChecked check).
270 
271  Technical note: cannot use `static SG::Decorator` as we will have
272  multiple instances of this tool with different decoration names.
273 */
274 //______________________________________________________________________________
276  unsigned int iRunNumber, unsigned int iMu)
277 {
278  double dSf = 0.;
279 
282  {
283  m_bSFIsAvailable = decor.isAvailable(xTau);
285  if (m_bSFIsAvailable)
286  {
287  ATH_MSG_DEBUG(m_sVarName << " decoration is available on first tau processed, switched off applyEfficiencyScaleFactor for further taus.");
288  ATH_MSG_DEBUG("If an application of efficiency scale factors needs to be redone, please pass a shallow copy of the original tau.");
289  }
290  }
291  if (m_bSFIsAvailable)
292  return CP::CorrectionCode::Ok;
293 
294  // retrieve scale factor
295  CP::CorrectionCode tmpCorrectionCode = getEfficiencyScaleFactor(xTau, dSf, iRunNumber, iMu);
296  // adding scale factor to tau as decoration
297  decor(xTau) = dSf;
298 
299  return tmpCorrectionCode;
300 }
301 
302 /*
303  standard check if a systematic is available
304 */
305 //______________________________________________________________________________
307 {
309  return sys.find(systematic) != sys.end();
310 }
311 
312 /*
313  standard way to return systematics that are available (including recommended
314  systematics)
315 */
316 //______________________________________________________________________________
318 {
320 }
321 
322 /*
323  standard way to return systematics that are recommended
324 */
325 //______________________________________________________________________________
327 {
329 }
330 
331 /*
332  Configure the tool to use a systematic variation for further usage, until the
333  tool is reconfigured with this function. The passed systematic set is checked
334  for sanity:
335  - unsupported systematics are skipped
336  - only combinations of up or down supported systematics is allowed
337  - don't mix recommended systematics with other available systematics, cause
338  sometimes recommended are a quadratic sum of the other variations,
339  e.g. TOTAL=(SYST^2 + STAT^2)^0.5
340 */
341 //______________________________________________________________________________
343 {
344 
345  // first check if we already know this systematic configuration
346  auto itSystematicSet = m_mSystematicSets.find(sSystematicSet);
347  if (itSystematicSet != m_mSystematicSets.end())
348  {
349  m_sSystematicSet = &itSystematicSet->first;
350  return StatusCode::SUCCESS;
351  }
352 
353  // sanity checks if systematic set is supported
354  double dDirection = 0.;
355  CP::SystematicSet sSystematicSetAvailable;
356  for (auto sSyst : sSystematicSet)
357  {
358  // check if systematic is available
359  auto it = m_mSystematicsHistNames.find(sSyst.basename());
360  if (it == m_mSystematicsHistNames.end())
361  {
362  ATH_MSG_VERBOSE("unsupported systematic variation: "<< sSyst.basename()<<"; skipping this one");
363  continue;
364  }
365 
366 
367  if (sSyst.parameter() * dDirection < 0)
368  {
369  ATH_MSG_ERROR("unsupported set of systematic variations, you should either use only \"UP\" or only \"DOWN\" systematics in one set!");
370  ATH_MSG_ERROR("systematic set will not be applied");
371  return StatusCode::FAILURE;
372  }
373  dDirection = sSyst.parameter();
374 
375  if ((m_sRecommendedSystematics.find(sSyst.basename()) != m_sRecommendedSystematics.end()) and sSystematicSet.size() > 1)
376  {
377  ATH_MSG_ERROR("unsupported set of systematic variations, you should not combine \"TAUS_{TRUE|FAKE}_EFF_*_TOTAL\" with other systematic variations!");
378  ATH_MSG_ERROR("systematic set will not be applied");
379  return StatusCode::FAILURE;
380  }
381 
382  // finally add the systematic to the set of systematics to process
383  sSystematicSetAvailable.insert(sSyst);
384  }
385 
386  // store this calibration for future use, and make it current
387  m_sSystematicSet = &m_mSystematicSets.insert(std::pair<CP::SystematicSet,std::string>(sSystematicSetAvailable, sSystematicSet.name())).first->first;
388 
389  return StatusCode::SUCCESS;
390 }
391 
392 //=================================PRIVATE-PART=================================
393 std::string CommonEfficiencyTool::ConvertProngToString(const int fProngness) const
394 {
395  return fProngness == 1 ? "_1p" : "_3p";
396 }
397 
398 /*
399  mu converter, returns "_highMu" for average number of vertices higher than 35 and
400  "_lowMu" for everything below
401 */
402 //______________________________________________________________________________
403 std::string CommonEfficiencyTool::ConvertMuToString(const int iMu) const
404 {
405  if (iMu > 35 )
406  return "_highMu";
407 
408  return "_lowMu";
409 }
410 
411 /*
412  decay mode converter
413 */
414 //______________________________________________________________________________
415 std::string CommonEfficiencyTool::ConvertDecayModeToString(const int iDecayMode) const
416 {
417  switch(iDecayMode)
418  {
420  return "_r1p0n";
422  return "_r1p1n";
424  return "_r1pXn";
426  return "_r3p0n";
428  return "_r3pXn";
429  default:
430  return "";
431  }
432 }
433 
434 /*
435  Read in a root file and store all objects to a map of this type:
436  std::map<std::string, tTupleObjectFunc > (see header) It's basically a map of
437  the histogram name and a function pointer based on the TObject type (TH1F,
438  TH1D, TF1). This is resolved in the function:
439  - CommonEfficiencyTool::addHistogramToSFMap
440  Further this function figures out the axis definition (see description on the
441  top)
442 */
443 //______________________________________________________________________________
444 void CommonEfficiencyTool::ReadInputs(const TFile& fFile)
445 {
446  m_mSF->clear();
447 
448  // initialize function pointer
449  m_fX = &finalTauPt;
450  m_fY = &finalTauEta;
451 
452  TKey *kKey;
453  TIter itNext(fFile.GetListOfKeys());
454  while ((kKey = (TKey*)itNext()))
455  {
456  // parse file content for objects of type TNamed, check their title for
457  // known strings and reset funtion pointer
458  std::string sKeyName = kKey->GetName();
459  if (sKeyName == "Xaxis")
460  {
461  TNamed* tObj = (TNamed*)kKey->ReadObj();
462  std::string sTitle = tObj->GetTitle();
463  delete tObj;
464  if (sTitle == "P" || sTitle == "PFinalCalib")
465  {
466  m_fX = &finalTauP;
467  ATH_MSG_DEBUG("using full momentum for x-axis");
468  }
469  if (sTitle == "TruthDecayMode")
470  {
471  m_fX = &truthDecayMode;
472  ATH_MSG_DEBUG("using truth decay mode for x-axis");
473  }
474  if (sTitle == "truth pt")
475  {
476  m_fX = &truthTauPt;
477  ATH_MSG_DEBUG("using truth pT for x-axis");
478  }
479  if (sTitle == "|eta|")
480  {
481  m_fX = &finalTauAbsEta;
482  ATH_MSG_DEBUG("using absolute tau eta for x-axis");
483  }
484 
485  continue;
486  }
487  else if (sKeyName == "Yaxis")
488  {
489  TNamed* tObj = (TNamed*)kKey->ReadObj();
490  std::string sTitle = tObj->GetTitle();
491  delete tObj;
492  if (sTitle == "track-eta")
493  {
495  ATH_MSG_DEBUG("using leading track eta for y-axis");
496  }
497  else if (sTitle == "|eta|")
498  {
499  m_fY = &finalTauAbsEta;
500  ATH_MSG_DEBUG("using absolute tau eta for y-axis");
501  }
502  else if (sTitle == "mu")
503  {
504  m_fY = [this](const xAOD::TauJet&) -> double {
505  const xAOD::EventInfo* xEventInfo = nullptr;
506  if (evtStore()->retrieve(xEventInfo,"EventInfo").isFailure()) {
507  return 0;
508  }
509  if (xEventInfo->runNumber()==284500)
510  {
511  return xEventInfo->averageInteractionsPerCrossing();
512  }
513  else if (xEventInfo->runNumber()==300000 || xEventInfo->runNumber()==310000)
514  {
515  return xEventInfo->actualInteractionsPerCrossing();
516  }
517  return 0;
518  };
519  ATH_MSG_DEBUG("using average mu for y-axis");
520  }
521  else if (sTitle == "truth |eta|")
522  {
523  m_fY = &truthTauAbsEta;
524  ATH_MSG_DEBUG("using absolute truth tau eta for y-axis");
525  }
526  continue;
527  }
528 
529  std::vector<std::string> vSplitName = {};
530  split(sKeyName,'_',vSplitName);
531  if (vSplitName[0] == "sf")
532  {
533  addHistogramToSFMap(kKey, sKeyName);
534  }
535  else
536  {
537  // std::string sDirection = vSplitName[1];
538  if (sKeyName.find("_up_") != std::string::npos or sKeyName.find("_down_") != std::string::npos)
539  addHistogramToSFMap(kKey, sKeyName);
540  else
541  {
542  size_t iPos = sKeyName.find('_');
543  addHistogramToSFMap(kKey, sKeyName.substr(0,iPos)+"_up"+sKeyName.substr(iPos));
544  addHistogramToSFMap(kKey, sKeyName.substr(0,iPos)+"_down"+sKeyName.substr(iPos));
545  }
546  }
547  }
548  ATH_MSG_INFO("data loaded from " << fFile.GetName());
549 }
550 
551 /*
552  Create the tuple objects for the map
553 */
554 //______________________________________________________________________________
555 void CommonEfficiencyTool::addHistogramToSFMap(TKey* kKey, const std::string& sKeyName)
556 {
557  // handling for the 3 different input types TH1F/TH1D/TF1, function pointer
558  // handle the access methods for the final scale factor retrieval
559  TClass *cClass = gROOT->GetClass(kKey->GetClassName());
560  if (cClass->InheritsFrom("TH2"))
561  {
562  TH1* oObject = (TH1*)kKey->ReadObj();
563  oObject->SetDirectory(0);
564  (*m_mSF)[sKeyName] = tTupleObjectFunc(oObject,&getValueTH2);
565  ATH_MSG_DEBUG("added histogram with name "<<sKeyName);
566  }
567  else if (cClass->InheritsFrom("TH3"))
568  {
569  TH1* oObject = (TH1*)kKey->ReadObj();
570  oObject->SetDirectory(0);
571  (*m_mSF)[sKeyName] = tTupleObjectFunc(oObject,&getValueTH3);
572  ATH_MSG_DEBUG("added histogram with name "<<sKeyName);
573  }else if (cClass->InheritsFrom("TH1"))
574  {
575  TH1* oObject = (TH1*)kKey->ReadObj();
576  oObject->SetDirectory(0);
577  (*m_mSF)[sKeyName] = tTupleObjectFunc(oObject,&getValueTH1);
578  ATH_MSG_DEBUG("added histogram with name "<<sKeyName);
579  }
580  else if (cClass->InheritsFrom("TF1"))
581  {
582  TObject* oObject = kKey->ReadObj();
583  (*m_mSF)[sKeyName] = tTupleObjectFunc(oObject,&getValueTF1);
584  ATH_MSG_DEBUG("added function with name "<<sKeyName);
585  }
586  else
587  {
588  ATH_MSG_DEBUG("ignored object with name "<<sKeyName);
589  }
590 }
591 
592 /*
593  This function parses the names of the obejects from the input file and
594  generates the systematic sets and defines which ones are recommended or only
595  available. It also checks, based on the root file name, on which tau it needs
596  to be applied, e.g. only on reco taus coming from true taus or on those faked
597  by true electrons...
598 
599  Examples:
600  filename: Reco_TrueHadTau_2016-ichep.root -> apply only to true taus
601  histname: sf_1p -> nominal 1p scale factor
602  histname: TOTAL_3p -> "total" 3p NP, recommended
603  histname: afii_1p -> "total" 3p NP, not recommended, but available
604 */
605 //______________________________________________________________________________
607 {
608  // creation of basic string for all NPs, e.g. "TAUS_TRUEHADTAU_EFF_RECO_"
609  std::vector<std::string> vSplitInputFilePath = {};
610  split(m_sInputFileName,'_',vSplitInputFilePath);
611  std::string sEfficiencyType = vSplitInputFilePath.at(0);
612  std::string sTruthType = vSplitInputFilePath.at(1);
613  std::transform(sEfficiencyType.begin(), sEfficiencyType.end(), sEfficiencyType.begin(), toupper);
614  std::transform(sTruthType.begin(), sTruthType.end(), sTruthType.begin(), toupper);
615  std::string sSystematicBaseString = "TAUS_"+sTruthType+"_EFF_"+sEfficiencyType+"_";
616 
617  // set truth type to check for in truth matching
618  if (sTruthType=="TRUEHADTAU") m_eCheckTruth = TauAnalysisTools::TruthHadronicTau;
619  else if (sTruthType=="TRUEELECTRON") m_eCheckTruth = TauAnalysisTools::TruthElectron;
620  else if (sTruthType=="TRUEMUON") m_eCheckTruth = TauAnalysisTools::TruthMuon;
621  else if (sTruthType=="TRUEJET") m_eCheckTruth = TauAnalysisTools::TruthJet;
622  else if (sTruthType=="TRUEHADDITAU") m_eCheckTruth = TauAnalysisTools::TruthHadronicDiTau;
623  // 3p eVeto, still need this to be measurable in T&P
624  if (sEfficiencyType=="ELERNN" || sEfficiencyType=="ELEOLR") m_bNoMultiprong = true;
625 
626  for (auto mSF : *m_mSF)
627  {
628  // parse for nuisance parameter in histogram name
629  std::vector<std::string> vSplitNP = {};
630  split(mSF.first,'_',vSplitNP);
631  std::string sNP = vSplitNP.at(0);
632  std::string sNPUppercase = vSplitNP.at(0);
633 
634  // skip nominal scale factors
635  if (sNP == "sf") continue;
636 
637  // skip if 3p histogram to avoid duplications (TODO: come up with a better solution)
638  //if (mSF.first.find("_3p") != std::string::npos) continue;
639 
640  // test if NP starts with a capital letter indicating that this should be recommended
641  bool bIsRecommended = false;
642  if (isupper(sNP.at(0)) || isupper(sNP.at(1)))
643  bIsRecommended = true;
644 
645  // make sNP uppercase and build final NP entry name
646  std::transform(sNPUppercase.begin(), sNPUppercase.end(), sNPUppercase.begin(), toupper);
647  std::string sSystematicString = sSystematicBaseString+sNPUppercase;
648 
649  // add all found systematics to the AffectingSystematics
651  m_sAffectingSystematics.insert(CP::SystematicVariation (sSystematicString, -1));
652  // only add found uppercase systematics to the RecommendedSystematics
653  if (bIsRecommended)
654  {
657  }
658 
659  ATH_MSG_DEBUG("connected base name " << sNP << " with systematic " <<sSystematicString);
660  m_mSystematicsHistNames.insert({sSystematicString,sNP});
661  }
662 }
663 
664 /*
665  return value from the tuple map object based on the pt/eta values (or the
666  corresponding value in case of configuration)
667 */
668 //______________________________________________________________________________
670  const xAOD::TauJet& xTau,
671  double& dEfficiencyScaleFactor) const
672 {
673  const tSFMAP& mSF = *m_mSF;
674  auto it = mSF.find (sHistName);
675  if (it == mSF.end())
676  {
677  ATH_MSG_ERROR("Object with name "<<sHistName<<" was not found in input file.");
678  ATH_MSG_DEBUG("Content of input file");
679  for (auto eEntry : mSF)
680  ATH_MSG_DEBUG(" Entry: "<<eEntry.first);
682  }
683 
684  // get a tuple (TObject*,functionPointer) from the scale factor map
685  tTupleObjectFunc tTuple = it->second;
686 
687  // get pt and eta (for x and y axis respectively)
688  double dPt = m_fX(xTau);
689  double dEta = m_fY(xTau);
690 
691  double dVars[2] = {dPt, dEta};
692 
693  // finally obtain efficiency scale factor from TH1F/TH1D/TF1, by calling the
694  // function pointer stored in the tuple from the scale factor map
695  return (std::get<1>(tTuple))(std::get<0>(tTuple), dEfficiencyScaleFactor, dVars);
696 }
697 
698 /*
699  find the particular value in TH1 depending on pt (or the
700  corresponding value in case of configuration)
701  Note: In case values are outside of bin ranges, the closest bin value is used
702 */
703 //______________________________________________________________________________
705  double& dEfficiencyScaleFactor, double dVars[])
706 {
707  double dPt = dVars[0];
708 
709  const TH1* hHist = dynamic_cast<const TH1*>(oObject);
710 
711  if (!hHist)
712  {
713  // ATH_MSG_ERROR("Problem with casting TObject of type "<<oObject->ClassName()<<" to TH2F");
715  }
716 
717  // protect values from underflow bins
718  dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
719  // protect values from overflow bins (times .999 to keep it inside last bin)
720  dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
721 
722  // get bin from TH2 depending on x and y values; finally set the scale factor
723  int iBin = hHist->FindFixBin(dPt);
724  dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
725  return CP::CorrectionCode::Ok;
726 }
727 
728 /*
729  find the particular value in TH2 depending on pt and eta (or the
730  corresponding value in case of configuration)
731  Note: In case values are outside of bin ranges, the closest bin value is used
732 */
733 //______________________________________________________________________________
735  double& dEfficiencyScaleFactor, double dVars[])
736 {
737  double dPt = dVars[0];
738  double dEta = dVars[1];
739 
740  const TH2* hHist = dynamic_cast<const TH2*>(oObject);
741 
742  if (!hHist)
743  {
744  // ATH_MSG_ERROR("Problem with casting TObject of type "<<oObject->ClassName()<<" to TH2F");
746  }
747 
748  // protect values from underflow bins
749  dPt = std::max(dPt,hHist->GetXaxis()->GetXmin());
750  dEta = std::max(dEta,hHist->GetYaxis()->GetXmin());
751  // protect values from overflow bins (times .999 to keep it inside last bin)
752  dPt = std::min(dPt,hHist->GetXaxis()->GetXmax() * .999);
753  dEta = std::min(dEta,hHist->GetYaxis()->GetXmax() * .999);
754 
755  // get bin from TH2 depending on x and y values; finally set the scale factor
756  int iBin = hHist->FindFixBin(dPt,dEta);
757  dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
758  return CP::CorrectionCode::Ok;
759 }
760 
761 /*
762  find the particular value in TH3 depending on x, y, z
763  Note: In case values are outside of bin ranges, the closest bin value is used
764 */
765 //______________________________________________________________________________
767  double& dEfficiencyScaleFactor, double dVars[])
768 {
769  double dX = dVars[0];
770  double dY = dVars[1];
771  double dZ = dVars[2];
772 
773  const TH3* hHist = dynamic_cast<const TH3*>(oObject);
774 
775  if (!hHist)
776  {
777  // ATH_MSG_ERROR("Problem with casting TObject of type "<<oObject->ClassName()<<" to TH2D");
779  }
780 
781  // protect values from underflow bins
782  dX = std::max(dX,hHist->GetXaxis()->GetXmin());
783  dY = std::max(dY,hHist->GetYaxis()->GetXmin());
784  dZ = std::max(dZ,hHist->GetZaxis()->GetXmin());
785  // protect values from overflow bins (times .999 to keep it inside last bin)
786  dX = std::min(dX,hHist->GetXaxis()->GetXmax() * .999);
787  dY = std::min(dY,hHist->GetYaxis()->GetXmax() * .999);
788  dZ = std::min(dZ,hHist->GetZaxis()->GetXmax() * .999);
789 
790  // get bin from TH2 depending on x and y values; finally set the scale factor
791  int iBin = hHist->FindFixBin(dX,dY,dZ);
792  dEfficiencyScaleFactor = hHist->GetBinContent(iBin);
793  return CP::CorrectionCode::Ok;
794 }
795 
796 /*
797  Find the particular value in TF1 depending on pt and eta (or the corresponding
798  value in case of configuration)
799 */
800 //______________________________________________________________________________
802  double& dEfficiencyScaleFactor, double dVars[])
803 {
804  double dPt = dVars[0];
805  double dEta = dVars[1];
806 
807  const TF1* fFunc = static_cast<const TF1*>(oObject);
808 
809  if (!fFunc)
810  {
811  // ATH_MSG_ERROR("Problem with casting TObject of type "<<oObject->ClassName()<<" to TF1");
813  }
814 
815  // evaluate TFunction and set scale factor
816  dEfficiencyScaleFactor = fFunc->Eval(dPt, dEta);
817  return CP::CorrectionCode::Ok;
818 }
xAOD::TauJetParameters::Mode_1p0n
@ Mode_1p0n
Definition: TauDefs.h:386
TauAnalysisTools
Definition: TruthCollectionMakerTau.h:16
xAOD::TauJetParameters::PanTau_DecayMode
@ PanTau_DecayMode
Definition: TauDefs.h:360
TauAnalysisTools::TruthElectron
@ TruthElectron
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:100
TauAnalysisTools::CommonEfficiencyTool::m_eCheckTruth
TruthMatchedParticleType m_eCheckTruth
Definition: CommonEfficiencyTool.h:148
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TauAnalysisTools::CommonEfficiencyTool::ReadInputs
void ReadInputs(const TFile &fFile)
Definition: CommonEfficiencyTool.cxx:444
xAOD::TauJetParameters::Mode_1p1n
@ Mode_1p1n
Definition: TauDefs.h:387
max
#define max(a, b)
Definition: cfImp.cxx:41
TauAnalysisTools::truthTauAbsEta
double truthTauAbsEta(const xAOD::TauJet &xTau)
return truth match tau eta (if hadronic truth tau match)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:172
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TauAnalysisTools::CommonEfficiencyTool::getEfficiencyScaleFactor
virtual CP::CorrectionCode getEfficiencyScaleFactor(const xAOD::TauJet &tau, double &dEfficiencyScaleFactor, unsigned int iRunNumber=0, unsigned int iMu=0)
Declare the interface that the class provides.
Definition: CommonEfficiencyTool.cxx:155
TauAnalysisTools::CommonEfficiencyTool::m_bSkipTruthMatchCheck
bool m_bSkipTruthMatchCheck
Definition: CommonEfficiencyTool.h:142
TauAnalysisTools::TruthHadronicTau
@ TruthHadronicTau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:97
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TauAnalysisTools::truthTauPt
double truthTauPt(const xAOD::TauJet &xTau)
return truth match tau pt in GeV (if hadronic truth tau match)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:158
TauAnalysisTools::CommonEfficiencyTool::m_sSystematicSet
const CP::SystematicSet * m_sSystematicSet
Definition: CommonEfficiencyTool.h:99
CP::SystematicSet::empty
bool empty() const
returns: whether the set is empty
Definition: SystematicSet.h:67
TruthParticleContainer.h
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:526
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TauAnalysisTools::CommonEfficiencyTool::ConvertProngToString
std::string ConvertProngToString(const int iProngness) const
Definition: CommonEfficiencyTool.cxx:393
asg
Definition: DataHandleTestTool.h:28
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
TauAnalysisTools::CommonEfficiencyTool::tSFMAP
std::map< std::string, tTupleObjectFunc > tSFMAP
Definition: CommonEfficiencyTool.h:88
CP::SystematicSet::name
std::string name() const
returns: the systematics joined into a single string.
Definition: SystematicSet.cxx:278
TauAnalysisTools::CommonEfficiencyTool::applySystematicVariation
virtual StatusCode applySystematicVariation(const CP::SystematicSet &sSystematicSet)
configure this tool for the given list of systematic variations.
Definition: CommonEfficiencyTool.cxx:342
TauAnalysisTools::CommonEfficiencyTool::m_sVarName
std::string m_sVarName
Definition: CommonEfficiencyTool.h:140
xAOD::TauJet_v3::panTauDetail
bool panTauDetail(TauJetParameters::PanTauDetails panTauDetail, int &value) const
Get and set values of pantau details variables via enum.
Definition: TauJet_v3.cxx:367
TauAnalysisTools::finalTauPt
double finalTauPt(const xAOD::TauJet &xTau)
return MVA based tau pt in GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:113
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
TauAnalysisTools::TruthJet
@ TruthJet
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:101
CP::SystematicVariation
Definition: SystematicVariation.h:47
TauAnalysisTools::Unknown
@ Unknown
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:96
TauAnalysisTools::CommonEfficiencyTool::getValueTH3
static CP::CorrectionCode getValueTH3(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])
Definition: CommonEfficiencyTool.cxx:766
TauAnalysisTools::JETIDNONE
@ JETIDNONE
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:14
TauAnalysisTools::CommonEfficiencyTool::tTupleObjectFunc
std::tuple< TObject *, CP::CorrectionCode(*)(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[]) > tTupleObjectFunc
Definition: CommonEfficiencyTool.h:87
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
xAOD::EventInfo_v1::runNumber
uint32_t runNumber() const
The current event's run number.
TauAnalysisTools::CommonEfficiencyTool::isAffectedBySystematic
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
returns: whether this tool is affected by the given systematics
Definition: CommonEfficiencyTool.cxx:306
xAOD::TauJetParameters::Mode_1pXn
@ Mode_1pXn
Definition: TauDefs.h:388
TauAnalysisTools::CommonEfficiencyTool::~CommonEfficiencyTool
~CommonEfficiencyTool()
Definition: CommonEfficiencyTool.cxx:99
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
TauAnalysisTools::CommonEfficiencyTool::m_mSystematicSets
std::unordered_map< CP::SystematicSet, std::string > m_mSystematicSets
Definition: CommonEfficiencyTool.h:98
TauAnalysisTools::finalTauP
double finalTauP(const xAOD::TauJet &xTau)
return MVA based tau P in GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:134
TauAnalysisTools::CommonEfficiencyTool::getValue
virtual CP::CorrectionCode getValue(const std::string &sHistName, const xAOD::TauJet &xTau, double &dEfficiencyScaleFactor) const
Definition: CommonEfficiencyTool.cxx:669
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition: CorrectionCode.h:37
TauAnalysisTools::truthDecayMode
double truthDecayMode(const xAOD::TauJet &xTau)
return truth decay mode (if hadronic truth tau match)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:186
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
TauEfficiencyCorrectionsTool.h
TauAnalysisTools::ELEIDNONE
@ ELEIDNONE
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:32
TauAnalysisTools::CommonEfficiencyTool::recommendedSystematics
virtual CP::SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool recommends to use
Definition: CommonEfficiencyTool.cxx:326
TauAnalysisTools::CommonEfficiencyTool::m_sWP
std::string m_sWP
Definition: CommonEfficiencyTool.h:139
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TauAnalysisTools::CommonEfficiencyTool::m_mSF
std::unique_ptr< tSFMAP > m_mSF
Definition: CommonEfficiencyTool.h:95
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
CP::SystematicSet::end
const_iterator end() const
description: const iterator to the end of the set
Definition: SystematicSet.h:59
TauAnalysisTools::CommonEfficiencyTool::m_fX
std::function< double(const xAOD::TauJet &xTau)> m_fX
Definition: CommonEfficiencyTool.h:103
TauAnalysisTools::CommonEfficiencyTool::m_iJetIDLevel
int m_iJetIDLevel
Definition: CommonEfficiencyTool.h:145
TauAnalysisTools::CommonEfficiencyTool::m_bSFIsAvailable
bool m_bSFIsAvailable
Definition: CommonEfficiencyTool.h:150
TauAnalysisTools::CommonEfficiencyTool::getValueTH2
static CP::CorrectionCode getValueTH2(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])
Definition: CommonEfficiencyTool.cxx:734
xAOD::TauJetParameters::Mode_3p0n
@ Mode_3p0n
Definition: TauDefs.h:389
TauAnalysisTools::CommonEfficiencyTool::m_sSFHistName
std::string m_sSFHistName
Definition: CommonEfficiencyTool.h:141
min
#define min(a, b)
Definition: cfImp.cxx:40
TauAnalysisTools::TruthMuon
@ TruthMuon
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:99
TauAnalysisTools::CommonEfficiencyTool::m_sInputFilePath
std::string m_sInputFilePath
Definition: CommonEfficiencyTool.h:137
xAOD::EventInfo_v1::averageInteractionsPerCrossing
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
Definition: EventInfo_v1.cxx:397
TauAnalysisTools::CommonEfficiencyTool::generateSystematicSets
void generateSystematicSets()
Definition: CommonEfficiencyTool.cxx:606
PathResolver.h
TauAnalysisTools::CommonEfficiencyTool::m_sAffectingSystematics
CP::SystematicSet m_sAffectingSystematics
Definition: CommonEfficiencyTool.h:134
CommonEfficiencyTool.h
TauAnalysisTools::CommonEfficiencyTool::m_bUseTauSubstructure
bool m_bUseTauSubstructure
Definition: CommonEfficiencyTool.h:144
CP::SystematicSet::insert
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
Definition: SystematicSet.cxx:88
TauAnalysisTools::CommonEfficiencyTool::m_fY
std::function< double(const xAOD::TauJet &xTau)> m_fY
Definition: CommonEfficiencyTool.h:104
TauAnalysisTools::CommonEfficiencyTool::ConvertMuToString
std::string ConvertMuToString(const int iMu) const
Definition: CommonEfficiencyTool.cxx:403
TauAnalysisTools::CommonEfficiencyTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: CommonEfficiencyTool.cxx:113
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TauAnalysisTools::CommonEfficiencyTool::addHistogramToSFMap
void addHistogramToSFMap(TKey *kKey, const std::string &sKeyName)
Definition: CommonEfficiencyTool.cxx:555
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
CP::SystematicSet::find
iterator find(const SystematicVariation &sys) const
description: find an element in the set
Definition: SystematicSet.h:63
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
TauAnalysisTools::finalTauAbsEta
double finalTauAbsEta(const xAOD::TauJet &xTau)
return MVA based absolute tau eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:127
TauAnalysisTools::CommonEfficiencyTool::m_bSFIsAvailableChecked
bool m_bSFIsAvailableChecked
Definition: CommonEfficiencyTool.h:151
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TauAnalysisTools::CommonEfficiencyTool::CommonEfficiencyTool
CommonEfficiencyTool(const std::string &sName)
Create a proper constructor for Athena.
Definition: CommonEfficiencyTool.cxx:74
SG::Decorator::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
TauAnalysisTools::tauLeadTrackEta
double tauLeadTrackEta(const xAOD::TauJet &xTau)
return leading charge tau track eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:141
TauAnalysisTools::CommonEfficiencyTool::ConvertDecayModeToString
std::string ConvertDecayModeToString(const int iDecayMode) const
Definition: CommonEfficiencyTool.cxx:415
TauAnalysisTools::getTruthParticleType
TruthMatchedParticleType getTruthParticleType(const xAOD::TauJet &xTau)
return TauJet match type
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:572
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
xAOD::TauJetParameters::Mode_3pXn
@ Mode_3pXn
Definition: TauDefs.h:390
TauAnalysisTools::CommonEfficiencyTool::m_bNoMultiprong
bool m_bNoMultiprong
Definition: CommonEfficiencyTool.h:143
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:527
TauAnalysisTools::CommonEfficiencyTool::m_sInputFileName
std::string m_sInputFileName
Definition: CommonEfficiencyTool.h:138
TauAnalysisTools::CommonEfficiencyTool::affectingSystematics
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
Definition: CommonEfficiencyTool.cxx:317
TauAnalysisTools::CommonEfficiencyTool::applyEfficiencyScaleFactor
virtual CP::CorrectionCode applyEfficiencyScaleFactor(const xAOD::TauJet &xTau, unsigned int iRunNumber=0, unsigned int iMu=0)
Decorate the tau with its efficiency.
Definition: CommonEfficiencyTool.cxx:275
Decorator.h
Helper class to provide type-safe access to aux data.
TauAnalysisTools::CommonEfficiencyTool::m_bSplitMu
bool m_bSplitMu
Definition: CommonEfficiencyTool.h:152
TauAnalysisTools::CommonEfficiencyTool::m_mSystematicsHistNames
std::map< std::string, std::string > m_mSystematicsHistNames
Definition: CommonEfficiencyTool.h:101
TauAnalysisTools::CommonEfficiencyTool::getValueTH1
static CP::CorrectionCode getValueTH1(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])
Definition: CommonEfficiencyTool.cxx:704
TauAnalysisTools::TruthHadronicDiTau
@ TruthHadronicDiTau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:102
TauAnalysisTools::CommonEfficiencyTool::getValueTF1
static CP::CorrectionCode getValueTF1(const TObject *oObject, double &dEfficiencyScaleFactor, double dVars[])
Definition: CommonEfficiencyTool.cxx:801
TauAnalysisTools::CommonEfficiencyTool::m_sRecommendedSystematics
CP::SystematicSet m_sRecommendedSystematics
Definition: CommonEfficiencyTool.h:135
TauAnalysisTools::CommonEfficiencyTool::m_iEleIDLevel
int m_iEleIDLevel
Definition: CommonEfficiencyTool.h:146
TauAnalysisTools::finalTauEta
double finalTauEta(const xAOD::TauJet &xTau)
return MVA based tau eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:120
xAOD::EventInfo_v1::actualInteractionsPerCrossing
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
Definition: EventInfo_v1.cxx:380
TauAnalysisTools::split
void split(const std::string &sInput, const char cDelim, std::vector< std::string > &vOut)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:23