SpacePointAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file SpacePointAlg.h
4 ///
5 /// \brief Algorithm for generating space points from hits.
6 ///
7 /// \author H. Greenlee
8 ///
9 /// This class calculates space points (recob::SpacePoint) from an
10 /// unsorted collection of hits (recob::Hit). The resulting space
11 /// points will contain one hit from from two or three views.
12 ///
13 /// FCL parameters:
14 ///
15 /// MaxDT - The maximum time difference (ticks) between any pair of hits.
16 /// MaxS - The maximum 3-view wire separation parameter S (cm).
17 /// MinViews - Minimum number of views to make a space point (2 or 3).
18 /// EnableU - Use U view hits.
19 /// EnableV - Use V view hits.
20 /// EnableW - Use W view hits.
21 /// Filter - Filter space points flag.
22 /// Merge - Merge space points flag.
23 /// PreferColl - Collection view will be used for filtering and merging, and
24 /// space points will be sorted by collection wire.
25 ///
26 /// The parameters fMaxDT and fMaxS are used to implement a notion of whether
27 /// the input hits are compatible with being a space point. Parameter
28 /// MaxS is a cut on the 3-plane wire separation parameter S, which is
29 /// defined as follows:
30 ///
31 /// S = sin(theta_vw)*u + sin(theta_wu)*v + sin(theta_uv)*w
32 ///
33 /// where wire coordinates (u,v,w) are measured in cm with respect to a
34 /// common origin.
35 ///
36 /// The time offsets are subtracted from times embedded in hits before
37 /// comparing times in different planes, and before converting time
38 /// to distance.
39 ///
40 /// If enabled, filtering eliminates multiple space points with similar
41 /// times on the same wire of the most popluated plane.
42 ///
43 /// If enabled, merging combines multiple space points with similar
44 /// times on the same wire of the most populated plane (potentially
45 /// producing space points with more hits than the number of planes).
46 ///
47 /// There should eventually be a better way to specify time offsets.
48 ///
49 /// @bug This algorithm makes specific assumptions about geometry and views,
50 /// and it is *not portable*.
51 ///
52 ///
53 ////////////////////////////////////////////////////////////////////////
54 
55 #ifndef SPACEPOINTALG_H
56 #define SPACEPOINTALG_H
57 
58 #include <map>
59 #include <vector>
60 
62 #include "fhiclcpp/fwd.h"
63 
64 namespace detinfo {
65  class DetectorClocksData;
66  class DetectorPropertiesData;
67 }
68 
69 namespace trkf {
70  class KHitTrack;
71 }
72 namespace recob {
73  class Hit;
74  class SpacePoint;
75 }
76 
77 namespace trkf {
78 
79  class SpacePointAlg {
80  public:
82 
83  // Configuration Accessors.
84 
85  bool
86  filter() const noexcept
87  {
88  return fFilter;
89  }
90  bool
91  merge() const noexcept
92  {
93  return fMerge;
94  }
95  double
96  maxDT() const noexcept
97  {
98  return fMaxDT;
99  }
100  double
101  maxS() const noexcept
102  {
103  return fMaxS;
104  }
105  int
106  minViews() const noexcept
107  {
108  return fMinViews;
109  }
110  bool
111  enableU() const noexcept
112  {
113  return fEnableU;
114  }
115  bool
116  enableV() const noexcept
117  {
118  return fEnableV;
119  }
120  bool
121  enableW() const noexcept
122  {
123  return fEnableW;
124  }
125 
126  // Print constants obtained from geometry and properties services.
127  void update(detinfo::DetectorPropertiesData const& detProp) const;
128 
129  // Corrected time accessors.
130  double correctedTime(detinfo::DetectorPropertiesData const& detProp,
131  const recob::Hit& hit) const;
132 
133  // Spatial separation of hits (zero if two or fewer).
134  double separation(const art::PtrVector<recob::Hit>& hits) const;
135 
136  // Test whether the specified hits are compatible with a space point.
137  // The last two arguments can be used to override the default cuts.
138  bool compatible(detinfo::DetectorPropertiesData const& detProp,
139  const art::PtrVector<recob::Hit>& hits,
140  bool useMC = false) const;
141 
142  // Fill a single simple space point using the specified hits.
143  // Hits are assumed to be compatible.
144  void fillSpacePoint(detinfo::DetectorPropertiesData const& detProp,
145  const art::PtrVector<recob::Hit>& hits,
146  std::vector<recob::SpacePoint>& sptv,
147  int sptid) const;
148 
149  /// Fill a collection of space points.
150  void fillSpacePoints(detinfo::DetectorPropertiesData const& detProp,
151  std::vector<recob::SpacePoint>& spts,
152  std::multimap<double, KHitTrack> const& trackMap) const;
153 
154  // Fill a single complex space point using the specified hits.
155  // Complex space points allow multiple hits in one plane.
156  // Hits are assumed to be compatible.
157  void fillComplexSpacePoint(detinfo::DetectorPropertiesData const& detProp,
158  const art::PtrVector<recob::Hit>& hits,
159  std::vector<recob::SpacePoint>& sptv,
160  int sptid) const;
161 
162  // Fill a vector of space points from an unsorted collection of hits.
163  // Space points are generated for all compatible combinations of hits.
164  void makeSpacePoints(detinfo::DetectorClocksData const& clockData,
165  detinfo::DetectorPropertiesData const& detProp,
166  const art::PtrVector<recob::Hit>& hits,
167  std::vector<recob::SpacePoint>& spts) const;
168 
169  // Fill a vector of space points compatible with mc truth information
170  void makeMCTruthSpacePoints(detinfo::DetectorClocksData const& clockData,
171  detinfo::DetectorPropertiesData const& detProp,
172  const art::PtrVector<recob::Hit>& hits,
173  std::vector<recob::SpacePoint>& spts) const;
174 
175  // Get hits associated with a particular space point, based on most recent
176  // invocation of any make*SpacePoints method.
177  const art::PtrVector<recob::Hit>& getAssociatedHits(const recob::SpacePoint& spt) const;
178 
179  // Clear space point to Hit associations.
180  void
181  clearHitMap() const
182  {
183  fSptHitMap.clear();
184  }
185 
186  // Return number of space point to Hit associations.
187  int
188  numHitMap() const
189  {
190  return fSptHitMap.size();
191  }
192 
193  private:
194  // This is the real method for calculating space points (each of
195  // the public make*SpacePoints methods comes here).
196  void makeSpacePoints(detinfo::DetectorClocksData const& clockData,
197  detinfo::DetectorPropertiesData const& detProp,
198  const art::PtrVector<recob::Hit>& hits,
199  std::vector<recob::SpacePoint>& spts,
200  bool useMC) const;
201 
202  // Configuration paremeters.
203 
204  double fMaxDT; ///< Maximum time difference between planes.
205  double fMaxS; ///< Maximum space separation between wires.
206  int fMinViews; ///< Mininum number of views per space point.
207  bool fEnableU; ///< Enable flag (U).
208  bool fEnableV; ///< Enable flag (V).
209  bool fEnableW; ///< Enable flag (W).
210  bool fFilter; ///< Filter flag.
211  bool fMerge; ///< Merge flag.
212  bool fPreferColl; ///< Sort by collection wire.
213  double fTickOffsetU; ///< Tick offset for plane U.
214  double fTickOffsetV; ///< Tick offset for plane V.
215  double fTickOffsetW; ///< Tick offset for plane W.
216 
217  // Temporary variables.
218 
219  struct HitMCInfo {
220  std::vector<int> trackIDs; ///< Parent trackIDs.
221  std::vector<double> xyz; ///< Location of ionization (all tracks).
222  std::vector<const recob::Hit*> pchit; ///< Pointer to nearest neighbor hit (indexed by plane).
223  std::vector<double> dist2; ///< Distance to nearest neighbor hit (indexed by plane).
224  };
225  mutable std::map<const recob::Hit*, HitMCInfo> fHitMCMap;
226  mutable std::map<int, art::PtrVector<recob::Hit>> fSptHitMap;
227  };
228 }
229 
230 #endif
bool enableW() const noexcept
bool filter() const noexcept
Definition: SpacePointAlg.h:86
bool enableV() const noexcept
std::vector< const recob::Hit * > pchit
Pointer to nearest neighbor hit (indexed by plane).
std::map< const recob::Hit *, HitMCInfo > fHitMCMap
double fTickOffsetU
Tick offset for plane U.
Reconstruction base classes.
double fMaxDT
Maximum time difference between planes.
bool fFilter
Filter flag.
std::vector< double > dist2
Distance to nearest neighbor hit (indexed by plane).
bool fEnableW
Enable flag (W).
std::vector< int > trackIDs
Parent trackIDs.
int minViews() const noexcept
bool fEnableU
Enable flag (U).
std::map< int, art::PtrVector< recob::Hit > > fSptHitMap
std::vector< double > xyz
Location of ionization (all tracks).
bool merge() const noexcept
Definition: SpacePointAlg.h:91
double maxDT() const noexcept
Definition: SpacePointAlg.h:96
double fMaxS
Maximum space separation between wires.
General LArSoft Utilities.
bool fPreferColl
Sort by collection wire.
Detector simulation of raw signals on wires.
void clearHitMap() const
double fTickOffsetV
Tick offset for plane V.
Contains all timing reference information for the detector.
bool enableU() const noexcept
double fTickOffsetW
Tick offset for plane W.
double maxS() const noexcept
int fMinViews
Mininum number of views per space point.
int numHitMap() const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
bool fMerge
Merge flag.
bool fEnableV
Enable flag (V).