All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PhotoelectronPulseFunction.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Algorithms/PhotoelectronPulseFunction.h
3  * @brief Abstract interface of shape of a pulse from one photoelectron.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date March 4, 2020
6  *
7  * This is a header only library.
8  */
9 
10 #ifndef ICARUSCODE_PMT_ALGORITHMS_PHOTOELECTRONPULSEFUNCTION_H
11 #define ICARUSCODE_PMT_ALGORITHMS_PHOTOELECTRONPULSEFUNCTION_H
12 
13 
14 // LArSoft libraries
16 
17 // C++ standard library
18 #include <iosfwd> // std::ostream
19 #include <string>
20 #include <utility> // std::move()
21 #include <sstream>
22 
23 // -----------------------------------------------------------------------------
24 namespace icarus::opdet {
25 
26  template <typename T> class PhotoelectronPulseFunction;
27  template <typename Stream, typename T>
28  Stream& operator<< (Stream&& out, PhotoelectronPulseFunction<T> const& pulse);
29 
30 } // namespace icarus::opdet
31 
32 // -----------------------------------------------------------------------------
33 /**
34  * @brief Interface for a function describing a pulse from a photoelectron.
35  * @tparam T type used to represent time
36  *
37  * A function implementing this interface expresses a sampled value in ADC
38  * counts (`ADCcount` type) as function of time (`Time` type).
39  *
40  * The time types in LArSoft quantities library can be used as `Time` (`T`):
41  * e.g., `PhotoelectronPulseFunction<util::quantities::nanosecond>`.
42  *
43  */
44 template <typename T>
46 
47  public:
48  /// Type for ADC counts (floating point).
50 
51  using Time = T; ///< Type of time being used.
52 
53 
54  virtual ~PhotoelectronPulseFunction() = default;
55 
56  /**
57  * @brief Evaluates the pulse at the given time.
58  * @param time time to evaluate the shape at
59  * @return value of the pulse at the specified time
60  */
61  ADCcount evaluateAt(Time time) const { return doEvaluateAt(time); }
62 
63  /// Alias of `evaluateAt()`.
64  ADCcount operator() (Time time) const { return evaluateAt(time); }
65 
66  /// Returns the time at which the first peak is found.
67  Time peakTime() const { return doPeakTime(); }
68 
69  /// Returns the amplitude of the first peak in ADC counts.
70  ADCcount peakAmplitude() const { return doPeakAmplitude(); }
71 
72  /// Returns the baseline of the pulse in ADC counts.
73  ADCcount baseline() const { return doBaseline(); }
74 
75  /// Returns the polarity of the pulse (`+1`: positive, or `-1`: negative).
76  int polarity() const { return doPolarity(); }
77 
78 
79  // @{
80  /**
81  * @brief Prints on stream the parameters of this shape.
82  * @param out the stream to write into
83  * @param indent indentation string, prepended to all lines except first
84  * @param indentFirst indentation string prepended to the first line
85  */
86  void dump(
87  std::ostream& out,
88  std::string const& indent, std::string const& firstIndent
89  ) const
90  { doDump(out, indent, firstIndent); }
91  void dump(std::ostream&& out, std::string const& indent = "") const
92  { dump(out, indent, indent); }
93  // @}
94 
95 
96  // @{
97  /**
98  * @brief Returns the parameters of this shape as a descriptive string.
99  * @param indent indentation string, prepended to all lines except first
100  * @param indentFirst indentation string prepended to the first line
101  * @return a string with the parameters of this shape
102  */
103  std::string toString
104  (std::string const& indent, std::string const& firstIndent) const;
105  std::string toString(std::string const& indent = "") const
106  { return toString(indent, indent); }
107  // @}
108 
109 
110  protected:
111 
112  // --- BEGIN -- Mandatory customization --------------------------------------
113  /// @name Mandatory customization
114  /// @{
115 
116  /// Implementation of the function evaluation at `time`.
117  virtual ADCcount doEvaluateAt(Time time) const = 0;
118 
119  /// Returns the time at which the first peak is found.
120  virtual Time doPeakTime() const = 0;
121 
122  /// @}
123  // --- END -- Mandatory customization ----------------------------------------
124 
125 
126  // --- BEGIN -- Optional customization ---------------------------------------
127  /// @name Optional customization
128  /// @{
129 
130  /// Returns the amplitude of the first peak in ADC counts.
131  virtual ADCcount doPeakAmplitude() const { return evaluateAt(peakTime()); }
132 
133  /// Returns the baseline of the pulse.
134  virtual ADCcount doBaseline() const { return ADCcount{ 0 }; }
135 
136  /// Returns the polarity of the pulse (+1 or -1).
137  virtual int doPolarity() const
138  { return ((peakAmplitude() - baseline()) >= ADCcount{ 0 })? +1: -1; }
139 
140 
141  /**
142  * @brief Prints into the stream the parameters of this shape.
143  * @param out the C++ output stream to write into
144  * @param indent indentation string, prepended to all lines except first
145  * @param indentFirst indentation string prepended to the first line
146  */
147  virtual void doDump(
148  std::ostream& out,
149  std::string const& indent, std::string const& firstIndent
150  ) const {}
151 
152  /// @}
153  // --- END -- Optional customization -----------------------------------------
154 
155 
156 }; // class icarus::opdet::PhotoelectronPulseFunction<>
157 
158 
159 // -----------------------------------------------------------------------------
160 // --- template implementation
161 // -----------------------------------------------------------------------------
162 template <typename T>
164  (std::string const& indent, std::string const& firstIndent) const
165 {
166  std::ostringstream sstr;
167  dump(sstr, indent, firstIndent);
168  return std::move(sstr).str();
169 } // icarus::opdet::PhotoelectronPulseFunction<>::toString()
170 
171 
172 // -----------------------------------------------------------------------------
173 template <typename Stream, typename T>
174 Stream& icarus::opdet::operator<<
176  { out << pulse.toString(); return out; }
177 
178 
179 // -----------------------------------------------------------------------------
180 
181 #endif // ICARUSCODE_PMT_ALGORITHMS_PHOTOELECTRONPULSEFUNCTION_H
virtual ADCcount doEvaluateAt(Time time) const =0
Implementation of the function evaluation at time.
virtual int doPolarity() const
Returns the polarity of the pulse (+1 or -1).
ADCcount baseline() const
Returns the baseline of the pulse in ADC counts.
virtual ADCcount doPeakAmplitude() const
Returns the amplitude of the first peak in ADC counts.
A value measured in the specified unit.
Definition: quantities.h:566
Time peakTime() const
Returns the time at which the first peak is found.
Interface for a function describing a pulse from a photoelectron.
ADCcount evaluateAt(Time time) const
Evaluates the pulse at the given time.
virtual void doDump(std::ostream &out, std::string const &indent, std::string const &firstIndent) const
Prints into the stream the parameters of this shape.
Dimensioned variables related to electronics.
void dump(std::ostream &out, std::string const &indent, std::string const &firstIndent) const
Prints on stream the parameters of this shape.
ADCcount operator()(Time time) const
Alias of evaluateAt().
std::string toString(std::string const &indent, std::string const &firstIndent) const
Returns the parameters of this shape as a descriptive string.
virtual Time doPeakTime() const =0
Returns the time at which the first peak is found.
std::string toString(std::string const &indent="") const
ADCcount peakAmplitude() const
Returns the amplitude of the first peak in ADC counts.
counts_as< float > counts_f
Number of ADC counts, represented by float.
Definition: electronics.h:119
util::quantities::counts_f ADCcount
Type for ADC counts (floating point).
bnb BNB Stream
void dump(std::ostream &&out, std::string const &indent="") const
int polarity() const
Returns the polarity of the pulse (+1: positive, or -1: negative).
virtual ADCcount doBaseline() const
Returns the baseline of the pulse.