ATLAS Offline Software
Loading...
Searching...
No Matches
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
14namespace CP {
15 IsolationConditionCombined::IsolationConditionCombined(const std::string& name, const std::vector<xAOD::Iso::IsolationType>& isoTypes,
16 std::unique_ptr<TF1> isoFunction, const std::string& cutFunction, const std::string& isoDecSuffix, bool invertCut) :
17 IsolationCondition(name, isoTypes, isoDecSuffix),
18 m_cutFunction (std::make_unique<TF1>(cutFunction.c_str(), cutFunction.c_str())),
19 m_isoFunction (std::move(isoFunction)),
20 m_invertCut(invertCut)
21 {
22 }
23 IsolationConditionCombined::IsolationConditionCombined(const std::string& name, const std::vector<std::string>& isoTypes,
24 std::unique_ptr<TF1> isoFunction, const std::string& cutFunction, const std::string& isoDecSuffix, bool invertCut) :
25 IsolationCondition(name, isoTypes, isoDecSuffix),
26 m_cutFunction (std::make_unique<TF1>(cutFunction.c_str(), cutFunction.c_str())),
27 m_isoFunction (std::move(isoFunction)),
28 m_invertCut(invertCut)
29 {
30 }
31
33 const float cutValue = m_cutFunction->Eval(x.pt());
34 std::vector<double> isoVars(num_types(), 0);
35 for (unsigned int iacc = 0; iacc < num_types(); ++iacc) {
36 const FloatAccessor& acc = accessor(iacc);
37
38 if (!acc.isAvailable(x)) {
39 // Temporary fix for missing closeByCorr variables if no primary vertex exists for the event
40 // If closeByCorr variable does not exist, fallback to the standard isolation variable 2025/02
41 const FloatAccessor& acc_noCloseBy = accessor_noCloseBy(iacc);
42 if (acc_noCloseBy.isAvailable(x)) {
43 isoVars[iacc] = acc_noCloseBy(x);
44 }
45 else {
46 ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<"Accessor "<<SG::AuxTypeRegistry::instance().getName(acc.auxid())
47 <<" is not available. Expected when using primary AODs, post-p3793 derivations (only for *FixedRad or FixedCutPflow* for electrons), "
48 <<" pre-p3517 derivations (only for FC*), or pre-p3830 derivations (for other electron WPs)");
49 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'. ");
50 isoVars[iacc] = FLT_MAX;
51 }
52 } else
53 isoVars[iacc] = acc(x);
54 }
55 // In general TF1::EvalPar is non-const/not thread-safe. But for the special
56 // case of using it as TFormula it can be considered const/safe. It would be safer
57 // to change the interface to not allow a generic TF1.
58 TF1* f ATLAS_THREAD_SAFE = m_isoFunction.get();
59 const float isoValue = f->EvalPar(isoVars.data());
60 if (!m_invertCut) return isoValue <= cutValue;
61 return isoValue > cutValue;
62 }
63
65 const float cutValue = m_cutFunction->Eval(x.pt);
66 std::vector<double> isoVars;
67 for (unsigned int itype = 0; itype < num_types(); ++itype) isoVars.push_back(x.isolationValues[type(itype)]);
68 TF1* f ATLAS_THREAD_SAFE = m_isoFunction.get(); // see comment above
69 const float isoValue = f->EvalPar(isoVars.data());
70 if (!m_invertCut) return isoValue <= cutValue;
71 return isoValue > cutValue;
72 }
73} // namespace CP
#define ATH_MSG_WARNING(x)
#define x
Define macros for attributes used to control the static checker.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE
Messaging initialized (initMessaging)
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="", bool invertCut=false)
bool accept(const xAOD::IParticle &x) const override
IsolationCondition(const std::string &name, xAOD::Iso::IsolationType isoType, const std::string &isoDecSuffix="")
const FloatAccessor & accessor_noCloseBy(unsigned int n=0) const
const std::string & name() const
unsigned int num_types() const
xAOD::Iso::IsolationType type(unsigned int n=0) const
const FloatAccessor & accessor(unsigned int n=0) const
static AuxTypeRegistry & instance()
Return the singleton registry instance.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Class providing the definition of the 4-vector interface.
Select isolated Photons, Electrons and Muons.
STL namespace.
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.