Belle II Software development
angle.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <framework/utilities/Angle.h>
9
10#include <gtest/gtest.h>
11
12using namespace std;
13using namespace Belle2;
14
15namespace {
16 double constexpr epsilon = 1e-7;
17
18 TEST(Angle, BaseAngle)
19 {
20 class TestBaseAngle : public BaseAngle {
21 public:
22 TestBaseAngle(double angle, double error) : BaseAngle(angle, error) {};
23 };
24
25 const double angle = TMath::PiOver2();
26 const double error = TMath::PiOver4();
27
28 TestBaseAngle myBaseAngle(angle, error);
29 EXPECT_DOUBLE_EQ(angle, myBaseAngle.getAngle());
30 EXPECT_DOUBLE_EQ(error, myBaseAngle.getError());
31 EXPECT_DOUBLE_EQ(angle * TMath::RadToDeg(), myBaseAngle.getAngleInDeg());
32 EXPECT_DOUBLE_EQ(error * TMath::RadToDeg(), myBaseAngle.getErrorInDeg());
33 }
34
35 TEST(Angle, ThetaAngle)
36 {
37 const double angle = 0.4;
38 const double error = 0.2;
39
40 ThetaAngle myThetaAngle(angle, error);
41 EXPECT_FALSE(myThetaAngle.contains(ThetaAngle(0., 0.)));
42 EXPECT_FALSE(myThetaAngle.contains(ThetaAngle(1.6, 0.)));
43 EXPECT_TRUE(myThetaAngle.contains(ThetaAngle(angle - error / 2, 0.)));
44 EXPECT_TRUE(myThetaAngle.contains(ThetaAngle(angle + error / 2, 0.)));
45
46 EXPECT_FLOAT_EQ(TMath::PiOver2(), ThetaAngle(TMath::Pi() + TMath::PiOver2(), 0.).getAngle());
47 }
48
49 TEST(Angle, PhiAngleIntervalNormalCase)
50 {
51 double angle = 0.4;
52 double error = 0.2;
53 PhiAngle myPhiAngle(angle, error);
54 EXPECT_FALSE(myPhiAngle.contains(PhiAngle(0., 0.)));
55 EXPECT_FALSE(myPhiAngle.contains(PhiAngle(TMath::TwoPi(), 0.)));
56 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.)));
57 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.)));
58
59 EXPECT_FLOAT_EQ(TMath::Pi(), PhiAngle(TMath::TwoPi() + TMath::Pi(), 0.).getAngle());
60 }
61
62 TEST(Angle, PhiAngleIntervalBreaksZero)
63 {
64 const double angle = 0.1;
65 const double error = 0.3;
66 PhiAngle myPhiAngle(angle, error);
67 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.)));
68 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.)));
69 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.)));
70 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.)));
71 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.)));
72 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.)));
73 }
74
75 TEST(Angle, PhiAngleIntervalBreaksTwoPi)
76 {
77 const double angle = TMath::TwoPi() - 0.1;
78 const double error = 0.3;
79 PhiAngle myPhiAngle(angle, error);
80 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.)));
81 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.)));
82 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.)));
83 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.)));
84 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.)));
85 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.)));
86 }
87
88 TEST(Angle, PhiAngleNormalCase)
89 {
90 const double angle = TMath::Pi();
91 const double error = 0.0;
92 PhiAngle myPhiAngle(angle, error);
93 EXPECT_FALSE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.2)));
94 EXPECT_FALSE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.2)));
95 EXPECT_FALSE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
96 EXPECT_FALSE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
97 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.2)));
98 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.2)));
99 }
100
101 TEST(Angle, PhiAngleBreaksZero)
102 {
103 const double angle = 0.1;
104 const double error = 0.0;
105 PhiAngle myPhiAngle(angle, error);
106 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.2)));
107 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.2)));
108 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
109 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
110 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.2)));
111 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.2)));
112 }
113
114 TEST(Angle, PhiAngleBreaksTwoPi)
115 {
116 const double angle = TMath::TwoPi() - 0.1;
117 const double error = 0.0;
118 PhiAngle myPhiAngle(angle, error);
119 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.2)));
120 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.2)));
121 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
122 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
123 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.2)));
124 EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.2)));
125 }
126
127 TEST(Angle, PhiAngleAndErrorBreakTwoPi)
128 {
129 const double angle = -0.0275 + TMath::TwoPi();
130 const double error = 3 * 0.0104;
131 PhiAngle myPhiAngle(angle, error);
132 EXPECT_FALSE(myPhiAngle.containsIn(PhiAngle(2.6, 0), 1));
133 }
134
135} // namespace
Class to compare if two angles are compatible withing a given error range.
Definition: Angle.h:24
Abstract base class for different kinds of events.
STL namespace.