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

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

#include <CustomPulseFunction.h>

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

Classes

struct  PulseStats_t
 Record of collected information on the pulse shape. 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...
 
using ParameterValue_t = double
 Type of value for parameters (TFormula). More...
 
using NameAndValue_t = std::pair< std::string, ParameterValue_t >
 Type of parameter name/value definition. More...
 
using PulseParameters_t = std::vector< NameAndValue_t >
 Type of list of all function parameters. 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

 CustomPulseFunction (std::string const &expression, PulseParameters_t const &parameters, Time peakTime)
 Constructor: chooses shape and the values of its parameters. More...
 
 CustomPulseFunction (std::string const &expression, PulseParameters_t const &parameters, std::string const &peakTime)
 
Parameter accessors.
ParameterValue_t parameter (std::string const &name) const
 Returns the value of the parameter specified by name. 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

 CustomPulseFunction (std::string const &expression, PulseParameters_t const &parameters)
 Constructor implementation. 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 counts. 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...
 
PulseStats_t extractStats (Time peakTime) const
 Extracts statistics from pulse shape. More...
 

Static Private Member Functions

static std::string checkMissingParameters (TFormula const &formula, PulseParameters_t const &parameters)
 
static std::string checkExcessParameters (TFormula const &formula, PulseParameters_t const &parameters)
 
static void setParameters (TFormula &formula, PulseParameters_t const &parameters)
 Sets the value of the parameters of formula. More...
 

Private Attributes

TFormula fFormula
 Formula of the shape. More...
 
PulseStats_t fStats
 Collected information about the pulse. 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::CustomPulseFunction< T >

Describes the waveform from a single photoelectron.

Template Parameters
Timetype of time unit to be used

This functor (class behaving like a function) describes the shape of the response to a single photoelectron as a custom shape.

The shape is a formula interpreted via ROOT's TFormula. It is assumed to start at time 0.0 (in Time units).

Definition at line 38 of file CustomPulseFunction.h.

Member Typedef Documentation

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

Type for ADC counts (floating point).

Definition at line 61 of file CustomPulseFunction.h.

Definition at line 57 of file CustomPulseFunction.h.

template<typename T >
using icarus::opdet::CustomPulseFunction< T >::NameAndValue_t = std::pair<std::string, ParameterValue_t>

Type of parameter name/value definition.

Definition at line 68 of file CustomPulseFunction.h.

template<typename T >
using icarus::opdet::CustomPulseFunction< T >::ParameterValue_t = double

Type of value for parameters (TFormula).

Definition at line 65 of file CustomPulseFunction.h.

template<typename T >
using icarus::opdet::CustomPulseFunction< T >::PulseParameters_t = std::vector<NameAndValue_t>

Type of list of all function parameters.

Definition at line 71 of file CustomPulseFunction.h.

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

Type of time being used.

Definition at line 63 of file CustomPulseFunction.h.

Constructor & Destructor Documentation

template<typename T >
icarus::opdet::CustomPulseFunction< T >::CustomPulseFunction ( std::string const &  expression,
PulseParameters_t const &  parameters,
Time  peakTime 
)

Constructor: chooses shape and the values of its parameters.

Parameters
expressionmathematical expression of pulse shape
parametersthe list of named parameters and their values
peakTimeexpression of time of the maximum amplitude of the shape

The shape mathematical expression must be compatible with ROOT 6 TFormula. The formula must have a single independent variable, time measured in the Time scale. The value 0 of that time corresponds to when the photoelectron is emitted from the photocathode.

The peak time argument is used to report when the peak happens. It would be possible to compute it in a general way, but the implementation of that functionality is complicate enough to get it right and fast, that it's better to rely on user's knowledge. The value may be either a number or a string. The number (Time) directly represents the time of the peak, while the expression is another TFormula expression that can use the same parameters as the shape expression, so that for example it is possible to indicate the peak time of a shape like exp(-(x - [mu])**2) as [mu]. In this case, the peak time expression must use no variable.

Definition at line 197 of file CustomPulseFunction.h.

202  : CustomPulseFunction(expression, parameters)
203 {
205 } // icarus::opdet::CustomPulseFunction<>::CustomPulseFunction(Time)
CustomPulseFunction(std::string const &expression, PulseParameters_t const &parameters, Time peakTime)
Constructor: chooses shape and the values of its parameters.
Time peakTime() const
Returns the time at which the first peak is found.
PulseStats_t fStats
Collected information about the pulse.
PulseStats_t extractStats(Time peakTime) const
Extracts statistics from pulse shape.
template<typename T >
icarus::opdet::CustomPulseFunction< T >::CustomPulseFunction ( std::string const &  expression,
PulseParameters_t const &  parameters,
std::string const &  peakTime 
)

