25 #include "art/Framework/Core/ModuleMacros.h"
26 #include "art/Framework/Core/ReplicatedProducer.h"
27 #include "art/Framework/Principal/Event.h"
28 #include "art/Framework/Services/Registry/ServiceHandle.h"
29 #include "art_root_io/TFileService.h"
30 #include "art/Utilities/make_tool.h"
31 #include "canvas/Persistency/Common/Ptr.h"
32 #include "canvas/Persistency/Common/PtrVector.h"
33 #include "messagefacility/MessageLogger/MessageLogger.h"
34 #include "cetlib/cpu_timer.h"
54 #include "icarus_signal_processing/WaveformTools.h"
56 #include "tbb/parallel_for.h"
57 #include "tbb/blocked_range.h"
58 #include "tbb/task_arena.h"
59 #include "tbb/spin_mutex.h"
71 explicit WaveformIntegrity(fhicl::ParameterSet
const &, art::ProcessingFrame
const&);
73 void produce(art::Event&
evt, art::ProcessingFrame
const&)
override;
108 fNewRawDigitLabelVec = pset.get< std::vector<art::InputTag>> (
"NewRawDigitLabelVec", {
"daqTPC"});
109 fOldRawDigitLabelVec = pset.get< std::vector<art::InputTag>> (
"OldRawDigitLabelVec", {
"daqTPC"});
121 std::cout <<
"WaveformIntegrity not given equal size product label vectors" << std::endl;
127 art::Handle<std::vector<raw::RawDigit>> newRawDigitHandle;
131 art::Handle<std::vector<raw::RawDigit>> oldRawDigitHandle;
135 if (!newRawDigitHandle->size() || !oldRawDigitHandle->size())
137 std::cout <<
"WaveformIntegrity found a zero length buffer" << std::endl;
141 for(
size_t chanIdx = 0; chanIdx < newRawDigitHandle->size(); chanIdx++)
144 art::Ptr<raw::RawDigit> newDigitVec(newRawDigitHandle, chanIdx);
145 art::Ptr<raw::RawDigit> oldDigitVec(oldRawDigitHandle, chanIdx);
150 if (newChannel != oldChannel)
152 std::cout <<
"WaveformIntegrity finds channel mismatch, idx: " << chanIdx <<
", new channel: " << newChannel <<
", old channel: " << oldChannel << std::endl;
157 size_t dataSize = newDigitVec->Samples();
159 std::vector<short> newRawADC(dataSize);
160 std::vector<short> oldRawADC(dataSize);
163 raw::Uncompress(newDigitVec->ADCs(), newRawADC, newDigitVec->Compression());
164 raw::Uncompress(oldDigitVec->ADCs(), oldRawADC, oldDigitVec->Compression());
166 if (newRawADC != oldRawADC)
168 std::vector<short> diffVec;
169 std::vector<short> idxVec;
171 for(
size_t tickIdx = 0; tickIdx < newRawADC.size(); tickIdx++)
173 if (newRawADC[tickIdx] != oldRawADC[tickIdx])
175 diffVec.push_back(newRawADC[tickIdx] - oldRawADC[tickIdx]);
176 idxVec.push_back(tickIdx);
180 short maxDiff = *std::max_element(diffVec.begin(),diffVec.end());
181 short minDiff = *std::min_element(diffVec.begin(),diffVec.end());
185 std::cout <<
"==> Channel: " << newChannel <<
" - " << wireIDVec[0] <<
" - has " << diffVec.size() <<
" max/min: " << maxDiff <<
"/" << minDiff << std::endl;
200 std::vector<float> locWaveform = waveform;
203 std::sort(locWaveform.begin(), locWaveform.end(),[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
205 float threshold = 10.;
207 std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](
const auto& val){
return std::fabs(val) > threshold;});
210 int minNumBins = std::max(
int(0.8 * locWaveform.size()),
int(
std::distance(locWaveform.begin(),threshItr)));
213 float truncRms = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
215 truncRms = std::sqrt(std::max(0.,truncRms /
double(minNumBins)));
223 std::vector<float> locWaveform = waveform;
226 std::sort(locWaveform.begin(), locWaveform.end(),[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
229 float sumWaveform = std::accumulate(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2, 0.);
230 float meanWaveform = sumWaveform / float(locWaveform.size()/2);
232 std::vector<float> locWaveformDiff(locWaveform.size()/2);
234 std::transform(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,meanWaveform));
236 float localRMS = std::inner_product(locWaveformDiff.begin(), locWaveformDiff.end(), locWaveformDiff.begin(), 0.);
238 localRMS = std::sqrt(std::max(
float(0.),localRMS /
float(locWaveformDiff.size())));
240 float threshold = 6. * localRMS;
242 std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](
const auto& val){
return std::fabs(val) > threshold;});
245 int minNumBins = std::max(
int(0.8 * locWaveform.size()),
int(
std::distance(locWaveform.begin(),threshItr)));
248 float aveSum = std::accumulate(locWaveform.begin(), locWaveform.begin() + minNumBins, 0.);
249 float newPedestal = aveSum / minNumBins;
252 locWaveformDiff.resize(minNumBins);
254 std::transform(locWaveform.begin(),locWaveform.begin() + minNumBins,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,newPedestal));
256 localRMS = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
257 localRMS = std::sqrt(std::max(
float(0.),localRMS /
float(minNumBins)));
260 std::transform(waveform.begin(), waveform.end(), fixedWaveform.begin(), [newPedestal](
const auto& val){
return val - newPedestal;});
Utilities related to art service access.
This provides an interface for tools which are tasked with running the deconvolution algorithm...
Helper functions to create a wire.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
Definition of basic raw digits.
This provides an interface for tools which are tasked with finding the baselines in input waveforms...
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
Collect all the RawData header files together.
Class providing information about the quality of channels.
Description of geometry of one entire detector.
Interface for experiment-specific channel quality info provider.
Declaration of basic channel signal object.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Interface for experiment-specific service for channel quality info.
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
process_name can override from command line with o or output caldata
tbb::spin_mutex deconvolutionSpinMutex
art framework interface to geometry description
BEGIN_PROLOG could also be cout