ATLAS Offline Software
Loading...
Searching...
No Matches
BTaggingBoundsHandler Class Reference

#include <BTaggingBoundsHandler.h>

Inheritance diagram for BTaggingBoundsHandler:
Collaboration diagram for BTaggingBoundsHandler:

Classes

struct  varBounds

Public Types

using JetQuantityGetter = std::function<float(const xAOD::Jet&, BTaggingToolUtil::varType)>
using json = nlohmann::ordered_json

Public Member Functions

 BTaggingBoundsHandler (const json &jsonConfig, JetQuantityGetter *funcGetJetQuantity)
BTaggingBoundsHandler & operator= (BTaggingBoundsHandler &&) noexcept=default
 BTaggingBoundsHandler (BTaggingBoundsHandler &&) noexcept=default
 BTaggingBoundsHandler (const BTaggingBoundsHandler &)=delete
BTaggingBoundsHandler & operator= (const BTaggingBoundsHandler &)=delete
virtual ~BTaggingBoundsHandler ()=default
std::vector< BTaggingToolUtil::varType > getListVariables () const
bool isJetWithinBounds (const xAOD::Jet &jet) const
bool overlaps (const BTaggingBoundsHandler &o) const
virtual std::string to_string () const
std::string onlyBounds_to_string () const

Static Public Member Functions

template<class handlerClass>
static void checkOverlaps (const std::string &context, const std::vector< handlerClass > &handlers)

Protected Member Functions

bool operator< (const BTaggingBoundsHandler &o) const
bool operator> (const BTaggingBoundsHandler &o) const
bool operator== (const BTaggingBoundsHandler &o) const
bool operator!= (const BTaggingBoundsHandler &o) const

Protected Attributes

JetQuantityGetter * m_funcGetJetQuantity = nullptr
std::map< BTaggingToolUtil::varType, varBounds > m_varBinBounds

Friends

template<class handlerClass>
class BTaggingGridBoundsHandler
std::ostream & operator<< (std::ostream &os, const BTaggingBoundsHandler &handler)

Detailed Description

Definition at line 35 of file BTaggingBoundsHandler.h.

Member Typedef Documentation

◆ JetQuantityGetter

◆ json

using BTaggingBoundsHandler::json = nlohmann::ordered_json

Definition at line 42 of file BTaggingBoundsHandler.h.

Constructor & Destructor Documentation

◆ BTaggingBoundsHandler() [1/3]

BTaggingBoundsHandler::BTaggingBoundsHandler ( const json & jsonConfig,
JetQuantityGetter * funcGetJetQuantity )

Definition at line 27 of file BTaggingBoundsHandler.cxx.