Definition at line 210 of file CustomPulseFunction.h.

215  : CustomPulseFunction(expression, parameters)
216 {
217  TFormula peakExpr("CustomPulseFunctionPeak", peakTime.c_str(), false);
218 
219  // excess parameters are allowed because they might belong to `expression`
220  std::string const msg = checkMissingParameters(peakExpr, parameters);
221  if (!msg.empty()) throw std::runtime_error("CustomPulseFunction:" + msg);
222 
223  setParameters(peakExpr, parameters);
224  fStats = extractStats(Time{ peakExpr.Eval(0.0) }); // dummy value
225 
226 } // icarus::opdet::CustomPulseFunction<>::CustomPulseFunction(string)
static std::string checkMissingParameters(TFormula const &formula, PulseParameters_t const &parameters)
static void setParameters(TFormula &formula, PulseParameters_t const &parameters)
Sets the value of the parameters of formula.
CustomPulseFunction(std::string const &expression, PulseParameters_t const &parameters, Time peakTime)
Constructor: chooses shape and the values of its parameters.
Time peakTime() const
Returns the time at which the first peak is found.
PulseStats_t fStats
Collected information about the pulse.
typename Base_t::Time Time
Type of time being used.
PulseStats_t extractStats(Time peakTime) const
Extracts statistics from pulse shape.
template<typename T >
icarus::opdet::CustomPulseFunction< T >::CustomPulseFunction ( std::string const &  expression,
PulseParameters_t const &  parameters 
)
private

Constructor implementation.

Definition at line 231 of file CustomPulseFunction.h.

235  : fFormula{
236  "CustomPulseFunction", // fixed name, hope ROOT does not mess it up...
237  expression.c_str(),
238  false // addToGlobList
239  }
240 {
241  std::string const msg = checkMissingParameters(fFormula, parameters)
242  + checkExcessParameters(fFormula, parameters);
243  if (!msg.empty()) throw std::runtime_error("CustomPulseFunction:" + msg);
244 
245  setParameters(fFormula, parameters);
246 } // icarus::opdet::CustomPulseFunction<>::CustomPulseFunction(impl)
static std::string checkMissingParameters(TFormula const &formula, PulseParameters_t const &parameters)
static std::string checkExcessParameters(TFormula const &formula, PulseParameters_t const &parameters)
TFormula fFormula
Formula of the shape.
static void setParameters(TFormula &formula, PulseParameters_t const &parameters)
Sets the value of the parameters of formula.

Member Function Documentation

template<typename T >
std::string icarus::opdet::CustomPulseFunction< T >::checkExcessParameters ( TFormula const &  formula,
PulseParameters_t const &  parameters 
)
staticprivate

Returns a message about parameters which are not in formula.

Returns
a message about excess parameters, empty if none

Definition at line 318 of file CustomPulseFunction.h.

319 {
320  std::set<std::string> offered;
321  for (auto const& nameAndValue: parameters)
322  offered.insert(nameAndValue.first);
323  std::set<std::string> required;
324  for (auto const iPar: util::counter(formula.GetNpar()))
325  required.insert(formula.GetParName(iPar));
326 
327  std::set<std::string> excess;
328  std::set_difference(
329  offered.cbegin(), offered.cend(), required.cbegin(), required.cend(),
330  std::inserter(excess, excess.begin())
331  );
332  if (excess.empty()) return {}; // success
333 
334  std::string msg
335  { "\n * " + std::to_string(excess.size()) + " unused parameters:" };
336  for (auto const& name: excess) msg += "\n - '" + name + "'";
337 
338  return msg;
339 
340 } // icarus::opdet::CustomPulseFunction<>::checkExcessParameters()
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
std::string to_string(WindowPattern const &pattern)
then echo fcl name
template<typename T >
std::string icarus::opdet::CustomPulseFunction< T >::checkMissingParameters ( TFormula const &  formula,
PulseParameters_t const &  parameters 
)
staticprivate

Returns a message about parameters in formula missing in parameters.

Returns
a message about missing parameters, empty if none

Definition at line 290 of file CustomPulseFunction.h.

