ATLAS Offline Software
BinUtilityTest.h
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.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUNITTESTS_BinUtilityTEST_H
10 #define TRKDETDESCRUNITTESTS_BinUtilityTEST_H
11 
12 // Athena & Gaudi includes
13 #include "GaudiKernel/ServiceHandle.h"
14 #include "GaudiKernel/ToolHandle.h"
15 // Trk includes
18 
19 #include <vector>
20 #include <map>
21 
22 namespace Trk {
23 
32  public:
33 
35  BinUtilityTest(const std::string& name, ISvcLocator* pSvcLocator);
36 
37  /* specify the test here */
39 
40  private:
42  void prepareData(std::vector<float>& vec, std::map<float, size_t>& map, float& low, float& high);
43 
45  size_t searchInVectorWithBoundary(std::vector<float>& array, float value)
46  {
47  if ( value < array[0] ) return 0;
48  if ( value > array[array.size()-1] ) return (array.size()-1);
49  std::vector<float>::iterator vIter = array.begin();
50  size_t bin = 0;
51  for ( ; vIter != array.end() ; ++vIter, ++bin )
52  if ((*vIter) > value) break;
53  return (bin-1);
54  }
55 
57  size_t binarySearchWithBoundary(std::vector<float>& array, float value)
58  {
59  // Binary search in an array of n values to locate value
60  // underflow
61  if ( value < array[0] ) return 0;
62  if ( value > array[array.size()-1] ) return (array.size()-1);
63  // prepare and run
64  size_t nabove, nbelow, middle;
65  // overflow
66  nabove = array.size()+1;
67  if ( value > array[nabove-2]) return nabove-2;
68  // binary search
69  nbelow = 0;
70  while (nabove-nbelow > 1) {
71  middle = (nabove+nbelow)/2;
72  if (value == array[middle-1]) return middle-1;
73  if (value < array[middle-1]) nabove = middle;
74  else nbelow = middle;
75  }
76  return nbelow-1;
77  }
78 
81 
82  };
83 }
84 
85 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
ISurfaceBuilder.h
Trk::BinUtilityTest::m_numberOfSegments
size_t m_numberOfSegments
Definition: BinUtilityTest.h:79
Trk::TrkDetDescrUnitTestBase
Definition: TrkDetDescrUnitTestBase.h:27
Trk::BinUtilityTest::binarySearchWithBoundary
size_t binarySearchWithBoundary(std::vector< float > &array, float value)
A binary search with underflow/overflow.
Definition: BinUtilityTest.h:57
bin
Definition: BinsDiffFromStripMedian.h:43
athena.value
value
Definition: athena.py:122
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Trk::BinUtilityTest::searchInVectorWithBoundary
size_t searchInVectorWithBoundary(std::vector< float > &array, float value)
A binary search with a map - superior in O(10) searches.
Definition: BinUtilityTest.h:45
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
lumiFormat.array
array
Definition: lumiFormat.py:98
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
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
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
TrkDetDescrUnitTestBase.h
Trk::BinUtilityTest::runTest
StatusCode runTest()
Definition: BinUtilityTest.cxx:24
Trk::BinUtilityTest
Definition: BinUtilityTest.h:31