LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
CandHitStandard_tool.cc
Go to the documentation of this file.
1 
7 
11 
12 #include <algorithm>
13 
14 namespace reco_tool {
15 
17  public:
18  explicit CandHitStandard(const fhicl::ParameterSet& pset);
19 
20  void findHitCandidates(const recob::Wire::RegionsOfInterest_t::datarange_t&,
21  const size_t,
22  const size_t,
23  const size_t,
24  HitCandidateVec&) const override;
25 
26  void MergeHitCandidates(const recob::Wire::RegionsOfInterest_t::datarange_t&,
27  const HitCandidateVec&,
28  MergeHitCandidateVec&) const override;
29 
30  private:
33  const size_t,
34  const size_t,
35  HitCandidateVec&) const;
36 
37  // Member variables from the fhicl file
38  const float fRoiThreshold;
39 
42  };
43 
44  //----------------------------------------------------------------------
45  // Constructor.
47  : fRoiThreshold(pset.get<float>("RoiThreshold", 5.))
48  {}
49 
51  const recob::Wire::RegionsOfInterest_t::datarange_t& dataRange,
52  const size_t roiStartTick,
53  const size_t channel,
54  const size_t /* eventCount */,
55  HitCandidateVec& hitCandidateVec) const
56  {
57  // Recover the actual waveform
58  const Waveform& waveform = dataRange.data();
59 
60  // Recover the plane index for this method
61  std::vector<geo::WireID> wids = fWireReadoutGeom->ChannelToWire(channel);
62  const size_t plane = wids[0].Plane;
63 
64  // Use the recursive version to find the candidate hits
65  findHitCandidates(waveform.begin(), waveform.end(), roiStartTick, plane, hitCandidateVec);
66  }
67 
70  const size_t roiStartTick,
71  const size_t planeIdx,
72  HitCandidateVec& hitCandidateVec) const
73  {
74  // Need a minimum number of ticks to do any work here
75  if (std::distance(startItr, stopItr) > 4) {
76  // Find the highest peak in the range given
77  auto maxItr = std::max_element(startItr, stopItr);
78 
79  float maxValue = *maxItr;
80  int maxTime = std::distance(startItr, maxItr);
81 
82  if (maxValue > fRoiThreshold) {
83  // backwards to find first bin for this candidate hit
84  auto firstItr = std::distance(startItr, maxItr) > 2 ? maxItr - 1 : startItr;
85 
86  while (firstItr != startItr) {
87  // Check for pathology where waveform goes too negative
88  if (*firstItr < -fRoiThreshold) break;
89 
90  // Check both sides of firstItr and look for min/inflection point
91  if (*firstItr < *(firstItr + 1) && *firstItr <= *(firstItr - 1)) break;
92 
93  firstItr--;
94  }
95 
96  int firstTime = std::distance(startItr, firstItr);
97 
98  // Recursive call to find all candidate hits earlier than this peak
99  findHitCandidates(startItr, firstItr + 1, roiStartTick, planeIdx, hitCandidateVec);
100 
101  // forwards to find last bin for this candidate hit
102  auto lastItr = std::distance(maxItr, stopItr) > 2 ? maxItr + 1 : stopItr - 1;
103 
104  while (lastItr != stopItr - 1) {
105  // Check for pathology where waveform goes too negative
106  if (*lastItr < -fRoiThreshold) break;
107 
108  // Check both sides of firstItr and look for min/inflection point
109  if (*lastItr <= *(lastItr + 1) && *lastItr < *(lastItr - 1)) break;
110 
111  lastItr++;
112  }
113 
114  int lastTime = std::distance(startItr, lastItr);
115 
116  // Now save this candidate's start and max time info
117  HitCandidate hitCandidate;
118  hitCandidate.startTick = roiStartTick + firstTime;
119  hitCandidate.stopTick = roiStartTick + lastTime;
120  hitCandidate.maxTick = roiStartTick + firstTime;
121  hitCandidate.minTick = roiStartTick + lastTime;
122  hitCandidate.maxDerivative = *(startItr + firstTime);
123  hitCandidate.minDerivative = *(startItr + lastTime);
124  hitCandidate.hitCenter = roiStartTick + maxTime;
125  hitCandidate.hitSigma = std::max(2., float(lastTime - firstTime) / 6.);
126  hitCandidate.hitHeight = maxValue;
127 
128  hitCandidateVec.push_back(hitCandidate);
129 
130  // Recursive call to find all candidate hits later than this peak
131  findHitCandidates(lastItr + 1,
132  stopItr,
133  roiStartTick + std::distance(startItr, lastItr + 1),
134  planeIdx,
135  hitCandidateVec);
136  }
137  }
138  }
139 
140  void CandHitStandard::MergeHitCandidates(const recob::Wire::RegionsOfInterest_t::datarange_t&,
141  const HitCandidateVec& hitCandidateVec,
142  MergeHitCandidateVec& mergedHitsVec) const
143  {
144  // If no hits then nothing to do here
145  if (hitCandidateVec.empty()) return;
146 
147  // The idea is to group hits that "touch" so they can be part of common fit, those that
148  // don't "touch" are fit independently. So here we build the output vector to achieve that
149  HitCandidateVec groupedHitVec;
150  int lastTick = hitCandidateVec.front().stopTick;
151 
152  // Step through the input hit candidates and group them by proximity
153  for (const auto& hitCandidate : hitCandidateVec) {
154  // Check condition that we have a new grouping
155  if (int(hitCandidate.startTick) - lastTick > 1) {
156  mergedHitsVec.emplace_back(groupedHitVec);
157 
158  groupedHitVec.clear();
159  }
160 
161  // Add the current hit to the current group
162  groupedHitVec.emplace_back(hitCandidate);
163 
164  lastTick = hitCandidate.stopTick;
165  }
166 
167  // Check end condition
168  if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
169  }
170 
172 }
CandHitStandard(const fhicl::ParameterSet &pset)
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
const geo::WireReadoutGeom * fWireReadoutGeom
void findHitCandidates(const recob::Wire::RegionsOfInterest_t::datarange_t &, const size_t, const size_t, const size_t, HitCandidateVec &) const override
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
intermediate_table::const_iterator const_iterator
const float fRoiThreshold
minimum maximum to minimum peak distance
Interface for a class providing readout channel mapping to geometry.
void MergeHitCandidates(const recob::Wire::RegionsOfInterest_t::datarange_t &, const HitCandidateVec &, MergeHitCandidateVec &) const override
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
virtual std::vector< WireID > ChannelToWire(raw::ChannelID_t channel) const =0
This provides an interface for tools which are tasked with finding candidate hits on input waveforms...
std::vector< HitCandidateVec > MergeHitCandidateVec
std::vector< HitCandidate > HitCandidateVec