All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
icarus_tool::ROIMorphological2D Class Reference
Inheritance diagram for icarus_tool::ROIMorphological2D:
icarus_tool::IROILocator

Public Member Functions

 ROIMorphological2D (const fhicl::ParameterSet &pset)
 
 ~ROIMorphological2D ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void initializeHistograms (art::TFileDirectory &) override
 
void FindROIs (const art::Event &, const ArrayFloat &, const std::vector< raw::ChannelID_t > &, const geo::PlaneID &, ArrayFloat &, ArrayBool &) override
 
- Public Member Functions inherited from icarus_tool::IROILocator
virtual ~IROILocator () noexcept=default
 

Private Member Functions

float getMedian (const icarus_signal_processing::VectorFloat, const unsigned int) const
 

Private Attributes

bool fOutputHistograms
 Diagnostic histogram output. More...
 
std::vector< size_t > fStructuringElement
 Structuring element for morphological filter. More...
 
std::vector< float > fThreshold
 Threshold to apply for saving signal. More...
 
std::vector< float > fMedianVec
 
std::vector< float > fRMSVec
 
std::vector< float > fMinValVec
 
std::vector< float > fMaxValVec
 
std::vector< float > fRangeVec
 
std::vector< bool > fHasROIVec
 
TTree * fTupleTree
 output analysis tree More...
 

Additional Inherited Members

- Public Types inherited from icarus_tool::IROILocator
using VectorBool = std::vector< bool >
 
using VectorFloat = std::vector< float >
 
using ArrayBool = std::vector< VectorBool >
 
using ArrayFloat = std::vector< VectorFloat >
 
using PlaneIDVec = std::vector< geo::PlaneID >
 

Detailed Description

Definition at line 30 of file ROIMorphological2D_tool.cc.

Constructor & Destructor Documentation

icarus_tool::ROIMorphological2D::ROIMorphological2D ( const fhicl::ParameterSet &  pset)
explicit

Definition at line 71 of file ROIMorphological2D_tool.cc.

71  : fOutputHistograms(false)
72 {
73  configure(pset);
74 }
bool fOutputHistograms
Diagnostic histogram output.
void configure(const fhicl::ParameterSet &pset) override
icarus_tool::ROIMorphological2D::~ROIMorphological2D ( )

Definition at line 76 of file ROIMorphological2D_tool.cc.

77 {
78 }

Member Function Documentation

void icarus_tool::ROIMorphological2D::configure ( const fhicl::ParameterSet &  pset)
overridevirtual

Implements icarus_tool::IROILocator.

Definition at line 80 of file ROIMorphological2D_tool.cc.

81 {
82  // Start by recovering the parameters
83  fStructuringElement = pset.get<std::vector<size_t> >("StructuringElement", std::vector<size_t>()={8,16});
84  fThreshold = pset.get<std::vector<float> >("Threshold", std::vector<float>()={2.75,2.75,2.75});
85 
86 // fButterworthOrder = pset.get<unsigned int >("ButterworthOrder", 2);
87 // fButterworthThreshold = pset.get<unsigned int >("ButterworthThreshld", 30);
88 
89 // fButterworthFilter = std::make_unique<icarus_signal_processing::HighPassButterworthFilter>(fButterworthThreshold,fButterworthOrder,4096);
90 
91  return;
92 }
std::vector< size_t > fStructuringElement
Structuring element for morphological filter.
std::vector< float > fThreshold
Threshold to apply for saving signal.
void icarus_tool::ROIMorphological2D::FindROIs ( const art::Event &  event,
const ArrayFloat constInputImage,
const std::vector< raw::ChannelID_t > &  channelVec,
const geo::PlaneID planeID,
ArrayFloat morphedWaveforms,
ArrayBool outputROIs 
)
overridevirtual

Implements icarus_tool::IROILocator.

Definition at line 94 of file ROIMorphological2D_tool.cc.

