Belle II Software light-2406-ragdoll
Angle.h
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
9#pragma once
10
11#include <TMath.h>
12
13#include <utility>
14
15namespace Belle2 {
24 class BaseAngle {
25 public:
30 BaseAngle(double angle, double error) : m_angle(angle), m_error(error) {};
31
33 virtual ~BaseAngle() {};
34
37 double getAngle() const { return m_angle; }
38
41 double getError() const { return m_error; }
42
45 double getAngleInDeg() const { return m_angle * TMath::RadToDeg(); }
46
49 double getErrorInDeg() const { return m_error * TMath::RadToDeg(); }
50
51 protected:
52
53 double m_angle;
54 double m_error;
56 };
57
58
63 class ThetaAngle : public BaseAngle {
64 public:
71 ThetaAngle(double angle, double error) : BaseAngle(angle, error)
72 {
73 m_angle = std::fabs(std::fmod(m_angle, TMath::Pi()));
74 }
75
80 bool contains(const ThetaAngle& angle) const
81 {
82 return containsIn(angle, 1);
83 }
84
90 bool containsIn(const ThetaAngle& angle, double sigma) const
91 {
92 double angularDistance, sigmaError;
93 /* Distance in the range [0, pi]. */
94 angularDistance = std::abs(m_angle - angle.getAngle());
95 sigmaError = sigma * (m_error + angle.getError());
96 return angularDistance < sigmaError;
97 }
98
99 };
100
101
106 class PhiAngle : public BaseAngle {
107 public:
114 PhiAngle(double angle, double error) : BaseAngle(angle, error)
115 {
116 /* Angle in the range (-2 * pi, 2 * pi). */
117 m_angle = std::fmod(m_angle, TMath::TwoPi());
118 if (m_angle < 0)
119 m_angle = m_angle + TMath::TwoPi();
120 }
121
126 bool contains(const PhiAngle& angle) const
127 {
128 return containsIn(angle, 1);
129 }
130
136 bool containsIn(const PhiAngle& angle, double sigma) const
137 {
138 double angularDistance, shortestAngularDistance, sigmaError;
139 /* Distance in the range [0, 2 * pi). */
140 angularDistance = std::abs(m_angle - angle.getAngle());
141 /* Distance in the range [0, pi]. */
142 if (angularDistance > TMath::Pi())
143 shortestAngularDistance = TMath::TwoPi() - angularDistance;
144 else
145 shortestAngularDistance = angularDistance;
146 sigmaError = sigma * (m_error + angle.getError());
147 return shortestAngularDistance < sigmaError;
148 }
149
150 };
151
153}
Class to compare if two angles are compatible withing a given error range.
Definition: Angle.h:24
double getErrorInDeg() const
Getter for the error of the angle in degrees.
Definition: Angle.h:49
BaseAngle(double angle, double error)
Constructor.
Definition: Angle.h:30
double getAngle() const
Getter for the angle.
Definition: Angle.h:37
double getError() const
Getter for the error of the angle.
Definition: Angle.h:41
double getAngleInDeg() const
Getter for angle in degrees.
Definition: Angle.h:45
double m_error
Error in rad.
Definition: Angle.h:54
double m_angle
Angle in rad.
Definition: Angle.h:53
virtual ~BaseAngle()
Destructor.
Definition: Angle.h:33
bool containsIn(const PhiAngle &angle, double sigma) const
Check if two angles are compatible.
Definition: Angle.h:136
PhiAngle(double angle, double error)
Constructor using radian units.
Definition: Angle.h:114
bool contains(const PhiAngle &angle) const
Check if two angles are compatible.
Definition: Angle.h:126
ThetaAngle(double angle, double error)
Constructor using radian units.
Definition: Angle.h:71
bool containsIn(const ThetaAngle &angle, double sigma) const
Check if two angles are compatible.
Definition: Angle.h:90
bool contains(const ThetaAngle &angle) const
Check if two angles are compatible.
Definition: Angle.h:80
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24