All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PMTPulseRecoBase.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // PMTPulseRecoBase source
4 //
5 ////////////////////////////////////////////////////////////////////////
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)
16  , _status (true)
17  //*************************************************************************
18  { Reset(); }
19 
20  //***********************************************
21  const std::string& PMTPulseRecoBase::Name() const
22  //***********************************************
23  { return _name; }
24 
25  //*****************************************
27  //*****************************************
28  { return _status; }
29 
30  //******************************************************************
32  const PedestalMean_t& mean_v,
33  const PedestalSigma_t& sigma_v )
34  //******************************************************************
35  {
36  _status = this->RecoPulse(wf,mean_v,sigma_v);
37  return _status;
38  }
39 
40  //*****************************************************************************
41  bool CheckIndex(const std::vector<short> &wf, const size_t &begin, size_t &end)
42  //*****************************************************************************
43  {
44  if(begin >= wf.size() || end >= wf.size() || begin > end){
45 
46  std::cerr <<"Invalid arguments: waveform length = " << wf.size() << " begin = " << begin << " end = " << end << std::endl;
47 
48  return false;
49  }
50 
51  if(!end) end = wf.size() - 1;
52 
53  return true;
54  }
55 
56  //***************************************************************
58  //***************************************************************
59  {
61 
62  _pulse_v.clear();
63 
64  _pulse_v.reserve(3);
65  }
66 
67  //***************************************************************
68  const pulse_param& PMTPulseRecoBase::GetPulse(size_t index) const
69  //***************************************************************
70  {
71 
72  if(index >= _pulse_v.size()) {
73 
74  std::cerr << "\033[93m"
75  << "Invalid pulse index: " << index
76  << "\033[00m"
77  << std::endl;
78 
79  throw std::exception();
80  }
81 
82  else return _pulse_v.at(index);
83 
84  }
85 
86  //***************************************************************
88  //***************************************************************
89  {
90  return _pulse_v;
91  }
92 
93  //***************************************************************
94  bool PMTPulseRecoBase::Integral(const std::vector<short> &wf,
95  double &result,
96  size_t begin,
97  size_t end) const
98  //***************************************************************
99  {
100 
101  if(!CheckIndex(wf,begin,end)) return false;
102 
103  std::vector<short>::const_iterator begin_iter(wf.begin());
104 
105  std::vector<short>::const_iterator end_iter(wf.begin());
106 
107  begin_iter = begin_iter + begin;
108 
109  end_iter = end_iter + end + 1;
110 
111  result = (double)(std::accumulate(begin_iter, end_iter, 0));
112 
113  return true;
114  }
115 
116  //***************************************************************
117  bool PMTPulseRecoBase::Derivative(const std::vector<short> &wf,
118  std::vector<int32_t> &diff,
119  size_t begin,
120  size_t end) const
121  //***************************************************************
122  {
123 
124  if(CheckIndex(wf,begin,end)){
125 
126  diff.clear();
127  diff.reserve(end - begin);
128 
129  for(size_t index = begin ; index <= end ; ++index)
130 
131  diff.push_back(wf.at(index+1) - wf.at(index));
132 
133  return true;
134  }
135 
136  return false;
137 
138  }
139 
140  //***************************************************************
141  size_t PMTPulseRecoBase::Max(const std::vector<short> &wf,
142  double &result,
143  size_t begin,
144  size_t end) const
145  //***************************************************************
146  {
147 
148  size_t target_index = wf.size() + 1;
149 
150  result = 0;
151 
152  if(CheckIndex(wf,begin,end)) {
153 
154  for(size_t index = begin; index <= end; ++index)
155 
156  if( result < wf.at(index)) { target_index = index; result = (double)(wf.at(index)); }
157 
158  }
159 
160  return target_index;
161 
162  }
163 
164  //***************************************************************
165  size_t PMTPulseRecoBase::Min(const std::vector<short> &wf,
166  double &result,
167  size_t begin,
168  size_t end) const
169  //***************************************************************
170  {
171 
172  size_t target_index = wf.size() + 1;
173 
174  result = 4096;
175 
176  if(CheckIndex(wf,begin,end)) {
177 
178  for(size_t index = begin; index <= end; ++index)
179 
180  if( result > wf.at(index)) { target_index = index; result = (double)(wf.at(index)); }
181 
182  }
183 
184  return target_index;
185 
186  }
187 }
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.
BEGIN_PROLOG could also be cerr
std::string _name
Unique name.
size_t Min(const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
const std::string & Name() const
Name getter.
pulse_param _pulse
A subject pulse_param object to be filled with the last reconstructed pulse parameters.
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.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
std::vector< short > Waveform_t
virtual bool RecoPulse(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)=0
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
bool Reconstruct(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)
then echo fcl name
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
BEGIN_PROLOG don t mess with this pandoraTrackGausCryoW true
PMTPulseRecoBase(const std::string name="noname")
Default constructor with fhicl parameters.