95 {
96  if (morphedWaveforms.size() != constInputImage.size()) morphedWaveforms.resize(constInputImage.size(),icarus_signal_processing::VectorFloat(constInputImage[0].size()));
97 
98  for(auto& morph : morphedWaveforms) std::fill(morph.begin(),morph.end(),0.); // explicit initialization
99 
100  // Make a local copy of the input image so we can do some smoothing
101  ArrayFloat inputImage(constInputImage.size(),VectorFloat(constInputImage[0].size()));
102 
103  // get an instance of the waveform tools
104  icarus_signal_processing::WaveformTools<float> waveformTools;
105 
106  for(size_t waveIdx = 0; waveIdx < inputImage.size(); waveIdx++) waveformTools.triangleSmooth(constInputImage[waveIdx],inputImage[waveIdx]);
107 
108 // ArrayFloat inputImage(constInputImage);
109 
110 // for(auto& waveform : inputImage) (*fButterworthFilter)(waveform);
111 
112  // Use this to get the 2D Dilation of each waveform
113  icarus_signal_processing::Dilation2D(fStructuringElement[0],fStructuringElement[1])(inputImage.begin(),inputImage.size(),morphedWaveforms.begin());
114 
115  if (fOutputHistograms)
116  {
117  fMedianVec.clear();
118  fRMSVec.clear();
119  fMinValVec.clear();
120  fMaxValVec.clear();
121  fRangeVec.clear();
122  fHasROIVec.clear();
123  }
124 
125  // Now traverse each waveform and look for the ROIs
126  for(size_t waveIdx = 0; waveIdx < morphedWaveforms.size(); waveIdx++)
127  {
128  // We start working with the morphed waveform
129  VectorFloat& morphedWave = morphedWaveforms[waveIdx];
130 
131  // We need to zero suppress so we can find the rms
132  float median = getMedian(morphedWave, morphedWave.size());
133 
134  for(auto& val : morphedWave) val -= median;
135 
136 // float threshold = rms * fThreshold[planeID.Plane];
137  float threshold = fThreshold[planeID.Plane];
138 
139  // Right size the selected values array
140  VectorBool& selVals = outputROIs[waveIdx];
141 
142  if (selVals.size() != morphedWave.size()) selVals.resize(morphedWave.size());
143 
144  std::fill(selVals.begin(),selVals.end(),false);
145 
146  bool hasROI(false);
147 
148  for(size_t idx = 0; idx < morphedWave.size(); idx++)
149  {
150  if (morphedWave[idx] > threshold)
151  {
152  selVals[idx] = true;
153  hasROI = true;
154  }
155  }
156 
157  if (fOutputHistograms)
158  {
159  VectorFloat rmsVec = morphedWave;
160  size_t maxIdx = 0.75 * rmsVec.size();
161 
162  std::nth_element(rmsVec.begin(), rmsVec.begin() + maxIdx, rmsVec.end());
163 
164  float rms = std::sqrt(std::inner_product(rmsVec.begin(), rmsVec.begin() + maxIdx, rmsVec.begin(), 0.) / float(maxIdx));
165  float minVal = *std::min_element(morphedWave.begin(),morphedWave.end());
166  float maxVal = *std::max_element(morphedWave.begin(),morphedWave.end());
167 
168  fMedianVec.emplace_back(median);
169  fRMSVec.emplace_back(rms);
170  fMinValVec.emplace_back(minVal);
171  fMaxValVec.emplace_back(maxVal);
172  fRangeVec.emplace_back(maxVal-minVal);
173  fHasROIVec.emplace_back(hasROI);
174  }
175  }
176 
177  if (fOutputHistograms) fTupleTree->Fill();
178 
179  return;
180 }
std::vector< bool > VectorBool
Definition: IROILocator.h:34
std::vector< size_t > fStructuringElement
Structuring element for morphological filter.
std::vector< float > fThreshold
Threshold to apply for saving signal.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
std::vector< VectorFloat > ArrayFloat
Definition: IROILocator.h:37
bool fOutputHistograms
Diagnostic histogram output.
float getMedian(const icarus_signal_processing::VectorFloat, const unsigned int) const
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
std::vector< float > VectorFloat
Definition: IROILocator.h:35
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
TTree * fTupleTree
output analysis tree
float icarus_tool::ROIMorphological2D::getMedian ( const icarus_signal_processing::VectorFloat  vals,
const unsigned int  nVals 
) const
private

