13 #include "cetlib_except/exception.h" 112 if (fOutputHistograms)
143 fWaveformTool->triangleSmooth(rawDerivativeVec, derivativeVec);
146 size_t plane = wids[0].Plane;
147 size_t cryo = wids[0].Cryostat;
148 size_t tpc = wids[0].TPC;
149 size_t wire = wids[0].Wire;
152 hitCandidateVec.clear();
157 if (hitCandidateVec.empty())
161 std::cout <<
"** C/T/P: " << cryo <<
"/" << tpc <<
"/" << plane <<
", wire: " << wire <<
" has not hits with input size: " << waveform.size() << std::endl;
166 for(
auto& hitCandidate : hitCandidateVec)
168 size_t centerIdx = hitCandidate.hitCenter;
170 hitCandidate.hitHeight = waveform.at(centerIdx);
188 size_t waveformSize = waveform.size();
189 int waveStart = roiStartTick;
190 int waveStop = waveStart + waveformSize;
192 TProfile* waveHist = dir.
make<TProfile>(Form(
"HWfm_%03zu_ctw%01zu-%01zu-%01zu-%05zu",channelCnt,cryo,tpc,plane,wire),
"Waveform", waveformSize, waveStart, waveStop, -500., 500.);
193 TProfile* derivHist = dir.
make<TProfile>(Form(
"HDer_%03zu_ctw%01zu-%01zu-%01zu-%05zu",channelCnt,cryo,tpc,plane,wire),
"Derivative", waveformSize, waveStart, waveStop, -500., 500.);
194 TProfile* candHitHist = dir.
make<TProfile>(Form(
"HCan_%03zu_ctw%01zu-%01zu-%01zu-%05zu",channelCnt,cryo,tpc,plane,wire),
"Cand Hits", waveformSize, waveStart, waveStop, -500., 500.);
195 TProfile* maxDerivHist = dir.
make<TProfile>(Form(
"HMax_%03zu_ctw%01zu-%01zu-%01zu-%05zu",channelCnt,cryo,tpc,plane,wire),
"Maxima", waveformSize, waveStart, waveStop, -500., 500.);
198 for(
size_t idx = 0; idx < waveform.size(); idx++)
200 waveHist->Fill(roiStartTick + idx, waveform.at(idx));
201 derivHist->Fill(roiStartTick + idx, derivativeVec.at(idx));
205 for(
const auto& hitCandidate : hitCandidateVec)
207 candHitHist->Fill(hitCandidate.hitCenter, hitCandidate.hitHeight);
208 maxDerivHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative);
209 maxDerivHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative);
211 fDStopStartHist->Fill(hitCandidate.stopTick - hitCandidate.startTick, 1.);
224 float dPeakThreshold,
231 std::pair<Waveform::const_iterator, Waveform::const_iterator> minMaxPair = std::minmax_element(startItr, stopItr);
237 if (std::fabs(*maxItr) > std::fabs(*minItr)) minItr =
findNearestMin(maxItr, stopItr);
240 int deltaTicks = std::distance(maxItr,minItr);
241 float range = *maxItr - *minItr;
244 if (deltaTicks >= dTicksThreshold && range > dPeakThreshold)
250 int startTick = std::distance(startItr,newEndItr);
256 int stopTick = std::distance(startItr,newStartItr);
259 if (startTick > dTicksThreshold)
262 if (*(newEndItr-1) > 0.) {dTicksThreshold = 2; dPeakThreshold = 0.; }
265 findHitCandidates(startItr,newEndItr+1,roiStartTick,dTicksThreshold,dPeakThreshold,hitCandidateVec);
274 if (2 * std::distance(peakItr,minItr) < std::distance(maxItr,peakItr)) peakItr--;
275 else if (2 * std::distance(maxItr,peakItr) < std::distance(peakItr,minItr)) peakItr++;
277 hitCandidate.startTick = roiStartTick + startTick;
278 hitCandidate.stopTick = roiStartTick +
stopTick;
279 hitCandidate.maxTick = roiStartTick + std::distance(startItr,maxItr);
280 hitCandidate.minTick = roiStartTick + std::distance(startItr,minItr);
281 hitCandidate.maxDerivative = maxItr != stopItr ? *maxItr : 0.;
282 hitCandidate.minDerivative = minItr != stopItr ? *minItr : 0.;
283 hitCandidate.hitCenter = roiStartTick + std::distance(startItr,peakItr) + 0.5;
284 hitCandidate.hitSigma = 0.5 * float(hitCandidate.minTick - hitCandidate.maxTick);
285 hitCandidate.hitHeight = hitCandidate.hitSigma * (hitCandidate.maxDerivative - hitCandidate.minDerivative) / 1.2130;
287 hitCandidateVec.push_back(hitCandidate);
290 if (std::distance(newStartItr,stopItr) > dTicksThreshold)
293 if (*(newStartItr+1) < 0.) {dTicksThreshold = 2; dPeakThreshold = 0.; }
296 findHitCandidates(newStartItr,stopItr,roiStartTick + stopTick,dTicksThreshold,dPeakThreshold,hitCandidateVec);
308 if (hitCandidateVec.empty())
return;
316 size_t lastStopTick = hitCandidateVec.front().stopTick;
319 for(
const auto& hitCandidate : hitCandidateVec)
327 mergedHitsVec.emplace_back(groupedHitVec);
329 groupedHitVec.clear();
333 groupedHitVec.emplace_back(hitCandidate);
335 lastStopTick = hitCandidate.stopTick;
340 if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
352 while((lastItr + 1) != stopItr)
354 if (*(lastItr + 1) > *lastItr)
break;
369 if (std::distance(startItr,minItr) > 0)
372 while((lastItr - 1) != startItr)
374 if (*(lastItr - 1) < *lastItr)
break;
388 if (std::distance(startItr,lastItr) > 0)
397 while(loopItr != startItr)
400 if (*loopItr < 0. || !(*loopItr < *lastItr))
break;
405 else lastItr = startItr;
415 if (std::distance(minItr,stopItr) > 1)
420 while(loopItr != stopItr)
423 if (*loopItr > 0. || !(*loopItr > *lastItr))
break;
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
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="")
T get(std::string const &key) const
Description of geometry of one entire detector.
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
T * make(ARGS...args) const
This provides an interface for tools which are tasked with finding candidate hits on input waveforms...
art framework interface to geometry description