ClusterMergeAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file ClusterMergeAlg.h
3 //
4 // \brief ClusterMergeAlg header file
5 //
6 // \author david.kaleko@gmail.com, kazuhiro@nevis.columbia.edu
7 //
8 ////////////////////////////////////////////////////////////////////////
9 
10 #ifndef CLUSTERMERGEALG_H
11 #define CLUSTERMERGEALG_H
12 
13 // ART includes
14 #include "fhiclcpp/ParameterSet.h"
16 #include "art_root_io/TFileService.h"
17 #include "art_root_io/TFileDirectory.h"
22 
23 // LArSoft
31 // STL
32 #include <set>
33 #include <vector>
34 #include <sstream>
35 
36 // ROOT
37 #include <TString.h>
38 #include <TTree.h>
39 
40 namespace cluster
41 {
42 
43  /**
44  \struct cluster_merge_info
45  A utility struct for cluster-wise analysis information for merging
46  */
48 
49  unsigned int cluster_index; ///< Input cluster ID
50  geo::View_t view; ///< Wire plane ID
51  geo::PlaneID planeID; ///< plane ID
52 
53  float start_wire; ///< Vertex wire
54  float start_time; ///< Vertex time
55  float end_wire; ///< End point wire
56  float end_time; ///< End point time
57 
58  double start_wire_err; ///< Vertex wire error
59  double start_time_err; ///< Vertex time error
60  double end_wire_err; ///< End point wire error
61  double end_time_err; ///< End point time error
62 
63  float angle; ///< 2D starting angle (in radians)
64 
65  /// Default constructor
66  cluster_merge_info(): planeID() {
67 
68  cluster_index = 0xffffffff;
69  view = geo::kUnknown;
70  start_wire = start_time = end_wire = end_time = -1;
71  start_wire_err = start_time_err = end_wire_err =end_time_err = -1;
72 
73  };
74 
75  /// Initialization from a recob::Cluster
77  :cluster_index(cl.ID())
78  ,view(cl.View())
79  ,planeID(cl.Plane())
80  ,start_wire(cl.StartWire())
81  ,start_time(cl.StartTick())
82  ,end_wire(cl.EndWire())
83  ,end_time(cl.EndTick())
84  ,angle(cl.StartAngle())
85  {}
86  };
87 
89 
90  public:
91 
92  /// Default constructor with fhicl parameters
94 
95  /// Method to set verbose mode
96  void VerboseMode(bool on) { _verbose = on; }
97 
98  /// Method to report the current configuration
99  void ReportConfig() const;
100 
101  /// Method to set cut value in degrees for angle compatibility test
102  void SetAngleCut(double angle) { _max_allowed_2D_angle_diff = angle; }
103 
104  /// Method to set cut value in cm^2 for distance compatibility test
105  void SetSquaredDistanceCut(double d) { _max_2D_dist2 = d; }
106 
107  /// Method to add a cluster information for processing
108  void AppendClusterInfo(const recob::Cluster &in_cluster,
109  const std::vector<art::Ptr<recob::Hit> > &in_hit_v);
110 
111  /// Method to add a cluster information for processing
112  void AppendClusterInfo(const art::Ptr<recob::Cluster> in_cluster,
113  const std::vector<art::Ptr<recob::Hit> > &in_hit_v);
114 
115  /// Method to clear event-wise information (both input cluster info & output merged cluster sets)
116  void ClearEventInfo();
117 
118  /**
119  Method to execute the algorithm. All parameter configuration + adding input cluster information
120  should be done before calling this function. This function generate a resulting set of cluster IDs
121  for merging, which can be accessed through GetClusterSets() function.
122  */
123  void ProcessMergeAlg();
124 
125  /// Method to extract resulting set of cluster IDs for merging computed by ProcessMergeAlg() function.
126  const std::vector<std::vector<unsigned int> > GetClusterSets () const {return _cluster_sets_v;};
127 
128  /// Method to compare a compatibility between two clusters
129  bool CompareClusters(const cluster_merge_info &clus_info_A,
130  const cluster_merge_info &clus_info_B);
131 
132  /**
133  Function to compare the 2D angles of two clusters and return true if they are
134  within the maximum allowed parameter. Includes shifting by 180 for backwards clusters.
135  This is called within CompareClusters().
136  */
137  bool Angle2DCompatibility(const cluster_merge_info &clus_info_A,
138  const cluster_merge_info &clus_info_B) const;
139 
140  /**
141  Function to compare the 2D distance of two clusters and return true if they are
142  within the maximum allowed distance.The distance-squared is computed by another
143  function, ShortestDistanceSquared().
144  This is called within CompareClusters().
145  */
146  bool ShortestDistanceCompatibility(const cluster_merge_info &clus_info_A,
147  const cluster_merge_info &clus_info_B) const;
148 
149  /**
150  Function to compute a distance between a 2D point (point_x, point_y) to a 2D finite line segment
151  (start_x, start_y) => (end_x, end_y).
152  */
153  double ShortestDistanceSquared(double point_x, double point_y,
154  double start_x, double start_y,
155  double end_x, double end_y ) const;
156 
157  /**
158  Function to print to screen a specific cluser's info
159  from ClusterPrepAna module. Used for debugging.
160  */
161  void PrintClusterVars(cluster_merge_info clus_info) const;
162 
163  /**
164  Utility function to check if an index is already somewhere inside of _cluster_sets_v vector
165  returns the location of the element vector in _cluster_sets_v that contains the index
166  and returns -1 if the index is not in _cluster_sets_v anywhere
167  */
168  int isInClusterSets(unsigned int index) const;
169 
170  protected:
171 
172  /// Method to set a conversion factor from wire to cm scale
173  void SetWire2Cm(double f) { _wire_2_cm = f; }
174 
175  /// Method to set a conversion factor from time to cm scale
176  void SetTime2Cm(double f) { _time_2_cm = f; }
177 
178  /// Method to clear output merged cluster sets (_cluster_sets_v)
179  void ClearOutputInfo();
180 
181  /// Method to clear input cluster information
182  void ClearInputInfo();
183 
184  /// Method to clear quality control TTree variables
185  void ClearTTreeInfo();
186 
187  /// Method to prepare quality control TTree
188  void PrepareTTree();
189 
190  /// Method to prepare detector parameters
191  void PrepareDetParams();
192 
193  /// Method to fill hit-array-related information
194  void AppendHitInfo(cluster_merge_info &ci,
195  const std::vector<art::Ptr<recob::Hit> > &in_hit_v);
196 
197  /**
198  For a given pair of clusters, this function calls CompareClusters() and append to the resulting
199  merged cluster sets (_cluster_sets_v) by calling AppendToClusterSets() when they are compatible.
200  */
201  void BuildClusterSets(const cluster_merge_info &clus_info_A,
202  const cluster_merge_info &clus_info_B);
203 
204  /**
205  Function to loop through _cluster_sets_v and add in the un-mergable clusters
206  individually, because BuildClusterSets wouldn't have included them anywhere
207  */
208  void FinalizeClusterSets();
209 
210  /// A function to add a cluster to a merged sets (_cluster_sets_v)
211  int AppendToClusterSets(unsigned int cluster_index, int merged_index=-1);
212 
213  protected:
214 
215  bool _verbose; ///< Verbose mode boolean
216  bool _det_params_prepared; ///< Boolean to keep track of detector parameter preparation
217  TTree* _merge_tree; ///< Quality Control TTree pointer
218 
219  /**
220  Book-keeping vector which length is same as input cluster array's length.
221  The stored value is the merged cluster sets' index (_cluster_sets_v).
222  For instance, given 5 clusters (0, 1, 2, 3, 4) as an input among which
223  1,2,3 are to be merged. _cluster_merged_index may hold contents like
224  [1,0,0,0,2] when _cluster_sets_v contents are [[1,2,3],[0],[4]].
225  */
226  std::vector<int> _cluster_merged_index;
227 
228  /**
229  The result container of ProcessMergeAlg() function.
230  The structure is such that the inner vector holds the cluster IDs to be merged into one cluster.
231  Naturally we expect multiple merged clusters, hence it's a vector of vector.
232  */
233  std::vector<std::vector<unsigned int> > _cluster_sets_v;
234 
235  std::vector<cluster::cluster_merge_info> _u_clusters; ///< Input U-plane clusters' information
236  std::vector<cluster::cluster_merge_info> _v_clusters; ///< Input V-plane clusters' information
237  std::vector<cluster::cluster_merge_info> _w_clusters; ///< Input W-plane clusters' information
238 
239  double _wire_2_cm; ///< Conversion factor from wire number to cm scale
240  double _time_2_cm; ///< Conversion factor from time to cm scale
241  double _max_allowed_2D_angle_diff; //in degrees
242  double _max_2D_dist2; //in cm^2
243  double _min_distance_unit; //in cm^2
244  }; // class ClusterMergeAlg
245 
246 } //namespace cluster
247 #endif
void VerboseMode(bool on)
Method to set verbose mode.
void SetSquaredDistanceCut(double d)
Method to set cut value in cm^2 for distance compatibility test.
geo::PlaneID planeID
plane ID
AdcChannelData::View View
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
unsigned int ID
Unknown view.
Definition: geo_types.h:136
std::vector< cluster::cluster_merge_info > _v_clusters
Input V-plane clusters&#39; information.
double _time_2_cm
Conversion factor from time to cm scale.
const std::vector< std::vector< unsigned int > > GetClusterSets() const
Method to extract resulting set of cluster IDs for merging computed by ProcessMergeAlg() function...
cluster_merge_info()
Default constructor.
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
struct vector vector
double end_wire_err
End point wire error.
cluster_merge_info(const recob::Cluster &cl)
Initialization from a recob::Cluster.
double _wire_2_cm
Conversion factor from wire number to cm scale.
TTree * _merge_tree
Quality Control TTree pointer.
Set of hits with a 2D structure.
Definition: Cluster.h:71
std::vector< int > _cluster_merged_index
Cluster finding and building.
Particle class.
QAsciiDict< Entry > cl
std::vector< cluster::cluster_merge_info > _w_clusters
Input W-plane clusters&#39; information.
art framework interface to geometry description
float end_time
End point time.
double start_wire_err
Vertex wire error.
bool _verbose
Verbose mode boolean.
float start_wire
Vertex wire.
void SetTime2Cm(double f)
Method to set a conversion factor from time to cm scale.
void SetAngleCut(double angle)
Method to set cut value in degrees for angle compatibility test.
float start_time
Vertex time.
float angle
2D starting angle (in radians)
std::vector< std::vector< unsigned int > > _cluster_sets_v
bool _det_params_prepared
Boolean to keep track of detector parameter preparation.
unsigned int cluster_index
Input cluster ID.
Declaration of signal hit object.
std::vector< cluster::cluster_merge_info > _u_clusters
Input U-plane clusters&#39; information.
float end_wire
End point wire.
geo::View_t view
Wire plane ID.
Algorithm for generating space points from hits.
recob::tracking::Plane Plane
Definition: TrackState.h:17
double start_time_err
Vertex time error.
double end_time_err
End point time error.
void SetWire2Cm(double f)
Method to set a conversion factor from wire to cm scale.