LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
CandHitStandard_tool.cc
Go to the documentation of this file.
1 
7 
11 #include "cetlib_except/exception.h"
14 
15 #include <cmath>
16 #include <fstream>
17 
18 namespace reco_tool
19 {
20 
22 {
23 public:
24  explicit CandHitStandard(const fhicl::ParameterSet& pset);
25 
27 
28  void configure(const fhicl::ParameterSet& pset) override;
29 
30  void findHitCandidates(const std::vector<float>&,
31  size_t,
32  size_t,
33  size_t,
34  HitCandidateVec&) const override;
35 
36  void MergeHitCandidates(const std::vector<float>&,
37  const HitCandidateVec&,
38  MergeHitCandidateVec&) const override;
39 
40 private:
41 
44  size_t,
45  size_t,
46  HitCandidateVec&) const;
47 
48  // Member variables from the fhicl file
49  int fPlane;
50  float fRoiThreshold;
51 
52  const geo::GeometryCore* fGeometry = lar::providerFrom<geo::Geometry>();
53 };
54 
55 //----------------------------------------------------------------------
56 // Constructor.
58 {
59  configure(pset);
60 }
61 
63 {
64 }
65 
67 {
68  // Start by recovering the parameters
69  fPlane = pset.get< int >("Plane", 0);
70  fRoiThreshold = pset.get< float >("RoiThreshold", 5.);
71 
72  return;
73 }
74 
75 void CandHitStandard::findHitCandidates(const std::vector<float>& waveform,
76  size_t roiStartTick,
77  size_t channel,
78  size_t eventCount,
79  HitCandidateVec& hitCandidateVec) const
80 {
81  // Recover the plane index for this method
82  std::vector<geo::WireID> wids = fGeometry->ChannelToWire(channel);
83  size_t plane = wids[0].Plane;
84 
85  // Use the recursive version to find the candidate hits
86  findHitCandidates(waveform.begin(),waveform.end(),roiStartTick,plane,hitCandidateVec);
87 
88  return;
89 }
90 
93  size_t roiStartTick,
94  size_t planeIdx,
95  HitCandidateVec& hitCandidateVec) const
96 {
97  // Need a minimum number of ticks to do any work here
98  if (std::distance(startItr,stopItr) > 4)
99  {
100  // Find the highest peak in the range given
101  auto maxItr = std::max_element(startItr, stopItr);
102 
103  float maxValue = *maxItr;
104  int maxTime = std::distance(startItr,maxItr);
105 
106  if (maxValue > fRoiThreshold)
107  {
108  // backwards to find first bin for this candidate hit
109  auto firstItr = std::distance(startItr,maxItr) > 2 ? maxItr - 1 : startItr;
110 
111  while(firstItr != startItr)
112  {
113  // Check for pathology where waveform goes too negative
114  if (*firstItr < -fRoiThreshold) break;
115 
116  // Check both sides of firstItr and look for min/inflection point
117  if (*firstItr < *(firstItr+1) && *firstItr <= *(firstItr-1)) break;
118 
119  firstItr--;
120  }
121 
122  int firstTime = std::distance(startItr,firstItr);
123 
124  // Recursive call to find all candidate hits earlier than this peak
125  findHitCandidates(startItr, firstItr + 1, roiStartTick, planeIdx, hitCandidateVec);
126 
127  // forwards to find last bin for this candidate hit
128  auto lastItr = std::distance(maxItr,stopItr) > 2 ? maxItr + 1 : stopItr - 1;
129 
130  while(lastItr != stopItr - 1)
131  {
132  // Check for pathology where waveform goes too negative
133  if (*lastItr < -fRoiThreshold) break;
134 
135  // Check both sides of firstItr and look for min/inflection point
136  if (*lastItr <= *(lastItr+1) && *lastItr < *(lastItr-1)) break;
137 
138  lastItr++;
139  }
140 
141  int lastTime = std::distance(startItr,lastItr);
142 
143  // Now save this candidate's start and max time info
144  HitCandidate hitCandidate;
145  hitCandidate.startTick = roiStartTick + firstTime;
146  hitCandidate.stopTick = roiStartTick + lastTime;
147  hitCandidate.maxTick = roiStartTick + firstTime;
148  hitCandidate.minTick = roiStartTick + lastTime;
149  hitCandidate.maxDerivative = *(startItr + firstTime);
150  hitCandidate.minDerivative = *(startItr + lastTime);
151  hitCandidate.hitCenter = roiStartTick + maxTime;
152  hitCandidate.hitSigma = std::max(2.,float(lastTime - firstTime) / 6.);
153  hitCandidate.hitHeight = maxValue;
154 
155  hitCandidateVec.push_back(hitCandidate);
156 
157  // Recursive call to find all candidate hits later than this peak
158  findHitCandidates(lastItr + 1, stopItr, roiStartTick + std::distance(startItr,lastItr + 1), planeIdx, hitCandidateVec);
159  }
160  }
161 
162  return;
163 }
164 
165 void CandHitStandard::MergeHitCandidates(const std::vector<float>& signalVec,
166  const HitCandidateVec& hitCandidateVec,
167  MergeHitCandidateVec& mergedHitsVec) const
168 {
169  // If no hits then nothing to do here
170  if (hitCandidateVec.empty()) return;
171 
172  // The idea is to group hits that "touch" so they can be part of common fit, those that
173  // don't "touch" are fit independently. So here we build the output vector to achieve that
174  HitCandidateVec groupedHitVec;
175  int lastTick = hitCandidateVec.front().stopTick;
176 
177  // Step through the input hit candidates and group them by proximity
178  for(const auto& hitCandidate : hitCandidateVec)
179  {
180  // Check condition that we have a new grouping
181  if (int(hitCandidate.startTick) - lastTick > 1)
182  {
183  mergedHitsVec.emplace_back(groupedHitVec);
184 
185  groupedHitVec.clear();
186  }
187 
188  // Add the current hit to the current group
189  groupedHitVec.emplace_back(hitCandidate);
190 
191  lastTick = hitCandidate.stopTick;
192  }
193 
194  // Check end condition
195  if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
196 
197  return;
198 }
199 
201 }
CandHitStandard(const fhicl::ParameterSet &pset)
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:45
void findHitCandidates(const std::vector< float > &, size_t, size_t, size_t, HitCandidateVec &) const override
std::vector< HitCandidate_t > HitCandidateVec
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
Int_t max
Definition: plot.C:27
int fPlane
Plane we are meant to work with.
void configure(const fhicl::ParameterSet &pset) override
intermediate_table::const_iterator const_iterator
T get(std::string const &key) const
Definition: ParameterSet.h:231
float fRoiThreshold
minimum maximum to minimum peak distance
Description of geometry of one entire detector.
void MergeHitCandidates(const std::vector< float > &, const HitCandidateVec &, MergeHitCandidateVec &) const override
const geo::GeometryCore * fGeometry
This provides an interface for tools which are tasked with finding candidate hits on input waveforms...
std::vector< HitCandidateVec > MergeHitCandidateVec
art framework interface to geometry description