Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
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
18namespace JGEOMETRY3D {}
19namespace JPP { using namespace JGEOMETRY3D; }
20
21namespace 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 */
75 {}
76
77
78 /**
79 * Constructor.
80 *
81 * \param dir direction
82 */
83 JOmega3D(const JAngle3D& dir) :
85 {
86 push_back(dir);
87 }
88
89
90 /**
91 * Constructor.
92 *
93 * \param grid angular spacing [rad]
94 */
95 JOmega3D(const double grid) :
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 * Get approximate angular spacing given number of directions.
169 *
170 * \param N number of directions
171 * \return angle [rad]
172 */
173 static inline double getAngle(const size_t N)
174 {
175 if (N != 0)
176 return 10.0 * sqrt((double) 240 / (double) N) * PI / 180.0;
177 else
178 return PI;
179 }
180 };
181
182
183 /**
184 * Auxiliary data structure to group direction sets.
185 */
186 struct JOmega3S_t :
187 JAngle3D, // principle direction
188 JOmega3D // associated direction set
189 {};
190
191
192 /**
193 * Group of direction sets.
194 */
195 struct JOmega3S :
196 std::vector<JOmega3S_t>
197 {
198 /**
199 * Constructor.
200 *
201 * \param omega set of directions
202 * \param group set of directions
203 */
204 JOmega3S(const JOmega3D& omega,
205 const JOmega3D& group)
206 {
207 for (JOmega3D::const_iterator i = group.begin(); i != group.end(); ++i) {
208 this->push_back({*i, {}});
209 }
210
211 for (JOmega3D::const_iterator i = omega.begin(); i != omega.end(); ++i) {
212
213 const int index = group.find(*i);
214
215 (*this)[index].push_back(*i);
216 }
217 }
218
219
220 /**
221 * Constructor.
222 *
223 * \param omega set of directions
224 * \param N number of groups
225 */
226 JOmega3S(const JOmega3D& omega,
227 const size_t N) :
229 {}
230
231
232 /**
233 * Constructor.
234 *
235 * \param grid angular spacing [rad]
236 * \param N number of groups
237 */
238 JOmega3S(const double grid,
239 const size_t N) :
240 JOmega3S(JOmega3D(grid), N)
241 {}
242 };
243}
244
245#endif
Mathematical constants.
Data structure for angles in three dimensions.
Definition JAngle3D.hh:35
double getDot(const JAngle3D &angle) const
Get dot product.
Definition JAngle3D.hh:230
Data structure for direction in three dimensions.
Direction set covering (part of) solid angle.
Definition JOmega3D.hh:68
JOmega3D()
Default constructor.
Definition JOmega3D.hh:73
void configure(const JAngle3D &dir, const range_type &theta, const double grid)
Configure direction set.
Definition JOmega3D.hh:126
JOmega3D(const JAngle3D &dir, const range_type &theta, const double grid)
Constructor.
Definition JOmega3D.hh:110
static double getAngle(const size_t N)
Get approximate angular spacing given number of directions.
Definition JOmega3D.hh:173
JOmega3D(const JAngle3D &dir)
Constructor.
Definition JOmega3D.hh:83
JOmega3D(const double grid)
Constructor.
Definition JOmega3D.hh:95
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition JAngle3D.hh:19
double getAngle(const JQuaternion3D &first, const JQuaternion3D &second)
Get space angle between quanternions.
static const double PI
Mathematical constants.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Base class for direction set.
Definition JOmega3D.hh:31
std::pair< double, double > range_type
Definition JOmega3D.hh:32
int find(const JAngle3D &dir) const
Get index of direction closest to given direction.
Definition JOmega3D.hh:41
Auxiliary data structure to group direction sets.
Definition JOmega3D.hh:189
Group of direction sets.
Definition JOmega3D.hh:197
JOmega3S(const JOmega3D &omega, const JOmega3D &group)
Constructor.
Definition JOmega3D.hh:204
JOmega3S(const JOmega3D &omega, const size_t N)
Constructor.
Definition JOmega3D.hh:226
JOmega3S(const double grid, const size_t N)
Constructor.
Definition JOmega3D.hh:238