aggregate_clhep_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (ClhepProduct aggregation Test)
2 #include "MockRun.h"
3 #include "boost/test/unit_test.hpp"
4 
5 #include "CLHEP/Matrix/Matrix.h"
6 #include "CLHEP/Matrix/SymMatrix.h"
7 #include "CLHEP/Matrix/Vector.h"
8 #include "CLHEP/Vector/LorentzVector.h"
9 #include "CLHEP/Vector/ThreeVector.h"
10 #include "CLHEP/Vector/TwoVector.h"
11 
12 using arttest::MockRun;
13 using CLHEP::Hep2Vector;
14 using CLHEP::Hep3Vector;
15 using CLHEP::HepLorentzVector;
16 using CLHEP::HepMatrix;
17 using CLHEP::HepSymMatrix;
18 using CLHEP::HepVector;
19 
20 namespace {
21  double constexpr tolerance = std::numeric_limits<double>::epsilon();
22 }
23 
24 BOOST_AUTO_TEST_SUITE(aggregate_clhep_t)
25 
27 {
28  HepVector a(3, 0);
29  a[0] = 1;
30  a[1] = 2;
31  a[2] = 3;
32 
33  HepVector b(3, 0);
34  b[0] = 3;
35  b[1] = 2;
36  b[2] = 1;
37 
38  MockRun r;
39  r.put<HepVector>(a);
40  r.put<HepVector>(b);
41 
42  auto const& c = r.get<HepVector>();
43  BOOST_CHECK_CLOSE_FRACTION(c[0], 4, tolerance);
44  BOOST_CHECK_CLOSE_FRACTION(c[1], 4, tolerance);
45  BOOST_CHECK_CLOSE_FRACTION(c[2], 4, tolerance);
46 }
47 
49 {
50  MockRun r;
51  r.put<Hep2Vector>(0, 3);
52  r.put<Hep2Vector>(3, 5);
53  auto const& c = r.get<Hep2Vector>();
54  BOOST_CHECK_CLOSE_FRACTION(c[0], 3, tolerance);
55  BOOST_CHECK_CLOSE_FRACTION(c[1], 8, tolerance);
56 }
57 
59 {
60  MockRun r;
61  r.put<Hep3Vector>(0, 3, 19.2);
62  r.put<Hep3Vector>(3, 5, 1.34);
63  auto const& c = r.get<Hep3Vector>();
64  BOOST_CHECK_CLOSE_FRACTION(c[0], 3, tolerance);
65  BOOST_CHECK_CLOSE_FRACTION(c[1], 8, tolerance);
66  BOOST_CHECK_CLOSE_FRACTION(c[2], 20.54, tolerance);
67 }
68 
69 BOOST_AUTO_TEST_CASE(heplorentzvector)
70 {
71  MockRun r;
72  r.put<HepLorentzVector>(0, 3, 19.2, 6);
73  r.put<HepLorentzVector>(3, 5, 1.34, 7);
74  auto const& c = r.get<HepLorentzVector>();
75  BOOST_CHECK_CLOSE_FRACTION(c[0], 3, tolerance);
76  BOOST_CHECK_CLOSE_FRACTION(c[1], 8, tolerance);
77  BOOST_CHECK_CLOSE_FRACTION(c[2], 20.54, tolerance);
78  BOOST_CHECK_CLOSE_FRACTION(c[3], 13, tolerance);
79 }
80 
82 {
83  unsigned constexpr nrows{3};
84  unsigned constexpr ncols{2};
85 
86  HepMatrix m1(nrows, ncols);
87  m1(1, 1) = 1;
88  m1(1, 2) = 0;
89  m1(2, 1) = 0;
90  m1(2, 2) = 1;
91  m1(3, 1) = 1;
92  m1(3, 2) = 1;
93 
94  HepMatrix m2(nrows, ncols);
95  m2(1, 1) = 0;
96  m2(1, 2) = 1;
97  m2(2, 1) = 1;
98  m2(2, 2) = 0;
99  m2(3, 1) = 1;
100  m2(3, 2) = 1;
101 
102  MockRun r;
103  r.put<HepMatrix>(m1);
104  r.put<HepMatrix>(m2);
105 
106  auto const& c = r.get<HepMatrix>();
107  for (unsigned i{1}; i <= 2; ++i)
108  for (unsigned j{1}; j <= 2; ++j)
109  BOOST_CHECK_CLOSE_FRACTION((c(i, j)), 1, tolerance);
110  BOOST_CHECK_CLOSE_FRACTION((c(3, 1)), 2, tolerance);
111  BOOST_CHECK_CLOSE_FRACTION((c(3, 2)), 2, tolerance);
112 }
113 
114 BOOST_AUTO_TEST_CASE(hepsymmatrix)
115 {
116  unsigned constexpr n{2};
117  MockRun r;
118  HepSymMatrix m1(n);
119  m1(1, 1) = 1;
120  m1(1, 2) = 0;
121  m1(2, 1) = 0;
122  m1(2, 2) = 1;
123 
124  HepSymMatrix m2(n);
125  m2(1, 1) = 0;
126  m2(1, 2) = 1;
127  m2(2, 1) = 1;
128  m2(2, 2) = 0;
129 
130  r.put<HepSymMatrix>(m1);
131  r.put<HepSymMatrix>(m2);
132 
133  auto const& c = r.get<HepSymMatrix>();
134  for (unsigned i{1}; i <= n; ++i)
135  for (unsigned j{1}; j <= n; ++j)
136  BOOST_CHECK_CLOSE_FRACTION((c(i, j)), 1, tolerance);
137 }
138 
139 BOOST_AUTO_TEST_SUITE_END()
auto const tolerance
static constexpr double m2
Definition: Units.h:72
std::void_t< T > n
const double a
T get() const
Definition: MockRun.h:24
BOOST_AUTO_TEST_CASE(hepvector)
void put(ARGS &&...args)
Definition: MockRun.h:16
static bool * b
Definition: config.cpp:1043
unsigned nrows(sqlite3 *db, std::string const &tablename)
Definition: helpers.cc:82