Jpp 21.0.1
the software that should make you happy
Loading...
Searching...
No Matches
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
11
12
13/**
14 * \file
15 *
16 * Auxiliary methods for selection of reconstructed tracks.
17 * \author mdejong
18 */
19
20/// @brief Setup information from file containing metadata
21/// @param filename Name of the file containing the metadata
22void setup_from_meta_file(const char *filename);
23
24/// @brief Test if the track has a full reconstruction chain
25/// @param track Track
26/// @return True if the reconstruction chain is full
27bool has_all_reco_stages(const Trk &track);
28
29/// @brief Test whether given track has a full jppmuon chain
30/// @param track Track
31/// @return True if the reconstruction chain is full
32bool has_jppmuon_all_reco_stages(const Trk &track);
33
34/// @brief Test whether given track has a full jppshower chain
35/// @param track Track
36/// @return True if the reconstruction chain is full
37bool has_jppshower_all_reco_stages(const Trk &track);
38
39/// @brief Test whether given track has a full aashower chain
40/// @param track Track
41/// @return True if the reconstruction chain is full
42bool has_aashower_all_reco_stages(const Trk &track);
43
44/**
45 * Range of reconstruction stages.
46 */
48 /**
49 * Defaut constructor.
50 */
52 lower(0),
53 upper(std::numeric_limits<int>::max())
54 {}
55
56
57 /**
58 * Constructor.
59 *
60 * \param lower lower reconstruction stage
61 * \param upper upper reconstruction stage
62 */
63 rec_stages_range(const int lower, const int upper) :
64 lower(lower),
66 {}
67
68
69 /**
70 * Constructor.
71 *
72 * \param stage reconstruction stage
73 */
74 rec_stages_range(const int stage) :
75 lower(stage),
76 upper(stage)
77 {}
78
79
80 /**
81 * Test if given reconstruction stage is within range.
82 *
83 * \param stage reconstruction stage
84 * \return true if within range; else false
85 */
86 inline bool operator()(const int stage) const
87 {
88 return (stage >= lower && stage <= upper);
89 }
90
91 int lower;
92 int upper;
93};
94
95
96/**
97 * Reconstruction type dependent comparison of track quality.
98 *
99 * The specialisation of this class should implement the function object operator
100 * <pre>
101 * inline bool operator()(const Trk& first, const Trk& second) const
102 * </pre>
103 * and return true if the first track is better then the second track.
104 */
105template<int reconstruction_type>
107 /**
108 * The default comparison is based on:
109 * -# number of reconstruction stages, i.e. <tt>Trk::rec_stages.size()</tt> (the larger the better);
110 * -# likelihood of the final track, i.e. <tt>Trk::lik</tt> (the larger the better).
111 *
112 * \param first first track
113 * \param second second track
114 * \return true if first track has better quality than second; else false
115 */
116 inline bool operator()(const Trk& first, const Trk& second) const
117 {
118 if (first.rec_stages.size() == second.rec_stages.size())
119 return first.lik > second.lik;
120 else
121 return first.rec_stages.size() > second.rec_stages.size();
122 }
123};
124
125
126/**
127 * Auxiliary class to test whether given track has specified history.\n
128 * The history of a track consists of a reconstruction type and a range of application types.
129 */
131 /**
132 * Constructor.
133 *
134 * \param type reconstruction type
135 * \param range range of application types
136 */
138 type (type),
139 range(range)
140 {}
141
142 /**
143 * \param track track
144 * \return true if given track has specified history; else false
145 */
146 inline bool operator()(const Trk& track) const
147 {
148 if (track.rec_type == type)
149 return std::find_if(track.rec_stages.begin(), track.rec_stages.end(), range) != track.rec_stages.end();
150 else
151 return false;
152 }
153
154 const int type; //!< reconstruction type
155 const rec_stages_range range; //!< range of application types
156};
157
158
159/**
160 * Test whether given track has muon prefit in history.
161 *
162 * \param track track
163 * \return true if muon prefit in history; else false
164 */
165inline bool has_jppmuon_prefit(const Trk& track)
166{
167 return ::has_history(JPP_RECONSTRUCTION_TYPE, JMUONPREFIT)(track);
168}
169
170
171/**
172 * Test whether given track has muon simplex fit in history.
173 *
174 * \param track track
175 * \return true if muon simplex fit in history; else false
176 */
177inline bool has_jppmuon_simplex(const Trk& track)
178{
179 return ::has_history(JPP_RECONSTRUCTION_TYPE, JMUONSIMPLEX)(track);
180}
181
182
183/**
184 * Test whether given track has muon gandalf fit in history.
185 *
186 * \param track track
187 * \return true if muon gandalf fit in history; else false
188 */
189inline bool has_jppmuon_gandalf(const Trk& track)
190{
191 return ::has_history(JPP_RECONSTRUCTION_TYPE, JMUONGANDALF)(track);
192}
193
194
195/**
196 * Test whether given track has muon energy fit in history.
197 *
198 * \param track track
199 * \return true if muon energy fit in history; else false
200 */
201inline bool has_jppmuon_energy(const Trk& track)
202{
203 return ::has_history(JPP_RECONSTRUCTION_TYPE, JMUONENERGY)(track);
204}
205
206
207/**
208 * Test whether given track has muon start fit in history.
209 *
210 * \param track track
211 * \return true if muon start fit in history; else false
212 */
213inline bool has_jppmuon_start(const Trk& track)
214{
215 return ::has_history(JPP_RECONSTRUCTION_TYPE, JMUONSTART)(track);
216}
217
218
219/**
220 * Test whether given track has default muon fit in history.
221 *
222 * \param track track
223 * \return true if muon fit in history; else false
224 */
225inline bool has_jppmuon_fit(const Trk& track)
226{
227 return ::has_history(JPP_RECONSTRUCTION_TYPE, rec_stages_range(JMUONBEGIN, JMUONEND))(track);
228}
229
230/// @brief Test if track has a full jppmuon fit
231/// @param track Track
232/// @return True if it has a full jppmuon fit
233bool has_jppmuon_full_fit(const Trk &track);
234
235/**
236 * Test whether given track has shower prefit in history.
237 *
238 * \param track track
239 * \return true if shower prefit in history; else false
240 */
241inline bool has_shower_prefit(const Trk& track)
242{
243 return ::has_history(JPP_RECONSTRUCTION_TYPE, JSHOWERPREFIT)(track);
244}
245
246
247/**
248 * Test whether given track has shower position fit in history.
249 *
250 * \param track track
251 * \return true if shower position fit in history; else false
252 */
253inline bool has_shower_positionfit(const Trk& track)
254{
255 return ::has_history(JPP_RECONSTRUCTION_TYPE, JSHOWERPOSITIONFIT)(track);
256}
257
258
259/**
260 * Test whether given track has shower complete fit in history.
261 *
262 * \param track track
263 * \return true if shower complete fit in history; else false
264 */
265inline bool has_shower_completefit(const Trk& track)
266{
267 return ::has_history(JPP_RECONSTRUCTION_TYPE, JSHOWERCOMPLETEFIT)(track);
268}
269
270
271/**
272 * Test whether given track has default shower fit in history.
273 *
274 * \param track track
275 * \return true if shower fit in history; else false
276 */
277inline bool has_shower_fit(const Trk& track)
278{
279 return ::has_history(JPP_RECONSTRUCTION_TYPE, rec_stages_range(JSHOWERBEGIN, JSHOWEREND))(track);
280}
281
282/// @brief Test if the track has a full jppshower fit
283/// @param track Track
284/// @return True if the track has a full jppshower fit
285bool has_shower_full_fit(const Trk &track);
286
287/**
288 * Test whether given track has default shower fit in history.
289 *
290 * \param track track
291 * \return true if shower fit in history; else false
292 */
293inline bool has_aashower_fit(const Trk& track)
294{
296}
297
298/// @brief Test if the track has a full aashower fit
299/// @param track Track
300/// @return True if the track has a full aashower fit
301bool has_aashower_full_fit(const Trk &track);
302
303/**
304 * Test whether given event has a track according selection.\n
305 * The track selector corresponds to the function operator <tt>bool selector(const Trk&);</tt>.
306 *
307 * \param evt event
308 * \param selector track selector
309 * \return true if at least one corresponding track; else false
310 */
311template<class JTrackSelector_t>
312inline bool has_reconstructed_track(const Evt& evt, JTrackSelector_t selector)
313{
314 return std::find_if(evt.trks.begin(), evt.trks.end(), selector) != evt.trks.end();
315}
316
317
318/**
319 * Test whether given event has a track according selection.
320 *
321 * \param evt event
322 * \param range range of application types
323 * \return true if at least one corresponding track; else false
324 */
325template<int reconstruction_type>
326inline bool has_reconstructed_track(const Evt& evt, const rec_stages_range range = rec_stages_range())
327{
328 return ::has_reconstructed_track(evt, ::has_history(reconstruction_type, range));
329}
330
331
332/**
333 * Test whether given event has a track with muon reconstruction.
334 *
335 * \param evt event
336 * \return true if at least one reconstructed muon; else false
337 */
338inline bool has_reconstructed_jppmuon(const Evt& evt)
339{
341}
342
343
344/**
345 * Test whether given event has a track with shower reconstruction.
346 *
347 * \param evt event
348 * \return true if at least one reconstructed shower; else false
349 */
350inline bool has_reconstructed_jppshower(const Evt& evt)
351{
353}
354
355
356/**
357 * Test whether given event has a track with aashower reconstruction.
358 *
359 * \param evt event
360 * \return true if at least one reconstructed shower; else false
361 */
362inline bool has_reconstructed_aashower(const Evt& evt)
363{
365}
366
367
368/**
369 * Get best reconstructed track.\n
370 * The track selector corresponds to the function operator <tt>bool selector(const Trk&);</tt> and
371 * the track comparator to <tt>bool comparator(const Trk&, const Trk&);</tt>.\n
372 * This method throws an exception in case no track is present.\n
373 * The method <tt>has_reconstructed_track</tt> can be used to avoid this exception.
374 *
375 * \param evt event
376 * \param selector track selector
377 * \param comparator track comparator
378 * \return track
379 */
380template<class JTrackSelector_t, class JQualitySorter_t>
381inline const Trk& get_best_reconstructed_track(const Evt& evt,
382 JTrackSelector_t selector,
383 JQualitySorter_t comparator)
384{
385 std::vector<Trk>::const_iterator p = std::find_if(evt.trks.begin(), evt.trks.end(), selector);
386
387 for (std::vector<Trk>::const_iterator i = p; i != evt.trks.end(); ++i) {
388 if (selector(*i) && comparator(*i, *p)) {
389 p = i;
390 }
391 }
392
393 if (p != evt.trks.end())
394 return *p;
395 else
396 THROW(Exception, "This event has no reconstructed track with given selector.");
397}
398
399
400/**
401 * Get best reconstructed track.
402 *
403 * \param evt event
404 * \param range range of application types
405 * \return track
406 */
407template<int reconstruction_type>
408inline const Trk& get_best_reconstructed_track(const Evt& evt, const rec_stages_range range = rec_stages_range())
409{
410 return get_best_reconstructed_track(evt, ::has_history(reconstruction_type, range), quality_sorter<reconstruction_type>());
411}
412
413
414/**
415 * Get best reconstructed muon.
416 *
417 * \param evt event
418 * \return track
419 */
424
425
426/**
427 * Get best reconstructed shower.
428 *
429 * \param evt event
430 * \return track
431 */
436
437
438/**
439 * Get best reconstructed aashower.
440 *
441 * \param evt event
442 * \return track
443 */
448
449#endif
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
static const int JMUONBEGIN
begin range of reconstruction stages
static const int AASHOWERBEGIN
begin range of reconstruction stages
static const int JSHOWEREND
end range of reconstruction stages
static const int JPP_RECONSTRUCTION_TYPE
ile KM3NeT Data Definitions v3.6.5 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 JSHOWERBEGIN
begin range of reconstruction stages
static const int JMUONEND
end range of reconstruction stages
General exception.
Definition Exception.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 identifiers of successful 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.
const Trk & get_best_reconstructed_jppshower(const Evt &evt)
Get best reconstructed shower.
bool has_jppmuon_gandalf(const Trk &track)
Test whether given track has muon gandalf fit in history.
bool has_jppmuon_full_fit(const Trk &track)
Test if track has a full jppmuon fit.
bool has_jppmuon_start(const Trk &track)
Test whether given track has muon start fit in history.
const Trk & get_best_reconstructed_jppmuon(const Evt &evt)
Get best reconstructed muon.
bool has_jppmuon_simplex(const Trk &track)
Test whether given track has muon simplex fit in history.
bool has_all_reco_stages(const Trk &track)
Test if the track has a full reconstruction chain.
bool has_reconstructed_jppshower(const Evt &evt)
Test whether given event has a track with shower reconstruction.
bool has_aashower_all_reco_stages(const Trk &track)
Test whether given track has a full aashower chain.
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.
const Trk & get_best_reconstructed_track(const Evt &evt, JTrackSelector_t selector, JQualitySorter_t comparator)
Get best reconstructed track.
bool has_shower_positionfit(const Trk &track)
Test whether given track has shower position fit in history.
const Trk & get_best_reconstructed_aashower(const Evt &evt)
Get best reconstructed aashower.
bool has_aashower_fit(const Trk &track)
Test whether given track has default shower fit in history.
bool has_shower_full_fit(const Trk &track)
Test if the track has a full jppshower fit.
void setup_from_meta_file(const char *filename)
Setup information from file containing metadata.
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.
bool has_jppshower_all_reco_stages(const Trk &track)
Test whether given track has a full jppshower chain.
bool has_jppmuon_all_reco_stages(const Trk &track)
Test whether given track has a full jppmuon chain.
bool has_jppmuon_energy(const Trk &track)
Test whether given track has muon energy fit in history.
bool has_aashower_full_fit(const Trk &track)
Test if the track has a full aashower fit.