LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 <iosfwd> // std::ostream
20 #include <limits> // std::numeric_limits<>
21 #include <string>
22 #include <utility> // std::forward(), std::declval()
23 
24 namespace recob {
25 
58 
60  static constexpr unsigned int MaxFlags = 32;
61 
64 
67 
70 
73 
75 
111  static constexpr FlagIndex_t BeginTrajectoryFlags = 0;
113 
115  static constexpr Flag_t HitIgnored{0};
116 
118  static constexpr Flag_t NoPoint{1};
119 
128  static constexpr Flag_t Suspicious{2};
129 
131  static constexpr Flag_t Merged{3};
132 
134  static constexpr Flag_t DeltaRay{4};
135 
137  static constexpr Flag_t DetectorIssue{5};
138 
140  static constexpr Flag_t Shared{6};
141 
143  static constexpr Flag_t TrajReserved1{7};
144 
146  static constexpr FlagIndex_t EndTrajectoryFlags = 8;
147 
149  //------------------------------------------------------------------------
151 
165 
168  static constexpr Flag_t ExcludedFromFit{8};
169 
171  static constexpr Flag_t Rejected{9};
172 
186  static constexpr Flag_t Reinterpreted{10};
187 
189  static constexpr Flag_t TrackReserved5{11};
190 
192  static constexpr Flag_t TrackReserved4{12};
193 
195  static constexpr Flag_t TrackReserved3{13};
196 
198  static constexpr Flag_t TrackReserved2{14};
199 
201  static constexpr Flag_t TrackReserved1{15};
202 
204  static constexpr FlagIndex_t EndTrackFlags = 16;
205 
207  //------------------------------------------------------------------------
210 
213 
216 
218  //------------------------------------------------------------------------
221 
224 
226  static constexpr FlagIndex_t EndUserReservedFlags = 32;
228  //------------------------------------------------------------------------
229 
231  static constexpr FlagIndex_t maxFlags() { return MaxFlags; }
232 
234  static constexpr bool isFlag(Flag_t flag) { return flag.index() < MaxFlags; }
235 
238 
240  static std::string name(Flag_t flag)
241  {
242  return isFlag(flag) ? names[flag.index()] : invalidFlagName(flag.index());
243  }
244 
246  using NameMap_t = std::array<std::string, MaxFlags>;
247 
249  static NameMap_t initNames();
250 
252 
253  private:
254  static_assert(EndTrajectoryFlags <= BeginTrackFlags, "Too many trajectory flags");
255  static_assert(EndTrackFlags <= BeginExperimentReservedFlags, "Too many track flags");
256  static_assert(EndExperimentReservedFlags <= BeginUserReservedFlags,
257  "Too many experiment-defined flags");
258  static_assert(EndUserReservedFlags <= MaxFlags, "Too many user-defined flags");
259 
260  static const NameMap_t names;
261 
263  static std::string decorateFlagName(std::string baseName, Flag_t flag);
264 
266  static std::string invalidFlagName(Flag_t flag);
267 
269  static void initDefaultFlagRangeNames(NameMap_t& flagNames,
270  FlagIndex_t BeginFlags,
271  FlagIndex_t EndFlags,
272  std::string baseName);
273 
275  static void initDefaultFlagsNames(NameMap_t& flagNames);
276 
278  static void setFlagNames(NameMap_t& flagNames);
279 
280  }; // class TrajectoryPointFlagTraits
281 
305 
306  public:
309 
311 
313 
315 
317 
318  using HitIndex_t = unsigned int;
319 
321  static constexpr HitIndex_t InvalidHitIndex = std::numeric_limits<HitIndex_t>::max();
322 
325  constexpr TrajectoryPointFlags() = default;
326 
337  constexpr TrajectoryPointFlags(HitIndex_t fromHit) : fFromHit(fromHit) {}
338 
356  constexpr TrajectoryPointFlags(HitIndex_t fromHit, Mask_t flags)
357  : fFromHit(fromHit), fFlags(flags)
358  {}
359 
376  template <typename... Flags>
377  constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags... flags)
378  : TrajectoryPointFlags(fromHit, makeMask(flags...))
379  {}
380 
383 
393  constexpr bool isAllocated(FlagIndex_t flagIndex) const
394  {
395  return flagIndex < flags().capacity();
396  }
397 
399  constexpr FlagIndex_t nFlags() const { return flag::maxFlags(); }
400 
403  constexpr bool isFlag(FlagIndex_t flagIndex) const { return flags().isFlag(flagIndex); }
404 
407  constexpr bool isFlag(Flag_t flag) const { return flags().isFlag(flag); }
408 
418  bool test(FlagIndex_t index) const { return flags().test(index); }
419 
429  bool test(Flag_t flag) const { return flags().test(flag); }
430 
439  bool get(Flag_t flag) const { return flags().get(flag); }
440 
447  bool isDefined(Flag_t flag) const { return flags().isDefined(flag); }
448 
455  bool isSet(Flag_t flag) const { return flags().isSet(flag); }
456 
463  bool isUnset(Flag_t flag) const { return flags().isUnset(flag); }
464 
477  bool match(Mask_t mask) const { return flags().match(mask); }
478 
480 
482  constexpr Mask_t const& mask() const { return flags().mask(); }
483 
485  constexpr Flags_t const& flags() const { return fFlags; }
486 
488 
504  bool anySet(Mask_t mask) const { return flags().anySet(mask); }
505 
514  bool noneSet(Mask_t mask) const { return flags().noneSet(mask); }
515 
517 
520 
522  bool isHitIgnored() const { return isSet(flag::HitIgnored); }
523 
525  bool isPointValid() const { return !isSet(flag::NoPoint); }
526 
528  bool isMerged() const { return isSet(flag::Merged); }
529 
531  bool isShared() const { return isSet(flag::Shared); }
532 
534  bool isDeltaRay() const { return isSet(flag::DeltaRay); }
535 
537  bool hasDetectorIssues() const { return isSet(flag::DetectorIssue); }
538 
540  bool isOtherwiseSuspicious() const { return isSet(flag::Suspicious); }
541 
544  bool isExclusive() const { return noneSet(SomehowSharedMask()); }
545 
547  bool isExcludedFromFit() const { return get(flag::ExcludedFromFit); }
548 
550  bool belongsToTrack() const { return !isSet(flag::Rejected); }
551 
553  bool isHitReinterpreted() const { return isSet(flag::Reinterpreted); }
554 
557  bool isIncludedInFit() const { return noneSet(ExcludedFromTrackFitMask()); }
558 
565  bool isPointFlawed() const { return anySet(ImperfectPointMask()); }
566 
573  bool isPointFlawless() const { return noneSet(ImperfectPointMask()); }
574 
576 
579 
582  constexpr bool hasOriginalHitIndex() const { return fromHit() != InvalidHitIndex; }
583 
587  constexpr HitIndex_t fromHit() const { return fFromHit; }
588 
590 
592  constexpr bool operator==(TrajectoryPointFlags const& other) const;
593 
595  constexpr bool operator!=(TrajectoryPointFlags const& other) const;
596 
616  template <typename Stream>
617  void dump(Stream&& out,
618  unsigned int verbosity,
619  std::string indent,
620  std::string indentFirst) const;
621 
633  template <typename Stream>
634  void dump(Stream&& out, unsigned int verbosity = 1, std::string indent = {}) const
635  {
636  dump(std::forward<Stream>(out), verbosity, indent, indent);
637  }
638 
651  template <typename... Flags>
652  static constexpr Mask_t makeMask(Flags... flags);
653 
655  static constexpr Mask_t DefaultFlagsMask();
656 
657  private:
658  HitIndex_t fFromHit = InvalidHitIndex;
659 
661  constexpr bool sameAs(TrajectoryPointFlags const& other) const;
662 
664  static constexpr Mask_t ImperfectPointMask();
665 
667  static constexpr Mask_t SomehowSharedMask();
668 
670  static constexpr Mask_t ExcludedFromTrackFitMask();
671 
672  Flags_t fFlags{DefaultFlagsMask()};
673 
674  }; // TrajectoryPointFlags<>
675 
677  std::ostream& operator<<(std::ostream& out, recob::TrajectoryPointFlags const& flags);
678 
679 } // namespace recob
680 
681 //------------------------------------------------------------------------------
682 //--- inline implementation
683 //---
684 template <typename... Flags>
686  Flags... flags)
687 {
688  return Mask_t(flags...);
689 }
690 
691 //------------------------------------------------------------------------------
693 {
694  return (flags() == other.flags()) && (fromHit() == other.fromHit());
695 }
696 
698  TrajectoryPointFlags const& other) const
699 {
700  return sameAs(other);
701 }
702 
704  TrajectoryPointFlags const& other) const
705 {
706  return !sameAs(other);
707 }
708 
709 //------------------------------------------------------------------------------
712 {
713  return flag::NoPoint + flag::HitIgnored + flag::Suspicious + flag::Merged + flag::DeltaRay +
714  flag::DetectorIssue + flag::Shared;
715 } // recob::TrajectoryPointFlags::ImperfectPointMask()
716 
719 {
720  return flag::Merged + flag::DeltaRay + flag::Shared;
721 }
722 
725 {
726  return flag::ExcludedFromFit + flag::Rejected;
727 }
728 
729 //------------------------------------------------------------------------------
730 inline constexpr typename recob::TrajectoryPointFlags::Mask_t
732 {
733  return makeMask(-flag::NoPoint);
734 } // recob::TrajectoryPointFlags::DefaultFlagsMask()
735 
736 //------------------------------------------------------------------------------
737 //--- template implementation
738 //---
739 
740 #include "TrajectoryPointFlags.tcc"
741 
742 //------------------------------------------------------------------------------
743 
744 #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 operator!=(TrajectoryPointFlags const &other) const
Returns whether other has content different than this one.
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.
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.
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.
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:40
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:407
bool isPointValid() const
Returns whether the associated point is valid.
constexpr TrajectoryPointFlags(HitIndex_t fromHit, Mask_t flags)
Constructor: copies all the flags.
static constexpr unsigned int MaxFlags
Number of flags allocated (may be unused and unassigned).
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)
constexpr bool operator==(TrajectoryPointFlags const &other) const
Returns whether other has the same content as this one.
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:59
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:56
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
Collection of utilities for dumping data on screen.
Definition: DumperBase.h:28
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 operator!=(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
Never admit a infinite_endcount_iterator to be equal to anything else.
Definition: counter.h:266
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.
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.
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
Definition: counter.h:278
constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags...flags)
Constructor: activates only the specified flags.
void dump(Stream &&out, unsigned int verbosity=1, std::string indent={}) const
Prints flag content into a stream.
Set of flags pertaining a point of the track.
BitMask< Storage > Mask_t
Type of bit mask for this flag set.
Definition: FlagSet.h:48
std::ostream & operator<<(std::ostream &o, Cluster const &c)
Definition: Cluster.cxx:168
constexpr FlagIndex_t nFlags() const
Returns the number of defined flags.