ATLAS Offline Software
Loading...
Searching...
No Matches
Trk::BinningData Class Referencefinal

This class holds all the data necessary for the bin calculation. More...

#include <BinningData.h>

Collaboration diagram for Trk::BinningData:

Public Member Functions

 BinningData (const BinningData &)=default
 BinningData (BinningData &&)=default
BinningDataoperator= (const BinningData &)=default
BinningDataoperator= (BinningData &&)=default
 ~BinningData ()=default
 BinningData (BinningType bType, BinningOption bOption, BinningValue bValue, size_t bBins, float bMin, float bMax, float bStep, float bSubStep=0, std::vector< float > bBoundaries=std::vector< float >())
 Constructor with arguments.
 BinningData (BinningOption bOption, float bRefPhi, const std::vector< std::pair< int, float > > &bBoundaries)
 Constructor for binH type : non-equidistant binning assumed.
float value (const Amg::Vector2D &lposition) const
 take the right float value - assumes the correct local position expression
float value (const Amg::Vector3D &position) const
 take the right float value
float gaugePhi (float phi) const
 gauge phi
std::pair< float, float > valueH (const Amg::Vector2D &lposition) const
 take float values for binH
std::pair< float, float > valueH (const Amg::Vector3D &position) const
 take float values for binH
bool inside (const Amg::Vector3D &position) const
 Check if bin is inside from Vector3D.
bool inside (const Amg::Vector2D &lp) const
 Check if bin is inside from Vector2D.
size_t searchLocal (const Amg::Vector2D &lposition) const
 generic search from a 2D position — corresponds to local coordinate schema
size_t searchGlobal (const Amg::Vector3D &position) const
 generic search from a 3D position
size_t search (float value) const
 generic search - forwards to correct function pointer
size_t searchH (std::pair< double, double > value) const
 generic search - forwards to correct function pointer
size_t entry (const Amg::Vector3D &position) const
 the entry bin
size_t next (const Amg::Vector3D &position, const Amg::Vector3D &dir) const
 the next bin : gives -1 if the next one is outside
std::pair< size_t, float > distanceToNext (const Amg::Vector3D &position, const Amg::Vector3D &dir) const
 distance to the next bin : gives -1 if the next one is outside
LayerOrder orderDirection (const Amg::Vector3D &position, const Amg::Vector3D &dir) const
 layer order is needed for value H binning
float binPosition (size_t bin, float pos) const
 bin->BinningValue navigation : pos=+-1.

Public Attributes

BinningType type
 holding all the data for binning calculatuion
BinningOption option
BinningValue binvalue
size_t bins
float min
float max
float step
float subStep
float refphi
std::vector< float > boundaries
std::vector< std::pair< int, float > > hbounds

Static Private Member Functions

static size_t searchEaquidstantWithBoundary (float value, const BinningData &bData)
 Equidistant search : equidist 0.
static size_t searchBiequidistantWithBoundary (float value, const BinningData &bData)
 Biequidistant search : biequidist 1.
static size_t searchInVectorWithBoundary (float value, const BinningData &bData)
 Linear search in vector - superior in O(10) searches: arbitraty 2.
static size_t binarySearchWithBoundary (float value, const BinningData &bData)
 A binary search with underflow/overflow - faster than vector search for O(50) objects.
static size_t searchInVectorWithMixedBoundary (std::pair< float, float > val, const BinningData &bData)
 Search in mixed vector - linear in O-10 bins, otherwise binary.

Private Attributes

size_t(* m_functionPtr )(float, const BinningData &)
 the pointer to the function to be used
size_t(* m_mixPtr )(std::pair< float, float >, const BinningData &)

Detailed Description

This class holds all the data necessary for the bin calculation.

phi has a very particular behaviour:

  • there's the change around +/- PI
Author
Andreas.Salzburger @ cern.ch, Sharka.Todorova @ cern.ch

Definition at line 48 of file BinningData.h.

Constructor & Destructor Documentation

◆ BinningData() [1/4]

Trk::BinningData::BinningData ( const BinningData & )
default

◆ BinningData() [2/4]

Trk::BinningData::BinningData ( BinningData && )
default

◆ ~BinningData()

Trk::BinningData::~BinningData ( )
default

◆ BinningData() [3/4]

