ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinUtilityTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BinUtilityTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
14 
15 namespace Acts {
16 namespace Test {
17 
18 namespace tt = boost::test_tools;
19 
20 // OPEN - equidistant binning tests
21 BOOST_AUTO_TEST_CASE(BinUtility_equidistant_binning) {
22  Vector3D xyzPosition(1.5, 2.5, 3.5);
23  Vector3D edgePosition(0.5, 0.5, 0.5);
24 
25  // | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
26  BinUtility xUtil_eq(10, 0., 10., open, binX);
27  BinUtility yUtil_eq(10, 0., 10., open, binY);
28  BinUtility zUtil_eq(10, 0., 10., open, binZ);
29  BOOST_CHECK_EQUAL(xUtil_eq.bins(), (size_t)10);
30  // make it 2-dim
31  BinUtility xyUtil_eq(10, 0., 10., open, binX);
32  xyUtil_eq += yUtil_eq;
33  BOOST_CHECK_EQUAL(xyUtil_eq.bins(), 100u);
34  // make it 3-dim
35  BinUtility xyzUtil_eq(xyUtil_eq);
36  xyzUtil_eq += zUtil_eq;
37  BOOST_CHECK_EQUAL(xyzUtil_eq.bins(), 1000u);
38  // check the dimensions
39  BOOST_CHECK_EQUAL(xUtil_eq.dimensions(), 1u);
40  BOOST_CHECK_EQUAL(xyUtil_eq.dimensions(), 2u);
41  BOOST_CHECK_EQUAL(xyzUtil_eq.dimensions(), 3u);
42 
43  // bin triples and clusters
44  auto xTriple = xUtil_eq.binTriple(xyzPosition);
45  auto xyTriple = xyUtil_eq.binTriple(xyzPosition);
46  auto xyzTriple = xyzUtil_eq.binTriple(xyzPosition);
47 
48  BOOST_CHECK_EQUAL(xTriple[0], 1u);
49  BOOST_CHECK_EQUAL(xTriple[1], 0u);
50  BOOST_CHECK_EQUAL(xTriple[2], 0u);
51 
52  BOOST_CHECK_EQUAL(xyTriple[0], 1u);
53  BOOST_CHECK_EQUAL(xyTriple[1], 2u);
54  BOOST_CHECK_EQUAL(xyTriple[2], 0u);
55 
56  BOOST_CHECK_EQUAL(xyzTriple[0], 1u);
57  BOOST_CHECK_EQUAL(xyzTriple[1], 2u);
58  BOOST_CHECK_EQUAL(xyzTriple[2], 3u);
59 
60  // Full range
61  std::vector<size_t> xRangeCheck0 = {0, 1, 2};
62  std::vector<size_t> xyRangeCheck1 = {1, 2, 3};
63  std::vector<size_t> xyzRangeCheck2 = {2, 3, 4};
64 
65  auto xNrange0 = xUtil_eq.neighbourRange(xyzPosition, 0);
66  BOOST_CHECK_EQUAL_COLLECTIONS(xNrange0.begin(), xNrange0.end(),
67  xRangeCheck0.begin(), xRangeCheck0.end());
68 
69  auto xNrange1 = xUtil_eq.neighbourRange(xyzPosition, 1);
70  BOOST_CHECK_EQUAL(xNrange1.size(), 1u);
71  BOOST_CHECK_EQUAL(xNrange1[0], 0u);
72 
73  auto xNrange2 = xUtil_eq.neighbourRange(xyzPosition, 2);
74  BOOST_CHECK_EQUAL(xNrange2.size(), 1u);
75  BOOST_CHECK_EQUAL(xNrange2[0], 0u);
76 
77  auto xyNrange1 = xyUtil_eq.neighbourRange(xyzPosition, 1);
78  BOOST_CHECK_EQUAL_COLLECTIONS(xyNrange1.begin(), xyNrange1.end(),
79  xyRangeCheck1.begin(), xyRangeCheck1.end());
80 
81  auto xyzNrange2 = xyzUtil_eq.neighbourRange(xyzPosition, 2);
82  BOOST_CHECK_EQUAL_COLLECTIONS(xyzNrange2.begin(), xyzNrange2.end(),
83  xyzRangeCheck2.begin(), xyzRangeCheck2.end());
84 
85  // Partial range
86  std::vector<size_t> xEdgeCheck = {0, 1};
87  auto xEdgeRange = xUtil_eq.neighbourRange(edgePosition, 0);
88  BOOST_CHECK_EQUAL_COLLECTIONS(xEdgeRange.begin(), xEdgeRange.end(),
89  xEdgeCheck.begin(), xEdgeCheck.end());
90 }
91 } // namespace Test
92 } // namespace Acts