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