Trk::BinningData::BinningData ( BinningType bType,
BinningOption bOption,
BinningValue bValue,
size_t bBins,
float bMin,
float bMax,
float bStep,
float bSubStep = 0,
std::vector< float > bBoundaries = std::vector<float>() )
inline

Constructor with arguments.

Definition at line 72 of file BinningData.h.

81 : type(bType)
82 , option(bOption)
83 , binvalue(bValue)
84 , bins(bBins)
85 , min(bMin)
86 , max(bMax)
87 , step(bStep != 0. ? bStep : 1.)
88 , subStep(bSubStep)
89 , refphi(0.)
90 , boundaries(std::move(bBoundaries))
91 , hbounds(std::vector<std::pair<int, float>>())
92 , m_mixPtr(nullptr)
93 {
94 if (bType == Trk::equidistant)
96 else if (bType == Trk::biequidistant)
98 else
100 }
std::vector< float > boundaries
Definition BinningData.h:61
static size_t binarySearchWithBoundary(float value, const BinningData &bData)
A binary search with underflow/overflow - faster than vector search for O(50) objects.
BinningOption option
Definition BinningData.h:53
size_t(* m_functionPtr)(float, const BinningData &)
the pointer to the function to be used
BinningValue binvalue
Definition BinningData.h:54
std::vector< std::pair< int, float > > hbounds
Definition BinningData.h:62
size_t(* m_mixPtr)(std::pair< float, float >, const BinningData &)
static size_t searchInVectorWithBoundary(float value, const BinningData &bData)
Linear search in vector - superior in O(10) searches: arbitraty 2.
BinningType type
holding all the data for binning calculatuion
Definition BinningData.h:52
static size_t searchEaquidstantWithBoundary(float value, const BinningData &bData)
Equidistant search : equidist 0.
static size_t searchBiequidistantWithBoundary(float value, const BinningData &bData)
Biequidistant search : biequidist 1.
@ biequidistant
Definition BinningType.h:33
@ equidistant
Definition BinningType.h:32

◆ BinningData() [4/4]

Trk::BinningData::BinningData ( BinningOption bOption,
float bRefPhi,
const std::vector< std::pair< int, float > > & bBoundaries )
inline

Constructor for binH type : non-equidistant binning assumed.

Definition at line 103 of file BinningData.h.

107 , option(bOption)
109 , bins(bOption == Trk::open ? bBoundaries.size() - 1 : bBoundaries.size())
110 , min(bBoundaries.front().second)
111 , max(bBoundaries.back().second)
112 , step(1.)
113 , subStep(0.) // non-zero value needed for next()
114 , refphi(bRefPhi)
115 , boundaries(std::vector<float>())
116 , hbounds(bBoundaries)
117 , m_functionPtr(nullptr)
119 {}
static size_t searchInVectorWithMixedBoundary(std::pair< float, float > val, const BinningData &bData)
Search in mixed vector - linear in O-10 bins, otherwise binary.
@ open
Definition BinningType.h:40
@ arbitrary
Definition BinningType.h:34
@ binH
Definition BinningType.h:53

Member Function Documentation

◆ binarySearchWithBoundary()

size_t Trk::BinningData::binarySearchWithBoundary ( float value,
const BinningData & bData )
inlinestaticprivate

A binary search with underflow/overflow - faster than vector search for O(50) objects.

Definition at line 394 of file BinningData.h.

395 {
396 if (bData.boundaries.empty())[[unlikely]]{
397 throw std::runtime_error("binarySearchWithBoundary: boundaries vector is empty.");
398 }
399 // Binary search in an array of n values to locate value
400 if (bData.binvalue == binPhi)
401 while (value < bData.boundaries[0])
402 value += 2.f * std::numbers::pi_v<float>;
403 if (bData.binvalue == binPhi)
404 while (value > bData.max)
405 value -= 2.f * std::numbers::pi_v<float>;
406 // underflow
407 if (value <= bData.boundaries[0])
408 return (bData.option == closed) ? (bData.bins - 1) : 0;
409 // overflow
410 if (value >= bData.max)
411 return (bData.option == closed) ? 0 : bData.boundaries.size() - 1;
412 const auto it = std::ranges::upper_bound(bData.boundaries, value);
413 return std::distance(bData.boundaries.begin(), it) - 1;
414 }
float value(const Amg::Vector2D &lposition) const
take the right float value - assumes the correct local position expression
@ closed
Definition BinningType.h:41
@ binPhi
Definition BinningType.h:51
#define unlikely(x)