28 {
29
30 m_funcGetJetQuantity = funcGetJetQuantity;
31 // Make sure that the pointer to the function provided is valud
33 throw std::runtime_error("Jet quantity getter function is a null pointer for jsonConfig=" + jsonConfig.dump());
34 }
35
36 // Make sure the function that is held by the pointer has been defined
37 if ( !(*m_funcGetJetQuantity) ){
38 throw std::runtime_error("Jet quantity getter function points to a std::function that has not been initialized for jsonConfig=" + jsonConfig.dump());
39 }
40
41 // The BTaggingBoundsHandler expects a json configuration that contains an entry called "binVariables".
42 // The content that is not read by the BTaggingBoundsHandler can be stored in another entry e.g. called "content"
43 // For example:
44 // jsonConfig = { "binVariables": {"pT": [250, 300 ] , "mass": [50 , 75]}, "content": {"SF": 0.9, uncerts:{ "SF_uncert_1": 0.1, "SF_uncert_2": 0.03}} }
45 // The binVariables can contain several variables with [low, high) values specified
46
47 if (!jsonConfig.contains("binVariables")) {
48 throw std::runtime_error(
49 "jsonConfig does not contain binVariables entry jsonConfig=" + jsonConfig.dump());
50 }
51
52 // Retrieve binVariables
53 const auto &binVariables = jsonConfig["binVariables"];
54
55 // Make sure that binVariables it is not empty and that it is an array
56 if (binVariables.empty()){
57 throw std::runtime_error(
58 "binVariables entry is empty for jsonConfig=" + jsonConfig.dump());
59 }
60 if (!binVariables.is_object()){
61 throw std::runtime_error(
62 "binVariables entry is not an object for jsonConfig=" + jsonConfig.dump());
63 }
64
65 // Loop over entries from binVariables
66 // and retrieve corresponding min and max values for each variable
67 for (const auto& [varName, varBinRange] : binVariables.items()){
68 // Make sure that varBinRange is a list of [low, high] value
69 if (!varBinRange.is_array() || varBinRange.size() != 2) {
70 throw std::runtime_error(
71 "Bin range for varName='" + varName + "' must be [low, high] while varBinRange="+ varBinRange.dump() + " for jsonConfig=" + jsonConfig.dump());
72 }
73
74 // Retrieve variable type
76 try {
77 vType = BTaggingToolUtil::getVariableType( varName );
78 }
79 catch (const std::exception& e) {
80 // throw error
81 throw std::runtime_error("Could not retrieve variable type for varName='" + varName + "': " + e.what());
82 }
83
84 // Retrieve the corresponding bounds
85 varBounds vBounds;
86 vBounds.lowerBound = BTaggingToolUtil::getExtendedFloat(varBinRange[0]);
87 vBounds.upperBound = BTaggingToolUtil::getExtendedFloat(varBinRange[1]);
88
89 // Make sure that lowerBounds and upperBounds are not NaNs
90 if (!std::isfinite(vBounds.lowerBound)){
91 throw std::runtime_error(
92 "Bin issue lower bound is not a finite number for varName='" + varName +
93 "' while varBinRange="+ varBinRange.dump() + " for jsonConfig=" + jsonConfig.dump());
94 }
95 if (!std::isfinite(vBounds.upperBound)){
96 throw std::runtime_error(
97 "Bin issue upper bound is not a finite number for varName='" + varName +
98 "' while varBinRange="+ varBinRange.dump() + " for jsonConfig=" + jsonConfig.dump());
99 }
100
101 // Let's make sure that lowerBound < upperBound
102 if (vBounds.lowerBound >= vBounds.upperBound){
103 throw std::runtime_error(
104 "Bin issue, the min value >= max value for varName='" + varName +"': min=" + std::to_string(vBounds.lowerBound)+ ", max=" + std::to_string(vBounds.upperBound) + " for jsonConfig=" + jsonConfig.dump());
105 }
106
107 // Finally add the varBounds to the map of variable bounds
108 m_varBinBounds[vType] = vBounds;
109 }
110}
std::map< BTaggingToolUtil::varType, varBounds > m_varBinBounds
JetQuantityGetter * m_funcGetJetQuantity
static float getExtendedFloat(const nlohmann::json &config)
static varType getVariableType(const std::string &varName)

◆ BTaggingBoundsHandler() [2/3]

BTaggingBoundsHandler::BTaggingBoundsHandler ( BTaggingBoundsHandler && )
defaultnoexcept

◆ BTaggingBoundsHandler() [3/3]

BTaggingBoundsHandler::BTaggingBoundsHandler ( const BTaggingBoundsHandler & )
delete

◆ ~BTaggingBoundsHandler()

virtual BTaggingBoundsHandler::~BTaggingBoundsHandler ( )
virtualdefault

Member Function Documentation

◆ checkOverlaps()

template<class handlerClass>
void BTaggingBoundsHandler::checkOverlaps ( const std::string & context,
const std::vector< handlerClass > & handlers )
inlinestatic

Definition at line 77 of file BTaggingBoundsHandler.h.

77 {
78 for (size_t i = 0; i < handlers.size(); ++i) {
79 for (size_t j = i + 1; j < handlers.size(); ++j) {
80 if (handlers[i].overlaps(handlers[j])) {
81 throw std::runtime_error("Overlapping bins for " + context + ": " + handlers[i].to_string() + " and " + handlers[j].to_string());
82 }
83 }
84 }
85 }
bool overlaps(const BTaggingBoundsHandler &o) const
virtual std::string to_string() const
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ getListVariables()

