All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
pmtana::AlgoSlidingWindow Class Reference

#include <AlgoSlidingWindow.h>

Inheritance diagram for pmtana::AlgoSlidingWindow:
pmtana::PMTPulseRecoBase

Public Member Functions

 AlgoSlidingWindow (const std::string name="SlidingWindow")
 Default constructor. More...
 
 AlgoSlidingWindow (const fhicl::ParameterSet &pset, std::unique_ptr< pmtana::RiseTimeCalculatorBase > risetimecalculator=nullptr, const std::string name="SlidingWindow")
 Alternative ctor. More...
 
void Reset ()
 Implementation of AlgoSlidingWindow::reset() method. More...
 
- Public Member Functions inherited from pmtana::PMTPulseRecoBase
 PMTPulseRecoBase (const std::string name="noname")
 Default constructor with fhicl parameters. More...
 
virtual ~PMTPulseRecoBase ()=default
 Default destructor. More...
 
const std::string & Name () const
 Name getter. More...
 
bool Status () const
 Status getter. More...
 
bool Reconstruct (const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)
 
const pulse_paramGetPulse (size_t index=0) const
 
const pulse_param_arrayGetPulses () const
 A getter for the whole array of pulse_param struct object. More...
 
size_t GetNPulse () const
 A getter for the number of reconstructed pulses from the input waveform. More...
 

Protected Member Functions

bool RecoPulse (const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)
 Implementation of AlgoSlidingWindow::reco() method. More...
 