◆ binPosition()

float Trk::BinningData::binPosition ( size_t bin,
float pos ) const
inline

bin->BinningValue navigation : pos=+-1.

edges/ 0. bin center

Definition at line 307 of file BinningData.h.

308 {
309
310 if (type == Trk::equidistant)
311 return (min + (2. * bin + pos + 1.) * step / 2.);
312
313 float bmin = (binvalue == Trk::binH) ? hbounds[bin].second : boundaries[bin];
314 float bmax = (binvalue == Trk::binH) ? hbounds[bin + 1].second
315 : bin + 1 < boundaries.size() ? boundaries[bin + 1] : boundaries[bin] + step;
316
317 return (bmin + 0.5 * (pos + 1.) * (bmax - bmin));
318 }
size_t size() const
Number of registered mappings.

◆ distanceToNext()

std::pair< size_t, float > Trk::BinningData::distanceToNext ( const Amg::Vector3D & position,
const Amg::Vector3D & dir ) const
inline

distance to the next bin : gives -1 if the next one is outside

Definition at line 252 of file BinningData.h.

253 {
254 // current value
255 float val = (binvalue == Trk::binH) ? valueH(position).first : value(position);
256 // probe value
257 Amg::Vector3D probe = position + 0.5 * step * dir.normalized();
258 float nextval = (binvalue == Trk::binH) ? valueH(probe).first : value(probe);
259 // current bin
260 int bin0 = (binvalue == Trk::binH) ? searchH(valueH(position)) : search(val);
261 // next bin
262 int bin = (nextval - val) > 0. ? bin0 + 1 : bin0 - 1;
263 if (bin > int(bins) - 1)
264 bin = (option == closed) ? 0 : bin0;
265 if (bin < 0)
266 bin = (option == closed) ? bins - 1 : 0;
267
268 // boundary value
269 float bval = 0.;
270 if (binvalue == Trk::binH) {
271 bval = (nextval > val) ? hbounds[bin0 + 1].second : hbounds[bin0].second; // non-equidistant
272
273 // may need to recalculate current value and probe
274 if (nextval > val) {
275 if (hbounds[bin0 + 1].first > 0) {
276 val = valueH(position).second;
277 nextval = valueH(probe).second;
278 }
279 } else {
280 if (hbounds[bin0].first > 0) {
281 val = valueH(position).second;
282 nextval = valueH(probe).second;
283 }
284 }
285 } else {
286 bval = (nextval > val) ? boundaries[bin0 + 1] : boundaries[bin0]; // non-equidistant
287 if (type == Trk::equidistant)
288 bval = min + bin0 * step;
289 }
290 // differential
291 float dd = 2 * (nextval - val) / step;
292 // distance estimate
293 float dist = std::fabs(dd) > 1.e-06 ? (bval - val) / dd : 1.e06;
294 return std::pair<size_t, float>(bin, dist);
295 }
std::pair< float, float > valueH(const Amg::Vector2D &lposition) const
take float values for binH
size_t searchH(std::pair< double, double > value) const
generic search - forwards to correct function pointer
size_t search(float value) const
generic search - forwards to correct function pointer
Eigen::Matrix< double, 3, 1 > Vector3D
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.

◆ entry()

size_t Trk::BinningData::entry ( const Amg::Vector3D & position) const
inline

the entry bin

Definition at line 230 of file BinningData.h.

231 {
233 return (bin < bins - bin) ? bin : bins - 1;
234 }

◆ gaugePhi()

float Trk::BinningData::gaugePhi ( float phi) const
inline

gauge phi

Definition at line 149 of file BinningData.h.

150 {
151 if (max > M_PI && phi < min && phi < 0.) {
152 phi = M_PI + phi;
153 phi += M_PI;
154 }
155 return phi;
156 }
#define M_PI
@ phi
Definition ParamDefs.h:75

◆ inside() [1/2]

bool Trk::BinningData::inside ( const Amg::Vector2D & lp) const
inline

Check if bin is inside from Vector2D.

