All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PedAlgoFixed.cxx
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/OpReco/Algorithms/PedAlgoFixed.cxx
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 // ICARUS libraries
12 
13 // framework libraries
14 #ifndef ICARUS_NO_CONFIGURATION_VALIDATION
15 # include "fhiclcpp/ParameterSet.h"
16 #endif // ICARUS_NO_CONFIGURATION_VALIDATION
17 
18 // C/C++ standard libraries
19 #include <algorithm> // std::fill(), std::find()
20 #include <iterator> // std::distance()
21 #include <stdexcept> // std::runtime_error
22 #include <limits> // std::numeric_limits<>
23 #include <cstdint> // std::ptrdiff_t
24 
25 
26 // -----------------------------------------------------------------------------
27 #ifndef ICARUS_NO_CONFIGURATION_VALIDATION
29  (Parameters const& params, std::string const& name /* = "PedFixed" */)
31  , fWaveformTag{ params().WaveformTag() }
32  , fPedestalTag{ params().PedestalTag() }
33  , fRMSTag{ params().RMSTag().value_or(fPedestalTag) }
34  {}
35 
36 #else // ICARUS_NO_CONFIGURATION_VALIDATION
38  fhicl::ParameterSet const& pset,
39  std::string const& name /* = "PedFixed" */
40 )
41  : pmtana::PMTPedestalBase(name)
42  , fWaveformTag{ pset.get<std::string>("WaveformTag") }
43  , fPedestalTag{ pset.get<std::string>("PedestalTag") }
44  , fRMSTag{ pset.get<std::string>("RMSTag", fPedestalTag) }
45  {}
46 
47 #endif // ICARUS_NO_CONFIGURATION_VALIDATION
48 
49 // -----------------------------------------------------------------------------
51  if (
52  (inputSet.pedestals.size() != inputSet.waveforms.size())
53  || (inputSet.RMSs.size() != inputSet.waveforms.size())
54  ) {
55  throw std::runtime_error{
56  "pmtana::PedAlgoFixed::setParameters(): inconsistent sizes of input: "
57  + std::to_string(inputSet.waveforms.size()) + " waveforms, "
58  + std::to_string(inputSet.pedestals.size()) + " pedestals, "
59  + std::to_string(inputSet.RMSs.size()) + " RMS.\n"
60  };
61  }
62 
63  fInput = std::move(inputSet);
64 
65 } // pmtana::PedAlgoFixed::setParameters()
66 
67 
68 // -----------------------------------------------------------------------------
70  fInput = {};
71 } // pmtana::PedAlgoFixed::clearParameters()
72 
73 
74 // -----------------------------------------------------------------------------
76  const pmtana::Waveform_t& wf,
77  pmtana::PedestalMean_t& mean_v,
79 ) {
80 
81  auto const [ inputSet, waveformIndex ] = findWaveform(wf);
82  if (!inputSet) {
83  // this means that this work is hopeless
84  throw std::logic_error{
85  "pmtana::PedAlgoFixed::ComputePedestal(): input waveform (address="
86  + std::to_string(reinterpret_cast<std::intptr_t>(&wf))
87  + ") not registered in any input (ID: "
89  };
90  }
91 
92  std::size_t const nSamples = inputSet->waveforms[waveformIndex]->size();
93 
94  mean_v.resize(nSamples);
95  std::fill(mean_v.begin(), mean_v.end(), inputSet->pedestals[waveformIndex]);
96 
97  sigma_v.resize(nSamples);
98  std::fill(sigma_v.begin(), sigma_v.end(), inputSet->RMSs[waveformIndex]);
99 
100  return true;
101 
102 } // pmtana::PedAlgoFixed::ComputePedestal()
103 
104 
105 // -----------------------------------------------------------------------------
107  (pmtana::Waveform_t const& waveform) const
108  -> std::pair<InputSet_t const*, std::size_t>
109 {
110  InputSet_t const* inputSet = &fInput;
111  auto const wbegin = inputSet->waveforms.begin();
112  auto const wend = inputSet->waveforms.end();
113  if (auto it = std::find(wbegin, wend, &waveform); it == wend)
114  return { nullptr, std::numeric_limits<std::size_t>::max() };
115  else
116  return { inputSet, std::distance(wbegin, it) };
117 
118 } // pmtana::PedAlgoFixed::findWaveform()
119 
120 
121 // -----------------------------------------------------------------------------
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
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.
Pedestal &quot;algorithm&quot; reading the pedestals from somewhere else.
std::vector< float > pedestals
In ADC counts by waveform.
Definition: PedAlgoFixed.h:74
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
std::vector< pmtana::Waveform_t const * > waveforms
All the waveforms that are going to process.
Definition: PedAlgoFixed.h:73
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
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
unsigned int inputID
An unique identifier for this input set.
Definition: PedAlgoFixed.h:71
std::string to_string(WindowPattern const &pattern)
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::vector< double > PedestalMean_t
InputSet_t fInput
The set of input waveforms currently registered.
Definition: PedAlgoFixed.h:142