8 #include "art/Utilities/ToolMacros.h"
9 #include "art_root_io/TFileService.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "cetlib_except/exception.h"
30 void configure(
const fhicl::ParameterSet& pset)
override;
46 art::ServiceHandle<util::SignalShapingServiceSBND>
sss;
63 std::vector<float> uin;
64 std::vector<float> vin;
65 std::vector<float> zin;
68 fThreshold = pset.get< std::vector<float> >(
"Threshold" );
69 fNumSigma = pset.get< std::vector<int> > (
"NumSigma" );
70 uin = pset.get< std::vector<float> >(
"uPlaneROIPad" );
71 vin = pset.get< std::vector<float> >(
"vPlaneROIPad" );
72 zin = pset.get< std::vector<float> >(
"zPlaneROIPad" );
74 if(uin.size() != 2 || vin.size() != 2 || zin.size() != 2) {
75 throw art::Exception(art::errors::Configuration)
76 <<
"u/v/z plane ROI pad size != 2";
91 sss = art::ServiceHandle<util::SignalShapingServiceSBND>();
105 size_t stopBin(numBins);
106 float elecNoise =
sss->GetRawNoise(channel);
110 float rawNoise = std::max(rmsNoise,
double(elecNoise));
113 float stopThreshold = startThreshold;
116 float runningSum = std::accumulate(waveform.begin(),waveform.begin()+numBins, 0.);
118 size_t roiStartBin(0);
119 bool roiCandStart(
false);
128 runningSum -= waveform[startBin++];
131 runningSum += waveform[stopBin++];
136 if (fabs(runningSum) < stopThreshold)
140 roiCandStart =
false;
146 if (fabs(runningSum) > startThreshold)
155 if (roiCandStart) roiVec.push_back(
CandidateROI(roiStartBin, waveform.size() - 1));
158 for(
auto& roi : roiVec)
163 roi.second = std::min(roi.second +
fPostROIPad[planeID.
Plane],
float(waveform.size()) - 1);
167 if(roiVec.size() > 1)
173 size_t startRoi = roiVec.front().first;
174 size_t stopRoi = startRoi;
176 for(
auto& roi : roiVec)
178 if (roi.first <= stopRoi) stopRoi = roi.second;
183 startRoi = roi.first;
184 stopRoi = roi.second;
201 std::vector<float> locWaveform = waveform;
204 std::sort(locWaveform.begin(), locWaveform.end(),[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
207 float sumWaveform = std::accumulate(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2, 0.);
208 float meanWaveform = sumWaveform / float(locWaveform.size()/2);
210 std::vector<float> locWaveformDiff(locWaveform.size()/2);
211 std::transform(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,meanWaveform));
213 double localRMS = std::inner_product(locWaveformDiff.begin(), locWaveformDiff.end(), locWaveformDiff.begin(), 0.);
215 localRMS = std::sqrt(std::max(
float(0.),
float(localRMS) /
float(locWaveformDiff.size())));
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.
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
Service to provide microboone-specific signal shaping for simulation (convolution) and reconstruction...
PlaneID_t Plane
Index of the plane within its TPC.
Description of geometry of one entire detector.
art framework interface to geometry description