ATLAS Offline Software
IsolationConditionCombined.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
7 
8 #include <TF2.h>
9 #include <TH3.h>
10 
11 #include <algorithm>
12 #include <cmath>
13 
14 namespace CP {
15  IsolationConditionCombined::IsolationConditionCombined(const std::string& name, const std::vector<xAOD::Iso::IsolationType>& isoType,
16  std::unique_ptr<TF1> isoFunction, const std::string& cutFunction, const std::string& isoDecSuffix) :
17  IsolationCondition(name, isoType, isoDecSuffix),
18  m_cutFunction (std::make_unique<TF1>(cutFunction.c_str(), cutFunction.c_str())),
19  m_isoFunction (std::move(isoFunction))
20  {
21  }
23  const float cutValue = m_cutFunction->Eval(x.pt());
24  std::vector<double> isoVars(num_types(), 0);
25  for (unsigned int acc = 0; acc < num_types(); ++acc) {
26  const FloatAccessor& acc_ele = accessor(acc);
27 
28  if (!acc_ele.isAvailable(x)) {
29  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<"Accessor "<<SG::AuxTypeRegistry::instance().getName(acc_ele.auxid())
30  <<" is not available. Expected when using primary AODs, post-p3793 derivations (only for *FixedRad or FixedCutPflow* for electrons), "
31  <<" pre-p3517 derivations (only for FC*), or pre-p3830 derivations (for other electron WPs)");
32  if (!m_isoDecSuffix.empty()) throw std::runtime_error ("IsolationConditionCombined: IsolationSelectionTool property 'IsoDecSuffix' is set to " + m_isoDecSuffix + ". Must run on derivation made with IsolationCloseByCorrection to create the isolation variables with this suffix, or remove 'IsoDecSuffix'. ");
33  isoVars[acc] = FLT_MAX;
34  } else
35  isoVars[acc] = acc_ele(x);
36  }
37  // In general TF1::EvalPar is non-const/not thread-safe. But for the special
38  // case of using it as TFormula it can be considered const/safe. It would be safer
39  // to change the interface to not allow a generic TF1.
40  TF1* f ATLAS_THREAD_SAFE = m_isoFunction.get();
41  const float isoValue = f->EvalPar(isoVars.data());
42  return isoValue <= cutValue;
43  }
44 
46  const float cutValue = m_cutFunction->Eval(x.pt);
47  std::vector<double> isoVars;
48  for (unsigned int itype = 0; itype < num_types(); ++itype) isoVars.push_back(x.isolationValues[type(itype)]);
49  TF1* f ATLAS_THREAD_SAFE = m_isoFunction.get(); // see comment above
50  const float isoValue = f->EvalPar(isoVars.data());
51  return isoValue <= cutValue;
52  }
53 } // namespace CP
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
SG::ConstAccessor::auxid
SG::auxid_t auxid() const
Return the aux id for this variable.
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
CP::IsolationCondition::type
xAOD::Iso::IsolationType type(unsigned int n=0) const
Definition: IsolationCondition.cxx:37
x
#define x
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::IsolationConditionCombined::m_isoFunction
std::unique_ptr< TF1 > m_isoFunction
Definition: IsolationConditionCombined.h:24
CP::IsolationCondition::num_types
unsigned int num_types() const
Definition: IsolationCondition.cxx:35
dumpTruth.getName
getName
Definition: dumpTruth.py:34
CP::IsolationCondition
Definition: IsolationCondition.h:30
AthMessaging::ATLAS_THREAD_SAFE
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
Definition: AthMessaging.h:141
CP::strObj
Definition: IsolationCondition.h:23
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CP::IsolationCondition::accessor
const FloatAccessor & accessor(unsigned int n=0) const
Definition: IsolationCondition.cxx:38
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IsolationConditionCombined.h
CP::IsolationConditionCombined::IsolationConditionCombined
IsolationConditionCombined(const std::string &name, const std::vector< xAOD::Iso::IsolationType > &isoType, std::unique_ptr< TF1 > isoFunction, const std::string &cutFunction, const std::string &isoDecSuffix="")
Definition: IsolationConditionCombined.cxx:15
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::IsolationCondition::m_isoDecSuffix
std::string m_isoDecSuffix
Definition: IsolationCondition.h:56
CP::IsolationConditionCombined::m_cutFunction
std::unique_ptr< TF1 > m_cutFunction
Definition: IsolationConditionCombined.h:23
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
checker_macros.h
Define macros for attributes used to control the static checker.
CP::IsolationConditionCombined::accept
bool accept(const xAOD::IParticle &x) const override
Definition: IsolationConditionCombined.cxx:22