Definition at line 189 of file BinningData.h.

190 {
191 if (option == Trk::closed)
192 return true;
193 if (binvalue != Trk::binH) {
194 float val = value(lp);
195 return (val > min - 0.001 && val < max + 0.001);
196 }
197 std::pair<double, double> valH = valueH(lp);
198 float valmin = hbounds.front().first == 0 ? valH.first : valH.second;
199 float valmax = hbounds.back().first == 0 ? valH.first : valH.second;
200 return (valmin > min - 0.001 && valmax < max + 0.001);
201 }

◆ inside() [2/2]

bool Trk::BinningData::inside ( const Amg::Vector3D & position) const
inline

Check if bin is inside from Vector3D.

Definition at line 171 of file BinningData.h.

172 {
173 // closed one is always inside
174 if (option == Trk::closed)
175 return true;
176 // all other options except value H
177 if (binvalue != Trk::binH) {
178 float val = value(position);
179 return (val > min - 0.001 && val < max + 0.001);
180 }
181 // value H case
182 std::pair<double, double> valH = valueH(position);
183 float valmin = hbounds.front().first == 0 ? valH.first : valH.second;
184 float valmax = hbounds.back().first == 0 ? valH.first : valH.second;
185 return (valmin > min - 0.001 && valmax < max + 0.001);
186 }

◆ next()

size_t Trk::BinningData::next ( const Amg::Vector3D & position,
const Amg::Vector3D & dir ) const
inline

the next bin : gives -1 if the next one is outside

Definition at line 237 of file BinningData.h.

238 {
239 float val = value(position);
240 Amg::Vector3D probe = position + 0.5 * step * dir.normalized();
241 float nextval = value(probe);
242 int bin = (binvalue == Trk::binH) ? searchH(valueH(position)) : search(val);
243 bin = (nextval > val && bin != int(bins - 1)) ? bin + 1 : (bin) ? bin - 1 : 0;
244 // closed setup
245 if (option == closed)
246 return (bin < 0 || bin + 1 > int(bins)) ? ((bin < 0) ? bins - 1 : 0) : bin;
247 // open setup
248 return bin;
249 }

◆ operator=() [1/2]

BinningData & Trk::BinningData::operator= ( BinningData && )
default

◆ operator=() [2/2]

BinningData & Trk::BinningData::operator= ( const BinningData & )
default

◆ orderDirection()

LayerOrder Trk::BinningData::orderDirection ( const Amg::Vector3D & position,
const Amg::Vector3D & dir ) const
inline

layer order is needed for value H binning

Definition at line 298 of file BinningData.h.

299 {
300 float val = (binvalue == Trk::binH) ? valueH(position).first : value(position);
301 Amg::Vector3D probe = position + 0.5 * step * dir.normalized();
302 float nextval = (binvalue == Trk::binH) ? valueH(probe).first : value(probe);
303 return (nextval > val) ? Trk::next : Trk::previous;
304 }
@ next
Definition BinningData.h:35
@ previous
Definition BinningData.h:34

◆ search()

size_t Trk::BinningData::search ( float value) const
inline

generic search - forwards to correct function pointer

Definition at line 216 of file BinningData.h.

217 {
218 assert(m_functionPtr != nullptr);
219 return (*m_functionPtr)(value, *this);
220 }

◆ searchBiequidistantWithBoundary()

size_t Trk::BinningData::searchBiequidistantWithBoundary ( float value,
const BinningData & bData )
inlinestaticprivate

Biequidistant search : biequidist 1.

Definition at line 342 of file BinningData.h.

343 {
344 // the easy exits (first / last)
345 if (value < bData.min)
346 return (bData.option == closed) ? (bData.bins - 1) : 0;
347 if (value > bData.max)
348 return (bData.option == closed) ? 0 : (bData.bins - 1);
349 // special treatment for first and last bin
350 if (value > bData.max - bData.step)
351 return bData.bins - 1;
352 // decide the leading bin number (low leading bin)
353 size_t leadbin = int((value - bData.min) / bData.step);
354 float bDist = value - (bData.min + (leadbin + 1) * bData.step);
355 int addon = int(bDist / bData.subStep) ? 0 : 1;
356 // return the bin
357 return leadbin * 2 + addon;
358 }