291 {
292  std::set<std::string> required;
293  for (auto const iPar: util::counter(formula.GetNpar()))
294  required.insert(formula.GetParName(iPar));
295  std::set<std::string> offered;
296  for (auto const& nameAndValue: parameters)
297  offered.insert(nameAndValue.first);
298 
299  std::set<std::string> missing;
300  std::set_difference(
301  required.cbegin(), required.cend(), offered.cbegin(), offered.cend(),
302  std::inserter(missing, missing.begin())
303  );
304  if (missing.empty()) return {}; // success
305 
306  std::string msg
307  { "\n * " + std::to_string(missing.size()) + " parameters missing:" };
308  for (auto const& name: missing) msg += "\n - '" + name + "'";
309 
310  return msg;
311 
312 } // icarus::opdet::CustomPulseFunction<>::checkMissingParameters()
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
std::string to_string(WindowPattern const &pattern)
then echo fcl name
template<typename T >
void icarus::opdet::CustomPulseFunction< 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 266 of file CustomPulseFunction.h.

270 {
271  out
272  << firstIndent << "Custom pulse shape: " << fFormula.GetTitle()
273  << "\n" << indent << " peak " << fStats.peakAmplitude
274  << " at " << fStats.peakTime
275  ;
276  if (fFormula.GetNpar() > 0) {
277  out << "\n" << indent << "Parameters (" << fFormula.GetNpar() << "):";
278  for (auto const iPar: util::counter(fFormula.GetNpar())) {
279  out << "\n" << indent << " [" << fFormula.GetParName(iPar) << "] = "
280  << fFormula.GetParameter(iPar);
281  } // for
282  } // if parameters
283  out << '\n';
284 } // icarus::opdet::CustomPulseFunction<>::doDump()
TFormula fFormula
Formula of the shape.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
ADCcount peakAmplitude
Pulse amplitude at peak time.
PulseStats_t fStats
Collected information about the pulse.
template<typename T >
virtual ADCcount icarus::opdet::CustomPulseFunction< T >::doEvaluateAt ( Time  time) const
inlineoverrideprivatevirtual

Evaluates the pulse at the given time.

Parameters
timetime to evaluate the shape at

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

Definition at line 149 of file CustomPulseFunction.h.

150  { return ADCcount::castFrom(fFormula.Eval(static_cast<double>(time))); }
TFormula fFormula
Formula of the shape.
template<typename T >
virtual ADCcount icarus::opdet::CustomPulseFunction< T >::doPeakAmplitude ( ) const
inlineoverrideprivatevirtual

Returns the amplitude of the first peak in ADC counts.

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

Definition at line 156 of file CustomPulseFunction.h.

157  { return fStats.peakAmplitude; }
ADCcount peakAmplitude
Pulse amplitude at peak time.
PulseStats_t fStats
Collected information about the pulse.
template<typename T >
virtual Time icarus::opdet::CustomPulseFunction< T >::doPeakTime ( ) const
inlineoverrideprivatevirtual

Returns the time at which the first peak is found.

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

Definition at line 153 of file CustomPulseFunction.h.

153 { return fStats.peakTime; }
PulseStats_t fStats
Collected information about the pulse.
template<typename T >
auto icarus::opdet::CustomPulseFunction< T >::extractStats ( Time  peakTime) const
private

Extracts statistics from pulse shape.

Definition at line 252 of file CustomPulseFunction.h.

253 {
254  PulseStats_t stats;
255 
256  stats.peakTime = peakTime;
257  stats.peakAmplitude = (*this)(peakTime);
258  stats.negativePulse = stats.peakAmplitude < ADCcount{ 0 };
259 
260  return stats;
261 } // icarus::opdet::CustomPulseFunction<>::extractStats()
Time peakTime() const
Returns the time at which the first peak is found.
typename Base_t::ADCcount ADCcount
Type for ADC counts (floating point).
template<typename T >
ParameterValue_t icarus::opdet::CustomPulseFunction< T >::parameter ( std::string const &  name) const

Returns the value of the parameter specified by name.

template<typename T >
void icarus::opdet::CustomPulseFunction< T >::setParameters ( TFormula &  formula,
PulseParameters_t const &  parameters 
)
staticprivate

Sets the value of the parameters of formula.

Definition at line 346 of file CustomPulseFunction.h.

347 {
348  for (auto const& [ name, value ]: parameters) {
349  auto const iPar = formula.GetParNumber(name.c_str());
350  if (iPar < 0) continue;
351  formula.SetParameter(iPar, value);
352  } // for
353 } // icarus::opdet::CustomPulseFunction<>::setParameters()
then echo fcl name
temporary value

Member Data Documentation

template<typename T >
TFormula icarus::opdet::CustomPulseFunction< T >::fFormula
private

Formula of the shape.

Definition at line 129 of file CustomPulseFunction.h.

template<typename T >
PulseStats_t icarus::opdet::CustomPulseFunction< T >::fStats
private

Collected information about the pulse.

Definition at line 131 of file CustomPulseFunction.h.


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