std::vector< BTaggingToolUtil::varType > BTaggingBoundsHandler::getListVariables ( ) const

Definition at line 113 of file BTaggingBoundsHandler.cxx.

113 {
114 std::vector<BTaggingToolUtil::varType> varTypes;
115 for (const auto& itr : m_varBinBounds){
116 varTypes.push_back(itr.first);
117 }
118 return varTypes;
119}

◆ isJetWithinBounds()

bool BTaggingBoundsHandler::isJetWithinBounds ( const xAOD::Jet & jet) const

Definition at line 121 of file BTaggingBoundsHandler.cxx.

121 {
122 // Loop over all variables e.g. pT, eta etc
123 for (const auto& [vType, bounds] : m_varBinBounds) {
124 // For each variable get the corresponding jet value
125 // e.g. get the jet pT if the variable is pT
126 const float value = (*m_funcGetJetQuantity)(jet, vType);
127 // Check if the jet value is within the lower and upper bound defined for the bin
128 // e.g. check if jet pT is within pTmin and pTmax
129 // If not within those bounds then the jet is not falling in the bin
130 // thus return false
131 if (value < bounds.lowerBound || value >= bounds.upperBound) {
132 return false;
133 }
134 }
135 // If reaching this point it means the jet is falling into the bin
136 // Hence returning true
137 return true;
138}

◆ onlyBounds_to_string()

std::string BTaggingBoundsHandler::onlyBounds_to_string ( ) const

Definition at line 140 of file BTaggingBoundsHandler.cxx.

140 {
141 std::ostringstream os;
142 // Add the list of variables with lower and upper bounds
143 // e.g. "pT: [250, 500], mass: [50, 100]"
144 // The separator ", " is only added between entries, not after the last one
145 bool first = true;
146 for (const auto& [vType, bounds] : m_varBinBounds) {
147 if (!first) os << ", ";
148 first = false;
149 os << BTaggingToolUtil::getVariableName(vType) << ": [" << bounds.lowerBound << ", " << bounds.upperBound << "]";
150 }
151 return os.str();
152}
static std::string getVariableName(const varType vType)
bool first
Definition DeMoScan.py:534

◆ operator!=()

bool BTaggingBoundsHandler::operator!= ( const BTaggingBoundsHandler & o) const
inlineprotected

Definition at line 141 of file BTaggingBoundsHandler.h.

141{ return !(*this == o); }

◆ operator<()

bool BTaggingBoundsHandler::operator< ( const BTaggingBoundsHandler & o) const
protected

Definition at line 160 of file BTaggingBoundsHandler.cxx.

160 {
161 // Ordering of handlers loop over variables as stored in the map
162 // and let the first variable whose bounds differ decide of the ordering
163
164 // Make sure maps have the same size
165 if (m_varBinBounds.size() != o.m_varBinBounds.size()) {
166 throw std::logic_error("Cannot compare handlers with a different number of variables: " + this->to_string() + " versus " + o.to_string() );
167 }
168
169 // Make sure that the function used to retrieve the jet quantities is also the same
170 // We do not want to have two handlers with different functions
171 // as they may then return different jet quantities e.g. imagine one handler
172 // is returning the regular jet pT while the other one returns the regressed jet pT
173 // that would imply migration and so we cannot ensure orthogonality in that case
175 throw std::logic_error("Cannot compare handlers with a different jet quantity getter function: " + this->to_string() + " versus " + o.to_string() );
176 }
177
178 // Loop over the different variables bounds and compare
179 for (const auto& [vType, vBounds1] : m_varBinBounds) {
180 // Make sure the other handler has the same variable
181 const auto it = o.m_varBinBounds.find(vType);
182 if (it == o.m_varBinBounds.end()) {
183 throw std::logic_error("Cannot compare handlers: variable '" + BTaggingToolUtil::getVariableName(vType) +
184 "' missing in the other handler");
185 }
186 const varBounds& vBounds2 = it->second;
187 // First variable whose bounds differ decides the ordering
188 if (!(vBounds1 == vBounds2)) return vBounds1 < vBounds2;
189 }
190 return false; // all bounds equal
191}

