All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
caldata::WaveformIntegrity Class Reference
Inheritance diagram for caldata::WaveformIntegrity:

Public Member Functions

 WaveformIntegrity (fhicl::ParameterSet const &, art::ProcessingFrame const &)
 
void produce (art::Event &evt, art::ProcessingFrame const &) override
 
void reconfigure (fhicl::ParameterSet const &p)
 

Private Member Functions

float fixTheFreakingWaveform (const std::vector< float > &, raw::ChannelID_t, std::vector< float > &) const
 
float getTruncatedRMS (const std::vector< float > &) const
 

Private Attributes

std::vector< art::InputTag > fNewRawDigitLabelVec
 New Raw Digits. More...
 
std::vector< art::InputTag > fOldRawDigitLabelVec
 From previous run. More...
 
icarus_signal_processing::WaveformTools
< float > 
fWaveformTool
 
const geo::GeometryCorefGeometry = lar::providerFrom<geo::Geometry>()
 
const
lariov::ChannelStatusProvider
fChannelFilter = lar::providerFrom<lariov::ChannelStatusService>()
 
const lariov::DetPedestalProviderfPedRetrievalAlg = lar::providerFrom<lariov::DetPedestalService>()
 

Detailed Description

Definition at line 66 of file WaveformIntegrity_module.cc.

Constructor & Destructor Documentation

caldata::WaveformIntegrity::WaveformIntegrity ( fhicl::ParameterSet const &  pset,
art::ProcessingFrame const &  frame 
)
explicit

Definition at line 99 of file WaveformIntegrity_module.cc.

99  : art::ReplicatedProducer(pset,frame)
100 {
101  this->reconfigure(pset);
102 }
void reconfigure(fhicl::ParameterSet const &p)

Member Function Documentation

float caldata::WaveformIntegrity::fixTheFreakingWaveform ( const std::vector< float > &  waveform,
raw::ChannelID_t  channel,
std::vector< float > &  fixedWaveform 
) const
private

Definition at line 220 of file WaveformIntegrity_module.cc.

221 {
222  // do rms calculation - the old fashioned way and over all adc values
223  std::vector<float> locWaveform = waveform;
224 
225  // sort in ascending order so we can truncate the sume
226  std::sort(locWaveform.begin(), locWaveform.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
227 
228  // Get the mean of the waveform we're checking...
229  float sumWaveform = std::accumulate(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2, 0.);
230  float meanWaveform = sumWaveform / float(locWaveform.size()/2);
231 
232  std::vector<float> locWaveformDiff(locWaveform.size()/2);
233 
234  std::transform(locWaveform.begin(),locWaveform.begin() + locWaveform.size()/2,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,meanWaveform));
235 
236  float localRMS = std::inner_product(locWaveformDiff.begin(), locWaveformDiff.end(), locWaveformDiff.begin(), 0.);
237 
238  localRMS = std::sqrt(std::max(float(0.),localRMS / float(locWaveformDiff.size())));
239 
240  float threshold = 6. * localRMS;
241 
242  std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](const auto& val){return std::fabs(val) > threshold;});
243 
244  //int minNumBins = std::max(int(fTruncRMSMinFraction * locWaveform.size()),int(std::distance(locWaveform.begin(),threshItr)));
245  int minNumBins = std::max(int(0.8 * locWaveform.size()),int(std::distance(locWaveform.begin(),threshItr)));
246 
247  // recalculate the mean
248  float aveSum = std::accumulate(locWaveform.begin(), locWaveform.begin() + minNumBins, 0.);
249  float newPedestal = aveSum / minNumBins;
250 
251  // recalculate the rms
252  locWaveformDiff.resize(minNumBins);
253 
254  std::transform(locWaveform.begin(),locWaveform.begin() + minNumBins,locWaveformDiff.begin(), std::bind(std::minus<float>(),std::placeholders::_1,newPedestal));
255 
256  localRMS = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
257  localRMS = std::sqrt(std::max(float(0.),localRMS / float(minNumBins)));
258 
259  // Set the waveform to the new baseline
260  std::transform(waveform.begin(), waveform.end(), fixedWaveform.begin(), [newPedestal](const auto& val){return val - newPedestal;});
261 
262  return localRMS;
263 }
static constexpr Sample_t transform(Sample_t sample)
walls no right
Definition: selectors.fcl:105
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
walls no left
Definition: selectors.fcl:105
float caldata::WaveformIntegrity::getTruncatedRMS ( const std::vector< float > &  waveform) const
private

