SurfYZLineTest.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE ( SurfYZTest )
2 #include "boost/test/unit_test.hpp"
3 
4 //
5 // File: SurfYZLineTest.cxx
6 //
7 // Purpose: Unit test for SurfYZLine.
8 //
9 
10 #include <cmath>
13 #include "cetlib_except/exception.h"
14 
16 auto const tol = 1.e-6% tolerance();
17 
19 {
21  surf1(),
22  surf2(0., 0., 0., 0.),
23  surf3(1., 1., 1., 0.),
24  surf4(2., 2., 2., 1.) {}
25  trkf::SurfYZLine surf1; // Default constructed.
26  trkf::SurfYZLine surf2; // Same as surf1.
27  trkf::SurfYZLine surf3; // Different origin, parallel to surf1 and surf2.
28  trkf::SurfYZLine surf4; // Not parallel.
29 };
30 
31 BOOST_FIXTURE_TEST_SUITE(SurfYZLineTest, SurfYZLineTestFixture)
32 
33 // Test equality comparisons.
34 
36  BOOST_TEST(surf1.isEqual(surf2));
37  BOOST_TEST(!surf1.isEqual(surf3));
38  BOOST_TEST(!surf1.isEqual(surf4));
39  BOOST_TEST(!surf2.isEqual(surf3));
40  BOOST_TEST(!surf2.isEqual(surf4));
41  BOOST_TEST(!surf3.isEqual(surf4));
42 }
43 
44 // Test parallel comparisions.
45 
47  BOOST_TEST(surf1.isParallel(surf2));
48  BOOST_TEST(surf1.isParallel(surf3));
49  BOOST_TEST(!surf1.isParallel(surf4));
50  BOOST_TEST(surf2.isParallel(surf3));
51  BOOST_TEST(!surf2.isParallel(surf4));
52  BOOST_TEST(!surf3.isParallel(surf4));
53 }
54 
55 // Test coordinate transformations.
56 
57 BOOST_AUTO_TEST_CASE(Transformation) {
58  double xyz1[3] = {1., 2., 3.};
59  double xyz2[3];
60  double uvw[3];
61  surf4.toLocal(xyz1, uvw);
62  surf4.toGlobal(uvw, xyz2);
63  for(int i=0; i<3; ++i)
64  BOOST_TEST(xyz1[i] == xyz2[i], tol);
65 }
66 
67 // Test separation.
68 
69 BOOST_AUTO_TEST_CASE(Separation) {
70  BOOST_TEST(surf1.distanceTo(surf2) == 0.);
71  BOOST_TEST(surf1.distanceTo(surf3) == sqrt(2.), tol);
72  BOOST_TEST(surf3.distanceTo(surf1) == sqrt(2.), tol);
73 }
74 
75 // Should throw exception (not parallel).
76 
77 BOOST_AUTO_TEST_CASE(NotParallel) {
78  BOOST_CHECK_EXCEPTION( surf1.distanceTo(surf4), cet::exception,
79  [](cet::exception const & e)
80  {
81  return e.category() == "SurfYZLine";
82  } );
83 }
84 
85 // Test track parameters.
86 
87 BOOST_AUTO_TEST_CASE(TrackParameters) {
88  trkf::TrackVector v(5);
89  v(0) = 0.1; // r.
90  v(1) = 0.2; // v.
91  v(2) = 2.; // phi.
92  v(3) = 1.; // eta.
93  v(4) = 0.5; // p = 2 GeV.
94 
95  double xyz[3];
96  double mom[3];
97  surf1.getPosition(v, xyz);
98  BOOST_TEST(xyz[0] == -0.1*std::sin(2.), tol);
99  BOOST_TEST(xyz[1] == 0.2, tol);
100  BOOST_TEST(xyz[2] == 0.1*std::cos(2.), tol);
101  surf3.getPosition(v, xyz);
102  BOOST_TEST(xyz[0] == 1. - 0.1*std::sin(2.), tol);
103  BOOST_TEST(xyz[1] == 1.2, tol);
104  BOOST_TEST(xyz[2] == 1. + 0.1*std::cos(2.), tol);
106  BOOST_TEST(mom[0] == 2. * std::cos(2.) / std::cosh(1.), tol);
107  BOOST_TEST(mom[1] == 2. * std::tanh(1.), tol);
108  BOOST_TEST(mom[2] == 2. * std::sin(2.) / cosh(1.), tol);
110  BOOST_TEST(mom[0] == 2. * std::cos(2.) / std::cosh(1.), tol);
111  BOOST_TEST(mom[1] == 2. * std::tanh(1.), tol);
112  BOOST_TEST(mom[2] == 2. * std::sin(2.) / cosh(1.), tol);
113  surf1.getMomentum(v, mom);
114  BOOST_TEST(mom[0] == 2. * std::cos(2.) / std::cosh(1.), tol);
115  BOOST_TEST(mom[1] == 2. * std::tanh(1.), tol);
116  BOOST_TEST(mom[2] == 2. * std::sin(2.) / cosh(1.), tol);
117 }
118 
119 BOOST_AUTO_TEST_SUITE_END()
trkf::SurfYZLine surf3
auto const tol
auto const tolerance
virtual void toGlobal(const double uvw[3], double xyz[3]) const
Transform local to global coordinates.
Definition: SurfYZLine.cxx:93
virtual bool isEqual(const Surface &surf) const
Test two surfaces for equality, within tolerance.
Definition: SurfYZLine.cxx:270
trkf::SurfYZLine surf2
virtual void toLocal(const double xyz[3], double uvw[3]) const
Transform global to local coordinates.
Definition: SurfYZLine.cxx:71
trkf::SurfYZLine surf4
trkf::SurfYZLine surf1
virtual void getMomentum(const TrackVector &vec, double mom[3], TrackDirection dir=UNKNOWN) const
Get momentum vector of track.
Definition: SurfYZLine.cxx:161
virtual bool isParallel(const Surface &surf) const
Test whether two surfaces are parallel, within tolerance.
Definition: SurfYZLine.cxx:208
virtual double distanceTo(const Surface &surf) const
Find perpendicular distance to a parallel surface.
Definition: SurfYZLine.cxx:237
const double e
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
Kalman filter linear algebra typedefs.
BOOST_AUTO_TEST_CASE(Equality)
Line surface perpendicular to x-axis.
virtual void getPosition(const TrackVector &vec, double xyz[3]) const
Get position of track.
Definition: SurfYZLine.cxx:134
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33