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 #include <cmath>
16 
17 namespace Acts {
18 namespace Test {
19 
20 namespace tt = boost::test_tools;
21 
22 // OPEN - equidistant binning tests
23 BOOST_AUTO_TEST_CASE(BinUtility_equidistant_binning) {
24  Vector3D xyzPosition(1.5, 2.5, 3.5);
25  Vector3D edgePosition(0.5, 0.5, 0.5);
26 
27  // | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
28  BinUtility xUtil_eq(10, 0., 10., open, binX);
29  BinUtility yUtil_eq(10, 0., 10., open, binY);
30  BinUtility zUtil_eq(10, 0., 10., open, binZ);
31  BOOST_CHECK_EQUAL(xUtil_eq.bins(), (size_t)10);
32  // make it 2-dim
33  BinUtility xyUtil_eq(10, 0., 10., open, binX);
34  xyUtil_eq += yUtil_eq;
35  BOOST_CHECK_EQUAL(xyUtil_eq.bins(), 100u);
36  // make it 3-dim
37  BinUtility xyzUtil_eq(xyUtil_eq);
38  xyzUtil_eq += zUtil_eq;
39  BOOST_CHECK_EQUAL(xyzUtil_eq.bins(), 1000u);
40  // check the dimensions
41  BOOST_CHECK_EQUAL(xUtil_eq.dimensions(), 1u);
42  BOOST_CHECK_EQUAL(xyUtil_eq.dimensions(), 2u);
43  BOOST_CHECK_EQUAL(xyzUtil_eq.dimensions(), 3u);
44 
45  // bin triples and clusters
46  auto xTriple = xUtil_eq.binTriple(xyzPosition);
47  auto xyTriple = xyUtil_eq.binTriple(xyzPosition);
48  auto xyzTriple = xyzUtil_eq.binTriple(xyzPosition);
49 
50  BOOST_CHECK_EQUAL(xTriple[0], 1u);
51  BOOST_CHECK_EQUAL(xTriple[1], 0u);
52  BOOST_CHECK_EQUAL(xTriple[2], 0u);
53 
54  BOOST_CHECK_EQUAL(xyTriple[0], 1u);
55  BOOST_CHECK_EQUAL(xyTriple[1], 2u);
56  BOOST_CHECK_EQUAL(xyTriple[2], 0u);
57 
58  BOOST_CHECK_EQUAL(xyzTriple[0], 1u);
59  BOOST_CHECK_EQUAL(xyzTriple[1], 2u);
60  BOOST_CHECK_EQUAL(xyzTriple[2], 3u);
61 
62  // Full range
63  std::vector<size_t> xRangeCheck0 = {0, 1, 2};
64  std::vector<size_t> xyRangeCheck1 = {1, 2, 3};
65  std::vector<size_t> xyzRangeCheck2 = {2, 3, 4};
66 
67  auto xNrange0 = xUtil_eq.neighbourRange(xyzPosition, 0);
68  BOOST_CHECK_EQUAL_COLLECTIONS(xNrange0.begin(), xNrange0.end(),
69  xRangeCheck0.begin(), xRangeCheck0.end());
70 
71  auto xNrange1 = xUtil_eq.neighbourRange(xyzPosition, 1);
72  BOOST_CHECK_EQUAL(xNrange1.size(), 1u);
73  BOOST_CHECK_EQUAL(xNrange1[0], 0u);
74 
75  auto xNrange2 = xUtil_eq.neighbourRange(xyzPosition, 2);
76  BOOST_CHECK_EQUAL(xNrange2.size(), 1u);
77  BOOST_CHECK_EQUAL(xNrange2[0], 0u);
78 
79  auto xyNrange1 = xyUtil_eq.neighbourRange(xyzPosition, 1);
80  BOOST_CHECK_EQUAL_COLLECTIONS(xyNrange1.begin(), xyNrange1.end(),
81  xyRangeCheck1.begin(), xyRangeCheck1.end());
82 
83  auto xyzNrange2 = xyzUtil_eq.neighbourRange(xyzPosition, 2);
84  BOOST_CHECK_EQUAL_COLLECTIONS(xyzNrange2.begin(), xyzNrange2.end(),
85  xyzRangeCheck2.begin(), xyzRangeCheck2.end());
86 
87  // Partial range
88  std::vector<size_t> xEdgeCheck = {0, 1};
89  auto xEdgeRange = xUtil_eq.neighbourRange(edgePosition, 0);
90  BOOST_CHECK_EQUAL_COLLECTIONS(xEdgeRange.begin(), xEdgeRange.end(),
91  xEdgeCheck.begin(), xEdgeCheck.end());
92 }
93 // OPEN - local to global transform test
94 BOOST_AUTO_TEST_CASE(BinUtility_transform) {
95  Transform3D transform_LtoG = Transform3D::Identity();
96  transform_LtoG = transform_LtoG * Translation3D(0., 0., -50);
97  transform_LtoG = transform_LtoG * AngleAxis3D(M_PI / 4, Vector3D(0, 0, 1));
98  ;
99 
100  Transform3D transform_GtoL = transform_LtoG.inverse();
101 
102  BinUtility rUtil(10, 0., 100., open, binR);
103  BinUtility phiUtil(10, -M_PI, M_PI, closed, binPhi);
104  BinUtility zUtil(10, -100., 100., open, binZ);
105 
106  BinUtility noTranform;
107  noTranform += rUtil;
108  noTranform += phiUtil;
109  noTranform += zUtil;
110 
111  BinUtility withTranform(transform_LtoG);
112  withTranform += rUtil;
113  withTranform += phiUtil;
114  withTranform += zUtil;
115 
116  Vector3D pos1(0, 0, 0);
117  Vector3D pos2(60, 0, 0);
118  Vector3D pos3(34, M_PI / 2, 0);
119  Vector3D pos4(0, 0, -80);
120  Vector3D pos5(80, -M_PI / 4, 50);
121 
122  for (int i = 0; i < 3; i++) {
123  BOOST_CHECK_EQUAL(withTranform.bin(pos1, i),
124  noTranform.bin(transform_GtoL * pos1, i));
125  BOOST_CHECK_EQUAL(withTranform.bin(pos2, i),
126  noTranform.bin(transform_GtoL * pos2, i));
127  BOOST_CHECK_EQUAL(withTranform.bin(pos3, i),
128  noTranform.bin(transform_GtoL * pos3, i));
129  BOOST_CHECK_EQUAL(withTranform.bin(pos4, i),
130  noTranform.bin(transform_GtoL * pos4, i));
131  BOOST_CHECK_EQUAL(withTranform.bin(pos5, i),
132  noTranform.bin(transform_GtoL * pos5, i));
133  }
134 }
135 
136 } // namespace Test
137 } // namespace Acts