Belle II Software  release-08-01-10
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 
12 using namespace std;
13 using namespace Belle2;
14 
15 namespace {
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  EXPECT_DOUBLE_EQ(angle - error, myBaseAngle.getLowerIntervalBoundary());
34  EXPECT_DOUBLE_EQ(angle + error, myBaseAngle.getUpperIntervalBoundary());
35  }
36 
37  TEST(Angle, ThetaAngle)
38  {
39  const double angle = 0.4;
40  const double error = 0.2;
41 
42  ThetaAngle myThetaAngle(angle, error);
43  EXPECT_FALSE(myThetaAngle.contains(ThetaAngle(0., 0.)));
44  EXPECT_FALSE(myThetaAngle.contains(ThetaAngle(1.6, 0.)));
45  EXPECT_TRUE(myThetaAngle.contains(ThetaAngle(angle - error / 2, 0.)));
46  EXPECT_TRUE(myThetaAngle.contains(ThetaAngle(angle + error / 2, 0.)));
47 
48  EXPECT_FLOAT_EQ(TMath::PiOver2(), ThetaAngle(TMath::Pi() + TMath::PiOver2(), 0.).getAngle());
49  }
50 
51  TEST(Angle, PhiAngleIntervalNormalCase)
52  {
53  double angle = 0.4;
54  double error = 0.2;
55  PhiAngle myPhiAngle(angle, error);
56  EXPECT_FALSE(myPhiAngle.contains(PhiAngle(0., 0.)));
57  EXPECT_FALSE(myPhiAngle.contains(PhiAngle(TMath::TwoPi(), 0.)));
58  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.)));
59  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.)));
60 
61  EXPECT_FLOAT_EQ(TMath::Pi(), PhiAngle(TMath::TwoPi() + TMath::Pi(), 0.).getAngle());
62  }
63 
64  TEST(Angle, PhiAngleIntervalBreaksZero)
65  {
66  const double angle = 0.1;
67  const double error = 0.3;
68  PhiAngle myPhiAngle(angle, error);
69  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.)));
70  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.)));
71  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.)));
72  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.)));
73  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.)));
74  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.)));
75  }
76 
77  TEST(Angle, PhiAngleIntervalBreaksTwoPi)
78  {
79  const double angle = TMath::TwoPi() - 0.1;
80  const double error = 0.3;
81  PhiAngle myPhiAngle(angle, error);
82  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.)));
83  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.)));
84  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.)));
85  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.)));
86  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.)));
87  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.)));
88  }
89 
90  TEST(Angle, PhiAngleNormalCase)
91  {
92  const double angle = TMath::Pi();
93  const double error = 0.0;
94  PhiAngle myPhiAngle(angle, error);
95  EXPECT_FALSE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.2)));
96  EXPECT_FALSE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.2)));
97  EXPECT_FALSE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
98  EXPECT_FALSE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
99  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.2)));
100  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.2)));
101  }
102 
103  TEST(Angle, PhiAngleBreaksZero)
104  {
105  const double angle = 0.1;
106  const double error = 0.0;
107  PhiAngle myPhiAngle(angle, error);
108  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.2)));
109  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.2)));
110  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
111  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
112  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.2)));
113  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.2)));
114  }
115 
116  TEST(Angle, PhiAngleBreaksTwoPi)
117  {
118  const double angle = TMath::TwoPi() - 0.1;
119  const double error = 0.0;
120  PhiAngle myPhiAngle(angle, error);
121  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 + epsilon, 0.2)));
122  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(0 - epsilon, 0.2)));
123  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
124  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
125  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle - error / 2, 0.2)));
126  EXPECT_TRUE(myPhiAngle.contains(PhiAngle(angle + error / 2, 0.2)));
127  }
128 
129  TEST(Angle, PhiAngleAndErrorBreakTwoPi)
130  {
131  const double angle = -0.0275 + TMath::TwoPi();
132  const double error = 3 * 0.0104;
133  PhiAngle myPhiAngle(angle, error);
134  EXPECT_FALSE(myPhiAngle.containsIn(PhiAngle(2.6, 0), 1));
135  }
136 
137 } // namespace
Class to compare if two angles are compatible withing a given error range.
Definition: Angle.h:24
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.