ATLAS Offline Software
Loading...
Searching...
No Matches
BinUtilityTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// BinUtilityTest.cxx, (c) ATLAS Detector software
8
9// Trk includes
12
13Trk::BinUtilityTest::BinUtilityTest(const std::string& name, ISvcLocator* pSvcLocator) :
14 Trk::TrkDetDescrUnitTestBase(name, pSvcLocator),
17{
18 declareProperty("NumberOfSegments", m_numberOfSegments);
19 declareProperty("NumberOfTetsPerSet", m_numberOfTestsPerSet);
20
21
22}
23
25{
26
27 ATH_MSG_VERBOSE("Running the BinUtilityTest Test");
28
29 // Contstruction of bin array test
30 // add a closed equidistant binning in Rphi
31 Trk::BinUtility testUtil(10, 0., m_flatDist->shoot()*1000.*M_PI, Trk::closed, Trk::binRPhi);
32 ATH_MSG_VERBOSE(" Created 1D bin utitlity : " << testUtil );
33 // add an equidistant binning in Z
34 testUtil += Trk::BinUtility(24, -400., 400., Trk::open, Trk::binZ);
35 ATH_MSG_VERBOSE(" Created 2D bin utitlity : " << testUtil );
36 // add a bi equidistant binning in X
37 testUtil += Trk::BinUtility(5, m_flatDist->shoot()*10., m_flatDist->shoot()*80., 1000.+m_flatDist->shoot()*1000 , Trk::open, Trk::binX);
38 ATH_MSG_VERBOSE(" Created 3D bin utitlity : " << testUtil );
39
40 // Arbitrary binning test
41 for (size_t it = 0; it < Trk::TrkDetDescrUnitTestBase::m_numTests; ++it) {
42 std::vector<float> binVector;
43 std::map<float, size_t> binMap;
44 float low;
45 float high;
46
47 prepareData(binVector, binMap, low, high);
48
49 Trk::BinUtility binUtility(binVector, Trk::open, Trk::binX);
50
51 // run the test n times
52 for (size_t itpv = 0; itpv < m_numberOfTestsPerSet; ++itpv) {
53 float value = low + (high - low) * Trk::TrkDetDescrUnitTestBase::m_flatDist->shoot();
54 Amg::Vector3D testPosition(value, 0., 0.);
55 size_t binVec = searchInVectorWithBoundary(binVector, testPosition.x());
56 size_t binBin = binarySearchWithBoundary(binVector, testPosition.x());
57 size_t binUtil = binUtility.bin(testPosition, 0);
58 if (binVec != binBin || binVec != binUtil )
59 ATH_MSG_WARNING("Searches through binary (" << binBin << "), vector (" << binVec << ") or tutility (" << binUtil << ") differ.");
60 }
61
62 }
63 return StatusCode::SUCCESS;
64}
65
66void Trk::BinUtilityTest::prepareData(std::vector<float>& vec, std::map<float, size_t>& map, float& low, float& high) {
67
68 // create the boundaries
70 high = low + 1000.*Trk::TrkDetDescrUnitTestBase::m_flatDist->shoot();
71 float range = high - low;
72 map[low] = 0;
73 map[high] = 0;
74 for (size_t is = 0; is < m_numberOfSegments-1; ++is){
75 map[low + range*m_flatDist->shoot()] = 0;
76 }
77 // now prepare the vector
78 vec.reserve(m_numberOfSegments+1);
79 std::map< float, size_t >::iterator sIter = map.begin();
80 for (size_t cs = 0 ; sIter != map.end(); ++sIter, ++cs ){
81 vec.push_back((*sIter).first);
82 (*sIter).second = cs;
83 }
84}
#define M_PI
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
std::vector< size_t > vec
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
size_t searchInVectorWithBoundary(std::vector< float > &array, float value)
A binary search with a map - superior in O(10) searches.
size_t binarySearchWithBoundary(std::vector< float > &array, float value)
A binary search with underflow/overflow.
void prepareData(std::vector< float > &vec, std::map< float, size_t > &map, float &low, float &high)
preparation of std::vector and std::map for comparison
BinUtilityTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
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
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
STL class.
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
@ 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