- Protected Member Functions inherited from pmtana::PMTPulseRecoBase
bool Integral (const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
 
bool Derivative (const std::vector< short > &wf, std::vector< int32_t > &diff, size_t begin=0, size_t end=0) const
 
size_t Max (const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
 
size_t Min (const std::vector< short > &wf, double &result, size_t begin=0, size_t end=0) const
 

Protected Attributes

bool _positive
 A boolean to set waveform positive/negative polarity. More...
 
float _adc_thres
 A variable holder for a user-defined absolute ADC threshold value. More...
 
float _tail_adc_thres
 
float _end_adc_thres
 
size_t _min_width
 A variable holder to ensure the minimum pulse width. More...
 
float _nsigma
 A variable holder for a multiplicative factor for the pedestal standard deviation to define the threshold. More...
 
float _tail_nsigma
 
float _end_nsigma
 
bool _verbose
 
size_t _num_presample
 
size_t _num_postsample
 
- Protected Attributes inherited from pmtana::PMTPulseRecoBase
pulse_param_array _pulse_v
 A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s). More...
 
pulse_param _pulse
 A subject pulse_param object to be filled with the last reconstructed pulse parameters. More...
 
std::unique_ptr
< pmtana::RiseTimeCalculatorBase
_risetime_calc_ptr = nullptr
 Tool for rise time calculation. More...
 

Detailed Description

This class implements threshold algorithm to AlgoSlidingWindow class.

Definition at line 32 of file AlgoSlidingWindow.h.

Constructor & Destructor Documentation

pmtana::AlgoSlidingWindow::AlgoSlidingWindow ( const std::string  name = "SlidingWindow")

Default constructor.

Definition at line 14 of file AlgoSlidingWindow.cxx.

15  //*********************************************************************
16  {}
then echo fcl name
PMTPulseRecoBase(const std::string name="noname")
Default constructor with fhicl parameters.
pmtana::AlgoSlidingWindow::AlgoSlidingWindow ( const fhicl::ParameterSet &  pset,
std::unique_ptr< pmtana::RiseTimeCalculatorBase risetimecalculator = nullptr,
const std::string  name = "SlidingWindow" 
)

Alternative ctor.

Definition at line 19 of file AlgoSlidingWindow.cxx.

25  //*********************************************************************
26  {
27  _positive = pset.get<bool>("PositivePolarity", true);
28 
29  _adc_thres = pset.get<float>("ADCThreshold");
30 
31  _tail_adc_thres = pset.get<float>("TailADCThreshold", _adc_thres);
32 
33  _end_adc_thres = pset.get<float>("EndADCThreshold");
34 
35  _nsigma = pset.get<float>("NSigmaThreshold");
36 
37  _tail_nsigma = pset.get<float>("TailNSigma", _nsigma);
38 
39  _end_nsigma = pset.get<float>("EndNSigmaThreshold");
40 
41  _verbose = pset.get<bool>("Verbosity");
42 
43  _num_presample = pset.get<size_t>("NumPreSample");
44 
45  _num_postsample = pset.get<size_t>("NumPostSample", 0);
46 
47  _min_width = pset.get<size_t>("MinPulseWidth", 0);
48 
49  _risetime_calc_ptr = std::move(risetimecalculator);
50 
51  Reset();
52  }
float _nsigma
A variable holder for a multiplicative factor for the pedestal standard deviation to define the thres...
std::unique_ptr< pmtana::RiseTimeCalculatorBase > _risetime_calc_ptr
Tool for rise time calculation.
bool _positive
A boolean to set waveform positive/negative polarity.
void Reset()
Implementation of AlgoSlidingWindow::reset() method.
float _adc_thres
A variable holder for a user-defined absolute ADC threshold value.
then echo fcl name
size_t _min_width
A variable holder to ensure the minimum pulse width.
PMTPulseRecoBase(const std::string name="noname")
Default constructor with fhicl parameters.

Member Function Documentation

bool pmtana::AlgoSlidingWindow::RecoPulse ( const pmtana::Waveform_t wf,
const pmtana::PedestalMean_t mean_v,
const pmtana::PedestalSigma_t sigma_v 
)
protectedvirtual

Implementation of AlgoSlidingWindow::reco() method.

Implements pmtana::PMTPulseRecoBase.

Definition at line 64 of file AlgoSlidingWindow.cxx.

68  {
69 
70  bool fire = false;
71 
72  bool in_tail = false;
73 
74  bool in_post = false;
75 
76  double pulse_tail_threshold = 0;
77 
78  double pulse_end_threshold = 0;
79 
80  double pulse_start_baseline = 0;
81 
82  int post_integration = 0;
83 
84  assert(wf.size() == mean_v.size() && wf.size() == sigma_v.size());
85 
86  //double threshold = ( _adc_thres > (_nsigma * _ped_rms) ? _adc_thres : (_nsigma * _ped_rms) );
87 
88  //threshold += _ped_mean;
89 
90  Reset();
91 
92  for (size_t i = 0; i < wf.size(); ++i) {
93 
94  double value = 0.;
95  if (_positive)
96  value = ((double)(wf[i])) - mean_v[i];
97  else
98  value = mean_v[i] - ((double)(wf[i]));
99 
100  float start_threshold = 0.;
101  float tail_threshold = 0.;
102  if (sigma_v[i] * _nsigma < _adc_thres)
103  start_threshold = _adc_thres;
104  else
105  start_threshold = sigma_v[i] * _nsigma;
106 
107  if (sigma_v[i] * _tail_nsigma < _tail_adc_thres)
108  tail_threshold = _tail_adc_thres;
109  else
110  tail_threshold = sigma_v[i] * _tail_nsigma;
111 
112  // End pulse if significantly high peak found (new pulse)
113  if ((!fire || in_tail || in_post) && ((double)value > start_threshold)) {
114 
115  // If there's a pulse, end it
116  if (in_tail) {
117  _pulse.t_end = i - 1;
118 
119  // Register if width is acceptable
120  if ((_pulse.t_end - _pulse.t_start) >= _min_width) {
122  _pulse.t_rise = _risetime_calc_ptr->RiseTime(
123  {wf.begin()+_pulse.t_start, wf.begin()+_pulse.t_end},
124  {mean_v.begin()+_pulse.t_start, mean_v.begin()+_pulse.t_end},
125  _positive);
126 
127  _pulse_v.push_back(_pulse);
128  }
129 
131 
132  if (_verbose)
133  std::cout << "\033[93mPulse End\033[00m: "
134  << "baseline: " << mean_v[i] << " ... "
135  << " ... adc above: " << value << " T=" << i << std::endl;
136  }
137 
138  //
139  // Found a new pulse ... try to get a few samples prior to this
140  //
141 
142  pulse_tail_threshold = tail_threshold;
143  pulse_start_baseline = mean_v[i];
144 
145  pulse_end_threshold = 0.;
146  if (sigma_v[i] * _end_nsigma < _end_adc_thres)
147  pulse_end_threshold = _end_adc_thres;
148  else
149  pulse_end_threshold = sigma_v[i] * _end_nsigma;
150 
151  int buffer_num_index = 0;
152  if (_pulse_v.size())
153  buffer_num_index = (int)i - _pulse_v.back().t_end - 1;
154  else
155  buffer_num_index = std::min(_num_presample, i);
156 
157  if (buffer_num_index > (int)_num_presample) buffer_num_index = _num_presample;
158 
159  if (buffer_num_index < 0) {
160  std::cerr << "\033[95m[ERROR]\033[00m Logic error! Negative buffer_num_index..."
161  << std::endl;
162  throw std::exception();
163  }
164 
165  // If there's a pulse, end we where in in_post, end the previous pulse first
166  if (in_post) {
167  // Find were
168  _pulse.t_end = static_cast<int>(i) - buffer_num_index;
169  if (_pulse.t_end > 0) --_pulse.t_end; // leave a gap, if we can
170 
171  // Register if width is acceptable
172  if ((_pulse.t_end - _pulse.t_start) >= _min_width) {
174  _pulse.t_rise = _risetime_calc_ptr->RiseTime(
175  {wf.begin()+_pulse.t_start, wf.begin()+_pulse.t_end},
176  {mean_v.begin()+_pulse.t_start, mean_v.begin()+_pulse.t_end},
177  _positive);
178 
179  _pulse_v.push_back(_pulse);
180  }
181 
183 
184  if (_verbose)
185  std::cout << "\033[93mPulse End\033[00m: new pulse starts during in_post: "
186  << "baseline: " << mean_v[i] << " ... "
187  << " ... adc above: " << value << " T=" << i << std::endl;
188  }
189 
190  _pulse.t_start = i - buffer_num_index;
191  _pulse.ped_mean = pulse_start_baseline;
192  _pulse.ped_sigma = sigma_v[i];
193 
194  for (size_t pre_index = _pulse.t_start; pre_index < i; ++pre_index) {
195 
196  double pre_adc = wf[pre_index];
197  if (_positive)
198  pre_adc -= pulse_start_baseline;
199  else
200  pre_adc = pulse_start_baseline - pre_adc;
201 
202  if (pre_adc > 0.) _pulse.area += pre_adc;
203  }
204 
205  if (_verbose)
206  std::cout << "\033[93mPulse Start\033[00m: "
207  << "baseline: " << mean_v[i] << " ... threshold: " << start_threshold
208  << " ... adc above baseline: " << value << " ... pre-adc sum: " << _pulse.area
209  << " T=" << i << std::endl;
210 
211  fire = true;
212  in_tail = false;
213  in_post = false;
214  }
215 
216  if (fire && value < pulse_tail_threshold) {
217  fire = false;
218  in_tail = true;
219  in_post = false;
220  }
221 
222  if ((fire || in_tail || in_post) && _verbose) {
223  std::cout << (fire ? "\033[93mPulsing\033[00m: " : "\033[93mIn-tail\033[00m: ")
224  << "baseline: " << mean_v[i] << " std: " << sigma_v[i]
225  << " ... adc above baseline " << value << " T=" << i << std::endl;
226  }
227 
228  if ((fire || in_tail) && value < pulse_end_threshold) {
229  in_post = true;
230  fire = in_tail = false;
231  post_integration = _num_postsample;
232  }
233 
234  if (in_post && post_integration < 1) {
235  // Found the end of a pulse
236  _pulse.t_end = i - 1;
237 
238  // Register if width is acceptable
239  if ((_pulse.t_end - _pulse.t_start) >= _min_width) {
241  _pulse.t_rise = _risetime_calc_ptr->RiseTime(
242  {wf.begin()+_pulse.t_start, wf.begin()+_pulse.t_end},
243  {mean_v.begin()+_pulse.t_start, mean_v.begin()+_pulse.t_end},
244  _positive);
245 
246  _pulse_v.push_back(_pulse);
247  }
248 
249  if (_verbose)
250  std::cout << "\033[93mPulse End\033[00m: "
251  << "baseline: " << mean_v[i] << " ... adc: " << value << " T=" << i
252  << " ... area sum " << _pulse.area << std::endl;
253 
255 
256  fire = false;
257  in_tail = false;
258  in_post = false;
259  }
260 
261  if (fire || in_tail || in_post) {
262 
263  //_pulse.area += ((double)value - (double)mean_v[i]);
264  _pulse.area += value;
265 
266  if (_pulse.peak < value) {
267 
268  // Found a new maximum
269  _pulse.peak = value;
270 
271  _pulse.t_max = i;
272  }
273 
274  if (in_post) --post_integration;
275  }
276  }
277 
278  if (fire || in_tail || in_post) {
279 
280  // Take care of a pulse that did not finish within the readout window.
281 
282  fire = false;
283  in_tail = false;
284 
285  _pulse.t_end = wf.size() - 1;
286 
287  // Register if width is acceptable
288  if ((_pulse.t_end - _pulse.t_start) >= _min_width) {
290  _pulse.t_rise = _risetime_calc_ptr->RiseTime(
291  {wf.begin()+_pulse.t_start, wf.begin()+_pulse.t_end},
292  {mean_v.begin()+_pulse.t_start, mean_v.begin()+_pulse.t_end},
293  _positive);
294  _pulse_v.push_back(_pulse);
295  }
296 
298  }
299 
300  return true;
301  }
BEGIN_PROLOG could also be cerr
float _nsigma
A variable holder for a multiplicative factor for the pedestal standard deviation to define the thres...
pulse_param _pulse
A subject pulse_param object to be filled with the last reconstructed pulse parameters.
std::unique_ptr< pmtana::RiseTimeCalculatorBase > _risetime_calc_ptr
Tool for rise time calculation.
bool _positive
A boolean to set waveform positive/negative polarity.
void Reset()
Implementation of AlgoSlidingWindow::reset() method.
float _adc_thres
A variable holder for a user-defined absolute ADC threshold value.
temporary value
size_t _min_width
A variable holder to ensure the minimum pulse width.
pulse_param_array _pulse_v
A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s)...
BEGIN_PROLOG could also be cout
void pmtana::AlgoSlidingWindow::Reset ( )
virtual

