ATLAS Offline Software
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 
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 
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 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Trk::BinUtilityTest::m_numberOfSegments
size_t m_numberOfSegments
Definition: BinUtilityTest.h:79
Trk::TrkDetDescrUnitTestBase::m_flatDist
Rndm::Numbers * m_flatDist
Definition: TrkDetDescrUnitTestBase.h:58
Trk::TrkDetDescrUnitTestBase::m_numTests
size_t m_numTests
number of tests
Definition: TrkDetDescrUnitTestBase.h:61
Trk::binZ
@ binZ
Definition: BinningType.h:49
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::TrkDetDescrUnitTestBase
Definition: TrkDetDescrUnitTestBase.h:27
BinUtility.h
skel.it
it
Definition: skel.GENtoEVGEN.py:423
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::closed
@ closed
Definition: BinningType.h:41
athena.value
value
Definition: athena.py:122
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::BinUtilityTest::m_numberOfTestsPerSet
size_t m_numberOfTestsPerSet
Definition: BinUtilityTest.h:80
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
Trk::binX
@ binX
Definition: BinningType.h:47
Trk::BinUtility
Definition: BinUtility.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Trk::BinUtilityTest::prepareData
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
Definition: BinUtilityTest.cxx:66
Trk::BinUtilityTest::BinUtilityTest
BinUtilityTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: BinUtilityTest.cxx:13
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::open
@ open
Definition: BinningType.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::binRPhi
@ binRPhi
Definition: BinningType.h:52
BinUtilityTest.h
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:136
Trk::BinUtilityTest::runTest
StatusCode runTest()
Definition: BinUtilityTest.cxx:24