Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGeometry3DToolkit.hh
Go to the documentation of this file.
1 #ifndef __JGEOMETRY3DTOOLKIT__
2 #define __JGEOMETRY3DTOOLKIT__
3 
4 #include <iterator>
5 
7 
10 
11 #include "JPhysics/JConstants.hh"
12 
13 #include "JMath/JMathToolkit.hh"
14 
15 
16 /**
17  * \author mdejong
18  */
19 
20 /**
21  * Auxiliary classes and methods for 3D geometrical objects and operations.
22  */
23 namespace JGEOMETRY3D {}
24 namespace JPP { using namespace JGEOMETRY3D; }
25 
26 namespace JGEOMETRY3D {
27 
28  using JMATH::getDistance;
29 
30 
31  /**
32  * Center.
33  */
34  class JCenter3D :
35  public JPosition3D
36  {
37  public:
38  /**
39  * Constructor.
40  *
41  * \param p0 first position
42  * \param p1 second position
43  */
44  JCenter3D(const JVector3D& p0,
45  const JVector3D& p1) :
46  JPosition3D()
47  {
48  add(p0);
49  add(p1);
50 
51  div(2);
52  }
53 
54 
55  /**
56  * Constructor.
57  *
58  * \param p0 first position
59  * \param p1 second position
60  * \param p2 third position
61  */
62  JCenter3D(const JVector3D& p0,
63  const JVector3D& p1,
64  const JVector3D& p2) :
65  JPosition3D()
66  {
67  add(p0);
68  add(p1);
69  add(p2);
70 
71  div(3);
72  }
73 
74 
75  /**
76  * Constructor.
77  *
78  * \param __begin begin of data
79  * \param __end end of data
80  */
81  template<class T>
82  JCenter3D(T __begin,
83  T __end) :
84  JPosition3D()
85  {
86  if (__begin != __end) {
87 
88  for (T i = __begin; i != __end; ++i) {
89  add(*i);
90  }
91 
92  div(std::distance(__begin, __end));
93  }
94  }
95  };
96 
97 
98  /**
99  * Weighed center.
100  */
102  public JPosition3D
103  {
104  public:
105  /**
106  * Constructor.
107  *
108  * \param __begin begin of data
109  * \param __end end of data
110  */
111  template<class T>
113  T __end) :
114  JPosition3D()
115  {
116  if (__begin != __end) {
117 
118  double __w = 0.0;
119 
120  for (T i = __begin; i != __end; ++i) {
121  __x += i->getX() * i->getW();
122  __y += i->getY() * i->getW();
123  __z += i->getZ() * i->getW();
124  __w += i->getW();
125  }
126 
127  div(__w);
128  }
129  }
130  };
131 
132 
133  /**
134  * Auxiliary class for determination of smallest distance between pair of 3D points.
135  */
137  protected:
138  /**
139  * Recursive method to find the smallest distance.
140  *
141  * \param __begin begin of data
142  * \param __end end of data
143  * \return minimal distance
144  */
145  template<class T>
146  static double getDmin(T __begin, T __end)
147  {
148  using namespace std;
149 
150  const int N = distance(__begin, __end);
151 
152  if (N <= 3) {
153 
154  double Dmin = numeric_limits<double>::max();
155 
156  for (T i = __begin; i != __end; ++i) {
157  for (T j = i; ++j != __end; ) {
158 
159  const double d = getDistance(*i, *j);
160 
161  if (d < Dmin) {
162  Dmin = d;
163  }
164  }
165  }
166 
167  return Dmin;
168 
169  } else {
170 
171  T i = __begin;
172 
173  advance(i, N/2);
174 
175  const double dl = getDmin(__begin, i);
176  const double dr = getDmin(i, __end);
177 
178  const double Dmin = min(dl, dr);
179 
180  T il = i;
181  T ir = i;
182 
183  while (--il != __begin && i ->getZ() - il->getZ() < Dmin) {}
184  while (++ir != __end && ir->getZ() - i ->getZ() < Dmin) {}
185 
186  const double dz = JGEOMETRY2D::getSmallestDistance2D(++il, ir, Dmin);
187 
188  sort(il, ir, compareZ);
189 
190  return min(Dmin, dz);
191  }
192  }
193 
194 
195  /**
196  * Auxiliary class for sorting elements.
197  */
198  struct JCompareZ {
199  /**
200  * Compare x-positions of given points.
201  *
202  * \param first first point
203  * \param second second point
204  * \return true if x of first point less than that of second; else false
205  */
206  template<class T>
207  inline bool operator()(const T& first, const T& second) const
208  {
209  return first.getZ() < second.getZ();
210  }
211  };
212 
213 
214  public:
215  /**
216  * Default constructor.
217  */
219  {}
220 
221 
222  static const JCompareZ compareZ; //!< Function object for sorting elements.
223 
224 
225  /**
226  * Get smallest distance between two points.\n
227  * Note that this method changes the order of the elements.
228  *
229  * \param __begin begin of data
230  * \param __end end of data
231  * \return minimal distance
232  */
233  template<class T>
234  double operator()(T __begin, T __end) const
235  {
236  using namespace std;
237 
238  sort(__begin, __end, compareZ);
239 
240  return getDmin(__begin, __end);
241  }
242  };
243 
244 
245  /**
246  * Auxiliary function to retrieve the maximum cylindrical containment volume.
247  *
248  * \return maximum cylindrical containment volume
249  */
251  {
252  using namespace JPP;
253 
254  const double R_Earth = R_EARTH_KM * 1e3; // m
255 
256  const JVector2D center(0.0, 0.0);
257  const JCircle2D circle(center, R_Earth);
258 
259  return JCylinder3D(circle, -R_Earth, R_Earth);
260  }
261 
262 
263  /**
264  * Function object for smallest distance determination.
265  */
267 }
268 
269 #endif
270 
271 
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
static const JSmallestDistance3D getSmallestDistance3D
Function object for smallest distance determination.
static const double R_EARTH_KM
Geophysics constants.
TPaveText * p1
Auxiliary methods for geometrical methods.
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Data structure for circle in two dimensions.
Definition: JCircle2D.hh:33
JSmallestDistance3D()
Default constructor.
static const JSmallestDistance2D getSmallestDistance2D
Function object for smallest distance determination.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double getDistance(const JFirst_t &first, const JSecond_t &second)
Get distance between objects.
static double getDmin(T __begin, T __end)
Recursive method to find the smallest distance.
JCenter3D(T __begin, T __end)
Constructor.
Cylinder object.
Definition: JCylinder3D.hh:39
Data structure for vector in three dimensions.
Definition: JVector3D.hh:34
static const JCompareZ compareZ
Function object for sorting elements.
const JCylinder3D getMaximumContainmentVolume()
Auxiliary function to retrieve the maximum cylindrical containment volume.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Physics constants.
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
double operator()(T __begin, T __end) const
Get smallest distance between two points.
p2
Definition: module-Z:fit.sh:74
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:47
JCenter3D(const JVector3D &p0, const JVector3D &p1, const JVector3D &p2)
Constructor.
JCenter3D(const JVector3D &p0, const JVector3D &p1)
Constructor.
Auxiliary class for sorting elements.
int j
Definition: JPolint.hh:703
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
JVector3D & div(const double factor)
Scale vector.
Definition: JVector3D.hh:190
JWeighedCenter3D(T __begin, T __end)
Constructor.
bool operator()(const T &first, const T &second) const
Compare x-positions of given points.
JVector3D & add(const JVector3D &vector)
Add vector.
Definition: JVector3D.hh:142
Auxiliary class for determination of smallest distance between pair of 3D points. ...