Definition at line 197 of file WaveformIntegrity_module.cc.

198 {
199  // do rms calculation - the old fashioned way and over all adc values
200  std::vector<float> locWaveform = waveform;
201 
202  // sort in ascending order so we can truncate the sume
203  std::sort(locWaveform.begin(), locWaveform.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
204 
205  float threshold = 10.; //fTruncRMSThreshold;
206 
207  std::vector<float>::iterator threshItr = std::find_if(locWaveform.begin(),locWaveform.end(),[threshold](const auto& val){return std::fabs(val) > threshold;});
208 
209  //int minNumBins = std::max(int(fTruncRMSMinFraction * locWaveform.size()),int(std::distance(locWaveform.begin(),threshItr)));
210  int minNumBins = std::max(int(0.8 * locWaveform.size()),int(std::distance(locWaveform.begin(),threshItr)));
211 
212  // Get the truncated sum
213  float truncRms = std::inner_product(locWaveform.begin(), locWaveform.begin() + minNumBins, locWaveform.begin(), 0.);
214 
215  truncRms = std::sqrt(std::max(0.,truncRms / double(minNumBins)));
216 
217  return truncRms;
218 }
walls no right
Definition: selectors.fcl:105
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
walls no left
Definition: selectors.fcl:105
void caldata::WaveformIntegrity::produce ( art::Event &  evt,
art::ProcessingFrame const &  frame 
)
override

Definition at line 115 of file WaveformIntegrity_module.cc.

116 {
117  // We loop over the collection of RawDigits in our input list
118  // This is not done multi threaded as a way to cut down on overall job memory usage...
119  if (fNewRawDigitLabelVec.size() != fOldRawDigitLabelVec.size())
120  {
121  std::cout << "WaveformIntegrity not given equal size product label vectors" << std::endl;
122  return;
123  }
124 
125  for(size_t prodIdx = 0; prodIdx < fNewRawDigitLabelVec.size(); prodIdx++)
126  {
127  art::Handle<std::vector<raw::RawDigit>> newRawDigitHandle;
128 
129  evt.getByLabel(fNewRawDigitLabelVec[prodIdx],newRawDigitHandle);
130 
131  art::Handle<std::vector<raw::RawDigit>> oldRawDigitHandle;
132 
133  evt.getByLabel(fOldRawDigitLabelVec[prodIdx],oldRawDigitHandle);
134 
135  if (!newRawDigitHandle->size() || !oldRawDigitHandle->size())
136  {
137  std::cout << "WaveformIntegrity found a zero length buffer" << std::endl;
138  continue;
139  }
140 
141  for(size_t chanIdx = 0; chanIdx < newRawDigitHandle->size(); chanIdx++)
142  {
143  // get the reference to the current raw::RawDigit
144  art::Ptr<raw::RawDigit> newDigitVec(newRawDigitHandle, chanIdx);
145  art::Ptr<raw::RawDigit> oldDigitVec(oldRawDigitHandle, chanIdx);
146 
147  raw::ChannelID_t newChannel = newDigitVec->Channel();
148  raw::ChannelID_t oldChannel = oldDigitVec->Channel();
149 
150  if (newChannel != oldChannel)
151  {
152  std::cout << "WaveformIntegrity finds channel mismatch, idx: " << chanIdx << ", new channel: " << newChannel << ", old channel: " << oldChannel << std::endl;
153 
154  continue;
155  }
156 
157  size_t dataSize = newDigitVec->Samples();
158 
159  std::vector<short> newRawADC(dataSize);
160  std::vector<short> oldRawADC(dataSize);
161 
162  // uncompress the data
163  raw::Uncompress(newDigitVec->ADCs(), newRawADC, newDigitVec->Compression());
164  raw::Uncompress(oldDigitVec->ADCs(), oldRawADC, oldDigitVec->Compression());
165 
166  if (newRawADC != oldRawADC)
167  {
168  std::vector<short> diffVec;
169  std::vector<short> idxVec;
170 
171  for(size_t tickIdx = 0; tickIdx < newRawADC.size(); tickIdx++)
172  {
173  if (newRawADC[tickIdx] != oldRawADC[tickIdx])
174  {
175  diffVec.push_back(newRawADC[tickIdx] - oldRawADC[tickIdx]);
176  idxVec.push_back(tickIdx);
177  }
178  }
179 
180  short maxDiff = *std::max_element(diffVec.begin(),diffVec.end());
181  short minDiff = *std::min_element(diffVec.begin(),diffVec.end());
182 
183  std::vector<geo::WireID> wireIDVec = fGeometry->ChannelToWire(newChannel);
184 
185  std::cout << "==> Channel: " << newChannel << " - " << wireIDVec[0] << " - has " << diffVec.size() << " max/min: " << maxDiff << "/" << minDiff << std::endl;
186 // for(size_t idx = 0; diffVec.size(); idx++) std::cout << idxVec[idx] << "/" << diffVec[idx] << " ";
187 // std::cout << std::endl;
188  }
189 
190  }
191 
192  }
193 
194  return;
195 } // produce
const geo::GeometryCore * fGeometry
std::vector< art::InputTag > fOldRawDigitLabelVec
From previous run.
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
std::vector< art::InputTag > fNewRawDigitLabelVec
New Raw Digits.
TCEvent evt
Definition: DataStructs.cxx:8
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
BEGIN_PROLOG could also be cout
void caldata::WaveformIntegrity::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 105 of file WaveformIntegrity_module.cc.

106 {
107  // Recover the parameters
108  fNewRawDigitLabelVec = pset.get< std::vector<art::InputTag>> ("NewRawDigitLabelVec", {"daqTPC"});
109  fOldRawDigitLabelVec = pset.get< std::vector<art::InputTag>> ("OldRawDigitLabelVec", {"daqTPC"});
110 
111  return;
112 }
std::vector< art::InputTag > fOldRawDigitLabelVec
From previous run.
std::vector< art::InputTag > fNewRawDigitLabelVec
New Raw Digits.

Member Data Documentation

const lariov::ChannelStatusProvider* caldata::WaveformIntegrity::fChannelFilter = lar::providerFrom<lariov::ChannelStatusService>()
private

Definition at line 91 of file WaveformIntegrity_module.cc.

const geo::GeometryCore* caldata::WaveformIntegrity::fGeometry = lar::providerFrom<geo::Geometry>()
private

Definition at line 90 of file WaveformIntegrity_module.cc.

std::vector<art::InputTag> caldata::WaveformIntegrity::fNewRawDigitLabelVec
private

New Raw Digits.

Definition at line 85 of file WaveformIntegrity_module.cc.

std::vector<art::InputTag> caldata::WaveformIntegrity::fOldRawDigitLabelVec
private

From previous run.

Definition at line 86 of file WaveformIntegrity_module.cc.

const lariov::DetPedestalProvider* caldata::WaveformIntegrity::fPedRetrievalAlg = lar::providerFrom<lariov::DetPedestalService>()
private

Definition at line 92 of file WaveformIntegrity_module.cc.

icarus_signal_processing::WaveformTools<float> caldata::WaveformIntegrity::fWaveformTool
private

Definition at line 88 of file WaveformIntegrity_module.cc.


The documentation for this class was generated from the following file: