LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
reco_tool::CandHitMorphological Class Reference
Inheritance diagram for reco_tool::CandHitMorphological:
reco_tool::ICandidateHitFinder

Public Member Functions

 CandHitMorphological (const fhicl::ParameterSet &pset)
 
 ~CandHitMorphological ()
 
void configure (const fhicl::ParameterSet &pset) override
 
void findHitCandidates (const Waveform &, size_t, size_t, size_t, HitCandidateVec &) const override
 
void MergeHitCandidates (const Waveform &, const HitCandidateVec &, MergeHitCandidateVec &) const override
 

Private Types

using HitCandidate_t = struct HitCandidate{size_t startTick
 
using HitCandidateVec = std::vector< HitCandidate_t >
 
using MergeHitCandidateVec = std::vector< HitCandidateVec >
 
using Waveform = std::vector< float >
 

Private Member Functions

void findHitCandidates (Waveform::const_iterator, Waveform::const_iterator, Waveform::const_iterator, Waveform::const_iterator, Waveform::const_iterator, Waveform::const_iterator, size_t, float, HitCandidateVec &) const
 
void findHitCandidates (Waveform::const_iterator, Waveform::const_iterator, size_t, int, float, HitCandidateVec &) const
 
Waveform::const_iterator findNearestMax (Waveform::const_iterator, Waveform::const_iterator) const
 
Waveform::const_iterator findNearestMin (Waveform::const_iterator, Waveform::const_iterator) const
 
Waveform::const_iterator findStartTick (Waveform::const_iterator, Waveform::const_iterator) const
 
Waveform::const_iterator findStopTick (Waveform::const_iterator, Waveform::const_iterator) const
 

Private Attributes

size_t fPlane
 
float fDilationThreshold
 
float fDilationFraction
 
float fErosionFraction
 
int fMinDeltaTicks
 
float fMinDeltaPeaks
 
float fMinHitHeight
 
size_t fNumInterveningTicks
 
int fStructuringElement
 
bool fOutputHistograms
 
art::TFileDirectoryfHistDirectory
 
TH1F * fDStopStartHist
 
TH1F * fDMaxTickMinTickHist
 
TH1F * fDMaxDerivMinDerivHist
 
size_t fLastChannel
 
size_t fChannelCnt
 
std::unique_ptr< reco_tool::IWaveformToolfWaveformTool
 
const geo::GeometryCorefGeometry = lar::providerFrom<geo::Geometry>()
 
size_t stopTick
 
size_t maxTick
 
size_t minTick
 
float maxDerivative
 
float minDerivative
 
float hitCenter
 
float hitSigma
 
float hitHeight
 

Detailed Description

Definition at line 26 of file CandHitMorphological_tool.cc.

Member Typedef Documentation

using reco_tool::ICandidateHitFinder::HitCandidate_t = struct HitCandidate { size_t startTick
inherited

Definition at line 30 of file ICandidateHitFinder.h.

Definition at line 41 of file ICandidateHitFinder.h.

Definition at line 42 of file ICandidateHitFinder.h.

using reco_tool::ICandidateHitFinder::Waveform = std::vector<float>
inherited

Definition at line 44 of file ICandidateHitFinder.h.

Constructor & Destructor Documentation

reco_tool::CandHitMorphological::CandHitMorphological ( const fhicl::ParameterSet pset)
explicit

Definition at line 101 of file CandHitMorphological_tool.cc.

References configure().

102 {
103  configure(pset);
104 }
void configure(const fhicl::ParameterSet &pset) override
reco_tool::CandHitMorphological::~CandHitMorphological ( )

Definition at line 106 of file CandHitMorphological_tool.cc.

107 {
108 }

Member Function Documentation

void reco_tool::CandHitMorphological::configure ( const fhicl::ParameterSet pset)
overridevirtual

Implements reco_tool::ICandidateHitFinder.

Definition at line 110 of file CandHitMorphological_tool.cc.

References dir, fChannelCnt, fDilationFraction, fDilationThreshold, fDMaxDerivMinDerivHist, fDMaxTickMinTickHist, fDStopStartHist, fErosionFraction, fHistDirectory, fLastChannel, fMinDeltaPeaks, fMinDeltaTicks, fMinHitHeight, fNumInterveningTicks, fOutputHistograms, fPlane, fStructuringElement, fWaveformTool, art::ServiceHandle< T, SCOPE >::get(), fhicl::ParameterSet::get(), art::TFileDirectory::make(), max, and art::TFileDirectory::mkdir().

Referenced by CandHitMorphological().

111 {
112  // Recover our parameters
113  fPlane = pset.get< size_t >("Plane", 0);
114  fDilationThreshold = pset.get< float >("DilationThreshold", 4.);
115  fDilationFraction = pset.get< float >("DilationFraction", 0.75);
116  fErosionFraction = pset.get< float >("ErosionFraction", 0.2);
117  fMinDeltaTicks = pset.get< int >("MinDeltaTicks", 0);
118  fMinDeltaPeaks = pset.get< float >("MinDeltaPeaks", 0.025);
119  fMinHitHeight = pset.get< float >("MinHitHeight", 1.0);
120  fNumInterveningTicks = pset.get< size_t >("NumInterveningTicks", 6);
121  fStructuringElement = pset.get< int >("StructuringElement", 20);
122  fOutputHistograms = pset.get< bool >("OutputHistograms", false);
123 
124  // Recover the baseline tool
125  fWaveformTool = art::make_tool<reco_tool::IWaveformTool> (pset.get<fhicl::ParameterSet>("WaveformAlgs"));
126 
127  // Set the last channel to some nonsensical value
129  fChannelCnt = 0;
130 
131  // If asked, define the global histograms
132  if (fOutputHistograms)
133  {
134  // Access ART's TFileService, which will handle creating and writing
135  // histograms and n-tuples for us.
137 
138  fHistDirectory = tfs.get();
139 
140  // Make a directory for these histograms
141  art::TFileDirectory dir = fHistDirectory->mkdir(Form("HitPlane_%1zu",fPlane));
142 
143  fDStopStartHist = dir.make<TH1F>(Form("DStopStart_%1zu", fPlane), ";Delta Stop/Start;", 200, 0., 200.);
144  fDMaxTickMinTickHist = dir.make<TH1F>(Form("DMaxTMinT_%1zu", fPlane), ";Delta Max/Min Tick;", 200, 0., 200.);
145  fDMaxDerivMinDerivHist = dir.make<TH1F>(Form("DMaxDMinD_%1zu", fPlane), ";Delta Max/Min Deriv;", 200, 0., 200.);
146  }
147 
148  return;
149 }
T * get() const
Definition: ServiceHandle.h:71
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
Int_t max
Definition: plot.C:27
std::unique_ptr< reco_tool::IWaveformTool > fWaveformTool
T get(std::string const &key) const
Definition: ParameterSet.h:231
T * make(ARGS...args) const
TDirectory * dir
Definition: macro.C:5
void reco_tool::CandHitMorphological::findHitCandidates ( const Waveform waveform,
size_t  roiStartTick,
size_t  channel,
size_t  eventCount,
HitCandidateVec hitCandidateVec 
) const
overridevirtual

Implements reco_tool::ICandidateHitFinder.

Definition at line 151 of file CandHitMorphological_tool.cc.

References geo::GeometryCore::ChannelToWire(), dir, fChannelCnt, fDilationThreshold, fDMaxDerivMinDerivHist, fDMaxTickMinTickHist, fDStopStartHist, fGeometry, fHistDirectory, fLastChannel, fOutputHistograms, fStructuringElement, fWaveformTool, art::TFileDirectory::make(), and art::TFileDirectory::mkdir().

Referenced by findHitCandidates().

156 {
157  // In this case we want to find hit candidates based on the derivative of of the input waveform
158  // We get this from our waveform algs too...
159  Waveform rawDerivativeVec;
160  Waveform derivativeVec;
161 
162  fWaveformTool->firstDerivative(waveform, rawDerivativeVec);
163  fWaveformTool->triangleSmooth(rawDerivativeVec, derivativeVec);
164 
165  // Now we get the erosion/dilation vectors
166  Waveform erosionVec;
167  Waveform dilationVec;
168  Waveform averageVec;
169  Waveform differenceVec;
170 
171  reco_tool::HistogramMap histogramMap;
172 
173  // Compute the morphological filter vectors
174  fWaveformTool->getErosionDilationAverageDifference(waveform, fStructuringElement, histogramMap, erosionVec, dilationVec, averageVec, differenceVec);
175 
176  // Now find the hits
177  findHitCandidates(derivativeVec.begin(), derivativeVec.end(),
178  erosionVec.begin(), erosionVec.end(),
179  dilationVec.begin(), dilationVec.end(),
180  roiStartTick,
182  hitCandidateVec);
183 
184  // Reset the hit height from the input waveform
185  for(auto& hitCandidate : hitCandidateVec)
186  {
187  size_t centerIdx = hitCandidate.hitCenter;
188 
189  hitCandidate.hitHeight = waveform.at(centerIdx);
190  }
191 
192  // Keep track of histograms if requested
193  if (fOutputHistograms)
194  {
195  // Recover the details...
196  std::vector<geo::WireID> wids = fGeometry->ChannelToWire(channel);
197  size_t plane = wids[0].Plane;
198  size_t cryo = wids[0].Cryostat;
199  size_t tpc = wids[0].TPC;
200  size_t wire = wids[0].Wire;
201 
202  if (channel != fLastChannel) fChannelCnt = 0;
203 
204  // Make a directory for these histograms
205  art::TFileDirectory dir = fHistDirectory->mkdir(Form("HitPlane_%1zu/ev%04zu/c%1zut%1zuwire_%05zu",plane,eventCount,cryo,tpc,wire));
206 
207  size_t waveformSize = waveform.size();
208  int waveStart = roiStartTick;
209  int waveStop = waveStart + waveformSize;
210 
211  TProfile* waveHist = dir.make<TProfile>(Form("HWfm_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Waveform", waveformSize, waveStart, waveStop, -500., 500.);
212  TProfile* derivHist = dir.make<TProfile>(Form("HDer_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Derivative", waveformSize, waveStart, waveStop, -500., 500.);
213  TProfile* erosionHist = dir.make<TProfile>(Form("HEro_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Erosion", waveformSize, waveStart, waveStop, -500., 500.);
214  TProfile* dilationHist = dir.make<TProfile>(Form("HDil_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Dilation", waveformSize, waveStart, waveStop, -500., 500.);
215  TProfile* candHitHist = dir.make<TProfile>(Form("HCan_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Cand Hits", waveformSize, waveStart, waveStop, -500., 500.);
216  TProfile* maxDerivHist = dir.make<TProfile>(Form("HMax_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Maxima", waveformSize, waveStart, waveStop, -500., 500.);
217  TProfile* strtStopHist = dir.make<TProfile>(Form("HSSS_%03zu_ctw%01zu-%01zu-%01zu-%05zu",fChannelCnt,cryo,tpc,plane,wire), "Start/Stop", waveformSize, waveStart, waveStop, -500., 500.);
218 
219  // Fill wave/derivative
220  for(size_t idx = 0; idx < waveform.size(); idx++)
221  {
222  waveHist->Fill(roiStartTick + idx, waveform.at(idx));
223  derivHist->Fill(roiStartTick + idx, derivativeVec.at(idx));
224  erosionHist->Fill(roiStartTick + idx, erosionVec.at(idx));
225  dilationHist->Fill(roiStartTick + idx, dilationVec.at(idx));
226  }
227 
228  // Fill hits
229  for(const auto& hitCandidate : hitCandidateVec)
230  {
231  candHitHist->Fill(hitCandidate.hitCenter, hitCandidate.hitHeight);
232  maxDerivHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative);
233  maxDerivHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative);
234  strtStopHist->Fill(hitCandidate.startTick, waveform.at(hitCandidate.startTick));
235  strtStopHist->Fill(hitCandidate.stopTick, waveform.at(hitCandidate.stopTick));
236 
237  fDStopStartHist->Fill(hitCandidate.stopTick - hitCandidate.startTick, 1.);
238  fDMaxTickMinTickHist->Fill(hitCandidate.minTick - hitCandidate.maxTick, 1.);
239  fDMaxDerivMinDerivHist->Fill(hitCandidate.maxDerivative - hitCandidate.minDerivative, 1.);
240  }
241 
242  fLastChannel = channel;
243  fChannelCnt++;
244  }
245 
246  return;
247 }
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
TFileDirectory mkdir(std::string const &dir, std::string const &descr="")
std::unique_ptr< reco_tool::IWaveformTool > fWaveformTool
void findHitCandidates(const Waveform &, size_t, size_t, size_t, HitCandidateVec &) const override
std::map< int, TProfile * > HistogramMap
Definition: IWaveformTool.h:37
T * make(ARGS...args) const
TDirectory * dir
Definition: macro.C:5
void reco_tool::CandHitMorphological::findHitCandidates ( Waveform::const_iterator  derivStartItr,
Waveform::const_iterator  derivStopItr,
Waveform::const_iterator  erosionStartItr,
Waveform::const_iterator  erosionStopItr,
Waveform::const_iterator  dilationStartItr,
Waveform::const_iterator  dilationStopItr,
size_t  roiStartTick,
float  dilationThreshold,
HitCandidateVec hitCandidateVec 
) const
private

Definition at line 249 of file CandHitMorphological_tool.cc.

References fDilationThreshold, fErosionFraction, findHitCandidates(), fMinDeltaPeaks, and fMinDeltaTicks.

255 {
256  // This function aims to use the erosion/dilation vectors to find candidate hit regions
257  // Once armed with a region then the "standard" differential approach is used to return the candidate peaks
258 
259  // Don't do anything if not enough ticks
260  int ticksInInputWaveform = std::distance(derivStartItr, derivStopItr);
261 
262  if (ticksInInputWaveform < fMinDeltaTicks) return;
263 
264  // This function is recursive, we start by finding the largest element of the dilation vector
265  Waveform::const_iterator maxItr = std::max_element(dilationStartItr,dilationStopItr);
266  float maxVal = *maxItr;
267 
268  // Check that the peak is of reasonable height...
269  if (maxVal < dilationThreshold) return;
270 
271  int maxBin = std::distance(dilationStartItr,maxItr);
272 
273  // The candidate hit region we want lies between the two nearest minima to the maximum we just found
274  // subject to the condition that the erosion vector has return to less than zero
275  Waveform::const_iterator firstDerItr = derivStartItr + maxBin;
276  Waveform::const_iterator erosionItr = erosionStartItr + maxBin;
277 
278  float firstDerivValue = -1.;
279  float erosionCutValue = fErosionFraction * maxVal;
280 
281  // Search for starting point
282  while(firstDerItr != derivStartItr)
283  {
284  // Look for the turnover point
285  if (*erosionItr-- < erosionCutValue)
286  {
287  // We are looking for the zero crossing signifying a minimum value in the waveform
288  // (so the previous derivative < 0 while current is > 0)
289  // We are moving "backwards" so the current value <= 0, the previous value > 0
290  if (*firstDerItr * firstDerivValue <= 0. && firstDerivValue > 0.) break;
291  }
292 
293  firstDerivValue = *firstDerItr--;
294  }
295 
296  // Set the start bin
297  int hitRegionStart = std::distance(derivStartItr,firstDerItr);
298 
299  // Now go the other way
300  Waveform::const_iterator lastDerItr = derivStartItr + maxBin;
301 
302  // Reset the local variables
303  float lastDerivValue = 1.;
304 
305  erosionItr = erosionStartItr + maxBin;
306 
307  // Search for starting point
308  while(lastDerItr != derivStopItr)
309  {
310  if (*erosionItr++ <= erosionCutValue)
311  {
312  // We are again looking for the zero crossing signifying a minimum value in the waveform
313  // This time we are moving forward, so test is that previous value < 0, new value >= 0
314  if (*lastDerItr * lastDerivValue <= 0. && lastDerivValue < 0.) break;
315  }
316 
317  lastDerivValue = *lastDerItr++;
318  }
319 
320  // Set the stop bin
321  int hitRegionStop = std::distance(derivStartItr,lastDerItr);
322 
323  // Recursive call to find any hits in front of where we are now
324  if (hitRegionStart > fMinDeltaTicks)
325  findHitCandidates(derivStartItr, derivStartItr + hitRegionStart,
326  erosionStartItr, erosionStartItr + hitRegionStart,
327  dilationStartItr, dilationStartItr + hitRegionStart,
328  roiStartTick,
329  2. * fDilationThreshold,
330  hitCandidateVec);
331 
332  // Call the differential hit finding to get the actual hits within the region
333  findHitCandidates(derivStartItr + hitRegionStart, derivStartItr + hitRegionStop,
334  roiStartTick + hitRegionStart,
337  hitCandidateVec);
338 
339  // Now call ourselves again to find any hits trailing the region we just identified
340  if (std::distance(lastDerItr,derivStopItr) > fMinDeltaTicks)
341 // if (std::distance(lastDilItr,dilationStopItr) > fMinDeltaTicks)
342  findHitCandidates(derivStartItr + hitRegionStop, derivStopItr,
343  erosionStartItr + hitRegionStop, erosionStopItr,
344  dilationStartItr + hitRegionStop, dilationStopItr,
345  roiStartTick + hitRegionStop,
346  2. * fDilationThreshold,
347  hitCandidateVec);
348 
349  return;
350 }
intermediate_table::const_iterator const_iterator
void findHitCandidates(const Waveform &, size_t, size_t, size_t, HitCandidateVec &) const override
void reco_tool::CandHitMorphological::findHitCandidates ( Waveform::const_iterator  startItr,
Waveform::const_iterator  stopItr,
size_t  roiStartTick,
int  dTicksThreshold,
float  dPeakThreshold,
HitCandidateVec hitCandidateVec 
) const
private

Definition at line 352 of file CandHitMorphological_tool.cc.

References findHitCandidates(), findNearestMax(), findNearestMin(), findStartTick(), findStopTick(), fMinDeltaPeaks, fMinDeltaTicks, art::left(), art::right(), and reco_tool::ICandidateHitFinder::stopTick.

358 {
359  // Search for candidate hits...
360  // The idea will be to find the largest deviation in the input derivative waveform as the starting point. Depending
361  // on if a maximum or minimum, we search forward or backward to find the minimum or maximum that our extremum
362  // corresponds to.
363  std::pair<Waveform::const_iterator, Waveform::const_iterator> minMaxPair = std::minmax_element(startItr, stopItr);
364 
365  Waveform::const_iterator maxItr = minMaxPair.second;
366  Waveform::const_iterator minItr = minMaxPair.first;
367 
368  // Use the larger of the two as the starting point and recover the nearest max or min
369  if (std::fabs(*maxItr) > std::fabs(*minItr)) minItr = findNearestMin(maxItr, stopItr);
370  else maxItr = findNearestMax(minItr,startItr);
371 
372  int deltaTicks = std::distance(maxItr,minItr);
373  float range = *maxItr - *minItr;
374 
375  // At some point small rolling oscillations on the waveform need to be ignored...
376  if (deltaTicks >= dTicksThreshold && range > dPeakThreshold)
377  {
378  // Need to back up to find zero crossing, this will be the starting point of our
379  // candidate hit but also the endpoint of the pre sub-waveform we'll search next
380  Waveform::const_iterator newEndItr = findStartTick(maxItr, startItr);
381 
382  int startTick = std::distance(startItr,newEndItr);
383 
384  // Now need to go forward to again get close to zero, this will then be the end point
385  // of our candidate hit and the starting point for the post sub-waveform to search
386  Waveform::const_iterator newStartItr = findStopTick(minItr, stopItr);
387 
388  int stopTick = std::distance(startItr,newStartItr);
389 
390  // Find hits in the section of the waveform leading up to this candidate hit
391  if (startTick > 2)
392  {
393  // Special handling for merged hits
394  if (*(newEndItr-1) > 0.) {dTicksThreshold = 2; dPeakThreshold = 0.; }
395  else {dTicksThreshold = fMinDeltaTicks; dPeakThreshold = fMinDeltaPeaks;}
396 
397  findHitCandidates(startItr,newEndItr+1,roiStartTick,dTicksThreshold,dPeakThreshold,hitCandidateVec);
398  }
399 
400  // Create a new hit candidate and store away
401  HitCandidate_t hitCandidate;
402 
403  Waveform::const_iterator peakItr = std::min_element(maxItr,minItr,[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
404 
405  // Check balance
406  if (2 * std::distance(peakItr,minItr) < std::distance(maxItr,peakItr)) peakItr--;
407  else if (2 * std::distance(maxItr,peakItr) < std::distance(peakItr,minItr)) peakItr++;
408 
409  // Special handling of the start tick for multiple hits
410  size_t hitCandidateStartTick = roiStartTick + startTick;
411 
412  if (!hitCandidateVec.empty())
413  {
414  int deltaTicks = hitCandidateStartTick - hitCandidateVec.back().stopTick;
415 
416  if (deltaTicks > 0)
417  {
418  hitCandidateStartTick -= deltaTicks / 2;
419  hitCandidateVec.back().stopTick += deltaTicks / 2;
420  }
421  }
422 
423  hitCandidate.startTick = hitCandidateStartTick;
424  hitCandidate.stopTick = roiStartTick + stopTick;
425  hitCandidate.maxTick = roiStartTick + std::distance(startItr,maxItr);
426  hitCandidate.minTick = roiStartTick + std::distance(startItr,minItr);
427  hitCandidate.maxDerivative = maxItr != stopItr ? *maxItr : 0.;
428  hitCandidate.minDerivative = minItr != stopItr ? *minItr : 0.;
429  hitCandidate.hitCenter = roiStartTick + std::distance(startItr,peakItr) + 0.5;
430  hitCandidate.hitSigma = 0.5 * float(hitCandidate.minTick - hitCandidate.maxTick);
431  hitCandidate.hitHeight = hitCandidate.hitSigma * (hitCandidate.maxDerivative - hitCandidate.minDerivative) / 1.2130;
432 
433  hitCandidateVec.push_back(hitCandidate);
434 
435  // Finally, search the section of the waveform following this candidate for more hits
436  if (std::distance(newStartItr,stopItr) > 2)
437  {
438  // Special handling for merged hits
439  if (*(newStartItr+1) < 0.) {dTicksThreshold = 2; dPeakThreshold = 0.; }
440  else {dTicksThreshold = fMinDeltaTicks; dPeakThreshold = fMinDeltaPeaks;}
441 
442  findHitCandidates(newStartItr,stopItr,roiStartTick + stopTick,dTicksThreshold,dPeakThreshold,hitCandidateVec);
443  }
444  }
445 
446  return;
447 }
Waveform::const_iterator findNearestMin(Waveform::const_iterator, Waveform::const_iterator) const
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:112
Waveform::const_iterator findStopTick(Waveform::const_iterator, Waveform::const_iterator) const
struct HitCandidate{size_t startTick HitCandidate_t
Waveform::const_iterator findStartTick(Waveform::const_iterator, Waveform::const_iterator) const
intermediate_table::const_iterator const_iterator
void findHitCandidates(const Waveform &, size_t, size_t, size_t, HitCandidateVec &) const override
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
Waveform::const_iterator findNearestMax(Waveform::const_iterator, Waveform::const_iterator) const
ICandidateHitFinder::Waveform::const_iterator reco_tool::CandHitMorphological::findNearestMax ( Waveform::const_iterator  minItr,
Waveform::const_iterator  startItr 
) const
private

Definition at line 509 of file CandHitMorphological_tool.cc.

Referenced by findHitCandidates().

510 {
511  // Set the internal loop variable...
512  Waveform::const_iterator lastItr = minItr;
513 
514  // One extra condition to watch for here, make sure we can actually back up!
515  if (std::distance(startItr,minItr) > 0)
516  {
517  // Similar to searching for a maximum, we loop backward over ticks looking for the waveform to start decreasing
518  while((lastItr - 1) != startItr)
519  {
520  if (*(lastItr - 1) < *lastItr) break;
521 
522  lastItr--;
523  }
524  }
525 
526  return lastItr;
527 }
intermediate_table::const_iterator const_iterator
ICandidateHitFinder::Waveform::const_iterator reco_tool::CandHitMorphological::findNearestMin ( Waveform::const_iterator  maxItr,
Waveform::const_iterator  stopItr 
) const
private

Definition at line 491 of file CandHitMorphological_tool.cc.

Referenced by findHitCandidates().

492 {
493  // reset the min iterator and search forward to find the nearest minimum
494  Waveform::const_iterator lastItr = maxItr;
495 
496  // The strategy is simple...
497  // We are at a maximum so we search forward until we find the lowest negative point
498  while((lastItr + 1) != stopItr)
499  {
500  if (*(lastItr + 1) > *lastItr) break;
501 
502  lastItr++;
503  }
504 
505  // The minimum will be the last iterator value...
506  return lastItr;
507 }
intermediate_table::const_iterator const_iterator
ICandidateHitFinder::Waveform::const_iterator reco_tool::CandHitMorphological::findStartTick ( Waveform::const_iterator  maxItr,
Waveform::const_iterator  startItr 
) const
private

Definition at line 529 of file CandHitMorphological_tool.cc.

Referenced by findHitCandidates().

530 {
531  Waveform::const_iterator lastItr = maxItr;
532 
533  // If we can't back up then there is nothing to do
534  if (std::distance(startItr,lastItr) > 0)
535  {
536  // In theory, we are starting at a maximum and want to find the "start" of the candidate peak
537  // Ideally we would look to search backward to the point where the (derivative) waveform crosses zero again.
538  // However, the complication is that we need to watch for the case where two peaks are merged together and
539  // we might run through another peak before crossing zero...
540  // So... loop until we hit the startItr...
541  Waveform::const_iterator loopItr = lastItr - 1;
542 
543  while(loopItr != startItr)
544  {
545  // Ideal world case, we cross zero... but we might encounter a minimum... or an inflection point
546  if (*loopItr < 0. || !(*loopItr < *lastItr)) break;
547 
548  lastItr = loopItr--;
549  }
550  }
551  else lastItr = startItr;
552 
553  return lastItr;
554 }
intermediate_table::const_iterator const_iterator
ICandidateHitFinder::Waveform::const_iterator reco_tool::CandHitMorphological::findStopTick ( Waveform::const_iterator  minItr,
Waveform::const_iterator  stopItr 
) const
private

Definition at line 556 of file CandHitMorphological_tool.cc.

References DEFINE_ART_CLASS_TOOL.

Referenced by findHitCandidates().

557 {
558  Waveform::const_iterator lastItr = minItr;
559 
560  // If we can't go forward then there is really nothing to do
561  if (std::distance(minItr,stopItr) > 1)
562  {
563  // Pretty much the same strategy as for finding the start tick...
564  Waveform::const_iterator loopItr = lastItr + 1;
565 
566  while(loopItr != stopItr)
567  {
568  // Ideal case that we have crossed zero coming from a minimum... but watch for a maximum as well
569  if (*loopItr > 0. || !(*loopItr > *lastItr)) break;
570 
571  lastItr = loopItr++;
572  }
573  }
574 
575  return lastItr;
576 }
intermediate_table::const_iterator const_iterator
void reco_tool::CandHitMorphological::MergeHitCandidates ( const Waveform signalVec,
const HitCandidateVec hitCandidateVec,
MergeHitCandidateVec mergedHitsVec 
) const
overridevirtual

Implements reco_tool::ICandidateHitFinder.

Definition at line 449 of file CandHitMorphological_tool.cc.

References fMinHitHeight, and fNumInterveningTicks.

452 {
453  // If nothing on the input end then nothing to do
454  if (hitCandidateVec.empty()) return;
455 
456  // The idea is to group hits that "touch" so they can be part of common fit, those that
457  // don't "touch" are fit independently. So here we build the output vector to achieve that
458  // Get a container for the hits...
459  HitCandidateVec groupedHitVec;
460 
461  // Initialize the end of the last hit which we'll set to the first input hit's stop
462  size_t lastStopTick = hitCandidateVec.front().stopTick;
463 
464  // Step through the input hit candidates and group them by proximity
465  for(const auto& hitCandidate : hitCandidateVec)
466  {
467  // Small pulse height hits should not be considered?
468  if (hitCandidate.hitHeight > fMinHitHeight)
469  {
470  // Check condition that we have a new grouping
471  if (hitCandidate.startTick > lastStopTick + fNumInterveningTicks && !groupedHitVec.empty())
472  {
473  mergedHitsVec.emplace_back(groupedHitVec);
474 
475  groupedHitVec.clear();
476  }
477 
478  // Add the current hit to the current group
479  groupedHitVec.emplace_back(hitCandidate);
480 
481  lastStopTick = hitCandidate.stopTick;
482  }
483  }
484 
485  // Check end condition
486  if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
487 
488  return;
489 }
std::vector< HitCandidate_t > HitCandidateVec

Member Data Documentation

size_t reco_tool::CandHitMorphological::fChannelCnt
mutableprivate

Definition at line 91 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

float reco_tool::CandHitMorphological::fDilationFraction
private

Definition at line 74 of file CandHitMorphological_tool.cc.

Referenced by configure().

float reco_tool::CandHitMorphological::fDilationThreshold
private

Definition at line 73 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

TH1F* reco_tool::CandHitMorphological::fDMaxDerivMinDerivHist
private

Definition at line 88 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

TH1F* reco_tool::CandHitMorphological::fDMaxTickMinTickHist
private

Definition at line 87 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

TH1F* reco_tool::CandHitMorphological::fDStopStartHist
private

Definition at line 86 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

float reco_tool::CandHitMorphological::fErosionFraction
private

Definition at line 75 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

const geo::GeometryCore* reco_tool::CandHitMorphological::fGeometry = lar::providerFrom<geo::Geometry>()
private

Definition at line 96 of file CandHitMorphological_tool.cc.

Referenced by findHitCandidates().

art::TFileDirectory* reco_tool::CandHitMorphological::fHistDirectory
private

Definition at line 83 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

size_t reco_tool::CandHitMorphological::fLastChannel
mutableprivate

Definition at line 90 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

float reco_tool::CandHitMorphological::fMinDeltaPeaks
private

Definition at line 77 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

int reco_tool::CandHitMorphological::fMinDeltaTicks
private

Definition at line 76 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

float reco_tool::CandHitMorphological::fMinHitHeight
private

Definition at line 78 of file CandHitMorphological_tool.cc.

Referenced by configure(), and MergeHitCandidates().

size_t reco_tool::CandHitMorphological::fNumInterveningTicks
private

Definition at line 79 of file CandHitMorphological_tool.cc.

Referenced by configure(), and MergeHitCandidates().

bool reco_tool::CandHitMorphological::fOutputHistograms
private

Definition at line 81 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

size_t reco_tool::CandHitMorphological::fPlane
private

Definition at line 72 of file CandHitMorphological_tool.cc.

Referenced by configure().

int reco_tool::CandHitMorphological::fStructuringElement
private

Definition at line 80 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

std::unique_ptr<reco_tool::IWaveformTool> reco_tool::CandHitMorphological::fWaveformTool
private

Definition at line 94 of file CandHitMorphological_tool.cc.

Referenced by configure(), and findHitCandidates().

float reco_tool::ICandidateHitFinder::hitCenter
inherited

Definition at line 36 of file ICandidateHitFinder.h.

float reco_tool::ICandidateHitFinder::hitHeight
inherited

Definition at line 38 of file ICandidateHitFinder.h.

float reco_tool::ICandidateHitFinder::hitSigma
inherited

Definition at line 37 of file ICandidateHitFinder.h.

float reco_tool::ICandidateHitFinder::maxDerivative
inherited

Definition at line 34 of file ICandidateHitFinder.h.

size_t reco_tool::ICandidateHitFinder::maxTick
inherited

Definition at line 32 of file ICandidateHitFinder.h.

float reco_tool::ICandidateHitFinder::minDerivative
inherited

Definition at line 35 of file ICandidateHitFinder.h.

size_t reco_tool::ICandidateHitFinder::minTick
inherited

Definition at line 33 of file ICandidateHitFinder.h.

size_t reco_tool::ICandidateHitFinder::stopTick
inherited

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