Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackStatePropMaskTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackStatePropMaskTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 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/data/test_case.hpp>
10 #include <boost/test/tools/context.hpp>
11 #include <boost/test/unit_test.hpp>
12 
15 
16 #include <array>
17 #include <bitset>
18 #include <cstddef>
19 #include <type_traits>
20 
21 using namespace Acts;
22 
23 BOOST_AUTO_TEST_SUITE(TrackStatePropMaskTest)
24 
25 BOOST_AUTO_TEST_CASE(BitmaskOperators) {
26  using PM = TrackStatePropMask;
27 
28  auto bs1 = PM::Predicted;
29 
30  BOOST_CHECK(ACTS_CHECK_BIT(bs1, PM::Predicted));
31  BOOST_CHECK(!ACTS_CHECK_BIT(bs1, PM::Calibrated));
32 
33  auto bs2 = PM::Calibrated;
34 
35  BOOST_CHECK(!ACTS_CHECK_BIT(bs2, PM::Predicted));
36  BOOST_CHECK(ACTS_CHECK_BIT(bs2, PM::Calibrated));
37 
38  auto bs3 = PM::Calibrated | PM::Predicted;
39 
40  BOOST_CHECK(ACTS_CHECK_BIT(bs3, PM::Predicted));
41  BOOST_CHECK(ACTS_CHECK_BIT(bs3, PM::Calibrated));
42 
43  BOOST_CHECK(ACTS_CHECK_BIT(PM::All, PM::Predicted));
44  BOOST_CHECK(ACTS_CHECK_BIT(PM::All, PM::Calibrated));
45 
46  auto bs4 = PM::Predicted | PM::Jacobian | PM::Smoothed;
47  BOOST_CHECK(ACTS_CHECK_BIT(bs4, PM::Predicted));
48  BOOST_CHECK(ACTS_CHECK_BIT(bs4, PM::Jacobian));
49  BOOST_CHECK(ACTS_CHECK_BIT(bs4, PM::Smoothed));
50  BOOST_CHECK(!ACTS_CHECK_BIT(bs4, PM::Calibrated));
51  BOOST_CHECK(!ACTS_CHECK_BIT(bs4, PM::Filtered));
52 
53  auto cnv = [](auto a) -> std::bitset<8> {
54  return static_cast<std::underlying_type<PM>::type>(a);
55  };
56 
57  BOOST_CHECK(cnv(PM::All).all()); // all ones
58  BOOST_CHECK(cnv(PM::None).none()); // all zeros
59 
60  // test orthogonality
61  std::array<PM, 5> values{PM::Predicted, PM::Filtered, PM::Smoothed,
62  PM::Jacobian, PM::Calibrated};
63  for (size_t i = 0; i < values.size(); i++) {
64  for (size_t j = 0; j < values.size(); j++) {
65  PM a = values[i];
66  PM b = values[j];
67 
68  if (i == j) {
69  BOOST_CHECK(cnv(a & b).count() == 1);
70  } else {
71  BOOST_CHECK(cnv(a & b).none());
72  }
73  }
74  }
75 
76  BOOST_CHECK(cnv(PM::Predicted ^ PM::Filtered).count() == 2);
77  BOOST_CHECK(cnv(PM::Predicted ^ PM::Predicted).none());
78  BOOST_CHECK(~(PM::Predicted | PM::Calibrated) ==
79  (PM::All ^ PM::Predicted ^ PM::Calibrated));
80 
81  PM base = PM::None;
82  BOOST_CHECK(cnv(base) == 0);
83 
84  base &= PM::Filtered;
85  BOOST_CHECK(cnv(base) == 0);
86 
87  base |= PM::Filtered;
88  BOOST_CHECK(base == PM::Filtered);
89 
90  base |= PM::Calibrated;
91  BOOST_CHECK(base == (PM::Filtered | PM::Calibrated));
92 
93  base ^= PM::All;
94  BOOST_CHECK(base == ~(PM::Filtered | PM::Calibrated));
95 }
96 BOOST_AUTO_TEST_SUITE_END()