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