◆ searchEaquidstantWithBoundary()

size_t Trk::BinningData::searchEaquidstantWithBoundary ( float value,
const BinningData & bData )
inlinestaticprivate

Equidistant search : equidist 0.

Definition at line 326 of file BinningData.h.

327 {
328 int bin = ((value - bData.min) / bData.step);
329 // special treatment of the 0 bin for closed
330 if (bData.option == closed) {
331 if (value < bData.min)
332 return (bData.bins - 1);
333 if (value > bData.max)
334 return 0;
335 }
336 // if outside boundary : return boundary for open, opposite bin for closed
337 bin = bin < 0 ? ((bData.option == Trk::open) ? 0 : (bData.bins - 1)) : bin;
338 return size_t((bin <= int(bData.bins - 1)) ? bin : ((bData.option == open) ? (bData.bins - 1) : 0));
339 }

◆ searchGlobal()

size_t Trk::BinningData::searchGlobal ( const Amg::Vector3D & position) const
inline

generic search from a 3D position

Definition at line 210 of file BinningData.h.

211 {
213 }

◆ searchH()

size_t Trk::BinningData::searchH ( std::pair< double, double > value) const
inline

generic search - forwards to correct function pointer

Definition at line 223 of file BinningData.h.

224 {
225 assert(m_mixPtr != nullptr);
226 return (*m_mixPtr)(value, *this);
227 }

◆ searchInVectorWithBoundary()

size_t Trk::BinningData::searchInVectorWithBoundary ( float value,
const BinningData & bData )
inlinestaticprivate

Linear search in vector - superior in O(10) searches: arbitraty 2.

Definition at line 361 of file BinningData.h.

362 {
363 if (bData.boundaries.empty())[[unlikely]]{
364 throw std::runtime_error("searchInVectorWithBoundary: boundaries vector is empty.");
365 }
366 if (bData.binvalue == binPhi)
367 while (value < bData.boundaries[0])
368 value += 2 * M_PI;
369 if (bData.binvalue == binPhi)
370 while (value > bData.max)
371 value -= 2 * M_PI;
372 // lower boundary
373 if (value <= bData.boundaries[0]) {
374 return (bData.option == closed) ? (bData.bins - 1) : 0;
375 }
376 // higher boundary
377 if (value >= bData.max)
378 return (bData.option == closed) ? 0 : (bData.bins - 1);
379 // search
380 std::vector<float>::const_iterator vIter = bData.boundaries.begin();
381 size_t bin = 0;
382 for (; vIter != bData.boundaries.end(); ++vIter, ++bin){
383 if ((*vIter) > value){
384 break;
385 }
386 }
387 //overflow (i.e. bin == 0) can only happen if the boundaries vector is empty,
388 //which is already checked
389 //coverity[INTEGER_OVERFLOW]
390 return (bin - 1);
391 }

◆ searchInVectorWithMixedBoundary()

size_t Trk::BinningData::searchInVectorWithMixedBoundary ( std::pair< float, float > val,
const BinningData & bData )
inlinestaticprivate

Search in mixed vector - linear in O-10 bins, otherwise binary.

Definition at line 417 of file BinningData.h.

418 {
419 if ((bData.hbounds[0].first == 0 ? val.first : val.second) < bData.hbounds[0].second)
420 return (bData.option == closed) ? (bData.bins - 1) : 0;
421 if ((bData.hbounds.back().first == 0 ? val.first : val.second) >= bData.max)
422 return (bData.option == closed) ? 0 : (bData.bins - 1);
423
424 if (bData.hbounds.size() < 10) {
425 std::vector<std::pair<int, float>>::const_iterator vBeg = bData.hbounds.begin();
426 std::vector<std::pair<int, float>>::const_iterator vIter = vBeg + 1;
427 for (; vIter != bData.hbounds.end(); ++vIter)
428 if ((*vIter).second > ((*vIter).first == 0 ? val.first : val.second))
429 break;
430 return (vIter != bData.hbounds.end() ? vIter - vBeg - 1 : bData.bins - 1);
431 }
432
433 // Binary search in an array of n values to locate value
434 size_t nabove;
435 size_t nbelow;
436 size_t middle;
437 nabove = bData.hbounds.size();
438 // binary search
439 nbelow = 0;
440 while (nabove - nbelow > 1) {
441 middle = (nabove + nbelow) / 2;
442 float valm = bData.hbounds[middle].first == 0 ? val.first : val.second;
443 if (valm == bData.hbounds[middle].second) {
444 nbelow = middle;
445 break;
446 }
447 if (valm < bData.hbounds[middle].second)
448 nabove = middle;
449 else
450 nbelow = middle;
451 }
452
453 if (nbelow > bData.bins - 1)
454 return bData.bins - 1;
455 return nbelow;
456 }

