8 #include "art/Utilities/ToolMacros.h"
9 #include "art/Utilities/make_tool.h"
10 #include "art_root_io/TFileService.h"
11 #include "messagefacility/MessageLogger/MessageLogger.h"
12 #include "cetlib_except/exception.h"
16 #include "icarus_signal_processing/WaveformTools.h"
34 void configure(
const fhicl::ParameterSet& pset)
override;
128 std::vector<unsigned short> zin;
130 fPlane = pset.get<
size_t >(
"Plane" );
132 fNumSigma = pset.get<
float >(
"NumSigma" );
138 zin = pset.get< std::vector<unsigned short>>(
"roiLeadTrailPad" );
139 fMaxPadLen = pset.get<
unsigned short >(
"MaxPadLen", 200);
143 if(zin.size() != 2) {
144 throw art::Exception(art::errors::Configuration)
145 <<
"Plane ROI pad size != 2";
153 if (fOutputHistograms)
157 art::ServiceHandle<art::TFileService>
tfs;
164 fDiffMeanHist = dir.make<TH1F>(
"DiffMean",
";Diff Mean;", 100, -20., 20.);
165 fDiffRmsHist = dir.make<TH1F>(
"DiffRms",
";Diff RMS;", 200, 0., 10.);
167 fDTruncBinsHist = dir.make<TH1F>(
"DTruncBn",
"D trunc B", 500, 0., 1000.);
168 fDiffMaxHist = dir.make<TH1F>(
"DiffMax",
";Diff Max;", 200, 0., 200.);
169 fNumSigmaHist = dir.make<TH1F>(
"NSigma",
";#sigma;", 200, 0., 40.);
170 fThresholdHist = dir.make<TH1F>(
"Threshold",
";Threshold;", 200, 0., 40.);
171 fNumSigNextHist = dir.make<TH1F>(
"NSigNext",
";#sigma;", 200, 0., 50.);
172 fMaxDiffLength = dir.make<TH1F>(
"MaxLength",
";Delta t", 200, 0., 200.);
173 fDeltaTicksHist = dir.make<TH1F>(
"DeltaTix",
";Delta t", 200, 0., 200.);
175 fDTixVDLenHist = dir.make<TH2F>(
"DTixVDLen",
";Delta t;DLength", 100, 0., 100., 100, 0., 100.);
176 fDTixVDiffHist = dir.make<TH2F>(
"DTixVDiff",
";Delta t;Max Diff", 100, 0., 100., 100, 0., 100.);
177 fDiffVDilHist = dir.make<TH2F>(
"DiffVDil",
";Max Diff;Max Dilation", 100, 0., 200., 100, 0., 200.);
183 if (fNumBinsToAve > 1)
185 for(
int idx = 0; idx < fNumBinsToAve/2; idx++)
187 float weight = idx + 1;
194 if (fNumBinsToAve % 2 > 0)
fAveWeightVec.at(fNumBinsToAve/2) = fNumBinsToAve/2 + 1;
234 Waveform zeroSuppressed(differenceVec.size());
236 fWaveformTool.getTruncatedMean(differenceVec, truncMean, nTrunc, range);
238 std::transform(differenceVec.begin(),differenceVec.end(),zeroSuppressed.begin(),[truncMean](
auto& val){
return val - truncMean;});
240 fWaveformTool.getTruncatedRMS(zeroSuppressed, nSig, fullRMS, truncRMS, nTrunc);
244 Waveform zeroSuppressed(dilationVec.size());
246 fWaveformTool.getTruncatedMean(dilationVec, truncMean, nTrunc, range);
248 std::transform(dilationVec.begin(),dilationVec.end(),zeroSuppressed.begin(),[truncMean](
auto& val){
return val - truncMean;});
250 fWaveformTool.getTruncatedRMS(zeroSuppressed, nSig, fullRMS, truncRMS, nTrunc);
254 float threshold = truncMean +
fNumSigma * std::max(
float(0.02),truncRMS);
264 for(
size_t curBin = 0; curBin < waveform.size(); curBin++)
266 histogramMap.at(
WAVEFORMHIST)->Fill( curBin, waveform[curBin], 1.);
267 histogramMap.at(
WAVEFORM)->Fill( curBin, smoothWaveform[curBin], 1.);
268 histogramMap.at(
EROSION)->Fill( curBin, erosionVec[curBin], 1.);
269 histogramMap.at(
DILATION)->Fill( curBin, dilationVec[curBin], 1.);
270 histogramMap.at(
AVERAGE)->Fill( curBin, averageVec[curBin], 1.);
271 histogramMap.at(
DIFFERENCE)->Fill( curBin, differenceVec[curBin], 1.);
273 histogramMap.at(
TRUNCRMSHIST)->Fill( curBin, threshold, 1.);
280 Waveform::iterator maxItr;
282 if (
fUseDifference) maxItr = std::max_element(differenceVec.begin(),differenceVec.end());
283 else maxItr = std::max_element(dilationVec.begin(),dilationVec.end());
285 float maxDiff = *maxItr;
286 float nSigma = (maxDiff - truncMean) / std::max(
float(0.5),truncRMS);
287 int dTruncBins = int(differenceVec.size()) - nTrunc;
302 nSigma = (maxDiff - truncMean) / std::max(
float(0.5),truncRMS);
310 nSigma = (maxDiff - truncMean) / std::max(
float(0.5),truncRMS);
320 nSigma = (maxDiff - truncMean) / std::max(
float(0.5),truncRMS);
328 nSigma = (maxDiff - truncMean) / std::max(
float(0.5),truncRMS);
338 if (roiVec.empty())
return;
341 for(
auto& roi : roiVec)
343 if (!histogramMap.empty())
345 histogramMap.at(
ROIHISTOGRAM)->Fill(
int(roi.first), std::max(5.*truncRMS,1.));
346 histogramMap.at(
ROIHISTOGRAM)->Fill(
int(roi.second), std::max(5.*truncRMS,1.));
350 unsigned short halfROILen = (roi.second - roi.first) / 2;
355 roi.first = std::max(
int(roi.first - preROIPad),0);
357 roi.second = std::min(roi.second + postROIPad, waveform.size() - 1);
361 if(roiVec.size() > 1)
367 size_t startRoi = roiVec.front().first;
368 size_t stopRoi = startRoi;
370 for(
auto& roi : roiVec)
373 if (roi.first <= stopRoi + 50)
376 startRoi = std::min(startRoi,roi.first);
377 stopRoi = std::max(stopRoi,roi.second);
383 startRoi = roi.first;
384 stopRoi = roi.second;
405 int roiLength = stopTick - startTick;
411 Waveform::const_iterator maxItr = std::max_element(differenceVec.begin()+startTick,differenceVec.begin()+stopTick);
414 float maxDifference = *maxItr;
418 float dilationVal = dilationVec[maxTick];
421 if (maxDifference > threshold || dilationVal > threshold)
424 while(*maxItr == maxDifference) maxItr++;
426 int deltaTicks =
std::distance(differenceVec.begin(),maxItr) - maxTick;
429 int maxCandRoiTick = maxTick;
433 while(++maxCandRoiTick < stopTick)
435 float difference = differenceVec.at(maxCandRoiTick);
436 float erosion = erosionVec.at(maxCandRoiTick);
438 if (difference < threshold && erosion < 0.5 * threshold)
break;
441 maxCandRoiTick = std::min(maxCandRoiTick,stopTick);
444 int minCandRoiTick = maxTick;
446 while(--minCandRoiTick >= startTick)
448 float difference = differenceVec.at(minCandRoiTick);
449 float erosion = erosionVec.at(minCandRoiTick);
451 if (difference < threshold && erosion < 0.5 * threshold)
break;
455 minCandRoiTick = std::max(minCandRoiTick, startTick);
457 int max2MinDiff = maxCandRoiTick - minCandRoiTick;
459 if (
fOutputHistograms && !(startTick > 0 || stopTick <
int(differenceVec.size())))
461 float maxDilation = *std::max_element(dilationVec.begin() + minCandRoiTick, dilationVec.begin() + maxCandRoiTick);
478 roiCandidateVec.push_back(
CandidateROI(minCandRoiTick, maxCandRoiTick));
498 int roiLength = stopTick - startTick;
505 Waveform::const_iterator maxItr = std::max_element(dilationVec.begin()+startTick,dilationVec.begin()+stopTick);
508 float maxDilation = *maxItr;
511 while(*maxItr == maxDilation) maxItr++;
513 int deltaTicks =
std::distance(dilationVec.begin(),maxItr) - maxTick;
516 if (maxDilation > threshold)
519 int maxCandRoiTick =
std::distance(dilationVec.begin(),maxItr);
523 while(++maxCandRoiTick < stopTick)
525 float dilation = dilationVec.at(maxCandRoiTick);
526 float erosion = erosionVec.at(maxCandRoiTick);
528 if (dilation < threshold && erosion < 0.5 * threshold)
break;
531 maxCandRoiTick = std::min(maxCandRoiTick,stopTick);
534 int minCandRoiTick = maxTick;
536 while(--minCandRoiTick >= startTick)
538 float dilation = dilationVec.at(minCandRoiTick);
539 float erosion = erosionVec.at(minCandRoiTick);
541 if (dilation < threshold && erosion < 0.5 * threshold)
break;
545 minCandRoiTick = std::max(minCandRoiTick, startTick);
547 int max2MinDiff = maxCandRoiTick - minCandRoiTick;
551 float maxDifference = *std::max_element(differenceVec.begin() + minCandRoiTick, differenceVec.begin() + maxCandRoiTick);
565 findROICandidatesDilation(differenceVec, erosionVec, dilationVec, startTick, minCandRoiTick, threshold, roiCandidateVec);
568 roiCandidateVec.push_back(
CandidateROI(minCandRoiTick, maxCandRoiTick));
571 findROICandidatesDilation(differenceVec, erosionVec, dilationVec, maxCandRoiTick+1, stopTick, threshold, roiCandidateVec);
584 outputWaveform.resize(inputWaveform.size());
594 std::fill(tempWaveform.begin(),tempWaveform.begin()+halfBins,0.);
595 std::fill(tempWaveform.end()-halfBins,tempWaveform.end(),0.);
598 std::copy(inputWaveform.begin(),inputWaveform.end(),tempWaveform.begin()+halfBins);
601 for(
size_t idx = 0; idx < inputWaveform.size(); idx++)
603 float weightedSum(0.);
607 outputWaveform.at(idx) = weightedSum /
fWeightSum;
610 else std::copy(inputWaveform.begin(),inputWaveform.end(),outputWaveform.begin());
652 size_t cryo = wids[0].Cryostat;
653 size_t tpc = wids[0].TPC;
655 size_t wire = wids[0].Wire;
658 art::TFileDirectory
dir =
fHistDirectory->mkdir(Form(
"Event_%03zu/C%1zuT%1zuP%1zu/Wire_%05zu",cnt,cryo,tpc,
fPlane,wire));
664 dir.make<TProfile>(
"SmoothWaveform",
"Waveform", waveformSize, 0, waveformSize, -500., 500.);
666 dir.make<TProfile>(
"Erosion",
"Erosion", waveformSize, 0, waveformSize, -500., 500.);
668 dir.make<TProfile>(
"Dilation",
"Dilation", waveformSize, 0, waveformSize, -500., 500.);
670 dir.make<TProfile>(
"Average",
"Average", waveformSize, 0, waveformSize, -500., 500.);
672 dir.make<TProfile>(
"Difference",
"Difference", waveformSize, 0, waveformSize, -500., 500.);
676 dir.make<TProfile>(
"ROI",
"ROI", waveformSize, 0, waveformSize, -500., 500.);
680 dir.make<TProfile>(
"TruncatedMean",
"Truncated Mean", waveformSize, 0, waveformSize, -500., 500.);
682 dir.make<TProfile>(
"TruncatedRMS",
"Truncated rms", waveformSize, 0, waveformSize, -500., 500.);
686 dir.make<TProfile>(
"InputWaveform",
"Waveform", waveformSize, 0, waveformSize, -500., 500.);
689 std::cout <<
"Caught exception trying to make new hists, tpc,plane,cnt,wire: " << tpc <<
", " <<
fPlane <<
", " << cnt <<
", " << wire << std::endl;
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.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
Description of geometry of one entire detector.
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description
BEGIN_PROLOG could also be cout