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 46 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 70 of file BinningData.h.

79 : type(bType)
80 , option(bOption)
81 , binvalue(bValue)
82 , bins(bBins)
83 , min(bMin)
84 , max(bMax)
85 , step(bStep != 0. ? bStep : 1.)
86 , subStep(bSubStep)
87 , refphi(0.)
88 , boundaries(std::move(bBoundaries))
89 , hbounds(std::vector<std::pair<int, float>>())
90 , m_mixPtr(nullptr)
91 {
92 if (bType == Trk::equidistant)
94 else if (bType == Trk::biequidistant)
96 else
98 }
std::vector< float > boundaries
Definition BinningData.h:59
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:51
size_t(* m_functionPtr)(float, const BinningData &)
the pointer to the function to be used
BinningValue binvalue
Definition BinningData.h:52
std::vector< std::pair< int, float > > hbounds
Definition BinningData.h:60
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:50
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 101 of file BinningData.h.

105 , option(bOption)
107 , bins(bOption == Trk::open ? bBoundaries.size() - 1 : bBoundaries.size())
108 , min(bBoundaries.front().second)
109 , max(bBoundaries.back().second)
110 , step(1.)
111 , subStep(0.) // non-zero value needed for next()
112 , refphi(bRefPhi)
113 , boundaries(std::vector<float>())
114 , hbounds(bBoundaries)
115 , m_functionPtr(nullptr)
117 {}
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 384 of file BinningData.h.

385 {
386 // Binary search in an array of n values to locate value
387 if (bData.binvalue == binPhi)
388 while (value < bData.boundaries[0])
389 value += 2 * acos(-1.);
390 if (bData.binvalue == binPhi)
391 while (value > bData.max)
392 value -= 2 * acos(-1.);
393 // underflow
394 if (value <= bData.boundaries[0])
395 return (bData.option == closed) ? (bData.bins - 1) : 0;
396 size_t nabove;
397 size_t nbelow;
398 size_t middle;
399 // overflow
400 nabove = bData.boundaries.size() + 1;
401 if (value >= bData.max)
402 return (bData.option == closed) ? 0 : nabove - 2;
403 // binary search
404 nbelow = 0;
405 while (nabove - nbelow > 1) {
406 middle = (nabove + nbelow) / 2;
407 if (value == bData.boundaries[middle - 1])
408 return middle - 1;
409 if (value < bData.boundaries[middle - 1])
410 nabove = middle;
411 else
412 nbelow = middle;
413 }
414 return nbelow - 1;
415 }
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

◆ binPosition()

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

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

edges/ 0. bin center

Definition at line 305 of file BinningData.h.

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

◆ 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 250 of file BinningData.h.

251 {
252 // current value
253 float val = (binvalue == Trk::binH) ? valueH(position).first : value(position);
254 // probe value
255 Amg::Vector3D probe = position + 0.5 * step * dir.normalized();
256 float nextval = (binvalue == Trk::binH) ? valueH(probe).first : value(probe);
257 // current bin
258 int bin0 = (binvalue == Trk::binH) ? searchH(valueH(position)) : search(val);
259 // next bin
260 int bin = (nextval - val) > 0. ? bin0 + 1 : bin0 - 1;
261 if (bin > int(bins) - 1)
262 bin = (option == closed) ? 0 : bin0;
263 if (bin < 0)
264 bin = (option == closed) ? bins - 1 : 0;
265
266 // boundary value
267 float bval = 0.;
268 if (binvalue == Trk::binH) {
269 bval = (nextval > val) ? hbounds[bin0 + 1].second : hbounds[bin0].second; // non-equidistant
270
271 // may need to recalculate current value and probe
272 if (nextval > val) {
273 if (hbounds[bin0 + 1].first > 0) {
274 val = valueH(position).second;
275 nextval = valueH(probe).second;
276 }
277 } else {
278 if (hbounds[bin0].first > 0) {
279 val = valueH(position).second;
280 nextval = valueH(probe).second;
281 }
282 }
283 } else {
284 bval = (nextval > val) ? boundaries[bin0 + 1] : boundaries[bin0]; // non-equidistant
285 if (type == Trk::equidistant)
286 bval = min + bin0 * step;
287 }
288 // differential
289 float dd = 2 * (nextval - val) / step;
290 // distance estimate
291 float dist = std::fabs(dd) > 1.e-06 ? (bval - val) / dd : 1.e06;
292 return std::pair<size_t, float>(bin, dist);
293 }
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

◆ entry()

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

the entry bin

Definition at line 228 of file BinningData.h.

229 {
230 size_t bin = (binvalue == Trk::binH) ? searchH(valueH(position)) : search(value(position));
231 return (bin < bins - bin) ? bin : bins - 1;
232 }

