ATLAS Offline Software
Loading...
Searching...
No Matches
BTaggingGridBoundsHandler< handlerClass > Class Template Reference

#include <BTaggingGridBoundsHandler.h>

Collaboration diagram for BTaggingGridBoundsHandler< handlerClass >:

Public Member Functions

 BTaggingGridBoundsHandler (const std::string &context, std::vector< handlerClass > &&handlers)
BTaggingGridBoundsHandler & operator= (BTaggingGridBoundsHandler &&) noexcept=default
 BTaggingGridBoundsHandler (BTaggingGridBoundsHandler &&) noexcept=default
 BTaggingGridBoundsHandler (const BTaggingGridBoundsHandler &)=delete
BTaggingGridBoundsHandler & operator= (const BTaggingGridBoundsHandler &)=delete
 ~BTaggingGridBoundsHandler ()=default
const handlerClass * getHandlerPtr (const xAOD::Jet &jet) const

Private Attributes

std::vector< handlerClass > m_handlers
std::vector< BTaggingToolUtil::varType > m_varTypes
BTaggingBoundsHandler::JetQuantityGetter * m_funcGetJetQuantity = nullptr
std::map< BTaggingToolUtil::varType, std::map< BTaggingBoundsHandler::varBounds, std::set< const handlerClass * >, std::less<> > > m_varBoundsSetHandlers

Detailed Description

template<class handlerClass>
class BTaggingGridBoundsHandler< handlerClass >

Definition at line 23 of file BTaggingGridBoundsHandler.h.

Constructor & Destructor Documentation

◆ BTaggingGridBoundsHandler() [1/3]

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

Definition at line 67 of file BTaggingGridBoundsHandler.h.

