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;
43 Waveform::const_iterator stopItr,
97 std::vector<unsigned short> zin;
99 fPlane = pset.get<
size_t > (
"Plane" );
100 fNumSigma = pset.get<
float > (
"NumSigma" );
104 zin = pset.get< std::vector<unsigned short> >(
"ROILeadTrailPadding" );
120 art::ServiceHandle<art::TFileService>
tfs;
127 fDiffMeanHist = dir.make<TH1F>(
"DiffMean",
";Diff Mean;", 100, -20., 20.);
128 fDiffRmsHist = dir.make<TH1F>(
"DiffRms",
";Diff RMS;", 100, 0., 5.);
130 fMinMaxDPeakHist = dir.make<TH1F>(
"MinMaxDPeak",
";Delta Peak;", 200, 0., 50.);
131 fMinMaxDistHist = dir.make<TH1F>(
"MinMaxDist",
";Peak Sep;", 50, 0., 50.);
132 fMinMaxSigmaHist = dir.make<TH1F>(
"MinMaxSigma",
";Peak Sep/rms;", 200, 0., 200.);
133 fDPeakVDistHist = dir.make<TH2F>(
"DPeakVDist",
";Delta Peak; Peak Sep", 200, 0, 50., 50, 0., 50.);
139 if (fNumBinsToAve > 1)
141 for(
int idx = 0; idx < fNumBinsToAve/2; idx++)
143 float weight = idx + 1;
150 if (fNumBinsToAve % 2 > 0)
fAveWeightVec.at(fNumBinsToAve/2) = fNumBinsToAve/2 + 1;
172 Waveform waveformDeriv(waveform.size());
178 else std::copy(waveform.begin(),waveform.end(),waveformDeriv.begin());
195 fWaveformTool.getTruncatedMean(aveWaveformDeriv, truncMean, nTrunc, range);
196 fWaveformTool.getTruncatedRMS(aveWaveformDeriv, nSig, fullRMS, truncRMS, nTrunc);
199 float truncRMSFloor = std::max(truncRMS,
float(0.25));
202 findROICandidates(aveWaveformDeriv.begin(),aveWaveformDeriv.end(),channel,0,truncRMSFloor,roiVec);
204 TProfile* roiHist(0);
213 size_t wire = wids[0].Wire;
221 TProfile* waveformHist = dir.make<TProfile>(Form(
"Wfm_%03zu_c%05zu",cnt,wire),
"Waveform", waveform.size(), 0, waveform.size(), -500., 500.);
222 TProfile* derivativeHist = dir.make<TProfile>(Form(
"Der_%03zu_c%05zu",cnt,wire),
"Derivative", waveformDeriv.size(), 0, waveformDeriv.size(), -500., 500.);
223 TProfile* aveDerivHist = dir.make<TProfile>(Form(
"Ave_%03zu_c%05zu",cnt,wire),
"AveDeriv", aveWaveformDeriv.size(), 0, aveWaveformDeriv.size(), -500., 500.);
225 roiHist = dir.make<TProfile>(Form(
"ROI_%03zu_c%05zu",cnt,wire),
"ROI", waveform.size(), 0, waveform.size(), -500., 500.);
227 for(
size_t binIdx = 0; binIdx < waveform.size(); binIdx++)
229 waveformHist->Fill(binIdx, waveform.at(binIdx));
230 derivativeHist->Fill(binIdx, waveformDeriv.at(binIdx));
235 for(
const auto& val : aveWaveformDeriv) aveDerivHist->Fill(binIdx++, val);
239 std::cout <<
"Caught exception trying to make new hists, plane,cnt,wire: " <<
fPlane <<
", " << cnt <<
", " << wire << std::endl;
243 if (roiVec.empty())
return;
248 for(
auto& roi : roiVec)
252 roiHist->Fill(
int(nMultiplier * roi.first), std::max(3.*truncRMS,1.));
253 roiHist->Fill(
int(nMultiplier * roi.second), std::max(3.*truncRMS,1.));
257 roi.first = std::max(
int(nMultiplier * roi.first -
fPreROIPad),0);
263 if(roiVec.size() > 1)
269 size_t startRoi = roiVec.front().first;
270 size_t stopRoi = startRoi;
272 for(
auto& roi : roiVec)
274 if (roi.first <= stopRoi +
fMaxTicksGap) stopRoi = roi.second;
279 startRoi = roi.first;
280 stopRoi = roi.second;
294 Waveform::const_iterator stopItr,
307 std::pair<Waveform::const_iterator,Waveform::const_iterator> minMaxItr = std::minmax_element(startItr, stopItr);
309 Waveform::const_iterator maxItr = minMaxItr.second;
310 Waveform::const_iterator minItr = minMaxItr.first;
320 if (*maxItr > std::fabs(*minItr))
328 float prevValue = *minItr++;
330 while(minItr != stopItr)
333 if (prevValue < 0. && *minItr > prevValue)
340 prevValue = *minItr++;
352 float prevValue = *maxItr--;
354 while(maxItr != startItr)
357 if (prevValue > 0. && *maxItr < prevValue)
364 prevValue = *maxItr--;
371 float maxMinRange = *maxItr - *minItr;
386 Waveform::const_reverse_iterator revItr = std::find_if(std::make_reverse_iterator(maxItr), std::make_reverse_iterator(startItr), std::bind(std::less<float>(),std::placeholders::_1,truncRMS));
388 maxItr = revItr.base();
389 minItr = std::find_if(minItr,stopItr,std::bind(std::greater<float>(),std::placeholders::_1,-truncRMS));
393 findROICandidates(startItr, maxItr, channel, roiStartTick, truncRMS, roiCandidateVec);
396 size_t newStartTick =
std::distance(startItr,maxItr) + roiStartTick;
397 size_t newStopTick =
std::distance(startItr,minItr) + roiStartTick;
399 roiCandidateVec.push_back(
CandidateROI(newStartTick, newStopTick));
402 findROICandidates(minItr, stopItr, channel, newStopTick, truncRMS, roiCandidateVec);
414 if (outputWaveform.size() != inputWaveform.size()) outputWaveform.resize(inputWaveform.size());
416 for(
size_t idx = 0; idx < inputWaveform.size(); idx++)
420 if ((idx + 1) % fNumBinsToAve == 0)
436 outputWaveform.resize(inputWaveform.size());
439 std::copy(inputWaveform.begin(),inputWaveform.begin()+halfBins,outputWaveform.begin());
440 std::copy(inputWaveform.end()-halfBins,inputWaveform.end(),outputWaveform.end()-halfBins);
442 for(
size_t idx = halfBins; idx < inputWaveform.size() - halfBins; idx++)
444 float weightedSum(0.);
446 for(
int wIdx = 0; wIdx <
fNumBinsToAve; wIdx++) weightedSum +=
fAveWeightVec.at(wIdx) * inputWaveform.at(idx - wIdx + halfBins);
448 outputWaveform.at(idx) = weightedSum /
fWeightSum;
Utilities related to art service access.
The data type to uniquely identify a Plane.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
enum geo::_plane_sigtype SigType_t
Description of geometry of one entire detector.
art::ServiceHandle< art::TFileService > tfs
art framework interface to geometry description
BEGIN_PROLOG could also be cout
Signal from collection planes.