All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
icarus::opdet::SampledWaveformFunction< T > Class Template Reference

Describes the waveform from a single photoelectron. More...

#include <SampledWaveformFunction.h>

Inheritance diagram for icarus::opdet::SampledWaveformFunction< T >:
icarus::opdet::PhotoelectronPulseFunction< T >

Classes

struct  WaveformSpecs_t
 Specifies the waveform shape and features. More...
 

Public Types

using ADCcount = typename Base_t::ADCcount
 Type for ADC counts (floating point). More...
 
using Time = typename Base_t::Time
 Type of time being used. More...
 
- Public Types inherited from icarus::opdet::PhotoelectronPulseFunction< T >
using ADCcount = util::quantities::counts_f
 Type for ADC counts (floating point). More...
 
using Time = T
 Type of time being used. More...
 

Public Member Functions

 SampledWaveformFunction (WaveformSpecs_t specs, Time peakTime, float gain)
 Constructor: initializes from an hard-coded shape. More...
 
Parameter accessors.
float gain () const
 Returns the gain the waveform is representing. More...
 
- Public Member Functions inherited from icarus::opdet::PhotoelectronPulseFunction< T >
virtual ~PhotoelectronPulseFunction ()=default
 
ADCcount evaluateAt (Time time) const
 Evaluates the pulse at the given time. More...
 
ADCcount operator() (Time time) const
 Alias of evaluateAt(). More...
 
Time peakTime () const
 Returns the time at which the first peak is found. More...
 
ADCcount peakAmplitude () const
 Returns the amplitude of the first peak in ADC counts. More...
 
ADCcount baseline () const
 Returns the baseline of the pulse in ADC counts. More...
 
int polarity () const
 Returns the polarity of the pulse (+1: positive, or -1: negative). More...
 
void dump (std::ostream &out, std::string const &indent, std::string const &firstIndent) const
 Prints on stream the parameters of this shape. More...
 
void dump (std::ostream &&out, std::string const &indent="") const
 
std::string toString (std::string const &indent, std::string const &firstIndent) const
 Returns the parameters of this shape as a descriptive string. More...
 
std::string toString (std::string const &indent="") const
 

Private Types

using Base_t = icarus::opdet::PhotoelectronPulseFunction< T >
 

Private Member Functions

Time sampleDuration () const
 The duration of each sample. More...
 
virtual ADCcount doEvaluateAt (Time time) const override
 Evaluates the pulse at the given time. More...
 
virtual Time doPeakTime () const override
 Returns the time at which the first peak is found. More...
 
virtual ADCcount doPeakAmplitude () const override
 Returns the amplitude of the first peak in ADC. More...
 
virtual void doDump (std::ostream &out, std::string const &indent, std::string const &firstIndent) const override
 Prints on stream the parameters of this shape. More...
 
bool hasSample (std::ptrdiff_t index) const
 Returns whether a sample with the specified index is within the range. More...
 
ADCcount integral () const
 Returns the integral of the waveform. More...
 
std::vector< ADCcountbuildSamples (float targetGain) const
 Transforms the input waveform. More...
 

Static Private Member Functions

static std::size_t findPeak (std::vector< ADCcount > const &samples)
 Returns the index of the sample under the peak of the waveform. More...
 

Private Attributes

WaveformSpecs_t const fSource
 Waveform information. More...
 
std::vector< ADCcount > const fSamples
 All samples. More...
 
float const fGain
 The gain this waveform represents. More...
 
std::size_t const fPeakSample
 The sample with the absolute peak. More...
 
Time const fRefTime
 The time of the start of sample #0. More...
 

Additional Inherited Members

- Protected Member Functions inherited from icarus::opdet::PhotoelectronPulseFunction< T >
virtual ADCcount doEvaluateAt (Time time) const =0
 Implementation of the function evaluation at time. More...
 
virtual ADCcount doBaseline () const
 Returns the baseline of the pulse. More...
 
virtual int doPolarity () const
 Returns the polarity of the pulse (+1 or -1). More...
 

Detailed Description

template<typename T>
class icarus::opdet::SampledWaveformFunction< T >

Describes the waveform from a single photoelectron.

Template Parameters
Ttype of time unit to be used

This functor (class behaving like a function) describes the shape of the response to a single photoelectron in a non-analytical form from a sequence of samples.

The peak time is assigned to the sample with the largest value.

See more details in the constructor.

Definition at line 34 of file SampledWaveformFunction.h.

Member Typedef Documentation

template<typename T >
using icarus::opdet::SampledWaveformFunction< T >::ADCcount = typename Base_t::ADCcount

Type for ADC counts (floating point).

Definition at line 58 of file SampledWaveformFunction.h.

Definition at line 54 of file SampledWaveformFunction.h.

template<typename T >
using icarus::opdet::SampledWaveformFunction< T >::Time = typename Base_t::Time

Type of time being used.

Definition at line 60 of file SampledWaveformFunction.h.

Constructor & Destructor Documentation

template<typename T >
icarus::opdet::SampledWaveformFunction< T >::SampledWaveformFunction ( WaveformSpecs_t  specs,
Time  peakTime,
float  gain 
)

Constructor: initializes from an hard-coded shape.

Parameters
waveformSpecsall information on the single photoelectron response
peakTimetime to assign to the peak
gainthe gain of the optical detector

The shape described in waveformSpecs is shifted in time so that evaluation at peakTime (evaluateAt(peakTime)) returns the peak amplitude; more precisely, peakTime is set to match the start of the largest sample.

The gain is rescaled starting from the one in the waveform specifications.

The polarity of the waveform is deduced by the value at peak.

Definition at line 177 of file SampledWaveformFunction.h.

178  : fSource { std::move(waveformSpecs) }
179  , fSamples { buildSamples(gain) }
180  , fGain { gain }
183  {}
Time const fRefTime
The time of the start of sample #0.
float const fGain
The gain this waveform represents.
Time sampleDuration() const
The duration of each sample.
float gain() const
Returns the gain the waveform is representing.
std::size_t const fPeakSample
The sample with the absolute peak.
static std::size_t findPeak(std::vector< ADCcount > const &samples)
Returns the index of the sample under the peak of the waveform.
Time peakTime() const
Returns the time at which the first peak is found.
std::vector< ADCcount > const fSamples
All samples.
std::vector< ADCcount > buildSamples(float targetGain) const
Transforms the input waveform.
WaveformSpecs_t const fSource
Waveform information.

Member Function Documentation

template<typename T >
auto icarus::opdet::SampledWaveformFunction< T >::buildSamples ( float  targetGain) const
private

Transforms the input waveform.

Parameters
waveforminput waveform (in millivolt and for a known gain)
targetGainthe desired gain
Returns
a sequence of samples in ADC

The returned waveform has the same time domain as the input one, but is expressed in ADC instead of voltage (conversion is perfectly linear, 2 V across 14 bits), and rescaled to meet the target gain.

Definition at line 231 of file SampledWaveformFunction.h.

232 {
233 
234  /*
235  * Sample conversion
236  * ------------------
237  *
238  * The waveform is expected in millivolt, and it expresses the response with/
239  * the photodetector set at a known gain.
240  * Our target is a waveform in ADC and the target gain in argument.
241  * The conversion factor is based on the full range of the digitizer,
242  * that is 2 V across 14 bit.
243  */
244  constexpr float VoltageRange = 2'000.0; // millivolt
245  constexpr unsigned short int ADCbits = 14;
246 
247  // 2 V in 14 bits (=> 8.192):
248  constexpr float mVtoADC = (1 << ADCbits) / VoltageRange;
249 
250  // if either the starting gain is unknown or the target gain is not specified,
251  // do not scale the gain
252  float const gainFactor = (fSource.gain != 0.0 && targetGain != 0.0)
253  ? (targetGain / fSource.gain): 1.0;
254  float const factor = gainFactor * mVtoADC;
255 
256  auto voltageToADC = [factor](float mV)
257  { return static_cast<ADCcount>(factor * mV); };
258 
259  std::vector<ADCcount> samples;
260  samples.reserve(fSource.samples.size());
261  std::transform(fSource.samples.begin(), fSource.samples.end(),
262  back_inserter(samples), voltageToADC);
263 
264  return samples;
265 
266 } // icarus::opdet::SampledWaveformFunction<>::buildSamples()
template<typename T >
void icarus::opdet::SampledWaveformFunction< T >::doDump ( std::ostream &  out,
std::string const &  indent,
std::string const &  firstIndent 
) const
overrideprivatevirtual

Prints on stream the parameters of this shape.

Parameters
outthe stream to write into
indentindentation string, prepended to all lines except first
indentFirstindentation string prepended to the first line

Reimplemented from icarus::opdet::PhotoelectronPulseFunction< T >.

Definition at line 199 of file SampledWaveformFunction.h.

203 {
204 
205  out << firstIndent
206  << "Pulse '" << fSource.name << "' (v. " << fSource.version
207  << ", " << fSource.date << "):"
208  << "\n" << indent << " " << fSource.description
209  << "\n" << indent
210  << " from " << fSamples.size() << "x " << sampleDuration() << " samples"
211  << ", peak at " << Base_t::peakTime()
212  << " with amplitude " << Base_t::peakAmplitude()
213  << "\n" << indent
214  << " start at " << fRefTime << ", gain " << fGain
215  << " (integral: " << integral() << ")"
216  << '\n'
217  ;
218 
219 } // icarus::opdet::SampledWaveformFunction<>::doDump()
Time const fRefTime
The time of the start of sample #0.
float const fGain
The gain this waveform represents.
Time sampleDuration() const
The duration of each sample.
std::string date
An indication of the date of the waveform.
ADCcount integral() const
Returns the integral of the waveform.
Time peakTime() const
Returns the time at which the first peak is found.
std::string description
Description of this waveform.
std::vector< ADCcount > const fSamples
All samples.
ADCcount peakAmplitude() const
Returns the amplitude of the first peak in ADC counts.
WaveformSpecs_t const fSource
Waveform information.
template<typename T >
auto icarus::opdet::SampledWaveformFunction< T >::doEvaluateAt ( Time  time) const
overrideprivatevirtual

Evaluates the pulse at the given time.

Parameters
timetime to evaluate the shape at

The scale of the time is defined by the peak time passed at construction.

Definition at line 188 of file SampledWaveformFunction.h.

190 {
191  std::ptrdiff_t const iSample = static_cast<std::ptrdiff_t>
192  (std::floor((time - fRefTime)/sampleDuration()));
193  return hasSample(iSample)? fSamples[iSample]: ADCcount{ 0 };
194 } // icarus::opdet::SampledWaveformFunction<>::doEvaluateAt()
Time const fRefTime
The time of the start of sample #0.
bool hasSample(std::ptrdiff_t index) const
Returns whether a sample with the specified index is within the range.
Time sampleDuration() const
The duration of each sample.
std::vector< ADCcount > const fSamples
All samples.
typename Base_t::ADCcount ADCcount
Type for ADC counts (floating point).
template<typename T >
virtual ADCcount icarus::opdet::SampledWaveformFunction< T >::doPeakAmplitude ( ) const
inlineoverrideprivatevirtual

Returns the amplitude of the first peak in ADC.

Reimplemented from icarus::opdet::PhotoelectronPulseFunction< T >.

Definition at line 129 of file SampledWaveformFunction.h.

130  { return fSamples[fPeakSample]; }
std::size_t const fPeakSample
The sample with the absolute peak.
std::vector< ADCcount > const fSamples
All samples.
template<typename T >
virtual Time icarus::opdet::SampledWaveformFunction< T >::doPeakTime ( ) const
inlineoverrideprivatevirtual

Returns the time at which the first peak is found.

Implements icarus::opdet::PhotoelectronPulseFunction< T >.

Definition at line 125 of file SampledWaveformFunction.h.

126  { return fRefTime + fPeakSample * sampleDuration(); }
Time const fRefTime
The time of the start of sample #0.
Time sampleDuration() const
The duration of each sample.
std::size_t const fPeakSample
The sample with the absolute peak.
template<typename T >
std::size_t icarus::opdet::SampledWaveformFunction< T >::findPeak ( std::vector< ADCcount > const &  samples)
staticprivate

Returns the index of the sample under the peak of the waveform.

Definition at line 272 of file SampledWaveformFunction.h.

273 {
274  assert(!samples.empty());
275  auto const sbegin = samples.begin();
276  auto const [ min, max ] = std::minmax_element(sbegin, samples.end());
277  // assume baseline 0:
278  return ((min->abs() > max->abs())? min: max) - sbegin;
279 } // icarus::opdet::SampledWaveformFunction<T>::findPeak()
template<typename T >
float icarus::opdet::SampledWaveformFunction< T >::gain ( ) const
inline

Returns the gain the waveform is representing.

Definition at line 95 of file SampledWaveformFunction.h.

95 { return fGain; }
float const fGain
The gain this waveform represents.
template<typename T >
bool icarus::opdet::SampledWaveformFunction< T >::hasSample ( std::ptrdiff_t  index) const
inlineprivate

Returns whether a sample with the specified index is within the range.

Definition at line 147 of file SampledWaveformFunction.h.

148  { return (index >= 0) && (std::size_t(index) < fSamples.size()); }
std::vector< ADCcount > const fSamples
All samples.
template<typename T >
auto icarus::opdet::SampledWaveformFunction< T >::integral ( ) const
private

Returns the integral of the waveform.

Definition at line 224 of file SampledWaveformFunction.h.

225  { return std::reduce(fSamples.begin(), fSamples.end()); }
std::vector< ADCcount > const fSamples
All samples.
template<typename T >
Time icarus::opdet::SampledWaveformFunction< T >::sampleDuration ( ) const
inlineprivate

The duration of each sample.

Definition at line 112 of file SampledWaveformFunction.h.

112 { return fSource.sampleDuration; }
WaveformSpecs_t const fSource
Waveform information.

Member Data Documentation

template<typename T >
float const icarus::opdet::SampledWaveformFunction< T >::fGain
private

The gain this waveform represents.

Definition at line 105 of file SampledWaveformFunction.h.

template<typename T >
std::size_t const icarus::opdet::SampledWaveformFunction< T >::fPeakSample
private

The sample with the absolute peak.

Definition at line 107 of file SampledWaveformFunction.h.

template<typename T >
Time const icarus::opdet::SampledWaveformFunction< T >::fRefTime
private

The time of the start of sample #0.

Definition at line 109 of file SampledWaveformFunction.h.

template<typename T >
std::vector<ADCcount> const icarus::opdet::SampledWaveformFunction< T >::fSamples
private

All samples.

Definition at line 103 of file SampledWaveformFunction.h.

template<typename T >
WaveformSpecs_t const icarus::opdet::SampledWaveformFunction< T >::fSource
private

Waveform information.

Definition at line 101 of file SampledWaveformFunction.h.


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