◆ gaugePhi()

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

gauge phi

Definition at line 147 of file BinningData.h.

148 {
149 if (max > M_PI && phi < min && phi < 0.) {
150 phi = M_PI + phi;
151 phi += M_PI;
152 }
153 return phi;
154 }
#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 187 of file BinningData.h.

188 {
189 if (option == Trk::closed)
190 return true;
191 if (binvalue != Trk::binH) {
192 float val = value(lp);
193 return (val > min - 0.001 && val < max + 0.001);
194 }
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);
199 }

◆ inside() [2/2]

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

Check if bin is inside from Vector3D.

Definition at line 169 of file BinningData.h.

170 {
171 // closed one is always inside
172 if (option == Trk::closed)
173 return true;
174 // all other options except value H
175 if (binvalue != Trk::binH) {
176 float val = value(position);
177 return (val > min - 0.001 && val < max + 0.001);
178 }
179 // value H case
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);
184 }

◆ 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 235 of file BinningData.h.

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

◆ 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 296 of file BinningData.h.

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

◆ search()

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

generic search - forwards to correct function pointer

Definition at line 214 of file BinningData.h.

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

◆ searchBiequidistantWithBoundary()

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

Biequidistant search : biequidist 1.

Definition at line 340 of file BinningData.h.

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

◆ searchEaquidstantWithBoundary()

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

Equidistant search : equidist 0.

Definition at line 324 of file BinningData.h.

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

◆ searchGlobal()

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

generic search from a 3D position

Definition at line 208 of file BinningData.h.

209 {
210 return (binvalue == Trk::binH) ? searchH(valueH(position)) : search(value(position));
211 }

◆ searchH()

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

generic search - forwards to correct function pointer

Definition at line 221 of file BinningData.h.

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

◆ 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 359 of file BinningData.h.

360 {
361 if (bData.binvalue == binPhi)
362 while (value < bData.boundaries[0])
363 value += 2 * M_PI;
364 if (bData.binvalue == binPhi)
365 while (value > bData.max)
366 value -= 2 * M_PI;
367 // lower boundary
368 if (value <= bData.boundaries[0]) {
369 return (bData.option == closed) ? (bData.bins - 1) : 0;
370 }
371 // higher boundary
372 if (value >= bData.max)
373 return (bData.option == closed) ? 0 : (bData.bins - 1);
374 // search
375 std::vector<float>::const_iterator vIter = bData.boundaries.begin();
376 size_t bin = 0;
377 for (; vIter != bData.boundaries.end(); ++vIter, ++bin)
378 if ((*vIter) > value)
379 break;
380 return (bin - 1);
381 }

◆ 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 418 of file BinningData.h.

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

◆ 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 202 of file BinningData.h.

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

◆ 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 120 of file BinningData.h.

121 {
122 // ordered after occurence
124 return lposition[0];
125 if (binvalue == Trk::binPhi)
126 return gaugePhi(lposition[1]);
127 return lposition[1];
128 }
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 131 of file BinningData.h.

132 {
133 // ordered after occurence
135 return (position.perp());
136 if (binvalue == Trk::binRPhi)
137 return (position.perp() * position.phi());
138 if (binvalue == Trk::binEta)
139 return (position.eta());
140 if (binvalue < 3)
141 return (position[binvalue]);
142 // phi gauging
143 return gaugePhi(position.phi());
144 }
@ 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 157 of file BinningData.h.

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

◆ valueH() [2/2]

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

take float values for binH

Definition at line 163 of file BinningData.h.

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

Member Data Documentation

◆ bins

size_t Trk::BinningData::bins

Definition at line 53 of file BinningData.h.

◆ binvalue

BinningValue Trk::BinningData::binvalue

Definition at line 52 of file BinningData.h.

◆ boundaries

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

Definition at line 59 of file BinningData.h.

◆ hbounds

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

Definition at line 60 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 320 of file BinningData.h.

◆ m_mixPtr

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

Definition at line 321 of file BinningData.h.

◆ max

float Trk::BinningData::max

Definition at line 55 of file BinningData.h.

◆ min

float Trk::BinningData::min

Definition at line 54 of file BinningData.h.

◆ option

BinningOption Trk::BinningData::option

Definition at line 51 of file BinningData.h.

◆ refphi

float Trk::BinningData::refphi

Definition at line 58 of file BinningData.h.

◆ step

float Trk::BinningData::step

Definition at line 56 of file BinningData.h.

◆ subStep

float Trk::BinningData::subStep

Definition at line 57 of file BinningData.h.

◆ type

BinningType Trk::BinningData::type

holding all the data for binning calculatuion

Definition at line 50 of file BinningData.h.


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