Definition at line 182 of file ROIMorphological2D_tool.cc.

183 {
184  float median(0.);
185 
186  if (nVals > 2)
187  {
188  if (nVals % 2 == 0)
189  {
190  const auto m1 = vals.begin() + nVals / 2 - 1;
191  const auto m2 = vals.begin() + nVals / 2;
192  std::nth_element(vals.begin(), m1, vals.begin() + nVals);
193  const auto e1 = *m1;
194  std::nth_element(vals.begin(), m2, vals.begin() + nVals);
195  const auto e2 = *m2;
196  median = (e1 + e2) / 2.0;
197  }
198  else
199  {
200  const auto m = vals.begin() + nVals / 2;
201  std::nth_element(vals.begin(), m, vals.begin() + nVals);
202  median = *m;
203  }
204  }
205 
206  return median;
207 }
tuple m
now if test mode generate materials, CRT shell, world, gdml header else just generate CRT shell for u...
physics pm2 e1
void icarus_tool::ROIMorphological2D::initializeHistograms ( art::TFileDirectory &  histDir)
overridevirtual

Implements icarus_tool::IROILocator.

Definition at line 209 of file ROIMorphological2D_tool.cc.

210 {
211  // It is assumed that the input TFileDirectory has been set up to group histograms into a common
212  // folder at the calling routine's level. Here we create one more level of indirection to keep
213  // histograms made by this tool separate.
214 
215  fTupleTree = histDir.make<TTree>("ROIFinder", "Tree by ROIMorphological2D_tool");
216 
217  fTupleTree->Branch("medians", "std::vector<float>", &fMedianVec);
218  fTupleTree->Branch("RMS", "std::vector<float>", &fRMSVec);
219  fTupleTree->Branch("minvals", "std::vector<float>", &fMinValVec);
220  fTupleTree->Branch("maxvals", "std::vector<float>", &fMaxValVec);
221  fTupleTree->Branch("range", "std::vector<float>", &fRangeVec);
222  fTupleTree->Branch("hasROI", "std::vector<bool>", &fHasROIVec);
223 
224  fOutputHistograms = true;
225 
226  return;
227 }
bool fOutputHistograms
Diagnostic histogram output.
TTree * fTupleTree
output analysis tree

Member Data Documentation

std::vector<bool> icarus_tool::ROIMorphological2D::fHasROIVec
private

Definition at line 62 of file ROIMorphological2D_tool.cc.

std::vector<float> icarus_tool::ROIMorphological2D::fMaxValVec
private

Definition at line 60 of file ROIMorphological2D_tool.cc.

std::vector<float> icarus_tool::ROIMorphological2D::fMedianVec
private

Definition at line 57 of file ROIMorphological2D_tool.cc.

std::vector<float> icarus_tool::ROIMorphological2D::fMinValVec
private

Definition at line 59 of file ROIMorphological2D_tool.cc.

bool icarus_tool::ROIMorphological2D::fOutputHistograms
private

Diagnostic histogram output.

Definition at line 46 of file ROIMorphological2D_tool.cc.

std::vector<float> icarus_tool::ROIMorphological2D::fRangeVec
private

Definition at line 61 of file ROIMorphological2D_tool.cc.

std::vector<float> icarus_tool::ROIMorphological2D::fRMSVec
private

Definition at line 58 of file ROIMorphological2D_tool.cc.

std::vector<size_t> icarus_tool::ROIMorphological2D::fStructuringElement
private

Structuring element for morphological filter.

Definition at line 49 of file ROIMorphological2D_tool.cc.

std::vector<float> icarus_tool::ROIMorphological2D::fThreshold
private

Threshold to apply for saving signal.

Definition at line 50 of file ROIMorphological2D_tool.cc.

TTree* icarus_tool::ROIMorphological2D::fTupleTree
private

output analysis tree

Definition at line 64 of file ROIMorphological2D_tool.cc.


The documentation for this class was generated from the following file: