13 #include "cetlib_except/exception.h" 132 if (fOutputHistograms)
163 fWaveformTool->triangleSmooth(rawDerivativeVec, derivativeVec);
178 erosionVec.begin(), erosionVec.end(),
179 dilationVec.begin(), dilationVec.end(),
185 for(
auto& hitCandidate : hitCandidateVec)
187 size_t centerIdx = hitCandidate.hitCenter;
189 hitCandidate.hitHeight = waveform.at(centerIdx);
197 size_t plane = wids[0].Plane;
198 size_t cryo = wids[0].Cryostat;
199 size_t tpc = wids[0].TPC;
200 size_t wire = wids[0].Wire;
207 size_t waveformSize = waveform.size();
208 int waveStart = roiStartTick;
209 int waveStop = waveStart + waveformSize;
211 TProfile* waveHist = dir.
make<TProfile>(Form(
"HWfm_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Waveform", waveformSize, waveStart, waveStop, -500., 500.);
212 TProfile* derivHist = dir.
make<TProfile>(Form(
"HDer_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Derivative", waveformSize, waveStart, waveStop, -500., 500.);
213 TProfile* erosionHist = dir.
make<TProfile>(Form(
"HEro_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Erosion", waveformSize, waveStart, waveStop, -500., 500.);
214 TProfile* dilationHist = dir.
make<TProfile>(Form(
"HDil_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Dilation", waveformSize, waveStart, waveStop, -500., 500.);
215 TProfile* candHitHist = dir.
make<TProfile>(Form(
"HCan_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Cand Hits", waveformSize, waveStart, waveStop, -500., 500.);
216 TProfile* maxDerivHist = dir.
make<TProfile>(Form(
"HMax_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Maxima", waveformSize, waveStart, waveStop, -500., 500.);
217 TProfile* strtStopHist = dir.
make<TProfile>(Form(
"HSSS_%03zu_ctw%01zu-%01zu-%01zu-%05zu",
fChannelCnt,cryo,tpc,plane,wire),
"Start/Stop", waveformSize, waveStart, waveStop, -500., 500.);
220 for(
size_t idx = 0; idx < waveform.size(); idx++)
222 waveHist->Fill(roiStartTick + idx, waveform.at(idx));
223 derivHist->Fill(roiStartTick + idx, derivativeVec.at(idx));
224 erosionHist->Fill(roiStartTick + idx, erosionVec.at(idx));
225 dilationHist->Fill(roiStartTick + idx, dilationVec.at(idx));
229 for(
const auto& hitCandidate : hitCandidateVec)
231 candHitHist->Fill(hitCandidate.hitCenter, hitCandidate.hitHeight);
232 maxDerivHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative);
233 maxDerivHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative);
234 strtStopHist->Fill(hitCandidate.startTick, waveform.at(hitCandidate.startTick));
235 strtStopHist->Fill(hitCandidate.stopTick, waveform.at(hitCandidate.stopTick));
237 fDStopStartHist->Fill(hitCandidate.stopTick - hitCandidate.startTick, 1.);
253 float dilationThreshold,
260 int ticksInInputWaveform = std::distance(derivStartItr, derivStopItr);
266 float maxVal = *maxItr;
269 if (maxVal < dilationThreshold)
return;
271 int maxBin = std::distance(dilationStartItr,maxItr);
278 float firstDerivValue = -1.;
282 while(firstDerItr != derivStartItr)
285 if (*erosionItr-- < erosionCutValue)
290 if (*firstDerItr * firstDerivValue <= 0. && firstDerivValue > 0.)
break;
293 firstDerivValue = *firstDerItr--;
297 int hitRegionStart = std::distance(derivStartItr,firstDerItr);
303 float lastDerivValue = 1.;
305 erosionItr = erosionStartItr + maxBin;
308 while(lastDerItr != derivStopItr)
310 if (*erosionItr++ <= erosionCutValue)
314 if (*lastDerItr * lastDerivValue <= 0. && lastDerivValue < 0.)
break;
317 lastDerivValue = *lastDerItr++;
321 int hitRegionStop = std::distance(derivStartItr,lastDerItr);
326 erosionStartItr, erosionStartItr + hitRegionStart,
327 dilationStartItr, dilationStartItr + hitRegionStart,
334 roiStartTick + hitRegionStart,
343 erosionStartItr + hitRegionStop, erosionStopItr,
344 dilationStartItr + hitRegionStop, dilationStopItr,
345 roiStartTick + hitRegionStop,
356 float dPeakThreshold,
363 std::pair<Waveform::const_iterator, Waveform::const_iterator> minMaxPair = std::minmax_element(startItr, stopItr);
369 if (std::fabs(*maxItr) > std::fabs(*minItr)) minItr =
findNearestMin(maxItr, stopItr);
372 int deltaTicks = std::distance(maxItr,minItr);
373 float range = *maxItr - *minItr;
376 if (deltaTicks >= dTicksThreshold && range > dPeakThreshold)
382 int startTick = std::distance(startItr,newEndItr);
388 int stopTick = std::distance(startItr,newStartItr);
394 if (*(newEndItr-1) > 0.) {dTicksThreshold = 2; dPeakThreshold = 0.; }
397 findHitCandidates(startItr,newEndItr+1,roiStartTick,dTicksThreshold,dPeakThreshold,hitCandidateVec);
406 if (2 * std::distance(peakItr,minItr) < std::distance(maxItr,peakItr)) peakItr--;
407 else if (2 * std::distance(maxItr,peakItr) < std::distance(peakItr,minItr)) peakItr++;
410 size_t hitCandidateStartTick = roiStartTick + startTick;
412 if (!hitCandidateVec.empty())
414 int deltaTicks = hitCandidateStartTick - hitCandidateVec.back().stopTick;
418 hitCandidateStartTick -= deltaTicks / 2;
419 hitCandidateVec.back().stopTick += deltaTicks / 2;
423 hitCandidate.startTick = hitCandidateStartTick;
424 hitCandidate.stopTick = roiStartTick +
stopTick;
425 hitCandidate.maxTick = roiStartTick + std::distance(startItr,maxItr);
426 hitCandidate.minTick = roiStartTick + std::distance(startItr,minItr);
427 hitCandidate.maxDerivative = maxItr != stopItr ? *maxItr : 0.;
428 hitCandidate.minDerivative = minItr != stopItr ? *minItr : 0.;
429 hitCandidate.hitCenter = roiStartTick + std::distance(startItr,peakItr) + 0.5;
430 hitCandidate.hitSigma = 0.5 * float(hitCandidate.minTick - hitCandidate.maxTick);
431 hitCandidate.hitHeight = hitCandidate.hitSigma * (hitCandidate.maxDerivative - hitCandidate.minDerivative) / 1.2130;
433 hitCandidateVec.push_back(hitCandidate);
436 if (std::distance(newStartItr,stopItr) > 2)
439 if (*(newStartItr+1) < 0.) {dTicksThreshold = 2; dPeakThreshold = 0.; }
442 findHitCandidates(newStartItr,stopItr,roiStartTick + stopTick,dTicksThreshold,dPeakThreshold,hitCandidateVec);
454 if (hitCandidateVec.empty())
return;
462 size_t lastStopTick = hitCandidateVec.front().stopTick;
465 for(
const auto& hitCandidate : hitCandidateVec)
473 mergedHitsVec.emplace_back(groupedHitVec);
475 groupedHitVec.clear();
479 groupedHitVec.emplace_back(hitCandidate);
481 lastStopTick = hitCandidate.stopTick;
486 if (!groupedHitVec.empty()) mergedHitsVec.emplace_back(groupedHitVec);
498 while((lastItr + 1) != stopItr)
500 if (*(lastItr + 1) > *lastItr)
break;
515 if (std::distance(startItr,minItr) > 0)
518 while((lastItr - 1) != startItr)
520 if (*(lastItr - 1) < *lastItr)
break;
534 if (std::distance(startItr,lastItr) > 0)
543 while(loopItr != startItr)
546 if (*loopItr < 0. || !(*loopItr < *lastItr))
break;
551 else lastItr = startItr;
561 if (std::distance(minItr,stopItr) > 1)
566 while(loopItr != stopItr)
569 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