ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryIDTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryIDTests.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 
12 
13 namespace Acts {
14 namespace Test {
15 
16 BOOST_AUTO_TEST_CASE(GeometryID_construct_default) {
17  GeometryID id;
18  BOOST_TEST(id.volume() == 0u);
19  BOOST_TEST(id.boundary() == 0u);
20  BOOST_TEST(id.layer() == 0u);
21  BOOST_TEST(id.approach() == 0u);
22  BOOST_TEST(id.sensitive() == 0u);
23 }
24 
25 BOOST_AUTO_TEST_CASE(GeometryID_construct_encoded) {
26  // not sure if it is a good idea to test for the encoding since it should be
27  // an implementation detail. only the resulting functionality is relevant.
28  GeometryID id = 0xa0b00c00d00affe0u;
29  BOOST_TEST(id.volume() == 0xa0u);
30  BOOST_TEST(id.boundary() == 0xb0u);
31  BOOST_TEST(id.layer() == 0x0c0u);
32  BOOST_TEST(id.approach() == 0x0du);
33  BOOST_TEST(id.sensitive() == 0x00affe0u);
34 }
35 
36 BOOST_AUTO_TEST_CASE(GeometryID_max_values) {
37  // compute maximum value for each component
38  constexpr GeometryID::Value volumeMax = (1u << 8) - 1;
39  constexpr GeometryID::Value boundaryMax = (1u << 8) - 1;
40  constexpr GeometryID::Value layerMax = (1u << 12) - 1;
41  constexpr GeometryID::Value approachMax = (1u << 8) - 1;
42  constexpr GeometryID::Value sensitiveMax = (1u << 28) - 1;
43  // reference values non-zero values everywhere
44  constexpr GeometryID ref = 0xdeadaffe01234567;
45  // values above the maximum are truncated
46  // max+1 has all available bits zeroed
47  BOOST_TEST(GeometryID(ref).setVolume(volumeMax + 1) ==
48  GeometryID(ref).setVolume(0u));
49  BOOST_TEST(GeometryID(ref).setBoundary(boundaryMax + 1) ==
50  GeometryID(ref).setBoundary(0u));
51  BOOST_TEST(GeometryID(ref).setLayer(layerMax + 1) ==
52  GeometryID(ref).setLayer(0u));
53  BOOST_TEST(GeometryID(ref).setApproach(approachMax + 1) ==
54  GeometryID(ref).setApproach(0u));
55  BOOST_TEST(GeometryID(ref).setSensitive(sensitiveMax + 1) ==
56  GeometryID(ref).setSensitive(0u));
57 }
58 
59 BOOST_AUTO_TEST_CASE(GeometryID_order) {
60  auto vol1 = GeometryID().setVolume(1u).setLayer(14u).setSensitive(5u);
61  auto vol2 = GeometryID().setVolume(2u).setLayer(13u).setSensitive(3u);
62  // order uses volume first even if other components are larger
63  BOOST_TEST(vol1 < vol2);
64  BOOST_TEST(GeometryID(vol1).setBoundary(64u) < vol2);
65  BOOST_TEST(GeometryID(vol1).setLayer(64u) < vol2);
66  BOOST_TEST(GeometryID(vol1).setApproach(64u) < vol2);
67  BOOST_TEST(GeometryID(vol1).setSensitive(64u) < vol2);
68  BOOST_TEST(vol2 < GeometryID(vol1).setVolume(3u));
69  // other components are hierachical
70  BOOST_TEST(GeometryID(vol1).setVolume(1u).setBoundary(2u) <
71  GeometryID(vol1).setVolume(2u).setBoundary(1u));
72  BOOST_TEST(GeometryID(vol1).setBoundary(1u).setLayer(2u) <
73  GeometryID(vol1).setBoundary(2u).setLayer(1u));
74  BOOST_TEST(GeometryID(vol1).setLayer(1u).setApproach(2u) <
75  GeometryID(vol1).setLayer(2u).setApproach(1u));
76  BOOST_TEST(GeometryID(vol1).setApproach(1u).setSensitive(2u) <
77  GeometryID(vol1).setApproach(2u).setSensitive(1u));
78 }
79 
80 } // namespace Test
81 } // namespace Acts