◆ operator=() [1/2]

BTaggingBoundsHandler & BTaggingBoundsHandler::operator= ( BTaggingBoundsHandler && )
defaultnoexcept

◆ operator=() [2/2]

BTaggingBoundsHandler & BTaggingBoundsHandler::operator= ( const BTaggingBoundsHandler & )
delete

◆ operator==()

bool BTaggingBoundsHandler::operator== ( const BTaggingBoundsHandler & o) const
inlineprotected

Definition at line 140 of file BTaggingBoundsHandler.h.

140{ return !(*this < o) && !(*this > o); }

◆ operator>()

bool BTaggingBoundsHandler::operator> ( const BTaggingBoundsHandler & o) const
inlineprotected

Definition at line 137 of file BTaggingBoundsHandler.h.

137{ return o < *this; }

◆ overlaps()

bool BTaggingBoundsHandler::overlaps ( const BTaggingBoundsHandler & o) const

Definition at line 193 of file BTaggingBoundsHandler.cxx.

193 {
194 // Two handlers that are N-dimensional bins overlap if
195 // for every variable their bounds overlap
196 // If for one variable there is no overlapping bounds then the bins are not overlapping
197
198 // Make sure maps have the same size
199 if (m_varBinBounds.size() != o.m_varBinBounds.size()) {
200 throw std::logic_error("Cannot check overlap of handlers with a different number of variables: " + this->to_string() + " versus " + o.to_string() );
201 }
202
203 // Make sure that the function used to retrieve the jet quantities is also the same
204 // We do not want to have two handlers with different functions
205 // as they may then return different jet quantities e.g. imagine one handler
206 // is returning the regular jet pT while the other one returns the regressed jet pT
207 // that would imply migration and so we cannot ensure orthogonality in that case
209 throw std::logic_error("Cannot compare handlers with a different jet quantity getter function: " + this->to_string() + " versus " + o.to_string() );
210 }
211
212 // Loop over the different variables bounds and check the overlap
213 for (const auto& [vType, vBounds1] : m_varBinBounds) {
214 // Make sure the other handler has the same variable
215 const auto it = o.m_varBinBounds.find(vType);
216 if (it == o.m_varBinBounds.end()) {
217 throw std::logic_error("Cannot check overlap of handlers: variable '" + BTaggingToolUtil::getVariableName(vType) +
218 "' missing in the other handler");
219 }
220 // If bounds do not overlap for one variable then bins do not overlap
221 if (!vBounds1.overlaps(it->second)) return false;
222 }
223 // Bounds overlap for all variables
224 // so handlers have some overlap
225 return true;
226}

◆ to_string()

std::string BTaggingBoundsHandler::to_string ( ) const
virtual

Reimplemented in BTaggingLargeREfficiencyJsonTool::LargeRMCMCHandler.

Definition at line 154 of file BTaggingBoundsHandler.cxx.

154 {
155 std::ostringstream os;
156 os << "BTaggingBoundsHandler(" << onlyBounds_to_string() << ")";
157 return os.str();
158}
std::string onlyBounds_to_string() const

◆ BTaggingGridBoundsHandler

template<class handlerClass>
friend class BTaggingGridBoundsHandler
friend

Definition at line 37 of file BTaggingBoundsHandler.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const BTaggingBoundsHandler & handler )
friend

Definition at line 67 of file BTaggingBoundsHandler.h.

67{ return (os << handler.to_string()); }
void handler(int sig)
signal handler
Definition rmain.cxx:100

Member Data Documentation

◆ m_funcGetJetQuantity

JetQuantityGetter* BTaggingBoundsHandler::m_funcGetJetQuantity = nullptr
protected

Definition at line 89 of file BTaggingBoundsHandler.h.

◆ m_varBinBounds

std::map<BTaggingToolUtil::varType, varBounds> BTaggingBoundsHandler::m_varBinBounds
protected

Definition at line 132 of file BTaggingBoundsHandler.h.


The documentation for this class was generated from the following files: