All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AsymGaussPulseFunction.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Algorithms/AsymGaussPulseFunction.h
3  * @brief Pulse from one photoelectron as two half Gaussian functions.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date March 4, 2020
6  *
7  * This library is header only.
8  *
9  */
10 
11 #ifndef ICARUSCODE_PMT_ALGORITHMS_ASYMGAUSSPULSEFUNCTION_H
12 #define ICARUSCODE_PMT_ALGORITHMS_ASYMGAUSSPULSEFUNCTION_H
13 
14 // library header
16 
17 // LArSoft libraries
19 
20 // C++ standard library
21 #include <ostream> // std::ostream
22 #include <string>
23 #include <utility> // std::forward()
24 #include <cmath> // std::exp()
25 
26 
27 // -----------------------------------------------------------------------------
28 namespace icarus::opdet {
29  template <typename T> class AsymGaussPulseFunction;
30 }
31 
32 // -----------------------------------------------------------------------------
33 /**
34  * @brief Describes the waveform from a single photoelectron.
35  * @tparam Time type of time unit to be used
36  *
37  * This functor (class behaving like a function) describes the shape of the
38  * response to a single photoelectron as an asymmetric Gaussian shape.
39  */
40 template <typename T>
43 {
45 
46  public:
47  /// Type for ADC counts (floating point).
48  using ADCcount = typename Base_t::ADCcount;
49 
50  using Time = typename Base_t::Time; ///< Type of time being used.
51 
52  /**
53  * @brief Constructor: assigns the parameters of the shape.
54  * @param amplitude the maximum amplitudes of the shape (at transition)
55  * @param peakTime the time of the maximum amplitude of the shape
56  * @param sigmaLeft the standard deviation of the shape before transition
57  * @param sigmaRight the standard deviation of the shape after transition
58  *
59  * The time parameters (`peakTime`, `sigmaLeft` and `sigmaRight`) must be
60  * measured in same unit. The `peakTime` defines the position of the shape
61  * with respect to time 0.
62  *
63  */
66  Time peakTime,
67  Time sigmaLeft,
68  Time sigmaRight
69  )
70  : fAmplitude(amplitude)
71  , fTransitTime(peakTime)
72  , fSigmaL(sigmaLeft)
73  , fSigmaR(sigmaRight)
74  {}
75 
76  /// @{
77  /// @name Parameter accessors.
78 
79 // Time peakTime() const { return fTransitTime; } // inherited
80  Time leftSigma() const { return fSigmaL; }
81  Time rightSigma() const { return fSigmaR; }
82  ADCcount amplitude() const { return fAmplitude; }
83 
84  /// @}
85 
86  /// Returns the value of normal distribution at specified point.
88  { return amplitude * std::exp(-sqr((x - mean)/sigma)/2.0); }
89 
90  private:
91  ADCcount fAmplitude; ///< Amplitude at peak (transition).
92  Time fTransitTime; ///< Time of transition between the two forms of shape.
93  Time fSigmaL; ///< RMS parameter of the shape before transition.
94  Time fSigmaR; ///< RMS parameter of the shape after transition.
95 
96  /// Returns the time of the center of the Gaussian.
97  Time myPeakTime() const { return fTransitTime; }
98 
99  /// Returns the amplitude of the pulse from the baseline, including its sign.
100  ADCcount myAmplitude() const { return fAmplitude; }
101 
102 
103  // --- BEGIN -- Interface implementation -------------------------------------
104  /**
105  * @brief Evaluates the pulse at the given time.
106  * @param time time to evaluate the shape at
107  *
108  * The scale of the time is defined by the transition time passed
109  * at construction.
110  */
111  virtual ADCcount doEvaluateAt(Time time) const override;
112 
113  /// Returns the time at which the first peak is found.
114  virtual Time doPeakTime() const override { return myPeakTime(); }
115 
116  /// Returns the amplitude of the first peak in ADC counts.
117  virtual ADCcount doPeakAmplitude() const override { return myAmplitude(); }
118 
119  /**
120  * @brief Prints on stream the parameters of this shape.
121  * @param out the stream to write into
122  * @param indent indentation string, prepended to all lines except first
123  * @param indentFirst indentation string prepended to the first line
124  */
125  virtual void doDump(
126  std::ostream& out,
127  std::string const& indent, std::string const& firstIndent
128  ) const override;
129 
130  // --- END -- Interface implementation -------------------------------------
131 
132  template <typename V>
133  static V sqr(V value) { return value * value; }
134 
135  template <typename V>
136  static V round(V value)
137  {
138  using namespace util::quantities::electronics_literals;
139  return (value.abs() < 1e-6_ADCf)? 0.0_ADCf: value;
140  }
141 
142 
143 }; // class icarus::opdet::AsymGaussPulseFunction<>
144 
145 
146 // -----------------------------------------------------------------------------
147 // --- template implementation
148 // -----------------------------------------------------------------------------
149 template <typename T>
151  -> ADCcount
152 {
153  return round(Gaussian(
154  time,
155  myPeakTime(),
156  ((time < myPeakTime())? leftSigma(): rightSigma()),
157  amplitude()
158  ));
159 } // icarus::opdet::AsymGaussPulseFunction<T>::doEvaluateAt()
160 
161 
162 // -----------------------------------------------------------------------------
163 template <typename T>
165  std::ostream& out,
166  std::string const& indent, std::string const& firstIndent
167  ) const
168 {
169  out
170  << firstIndent << "Pulse shape: asymmetric Gaussian with peak at "
171  << myPeakTime() << " and amplitude " << amplitude() << ":"
172  << '\n' << indent
173  << " (t < " << myPeakTime() << "): sigma " << leftSigma()
174  << '\n' << indent
175  << " (t >= " << myPeakTime() << "): sigma " << rightSigma()
176  << '\n';
177 } // icarus::opdet::AsymGaussPulseFunction<>::doDump()
178 
179 
180 // -----------------------------------------------------------------------------
181 
182 #endif // ICARUSCODE_PMT_ALGORITHMS_ASYMGAUSSPULSEFUNCTION_H
Time fSigmaR
RMS parameter of the shape after transition.
virtual Time doPeakTime() const override
Returns the time at which the first peak is found.
process_name opflash particleana ie x
virtual ADCcount doEvaluateAt(Time time) const override
Evaluates the pulse at the given time.
typename Base_t::ADCcount ADCcount
Type for ADC counts (floating point).
ADCcount myAmplitude() const
Returns the amplitude of the pulse from the baseline, including its sign.
static ADCcount Gaussian(Time x, Time mean, Time sigma, ADCcount amplitude)
Returns the value of normal distribution at specified point.
Abstract interface of shape of a pulse from one photoelectron.
BEGIN_PROLOG V
Time myPeakTime() const
Returns the time of the center of the Gaussian.
virtual void doDump(std::ostream &out, std::string const &indent, std::string const &firstIndent) const override
Prints on stream the parameters of this shape.
typename Base_t::Time Time
Type of time being used.
Time peakTime() const
Returns the time at which the first peak is found.
virtual ADCcount doPeakAmplitude() const override
Returns the amplitude of the first peak in ADC counts.
Time fTransitTime
Time of transition between the two forms of shape.
Interface for a function describing a pulse from a photoelectron.
Time fSigmaL
RMS parameter of the shape before transition.
Dimensioned variables related to electronics.
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
ADCcount fAmplitude
Amplitude at peak (transition).
do i e
temporary value
AsymGaussPulseFunction(ADCcount amplitude, Time peakTime, Time sigmaLeft, Time sigmaRight)
Constructor: assigns the parameters of the shape.
util::quantities::counts_f ADCcount
Type for ADC counts (floating point).
Describes the waveform from a single photoelectron.