11 #include "art/Framework/Services/Registry/ServiceHandle.h"
12 #include "art/Utilities/ToolMacros.h"
13 #include "art/Utilities/make_tool.h"
14 #include "art_root_io/TFileService.h"
15 #include "cetlib_except/exception.h"
41 Waveform::const_iterator,
49 Waveform::const_iterator)
const;
51 Waveform::const_iterator)
const;
54 Waveform::const_iterator
findStartTick(Waveform::const_iterator,
55 Waveform::const_iterator)
const;
56 Waveform::const_iterator
findStopTick(Waveform::const_iterator, Waveform::const_iterator)
const;
86 fPlane = pset.get<
size_t>(
"Plane", 0);
96 art::make_tool<reco_tool::IWaveformTool>(pset.get<fhicl::ParameterSet>(
"WaveformAlgs"));
99 if (fOutputHistograms) {
102 art::ServiceHandle<art::TFileService>
tfs;
110 dir.make<TH1F>(Form(
"DStopStart_%1zu",
fPlane),
";Delta Stop/Start;", 200, 0., 200.);
112 dir.make<TH1F>(Form(
"DMaxTMinT_%1zu",
fPlane),
";Delta Max/Min Tick;", 200, 0., 200.);
114 dir.make<TH1F>(Form(
"DMaxDMinD_%1zu",
fPlane),
";Delta Max/Min Deriv;", 200, 0., 200.);
122 const recob::Wire::RegionsOfInterest_t::datarange_t& dataRange,
123 const size_t roiStartTick,
124 const size_t channel,
125 const size_t eventCount,
134 const Waveform& waveform = dataRange.data();
137 fWaveformTool->triangleSmooth(rawDerivativeVec, derivativeVec);
140 size_t plane = wids[0].Plane;
141 size_t cryo = wids[0].Cryostat;
142 size_t tpc = wids[0].TPC;
143 size_t wire = wids[0].Wire;
146 hitCandidateVec.clear();
156 if (hitCandidateVec.empty()) {
158 std::cout <<
"** C/T/P: " << cryo <<
"/" << tpc <<
"/" << plane <<
", wire: " << wire
159 <<
" has not hits with input size: " << waveform.size() << std::endl;
164 for (
auto& hitCandidate : hitCandidateVec) {
165 size_t centerIdx = hitCandidate.hitCenter;
167 hitCandidate.hitHeight = waveform.at(centerIdx);
183 Form(
"HitPlane_%1zu/ev%04zu/c%1zut%1zuwire_%05zu", plane, eventCount, cryo, tpc, wire));
185 size_t waveformSize = waveform.size();
186 int waveStart = roiStartTick;
187 int waveStop = waveStart + waveformSize;
189 TProfile* waveHist = dir.make<TProfile>(
190 Form(
"HWfm_%03zu_ctw%01zu-%01zu-%01zu-%05zu", channelCnt, cryo, tpc, plane, wire),
197 TProfile* derivHist = dir.make<TProfile>(
198 Form(
"HDer_%03zu_ctw%01zu-%01zu-%01zu-%05zu", channelCnt, cryo, tpc, plane, wire),
205 TProfile* candHitHist = dir.make<TProfile>(
206 Form(
"HCan_%03zu_ctw%01zu-%01zu-%01zu-%05zu", channelCnt, cryo, tpc, plane, wire),
213 TProfile* maxDerivHist = dir.make<TProfile>(
214 Form(
"HMax_%03zu_ctw%01zu-%01zu-%01zu-%05zu", channelCnt, cryo, tpc, plane, wire),
223 for (
size_t idx = 0; idx < waveform.size(); idx++) {
224 waveHist->Fill(roiStartTick + idx, waveform.at(idx));
225 derivHist->Fill(roiStartTick + idx, derivativeVec.at(idx));
229 for (
const auto& hitCandidate : hitCandidateVec) {
230 candHitHist->Fill(hitCandidate.hitCenter, hitCandidate.hitHeight);
231 maxDerivHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative);
232 maxDerivHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative);
234 fDStopStartHist->Fill(hitCandidate.stopTick - hitCandidate.startTick, 1.);
245 Waveform::const_iterator stopItr,
246 const size_t roiStartTick,
248 float dPeakThreshold,
255 std::pair<Waveform::const_iterator, Waveform::const_iterator> minMaxPair =
256 std::minmax_element(startItr, stopItr);
258 Waveform::const_iterator maxItr = minMaxPair.second;
259 Waveform::const_iterator minItr = minMaxPair.first;
262 if (std::fabs(*maxItr) > std::fabs(*minItr))
268 float range = *maxItr - *minItr;
271 if (deltaTicks >= dTicksThreshold && range > dPeakThreshold) {
274 Waveform::const_iterator newEndItr =
findStartTick(maxItr, startItr);
280 Waveform::const_iterator newStartItr =
findStopTick(minItr, stopItr);
285 if (startTick > dTicksThreshold) {
287 if (*(newEndItr - 1) > 0.) {
297 startItr, newEndItr + 1, roiStartTick, dTicksThreshold, dPeakThreshold, hitCandidateVec);
303 Waveform::const_iterator peakItr =
304 std::min_element(maxItr, minItr, [](
const auto&
left,
const auto&
right) {
305 return std::fabs(
left) < std::fabs(
right);
314 hitCandidate.
startTick = roiStartTick + startTick;
315 hitCandidate.
stopTick = roiStartTick + stopTick;
318 hitCandidate.
maxDerivative = maxItr != stopItr ? *maxItr : 0.;
319 hitCandidate.
minDerivative = minItr != stopItr ? *minItr : 0.;
325 hitCandidateVec.push_back(hitCandidate);
328 if (std::distance(newStartItr, stopItr) > dTicksThreshold) {
330 if (*(newStartItr + 1) < 0.) {
341 roiStartTick + stopTick,
353 const recob::Wire::RegionsOfInterest_t::datarange_t& rangeData,
358 if (hitCandidateVec.empty())
return;
366 size_t lastStopTick = hitCandidateVec.front().stopTick;
369 for (
const auto& hitCandidate : hitCandidateVec) {
374 !groupedHitVec.empty()) {
375 mergedHitsVec.emplace_back(groupedHitVec);
377 groupedHitVec.clear();
381 groupedHitVec.emplace_back(hitCandidate);
383 lastStopTick = hitCandidate.stopTick;
388 if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
393 ICandidateHitFinder::Waveform::const_iterator
395 Waveform::const_iterator stopItr)
const
398 Waveform::const_iterator lastItr = maxItr;
402 while ((lastItr + 1) != stopItr) {
403 if (*(lastItr + 1) > *lastItr)
break;
412 ICandidateHitFinder::Waveform::const_iterator
414 Waveform::const_iterator startItr)
const
417 Waveform::const_iterator lastItr = minItr;
422 while ((lastItr - 1) != startItr) {
423 if (*(lastItr - 1) < *lastItr)
break;
432 ICandidateHitFinder::Waveform::const_iterator
434 Waveform::const_iterator startItr)
const
436 Waveform::const_iterator lastItr = maxItr;
445 Waveform::const_iterator loopItr = lastItr - 1;
447 while (loopItr != startItr) {
449 if (*loopItr < 0. || !(*loopItr < *lastItr))
break;
460 ICandidateHitFinder::Waveform::const_iterator
462 Waveform::const_iterator stopItr)
const
464 Waveform::const_iterator lastItr = minItr;
469 Waveform::const_iterator loopItr = lastItr + 1;
471 while (loopItr != stopItr) {
473 if (*loopItr > 0. || !(*loopItr > *lastItr))
break;
Utilities related to art service access.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
Description of geometry of one entire detector.
This provides an interface for tools which are tasked with finding candidate hits on input waveforms...
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description
BEGIN_PROLOG could also be cout