All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROICannyEdgeDetection_tool.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file ROICannyEdgeDetection.cc
3 /// \author T. Usher
4 ////////////////////////////////////////////////////////////////////////
5 
6 #include <cmath>
8 #include "art/Utilities/ToolMacros.h"
9 #include "art/Utilities/make_tool.h"
10 #include "art_root_io/TFileService.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
12 #include "cetlib_except/exception.h"
13 #include "cetlib/cpu_timer.h"
16 #include "icarus_signal_processing/WaveformTools.h"
17 #include "icarus_signal_processing/Denoising.h"
18 #include "icarus_signal_processing/ROIFinder2D.h"
19 
20 #include "TH1F.h"
21 #include "TH2F.h"
22 #include "TProfile.h"
23 
24 #include <fstream>
25 #include <chrono>
26 
27 namespace icarus_tool
28 {
29 
31 {
32 public:
33  explicit ROICannyEdgeDetection(const fhicl::ParameterSet& pset);
34 
36 
37  void configure(const fhicl::ParameterSet& pset) override;
38  void initializeHistograms(art::TFileDirectory&) override {return;}
39 
40  void FindROIs(const art::Event&, const ArrayFloat&, const std::vector<raw::ChannelID_t>&, const geo::PlaneID&, ArrayFloat&, ArrayBool&) override;
41 
42 private:
43 
44  using FloatPairVec = std::vector<std::pair<float,float>>;
45 
46  bool fDiagnosticOutput; //< Enable diagnostic output if desired
47 
48  // Start with parameters for Butterworth Filter
49  unsigned int fButterworthOrder; ///< Order parameter for Butterworth filter
50  unsigned int fButterworthThreshold; ///< Threshold for Butterworth filter
51 
52 // // Parameters for the 2D morphological filter
53 // unsigned int fMorph2DStructuringElementX; ///< Structuring element in X
54 // unsigned int fMorph2DStructuringElementY; ///< Structuring element in Y
55 //
56 // // Parameters for the denoiser
57 // unsigned int fCoherentNoiseGrouping; ///< Number of consecutive channels in coherent noise subtraction
58 // unsigned int fCoherentNoiseOffset; ///< Offset for the midplane...
59 // unsigned int fMorphologicalWindow; ///< Window size for filter
60 //// bool fOutputStats; ///< Output of timiing statistics?
61 // float fCoherentThresholdFactor; ///< Threshold factor for coherent noise removal
62 
63  // Parameters for the ROI finding
64  unsigned int fADFilter_SX; ///<
65  unsigned int fADFilter_SY; ///<
66  float fSigma_x; ///<
67  float fSigma_y; ///<
68  float fSigma_r; ///<
69  float fLowThreshold; ///<
70  float fHighThreshold; ///<
71  unsigned int fBinaryDilation_SX; ///<
72  unsigned int fBinaryDilation_SY; ///<
73 
74  icarus_signal_processing::VectorFloat fThresholdVec;
75 
76  const geo::Geometry* fGeometry; //< pointer to the Geometry service
77 
78  // Our denoising functions
79  std::unique_ptr<icarus_signal_processing::IFFTFilterFunction> fButterworthFilter;
80 // std::unique_ptr<icarus_signal_processing::IMorphologicalFunctions2D> fMorphologicalFilter;
81 // std::unique_ptr<icarus_signal_processing::IDenoiser2D> fDenoiser2D;
82  std::unique_ptr<icarus_signal_processing::BilateralFilters> fBilateralFilters;
83  std::unique_ptr<icarus_signal_processing::EdgeDetection> fEdgeDetection;
84  std::unique_ptr<icarus_signal_processing::IROIFinder2D> fROIFinder2D;
85 };
86 
87 //----------------------------------------------------------------------
88 // Constructor.
89 ROICannyEdgeDetection::ROICannyEdgeDetection(const fhicl::ParameterSet& pset)
90 {
91  configure(pset);
92 }
93 
95 {
96 }
97 
98 void ROICannyEdgeDetection::configure(const fhicl::ParameterSet& pset)
99 {
100  fDiagnosticOutput = pset.get<bool >("DiagnosticOutput", false);
101 
102  fButterworthOrder = pset.get<unsigned int >("ButterworthOrder", 2);
103  fButterworthThreshold = pset.get<unsigned int >("ButterworthThreshld", 30);
104 
105  fButterworthFilter = std::make_unique<icarus_signal_processing::HighPassButterworthFilter>(fButterworthThreshold,fButterworthOrder,4096);
106  //fButterworthFilter = std::make_unique<icarus_signal_processing::NoFFTFilter>();
107 
108 // fMorph2DStructuringElementX = pset.get<unsigned int >("Morph2DStructuringElementX", 7);
109 // fMorph2DStructuringElementY = pset.get<unsigned int >("Morph2DStructuringElementX", 28);
110 //
111 // fMorphologicalFilter = std::make_unique<icarus_signal_processing::Dilation2D>(fMorph2DStructuringElementX,fMorph2DStructuringElementY);
112 //
113 // fCoherentNoiseGrouping = pset.get<unsigned int >("CoherentNoiseGrouping", 32);
114 // fCoherentNoiseOffset = pset.get<unsigned int >("CoherentNoiseOffset", 24);
115 // fMorphologicalWindow = pset.get<unsigned int >("MorphologicalWindow", 10);
116 // fCoherentThresholdFactor = pset.get<float >("CoherentThresholdFactor", 2.5);
117 //
118 // fThresholdVec.resize(6560/fCoherentNoiseGrouping,fCoherentThresholdFactor);
119 //
120 // fDenoiser2D = std::make_unique<icarus_signal_processing::Denoiser2D_Hough>(fMorphologicalFilter.get(), fThresholdVec, fCoherentNoiseGrouping, fCoherentNoiseOffset, fMorphologicalWindow);
121 // //fDenoiser2D = std::make_unique<icarus_signal_processing::Denoiser2D>(fMorphologicalFilter.get(), fThresholdVec, fCoherentNoiseGrouping, fMorphologicalWindow);
122 
123  fADFilter_SX = pset.get<unsigned int >("ADFilter_SX", 7);
124  fADFilter_SY = pset.get<unsigned int >("ADFilter_SY", 7);
125  fSigma_x = pset.get<float >("Sigma_x", 10.0);
126  fSigma_y = pset.get<float >("Sigma_y", 10.0);
127  fSigma_r = pset.get<float >("Sigma_r", 30.0);
128 
129  fLowThreshold = pset.get<float >("LowThreshold", 10.0);
130  fHighThreshold = pset.get<float >("HighThreshold", 20.0);
131 
132  fBinaryDilation_SX = pset.get<unsigned int >("BinaryDilation_SX", 31);
133  fBinaryDilation_SY = pset.get<unsigned int >("BinaryDilation_SY", 31);
134 
135  fBilateralFilters = std::make_unique<icarus_signal_processing::BilateralFilters>();
136  fEdgeDetection = std::make_unique<icarus_signal_processing::EdgeDetection>();
137 
138  fROIFinder2D = std::make_unique<icarus_signal_processing::ROICannyFilter>(fButterworthFilter.get(),
139  nullptr, //fDenoiser2D.get(),
140  fBilateralFilters.get(),
141  fEdgeDetection.get(),
142  fADFilter_SX,
143  fADFilter_SY,
144  fSigma_x,
145  fSigma_y,
146  fSigma_r,
151 
152  fGeometry = art::ServiceHandle<geo::Geometry const>{}.get();
153 
154  return;
155 }
156 
157 void ROICannyEdgeDetection::FindROIs(const art::Event& event, const ArrayFloat& inputImage, const std::vector<raw::ChannelID_t>& channelVec, const geo::PlaneID& planeID, ArrayFloat& output, ArrayBool& outputROIs)
158 {
159  cet::cpu_timer theClockTotal;
160 
161  theClockTotal.start();
162 
163  std::cout << " --> calling icarus_signal_processing canny edge finder" << std::endl;
164 
165  // Now pass the entire data array to the denoisercoherent
166  (*fROIFinder2D)(inputImage,output,outputROIs); //,fWaveLessCoherent,fCorrectedMedians,fIntrinsicRMS,fMorphedWaveforms,finalErosion);
167 
168  std::cout << " --> have returned from canny" << std::endl;
169 
170  theClockTotal.stop();
171 
172  double totalTime = theClockTotal.accumulated_real_time();
173 
174  mf::LogInfo("TPCNoiseFilterCannyMC") << " *totalTime: " << totalTime << std::endl;
175 
176  std::cout << "--> ROICannyEdgeDetection finished!" << std::endl;
177  std::cout << " - Total time: " << totalTime << std::endl;
178 
179  return;
180 }
181 
182 DEFINE_ART_CLASS_TOOL(ROICannyEdgeDetection)
183 }
void initializeHistograms(art::TFileDirectory &) override
std::unique_ptr< icarus_signal_processing::IROIFinder2D > fROIFinder2D
void configure(const fhicl::ParameterSet &pset) override
std::vector< VectorBool > ArrayBool
Definition: IROILocator.h:36
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
std::vector< VectorFloat > ArrayFloat
Definition: IROILocator.h:37
unsigned int fButterworthThreshold
Threshold for Butterworth filter.
void FindROIs(const art::Event &, const ArrayFloat &, const std::vector< raw::ChannelID_t > &, const geo::PlaneID &, ArrayFloat &, ArrayBool &) override
unsigned int fButterworthOrder
Order parameter for Butterworth filter.
ROICannyEdgeDetection(const fhicl::ParameterSet &pset)
std::unique_ptr< icarus_signal_processing::BilateralFilters > fBilateralFilters
The geometry of one entire detector, as served by art.
Definition: Geometry.h:181
std::vector< std::pair< float, float >> FloatPairVec
icarus_signal_processing::VectorFloat fThresholdVec
std::unique_ptr< icarus_signal_processing::EdgeDetection > fEdgeDetection
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
This provides an interface for tools which are tasked with finding ROI&#39;s in input waveforms...
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::unique_ptr< icarus_signal_processing::IFFTFilterFunction > fButterworthFilter