9#ifndef TRKDETDESCRUTILS_BINNINGDATA_H
10#define TRKDETDESCRUTILS_BINNINGDATA_H
13#include "GaudiKernel/GaudiException.h"
60 std::vector<std::pair<int, float>>
hbounds;
78 std::vector<float> bBoundaries = std::vector<float>())
85 ,
step(bStep != 0. ? bStep : 1.)
103 const std::vector<std::pair<int, float>>& bBoundaries)
107 ,
bins(bOption ==
Trk::
open ? bBoundaries.size() - 1 : bBoundaries.size())
108 ,
min(bBoundaries.front().second)
109 ,
max(bBoundaries.back().second)
135 return (position.perp());
137 return (position.perp() * position.phi());
139 return (position.eta());
159 return (std::pair<double, double>(lposition[0], lposition[0] * cos(fabs(
refphi - lposition[1]))));
165 return (std::pair<double, double>(position.perp(), position.perp() * cos(fabs(position.phi() -
refphi))));
176 float val =
value(position);
177 return (val >
min - 0.001 && val <
max + 0.001);
180 std::pair<double, double> valH =
valueH(position);
181 float valmin =
hbounds.front().first == 0 ? valH.first : valH.second;
182 float valmax =
hbounds.back().first == 0 ? valH.first : valH.second;
183 return (valmin >
min - 0.001 && valmax <
max + 0.001);
192 float val =
value(lp);
193 return (val >
min - 0.001 && val <
max + 0.001);
195 std::pair<double, double> valH =
valueH(lp);
196 float valmin =
hbounds.front().first == 0 ? valH.first : valH.second;
197 float valmax =
hbounds.back().first == 0 ? valH.first : valH.second;
198 return (valmin >
min - 0.001 && valmax <
max + 0.001);
237 float val =
value(position);
239 float nextval =
value(probe);
244 return (bin < 0 || bin + 1 >
int(
bins)) ? ((
bin < 0) ?
bins - 1 : 0) :
bin;
260 int bin = (nextval - val) > 0. ? bin0 + 1 : bin0 - 1;
269 bval = (nextval > val) ?
hbounds[bin0 + 1].second :
hbounds[bin0].second;
273 if (
hbounds[bin0 + 1].first > 0) {
274 val =
valueH(position).second;
275 nextval =
valueH(probe).second;
279 val =
valueH(position).second;
280 nextval =
valueH(probe).second;
289 float dd = 2 * (nextval - val) /
step;
291 float dist = std::fabs(dd) > 1.e-06 ? (bval - val) / dd : 1.e06;
292 return std::pair<size_t, float>(
bin, dist);
309 return (
min + (2. *
bin + pos + 1.) *
step / 2.);
315 return (bmin + 0.5 * (pos + 1.) * (bmax - bmin));
330 return (bData.
bins - 1);
349 return bData.
bins - 1;
352 float bDist =
value - (bData.
min + (leadbin + 1) * bData.
step);
353 int addon = int(bDist / bData.
subStep) ? 0 : 1;
355 return leadbin * 2 + addon;
375 std::vector<float>::const_iterator vIter = bData.
boundaries.begin();
378 if ((*vIter) >
value)
389 value += 2 * acos(-1.);
392 value -= 2 * acos(-1.);
405 while (nabove - nbelow > 1) {
406 middle = (nabove + nbelow) / 2;
420 if ((bData.
hbounds[0].first == 0 ? val.first : val.second) < bData.
hbounds[0].second)
422 if ((bData.
hbounds.back().first == 0 ? val.first : val.second) >= bData.
max)
425 if (bData.
hbounds.size() < 10) {
428 for (; vIter != bData.
hbounds.end(); ++vIter)
429 if ((*vIter).second > ((*vIter).first == 0 ? val.first : val.second))
431 return (vIter != bData.
hbounds.end() ? vIter - vBeg - 1 : bData.
bins - 1);
441 while (nabove - nbelow > 1) {
442 middle = (nabove + nbelow) / 2;
443 float valm = bData.
hbounds[middle].first == 0 ? val.first : val.second;
444 if (valm == bData.
hbounds[middle].second) {
448 if (valm < bData.
hbounds[middle].second)
454 if (nbelow > bData.
bins - 1)
455 return bData.
bins - 1;
std::vector< float > boundaries
static size_t binarySearchWithBoundary(float value, const BinningData &bData)
A binary search with underflow/overflow - faster than vector search for O(50) objects.
size_t(* m_functionPtr)(float, const BinningData &)
the pointer to the function to be used
float binPosition(size_t bin, float pos) const
bin->BinningValue navigation : pos=+-1.
std::pair< float, float > valueH(const Amg::Vector2D &lposition) const
take float values for binH
BinningData(BinningOption bOption, float bRefPhi, const std::vector< std::pair< int, float > > &bBoundaries)
Constructor for binH type : non-equidistant binning assumed.
LayerOrder orderDirection(const Amg::Vector3D &position, const Amg::Vector3D &dir) const
layer order is needed for value H binning
std::vector< std::pair< int, float > > hbounds
static size_t searchInVectorWithMixedBoundary(std::pair< float, float > val, const BinningData &bData)
Search in mixed vector - linear in O-10 bins, otherwise binary.
size_t entry(const Amg::Vector3D &position) const
the entry bin
float value(const Amg::Vector2D &lposition) const
take the right float value - assumes the correct local position expression
size_t(* m_mixPtr)(std::pair< float, float >, const BinningData &)
size_t searchGlobal(const Amg::Vector3D &position) const
generic search from a 3D position
static size_t searchInVectorWithBoundary(float value, const BinningData &bData)
Linear search in vector - superior in O(10) searches: arbitraty 2.
std::pair< float, float > valueH(const Amg::Vector3D &position) const
take float values for binH
float value(const Amg::Vector3D &position) const
take the right float value
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
BinningData & operator=(BinningData &&)=default
bool inside(const Amg::Vector3D &position) const
Check if bin is inside from Vector3D.
BinningType type
holding all the data for binning calculatuion
static size_t searchEaquidstantWithBoundary(float value, const BinningData &bData)
Equidistant search : equidist 0.
size_t searchLocal(const Amg::Vector2D &lposition) const
generic search from a 2D position — corresponds to local coordinate schema
BinningData(BinningData &&)=default
BinningData & operator=(const BinningData &)=default
static size_t searchBiequidistantWithBoundary(float value, const BinningData &bData)
Biequidistant search : biequidist 1.
bool inside(const Amg::Vector2D &lp) const
Check if bin is inside from Vector2D.
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.
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
float gaugePhi(float phi) const
gauge phi
BinningData(const BinningData &)=default
size_t next(const Amg::Vector3D &position, const Amg::Vector3D &dir) const
the next bin : gives -1 if the next one is outside
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
LayerOrder
This enum is used to declare Layers as previous/next in respect of a 1-dimensional binned array.
BinningOption
enum BinValue
BinningType
, BinningOption & BinningAccess
BinningValue
how to take the global / local position