Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EqualityHelpers.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EqualityHelpers.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 #pragma once
10 
11 #include <boost/test/unit_test.hpp>
12 
13 #include "Acts/Geometry/Extent.hpp"
17 
18 #include <iostream>
19 
20 namespace Acts {
21 
29 inline static bool isEqual(const BinningData& ba, const BinningData& bb,
30  float tolerance) {
31  bool equalBool = (ba.type == bb.type) and (ba.option == bb.option) and
32  (ba.binvalue == bb.binvalue) and (ba.zdim == bb.zdim) and
34 
35  BOOST_CHECK(equalBool);
36  bool equalRange = (std::abs(ba.min - bb.min) < tolerance) and
37  (std::abs(ba.max - bb.max) < tolerance) and
38  (std::abs(ba.step - bb.step) < tolerance);
39 
40  BOOST_CHECK(equalRange);
41  bool euqalStructure =
42  (ba.subBinningData != nullptr)
43  ? isEqual(*ba.subBinningData, *bb.subBinningData, tolerance)
44  : (bb.subBinningData == nullptr);
45 
46  BOOST_CHECK(euqalStructure);
47 
48  bool equalBoundaries = (ba.boundaries().size() == bb.boundaries().size());
49  if (equalBoundaries) {
50  for (size_t ib = 0; ib < ba.boundaries().size(); ++ib) {
51  equalBoundaries =
52  (std::abs(ba.boundaries()[ib] - bb.boundaries()[ib]) < tolerance);
53  if (not equalBoundaries) {
54  break;
55  }
56  }
57  }
58  BOOST_CHECK(equalBoundaries);
59 
60  return equalBool and equalRange and euqalStructure;
61 }
62 
70 inline static bool isEqual(const BinUtility& ba, const BinUtility& bb,
71  float tolerance) {
72  bool equal = (ba.binningData().size() == bb.binningData().size());
73  BOOST_CHECK(equal);
74  if (equal) {
75  for (size_t ib = 0; ib < ba.binningData().size(); ++ib) {
76  equal = isEqual(ba.binningData()[ib], bb.binningData()[ib], tolerance);
77  BOOST_CHECK(equal);
78  }
79  }
80  return equal;
81 }
82 
90 inline static bool isEqual(const Acts::Extent& ea, const Acts::Extent& eb,
92  bool equalConstrains = true;
93  bool equalRange = true;
94  for (auto& bVal : s_binningValues) {
95  equalConstrains =
96  equalConstrains and (ea.constrains(bVal) == eb.constrains(bVal));
97  BOOST_CHECK(equalConstrains);
98  if (ea.constrains(bVal) and eb.constrains(bVal)) {
99  equalRange =
100  equalRange and std::abs(ea.min(bVal) - eb.min(bVal)) < tolerance;
101  equalRange =
102  equalRange and std::abs(ea.max(bVal) - eb.max(bVal)) < tolerance;
103  BOOST_CHECK(equalRange);
104  }
105  }
106  BOOST_CHECK(equalConstrains);
107  BOOST_CHECK(equalRange);
108  return equalRange and equalConstrains;
109 }
110 
111 } // namespace Acts