ATLAS Offline Software
Loading...
Searching...
No Matches
BinUtilityTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6// BinUtilityTest.cxx, (c) ATLAS Detector software
8
9// Trk includes
12
13
15{
16
17 ATH_MSG_VERBOSE("Running the BinUtilityTest Test");
18
19 // Contstruction of bin array test
20 // add a closed equidistant binning in Rphi
21 Trk::BinUtility testUtil(10, 0., m_flatDist->shoot()*1000.*M_PI, Trk::closed, Trk::binRPhi);
22 ATH_MSG_VERBOSE(" Created 1D bin utitlity : " << testUtil );
23 // add an equidistant binning in Z
24 testUtil += Trk::BinUtility(24, -400., 400., Trk::open, Trk::binZ);
25 ATH_MSG_VERBOSE(" Created 2D bin utitlity : " << testUtil );
26 // add a bi equidistant binning in X
27 testUtil += Trk::BinUtility(5, m_flatDist->shoot()*10., m_flatDist->shoot()*80., 1000.+m_flatDist->shoot()*1000 , Trk::open, Trk::binX);
28 ATH_MSG_VERBOSE(" Created 3D bin utitlity : " << testUtil );
29
30 // Arbitrary binning test
31 for (size_t it = 0; it < Trk::TrkDetDescrUnitTestBase::m_numTests; ++it) {
32 std::vector<float> binVector;
33 std::map<float, size_t> binMap;
34 float low;
35 float high;
36
37 prepareData(binVector, binMap, low, high);
38
39 Trk::BinUtility binUtility(binVector, Trk::open, Trk::binX);
40
41 // run the test n times
42 for (size_t itpv = 0; itpv < m_numberOfTestsPerSet; ++itpv) {
43 float value = low + (high - low) * Trk::TrkDetDescrUnitTestBase::m_flatDist->shoot();
44 Amg::Vector3D testPosition(value, 0., 0.);
45 size_t binVec = searchInVectorWithBoundary(binVector, testPosition.x());
46 size_t binBin = binarySearchWithBoundary(binVector, testPosition.x());
47 size_t binUtil = binUtility.bin(testPosition, 0);
48 if (binVec != binBin || binVec != binUtil )
49 ATH_MSG_WARNING("Searches through binary (" << binBin << "), vector (" << binVec << ") or tutility (" << binUtil << ") differ.");
50 }
51
52 }
53 return StatusCode::SUCCESS;
54}
55
56void Trk::BinUtilityTest::prepareData(std::vector<float>& vec, std::map<float, size_t>& map, float& low, float& high) {
57
58 // create the boundaries
60 high = low + 1000.*Trk::TrkDetDescrUnitTestBase::m_flatDist->shoot();
61 float range = high - low;
62 map[low] = 0;
63 map[high] = 0;
64 for (size_t is = 0; is < m_numberOfSegments-1; ++is){
65 map[low + range*m_flatDist->shoot()] = 0;
66 }
67 // now prepare the vector
68 vec.reserve(m_numberOfSegments+1);
69 std::map< float, size_t >::iterator sIter = map.begin();
70 for (size_t cs = 0 ; sIter != map.end(); ++sIter, ++cs ){
71 vec.push_back((*sIter).first);
72 (*sIter).second = cs;
73 }
74}
#define M_PI
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
std::vector< size_t > vec
std::size_t binarySearchWithBoundary(const std::vector< float > &v, float value)
A binary search with underflow/overflow.
Gaudi::Property< std::size_t > m_numberOfTestsPerSet
void prepareData(std::vector< float > &vec, std::map< float, std::size_t > &map, float &low, float &high)
preparation of std::vector and std::map for comparison
std::size_t searchInVectorWithBoundary(std::vector< float > &v, float value)
A linear search - superior in O(10) searches.
Gaudi::Property< std::size_t > m_numberOfSegments
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition BinUtility.h:39
size_t bin(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame).
Definition BinUtility.h:126
Gaudi::Property< size_t > m_numTests
number of tests
STL class.
Eigen::Matrix< double, 3, 1 > Vector3D
@ open
Definition BinningType.h:40
@ closed
Definition BinningType.h:41
@ binRPhi
Definition BinningType.h:52
@ binX
Definition BinningType.h:47
@ binZ
Definition BinningType.h:49