◆ searchLocal()

size_t Trk::BinningData::searchLocal ( const Amg::Vector2D & lposition) const
inline

generic search from a 2D position — corresponds to local coordinate schema

Definition at line 204 of file BinningData.h.

205 {
206 return (binvalue == Trk::binH) ? searchH(valueH(lposition)) : search(value(lposition));
207 }

◆ value() [1/2]

float Trk::BinningData::value ( const Amg::Vector2D & lposition) const
inline

take the right float value - assumes the correct local position expression

Definition at line 122 of file BinningData.h.

123 {
124 // ordered after occurence
126 return lposition[0];
127 if (binvalue == Trk::binPhi)
128 return gaugePhi(lposition[1]);
129 return lposition[1];
130 }
float gaugePhi(float phi) const
gauge phi
@ binR
Definition BinningType.h:50
@ binRPhi
Definition BinningType.h:52
@ binX
Definition BinningType.h:47

◆ value() [2/2]

float Trk::BinningData::value ( const Amg::Vector3D & position) const
inline

take the right float value

Definition at line 133 of file BinningData.h.

134 {
135 // ordered after occurence
137 return (position.perp());
138 if (binvalue == Trk::binRPhi)
139 return (position.perp() * position.phi());
140 if (binvalue == Trk::binEta)
141 return (position.eta());
142 if (binvalue < 3)
143 return (position[binvalue]);
144 // phi gauging
145 return gaugePhi(position.phi());
146 }
@ binEta
Definition BinningType.h:54

◆ valueH() [1/2]

std::pair< float, float > Trk::BinningData::valueH ( const Amg::Vector2D & lposition) const
inline

take float values for binH

Definition at line 159 of file BinningData.h.

160 {
161 return (std::pair<double, double>(lposition[0], lposition[0] * cos(fabs(refphi - lposition[1]))));
162 }

◆ valueH() [2/2]

std::pair< float, float > Trk::BinningData::valueH ( const Amg::Vector3D & position) const
inline

take float values for binH

Definition at line 165 of file BinningData.h.

166 {
167 return (std::pair<double, double>(position.perp(), position.perp() * cos(fabs(position.phi() - refphi))));
168 }

Member Data Documentation

◆ bins

size_t Trk::BinningData::bins

Definition at line 55 of file BinningData.h.

◆ binvalue

BinningValue Trk::BinningData::binvalue

Definition at line 54 of file BinningData.h.

◆ boundaries

std::vector<float> Trk::BinningData::boundaries

Definition at line 61 of file BinningData.h.

◆ hbounds

std::vector<std::pair<int, float> > Trk::BinningData::hbounds

Definition at line 62 of file BinningData.h.

◆ m_functionPtr

size_t(* Trk::BinningData::m_functionPtr) (float, const BinningData &)
private

the pointer to the function to be used

Definition at line 322 of file BinningData.h.

◆ m_mixPtr

size_t(* Trk::BinningData::m_mixPtr) (std::pair< float, float >, const BinningData &)
private

Definition at line 323 of file BinningData.h.

◆ max

float Trk::BinningData::max

Definition at line 57 of file BinningData.h.

◆ min

float Trk::BinningData::min

Definition at line 56 of file BinningData.h.

◆ option

BinningOption Trk::BinningData::option

Definition at line 53 of file BinningData.h.

◆ refphi

float Trk::BinningData::refphi

Definition at line 60 of file BinningData.h.

◆ step

float Trk::BinningData::step

Definition at line 58 of file BinningData.h.

◆ subStep

float Trk::BinningData::subStep

Definition at line 59 of file BinningData.h.

◆ type

BinningType Trk::BinningData::type

holding all the data for binning calculatuion

Definition at line 52 of file BinningData.h.


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