Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "JMath/JConstants.hh"
8 
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 namespace JGEOMETRY2D {}
18 namespace JPP { using namespace JGEOMETRY2D; }
19 
20 namespace JGEOMETRY2D {
21 
22  using JMATH::PI;
23 
24 
25  /**
26  * Base class for direction set.
27  */
28  struct JOmega2D_t :
29  public std::vector<JAngle2D>
30  {
31  /**
32  * Get index of direction closest to given direction.
33  *
34  * \param dir direction
35  * \return index (-1 if error)
36  */
37  int find(const JAngle2D& dir) const
38  {
39  double dot = -1.0;
40  int index = -1;
41 
42  for (const_iterator i = this->begin(); i != this->end(); ++i) {
43 
44  const double x = dir.getDot(*i);
45 
46  if (x > dot) {
47  dot = x;
48  index = std::distance(this->begin(), i);
49  }
50  }
51 
52  return index;
53  }
54  };
55 
56 
57  /**
58  * Direction set covering (part of) circle.
59  */
60  class JOmega2D :
61  public JOmega2D_t
62  {
63  public:
64  /**
65  * Default constructor.
66  */
68  JOmega2D_t()
69  {}
70 
71 
72  /**
73  * Constructor.
74  *
75  * \param grid angular spacing [rad]
76  */
77  JOmega2D(const double grid) :
78  JOmega2D_t()
79  {
80  configure(JAngle2D(0.0), PI, grid);
81  }
82 
83 
84 
85  /**
86  * Constructor.
87  *
88  * \param dir principal direction
89  * \param phiMax maximal angle [rad]
90  * \param grid angular spacing [rad]
91  */
92  JOmega2D(const JAngle2D& dir,
93  const double phiMax,
94  const double grid) :
95  JOmega2D_t()
96  {
97  configure(dir, phiMax, grid);
98  }
99 
100 
101  /**
102  * Configure direction set.
103  *
104  * \param dir principal direction
105  * \param phiMax maximal angle [rad]
106  * \param grid angular spacing [rad]
107  */
108  void configure(const JAngle2D& dir,
109  const double phiMax,
110  const double grid)
111  {
112  clear();
113 
114  // sanity checks
115 
116  double phi_min = 0.0;
117  double phi_max = phiMax;
118 
119  if (phi_max < 0.0) phi_max = 0.0;
120  if (phi_max > PI) phi_max = PI;
121 
122  if (phi_max > phi_min) {
123 
124  const double rad = phi_max - phi_min;
125  const double bin = rad / floor(rad/grid + 0.5); // angle step size
126 
127  for (double phi = phi_min; phi < phi_max + 0.5*bin; phi += bin) {
128 
129  if (phi < 0.5*bin) {
130  push_back(dir);
131  } else if (PI - phi < 0.5*bin) {
132  push_back(dir + PI);
133  } else {
134  push_back(dir + phi);
135  push_back(dir - phi);
136  }
137  }
138  }
139  }
140  };
141 }
142 
143 #endif
Data structure for angle in two dimensions.
Definition: JAngle2D.hh:33
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Direction set covering (part of) circle.
Definition: JOmega2D.hh:60
JOmega2D()
Default constructor.
Definition: JOmega2D.hh:67
Mathematical constants.
int find(const JAngle2D &dir) const
Get index of direction closest to given direction.
Definition: JOmega2D.hh:37
static const double PI
Mathematical constants.
double getDot(const JAngle2D &angle) const
Get dot product.
Definition: JAngle2D.hh:189
Base class for direction set.
Definition: JOmega2D.hh:28
void configure(const JAngle2D &dir, const double phiMax, const double grid)
Configure direction set.
Definition: JOmega2D.hh:108
JOmega2D(const JAngle2D &dir, const double phiMax, const double grid)
Constructor.
Definition: JOmega2D.hh:92
JOmega2D(const double grid)
Constructor.
Definition: JOmega2D.hh:77