ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkDetDescr
TrkDetDescrUnitTests
src
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
10
#include "
TrkDetDescrUnitTests/BinUtilityTest.h
"
11
#include "
TrkDetDescrUtils/BinUtility.h
"
12
13
Trk::BinUtilityTest::BinUtilityTest
(
const
std::string& name, ISvcLocator* pSvcLocator) :
14
Trk
::
TrkDetDescrUnitTestBase
(name, pSvcLocator),
15
m_numberOfSegments
(10),
16
m_numberOfTestsPerSet
(100000)
17
{
18
declareProperty
(
"NumberOfSegments"
,
m_numberOfSegments
);
19
declareProperty
(
"NumberOfTetsPerSet"
,
m_numberOfTestsPerSet
);
20
21
22
}
23
24
StatusCode
Trk::BinUtilityTest::runTest
()
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
66
void
Trk::BinUtilityTest::prepareData
(std::vector<float>&
vec
, std::map<float, size_t>&
map
,
float
& low,
float
& high) {
67
68
// create the boundaries
69
low = 500.*
Trk::TrkDetDescrUnitTestBase::m_flatDist
->shoot();
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
}
M_PI
#define M_PI
Definition
ActiveFraction.h:14
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
BinUtilityTest.h
BinUtility.h
vec
std::vector< size_t > vec
Definition
CombinationsGeneratorTest.cxx:9
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
Trk::BinUtilityTest::binarySearchWithBoundary
std::size_t binarySearchWithBoundary(const std::vector< float > &v, float value)
A binary search with underflow/overflow.
Definition
BinUtilityTest.h:60
Trk::BinUtilityTest::m_numberOfSegments
std::size_t m_numberOfSegments
Definition
BinUtilityTest.h:73
Trk::BinUtilityTest::BinUtilityTest
BinUtilityTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition
BinUtilityTest.cxx:13
Trk::BinUtilityTest::m_numberOfTestsPerSet
std::size_t m_numberOfTestsPerSet
Definition
BinUtilityTest.h:74
Trk::BinUtilityTest::prepareData
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
Definition
BinUtilityTest.cxx:66
Trk::BinUtilityTest::runTest
StatusCode runTest()
Definition
BinUtilityTest.cxx:24
Trk::BinUtilityTest::searchInVectorWithBoundary
std::size_t searchInVectorWithBoundary(std::vector< float > &v, float value)
A linear search - superior in O(10) searches.
Definition
BinUtilityTest.h:47
Trk::BinUtility
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition
BinUtility.h:39
Trk::BinUtility::bin
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
Trk::TrkDetDescrUnitTestBase::TrkDetDescrUnitTestBase
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition
TrkDetDescrUnitTestBase.cxx:12
Trk::TrkDetDescrUnitTestBase::m_numTests
size_t m_numTests
number of tests
Definition
TrkDetDescrUnitTestBase.h:61
Trk::TrkDetDescrUnitTestBase::m_flatDist
Rndm::Numbers * m_flatDist
Definition
TrkDetDescrUnitTestBase.h:58
map
STL class.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:47
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition
FakeTrackBuilder.h:9
Trk::open
@ open
Definition
BinningType.h:40
Trk::closed
@ closed
Definition
BinningType.h:41
Trk::binRPhi
@ binRPhi
Definition
BinningType.h:52
Trk::binX
@ binX
Definition
BinningType.h:47
Trk::binZ
@ binZ
Definition
BinningType.h:49
Generated on
for ATLAS Offline Software by
1.17.0