FuzzyKMeanAlg.h
Go to the documentation of this file.
1 ///
2 /// \file FuzzyKMeanAlg.h
3 /// \brief Utility class for making prongs from vertex
4 /// \version $Id: FuzzyKMeanAlg.h,v 1.4 2012-10-01 00:29:02 edniner Exp $
5 /// \author eniner@indiana.edu
6 ///
7 #ifndef FUZZ_FUZZYKMEANALG_H
8 #define FUZZ_FUZZYKMEANALG_H
9 
10 #include "fhiclcpp/types/Atom.h"
11 
12 #include "RecoBase/HitList.h"
13 
14 #include <string>
15 
16 namespace rb
17 {
18  class Cluster;
19  class HitList;
20 }
21 
22 
23 namespace fuzz
24 {
26  {
27  template<class T> using Atom = fhicl::Atom<T>;
29  using Name = fhicl::Name;
30 
31  Atom<bool> WeightByQ{Name("WeightByQ"), Comment("Weight all hits equally (false), or weight by charge (true)")};
32  Atom<double> Fuzz{Name("Fuzz"), Comment("Degree of fuzzykness in clusters")};
33  Atom<double> Tol{Name("Tol"), Comment("Tolerance for convergence of cluster centers on a solution")};
34  Atom<double> Beta{Name("Beta"), Comment("Cluster spread (2 sigma)")};
35  Atom<double> Memb{Name("Memb"), Comment("Min membership to a clust")};
36  Atom<unsigned int> MaxItr{Name("Maxitr"), Comment("Maximum number of clustering iterations")};
37 
38  Atom<double> Par1{Name("Par1"), Comment("Angular uncertainty has the form F(x)=Par1/x + Par2 + Par3*x."
39  "The parameters were modeled based off of simulations of muons and electrons.")};
40  Atom<double> Par2{Name("Par2"), Comment("Angular uncertainty has the form F(x)=Par1/x + Par2 + Par3*x."
41  "The parameters were modeled based off of simulations of muons and electrons.")};
42  Atom<double> Par3{Name("Par3"), Comment("Angular uncertainty has the form F(x)=Par1/x + Par2 + Par3*x."
43  "The parameters were modeled based off of simulations of muons and electrons.")};
44 
45  Atom<int> Bins{Name("Bins"), Comment("Number of angular bins to use to make density map for seeding")};
46  Atom<double> MergeAng{Name("MergeAng"), Comment("Maximum angular difference between cluster centers to consider a merge (radians)")};
47  Atom<double> MergeMemb{Name("MergeMemb"), Comment("Minimum degree of sharing between two clusters in order to merge")};
48 
49  Atom<double> Cutoff{Name("CutOff"), Comment("Distance (in cm) beyond which the angular uncertainty should remain constant")};
50  Atom<double> Duplicate{Name("Duplicate"), Comment("Threshold for two cluster centers being duplicates (in radians)")};
51  Atom<int> PrintLevel{Name("PrintLevel"), Comment("Level of debugging to control print statements (0=no debug, 1= major info, 2= minor info)")};
52  };
53 
54 
56  {
57  public:
58  explicit FuzzyKMeanAlg(const FuzzyKMeanParams& params);
59  ~FuzzyKMeanAlg();
60 
61  /// \brief Function to take in a cluster and build the hitlist needed to do the clustering
62  void LoadCluster(rb::Cluster slice);
63 
64  /// \brief A function to control all steps in clustering in 2D on a group of hits
65  /// \param minClust The minimum number of cluster candidates to make
66  /// \param maxClust The maximum number of cluster candidates to make
67  /// \param xy The x or y coordinate (depending on view) of the vertex to cluster around
68  /// \param z The z coordinate of the vertex to cluster around
69  /// \param view The detector view (either kX or kY) of the hits to use in clustering. This must be a 2d view
70  void DoClustering(unsigned int minClust, unsigned int maxClust,
71  double xy, double z, geo::View_t view);
72 
73  /// \brief A function to calculate membership weights for a specified number of clusters
74  /// \param n The number of cluster centers to use
75  void MakeClusters(unsigned int n);
76 
77  /// \brief A function to calculate the seeds used for the first round of clustering
78  /// \param n Number of seeds to calculate
79  void SeedA(unsigned int n);
80 
81  /// \brief A function to collect the hits that have not made it to a cluster yet and assign new cluster seeds based on that
82  bool FindUnclustered();
83 
84  /// \brief Calculate and return the distance from a hit to a cluster center
85  /// \param mu Mean position of cluster center (in radians)
86  /// \param x Position of a hit (in radians)
87  /// \param dx The uncertainty in hit position (in radians)
88  double Distance(double mu, double x, double dx);
89 
90  /// \brief Compute all distances for j hits to i cluster centers
91  void ComputeDij();
92 
93  /// \brief Compute the membership values for j hits to i cluster centers
94  void ComputeUij();
95 
96  /// \brief Update the mean cluster center positions
97  bool ComputeA();
98 
99  /// \brief Calculate and return the score evaluating the clustering
100  double Jpfuz();
101 
102  /// \brief Check if each of the cluster centers (after the algorith has converged) is unique, remove duplicates to reseed
103  bool CheckUnique();
104 
105  /// \brief Function to turn the 2D hit coordinates into angles (radians) with respect to the vertex for clustering
106  /// \param vXY The x or y (depending on view) vertex coordinate
107  /// \param vZ The z vertex coordinate
108  /// \param view The view, either kX or kY, of the hits to use. This needs to match the view supplied in vXY
109  void MakeAngles(double vXY, double vZ, geo::View_t view);
110 
111  /// \brief Function to merge cluster centers together that have significant overlap
112  void MergeClusters();
113 
114  public:
115  /// List of hits in slice
117 
118  /// Distance from vertex
119  std::vector<double> fDist;
120 
121  /// Hit weight, currently PE
122  std::vector<double> fW;
123 
124  /// Angle to vertex
125  std::vector<double> fX;
126 
127  /// Uncertainty in angle
128  std::vector<double> fdX;
129 
130  /// Dist clust i to sub. j
131  std::vector< std::vector<double> > fD;
132 
133  /// Assign cluster i to sub. j
134  std::vector< std::vector<double> > fU;
135 
136  /// Cluster centers
137  std::vector<double> fA;
138 
139  /// List of used seeds
140  std::vector<double> fSeed;
141 
142  /// Unused cell pos., uncert
143  std::vector<std::pair<double,double> > fUnused;
144 
145  /// List of max densities
146  std::vector<std::pair<double,double> > fLMax;
147 
148  private:
150  };
151 }
152 
153 
154 #endif
155 ////////////////////////////////////////////////////////////////////////
std::vector< std::vector< double > > fD
Dist clust i to sub. j.
std::vector< double > fSeed
List of used seeds.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::vector< double > fDist
Distance from vertex.
std::vector< DAQHit > HitList
Definition: HitList.h:15
std::vector< double > fdX
Uncertainty in angle.
A collection of associated CellHits.
Definition: Cluster.h:47
double Distance(double x1, double y1, double x2, double y2)
std::vector< double > fX
Angle to vertex.
std::vector< std::pair< double, double > > fLMax
List of max densities.
Just the essential information required for track fitting.
Definition: HitList.h:40
double dx[NP][NC]
std::vector< double > fA
Cluster centers.
std::vector< std::vector< double > > fU
Assign cluster i to sub. j.
rb::HitList fHL
List of hits in slice.
Fuzzy k-Means prong-finding algorithm.
FuzzyKMeanParams fParams
Perform a "2 point" Hough transform on a collection of hits.
z
Definition: test.py:28
std::vector< double > fW
Hit weight, currently PE.
std::vector< std::pair< double, double > > fUnused
Unused cell pos., uncert.
float Beta() const