69{
70 // If the vector of handler is empty raise error
71 if (m_handlers.empty()){
72 throw std::runtime_error("Vector of handlers provided is empty for context=" + context);
73 }
74
75 // Check there is no overlap between the handlers
76 // This check also ensures that the same variables
77 // are used acrross the handlers provided
78 try {
80 }
81 catch (const std::exception& e) {
82 throw std::runtime_error("Handler overlap issue found, " + std::string(e.what()));
83 }
84
85 // Get the list of variables used by the handlers.
86 // Since the same variables are used for all handlers (check done in the overlap check above)
87 // retrieve that list from the first handler in the vector
88 // It has been checked above the vector is never empty
89 m_varTypes = m_handlers.at(0).getListVariables();
90
91 // Get the jet quantity function
92 // The overlap check above ensures that the function that returns the jet quantity is the same
93 // accross all handlers hence retrieving it from the first handler
94 m_funcGetJetQuantity = m_handlers.at(0).m_funcGetJetQuantity;
95
96 // For sanity check let's make sure that this function is not a null pointer
97 // and it points to a function that has been initialized
99 throw std::runtime_error("Function to get jet quantity is either a null pointer or points to std::function that has not been initialized for context=" + context);
100 }
101
102
103 // Now we want to group handlers by bounds range for each variable
104 // so the matching jet-handler will be faster in the getHandlerPtr function
105 // Loop over each variable
107
108 // For each variable the varBounds vector
109 // will contains the bounds corresponding to the current variable
110 // for all handler
112
113 // Get epsilon value for float comparison from the first handler for the current variable
114 // The epsilon value should in any case be the same for all handlers
115 float varEps = m_handlers.at(0).m_varBinBounds.at(vType).varEps;
116
117 // Loop over each handler
118 for (const handlerClass& handler : m_handlers){
119 // // For debugging print the handler
120 // std::cout << "handler=" << handler << std::endl;
121
122 // Retrieve the lower and upper bounds associated to the current variable and current handler
123 const BTaggingBoundsHandler::varBounds & hdlrBounds = handler.m_varBinBounds.at(vType);
124 float lowerBound = hdlrBounds.lowerBound;
125 float upperBound = hdlrBounds.upperBound;
126
127 // // For debugging print information
128 // std::cout << "varName=" << BTaggingToolUtil::getVariableName(vType) << ", lowerBound=" << lowerBound << ", upperBound=" << upperBound << std::endl;
129 bool addLowerBound = true;
130 bool addUpperBound = true;
131 // Loop over values already in varBounds
132 for (const float &value: varBounds){
133 // Only do the check if the value is still considered to be added
134 // NB: lowerBound and upperBound are ensured to be different thanks to the handler checks
136 // It means that lowerBound and the current value are the same
137 // here using approxEqual as comparing two floats
138 // so the lowerBound value is already in the varBounds vector
139 // and thus should not be added
140 addLowerBound = false;
141 }
142 // Same reasoning as above but for the upper bound
144 addUpperBound = false;
145 }
146
147 // If both lower and upper bound should not be added
148 // exist this loop there is no point on continuing
149 if (!addLowerBound && !addUpperBound){ break ; }
150 }
151 // If addLowerBound is still true it means that lowerBound value
152 // it not found in the vector thus add it
153 // otherwise do nothing
154 if (addLowerBound){
155 varBounds.push_back(lowerBound);
156 }
157 // Same reasoning but for the upperBound value
158 if (addUpperBound){
159 varBounds.push_back(upperBound);
160 }
161 }
162 // Once having processed all handlers
163 // then sort the varBounds vector by increasing values
164 std::sort(varBounds.begin(), varBounds.end());
165 // For debugging
166 // std::cout << "varName=" << BTaggingToolUtil::getVariableName(vType) << ", varBounds=" << std::format("{}", varBounds) << std::endl;
167
168 // Now loop over the sorted vector
169 for (unsigned int i = 0; i < varBounds.size() - 1; i++){
170 // Build the corresponding varBounds
172 bounds.lowerBound = varBounds[i];
173 bounds.upperBound = varBounds[i+1];
174 bounds.varEps = varEps;
175
176 // For sanity check make sure that lowerBound is strictly smaller than upperBound
177 if (bounds.lowerBound >= bounds.upperBound){
178 throw std::runtime_error("bounds.lowerBound >= bounds.upperBound for context=" + context);
179 }
180
182 // Loop again over handlers
183 for (const handlerClass& handler : m_handlers){
184 // Retrieve the bounds of the current handler for the current variable
185 const BTaggingBoundsHandler::varBounds & hdlrBounds = handler.m_varBinBounds.at(vType);
186
187 // If there is an overlap between the bounds of the handler and the current bound that was just built
188 // it means the handler covers the current bounds range
189 // hence add the pointer to the handler to the set as the handler should be considered for that current bound
190 // Otherwise the handler does not corresponds to the current bounds
191 if (hdlrBounds.overlaps(bounds)){
192 handlerSet.insert( &handler );
193 }
194 }
195
196 // If the set of handler overlapping with the current bound
197 // is not empty then add that set to the map
198 if (handlerSet.size()){
200 // // For debugging
201 // std::cout << "varName=" << BTaggingToolUtil::getVariableName(vType) << ", bounds(lowerBounds, upperBound)=("<< bounds.lowerBound << ", " << bounds.upperBound << "): " ;
202 // // Iterate over the set
203 // bool firstHandler = true;
204 // for (const handlerClass *handler : m_varBoundsSetHandlers[vType][bounds]){
205 // if (!firstHandler){
206 // std::cout << ", ";
207 // }
208 // firstHandler = false;
209 // // Print handler content
210 // std::cout << (*handler);
211 // }
212 // std::cout << std::endl;
213 }
214 }
215 }
216}
static void checkOverlaps(const std::string &context, const std::vector< handlerClass > &handlers)
BTaggingBoundsHandler::JetQuantityGetter * m_funcGetJetQuantity
std::vector< handlerClass > m_handlers
std::map< BTaggingToolUtil::varType, std::map< BTaggingBoundsHandler::varBounds, std::set< const handlerClass * >, std::less<> > > m_varBoundsSetHandlers
std::vector< BTaggingToolUtil::varType > m_varTypes
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ BTaggingGridBoundsHandler() [2/3]

template<class handlerClass>
BTaggingGridBoundsHandler< handlerClass >::BTaggingGridBoundsHandler ( BTaggingGridBoundsHandler< handlerClass > && )
defaultnoexcept

◆ BTaggingGridBoundsHandler() [3/3]

template<class handlerClass>
BTaggingGridBoundsHandler< handlerClass >::BTaggingGridBoundsHandler ( const BTaggingGridBoundsHandler< handlerClass > & )
delete

◆ ~BTaggingGridBoundsHandler()

template<class handlerClass>
BTaggingGridBoundsHandler< handlerClass >::~BTaggingGridBoundsHandler ( )
default

Member Function Documentation

◆ getHandlerPtr()

template<class handlerClass>
const handlerClass * BTaggingGridBoundsHandler< handlerClass >::getHandlerPtr ( const xAOD::Jet & jet) const

