Jpp  19.1.0-rc.1
the software that should make you happy
tools/reconstruction.hh
Go to the documentation of this file.
1 #ifndef __TOOLS_RECONSTRUCTION__
2 #define __TOOLS_RECONSTRUCTION__
3 
4 #include <limits>
5 #include <algorithm>
6 
13 
14 
15 /**
16  * \file
17  *
18  * Auxiliary methods for selection of reconstructed tracks.
19  * \author mdejong
20  */
21 
22 
23 /**
24  * Range of reconstruction stages.
25  */
27  /**
28  * Defaut constructor.
29  */
31  lower(0),
32  upper(std::numeric_limits<int>::max())
33  {}
34 
35 
36  /**
37  * Constructor.
38  *
39  * \param lower lower reconstruction stage
40  * \param upper upper reconstruction stage
41  */
42  rec_stages_range(const int lower, const int upper) :
43  lower(lower),
44  upper(upper)
45  {}
46 
47 
48  /**
49  * Constructor.
50  *
51  * \param stage reconstruction stage
52  */
53  rec_stages_range(const int stage) :
54  lower(stage),
55  upper(stage)
56  {}
57 
58 
59  /**
60  * Test if given reconstruction stage is within range.
61  *
62  * \param stage reconstruction stage
63  * \return true if within range; else false
64  */
65  inline bool operator()(const int stage) const
66  {
67  return (stage >= lower && stage <= upper);
68  }
69 
70  int lower;
71  int upper;
72 };
73 
74 
75 /**
76  * Reconstruction type dependent comparison of track quality.
77  *
78  * The specialisation of this class should implement the function object operator
79  * <pre>
80  * inline bool operator()(const Trk& first, const Trk& second) const
81  * </pre>
82  * and return true if the first track is better then the second track.
83  */
84 template<int reconstruction_type>
86  /**
87  * The default comparison is based on:
88  * -# number of reconstruction stages, i.e. <tt>Trk::rec_stages.size()</tt> (the larger the better);
89  * -# likelihood of the final track, i.e. <tt>Trk::lik</tt> (the larger the better).
90  *
91  * \param first first track
92  * \param second second track
93  * \return true if first track has better quality than second; else false
94  */
95  inline bool operator()(const Trk& first, const Trk& second) const
96  {
97  if (first.rec_stages.size() == second.rec_stages.size())
98  return first.lik > second.lik;
99  else
100  return first.rec_stages.size() > second.rec_stages.size();
101  }
102 };
103 
104 
105 /**
106  * Auxiliary class to test whether given track has specified history.\n
107  * The history of a track consists of a reconstruction type and a range of application types.
108  */
109 struct has_history {
110  /**
111  * Constructor.
112  *
113  * \param type reconstruction type
114  * \param range range of application types
115  */
117  type (type),
118  range(range)
119  {}
120 
121  /**
122  * \param track track
123  * \return true if given track has specified history; else false
124  */
125  inline bool operator()(const Trk& track) const
126  {
127  if (track.rec_type == type)
128  return std::find_if(track.rec_stages.begin(), track.rec_stages.end(), range) != track.rec_stages.end();
129  else
130  return false;
131  }
132 
133  const int type; //!< reconstruction type
134  const rec_stages_range range; //!< range of application types
135 };
136 
137 
138 /**
139  * Test whether given track has muon prefit in history.
140  *
141  * \param track track
142  * \return true if muon prefit in history; else false
143  */
144 inline bool has_jppmuon_prefit(const Trk& track)
145 {
147 }
148 
149 
150 /**
151  * Test whether given track has muon simplex fit in history.
152  *
153  * \param track track
154  * \return true if muon simplex fit in history; else false
155  */
156 inline bool has_jppmuon_simplex(const Trk& track)
157 {
159 }
160 
161 
162 /**
163  * Test whether given track has muon gandalf fit in history.
164  *
165  * \param track track
166  * \return true if muon gandalf fit in history; else false
167  */
168 inline bool has_jppmuon_gandalf(const Trk& track)
169 {
171 }
172 
173 
174 /**
175  * Test whether given track has muon energy fit in history.
176  *
177  * \param track track
178  * \return true if muon energy fit in history; else false
179  */
180 inline bool has_jppmuon_energy(const Trk& track)
181 {
183 }
184 
185 
186 /**
187  * Test whether given track has muon start fit in history.
188  *
189  * \param track track
190  * \return true if muon start fit in history; else false
191  */
192 inline bool has_jppmuon_start(const Trk& track)
193 {
195 }
196 
197 
198 /**
199  * Test whether given track has default muon fit in history.
200  *
201  * \param track track
202  * \return true if muon fit in history; else false
203  */
204 inline bool has_jppmuon_fit(const Trk& track)
205 {
207 }
208 
209 
210 /**
211  * Test whether given track has shower prefit in history.
212  *
213  * \param track track
214  * \return true if shower prefit in history; else false
215  */
216 inline bool has_shower_prefit(const Trk& track)
217 {
219 }
220 
221 
222 /**
223  * Test whether given track has shower position fit in history.
224  *
225  * \param track track
226  * \return true if shower position fit in history; else false
227  */
228 inline bool has_shower_positionfit(const Trk& track)
229 {
231 }
232 
233 
234 /**
235  * Test whether given track has shower complete fit in history.
236  *
237  * \param track track
238  * \return true if shower complete fit in history; else false
239  */
240 inline bool has_shower_completefit(const Trk& track)
241 {
243 }
244 
245 
246 /**
247  * Test whether given track has default shower fit in history.
248  *
249  * \param track track
250  * \return true if shower fit in history; else false
251  */
252 inline bool has_shower_fit(const Trk& track)
253 {
255 }
256 
257 
258 /**
259  * Test whether given track has default shower fit in history.
260  *
261  * \param track track
262  * \return true if shower fit in history; else false
263  */
264 inline bool has_aashower_fit(const Trk& track)
265 {
267 }
268 
269 
270 /**
271  * Test whether given event has a track according selection.\n
272  * The track selector corresponds to the function operator <tt>bool selector(const Trk&);</tt>.
273  *
274  * \param evt event
275  * \param selector track selector
276  * \return true if at least one corresponding track; else false
277  */
278 template<class JTrackSelector_t>
279 inline bool has_reconstructed_track(const Evt& evt, JTrackSelector_t selector)
280 {
281  return std::find_if(evt.trks.begin(), evt.trks.end(), selector) != evt.trks.end();
282 }
283 
284 
285 /**
286  * Test whether given event has a track according selection.
287  *
288  * \param evt event
289  * \param range range of application types
290  * \return true if at least one corresponding track; else false
291  */
292 template<int reconstruction_type>
293 inline bool has_reconstructed_track(const Evt& evt, const rec_stages_range range = rec_stages_range())
294 {
295  return ::has_reconstructed_track(evt, ::has_history(reconstruction_type, range));
296 }
297 
298 
299 /**
300  * Test whether given event has a track with muon reconstruction.
301  *
302  * \param evt event
303  * \return true if at least one reconstructed muon; else false
304  */
305 inline bool has_reconstructed_jppmuon(const Evt& evt)
306 {
308 }
309 
310 
311 /**
312  * Test whether given event has a track with shower reconstruction.
313  *
314  * \param evt event
315  * \return true if at least one reconstructed shower; else false
316  */
317 inline bool has_reconstructed_jppshower(const Evt& evt)
318 {
320 }
321 
322 
323 /**
324  * Test whether given event has a track with aashower reconstruction.
325  *
326  * \param evt event
327  * \return true if at least one reconstructed shower; else false
328  */
329 inline bool has_reconstructed_aashower(const Evt& evt)
330 {
332 }
333 
334 
335 /**
336  * Get best reconstructed track.\n
337  * The track selector corresponds to the function operator <tt>bool selector(const Trk&);</tt> and
338  * the track comparator to <tt>bool comparator(const Trk&, const Trk&);</tt>.\n
339  * This method throws an exception in case no track is present.\n
340  * The method <tt>has_reconstructed_track</tt> can be used to avoid this exception.
341  *
342  * \param evt event
343  * \param selector track selector
344  * \param comparator track comparator
345  * \return track
346  */
347 template<class JTrackSelector_t, class JQualitySorter_t>
348 inline const Trk& get_best_reconstructed_track(const Evt& evt,
349  JTrackSelector_t selector,
350  JQualitySorter_t comparator)
351 {
352  std::vector<Trk>::const_iterator p = std::find_if(evt.trks.begin(), evt.trks.end(), selector);
353 
354  for (std::vector<Trk>::const_iterator i = p; i != evt.trks.end(); ++i) {
355  if (selector(*i) && comparator(*i, *p)) {
356  p = i;
357  }
358  }
359 
360  if (p != evt.trks.end())
361  return *p;
362  else
363  THROW(Exception, "This event has no reconstructed track with given selector.");
364 }
365 
366 
367 /**
368  * Get best reconstructed track.
369  *
370  * \param evt event
371  * \param range range of application types
372  * \return track
373  */
374 template<int reconstruction_type>
375 inline const Trk& get_best_reconstructed_track(const Evt& evt, const rec_stages_range range = rec_stages_range())
376 {
377  return get_best_reconstructed_track(evt, ::has_history(reconstruction_type, range), quality_sorter<reconstruction_type>());
378 }
379 
380 
381 /**
382  * Get best reconstructed muon.
383  *
384  * \param evt event
385  * \return track
386  */
387 inline const Trk& get_best_reconstructed_jppmuon(const Evt& evt)
388 {
390 }
391 
392 
393 /**
394  * Get best reconstructed shower.
395  *
396  * \param evt event
397  * \return track
398  */
399 inline const Trk& get_best_reconstructed_jppshower(const Evt& evt)
400 {
402 }
403 
404 
405 /**
406  * Get best reconstructed aashower.
407  *
408  * \param evt event
409  * \return track
410  */
411 inline const Trk& get_best_reconstructed_aashower(const Evt& evt)
412 {
414 }
415 
416 #endif
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
General exception.
Definition: Exception.hh:13
static const int JMUONBEGIN
begin range of reconstruction stages
static const int JSHOWERPOSITIONFIT
static const int AASHOWERBEGIN
begin range of reconstruction stages
static const int JSHOWEREND
end range of reconstruction stages
static const int JMUONGANDALF
static const int JMUONPREFIT
static const int JPP_RECONSTRUCTION_TYPE
KM3NeT Data Definitions v3.4.0-8-ge14cb17 https://git.km3net.de/common/km3net-dataformat.
static const int AASHOWEREND
end range of reconstruction stages
static const int AANET_RECONSTRUCTION_TYPE
aanet reconstruction type
static const int JMUONENERGY
static const int JSHOWERCOMPLETEFIT
static const int JSHOWERPREFIT
static const int JMUONSIMPLEX
static const int JSHOWERBEGIN
begin range of reconstruction stages
static const int JMUONSTART
static const int JMUONEND
end range of reconstruction stages
bool has_history(const JFit &fit, const int type)
Test whether given fit has specified history.
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
std::vector< Trk > trks
list of reconstructed tracks (can be several because of prefits,showers, etc).
Definition: Evt.hh:39
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition: Trk.hh:15
std::vector< int > rec_stages
list of identifyers of succesfull fitting stages resulting in this track
Definition: Trk.hh:26
int rec_type
identifier of the fitting algorithm/chain/strategy, see km3net-dataformat/definitions/reconstruction....
Definition: Trk.hh:25
double lik
likelihood or lambda value (for aafit, lambda)
Definition: Trk.hh:23
Auxiliary class to test whether given track has specified history.
const int type
reconstruction type
has_history(const int type, const rec_stages_range range)
Constructor.
const rec_stages_range range
range of application types
bool operator()(const Trk &track) const
Reconstruction type dependent comparison of track quality.
bool operator()(const Trk &first, const Trk &second) const
The default comparison is based on:
Range of reconstruction stages.
rec_stages_range(const int lower, const int upper)
Constructor.
bool operator()(const int stage) const
Test if given reconstruction stage is within range.
rec_stages_range()
Defaut constructor.
rec_stages_range(const int stage)
Constructor.
bool has_jppmuon_gandalf(const Trk &track)
Test whether given track has muon gandalf fit in history.
const Trk & get_best_reconstructed_track(const Evt &evt, JTrackSelector_t selector, JQualitySorter_t comparator)
Get best reconstructed track.
bool has_jppmuon_start(const Trk &track)
Test whether given track has muon start fit in history.
const Trk & get_best_reconstructed_jppshower(const Evt &evt)
Get best reconstructed shower.
bool has_jppmuon_simplex(const Trk &track)
Test whether given track has muon simplex fit in history.
bool has_reconstructed_jppshower(const Evt &evt)
Test whether given event has a track with shower reconstruction.
bool has_reconstructed_aashower(const Evt &evt)
Test whether given event has a track with aashower reconstruction.
bool has_reconstructed_track(const Evt &evt, JTrackSelector_t selector)
Test whether given event has a track according selection.
bool has_shower_prefit(const Trk &track)
Test whether given track has shower prefit in history.
bool has_jppmuon_prefit(const Trk &track)
Test whether given track has muon prefit in history.
bool has_shower_positionfit(const Trk &track)
Test whether given track has shower position fit in history.
bool has_aashower_fit(const Trk &track)
Test whether given track has default shower fit in history.
bool has_jppmuon_fit(const Trk &track)
Test whether given track has default muon fit in history.
bool has_reconstructed_jppmuon(const Evt &evt)
Test whether given event has a track with muon reconstruction.
bool has_shower_completefit(const Trk &track)
Test whether given track has shower complete fit in history.
bool has_shower_fit(const Trk &track)
Test whether given track has default shower fit in history.
const Trk & get_best_reconstructed_aashower(const Evt &evt)
Get best reconstructed aashower.
bool has_jppmuon_energy(const Trk &track)
Test whether given track has muon energy fit in history.
const Trk & get_best_reconstructed_jppmuon(const Evt &evt)
Get best reconstructed muon.