ClusterMatchAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file ClusterMatchAlg.h
3 //
4 // \brief ClusterMatchAlg header file
5 //
6 // \author kazuhiro@nevis.columbia.edu
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 #ifndef CLUSTERMATCHALG_H
11 #define CLUSTERMATCHALG_H
12 
13 // ART includes
17 #include "fhiclcpp/fwd.h"
18 
19 // LArSoft
25 namespace detinfo {
26  class DetectorClocksData;
27  class DetectorPropertiesData;
28 }
29 namespace trkf {
30  class SpacePointAlg;
31 }
32 
33 // STL
34 #include <vector>
35 
36 class TTree;
37 
38 namespace cluster {
40 
41  public:
42  /// Enum switch for various matching methods
44  kRoughZ = 0, ///< Rough-Z comparison method ... see Match_RoughZ() description
45  kRoughT, ///< Rough-Time comparison method ... see Match_RoughTime() description
46  kSpacePoint, ///< Use SpacePoint finder algorithm ... see Match_SpacePoint() description
47  kSumCharge, ///< Use summed charge comparison ... see Match_SumCharge() description
48  kMATCH_METHOD_MAX ///<
49  };
50 
51  /**
52  Local struct data container to store cluster's basic information
53  based on hits that consist the cluster. Looping over hit pointer
54  occurs when we create art::PtrVector<recob::Hit> from input file.
55  All information that is based on hits and is used for cluster-matching
56  should be extracted from there to maximize I/O efficiency as looping
57  over hits takes time.
58  In other words... all hits related variables should be stored here!
59  */
61 
62  unsigned short cluster_index; ///< Cluster's index position in the input cluster vector array
63  geo::View_t view; ///< Wire plane ID
64  unsigned int nhits; ///< Number of hits
65  unsigned short wire_max; ///< Maximum wire number in this cluster
66  unsigned short wire_min; ///< Minimum wire number in this cluster
67  double start_time_max; ///< Maximum "start time" among all hits in this cluster
68  double peak_time_max; ///< Maximum "peak time" among all hits in this cluster
69  double end_time_max; ///< Maximum "end time" among all hits in this cluster
70  double start_time_min; ///< Minimum "start time" among all hits in this cluster
71  double peak_time_min; ///< Minimum "peak time" among all hits in this cluster
72  double end_time_min; ///< Minimum "end time" among all hits in this cluster
73  double sum_charge; ///< Summed charge among all hits in this cluster
74 
75  /// Constructor with cluster's index ID
76  cluster_match_info(unsigned short index)
77  {
78  cluster_index = index;
79  view = geo::kUnknown;
80  wire_max = 0;
81  wire_min = 0xffff;
82  start_time_max = peak_time_max = end_time_max = -1.;
83  start_time_min = peak_time_min = end_time_min = 1.e9;
84  sum_charge = -1.;
85  };
86 
87  /// Default constructor
89  };
90 
91  public:
92  /// Default constructor with fhicl parameters
94 
95  /// Method to report the current configuration
96  void ReportConfig() const;
97 
98  /// Method to specify input MCTruth's module name (optional)
99  void
101  {
102  _ModName_MCTruth = name;
103  }
104 
105  /// Internal method to fill MCTruth information when available
106  void FillMCInfo(const art::Event& evt);
107 
108  /// Method to fill cluster information to be used for matching
109  void AppendClusterInfo(detinfo::DetectorPropertiesData const& det_prop,
110  const recob::Cluster& in_cluster,
111  const std::vector<art::Ptr<recob::Hit>>& in_hit_v);
112 
113  /**
114  Method to run matching algorithms for three planes.
115  Event info must be provided prior to this function call through FillEventInfo()
116  function call. If the function is called more than once w/o supplying the new
117  art::Event object, it does not perform any new matching unless a user explicitly
118  calls ClearEventInfo() and then fill event info again though FillEventInfo().
119  */
120  void MatchThreePlanes(detinfo::DetectorClocksData const& clock_data,
121  detinfo::DetectorPropertiesData const& det_prop);
122 
123  /// Two plane version of cluster matching method.
124  void MatchTwoPlanes(detinfo::DetectorClocksData const& clock_data,
125  detinfo::DetectorPropertiesData const& det_prop);
126 
127  /// Method to retrieve matched cluster combinations. The format is [wire_plane][cluster_index]
128  std::vector<std::vector<unsigned int>> GetMatchedClusters() const;
129 
130  /// Method to retrieve matched SpacePoint for each combinations.
131  const std::vector<std::vector<recob::SpacePoint>>&
133  {
134  return _matched_sps_v;
135  };
136 
137  /// Method to check if it is configured to store SpacePoint
138  bool
140  {
141  return _store_sps;
142  }
143 
144  /// Method to clear event-wise information
145  void ClearEventInfo();
146 
147  protected:
148  /// Method to clear input cluster information
149  void ClearMatchInputInfo();
150 
151  /// Method to clear output matched cluster information
152  void ClearMatchOutputInfo();
153 
154  /// Method to clear TTree variables
155  void ClearTTreeInfo();
156 
157  /// Internal method, called only once, to fill detector-wise information
158  void PrepareDetParams(detinfo::DetectorPropertiesData const& clockData);
159 
160  /// Internal method to create output TTree for quality checking of the algorithm
161  void PrepareTTree();
162 
163  void FillHitInfo(cluster_match_info& ci,
164  art::PtrVector<recob::Hit>& out_hit_v,
165  const std::vector<art::Ptr<recob::Hit>>& in_hit_v);
166 
167  /// Internal method to fill cluster-info tree
168  void AppendClusterTreeVariables(const cluster_match_info& ci);
169 
170  /**
171  Match clusters based on min/max Z boundary information. It checks clusters' overlap
172  along Z spatial coordinate based on 2 input cluster information.
173  */
174  bool Match_RoughZ(const cluster_match_info& ci1,
175  const cluster_match_info& ci2,
176  const geo::View_t v1,
177  const geo::View_t v2) const;
178 
179  /// Checks min/max hit timing among two clusters and make sure there is an overlap
180  bool Match_RoughTime(const cluster_match_info& ci1, const cluster_match_info& ci2);
181 
182  /**
183  Checks min/max hit timing among three clusters and make sure there is an overlap.
184  If _overlay_tratio_cut is set, then overlapped-time / cluster-timespan fraction
185  is compared to the set cut value to claim a match.
186  */
187  //bool Match_RoughTime(const cluster_match_info &ci1, const cluster_match_info &ci2, const cluster_match_info &ci3);
188 
189  /**
190  Checks the ratio of two clusters' summed charge. If the ratio is within 1 +/- set cut value,
191  two clusters are considered to match.
192  */
193  bool Match_SumCharge(const cluster_match_info& uc, const cluster_match_info& vc);
194 
195  /**
196  Cluster matching using space points. This can be slow as we run SpacePointFinder
197  algorithm per cluster pair. Three clusters (U, V, W) are considerd to "match" if
198  there found N spacepoints using hits in them and N > min_nsps where "min_nsps" is
199  the cut value you can set in SetNSpacePointCut() method.
200  */
201  bool Match_SpacePoint(detinfo::DetectorClocksData const& clockData,
202  detinfo::DetectorPropertiesData const& detProp,
203  const size_t uindex,
204  const size_t vindex,
205  const size_t windex,
206  std::vector<recob::SpacePoint>& sps_v);
207 
208  //
209  // Cut parameter values
210  //
211  size_t _num_sps_cut; ///< Number of SpacePoint used to cut in
212  ///< Match_SpacePoint method
213  double _overlay_tratio_cut; ///< Minimum overlayed time fraction among two
214  ///< clusters used in Match_RoughTime method
215  double _qratio_cut; ///< Maximum difference among clusters' charge sum used
216  ///< in Match_SumCharge method
217 
218  //
219  // Resulting data holder for matched cluster indexes
220  //
221  std::vector<unsigned int> _matched_uclusters_v; ///< U plane matched clusters' index
222  std::vector<unsigned int> _matched_vclusters_v; ///< V plane matched clusters' index
223  std::vector<unsigned int> _matched_wclusters_v; ///< W plane matched clusters' index
224  std::vector<std::vector<recob::SpacePoint>>
225  _matched_sps_v; ///< Local SpacePoint vector container
226 
227  //
228  // Run control variables
229  //
230  bool _match_methods[kMATCH_METHOD_MAX]; ///< Boolean list for enabled algorithms
232  bool _debug_mode; ///< Boolean to enable debug mode (call all enabled matching methods)
233  bool _store_sps; ///< Boolean to enable storage of SpacePoint vector
234  unsigned int _tot_planes;
238 
239  std::string _ModName_MCTruth; ///< MCTruth producer's module name
240 
241  std::vector<art::PtrVector<recob::Hit>>
242  _uhits_v; ///< Local Hit pointer vector container ... U-plane
243  std::vector<art::PtrVector<recob::Hit>>
244  _vhits_v; ///< Local Hit pointer vector container ... V-plane
245  std::vector<art::PtrVector<recob::Hit>>
246  _whits_v; ///< Local Hit pointer vector container ... W-plane
247 
248  std::vector<cluster_match_info> _ucluster_v; ///< Local cluster data container... U-plane
249  std::vector<cluster_match_info> _vcluster_v; ///< Local cluster data container... V-plane
250  std::vector<cluster_match_info> _wcluster_v; ///< Local cluster data container... W-plane
251 
252  trkf::SpacePointAlg* _sps_algo; ///< SpacePointFinder algorithm pointer
253 
254  //
255  // Quality control parameters to be saved in the TTree
256  //
257  TTree* _match_tree;
258  // Event-wise variables
259  double _mc_E;
260  double _mc_Px;
261  double _mc_Py;
262  double _mc_Pz;
263  double _mc_Vx;
264  double _mc_Vy;
265  double _mc_Vz;
266  int _pdgid;
267  unsigned short _tot_u;
268  unsigned short _tot_v;
269  unsigned short _tot_w;
270  unsigned short _tot_pass_qsum;
271  unsigned short _tot_pass_t;
272  unsigned short _tot_pass_z;
273  unsigned short _tot_pass_sps;
274 
275  // Cluster-combination-wise variable
276  std::vector<uint16_t> _u_nhits_v;
277  std::vector<uint16_t> _v_nhits_v;
278  std::vector<uint16_t> _w_nhits_v;
279  std::vector<uint16_t> _nsps;
280  std::vector<double> _qratio_v;
281  std::vector<double> _uv_tratio_v;
282  std::vector<double> _vw_tratio_v;
283  std::vector<double> _wu_tratio_v;
284 
285  // Cluster-wise variable
288  std::vector<uint16_t> _view_v;
289  std::vector<double> _charge_v;
290  std::vector<uint16_t> _nhits_v;
291  std::vector<double> _tstart_min_v;
292  std::vector<double> _tstart_max_v;
293  std::vector<double> _tpeak_min_v;
294  std::vector<double> _tpeak_max_v;
295  std::vector<double> _tend_min_v;
296  std::vector<double> _tend_max_v;
297 
298  }; // class ClusterMatchAlg
299 
300 } //namespace cluster
301 #endif
std::vector< uint16_t > _w_nhits_v
static QCString name
Definition: declinfo.cpp:673
Use summed charge comparison ... see Match_SumCharge() description.
trkf::SpacePointAlg * _sps_algo
SpacePointFinder algorithm pointer.
double peak_time_max
Maximum "peak time" among all hits in this cluster.
std::vector< art::PtrVector< recob::Hit > > _vhits_v
Local Hit pointer vector container ... V-plane.
void SetMCTruthModName(std::string name)
Method to specify input MCTruth&#39;s module name (optional)
double end_time_min
Minimum "end time" among all hits in this cluster.
std::vector< double > _vw_tratio_v
unsigned short wire_min
Minimum wire number in this cluster.
std::vector< art::PtrVector< recob::Hit > > _whits_v
Local Hit pointer vector container ... W-plane.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string string
Definition: nybbler.cc:12
Unknown view.
Definition: geo_types.h:136
double end_time_max
Maximum "end time" among all hits in this cluster.
std::vector< double > _wu_tratio_v
std::vector< double > _qratio_v
struct vector vector
bool _store_sps
Boolean to enable storage of SpacePoint vector.
MatchMethod_t
Enum switch for various matching methods.
Set of hits with a 2D structure.
Definition: Cluster.h:71
Use SpacePoint finder algorithm ... see Match_SpacePoint() description.
std::vector< cluster_match_info > _wcluster_v
Local cluster data container... W-plane.
Cluster finding and building.
Particle class.
unsigned short _tot_pass_sps
bool StoreSpacePoints() const
Method to check if it is configured to store SpacePoint.
std::vector< double > _tpeak_max_v
std::vector< double > _charge_v
std::vector< uint16_t > _nhits_v
unsigned short cluster_index
Cluster&#39;s index position in the input cluster vector array.
std::vector< double > _tend_max_v
std::vector< double > _tend_min_v
std::vector< uint16_t > _nsps
double peak_time_min
Minimum "peak time" among all hits in this cluster.
double sum_charge
Summed charge among all hits in this cluster.
Rough-Time comparison method ... see Match_RoughTime() description.
std::string _ModName_MCTruth
MCTruth producer&#39;s module name.
std::vector< art::PtrVector< recob::Hit > > _uhits_v
Local Hit pointer vector container ... U-plane.
std::vector< uint16_t > _u_nhits_v
General LArSoft Utilities.
std::vector< double > _tstart_max_v
std::vector< cluster_match_info > _vcluster_v
Local cluster data container... V-plane.
std::vector< double > _tstart_min_v
std::vector< double > _uv_tratio_v
bool _debug_mode
Boolean to enable debug mode (call all enabled matching methods)
const std::vector< std::vector< recob::SpacePoint > > & GetMatchedSpacePoints() const
Method to retrieve matched SpacePoint for each combinations.
Declaration of signal hit object.
std::vector< uint16_t > _view_v
unsigned short _tot_pass_qsum
Contains all timing reference information for the detector.
unsigned short wire_max
Maximum wire number in this cluster.
std::vector< uint16_t > _v_nhits_v
std::vector< std::vector< recob::SpacePoint > > _matched_sps_v
Local SpacePoint vector container.
std::vector< unsigned int > _matched_uclusters_v
U plane matched clusters&#39; index.
double start_time_max
Maximum "start time" among all hits in this cluster.
TCEvent evt
Definition: DataStructs.cxx:7
cluster_match_info(unsigned short index)
Constructor with cluster&#39;s index ID.
std::vector< unsigned int > _matched_wclusters_v
W plane matched clusters&#39; index.
std::vector< unsigned int > _matched_vclusters_v
V plane matched clusters&#39; index.
std::vector< double > _tpeak_min_v
std::vector< cluster_match_info > _ucluster_v
Local cluster data container... U-plane.
double start_time_min
Minimum "start time" among all hits in this cluster.