TrajectoryPointFlags.h
Go to the documentation of this file.
1 /**
2  * @file lardataobj/RecoBase/TrajectoryPointFlags.h
3  * @brief Set of flags pertaining a point of the track.
4  * @author Giuseppe Cerati (cerati@fnal.gov),
5  * Gianluca Petrillo (petrillo@fnal.gov)
6  * @date January 18, 2017
7  *
8  */
9 
10 #ifndef LARDATAOBJ_RECOBASE_TRAJECTORYPOINTFLAGS_H
11 #define LARDATAOBJ_RECOBASE_TRAJECTORYPOINTFLAGS_H
12 
13 // LArSoft libraries
16 
17 // C/C++ standard libraries
18 #include <array>
19 #include <string>
20 #include <limits> // std::numeric_limits<>
21 #include <utility> // std::forward(), std::declval()
22 #include <iosfwd> // std::ostream
23 
24 namespace recob {
25 
26 
27  /**
28  * @brief Namespace for the trajectory point flags
29  *
30  * This class is a glorified namespace for the definition of named flags.
31  *
32  * Each flag must have an identifier that is of integral type `FlagIndex_t`.
33  * There are four types of flags: pertaining a trajectory (and pattern
34  * recognition output), pertaining a track (and track fit output),
35  * experiment specific and user specific.
36  *
37  * The trajectory flags have a meaning in the bare context of reconstructed
38  * trajectory in space and patter recognition (see `recob::Trajectory` and
39  * see `recob::TrackTrajectory`), and they should preserve the same meaning
40  * after fitting into a track.
41  *
42  * The track flags have a meaning only in the context of a track
43  * (see `recob::Track`).
44  *
45  * The experiment-specific flags are placeholders that are expected to get
46  * a meaning that is consistent within a single experiment, and unrelated
47  * between experiments.
48  *
49  * The user-specific flags are placeholders that are expected to get a
50  * meaning that is specific to an algorithm. Objects from different
51  * algorithms will give these flags unrelated meaning.
52  *
53  * Code shared in LArSoft using the flags should rely only on the flags of
54  * the first two categories. Code that requires access to
55  * experiment-specific flags should be also experiment-specific.
56  *
57  */
59 
60  /// Number of flags allocated (may be unused and unassigned).
61  static constexpr unsigned int MaxFlags = 32;
62 
63  /// Type of mask of bits.
65 
66  /// Type of mask of bits.
68 
69  /// Type of single flag.
71 
72  /// Type of index of a single flag.
74 
75  /// @{
76  /**
77  * @name Trajectory flags.
78  *
79  * The definition of the flags will result somehow ambiguous, because it
80  * requires a judgement that is in the end arbitrary enough that it may be
81  * inconsistent between different algorithms.
82  *
83  * The design idea is that typically at most one flag is set. For example,
84  * if a hit is known to be associated to another trajectory, the point will
85  * be marked as `Shared` but not `Merged`, and if it is `Merged` or `Shared`
86  * it will not be flagged as `Suspicious`.
87  * Exceptions may apply. For example, a hit known to be shared with a
88  * &delta; ray which is reconstructed as a distinct trajectory may have both
89  * the `Shared` and the `DeltaRay` flags.
90  *
91  * Also note that there may be better ways than these flags to discover
92  * information. For example, the `DetectorIssue` flag might have been left
93  * unset because no check was done on the actual data quality, or because
94  * the failure of the channel was not yet known at the time the trajectory
95  * was reconstructed.
96  *
97  *
98  * Implementation note
99  * --------------------
100  *
101  * The single flags are of type `Flag_t`, which is effectively represented
102  * as a bit mask with a single bit set.
103  * The boundary flag indices instead are actual indices (type `FlagIndex_t`)
104  * which allows them to be beyond the range of the mask (think especially
105  * to `EndExperimentReservedFlags`, whose value of @f$ 2^{32} @f$ is just
106  * beyond the range of a 32-bit integer).
107  * Each flag can yield its index by the `index()` method, and this can be
108  * used to compare them to flag indices.
109  *
110  */
111 
112  /// First trajectory flag index.
113  static constexpr FlagIndex_t BeginTrajectoryFlags = 0;
114 
115  /// Hit was not included for the computation of the trajectory.
116  static constexpr Flag_t HitIgnored { 0 };
117 
118  /// The trajectory point is not defined.
119  static constexpr Flag_t NoPoint { 1 };
120 
121  /**
122  * @brief The point reconstruction is somehow questionable.
123  * @see Merged, DeltaRay
124  *
125  * For example, the hit might look ambiguous but there is no evidence of
126  * another track nearby or a &delta; ray emission. Reconstruction of the
127  * point might be biased, but we can't guess which type of bias we have.
128  */
129  static constexpr Flag_t Suspicious { 2 };
130 
131  /// The hit might have contribution from particles other than this.
132  static constexpr Flag_t Merged { 3 };
133 
134  /// The hit might have contribution from a &delta; ray.
135  static constexpr Flag_t DeltaRay { 4 };
136 
137  /// The hit is associated to a problematic channel.
138  static constexpr Flag_t DetectorIssue { 5 };
139 
140  /// The hit is known to be associated also to another trajectory.
141  static constexpr Flag_t Shared { 6 };
142 
143  /// Reserved for a future trajectory flag.
144  static constexpr Flag_t TrajReserved1 { 7 };
145 
146  /// After-the-last trajectory flag index
147  static constexpr FlagIndex_t EndTrajectoryFlags = 8;
148 
149  /// @}
150  //------------------------------------------------------------------------
151  /// @{
152  /**
153  * @name Track flags.
154  *
155  * As for the trajectory flags, the ones pertaining the track fitting are
156  * designed to be set in the most exclusive way possible.
157  *
158  * For example, a hit that is `Rejected` is not flagged as `ExcludedFromFit`
159  * (although it is indeed not included in the fit).
160  *
161  *
162  */
163 
164  /// First track flag index.
166 
167  /// The point belongs to this track but it was not included in the fit
168  /// because dubious in some sense.
169  static constexpr Flag_t ExcludedFromFit { 8 };
170 
171  /// The hit is extraneous to this track.
172  static constexpr Flag_t Rejected { 9 };
173 
174  /**
175  * @brief The hit content has been elaborated before being used in the fit.
176  *
177  * In this case, it is good practise for the fitting algorithm to associate
178  * the fitted point to the new hit.
179  * Nevertheless, a simpler code might assume that all associated hits are
180  * from the same data product, and fail to find the new one which will
181  * necessarily have to belong to a new hit collection.
182  *
183  * If you find yourself in the situation where you consider setting this
184  * flag, it may be useful to consult with LArSoft experts to determine if
185  * further support is needed for your use case.
186  */
187  static constexpr Flag_t Reinterpreted { 10 };
188 
189  /// Reserved for a future track flag.
190  static constexpr Flag_t TrackReserved5 { 11 };
191 
192  /// Reserved for a future track flag.
193  static constexpr Flag_t TrackReserved4 { 12 };
194 
195  /// Reserved for a future track flag.
196  static constexpr Flag_t TrackReserved3 { 13 };
197 
198  /// Reserved for a future track flag.
199  static constexpr Flag_t TrackReserved2 { 14 };
200 
201  /// Reserved for a future track flag.
202  static constexpr Flag_t TrackReserved1 { 15 };
203 
204  /// After-the-last track flag index.
205  static constexpr FlagIndex_t EndTrackFlags = 16;
206 
207  /// @}
208  //------------------------------------------------------------------------
209  /// @{
210  /// @name Flag reserved for the experiments (not to be used in LArSoft).
211 
212  /// First flag reserved to experiment.
214 
215  /// After-the-last flag reserved to experiment.
217 
218  /// @}
219  //------------------------------------------------------------------------
220  /// @{
221  /// @name Flag reserved for the users (algorithm-specific).
222 
223  /// First flag reserved to users.
224  static constexpr FlagIndex_t BeginUserReservedFlags
226 
227  /// After-the-last flag reserved to users.
228  static constexpr FlagIndex_t EndUserReservedFlags = 32;
229  /// @}
230  //------------------------------------------------------------------------
231 
232 
233  /// Number of flags allocated (may be unused and unassigned).
234  static constexpr FlagIndex_t maxFlags() { return MaxFlags; }
235 
236 
237  /// Returns whether the specified index represents a valid flag
238  static constexpr bool isFlag(Flag_t flag)
239  { return flag.index() < MaxFlags; }
240 
241  /// @{
242  /// @name Flag names
243 
244  /// Returns a string with the name of the specified flag
245  static std::string name(Flag_t flag)
246  {
247  return isFlag(flag)? names[flag.index()]: invalidFlagName(flag.index());
248  }
249 
250  /// Type storing flag names.
251  using NameMap_t = std::array<std::string, MaxFlags>;
252 
253  /// Returns a map of flag names.
254  static NameMap_t initNames();
255 
256  /// @}
257 
258  private:
259  static_assert(EndTrajectoryFlags <= BeginTrackFlags,
260  "Too many trajectory flags");
261  static_assert(EndTrackFlags <= BeginExperimentReservedFlags,
262  "Too many track flags");
263  static_assert(
264  EndExperimentReservedFlags <= BeginUserReservedFlags,
265  "Too many experiment-defined flags"
266  );
267  static_assert(EndUserReservedFlags <= MaxFlags,
268  "Too many user-defined flags");
269 
270  static const NameMap_t names; ///< Names of the flags.
271 
272  /// Combines a base name and an index into a flag name.
274 
275  /// Returns the name of an invalid flag with the specified index.
276  static std::string invalidFlagName(Flag_t flag);
277 
278  /// Initializes a range of flag names with default (decorated) names.
279  static void initDefaultFlagRangeNames(
280  NameMap_t& flagNames,
281  FlagIndex_t BeginFlags, FlagIndex_t EndFlags, std::string baseName
282  );
283 
284  /// Initialises all flag names with a default name.
285  static void initDefaultFlagsNames(NameMap_t& flagNames);
286 
287  /// Sets the names of the flags after default initialization.
288  static void setFlagNames(NameMap_t& flagNames);
289 
290  }; // class TrajectoryPointFlagTraits
291 
292 
293  /**
294  * @brief Set of flags pertaining a point of the track.
295  * @tparam FlagTraits type with the definition of the flag values
296  * @see recob::TrackTrajectory
297  *
298  * The "flags" contain metadata pertaining a single point in a trajectory
299  * or track.
300  *
301  * The metadata includes:
302  * * a set of flags, including some for a trajectory, some specific to a
303  * fitted track, some reserved for future use and some available to the
304  * users
305  * * an index pointing to the position of the hit in an originating
306  * trajectory, if such a trajectory exists. The specific convention to use
307  * this index must be documented by the using class (see
308  * `recob::TrackTrajectory`)
309  *
310  * The meaning of the flags is described in the FlagTraits type.
311  * This type needs to provide a `maxFlags()` static constexpr method to
312  * express how many flags should be stored, d
313  *
314  */
316 
317  public:
318 
319  /// Type of flag traits (indices and meaning of flags).
321 
322 
323  using Flags_t = flag::Flags_t; ///< Type holding the flags.
324 
325  using Mask_t = Flags_t::Mask_t; ///< Type holding the flags.
326 
327  using Flag_t = Flags_t::Flag_t; ///< Type of single flag.
328 
329  using FlagIndex_t = Flags_t::FlagIndex_t; ///< Type of index of single flag.
330 
331  using HitIndex_t = unsigned int; ///< Type for hit index.
332 
333 
334  /// Value marking an invalid hit index.
335  static constexpr HitIndex_t InvalidHitIndex
337 
338 
339  /// Default constructor: invalid hit index, default flags
340  /// (`DefaultFlagsMask()`).
341  constexpr TrajectoryPointFlags() = default;
342 
343  /**
344  * @brief Constructor: specified hit index, default flags.
345  * @param fromHit the original hit index
346  *
347  * This constructor can be used in constexpr flag definitions:
348  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
349  * using trkflag = recob::TrajectoryPointFlags::flag;
350  * constexpr recob::TrajectoryPointFlags flags(12);
351  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352  */
353  constexpr TrajectoryPointFlags(HitIndex_t fromHit)
354  : fFromHit(fromHit)
355  {}
356 
357  /**
358  * @brief Constructor: copies all the flags.
359  * @param fromHit the original hit index
360  * @param flags all the flags to set, as a bit mask
361  *
362  * This constructor can be used in constexpr flag definitions:
363  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
364  * using trkflag = recob::TrajectoryPointFlags::flag;
365  * constexpr recob::TrajectoryPointFlags flags(
366  * 12,
367  * recob::TrajectoryPointFlags::makeMask(
368  * trkflag::NoPoint,
369  * trkflag::HitIgnored
370  * )
371  * );
372  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373  */
374  constexpr TrajectoryPointFlags
375  (HitIndex_t fromHit, Mask_t flags)
376  : fFromHit(fromHit)
377  , fFlags(flags)
378  {}
379 
380  /**
381  * @brief Constructor: activates only the specified flags.
382  * @tparam Flags the type of flags to be set
383  * @param fromHit the original hit index
384  * @param flags all the flags to set
385  *
386  * This constructor can be used in constexpr flag definitions:
387  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
388  * using trkflag = recob::TrajectoryPointFlags::flag;
389  * constexpr recob::TrajectoryPointFlags flags(
390  * recob::TrajectoryPointFlags::InvalidHitIndex,
391  * trkflag::NoPoint,
392  * trkflag::Merged
393  * );
394  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
395  */
396  template <typename... Flags>
397  constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags... flags)
398  : TrajectoryPointFlags(fromHit, makeMask(flags...))
399  {}
400 
401 
402  /// @{
403  /// @name Access to flags by index
404 
405  /**
406  * @brief Returns whether there is room for a flag with the specified index.
407  * @param flagIndex index of the flag
408  * @return whether there is room for a flag with the specified index.
409  * @see isFlag()
410  *
411  * The flag may still be not present, in the sense that the allocated bit
412  * has no meaning associated to it and that flag is "unknown".
413  */
414  constexpr bool isAllocated(FlagIndex_t flagIndex) const
415  { return flagIndex < flags().capacity(); }
416 
417  /// Returns the number of defined flags.
418  constexpr FlagIndex_t nFlags() const
419  { return flag::maxFlags(); }
420 
421  /// Returns whether a flag with the specified index is known.
422  /// (all allocated flags are)
423  constexpr bool isFlag(FlagIndex_t flagIndex) const
424  { return flags().isFlag(flagIndex); }
425 
426  /// Returns whether a flag with the specified index is known.
427  /// (all allocated flags are)
428  constexpr bool isFlag(Flag_t flag) const
429  { return flags().isFlag(flag); }
430 
431  /**
432  * @brief Returns whether the specified flag is set.
433  * @param index index of the flag to be tested
434  * @return whether the specified flag is set
435  * @throw Flags_t::OutOfRangeError if the flag is not known (invalid index)
436  * @throw Flags_t::FlagNotDefinedError if the flag is not defined
437  *
438  * A single flag is tested.
439  */
440  bool test(FlagIndex_t index) const
441  { return flags().test(index); }
442 
443  /**
444  * @brief Returns whether the specified flag is set.
445  * @param flag flag to be tested
446  * @return whether the specified flag is set
447  * @throw Flags_t::OutOfRangeError if the flag is not known (invalid index)
448  * @throw Flags_t::FlagNotDefinedError if the flag is not defined
449  *
450  * A single flag is tested.
451  */
452  bool test(Flag_t flag) const
453  { return flags().test(flag); }
454 
455 
456  /**
457  * @brief Returns whether the specified flag is set.
458  * @param flag index of the flag to be tested
459  * @return whether the specified flag is set
460  *
461  * A single flag is tested.
462  * If the flag is not defined (invalid index), the result is undefined.
463  */
464  bool get(Flag_t flag) const
465  { return flags().get(flag); }
466 
467 
468  /**
469  * @brief Returns true if the flag has been assigned a value.
470  * @param flag the flag index
471  * @return true if the flag has been assigned a value
472  * @see isSet(), isUnset(), test()
473  */
474  bool isDefined(Flag_t flag) const
475  { return flags().isDefined(flag); }
476 
477  /**
478  * @brief Returns true if the flag exists and is set.
479  * @param flag the flag index
480  * @return true if the flag exists and is set
481  * @see isUnset()
482  */
483  bool isSet(Flag_t flag) const
484  { return flags().isSet(flag); }
485 
486  /**
487  * @brief Returns true if the flag exists and is not set.
488  * @param flag the flag index
489  * @return true if the flag exists and is not set
490  * @see isSet()
491  */
492  bool isUnset(Flag_t flag) const
493  { return flags().isUnset(flag); }
494 
495  /**
496  * @brief Returns true if the specified mask is matched.
497  * @param mask the mask of flags to be tested
498  * @return true if the specified mask is matched
499  * @see `util::flags::BitMask::match()`
500  *
501  * The current flags are tested against the specified mask.
502  * The flags that in `mask` are undefined are not tested at all.
503  * For this method to return true, all the remaining flags (that is, all the
504  * flags defined in `mask`) must be defined, and their value must match the
505  * one in `mask`.
506  */
507  bool match(Mask_t mask) const
508  { return flags().match(mask); }
509 
510 
511 
512  /// @}
513 
514  /// Returns the entire set of bits as a bit mask.
515  constexpr Mask_t const& mask() const
516  { return flags().mask(); }
517 
518  /// Returns the entire set of bits.
519  constexpr Flags_t const& flags() const
520  { return fFlags; }
521 
522 
523  /// @{
524  /**
525  * @name Multiple flag access
526  *
527  * @note This implementation is partial. Please contact the author to
528  * discuss your need.
529  */
530 
531  /**
532  * @brief Returns whether any of the bits set in the mask are set.
533  * @param mask mask with the bits to be checked defined and set (`isSet()`)
534  * @return whether any of the bits set in the mask are set
535  *
536  * The method returns true if of all the flags that are set
537  * (`Mask_t::isSet()`) in mask, at least one is set.
538  * Flags of mask that are unset or undefined are ignored.
539  */
540  bool anySet(Mask_t mask) const
541  { return flags().anySet(mask); }
542 
543  /**
544  * @brief Returns whether none of the bits set in the mask is set.
545  * @param mask mask with the bits to be checked defined and set (`isSet()`)
546  * @return whether none of the bits set in the mask is set
547  * @see anySet()
548  *
549  * This is the logical negation of `anySet()`.
550  */
551  bool noneSet(Mask_t mask) const
552  { return flags().noneSet(mask); }
553 
554 
555 
556  /// @}
557 
558  /// @{
559  /// @name Access to flags by meaning
560 
561  /// Returns whether the associated hit is considered ignored.
562  bool isHitIgnored() const
563  { return isSet(flag::HitIgnored); }
564 
565  /// Returns whether the associated point is valid.
566  bool isPointValid() const
567  { return !isSet(flag::NoPoint); }
568 
569  /// Returns whether the point has the `Merged` flag set.
570  bool isMerged() const
571  { return isSet(flag::Merged); }
572 
573  /// Returns whether the point has the `Shared` flag set.
574  bool isShared() const
575  { return isSet(flag::Shared); }
576 
577  /// Returns whether the point has the `DeltaRay` flag set.
578  bool isDeltaRay() const
579  { return isSet(flag::DeltaRay); }
580 
581  /// Returns whether the point has the `DetectorIssue` flag set.
582  bool hasDetectorIssues() const
583  { return isSet(flag::DetectorIssue); }
584 
585  /// Returns whether the point has the `Suspicious` flag set.
587  { return isSet(flag::Suspicious); }
588 
589  /// Returns whether the point has no flag set among `Shared`, `DeltaRay` and
590  /// `Merged`.
591  bool isExclusive() const
592  { return noneSet(SomehowSharedMask()); }
593 
594  /// Returns whether the point has the `ExcludedFromFit` flag set.
595  bool isExcludedFromFit() const
596  { return get(flag::ExcludedFromFit); }
597 
598  /// Returns whether the point has the `Rejected` flag set.
599  bool belongsToTrack() const
600  { return !isSet(flag::Rejected); }
601 
602  /// Returns whether the point has the `Reinterpreted` flag set.
603  bool isHitReinterpreted() const
604  { return isSet(flag::Reinterpreted); }
605 
606  /// Returns false if the point has the `ExcludedFromFit` or `Rejected` flag
607  /// set.
608  bool isIncludedInFit() const
609  { return noneSet(ExcludedFromTrackFitMask()); }
610 
611  /**
612  * @brief Returns whether the trajectory point has any problem flagged.
613  *
614  * A problematic point is basically one with any of the defined trajectory
615  * point flags set.
616  */
617  bool isPointFlawed() const
618  { return anySet(ImperfectPointMask()); }
619 
620  /**
621  * @brief Returns whether the trajectory point has no flagged problem.
622  *
623  * A problematic point is basically one with any of the defined trajectory
624  * point flags set.
625  */
626  bool isPointFlawless() const
627  { return noneSet(ImperfectPointMask()); }
628 
629  /// @}
630 
631  /// @{
632  /// @name Access to hit index
633 
634  /// Returns whether the original hit index is valid.
635  /// @see fromHit()
636  constexpr bool hasOriginalHitIndex() const
637  { return fromHit() != InvalidHitIndex; }
638 
639 
640  /// Returns the original index of the hit.
641  /// @return the index of the original hit (`InvalidHitIndex` if not set)
642  /// @see hasOriginalHitIndex()
643  constexpr HitIndex_t fromHit() const
644  { return fFromHit; }
645 
646  /// @}
647 
648 
649  /// Returns whether other has the same content as this one.
650  constexpr bool operator== (TrajectoryPointFlags const& other) const;
651 
652  /// Returns whether other has content different than this one.
653  constexpr bool operator!= (TrajectoryPointFlags const& other) const;
654 
655 
656  /**
657  * @brief Prints the flags content into a stream.
658  * @tparam Stream type of the output stream
659  * @param out stream to output the information into
660  * @param verbosity verbosity level (default: `1`)
661  * @param indent indentation string (default: none)
662  * @param indentFirst indentation for first output line (default: as indent)
663  *
664  * Prints on a single line all the flags that are set.
665  *
666  * Currently `indent` is not used since the output is single line.
667  *
668  * Information printed out (`verbosity` argument)
669  * -----------------------------------------------
670  *
671  * * level `0`: number of the flags set, and index
672  * * level `1`: name of the flags set, and index
673  *
674  */
675  template <typename Stream>
676  void dump(
677  Stream&& out,
678  unsigned int verbosity,
679  std::string indent, std::string indentFirst
680  ) const;
681 
682  /**
683  * @brief Prints flag content into a stream.
684  * @tparam Stream type of the output stream
685  * @param out stream to output the information into
686  * @param verbosity verbosity level (default: `1`)
687  * @param indent indentation string (default: none)
688  * @see Dump(Stream&&, unsigned int, std::string, std::string)
689  *
690  * Implementation detail for
691  * Dump(Stream&&, unsigned int, std::string, std::string).
692  */
693  template <typename Stream>
694  void dump
695  (Stream&& out, unsigned int verbosity = 1, std::string indent = {})
696  const
697  { dump(std::forward<Stream>(out), verbosity, indent, indent); }
698 
699 
700  /**
701  * @brief Returns a bit mask with only the specified bit set
702  * @tparam Flags the type of flags to be set
703  * @param flags all the flags to set
704  *
705  * This method can be used in constexpr flag definitions:
706  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
707  * using trkflag = recob::TrajectoryPointFlags::flag;
708  * constexpr auto mask = recob::TrajectoryPointFlags::makeMask
709  * (trkflag::NoPoint, trkflag::Merged);
710  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
711  */
712  template <typename... Flags>
713  static constexpr Mask_t makeMask(Flags... flags);
714 
715  /// Flags used in default construction.
716  static constexpr Mask_t DefaultFlagsMask();
717 
718  private:
719  HitIndex_t fFromHit = InvalidHitIndex; ///< Index of the original hit.
720 
721  /// Implementation detail of operator==()
722  constexpr bool sameAs(TrajectoryPointFlags const& other) const;
723 
724  /// Flags to define a non-perfect trajectory point
725  static constexpr Mask_t ImperfectPointMask();
726 
727  /// Flags to define a hit that is in some way shared
728  static constexpr Mask_t SomehowSharedMask();
729 
730  /// Flags to define a hit that is not included in the track fit
731  static constexpr Mask_t ExcludedFromTrackFitMask();
732 
733  Flags_t fFlags { DefaultFlagsMask() }; ///< Set of flags
734 
735  }; // TrajectoryPointFlags<>
736 
737 
738  /// Dumps flags into a stream with default verbosity.
739  std::ostream& operator<<
740  (std::ostream& out, recob::TrajectoryPointFlags const& flags);
741 
742 
743 } // namespace recob
744 
745 
746 //------------------------------------------------------------------------------
747 //--- inline implementation
748 //---
749 template <typename... Flags>
752  { return Mask_t(flags...); }
753 
754 
755 //------------------------------------------------------------------------------
756 inline constexpr bool recob::TrajectoryPointFlags::sameAs
758  { return (flags() == other.flags()) && (fromHit() == other.fromHit()); }
759 
760 inline constexpr bool recob::TrajectoryPointFlags::operator==
762  { return sameAs(other); }
763 
764 inline constexpr bool recob::TrajectoryPointFlags::operator!=
766  { return !sameAs(other); }
767 
768 
769 //------------------------------------------------------------------------------
772  return flag::NoPoint + flag::HitIgnored
773  + flag::Suspicious
774  + flag::Merged + flag::DeltaRay + flag::DetectorIssue + flag::Shared
775  ;
776 } // recob::TrajectoryPointFlags::ImperfectPointMask()
777 
780  { return flag::Merged + flag::DeltaRay + flag::Shared; }
781 
784  { return flag::ExcludedFromFit + flag::Rejected; }
785 
786 
787 //------------------------------------------------------------------------------
788 inline constexpr typename recob::TrajectoryPointFlags::Mask_t
790  return makeMask( -flag::NoPoint );
791 } // recob::TrajectoryPointFlags::DefaultFlagsMask()
792 
793 
794 //------------------------------------------------------------------------------
795 //--- template implementation
796 //---
797 
798 #include "TrajectoryPointFlags.tcc"
799 
800 //------------------------------------------------------------------------------
801 
802 #endif // LARDATAOBJ_RECOBASE_TRAJECTORYPOINTFLAGS_H
bool test(Flag_t flag) const
Returns whether the specified flag is set.
bool isHitIgnored() const
Returns whether the associated hit is considered ignored.
constexpr bool isFlag(FlagIndex_t flagIndex) const
static constexpr FlagIndex_t EndUserReservedFlags
After-the-last flag reserved to users.
static constexpr FlagIndex_t maxFlags()
Number of flags allocated (may be unused and unassigned).
static constexpr Flag_t Merged
The hit might have contribution from particles other than this.
constexpr bool isSet(Flag_t flag) const
Returns if the specified flag is set.
static constexpr Flag_t Suspicious
The point reconstruction is somehow questionable.
Reconstruction base classes.
static constexpr Mask_t makeMask(Flags...flags)
Returns a bit mask with only the specified bit set.
static constexpr Flag_t NoPoint
The trajectory point is not defined.
constexpr bool match(Mask_t const &mask) const
Returns whether all bits defined in the mask are equal to ours.
static constexpr Flag_t TrackReserved3
Reserved for a future track flag.
bool belongsToTrack() const
Returns whether the point has the Rejected flag set.
static constexpr FlagIndex_t EndTrajectoryFlags
After-the-last trajectory flag index.
std::string string
Definition: nybbler.cc:12
bool isSet(Flag_t flag) const
Returns true if the flag exists and is set.
static constexpr Mask_t DefaultFlagsMask()
Flags used in default construction.
Class holding flags.
constexpr bool anySet(Mask_t const &mask) const
Returns whether any of the bits set in the mask are set.
static constexpr bool isFlag(Flag_t flag)
Returns whether the specified index represents a valid flag.
static constexpr FlagIndex_t BeginTrackFlags
First track flag index.
static NameMap_t initNames()
Returns a map of flag names.
static constexpr size_t capacity()
Returns the number of flags the set has room for.
Flags_t::Flag_t Flag_t
Type of single flag.
bool isOtherwiseSuspicious() const
Returns whether the point has the Suspicious flag set.
constexpr TrajectoryPointFlags(HitIndex_t fromHit)
Constructor: specified hit index, default flags.
Namespace for the trajectory point flags.
constexpr Mask_t const & mask() const
Returns the entire set of bits as a bit mask.
bool isPointFlawed() const
Returns whether the trajectory point has any problem flagged.
static void setFlagNames(NameMap_t &flagNames)
Sets the names of the flags after default initialization.
static constexpr Flag_t TrackReserved1
Reserved for a future track flag.
static constexpr Flag_t Reinterpreted
The hit content has been elaborated before being used in the fit.
static constexpr FlagIndex_t BeginExperimentReservedFlags
First flag reserved to experiment.
A class containing a set of flags.
Definition: FlagSet.h:41
bool operator!=(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept
bool test(FlagIndex_t index) const
Returns whether the specified flag is set.
unsigned int HitIndex_t
Type for hit index.
static void initDefaultFlagRangeNames(NameMap_t &flagNames, FlagIndex_t BeginFlags, FlagIndex_t EndFlags, std::string baseName)
Initializes a range of flag names with default (decorated) names.
Class holding flags.
Flags_t::FlagIndex_t FlagIndex_t
Type of index of a single flag.
constexpr HitIndex_t fromHit() const
A class containing a set of flags.
Definition: BitMask.h:420
bool isPointValid() const
Returns whether the associated point is valid.
static constexpr unsigned int MaxFlags
Number of flags allocated (may be unused and unassigned).
constexpr bool isUnset(Flag_t flag) const
Returns if the specified flag is unset.
constexpr bool noneSet(Mask_t const &mask) const
Returns whether none of the bits set in the mask is set.
static std::string decorateFlagName(std::string baseName, Flag_t flag)
Combines a base name and an index into a flag name.
bool isShared() const
Returns whether the point has the Shared flag set.
static std::string invalidFlagName(Flag_t flag)
Returns the name of an invalid flag with the specified index.
constexpr bool hasOriginalHitIndex() const
static constexpr Mask_t ExcludedFromTrackFitMask()
Flags to define a hit that is not included in the track fit.
constexpr Flags_t const & flags() const
Returns the entire set of bits.
bool noneSet(Mask_t mask) const
Returns whether none of the bits set in the mask is set.
def dump(input_file, output_file)
Definition: dumpTree.py:102
typename Mask_t::Flag_t Flag_t
Type identifying a single flag.
Definition: FlagSet.h:60
static void initDefaultFlagsNames(NameMap_t &flagNames)
Initialises all flag names with a default name.
static constexpr Mask_t ImperfectPointMask()
Flags to define a non-perfect trajectory point.
static constexpr Mask_t SomehowSharedMask()
Flags to define a hit that is in some way shared.
constexpr bool sameAs(TrajectoryPointFlags const &other) const
Implementation detail of operator==()
bool isDeltaRay() const
Returns whether the point has the DeltaRay flag set.
static constexpr Flag_t TrackReserved4
Reserved for a future track flag.
static constexpr FlagIndex_t EndTrackFlags
After-the-last track flag index.
static constexpr FlagIndex_t EndExperimentReservedFlags
After-the-last flag reserved to experiment.
static int max(int a, int b)
static constexpr Flag_t HitIgnored
Hit was not included for the computation of the trajectory.
typename Mask_t::FlagIndex_t FlagIndex_t
Type of index of flag.
Definition: FlagSet.h:57
Flags_t::Flag_t Flag_t
Type of single flag.
static std::string name(Flag_t flag)
Returns a string with the name of the specified flag.
static constexpr Flag_t Rejected
The hit is extraneous to this track.
static constexpr Flag_t ExcludedFromFit
constexpr bool get(Flag_t flag) const
Returns if the specified flag is on ("set").
Flags_t::Mask_t Mask_t
Type of mask of bits.
constexpr BitMask< Storage > makeMask(Bits_t< Storage > bits)
Constructs a mask from bits.
bool match(Mask_t mask) const
Returns true if the specified mask is matched.
bool hasDetectorIssues() const
Returns whether the point has the DetectorIssue flag set.
bool isUnset(Flag_t flag) const
Returns true if the flag exists and is not set.
bool isPointFlawless() const
Returns whether the trajectory point has no flagged problem.
bool anySet(Mask_t mask) const
Returns whether any of the bits set in the mask are set.
constexpr bool isFlag(Flag_t flag) const
static constexpr Flag_t TrackReserved5
Reserved for a future track flag.
static constexpr FlagIndex_t BeginTrajectoryFlags
First trajectory flag index.
std::array< std::string, MaxFlags > NameMap_t
Type storing flag names.
static constexpr Flag_t TrajReserved1
Reserved for a future trajectory flag.
bool isHitReinterpreted() const
Returns whether the point has the Reinterpreted flag set.
static constexpr FlagIndex_t BeginUserReservedFlags
First flag reserved to users.
static constexpr Flag_t DetectorIssue
The hit is associated to a problematic channel.
bool isExcludedFromFit() const
Returns whether the point has the ExcludedFromFit flag set.
constexpr bool isAllocated(FlagIndex_t flagIndex) const
Returns whether there is room for a flag with the specified index.
static constexpr Flag_t DeltaRay
The hit might have contribution from a δ ray.
bool isDefined(Flag_t flag) const
Returns true if the flag has been assigned a value.
constexpr bool isDefined(Flag_t flag) const
Returns whether the flag is defined.
static QCString baseName
Definition: scanner.cpp:10890
Flags_t::FlagIndex_t FlagIndex_t
Type of index of single flag.
static constexpr Flag_t TrackReserved2
Reserved for a future track flag.
bool isMerged() const
Returns whether the point has the Merged flag set.
static const NameMap_t names
Names of the flags.
static constexpr Flag_t Shared
The hit is known to be associated also to another trajectory.
constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags...flags)
Constructor: activates only the specified flags.
Set of flags pertaining a point of the track.
BitMask< Storage > Mask_t
Type of bit mask for this flag set.
Definition: FlagSet.h:49
constexpr FlagIndex_t nFlags() const
Returns the number of defined flags.
bool operator==(ModuleKeyAndType const &a, ModuleKeyAndType const &b) noexcept