Definition at line 219 of file BTaggingGridBoundsHandler.h.

220{
221
222 // Perform the matching between the jet and the corresponding handler
223 // See MR https://gitlab.cern.ch/atlas/athena/-/merge_requests/92635
224 // for more explanation
225
226 bool firstVar = true;
228
229 // Loop over each variable
231 // Retrieve the corresponding jet value
232 // e.g. the jet pT, mass, absolute eta or so
233 const float jetValue = (*m_funcGetJetQuantity)(jet, vType);
234
235 // Find the set of handlers that are corresponding to the current jet value
236 // i.e. the set associated to the varBounds such that lowerBound <= jetValue < upperBound
237 // If the jet value falls outside of all bounds (out of range or in a hole)
238 // then no handler can match the jet
239 const auto itBounds = m_varBoundsSetHandlers.at(vType).find(jetValue);
240 if (itBounds == m_varBoundsSetHandlers.at(vType).end()){
241 // Jet value is out of bound there is no matching handler
242 // thus return a null pointer
243 return nullptr;
244 }
245
246 if (firstVar){
247 // If it's the first variable
248 // Simply copy the set of handlers matching the jet value
250 firstVar = false;
251 }
252 else {
253 // If it is not the first variable
254 // handlersSetMatchingJetValues contains the
255 // the list of pointers to handlers whose bounds
256 // correspond to the jet values of the variables processed so far
257 // The currentSet contains the list of handler pointers whose bounds
258 // contain the jet value corresponding to the current variable.
259 // Hence only keep the handlers present in both sets i.e. the intersection
260 // such that handlersSetMatchingJetValues is the list of handler pointers
261 // matching the jet values for all variables processed up to now
262 // including the current one
263
268 currentSet.begin(), currentSet.end(),
269 std::inserter(tmp, tmp.begin())
270 );
271
272 // So in the end handlersSetMatchingJetValues only contains
273 // the result of the intersection
275 }
276
277 if (!handlersSetMatchingJetValues.size()){
278 // The jet values make the jet out of bound
279 // thus return a null pointer
280 return nullptr;
281 }
282 }
283
284 // If arriving here it means a match was found between an handler and the jet provided
285 // otherwise a null pointer would have been returned earlier
286 // There can only be one handler matching the jet as there is no overlap between handlers
287 // If that's not the case there is a fundamental logical issue with the implementation of the current class
288 // and so we should absolutely raise an error
289 if (handlersSetMatchingJetValues.size() != 1){
290 throw std::runtime_error("handlersSetMatchingJetValues size is not 1, there is a fundamental logic issue in the BTaggingGridBoundsHandler class");
291 }
292
293 // If arriving here all good we have only one handler in the set
294 // retrieve it and return the pointer to that handler
295 // that is matching the jet
297 return handler;
298}

◆ operator=() [1/2]

template<class handlerClass>
BTaggingGridBoundsHandler & BTaggingGridBoundsHandler< handlerClass >::operator= ( BTaggingGridBoundsHandler< handlerClass > && )
defaultnoexcept

◆ operator=() [2/2]

template<class handlerClass>
BTaggingGridBoundsHandler & BTaggingGridBoundsHandler< handlerClass >::operator= ( const BTaggingGridBoundsHandler< handlerClass > & )
delete

Member Data Documentation

◆ m_funcGetJetQuantity

template<class handlerClass>
BTaggingBoundsHandler::JetQuantityGetter* BTaggingGridBoundsHandler< handlerClass >::m_funcGetJetQuantity = nullptr
private

Definition at line 54 of file BTaggingGridBoundsHandler.h.

◆ m_handlers

template<class handlerClass>
std::vector<handlerClass> BTaggingGridBoundsHandler< handlerClass >::m_handlers
private

Definition at line 49 of file BTaggingGridBoundsHandler.h.

◆ m_varBoundsSetHandlers

template<class handlerClass>
std::map<BTaggingToolUtil::varType, std::map<BTaggingBoundsHandler::varBounds, std::set<const handlerClass*>, std::less<> > > BTaggingGridBoundsHandler< handlerClass >::m_varBoundsSetHandlers
private

Definition at line 63 of file BTaggingGridBoundsHandler.h.

◆ m_varTypes

template<class handlerClass>
std::vector<BTaggingToolUtil::varType> BTaggingGridBoundsHandler< handlerClass >::m_varTypes
private

Definition at line 52 of file BTaggingGridBoundsHandler.h.


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