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