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