Jpp  19.1.0-rc.1
the software that should make you happy
JDetectorSubset.hh
Go to the documentation of this file.
1 #ifndef __JDETECTOR__JDETECTORSUBSET__
2 #define __JDETECTOR__JDETECTORSUBSET__
3 
4 #include <algorithm>
5 #include <limits>
6 
9 #include "JGeometry3D/JAxis3D.hh"
11 #include "JTools/JRange.hh"
12 #include "JDetector/JDetector.hh"
14 
15 
16 /**
17  * \file
18  *
19  * Auxiliary class to extract a subset of optical modules from a detector.
20  * \author mdejong
21  */
22 namespace JDETECTOR {}
23 namespace JPP { using namespace JDETECTOR; }
24 
25 namespace JDETECTOR {
26 
32  using JTOOLS::JRange;
33 
34 
35  /**
36  * Detector subset without binary search functionality.
37  */
39  public std::vector<JModule>
40  {
41  public:
42  /**
43  * Constructor.
44  *
45  * The positions and orientations of the modules and the PMTs after the transformation
46  * are relative to given particle track (see ANTARES-SOFT 2010-002).
47  * Only modules within given road width and z-axis range are accepted.
48  *
49  * \param detector detector
50  * \param track particle track
51  * \param Rmax maximal distance of approach [m]
52  * \param Z range of positions along z-axis [m]
53  */
54  JDetectorSubset_t(const JDetector& detector,
55  const JAxis3D& track,
56  const double Rmax = std::numeric_limits<double>::max(),
57  const JRange<double>& Z = JRange<double>())
58  {
59  const JTransformation3D transformation(track.getPosition(), track.getDirection());
60 
61  JModule module;
62 
63  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
64 
65  JPosition3D pos(i->getPosition());
66 
67  pos.transform(transformation.getRotation(), transformation.getPosition());
68 
69  if (Z(pos.getZ()) && pos.getX() <= Rmax) {
70 
71  module = *i;
72 
73  module.transform(transformation);
74 
75  this->push_back(module);
76  }
77  }
78  }
79 
80 
81  /**
82  * Constructor.
83  *
84  * The positions and orientations of the modules and the PMTs
85  * are offset with respect to given position.
86  * Only modules within given distance are accepted.
87  *
88  * \param detector detector
89  * \param position position of vertex
90  * \param Dmax maximal distance [m]
91  */
92  JDetectorSubset_t(const JDetector& detector,
93  const JVector3D& position,
94  const double Dmax = std::numeric_limits<double>::max())
95  {
96  for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
97 
98  JPosition3D pos(i->getPosition());
99 
100  pos.sub(position);
101 
102  if (pos.getLength() <= Dmax) {
103 
104  JModule module(*i);
105 
106  module.sub(position);
107 
108  this->push_back(module);
109  }
110  }
111  }
112  };
113 
114 
115  /**
116  * Detector subset with binary search functionality.
117  */
118  template<class JComparator_t>
120  public JDetectorSubset_t
121  {
122  public:
123  /**
124  * Auxiliary class for range of iterators.
125  */
126  struct range_type {
127  /**
128  * Constructor.
129  *
130  * \param begin begin of iteration
131  * \param end end of iteration
132  */
133  range_type(const_iterator begin,
134  const_iterator end) :
135  __begin(begin),
136  __end (end)
137  {}
138 
139  inline const_iterator begin() const { return __begin; } //!< begin of iteration
140  inline const_iterator end() const { return __end; } //!< end of iteration
141 
142  bool empty() const { return __begin == __end; } //!< check emptyness
143 
144  protected:
145  const_iterator __begin;
146  const_iterator __end;
147  };
148 
149 
150  /**
151  * Constructor.
152  *
153  * See constructor JDetectorSubset_t::JDetectorSubset_t.
154  * The modules are sorted according the specified comparator.
155  *
156  * \param detector detector
157  * \param track particle track
158  * \param comparator comparator
159  * \param Rmax maximal distance of approach [m]
160  * \param Z range of positions along z-axis [m]
161  */
162  JDetectorSubset(const JDetector& detector,
163  const JAxis3D& track,
164  const JComparator_t& comparator,
165  const double Rmax = std::numeric_limits<double>::max(),
166  const JRange<double>& Z = JRange<double>()) :
167  JDetectorSubset_t(detector, track, Rmax, Z),
168  compare(comparator)
169  {
170  std::sort(this->begin(), this->end(), compare);
171  }
172 
173 
174  /**
175  * Constructor.
176  *
177  * See constructor JDetectorSubset_t::JDetectorSubset_t.
178  * The modules are sorted according the default comparator.
179  *
180  * \param detector detector
181  * \param track particle track
182  * \param Rmax maximal distance of approach [m]
183  * \param Z range of positions along z-axis [m]
184  */
185  JDetectorSubset(const JDetector& detector,
186  const JAxis3D& track,
187  const double Rmax = std::numeric_limits<double>::max(),
188  const JRange<double>& Z = JRange<double>()) :
189  JDetectorSubset_t(detector, track, Rmax, Z),
190  compare()
191  {
192  std::sort(this->begin(), this->end(), compare);
193  }
194 
195 
196  /**
197  * Constructor.
198  *
199  * See constructor JDetectorSubset_t::JDetectorSubset_t.
200  * The modules are sorted according the specified comparator.
201  *
202  * \param detector detector
203  * \param position position of vertex
204  * \param comparator comparator
205  * \param Dmax maximal distance [m]
206  */
207  JDetectorSubset(const JDetector& detector,
208  const JVector3D& position,
209  const JComparator_t& comparator,
210  const double Dmax = std::numeric_limits<double>::max()) :
211  JDetectorSubset_t(detector, position, Dmax),
212  compare(comparator)
213  {
214  std::sort(this->begin(), this->end(), compare);
215  }
216 
217 
218  /**
219  * Constructor.
220  *
221  * See constructor JDetectorSubset_t::JDetectorSubset_t.
222  * The modules are sorted according the default comparator.
223  *
224  * \param detector detector
225  * \param position position of vertex
226  * \param Dmax maximal distance [m]
227  */
228  JDetectorSubset(const JDetector& detector,
229  const JVector3D& position,
230  const double Dmax = std::numeric_limits<double>::max()) :
231  JDetectorSubset_t(detector, position, Dmax),
232  compare()
233  {
234  std::sort(this->begin(), this->end(), compare);
235  }
236 
237 
238  /**
239  * Get comparator.
240  *
241  * \return compartor
242  */
243  const JComparator_t& getComparator() const
244  {
245  return compare;
246  }
247 
248 
249  /**
250  * Find first module after given value according specified comparator.
251  *
252  * \param value value
253  * \return iterator to module
254  */
255  const_iterator lower_bound(const double value) const
256  {
257  return std::lower_bound(this->begin(), this->end(), value, compare);
258  }
259 
260 
261  /**
262  * Get range of modules between given values according specified comparator.
263  *
264  * \param xmin minimal value
265  * \param xmax maximal value
266  * \return range of iterators
267  */
268  range_type getRange(const double xmin,
269  const double xmax) const
270  {
271  return range_type(this->lower_bound(xmin),
272  this->lower_bound(xmax));
273  }
274 
275  protected:
276  const JComparator_t compare;
277  };
278 }
279 
280 #endif
Data structure for detector geometry and calibration.
Auxiliary classes to compare modules.
Auxiliary class to define a range between two values.
Detector subset without binary search functionality.
JDetectorSubset_t(const JDetector &detector, const JVector3D &position, const double Dmax=std::numeric_limits< double >::max())
Constructor.
JDetectorSubset_t(const JDetector &detector, const JAxis3D &track, const double Rmax=std::numeric_limits< double >::max(), const JRange< double > &Z=JRange< double >())
Constructor.
Detector subset with binary search functionality.
const JComparator_t compare
const JComparator_t & getComparator() const
Get comparator.
const_iterator lower_bound(const double value) const
Find first module after given value according specified comparator.
JDetectorSubset(const JDetector &detector, const JAxis3D &track, const double Rmax=std::numeric_limits< double >::max(), const JRange< double > &Z=JRange< double >())
Constructor.
range_type getRange(const double xmin, const double xmax) const
Get range of modules between given values according specified comparator.
JDetectorSubset(const JDetector &detector, const JVector3D &position, const JComparator_t &comparator, const double Dmax=std::numeric_limits< double >::max())
Constructor.
JDetectorSubset(const JDetector &detector, const JVector3D &position, const double Dmax=std::numeric_limits< double >::max())
Constructor.
JDetectorSubset(const JDetector &detector, const JAxis3D &track, const JComparator_t &comparator, const double Rmax=std::numeric_limits< double >::max(), const JRange< double > &Z=JRange< double >())
Constructor.
Detector data structure.
Definition: JDetector.hh:96
Data structure for a composite optical module.
Definition: JModule.hh:75
void transform(const JRotation3D &R, const JVector3D &pos)
Transformation of geometry (see method JGEOMETRY3D::JPosition3D::transform(const JRotation3D&,...
Definition: JModule.hh:345
JModule & sub(const JVector3D &pos)
Subtract position.
Definition: JModule.hh:437
Axis object.
Definition: JAxis3D.hh:41
Data structure for direction in three dimensions.
Definition: JDirection3D.hh:35
const JDirection3D & getDirection() const
Get direction.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:38
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:130
void transform(const JRotation3D &R, const JVector3D &pos)
Transform position.
Definition: JPosition3D.hh:331
const JRotation3D & getRotation() const
Get rotation.
Definition: JRotation3D.hh:272
Data structure for vector in three dimensions.
Definition: JVector3D.hh:36
double getLength() const
Get length.
Definition: JVector3D.hh:246
double getZ() const
Get z position.
Definition: JVector3D.hh:115
JVector3D & sub(const JVector3D &vector)
Subtract vector.
Definition: JVector3D.hh:158
double getX() const
Get x position.
Definition: JVector3D.hh:94
Range of values.
Definition: JRange.hh:42
const double xmax
Definition: JQuadrature.cc:24
const double xmin
Definition: JQuadrature.cc:23
file Auxiliary data structures and methods for detector calibration.
Definition: JAnchor.hh:12
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JRange< int > range_type
Auxiliary class for range of iterators.
bool empty() const
check emptyness
const_iterator begin() const
begin of iteration
range_type(const_iterator begin, const_iterator end)
Constructor.
const_iterator end() const
end of iteration