Implementation of AlgoSlidingWindow::reset() method.

Reimplemented from pmtana::PMTPulseRecoBase.

Definition at line 56 of file AlgoSlidingWindow.cxx.

58  {
60  }
virtual void Reset()
A method to be called event-wise to reset parameters.

Member Data Documentation

float pmtana::AlgoSlidingWindow::_adc_thres
protected

A variable holder for a user-defined absolute ADC threshold value.

Definition at line 59 of file AlgoSlidingWindow.h.

float pmtana::AlgoSlidingWindow::_end_adc_thres
protected

Definition at line 59 of file AlgoSlidingWindow.h.

float pmtana::AlgoSlidingWindow::_end_nsigma
protected

Definition at line 65 of file AlgoSlidingWindow.h.

size_t pmtana::AlgoSlidingWindow::_min_width
protected

A variable holder to ensure the minimum pulse width.

Definition at line 62 of file AlgoSlidingWindow.h.

float pmtana::AlgoSlidingWindow::_nsigma
protected

A variable holder for a multiplicative factor for the pedestal standard deviation to define the threshold.

Definition at line 65 of file AlgoSlidingWindow.h.

size_t pmtana::AlgoSlidingWindow::_num_postsample
protected

Definition at line 67 of file AlgoSlidingWindow.h.

size_t pmtana::AlgoSlidingWindow::_num_presample
protected

Definition at line 67 of file AlgoSlidingWindow.h.

bool pmtana::AlgoSlidingWindow::_positive
protected

A boolean to set waveform positive/negative polarity.

Definition at line 56 of file AlgoSlidingWindow.h.

float pmtana::AlgoSlidingWindow::_tail_adc_thres
protected

Definition at line 59 of file AlgoSlidingWindow.h.

float pmtana::AlgoSlidingWindow::_tail_nsigma
protected

Definition at line 65 of file AlgoSlidingWindow.h.

bool pmtana::AlgoSlidingWindow::_verbose
protected

Definition at line 66 of file AlgoSlidingWindow.h.


The documentation for this class was generated from the following files: