BlurredClusteringAlg.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////
2 // Implementation of the Blurred Clustering algorithm
3 //
4 // Converts a hit map into a 2D image of the hits before convoling
5 // with a Gaussian function to introduce a weighted blurring.
6 // Clustering proceeds on this blurred image to create more
7 // complete clusters.
8 //
9 // M Wallbank (m.wallbank@sheffield.ac.uk), May 2015
10 ////////////////////////////////////////////////////////////////////
11 
12 #ifndef BlurredClustering_h
13 #define BlurredClustering_h
14 
15 // Framework includes
17 
18 // LArSoft includes
22 namespace detinfo {
23  class DetectorProperties;
24 }
25 namespace fhicl {
26  class ParameterSet;
27 }
28 namespace lariov {
29  class ChannelStatusProvider;
30 }
31 namespace geo {
32  struct WireID;
33 }
34 
35 // ROOT
36 #include "TString.h"
37 class TCanvas;
38 class TH2F;
39 
40 // c++
41 #include <array>
42 #include <string>
43 #include <vector>
44 
45 namespace cluster {
46  class BlurredClusteringAlg;
47 }
48 
50 public:
53 
54  /// Create the PDF to save debug images
55  void CreateDebugPDF(int run, int subrun, int event);
56 
57  /// Takes a vector of clusters (itself a vector of hits) and turns them into clusters using the initial hit selection
58  void ConvertBinsToClusters(std::vector<std::vector<double>> const& image,
59  std::vector<std::vector<int>> const& allClusterBins,
60  std::vector<art::PtrVector<recob::Hit>>& clusters) const;
61 
62  /// Takes hit map and returns a 2D vector representing wire and tick, filled with the charge
63  std::vector<std::vector<double>> ConvertRecobHitsToVector(
64  std::vector<art::Ptr<recob::Hit>> const& hits,
65  int readoutWindowSize);
66 
67  /// Find clusters in the histogram
68  int FindClusters(std::vector<std::vector<double>> const& image,
69  std::vector<std::vector<int>>& allcluster) const;
70 
71  /// Find the global wire position
72  int GlobalWire(geo::WireID const& wireID) const;
73 
74  /// Applies Gaussian blur to image
75  std::vector<std::vector<double>> GaussianBlur(
76  std::vector<std::vector<double>> const& image) const;
77 
78  /// Minimum size of cluster to save
79  unsigned int
80  GetMinSize() const noexcept
81  {
82  return fMinSize;
83  }
84 
85  /// Converts a 2D vector in a histogram for the debug pdf
86  TH2F* MakeHistogram(std::vector<std::vector<double>> const& image, TString name) const;
87 
88  /// Save the images for debugging
89  /// This version takes the final clusters and overlays on the hit map
90  void SaveImage(TH2F* image,
91  std::vector<art::PtrVector<recob::Hit>> const& allClusters,
92  int pad,
93  int tpc,
94  int plane);
95 
96  /// Save the images for debugging
97  void SaveImage(TH2F* image, int pad, int tpc, int plane);
98 
99  /// Save the images for debugging
100  /// This version takes a vector of bins and overlays the relevant bins on the hit map
101  void SaveImage(TH2F* image,
102  std::vector<std::vector<int>> const& allClusterBins,
103  int pad,
104  int tpc,
105  int plane);
106 
107 private:
108  /// Converts a vector of bins into a hit selection - not all the hits in the bins vector are real hits
109  art::PtrVector<recob::Hit> ConvertBinsToRecobHits(std::vector<std::vector<double>> const& image,
110  std::vector<int> const& bins) const;
111 
112  /// Converts a bin into a recob::Hit (not all of these bins correspond to recob::Hits - some are fake hits created by the blurring)
113  art::Ptr<recob::Hit> ConvertBinToRecobHit(std::vector<std::vector<double>> const& image,
114  int bin) const;
115 
116  /// Converts an xbin and a ybin to a global bin number
117  int ConvertWireTickToBin(std::vector<std::vector<double>> const& image, int xbin, int ybin) const;
118 
119  /// Returns the charge stored in the global bin value
120  double ConvertBinToCharge(std::vector<std::vector<double>> const& image, int bin) const;
121 
122  /// Count how many dead wires there are in the blurring region for a particular hit
123  /// Returns a pair of counters representing how many dead wires there are below and above the hit respectively
124  std::pair<int, int> DeadWireCount(int wire_bin, int width) const;
125 
126  /// Dynamically find the blurring radii and Gaussian sigma in each dimension
127  std::array<int, 4> FindBlurringParameters() const;
128 
129  /// Returns the hit time of a hit in a particular bin
130  double GetTimeOfBin(std::vector<std::vector<double>> const& image, int bin) const;
131 
132  /// Makes all the kernels which could be required given the tuned parameters
133  std::vector<std::vector<std::vector<double>>> MakeKernels() const;
134 
135  /// Determines the number of clustered neighbours of a hit
136  unsigned int NumNeighbours(int nx, std::vector<bool> const& used, int bin) const;
137 
138  /// Determine if a hit is within a time threshold of any other hits in a cluster
139  bool PassesTimeCut(std::vector<double> const& times, double time) const;
140 
141  bool fDebug;
143 
144  // Parameters used in the Blurred Clustering algorithm
145  int fBlurWire; // blur radius for Gauss kernel in the wire direction
146  int fBlurTick; // blur radius for Gauss kernel in the tick direction
147  double fSigmaWire; // sigma for Gaussian kernel in the wire direction
148  double fSigmaTick; // sigma for Gaussian kernel in the tick direction
149  int fMaxTickWidthBlur; // maximum distance to blur a hit based on its natural width in time
150  int fClusterWireDistance; // how far to cluster from seed in wire direction
151  int fClusterTickDistance; // how far to cluster from seed in tick direction
152  unsigned int fNeighboursThreshold; // min. number of neighbors to add to cluster
153  unsigned int fMinNeighbours; // minumum number of neighbors to keep in the cluster
154  unsigned int fMinSize; // minimum size for cluster
155  double fMinSeed; // minimum seed after blurring needed before clustering proceeds
156  double fTimeThreshold; // time threshold for clustering
157  double fChargeThreshold; // charge threshold for clustering
158 
159  // Blurring stuff
160  int fKernelWidth, fKernelHeight;
161  std::vector<std::vector<std::vector<double>>> fAllKernels;
162 
163  // Hit containers
164  std::vector<std::vector<art::Ptr<recob::Hit>>> fHitMap;
165  std::vector<bool> fDeadWires;
166 
167  int fLowerTick, fUpperTick;
168  int fLowerWire, fUpperWire;
169 
170  // For the debug pdf
171  TCanvas* fDebugCanvas{nullptr};
172  std::string fDebugPDFName{};
173 
174  // art service handles
176  lariov::ChannelStatusProvider const& fChanStatus{
178 };
179 
180 #endif
static QCString name
Definition: declinfo.cpp:673
std::vector< std::vector< art::Ptr< recob::Hit > > > fHitMap
std::string string
Definition: nybbler.cc:12
struct vector vector
Cluster finding and building.
art framework interface to geometry description
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
float DeadWireCount(const TCSlice &slc, const TrajPoint &tp1, const TrajPoint &tp2)
Definition: Utils.cxx:2139
Class providing information about the quality of channels.
General LArSoft Utilities.
art::ServiceHandle< geo::Geometry const > fGeom
Filters for channels, events, etc.
Declaration of signal hit object.
QTextStream & bin(QTextStream &s)
std::vector< std::vector< std::vector< double > > > fAllKernels
Interface for experiment-specific service for channel quality info.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
unsigned int GetMinSize() const noexcept
Minimum size of cluster to save.
Event finding and building.