Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOmega3D.hh
Go to the documentation of this file.
1 #ifndef __JOMEGA3D__
2 #define __JOMEGA3D__
3 
4 #include <cmath>
5 #include <utility>
6 #include <vector>
7 
8 #include "JMath/JConstants.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JGEOMETRY3D {}
19 namespace JPP { using namespace JGEOMETRY3D; }
20 
21 namespace JGEOMETRY3D {
22 
23  using JMATH::PI;
24 
25 
26  /**
27  * Base class for direction set.
28  */
29  struct JOmega3D_t :
30  public std::vector<JAngle3D>
31  {
33 
34 
35  /**
36  * Get index of direction closest to given direction.
37  *
38  * \param dir direction
39  * \return index (-1 if error)
40  */
41  int find(const JAngle3D& dir) const
42  {
43  double dot = -1.0;
44  int index = -1;
45 
46  for (const_iterator i = this->begin(); i != this->end(); ++i) {
47 
48  const double x = dir.getDot(*i);
49 
50  if (x > dot) {
51  dot = x;
52  index = std::distance(this->begin(), i);
53  }
54  }
55 
56  return index;
57  }
58  };
59 
60 
61  /**
62  * Direction set covering (part of) solid angle.\n
63  * The set consists of approximately equally spaced directions.\n
64  * In this, the spacing in azimuth angle is zenith angle dependent.
65  */
66  class JOmega3D :
67  public JOmega3D_t
68  {
69  public:
70  /**
71  * Default constructor.
72  */
74  JOmega3D_t()
75  {}
76 
77 
78  /**
79  * Constructor.
80  *
81  * \param dir direction
82  */
83  JOmega3D(const JAngle3D& dir) :
84  JOmega3D_t()
85  {
86  push_back(dir);
87  }
88 
89 
90  /**
91  * Constructor.
92  *
93  * \param grid angular spacing [rad]
94  */
95  JOmega3D(const double grid) :
96  JOmega3D_t()
97  {
98  configure(JAngle3D(0.0,0.0), range_type(0.0,PI), grid);
99  }
100 
101 
102 
103  /**
104  * Constructor.
105  *
106  * \param dir principal direction
107  * \param theta polar angle range [rad]
108  * \param grid angular spacing [rad]
109  */
110  JOmega3D(const JAngle3D& dir,
111  const range_type& theta,
112  const double grid) :
113  JOmega3D_t()
114  {
115  configure(dir, theta, grid);
116  }
117 
118 
119  /**
120  * Configure direction set.
121  *
122  * \param dir principal direction
123  * \param theta polar angle range [rad]
124  * \param grid angular spacing [rad]
125  */
126  void configure(const JAngle3D& dir,
127  const range_type& theta,
128  const double grid)
129  {
130  clear();
131 
132  // sanity checks
133 
134  double thetaMin = theta.first;
135  double thetaMax = theta.second;
136 
137  if (thetaMin < 0.0) { thetaMin = 0.0; }
138  if (thetaMin > PI) { thetaMin = PI; }
139  if (thetaMax < 0.0) { thetaMax = 0.0; }
140  if (thetaMax > PI) { thetaMax = PI; }
141 
142  if (thetaMax > thetaMin) {
143 
144  const JRotation3D R(dir);
145 
146  const double rad = thetaMax - thetaMin;
147  const double bin = rad / floor(rad/(1.4*grid) + 0.5); // polar angle step size
148  const double unit = 2.0 * sqrt(1.0 - cos(grid)); // azimuth angle unit step size
149 
150  for (double theta = thetaMin; theta < thetaMax + 0.5*bin; theta += bin) {
151 
152  double step;
153 
154  if (theta > 0.5*bin && PI - theta > 0.5*bin)
155  step = PI / floor(PI*sin(theta)/unit + 0.5); // polar angle dependent step size
156  else
157  step = 2.0*PI; // pole
158 
159  for (double phi = 0.0; phi < 2.0*PI - 0.5*step; phi += step) {
160  push_back(JDirection3D(JAngle3D(theta,phi)).rotate_back(R));
161  }
162  }
163  }
164  }
165  };
166 }
167 
168 #endif
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:33
JOmega3D(const JAngle3D &dir, const range_type &theta, const double grid)
Constructor.
Definition: JOmega3D.hh:110
JOmega3D()
Default constructor.
Definition: JOmega3D.hh:73
Data structure for direction in three dimensions.
Definition: JDirection3D.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.
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JAngle3D.hh:230
Rotation matrix.
Definition: JRotation3D.hh:111
Direction set covering (part of) solid angle.
Definition: JOmega3D.hh:66
std::pair< double, double > range_type
Definition: JOmega3D.hh:32
JOmega3D(const double grid)
Constructor.
Definition: JOmega3D.hh:95
Mathematical constants.
static const double PI
Mathematical constants.
int find(const JAngle3D &dir) const
Get index of direction closest to given direction.
Definition: JOmega3D.hh:41
then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:43
void configure(const JAngle3D &dir, const range_type &theta, const double grid)
Configure direction set.
Definition: JOmega3D.hh:126
Base class for direction set.
Definition: JOmega3D.hh:29
JOmega3D(const JAngle3D &dir)
Constructor.
Definition: JOmega3D.hh:83