All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Attributes | List of all members
opdet::SharedWaveformBaseline Class Reference

Extracts a common baseline from waveforms. More...

#include <SharedWaveformBaseline.h>

Classes

struct  BaselineInfo_t
 Type for algorithm result. More...
 
struct  Params_t
 Algorithm configuration parameters. More...
 

Public Member Functions

 SharedWaveformBaseline (Params_t params, std::string logCategory)
 
BaselineInfo_t operator() (std::vector< raw::OpDetWaveform const * > const &waveforms) const
 Returns a common baseline from all the specified waveforms. More...
 
Params_t const & parameters () const
 Returns the set of configuration parameters of this algorithm. More...
 

Private Attributes

Params_t fParams
 Algorithm parameters. More...
 
std::string fLogCategory
 Name of stream category for console messages. More...
 

Detailed Description

Extracts a common baseline from waveforms.

This algorithm processes a group of waveforms at a time, and returns a common baseline for them. The baseline is learned by looking at a fixed size of the beginning of each of the waveforms, as follows:

  1. the RMS of the first portion of each baseline is computed;
  2. the median of the samples on the same samples is also computed;
  3. an acceptance range is constructed, using the median of the sample as the center and nRMS times the median of the RMS as maximum distance from that center in either direction;
  4. as a second pass, if in the first portion of a waveform there are at least nExcessSamples samples in a row that are outside of the acceptance range, that waveform is excluded;
  5. all the samples in the first portion of the remaining waveforms are averaged to obtain the final estimation of the baseline; this last step should increase the resolution of the baseline beyond the median that was obtained at step 2.

The parameters are specified at algorithm construction time and are contained in the Params_t object.

Definition at line 52 of file SharedWaveformBaseline.h.

Constructor & Destructor Documentation

opdet::SharedWaveformBaseline::SharedWaveformBaseline ( Params_t  params,
std::string  logCategory 
)
inline

Definition at line 99 of file SharedWaveformBaseline.h.

99  :
100  fParams{ std::move(params) }
101  , fLogCategory{ std::move(logCategory) }
102  {}
std::string fLogCategory
Name of stream category for console messages.
Params_t fParams
Algorithm parameters.

Member Function Documentation

auto opdet::SharedWaveformBaseline::operator() ( std::vector< raw::OpDetWaveform const * > const &  waveforms) const

Returns a common baseline from all the specified waveforms.

Definition at line 120 of file SharedWaveformBaseline.cxx.

122 {
123  if (waveforms.empty()) return {};
124 
125  //
126  // first pass: find statistics
127  //
128  std::vector<raw::ADC_Count_t> samples;
129  samples.reserve(fParams.nSample * waveforms.size());
130  std::vector<double> RMSs;
131  RMSs.reserve(waveforms.size());
132 
133  for (raw::OpDetWaveform const* waveform: waveforms) {
134 
135  mf::LogTrace{ fLogCategory } << "Now processing: " << waveformIntro(waveform);
136 
137  if (waveform->size() < fParams.nSample) {
138  mf::LogTrace{ fLogCategory } << waveformIntro(waveform)
139  << ": skipped because shorter than " << fParams.nSample
140  << " samples";
141  continue;
142  }
143 
144  auto const begin = waveform->cbegin();
145  auto const end = std::next(begin, fParams.nSample);
146 
148  for (auto it = begin; it != end; ++it) stats.add(*it);
149  RMSs.push_back(stats.RMS());
150 
151  std::copy(waveform->begin(), waveform->end(), back_inserter(samples));
152  } // for
153 
154  double const medRMS = median(RMSs.cbegin(), RMSs.cend());
155  raw::ADC_Count_t const med = median(samples.cbegin(), samples.cend());
156 
157  mf::LogTrace{ fLogCategory } << "Stats of channel "
158  << waveforms.front()->ChannelNumber() << " from "
159  << fParams.nSample << " starting samples of " << waveforms.size()
160  << " waveforms: median=" << med << " ADC, median RMS of each waveform="
161  << medRMS << " ADC";
162 
163  //
164  // collect the samples
165  //
166  raw::ADC_Count_t const aboveThreshold
167  = med + static_cast<raw::ADC_Count_t>(std::round(medRMS * fParams.nRMS));
168  raw::ADC_Count_t const belowThreshold
169  = med - static_cast<raw::ADC_Count_t>(std::round(medRMS * fParams.nRMS));
170 
171  auto const sampleOutOfBoundary
172  = [this, aboveThreshold, belowThreshold](auto begin, auto end)
173  {
174  return findOutOfBoundary(begin, end,
175  belowThreshold, aboveThreshold,
177  };
178 
180  unsigned int nUsedWaveforms = 0U;
181  for (raw::OpDetWaveform const* waveform: waveforms) {
182 
183  auto const begin = waveform->cbegin();
184  auto const end = std::next(begin, fParams.nSample);
185 
186  //
187  // check whether to use this waveform
188  //
189  auto const firstExcess = sampleOutOfBoundary(begin, end);
190  if (firstExcess != end) {
191 
192  mf::LogTrace log { fLogCategory };
193  log
194  << waveformIntro(waveform) << " has " << fParams.nExcessSamples
195  << " samples in a row out of [ " << belowThreshold << " ; "
196  << aboveThreshold << " ] ADC starting at sample #"
197  << (firstExcess - begin) << ":";
198  for (
199  auto it = firstExcess; it != firstExcess + fParams.nExcessSamples; ++it
200  )
201  log << " " << *it;
202 
203  // should we try to recover part of the waveform here? e.g.
204  /*
205  if (((firstExcess - begin) < fParams.nSample*3/5) || (waveforms.size() >= 5))
206  continue;
207  end = begin + fParams.nSample / 2;
208  */
209 
210  } // if
211 
212  //
213  // include it
214  //
215  ++nUsedWaveforms;
216  stats.add_unweighted(begin, end);
217 
218  } // for
219 
220  return {
221  stats.Average() // baseline
222  , medRMS // RMS
223  , nUsedWaveforms // nWaveforms
224  , (unsigned int) stats.N() // nSamples
225  };
226 
227 } // opdet::SharedWaveformBaseline::operator()
std::size_t nSample
Number of samples to use from each waveform.
Weight_t RMS() const
Returns the root mean square.
Weight_t Average() const
Returns the value average.
unsigned int nExcessSamples
Number of samples out of range to discard a waveform.
std::string fLogCategory
Name of stream category for console messages.
int N() const
Returns the number of entries added.
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
double nRMS
Number of RMS from the baseline to discard a waveform.
Params_t fParams
Algorithm parameters.
T copy(T const &v)
void add(Data_t value, Weight_t weight=Weight_t(1.0))
Adds one entry with specified value and weight.
Params_t const& opdet::SharedWaveformBaseline::parameters ( ) const
inline

Returns the set of configuration parameters of this algorithm.

Definition at line 109 of file SharedWaveformBaseline.h.

109 { return fParams; }
Params_t fParams
Algorithm parameters.

Member Data Documentation

std::string opdet::SharedWaveformBaseline::fLogCategory
private

Name of stream category for console messages.

Definition at line 114 of file SharedWaveformBaseline.h.

Params_t opdet::SharedWaveformBaseline::fParams
private

Algorithm parameters.

Definition at line 112 of file SharedWaveformBaseline.h.


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