13 #include "art_root_io/TFileService.h" 14 #include "cetlib_except/exception.h" 59 using MaxMinPair = std::pair<Waveform::const_iterator, Waveform::const_iterator>;
63 Waveform::const_iterator>;
67 Waveform::const_iterator,
74 Waveform::const_iterator)
const;
76 Waveform::const_iterator)
const;
79 Waveform::const_iterator
findStartTick(Waveform::const_iterator,
80 Waveform::const_iterator)
const;
81 Waveform::const_iterator
findStopTick(Waveform::const_iterator, Waveform::const_iterator)
const;
142 <<
"Cannot fill histograms when multiple threads configured, please set " 143 "fOutputHistograms to false or change number of threads to 1\n";
148 <<
"Cannot write output waveforms when multiple threads configured, please set " 149 "fOutputHistograms to false or change number of threads to 1\n";
172 dir.make<TH1F>(Form(
"DStopStart_%1zu",
fPlane),
";Delta Stop/Start;", 100, 0., 100.);
174 dir.make<TH1F>(Form(
"DMaxTMinT_%1zu",
fPlane),
";Delta Max/Min Tick;", 100, 0., 100.);
176 dir.make<TH1F>(Form(
"DMaxDMinD_%1zu",
fPlane),
";Delta Max/Min Deriv;", 200, 0., 100.);
178 dir.make<TH1F>(Form(
"MaxErosion_%1zu",
fPlane),
";Max Erosion;", 200, -50., 150.);
180 dir.make<TH1F>(Form(
"MaxDilation_%1zu",
fPlane),
";Max Dilation;", 200, -50., 150.);
182 dir.make<TH1F>(Form(
"MaxDilEroRat_%1zu",
fPlane),
";Max Dil/Ero;", 200, -1., 1.);
190 const recob::Wire::RegionsOfInterest_t::datarange_t& dataRange,
191 const size_t roiStartTick,
193 const size_t eventCount,
202 const Waveform& waveform = dataRange.data();
205 fWaveformTool->triangleSmooth(rawDerivativeVec, derivativeVec);
237 for (
auto& hc : hitCandidateVec) {
239 if (startCand >= 0) hc.startTick =
std::max(hc.startTick,
size_t(startCand));
246 for (
auto& hitCandidate : hitCandidateVec) {
247 size_t centerIdx = hitCandidate.hitCenter;
249 hitCandidate.hitHeight = waveform.at(centerIdx);
256 size_t plane = wids[0].Plane;
257 size_t cryo = wids[0].Cryostat;
258 size_t tpc = wids[0].TPC;
259 size_t wire = wids[0].Wire;
265 Form(
"Event%04zu/c%1zuT%1zuP%1zu/Wire_%05zu", eventCount, cryo, tpc, plane, wire));
267 size_t waveformSize = waveform.size();
268 size_t waveStart = dataRange.begin_index();
271 dir.make<TProfile>(Form(
"HWfm_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
278 TProfile* derivHist =
279 dir.make<TProfile>(Form(
"HDer_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
286 TProfile* erosionHist =
287 dir.make<TProfile>(Form(
"HEro_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
294 TProfile* dilationHist =
295 dir.make<TProfile>(Form(
"HDil_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
302 TProfile* candHitHist =
303 dir.make<TProfile>(Form(
"HCan_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
310 TProfile* maxDerivHist =
311 dir.make<TProfile>(Form(
"HMax_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
318 TProfile* strtStopHist =
319 dir.make<TProfile>(Form(
"HSSS_%03zu_roiStart-%05zu",
fChannelCnt, waveStart),
328 for (
size_t idx = 0; idx < waveform.size(); idx++) {
329 waveHist->Fill(roiStartTick + idx, waveform.at(idx));
330 derivHist->Fill(roiStartTick + idx, derivativeVec.at(idx));
331 erosionHist->Fill(roiStartTick + idx, erosionVec.at(idx));
332 dilationHist->Fill(roiStartTick + idx, dilationVec.at(idx));
336 for (
const auto& hitCandidate : hitCandidateVec) {
337 candHitHist->Fill(hitCandidate.hitCenter, hitCandidate.hitHeight);
338 maxDerivHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative);
339 maxDerivHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative);
340 strtStopHist->Fill(hitCandidate.startTick, waveform.at(hitCandidate.startTick));
341 strtStopHist->Fill(hitCandidate.stopTick, waveform.at(hitCandidate.stopTick));
350 for (
const auto& hitCandidate : hitCandidateVec) {
351 fDStopStartHist->Fill(hitCandidate.stopTick - hitCandidate.startTick, 1.);
358 std::max_element(dilationVec.begin(), dilationVec.end());
360 std::max_element(erosionVec.begin(), erosionVec.end());
364 if (
std::abs(*maxDilationItr) > 0.) dilEroRat = *maxErosionItr / *maxDilationItr;
381 const size_t roiStartTick,
382 float dilationThreshold,
389 int ticksInInputWaveform =
std::distance(derivStartItr, derivStopItr);
395 float maxVal = *maxItr;
398 if (maxVal < dilationThreshold)
return;
407 float firstDerivValue = -1.;
411 while (firstDerItr != derivStartItr) {
413 if (*erosionItr-- < erosionCutValue) {
417 if (*firstDerItr * firstDerivValue <= 0. && firstDerivValue > 0.)
break;
420 firstDerivValue = *firstDerItr--;
424 int hitRegionStart =
std::distance(derivStartItr, firstDerItr);
430 float lastDerivValue = 1.;
432 erosionItr = erosionStartItr + maxBin;
435 while (lastDerItr != derivStopItr) {
436 if (*erosionItr++ <= erosionCutValue) {
439 if (*lastDerItr * lastDerivValue <= 0. && lastDerivValue < 0.)
break;
442 lastDerivValue = *lastDerItr++;
446 int hitRegionStop =
std::distance(derivStartItr, lastDerItr);
451 derivStartItr + hitRegionStart,
453 erosionStartItr + hitRegionStart,
455 dilationStartItr + hitRegionStart,
462 derivStartItr + hitRegionStop,
463 roiStartTick + hitRegionStart,
472 erosionStartItr + hitRegionStop,
474 dilationStartItr + hitRegionStop,
476 roiStartTick + hitRegionStop,
486 const size_t roiStartTick,
488 float dPeakThreshold,
497 startItr, stopItr, dTicksThreshold, dPeakThreshold, candHitParamsVec)) {
500 for (
const auto& tuple : candHitParamsVec) {
510 std::min_element(maxItr, minItr, [](
const auto&
left,
const auto&
right) {
511 return std::fabs(
left) < std::fabs(
right);
521 size_t hitCandidateStartTick = roiStartTick +
std::distance(startItr, candStartItr);
523 if (!hitCandidateVec.empty()) {
524 int deltaTicks = hitCandidateStartTick - hitCandidateVec.back().stopTick;
526 if (deltaTicks > 0) {
527 hitCandidateStartTick -= deltaTicks / 2;
528 hitCandidateVec.back().stopTick += deltaTicks / 2;
532 hitCandidate.
startTick = hitCandidateStartTick;
536 hitCandidate.
maxDerivative = maxItr != stopItr ? *maxItr : 0.;
537 hitCandidate.
minDerivative = minItr != stopItr ? *minItr : 0.;
543 hitCandidateVec.push_back(hitCandidate);
640 float dPeakThreshold,
644 bool foundCandidate(
false);
655 MaxMinPair minMaxPair = std::minmax_element(startItr, stopItr);
661 if (std::fabs(*maxItr) > std::fabs(*minItr))
667 float range = *maxItr - *minItr;
669 if (deltaTicks < 2)
return foundCandidate;
672 if (deltaTicks >= dTicksThreshold && range > dPeakThreshold) foundCandidate =
true;
684 startItr, candStartItr, dTicksThreshold, dPeakThreshold, candHitParamsVec);
687 candHitParamsVec.emplace_back(candStartItr, maxItr, minItr, candStopItr);
691 candStopItr, stopItr, dTicksThreshold, dPeakThreshold, candHitParamsVec);
693 return foundCandidate || prevTicks || postTicks;
698 const recob::Wire::RegionsOfInterest_t::datarange_t& rangeData,
703 if (hitCandidateVec.empty())
return;
711 size_t lastStopTick = hitCandidateVec.front().stopTick;
714 for (
const auto& hitCandidate : hitCandidateVec) {
719 !groupedHitVec.empty()) {
720 mergedHitsVec.emplace_back(groupedHitVec);
722 groupedHitVec.clear();
726 groupedHitVec.emplace_back(hitCandidate);
728 lastStopTick = hitCandidate.stopTick;
733 if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
747 while ((lastItr + 1) != stopItr) {
748 if (*(lastItr + 1) > *lastItr)
break;
767 while ((lastItr - 1) != startItr) {
768 if (*(lastItr - 1) < *lastItr)
break;
792 while (loopItr != startItr) {
794 if (*loopItr < 0. || !(*loopItr < *lastItr))
break;
816 while (loopItr != stopItr) {
818 if (*loopItr > 0. || !(*loopItr > *lastItr))
break;
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
art framework interface to geometry description
T get(std::string const &key) const
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static int max(int a, int b)
Description of geometry of one entire detector.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
This provides an interface for tools which are tasked with finding candidate hits on input waveforms...
static Globals * instance()
auto const & get(AssnsNode< L, R, D > const &r)