All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PedAlgoFixed.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/OpReco/Algorithms/PedAlgoFixed.h
3  * @brief Pedestal "algorithm" reading the pedestals from somewhere else.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date May 7, 2022
6  *
7  * @ingroup PulseReco
8  */
9 
10 #ifndef ICARUSCODE_PMT_OPRECO_ALGORITHMS_PEDALGOFIXED_H
11 #define ICARUSCODE_PMT_OPRECO_ALGORITHMS_PEDALGOFIXED_H
12 
13 /// LArSoft libraries
16 
17 // framework libraries
18 #ifndef ICARUS_NO_CONFIGURATION_VALIDATION
19 # include "fhiclcpp/types/Table.h"
20 # include "fhiclcpp/types/OptionalAtom.h"
21 # include "fhiclcpp/types/Atom.h"
22 #endif // ICARUS_NO_CONFIGURATION_VALIDATION
23 
24 /// C/C++ standard libraries
25 #include <string>
26 #include <vector>
27 #include <utility> // std::pair
28 #include <limits> // std::numeric_limits<>
29 
30 
31 // -----------------------------------------------------------------------------
32 namespace pmtana { class PedAlgoFixed; }
33 #ifdef ICARUS_NO_CONFIGURATION_VALIDATION
34 namespace fhicl { class ParameterSet; }
35 #else // ICARUS_NO_CONFIGURATION_VALIDATION
36 
37 #endif // ICARUS_NO_CONFIGURATION_VALIDATION
38 /**
39  * @class pmtana::PedAlgoFixed
40  * @brief Pedestal "algorithm" reading the pedestals from somewhere else.
41  * @addtogroup PulseReco
42  *
43  * This is a big hack.
44  *
45  * The optical reconstruction mini-framework passes to the pedestal algorithm
46  * only a pointer to the waveform samples, with no context at all.
47  * In this algorithm we need to figure out that context. We take the pointer of
48  * every single possible input, because we need to know the index of the
49  * waveform, which is required to match the index in the pedestal and RMS lists.
50  * We can't even just take the address of the first waveform, because we don't
51  * know the _actual_ type of the vector the waveform belongs too (in LArSoft,
52  * that is `raw::OpDetWaveform`, which has different size and therefore pointer
53  * math than the vector of samples it derives from).
54  *
55  *
56  * Multithreading note
57  * --------------------
58  *
59  * This class is not multithread-ready. To process multiple events, the input
60  * sets should be placed into a container with controlled access (one writes,
61  * many read).
62  *
63  */
65 
66  public:
67 
68  /// Input information.
69  struct InputSet_t {
70  /// An unique identifier for this input set.
71  unsigned int inputID = std::numeric_limits<unsigned int>::max();
72  /// All the waveforms that are going to process.
73  std::vector<pmtana::Waveform_t const*> waveforms;
74  std::vector<float> pedestals; ///< In ADC counts by waveform.
75  std::vector<float> RMSs; ///< In ADC counts by waveform.
76  /// Returns the number of elements in the input.
77  std::size_t size() const noexcept { return waveforms.size(); }
78  }; // InputSet_t
79 
80 #ifndef ICARUS_NO_CONFIGURATION_VALIDATION
81  struct Config {
82  fhicl::Atom<std::string> Name {
83  fhicl::Name{ "Name" },
84  fhicl::Comment
85  { "Name of this algorithm [mandatory in the ophit miniframework]" },
86  "Fixed" // default
87  };
88  fhicl::Atom<std::string> WaveformTag {
89  fhicl::Name{ "WaveformTag" },
90  fhicl::Comment{ "Tag of the data product with input waveforms." }
91  };
92  fhicl::Atom<std::string> PedestalTag {
93  fhicl::Name{ "PedestalTag" },
94  fhicl::Comment{ "Tag of the data product with input pedestal levels." }
95  };
96  fhicl::OptionalAtom<std::string> RMSTag {
97  fhicl::Name{ "RMSTag" },
98  fhicl::Comment{
99  "Tag of the data product with input pedestal RMS [default: like "
100  + PedestalTag.name() + "]."
101  }
102  };
103  }; // Config
104 
105  using Parameters = fhicl::Table<Config>;
106 
107  PedAlgoFixed(Parameters const& params, std::string const& name = "PedFixed");
108 
109 #else // !ICARUS_NO_CONFIGURATION_VALIDATION
110  /// Constructor from FHiCL configuration and optional class name
112  (fhicl::ParameterSet const& pset, std::string const& name = "PedFixed");
113 #endif // ICARUS_NO_CONFIGURATION_VALIDATION
114 
115  /// Returns the name of the configured waveform source.
116  std::string const& waveformSourceName() const { return fWaveformTag; }
117 
118  /// Returns the name of the configured pedestal source.
119  std::string const& pedestalSourceName() const { return fPedestalTag; }
120 
121  /// Returns the name of the configured RMS source.
122  std::string const& pedestalRMSName() const { return fRMSTag; }
123 
124  // --- BEGIN -- Class-specific interface: setup ------------------------------
125 
126  /// Records the current pedestals and RMS per channel.
127  void setParameters(InputSet_t inputSet);
128 
129  /// Removes the pedestal and RMS records.
130  void clearParameters();
131 
132  // --- END ---- Class-specific interface: setup ------------------------------
133 
134  protected:
135 
136  // --- BEGIN -- Configuration ------------------------------------------------
137  std::string fWaveformTag; ///< Name of the data source for waveforms.
138  std::string fPedestalTag; ///< Name of the data source for pedestals.
139  std::string fRMSTag; ///< Name of the data source for RMS.
140  // --- END ---- Configuration ------------------------------------------------
141 
142  InputSet_t fInput; ///< The set of input waveforms currently registered.
143 
144  /**
145  * @brief Computes the pedestal of the specified `waveform`.
146  * @param[in] waveform the waveform to be processed
147  * @param[out] mean_v the mean value of the pedestal, tick by tick
148  * @param[out] sigma_v the RMS of the pedestal, tick by tick
149  * @return whether the pedestal was successfully found
150  *
151  * The algorithm is quite simple, since it picks the baseline that was
152  * provided in the configuration.
153  */
154  virtual bool ComputePedestal(
155  pmtana::Waveform_t const& waveform,
156  pmtana::PedestalMean_t& mean_v,
157  pmtana::PedestalSigma_t& sigma_v
158  ) override;
159 
160  /// Returns the input set and index of the specified `waveform`.
161  std::pair<InputSet_t const*, std::size_t> findWaveform
162  (pmtana::Waveform_t const& waveform) const;
163 
164 }; // pmtana::PedAlgoFixed
165 
166 // -----------------------------------------------------------------------------
167 
168 #endif // ICARUSCODE_PMT_OPRECO_ALGORITHMS_PEDALGOFIXED_H
std::size_t size() const noexcept
Returns the number of elements in the input.
Definition: PedAlgoFixed.h:77
void setParameters(InputSet_t inputSet)
Records the current pedestals and RMS per channel.
std::vector< double > PedestalSigma_t
std::vector< float > RMSs
Definition: PedAlgoFixed.h:75
std::string fPedestalTag
Name of the data source for pedestals.
Definition: PedAlgoFixed.h:138
Pedestal &quot;algorithm&quot; reading the pedestals from somewhere else.
Definition: PedAlgoFixed.h:64
void clearParameters()
Removes the pedestal and RMS records.
fhicl::Table< Config > Parameters
Definition: PedAlgoFixed.h:105
std::pair< InputSet_t const *, std::size_t > findWaveform(pmtana::Waveform_t const &waveform) const
Returns the input set and index of the specified waveform.
Class definition file of PMTPedestalBase.
std::vector< float > pedestals
In ADC counts by waveform.
Definition: PedAlgoFixed.h:74
fhicl::Atom< std::string > WaveformTag
Definition: PedAlgoFixed.h:88
std::vector< pmtana::Waveform_t const * > waveforms
All the waveforms that are going to process.
Definition: PedAlgoFixed.h:73
fhicl::OptionalAtom< std::string > RMSTag
Definition: PedAlgoFixed.h:96
fhicl::Atom< std::string > Name
Definition: PedAlgoFixed.h:82
virtual bool ComputePedestal(pmtana::Waveform_t const &waveform, pmtana::PedestalMean_t &mean_v, pmtana::PedestalSigma_t &sigma_v) override
Computes the pedestal of the specified waveform.
std::vector< short > Waveform_t
BEGIN_PROLOG vertical distance to the surface Name
std::string const & pedestalSourceName() const
Returns the name of the configured pedestal source.
Definition: PedAlgoFixed.h:119
std::string const & waveformSourceName() const
Returns the name of the configured waveform source.
Definition: PedAlgoFixed.h:116
unsigned int inputID
An unique identifier for this input set.
Definition: PedAlgoFixed.h:71
fhicl::Atom< std::string > PedestalTag
Definition: PedAlgoFixed.h:92
std::string fRMSTag
Name of the data source for RMS.
Definition: PedAlgoFixed.h:139
PedAlgoFixed(Parameters const &params, std::string const &name="PedFixed")
then echo fcl name
std::string const & pedestalRMSName() const
Returns the name of the configured RMS source.
Definition: PedAlgoFixed.h:122
std::vector< double > PedestalMean_t
InputSet_t fInput
The set of input waveforms currently registered.
Definition: PedAlgoFixed.h:142
std::string fWaveformTag
Name of the data source for waveforms.
Definition: PedAlgoFixed.h:137