LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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
23 
24 // LArSoft includes
25 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom<>()
27 #include "larevt/CalibrationDBI/Interface/ChannelStatusService.h"
28 #include "larevt/CalibrationDBI/Interface/ChannelStatusProvider.h"
35 
36 // ROOT
37 #include <TTree.h>
38 #include <TH2F.h>
39 #include <TH2.h>
40 #include <TCanvas.h>
41 #include <TCutG.h>
42 #include <TString.h>
43 #include <TMarker.h>
44 #include <TColor.h>
45 #include <TCanvas.h>
46 #include <TStyle.h>
47 #include <TVirtualPad.h>
48 #include <TLatex.h>
49 #include <TGraph.h>
50 #include <TF1.h>
51 #include <TLine.h>
52 #include <TPrincipal.h>
53 #include <TMath.h>
54 #include <TVector.h>
55 #include <TVectorD.h>
56 #include <TVector2.h>
57 
58 // c++
59 #include <string>
60 #include <vector>
61 #include <map>
62 #include <sstream>
63 
64 
65 namespace cluster {
66  class BlurredClusteringAlg;
67 }
68 
70 public:
71 
73  virtual ~BlurredClusteringAlg();
74 
75  void reconfigure(fhicl::ParameterSet const&p);
76 
78  void CreateDebugPDF(int run, int subrun, int event);
79 
81  void ConvertBinsToClusters(std::vector<std::vector<double> > const& image,
82  std::vector<std::vector<int> > const& allClusterBins,
84 
86  std::vector<std::vector<double> > ConvertRecobHitsToVector(std::vector<art::Ptr<recob::Hit> > const& hits);
87 
89  int FindClusters(std::vector<std::vector<double> > const& image, std::vector<std::vector<int> >& allcluster);
90 
92  int GlobalWire(geo::WireID const& wireID);
93 
95  std::vector<std::vector<double> > GaussianBlur(std::vector<std::vector<double> > const& image);
96 
98  unsigned int GetMinSize() { return fMinSize; }
99 
101  TH2F* MakeHistogram(std::vector<std::vector<double> > const& image, TString name);
102 
105  void SaveImage(TH2F* image, std::vector<art::PtrVector<recob::Hit> > const& allClusters, int pad, int tpc, int plane);
106 
108  void SaveImage(TH2F* image, int pad, int tpc, int plane);
109 
112  void SaveImage(TH2F* image, std::vector<std::vector<int> > const& allClusterBins, int pad, int tpc, int plane);
113 
114 private:
115 
117  art::PtrVector<recob::Hit> ConvertBinsToRecobHits(std::vector<std::vector<double> > const& image, std::vector<int> const& bins);
118 
120  art::Ptr<recob::Hit> ConvertBinToRecobHit(std::vector<std::vector<double> > const& image, int bin);
121 
123  int ConvertWireTickToBin(std::vector<std::vector<double> > const& image, int xbin, int ybin);
124 
126  double ConvertBinToCharge(std::vector<std::vector<double> > const& image, int bin);
127 
130  std::pair<int,int> DeadWireCount(int wire_bin, int width);
131 
133  void FindBlurringParameters(int& blurwire, int& blurtick, int& sigmawire, int& sigmatick);
134 
136  double GetTimeOfBin(std::vector<std::vector<double> > const& image, int bin);
137 
139  void MakeKernels();
140 
142  unsigned int NumNeighbours(int nx, std::vector<bool> const& used, int bin);
143 
145  bool PassesTimeCut(std::vector<double> const& times, double time);
146 
147  bool fDebug;
148  std::string fDetector;
149 
150  // Parameters used in the Blurred Clustering algorithm
151  int fBlurWire; // blur radius for Gauss kernel in the wire direction
152  int fBlurTick; // blur radius for Gauss kernel in the tick direction
153  double fSigmaWire; // sigma for Gaussian kernel in the wire direction
154  double fSigmaTick; // sigma for Gaussian kernel in the tick direction
155  int fMaxTickWidthBlur; // maximum distance to blur a hit based on its natural width in time
156  int fClusterWireDistance; // how far to cluster from seed in wire direction
157  int fClusterTickDistance; // how far to cluster from seed in tick direction
158 // unsigned int fMinMergeClusterSize; // minimum size of a cluster to consider merging it to another
159  unsigned int fNeighboursThreshold; // min. number of neighbors to add to cluster
160  int fMinNeighbours; // minumum number of neighbors to keep in the cluster
161  unsigned int fMinSize; // minimum size for cluster
162  double fMinSeed; // minimum seed after blurring needed before clustering proceeds
163  double fTimeThreshold; // time threshold for clustering
164  double fChargeThreshold; // charge threshold for clustering
165 
166  // Blurring stuff
168  std::vector<std::vector<std::vector<double> > > fAllKernels;
169 
170  // Hit containers
171  std::vector<std::vector<art::Ptr<recob::Hit> > > fHitMap;
172  std::vector<bool> fDeadWires;
173 
176 
177  // For the debug pdf
178  TCanvas* fDebugCanvas;
179  std::string fDebugPDFName;
180 
181  // art service handles
184  lariov::ChannelStatusProvider const& fChanStatus = art::ServiceHandle<lariov::ChannelStatusService>()->GetProvider();
185 
186 };
187 
188 #endif
void FindBlurringParameters(int &blurwire, int &blurtick, int &sigmawire, int &sigmatick)
Dynamically find the blurring radii and Gaussian sigma in each dimension.
void SaveImage(TH2F *image, std::vector< art::PtrVector< recob::Hit > > const &allClusters, int pad, int tpc, int plane)
int FindClusters(std::vector< std::vector< double > > const &image, std::vector< std::vector< int > > &allcluster)
Find clusters in the histogram.
BlurredClusteringAlg(fhicl::ParameterSet const &pset)
Utilities related to art service access.
std::pair< int, int > DeadWireCount(int wire_bin, int width)
std::vector< std::vector< double > > GaussianBlur(std::vector< std::vector< double > > const &image)
Applies Gaussian blur to image.
void reconfigure(fhicl::ParameterSet const &p)
std::vector< std::vector< art::Ptr< recob::Hit > > > fHitMap
Declaration of signal hit object.
unsigned int NumNeighbours(int nx, std::vector< bool > const &used, int bin)
Determines the number of clustered neighbours of a hit.
double GetTimeOfBin(std::vector< std::vector< double > > const &image, int bin)
Returns the hit time of a hit in a particular bin.
Cluster finding and building.
art::ServiceHandle< geo::Geometry > fGeom
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
bool PassesTimeCut(std::vector< double > const &times, double time)
Determine if a hit is within a time threshold of any other hits in a cluster.
void CreateDebugPDF(int run, int subrun, int event)
Create the PDF to save debug images.
void hits()
Definition: readHits.C:15
int ConvertWireTickToBin(std::vector< std::vector< double > > const &image, int xbin, int ybin)
Converts an xbin and a ybin to a global bin number.
art::PtrVector< recob::Hit > ConvertBinsToRecobHits(std::vector< std::vector< double > > const &image, std::vector< int > const &bins)
Converts a vector of bins into a hit selection - not all the hits in the bins vector are real hits...
Provides recob::Track data product.
float bin[41]
Definition: plottest35.C:14
Encapsulate the geometry of a wire.
void MakeKernels()
Makes all the kernels which could be required given the tuned parameters.
TH2F * MakeHistogram(std::vector< std::vector< double > > const &image, TString name)
Converts a 2D vector in a histogram for the debug pdf.
Encapsulate the construction of a single detector plane.
art::Ptr< recob::Hit > ConvertBinToRecobHit(std::vector< std::vector< double > > const &image, int bin)
Converts a bin into a recob::Hit (not all of these bins correspond to recob::Hits - some are fake hit...
std::vector< std::vector< double > > ConvertRecobHitsToVector(std::vector< art::Ptr< recob::Hit > > const &hits)
Takes hit map and returns a 2D vector representing wire and tick, filled with the charge...
std::vector< std::vector< std::vector< double > > > fAllKernels
double ConvertBinToCharge(std::vector< std::vector< double > > const &image, int bin)
Returns the charge stored in the global bin value.
lariov::ChannelStatusProvider const & fChanStatus
detinfo::DetectorProperties const * fDetProp
void ConvertBinsToClusters(std::vector< std::vector< double > > const &image, std::vector< std::vector< int > > const &allClusterBins, std::vector< art::PtrVector< recob::Hit > > &clusters)
Takes a vector of clusters (itself a vector of hits) and turns them into clusters using the initial h...
unsigned int GetMinSize()
Minimum size of cluster to save.
art framework interface to geometry description
Event finding and building.
int GlobalWire(geo::WireID const &wireID)
Find the global wire position.