Jpp
JOmega3D.hh
Go to the documentation of this file.
1 #ifndef __JOMEGA3D__
2 #define __JOMEGA3D__
3 
4 #include <cmath>
5 #include <vector>
6 
7 #include "JTools/JConstants.hh"
8 #include "JTools/JAngleRange.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 JTOOLS::PI;
24  using JTOOLS::JAngleRange;
25 
26 
27  /**
28  * Base class for direction set.
29  */
30  struct JOmega3D_t :
31  public std::vector<JAngle3D>
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 JAngle3D& 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) solid angle.\n
61  * The set consists of approximately equally spaced directions.\n
62  * In this, the spacing in azimuth angle is zenith angle dependent.
63  */
64  class JOmega3D :
65  public JOmega3D_t
66  {
67  public:
68  /**
69  * Default constructor.
70  */
72  JOmega3D_t()
73  {}
74 
75 
76  /**
77  * Constructor.
78  *
79  * \param dir direction
80  */
81  JOmega3D(const JAngle3D& dir) :
82  JOmega3D_t()
83  {
84  push_back(dir);
85  }
86 
87 
88  /**
89  * Constructor.
90  *
91  * \param grid angular spacing [rad]
92  */
93  JOmega3D(const double grid) :
94  JOmega3D_t()
95  {
96  configure(JAngle3D(0.0,0.0), JAngleRange(0.0,PI), grid);
97  }
98 
99 
100 
101  /**
102  * Constructor.
103  *
104  * \param dir principal direction
105  * \param theta polar angle range [rad]
106  * \param grid angular spacing [rad]
107  */
108  JOmega3D(const JAngle3D& dir,
109  const JAngleRange& theta,
110  const double grid) :
111  JOmega3D_t()
112  {
113  configure(dir, theta, grid);
114  }
115 
116 
117  /**
118  * Configure direction set.
119  *
120  * \param dir principal direction
121  * \param theta polar angle range [rad]
122  * \param grid angular spacing [rad]
123  */
124  void configure(const JAngle3D& dir,
125  const JAngleRange& theta,
126  const double grid)
127  {
128  clear();
129 
130  // sanity checks
131 
132  double thetaMin = theta.getLowerLimit();
133  double thetaMax = theta.getUpperLimit();
134 
135  if (thetaMin < 0.0) { thetaMin = 0.0; }
136  if (thetaMin > PI) { thetaMin = PI; }
137  if (thetaMax < 0.0) { thetaMax = 0.0; }
138  if (thetaMax > PI) { thetaMax = PI; }
139 
140  if (thetaMax > thetaMin) {
141 
142  const JRotation3D R(dir);
143 
144  const double rad = thetaMax - thetaMin;
145  const double bin = rad / floor(rad/(1.4*grid) + 0.5); // polar angle step size
146  const double unit = 2.0 * sqrt(1.0 - cos(grid)); // azimuth angle unit step size
147 
148  for (double theta = thetaMin; theta < thetaMax + 0.5*bin; theta += bin) {
149 
150  double step;
151 
152  if (theta > 0.5*bin && PI - theta > 0.5*bin)
153  step = PI / floor(PI*sin(theta)/unit + 0.5); // polar angle dependent step size
154  else
155  step = 2.0*PI; // pole
156 
157  for (double phi = 0.0; phi < 2.0*PI - 0.5*step; phi += step) {
158  push_back(JDirection3D(JAngle3D(theta,phi)).rotate_back(R));
159  }
160  }
161  }
162  }
163  };
164 }
165 
166 #endif
JGEOMETRY3D::JOmega3D::JOmega3D
JOmega3D(const JAngle3D &dir)
Constructor.
Definition: JOmega3D.hh:81
JGEOMETRY3D::JOmega3D::configure
void configure(const JAngle3D &dir, const JAngleRange &theta, const double grid)
Configure direction set.
Definition: JOmega3D.hh:124
JGEOMETRY3D::JOmega3D::JOmega3D
JOmega3D(const JAngle3D &dir, const JAngleRange &theta, const double grid)
Constructor.
Definition: JOmega3D.hh:108
JDirection3D.hh
JAngleRange.hh
JTOOLS::JAngleRange
JRange< double > JAngleRange
Type definition for angle range.
Definition: JAngleRange.hh:19
std::vector
Definition: JSTDTypes.hh:12
JGEOMETRY3D::JDirection3D
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:32
JGEOMETRY3D::JOmega3D::JOmega3D
JOmega3D(const double grid)
Constructor.
Definition: JOmega3D.hh:93
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
JGEOMETRY3D::JOmega3D_t::find
int find(const JAngle3D &dir) const
Get index of direction closest to given direction.
Definition: JOmega3D.hh:39
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JConstants.hh
JAngle3D.hh
JGEOMETRY3D::JAngle3D
Data structure for angles in three dimensions.
Definition: JAngle3D.hh:31
JRotation3D.hh
JGEOMETRY3D::JOmega3D_t
Base class for direction set.
Definition: JOmega3D.hh:30
JTOOLS::PI
static const double PI
Constants.
Definition: JConstants.hh:20
JGEOMETRY3D
Auxiliary classes and methods for 3D geometrical objects and operations.
Definition: JAngle3D.hh:18
JGEOMETRY3D::JAngle3D::getDot
double getDot(const JAngle3D &angle) const
Get dot product.
Definition: JAngle3D.hh:228
JGEOMETRY3D::JOmega3D
Direction set covering (part of) solid angle.
Definition: JOmega3D.hh:64
JGEOMETRY3D::JOmega3D::JOmega3D
JOmega3D()
Default constructor.
Definition: JOmega3D.hh:71
JGEOMETRY3D::JRotation3D
Rotation matrix.
Definition: JRotation3D.hh:111