Jpp
JOmega2D.hh
Go to the documentation of this file.
1 #ifndef __JOMEGA2D__
2 #define __JOMEGA2D__
3 
4 #include <cmath>
5 #include <vector>
6 
7 #include "JTools/JConstants.hh"
8 #include "JTools/JAngleRange.hh"
9 
10 #include "JGeometry2D/JAngle2D.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JGEOMETRY2D {}
19 namespace JPP { using namespace JGEOMETRY2D; }
20 
21 namespace JGEOMETRY2D {
22 
23  using JTOOLS::PI;
24  using JTOOLS::JAngleRange;
25 
26 
27  /**
28  * Base class for direction set.
29  */
30  struct JOmega2D_t :
31  public std::vector<JAngle2D>
32  {
33  /**
34  * Get index of direction closest to given direction.
35  *
36  * \param dir direction
37  * \return index (-1 if error)
38  */
39  int find(const JAngle2D& dir) const
40  {
41  double dot = -1.0;
42  int index = -1;
43 
44  for (const_iterator i = this->begin(); i != this->end(); ++i) {
45 
46  const double x = dir.getDot(*i);
47 
48  if (x > dot) {
49  dot = x;
50  index = std::distance(this->begin(), i);
51  }
52  }
53 
54  return index;
55  }
56  };
57 
58 
59  /**
60  * Direction set covering (part of) circle.
61  */
62  class JOmega2D :
63  public JOmega2D_t
64  {
65  public:
66  /**
67  * Default constructor.
68  */
70  JOmega2D_t()
71  {}
72 
73 
74  /**
75  * Constructor.
76  *
77  * \param grid angular spacing [rad]
78  */
79  JOmega2D(const double grid) :
80  JOmega2D_t()
81  {
82  configure(JAngle2D(0.0), PI, grid);
83  }
84 
85 
86 
87  /**
88  * Constructor.
89  *
90  * \param dir principal direction
91  * \param phiMax maximal angle [rad]
92  * \param grid angular spacing [rad]
93  */
94  JOmega2D(const JAngle2D& dir,
95  const double phiMax,
96  const double grid) :
97  JOmega2D_t()
98  {
99  configure(dir, phiMax, grid);
100  }
101 
102 
103  /**
104  * Configure direction set.
105  *
106  * \param dir principal direction
107  * \param phiMax maximal angle [rad]
108  * \param grid angular spacing [rad]
109  */
110  void configure(const JAngle2D& dir,
111  const double phiMax,
112  const double grid)
113  {
114  clear();
115 
116  // sanity checks
117 
118  double phi_min = 0.0;
119  double phi_max = phiMax;
120 
121  if (phi_max < 0.0) phi_max = 0.0;
122  if (phi_max > PI) phi_max = PI;
123 
124  if (phi_max > phi_min) {
125 
126  const double rad = phi_max - phi_min;
127  const double bin = rad / floor(rad/grid + 0.5); // angle step size
128 
129  for (double phi = phi_min; phi < phi_max + 0.5*bin; phi += bin) {
130 
131  if (phi < 0.5*bin) {
132  push_back(dir);
133  } else if (PI - phi < 0.5*bin) {
134  push_back(dir + PI);
135  } else {
136  push_back(dir + phi);
137  push_back(dir - phi);
138  }
139  }
140  }
141  }
142  };
143 }
144 
145 #endif
JGEOMETRY2D::JOmega2D::JOmega2D
JOmega2D(const double grid)
Constructor.
Definition: JOmega2D.hh:79
JAngle2D.hh
JAngleRange.hh
JTOOLS::JAngleRange
JRange< double > JAngleRange
Type definition for angle range.
Definition: JAngleRange.hh:19
std::vector
Definition: JSTDTypes.hh:12
distance
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Definition: PhysicsEvent.hh:434
JRotation2D.hh
JGEOMETRY2D
Auxiliary classes and methods for 2D geometrical objects and operations.
Definition: JAngle2D.hh:18
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JConstants.hh
JGEOMETRY2D::JOmega2D::JOmega2D
JOmega2D()
Default constructor.
Definition: JOmega2D.hh:69
JGEOMETRY2D::JOmega2D_t
Base class for direction set.
Definition: JOmega2D.hh:30
JGEOMETRY2D::JAngle2D
Data structure for angle in two dimensions.
Definition: JAngle2D.hh:31
JGEOMETRY2D::JOmega2D_t::find
int find(const JAngle2D &dir) const
Get index of direction closest to given direction.
Definition: JOmega2D.hh:39
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JGEOMETRY2D::JOmega2D::configure
void configure(const JAngle2D &dir, const double phiMax, const double grid)
Configure direction set.
Definition: JOmega2D.hh:110
JGEOMETRY2D::JOmega2D::JOmega2D
JOmega2D(const JAngle2D &dir, const double phiMax, const double grid)
Constructor.
Definition: JOmega2D.hh:94
JGEOMETRY2D::JAngle2D::getDot
double getDot(const JAngle2D &angle) const
Get dot product.
Definition: JAngle2D.hh:187
JGEOMETRY2D::JOmega2D
Direction set covering (part of) circle.
Definition: JOmega2D.hh:62