LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrajectoryPointFlags.h
Go to the documentation of this file.
1 
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 <stdexcept> // std::out_of_range
21 #include <limits> // std::numeric_limits<>
22 #include <utility> // std::forward(), std::declval()
23 #include <iosfwd> // std::ostream
24 #include <cstddef> // std::size_t
25 
26 
27 namespace recob {
28 
29 
62 
64  static constexpr unsigned int MaxFlags = 32;
65 
68 
71 
74 
77 
79 
115  static constexpr FlagIndex_t BeginTrajectoryFlags = 0;
117 
119  static constexpr Flag_t HitIgnored { 0 };
120 
122  static constexpr Flag_t NoPoint { 1 };
123 
132  static constexpr Flag_t Suspicious { 2 };
133 
135  static constexpr Flag_t Merged { 3 };
136 
138  static constexpr Flag_t DeltaRay { 4 };
139 
141  static constexpr Flag_t DetectorIssue { 5 };
142 
144  static constexpr Flag_t Shared { 6 };
145 
147  static constexpr Flag_t TrajReserved1 { 7 };
148 
150  static constexpr FlagIndex_t EndTrajectoryFlags = 8;
151 
153  //------------------------------------------------------------------------
155 
169 
172  static constexpr Flag_t ExcludedFromFit { 8 };
173 
175  static constexpr Flag_t Rejected { 9 };
176 
190  static constexpr Flag_t Reinterpreted { 10 };
191 
193  static constexpr Flag_t TrackReserved5 { 11 };
194 
196  static constexpr Flag_t TrackReserved4 { 12 };
197 
199  static constexpr Flag_t TrackReserved3 { 13 };
200 
202  static constexpr Flag_t TrackReserved2 { 14 };
203 
205  static constexpr Flag_t TrackReserved1 { 15 };
206 
208  static constexpr FlagIndex_t EndTrackFlags = 16;
209 
211  //------------------------------------------------------------------------
214 
217 
220 
222  //------------------------------------------------------------------------
225 
227  static constexpr FlagIndex_t BeginUserReservedFlags
229 
231  static constexpr FlagIndex_t EndUserReservedFlags = 32;
233  //------------------------------------------------------------------------
234 
235 
237  static constexpr FlagIndex_t maxFlags() { return MaxFlags; }
238 
239 
241  static constexpr bool isFlag(Flag_t flag)
242  { return flag.index() < MaxFlags; }
243 
246 
248  static std::string name(Flag_t flag)
249  {
250  return isFlag(flag)? names[flag.index()]: invalidFlagName(flag.index());
251  }
252 
254  using NameMap_t = std::array<std::string, MaxFlags>;
255 
257  static NameMap_t initNames();
258 
260 
261  private:
262  static_assert(EndTrajectoryFlags <= BeginTrackFlags,
263  "Too many trajectory flags");
264  static_assert(EndTrackFlags <= BeginExperimentReservedFlags,
265  "Too many track flags");
266  static_assert(
267  EndExperimentReservedFlags <= BeginUserReservedFlags,
268  "Too many experiment-defined flags"
269  );
270  static_assert(EndUserReservedFlags <= MaxFlags,
271  "Too many user-defined flags");
272 
273  static const NameMap_t names;
274 
276  static std::string decorateFlagName(std::string baseName, Flag_t flag);
277 
279  static std::string invalidFlagName(Flag_t flag);
280 
282  static void initDefaultFlagRangeNames(
283  NameMap_t& flagNames,
284  FlagIndex_t BeginFlags, FlagIndex_t EndFlags, std::string baseName
285  );
286 
288  static void initDefaultFlagsNames(NameMap_t& flagNames);
289 
291  static void setFlagNames(NameMap_t& flagNames);
292 
293  }; // class TrajectoryPointFlagTraits
294 
295 
319 
320  public:
321 
324 
325 
327 
329 
331 
333 
334  using HitIndex_t = unsigned int;
335 
336 
338  static constexpr HitIndex_t InvalidHitIndex
340 
341 
344  constexpr TrajectoryPointFlags() = default;
345 
356  constexpr TrajectoryPointFlags(HitIndex_t fromHit)
357  : fFromHit(fromHit)
358  {}
359 
377  constexpr TrajectoryPointFlags
378  (HitIndex_t fromHit, Mask_t flags)
379  : fFromHit(fromHit)
380  , fFlags(flags)
381  {}
382 
399  template <typename... Flags>
400  constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags... flags)
401  : TrajectoryPointFlags(fromHit, makeMask(flags...))
402  {}
403 
404 
407 
417  constexpr bool isAllocated(FlagIndex_t flagIndex) const
418  { return flagIndex < flags().capacity(); }
419 
421  constexpr FlagIndex_t nFlags() const
422  { return flag::maxFlags(); }
423 
426  constexpr bool isFlag(FlagIndex_t flagIndex) const
427  { return flags().isFlag(flagIndex); }
428 
431  constexpr bool isFlag(Flag_t flag) const
432  { return flags().isFlag(flag); }
433 
443  bool test(FlagIndex_t index) const
444  { return flags().test(index); }
445 
455  bool test(Flag_t flag) const
456  { return flags().test(flag); }
457 
458 
467  bool get(Flag_t flag) const
468  { return flags().get(flag); }
469 
470 
477  bool isDefined(Flag_t flag) const
478  { return flags().isDefined(flag); }
479 
486  bool isSet(Flag_t flag) const
487  { return flags().isSet(flag); }
488 
495  bool isUnset(Flag_t flag) const
496  { return flags().isUnset(flag); }
497 
510  bool match(Mask_t mask) const
511  { return flags().match(mask); }
512 
513 
514 
516 
518  constexpr Mask_t const& mask() const
519  { return flags().mask(); }
520 
522  constexpr Flags_t const& flags() const
523  { return fFlags; }
524 
525 
527 
543  bool anySet(Mask_t mask) const
544  { return flags().anySet(mask); }
545 
554  bool noneSet(Mask_t mask) const
555  { return flags().noneSet(mask); }
556 
557 
558 
560 
563 
565  bool isHitIgnored() const
566  { return isSet(flag::HitIgnored); }
567 
569  bool isPointValid() const
570  { return !isSet(flag::NoPoint); }
571 
573  bool isMerged() const
574  { return isSet(flag::Merged); }
575 
577  bool isShared() const
578  { return isSet(flag::Shared); }
579 
581  bool isDeltaRay() const
582  { return isSet(flag::DeltaRay); }
583 
585  bool hasDetectorIssues() const
586  { return isSet(flag::DetectorIssue); }
587 
590  { return isSet(flag::Suspicious); }
591 
594  bool isExclusive() const
595  { return noneSet(SomehowSharedMask()); }
596 
598  bool isExcludedFromFit() const
599  { return get(flag::ExcludedFromFit); }
600 
602  bool belongsToTrack() const
603  { return !isSet(flag::Rejected); }
604 
606  bool isHitReinterpreted() const
607  { return isSet(flag::Reinterpreted); }
608 
611  bool isIncludedInFit() const
612  { return noneSet(ExcludedFromTrackFitMask()); }
613 
620  bool isPointFlawed() const
621  { return anySet(ImperfectPointMask()); }
622 
629  bool isPointFlawless() const
630  { return noneSet(ImperfectPointMask()); }
631 
633 
636 
639  constexpr bool hasOriginalHitIndex() const
640  { return fromHit() != InvalidHitIndex; }
641 
642 
646  constexpr HitIndex_t fromHit() const
647  { return fFromHit; }
648 
650 
651 
653  constexpr bool operator== (TrajectoryPointFlags const& other) const;
654 
656  constexpr bool operator!= (TrajectoryPointFlags const& other) const;
657 
658 
678  template <typename Stream>
679  void dump(
680  Stream&& out,
681  unsigned int verbosity,
682  std::string indent, std::string indentFirst
683  ) const;
684 
696  template <typename Stream>
697  void dump
698  (Stream&& out, unsigned int verbosity = 1, std::string indent = {})
699  const
700  { dump(std::forward<Stream>(out), verbosity, indent, indent); }
701 
702 
715  template <typename... Flags>
716  static constexpr Mask_t makeMask(Flags... flags);
717 
719  static constexpr Mask_t DefaultFlagsMask();
720 
721  private:
722  HitIndex_t fFromHit = InvalidHitIndex;
723 
725  constexpr bool sameAs(TrajectoryPointFlags const& other) const;
726 
728  static constexpr Mask_t ImperfectPointMask();
729 
731  static constexpr Mask_t SomehowSharedMask();
732 
734  static constexpr Mask_t ExcludedFromTrackFitMask();
735 
736  Flags_t fFlags { DefaultFlagsMask() };
737 
738  }; // TrajectoryPointFlags<>
739 
740 
742  std::ostream& operator<<
743  (std::ostream& out, recob::TrajectoryPointFlags const& flags);
744 
745 
746 } // namespace recob
747 
748 
749 //------------------------------------------------------------------------------
750 //--- inline implementation
751 //---
752 template <typename... Flags>
755  { return Mask_t(flags...); }
756 
757 
758 //------------------------------------------------------------------------------
759 inline constexpr bool recob::TrajectoryPointFlags::sameAs
761  { return (flags() == other.flags()) && (fromHit() == other.fromHit()); }
762 
763 inline constexpr bool recob::TrajectoryPointFlags::operator==
765  { return sameAs(other); }
766 
767 inline constexpr bool recob::TrajectoryPointFlags::operator!=
769  { return !sameAs(other); }
770 
771 
772 //------------------------------------------------------------------------------
775  return flag::NoPoint + flag::HitIgnored
776  + flag::Suspicious
777  + flag::Merged + flag::DeltaRay + flag::DetectorIssue + flag::Shared
778  ;
779 } // recob::TrajectoryPointFlags::ImperfectPointMask()
780 
783  { return flag::Merged + flag::DeltaRay + flag::Shared; }
784 
787  { return flag::ExcludedFromFit + flag::Rejected; }
788 
789 
790 //------------------------------------------------------------------------------
791 inline constexpr typename recob::TrajectoryPointFlags::Mask_t
793  return makeMask( -flag::NoPoint );
794 } // recob::TrajectoryPointFlags::DefaultFlagsMask()
795 
796 
797 //------------------------------------------------------------------------------
798 //--- template implementation
799 //---
800 
801 #include "TrajectoryPointFlags.tcc"
802 
803 //------------------------------------------------------------------------------
804 
805 #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.
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 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.
Int_t max
Definition: plot.C:27
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.
std::string indent(std::size_t const i)
bool noneSet(Mask_t mask) const
Returns whether none of the bits set in the mask is set.
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 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 operator!=(geometry_element_iterator< GEOIDITER > const &iter, GEOIDITER const &id_iter)
Comparison operator: geometry ID and element point to different IDs.
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.
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.
bool operator==(geometry_element_iterator< GEOIDITER > const &iter, GEOIDITER const &id_iter)
Comparison operator: geometry ID and element point to the same ID.
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.