LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
BlurredClusteringAlg.h
Go to the documentation of this file.
1 // 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
11 
12 #ifndef BlurredClustering_h
13 #define BlurredClustering_h
14 
15 // Framework includes
19 #include "fhiclcpp/fwd.h"
20 
21 // LArSoft includes
25 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
26 namespace detinfo {
27  class DetectorProperties;
28 }
29 namespace lariov {
30  class ChannelStatusProvider;
31 }
32 namespace geo {
33  struct WireID;
34 }
35 
36 // ROOT
37 #include "TString.h"
38 class TCanvas;
39 class TH2F;
40 
41 // c++
42 #include <array>
43 #include <string>
44 #include <vector>
45 
46 namespace cluster {
47  class BlurredClusteringAlg;
48 }
49 
51 public:
54 
56  void CreateDebugPDF(int run, int subrun, int event);
57 
59  void ConvertBinsToClusters(std::vector<std::vector<double>> const& image,
60  std::vector<std::vector<int>> const& allClusterBins,
61  std::vector<art::PtrVector<recob::Hit>>& clusters) const;
62 
64  std::vector<std::vector<double>> ConvertRecobHitsToVector(
66  int readoutWindowSize);
67 
69  int FindClusters(std::vector<std::vector<double>> const& image,
70  std::vector<std::vector<int>>& allcluster) const;
71 
73  int GlobalWire(geo::WireID const& wireID) const;
74 
76  std::vector<std::vector<double>> GaussianBlur(
77  std::vector<std::vector<double>> const& image) const;
78 
80  unsigned int GetMinSize() const noexcept { return fMinSize; }
81 
83  TH2F* MakeHistogram(std::vector<std::vector<double>> const& image, TString name) const;
84 
87  void SaveImage(TH2F* image,
88  std::vector<art::PtrVector<recob::Hit>> const& allClusters,
89  int pad,
90  int tpc,
91  int plane);
92 
94  void SaveImage(TH2F* image, int pad, int tpc, int plane);
95 
98  void SaveImage(TH2F* image,
99  std::vector<std::vector<int>> const& allClusterBins,
100  int pad,
101  int tpc,
102  int plane);
103 
104 private:
106  art::PtrVector<recob::Hit> ConvertBinsToRecobHits(std::vector<std::vector<double>> const& image,
107  std::vector<int> const& bins) const;
108 
110  art::Ptr<recob::Hit> ConvertBinToRecobHit(std::vector<std::vector<double>> const& image,
111  int bin) const;
112 
114  int ConvertWireTickToBin(std::vector<std::vector<double>> const& image, int xbin, int ybin) const;
115 
117  double ConvertBinToCharge(std::vector<std::vector<double>> const& image, int bin) const;
118 
121  std::pair<int, int> DeadWireCount(int wire_bin, int width) const;
122 
124  std::array<int, 4> FindBlurringParameters() const;
125 
127  double GetTimeOfBin(std::vector<std::vector<double>> const& image, int bin) const;
128 
130  std::vector<std::vector<std::vector<double>>> MakeKernels() const;
131 
133  unsigned int NumNeighbours(int nx, std::vector<bool> const& used, int bin) const;
134 
136  bool PassesTimeCut(std::vector<double> const& times, double time) const;
137 
138  bool fDebug;
139  std::string fDetector;
140 
141  // Parameters used in the Blurred Clustering algorithm
142  int fBlurWire; // blur radius for Gauss kernel in the wire direction
143  int fBlurTick; // blur radius for Gauss kernel in the tick direction
144  double fSigmaWire; // sigma for Gaussian kernel in the wire direction
145  double fSigmaTick; // sigma for Gaussian kernel in the tick direction
146  int fMaxTickWidthBlur; // maximum distance to blur a hit based on its natural width in time
147  int fClusterWireDistance; // how far to cluster from seed in wire direction
148  int fClusterTickDistance; // how far to cluster from seed in tick direction
149  unsigned int fNeighboursThreshold; // min. number of neighbors to add to cluster
150  unsigned int fMinNeighbours; // minumum number of neighbors to keep in the cluster
151  unsigned int fMinSize; // minimum size for cluster
152  double fMinSeed; // minimum seed after blurring needed before clustering proceeds
153  double fTimeThreshold; // time threshold for clustering
154  double fChargeThreshold; // charge threshold for clustering
155 
156  // Blurring stuff
157  int fKernelWidth, fKernelHeight;
158  std::vector<std::vector<std::vector<double>>> fAllKernels;
159 
160  // Hit containers
161  std::vector<std::vector<art::Ptr<recob::Hit>>> fHitMap;
162  std::vector<bool> fDeadWires;
163 
164  int fLowerTick, fUpperTick;
165  int fLowerWire, fUpperWire;
166 
167  // For the debug pdf
168  TCanvas* fDebugCanvas{nullptr};
169  std::string fDebugPDFName{};
170 
171  // art service handles
172  geo::WireReadoutGeom const* fWireReadoutGeom{
174  lariov::ChannelStatusProvider const& fChanStatus{
176 };
177 
178 #endif
std::vector< std::vector< art::Ptr< recob::Hit > > > fHitMap
Declaration of signal hit object.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
Cluster finding and building.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void hits()
Definition: readHits.C:15
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:2095
Interface for a class providing readout channel mapping to geometry.
General LArSoft Utilities.
float bin[41]
Definition: plottest35.C:14
Filters for channels, events, etc.
std::vector< std::vector< std::vector< double > > > fAllKernels
ROOT libraries.
art framework interface to geometry description
unsigned int GetMinSize() const noexcept
Minimum size of cluster to save.
Event finding and building.