LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PMTPulseRecoBase.cxx
Go to the documentation of this file.
1 //
3 // PMTPulseRecoBase source
4 //
6 
7 #include "PMTPulseRecoBase.h"
8 
9 #include <iostream>
10 #include <numeric>
11 
12 namespace pmtana {
13 
14  //*************************************************************************
15  PMTPulseRecoBase::PMTPulseRecoBase(const std::string name) : _name(name), _status(true)
16  //*************************************************************************
17  {
18  Reset();
19  }
20 
21  //***********************************************
22  const std::string& PMTPulseRecoBase::Name() const
23  //***********************************************
24  {
25  return _name;
26  }
27 
28  //*****************************************
30  //*****************************************
31  {
32  return _status;
33  }
34 
35  //******************************************************************
37  const PedestalMean_t& mean_v,
38  const PedestalSigma_t& sigma_v)
39  //******************************************************************
40  {
41  _status = this->RecoPulse(wf, mean_v, sigma_v);
42  return _status;
43  }
44 
45  //*****************************************************************************
46  bool CheckIndex(const std::vector<short>& wf, const size_t& begin, size_t& end)
47  //*****************************************************************************
48  {
49  if (begin >= wf.size() || end >= wf.size() || begin > end) {
50 
51  std::cerr << "Invalid arguments: waveform length = " << wf.size() << " begin = " << begin
52  << " end = " << end << std::endl;
53 
54  return false;
55  }
56 
57  if (!end) end = wf.size() - 1;
58 
59  return true;
60  }
61 
62  //***************************************************************
64  //***************************************************************
65  {
67 
68  _pulse_v.clear();
69 
70  _pulse_v.reserve(3);
71  }
72 
73  //***************************************************************
74  const pulse_param& PMTPulseRecoBase::GetPulse(size_t index) const
75  //***************************************************************
76  {
77 
78  if (index >= _pulse_v.size()) {
79 
80  std::cerr << "\033[93m"
81  << "Invalid pulse index: " << index << "\033[00m" << std::endl;
82 
83  throw std::exception();
84  }
85 
86  else
87  return _pulse_v.at(index);
88  }
89 
90  //***************************************************************
92  //***************************************************************
93  {
94  return _pulse_v;
95  }
96 
97  //***************************************************************
98  bool PMTPulseRecoBase::Integral(const std::vector<short>& wf,
99  double& result,
100  size_t begin,
101  size_t end) const
102  //***************************************************************
103  {
104 
105  if (!CheckIndex(wf, begin, end)) return false;
106 
107  std::vector<short>::const_iterator begin_iter(wf.begin());
108 
109  std::vector<short>::const_iterator end_iter(wf.begin());
110 
111  begin_iter = begin_iter + begin;
112 
113  end_iter = end_iter + end + 1;
114 
115  result = (double)(std::accumulate(begin_iter, end_iter, 0));
116 
117  return true;
118  }
119 
120  //***************************************************************
121  bool PMTPulseRecoBase::Derivative(const std::vector<short>& wf,
122  std::vector<int32_t>& diff,
123  size_t begin,
124  size_t end) const
125  //***************************************************************
126  {
127 
128  if (CheckIndex(wf, begin, end)) {
129 
130  diff.clear();
131  diff.reserve(end - begin);
132 
133  for (size_t index = begin; index <= end; ++index)
134 
135  diff.push_back(wf.at(index + 1) - wf.at(index));
136 
137  return true;
138  }
139 
140  return false;
141  }
142 
143  //***************************************************************
144  size_t PMTPulseRecoBase::Max(const std::vector<short>& wf,
145  double& result,
146  size_t begin,
147  size_t end) const
148  //***************************************************************
149  {
150 
151  size_t target_index = wf.size() + 1;
152 
153  result = 0;
154 
155  if (CheckIndex(wf, begin, end)) {
156 
157  for (size_t index = begin; index <= end; ++index)
158 
159  if (result < wf.at(index)) {
160  target_index = index;
161  result = (double)(wf.at(index));
162  }
163  }
164 
165  return target_index;
166  }
167 
168  //***************************************************************
169  size_t PMTPulseRecoBase::Min(const std::vector<short>& wf,
170  double& result,
171  size_t begin,
172  size_t end) const
173  //***************************************************************
174  {
175 
176  size_t target_index = wf.size() + 1;
177 
178  result = 4096;
179 
180  if (CheckIndex(wf, begin, end)) {
181 
182  for (size_t index = begin; index <= end; ++index)
183 
184  if (result > wf.at(index)) {
185  target_index = index;
186  result = (double)(wf.at(index));
187  }
188  }
189 
190  return target_index;
191  }
192 }
bool _status
Status after pulse reconstruction.
bool Integral(const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
bool Status() const
Status getter.
std::vector< double > PedestalSigma_t
virtual void Reset()
A method to be called event-wise to reset parameters.
std::string _name
Unique name.
size_t Min(const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
intermediate_table::const_iterator const_iterator
const std::string & Name() const
Name getter.
pulse_param _pulse
A subject pulse_param object to be filled with the last reconstructed pulse parameters.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
size_t Max(const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
bool CheckIndex(const std::vector< short > &wf, const size_t &begin, size_t &end)
const pulse_param_array & GetPulses() const
A getter for the whole array of pulse_param struct object.
std::vector< short > Waveform_t
virtual bool RecoPulse(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)=0
bool Reconstruct(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
std::vector< pmtana::pulse_param > pulse_param_array
Class definition file of PMTPulseRecoBase.
std::vector< double > PedestalMean_t
const pulse_param & GetPulse(size_t index=0) const
pulse_param_array _pulse_v
A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s)...
bool Derivative(const std::vector< short > &wf, std::vector< int32_t > &diff, size_t begin=0, size_t end=0) const
PMTPulseRecoBase(const std::string name="noname")
Default constructor with fhicl parameters.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33