LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
pmtana::AlgoThreshold Class Reference

#include "AlgoThreshold.h"

Inheritance diagram for pmtana::AlgoThreshold:
pmtana::PMTPulseRecoBase

Public Member Functions

 AlgoThreshold (const std::string name="AlgoThreshold")
 Default constructor. More...
 
 AlgoThreshold (const fhicl::ParameterSet &pset, std::unique_ptr< pmtana::RiseTimeCalculatorBase > risetimecalculator=nullptr, const std::string name="AlgoThreshold")
 Alternative constructor. More...
 
void Reset ()
 Implementation of AlgoThreshold::reset() method. 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 &wf, const pmtana::PedestalMean_t &mean_v, const pmtana::PedestalSigma_t &sigma_v)
 Implementation of AlgoThreshold::reco() method. More...
 
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

double _start_adc_thres
 A variable holder for a user-defined absolute ADC threshold value. More...
 
double _end_adc_thres
 
double _nsigma_start
 A variable holder for a multiplicative factor for the pedestal standard deviation to define the threshold. More...
 
double _nsigma_end
 
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 AlgoThreshold class. The algorithm defines a pulse in user-specified time window. A typical usage is to set the beginning of the window to be 0 (= start of the waveform) and integrate over the time of interest. By default, the ending is set to index=0, in which case it uses the ending index of the input waveform (i.e. full integration).

Definition at line 36 of file AlgoThreshold.h.

Constructor & Destructor Documentation

pmtana::AlgoThreshold::AlgoThreshold ( const std::string  name = "AlgoThreshold")

Default constructor.

Definition at line 14 of file AlgoThreshold.cxx.

References Reset().

14  : PMTPulseRecoBase(name)
15  //***************************************************************************
16  {
17  //_adc_thres = 3;
18  //_nsigma = 5;
19  Reset();
20  }
void Reset()
Implementation of AlgoThreshold::reset() method.
PMTPulseRecoBase(const std::string name="noname")
Default constructor with fhicl parameters.
pmtana::AlgoThreshold::AlgoThreshold ( const fhicl::ParameterSet pset,
std::unique_ptr< pmtana::RiseTimeCalculatorBase risetimecalculator = nullptr,
const std::string  name = "AlgoThreshold" 
)

Alternative constructor.

Definition at line 23 of file AlgoThreshold.cxx.

References _end_adc_thres, _nsigma_end, _nsigma_start, pmtana::PMTPulseRecoBase::_risetime_calc_ptr, _start_adc_thres, fhicl::ParameterSet::get(), and Reset().

27  : PMTPulseRecoBase(name)
28  //*******************************************************
29  {
30 
31  _start_adc_thres = pset.get<double>("StartADCThreshold");
32  _end_adc_thres = pset.get<double>("EndADCThreshold");
33 
34  //_nsigma = pset.get<double>("NSigmaThreshold");
35 
36  _nsigma_start = pset.get<double>("NSigmaThresholdStart");
37  _nsigma_end = pset.get<double>("NSigmaThresholdEnd");
38 
39  _risetime_calc_ptr = std::move(risetimecalculator);
40 
41  Reset();
42  }
void Reset()
Implementation of AlgoThreshold::reset() method.
T get(std::string const &key) const
Definition: ParameterSet.h:314
std::unique_ptr< pmtana::RiseTimeCalculatorBase > _risetime_calc_ptr
Tool for rise time calculation.
double _nsigma_start
A variable holder for a multiplicative factor for the pedestal standard deviation to define the thres...
Definition: AlgoThreshold.h:64
PMTPulseRecoBase(const std::string name="noname")
Default constructor with fhicl parameters.
double _start_adc_thres
A variable holder for a user-defined absolute ADC threshold value.
Definition: AlgoThreshold.h:59

Member Function Documentation

bool pmtana::PMTPulseRecoBase::Derivative ( const std::vector< short > &  wf,
std::vector< int32_t > &  diff,
size_t  begin = 0,
size_t  end = 0 
) const
protectedinherited

A method to compute derivative, which is a simple subtraction of previous ADC sample from each sample. The result is stored in the input "diff" reference vector which is int32_t type as a derivative could be negative.

Definition at line 121 of file PMTPulseRecoBase.cxx.

References util::begin(), pmtana::CheckIndex(), and util::end().

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  }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool CheckIndex(const std::vector< short > &wf, const size_t &begin, size_t &end)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
size_t pmtana::PMTPulseRecoBase::GetNPulse ( ) const
inlineinherited

A getter for the number of reconstructed pulses from the input waveform.

Definition at line 101 of file PMTPulseRecoBase.h.

Referenced by opdet::LEDCalibrationAna::analyze().

101 { return _pulse_v.size(); };
pulse_param_array _pulse_v
A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s)...
const pulse_param & pmtana::PMTPulseRecoBase::GetPulse ( size_t  index = 0) const
inherited

A getter for the pulse_param struct object. Reconstruction algorithm may have more than one pulse reconstructed from an input waveform. Note you must, accordingly, provide an index key to specify which pulse_param object to be retrieved.

Definition at line 74 of file PMTPulseRecoBase.cxx.

References pmtana::PMTPulseRecoBase::_pulse_v.

Referenced by opdet::LEDCalibrationAna::analyze().

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  }
pulse_param_array _pulse_v
A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s)...
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
const pulse_param_array & pmtana::PMTPulseRecoBase::GetPulses ( ) const
inherited

A getter for the whole array of pulse_param struct object.

Definition at line 91 of file PMTPulseRecoBase.cxx.

References pmtana::PMTPulseRecoBase::_pulse_v.

Referenced by opdet::RunHitFinder().

93  {
94  return _pulse_v;
95  }
pulse_param_array _pulse_v
A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s)...
bool pmtana::PMTPulseRecoBase::Integral ( const std::vector< short > &  wf,
double &  result,
size_t  begin = 0,
size_t  end = 0 
) const
protectedinherited

A method to integrate an waveform from index "begin" to the "end". The result is filled in "result" reference. If the "end" is default (=0), then "end" is set to the last index of the waveform.

Definition at line 98 of file PMTPulseRecoBase.cxx.

References util::begin(), pmtana::CheckIndex(), and util::end().

Referenced by pmtana::AlgoFixedWindow::RecoPulse().

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  }
intermediate_table::const_iterator const_iterator
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool CheckIndex(const std::vector< short > &wf, const size_t &begin, size_t &end)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
size_t pmtana::PMTPulseRecoBase::Max ( const std::vector< short > &  wf,
double &  result,
size_t  begin = 0,
size_t  end = 0 
) const
protectedinherited

A method to return the maximum value of ADC sample within the index from "begin" to "end". If the "end" is default (=0), then "end" is set to the last index of the waveform.

Definition at line 144 of file PMTPulseRecoBase.cxx.

References util::begin(), pmtana::CheckIndex(), and util::end().

Referenced by pmtana::AlgoFixedWindow::RecoPulse().

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  }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool CheckIndex(const std::vector< short > &wf, const size_t &begin, size_t &end)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
size_t pmtana::PMTPulseRecoBase::Min ( const std::vector< short > &  wf,
double &  result,
size_t  begin = 0,
size_t  end = 0 
) const
protectedinherited

A method to return the minimum value of ADC sample within the index from "begin" to "end". If the "end" is default (=0), then "end" is set to the last index of the waveform.

Definition at line 169 of file PMTPulseRecoBase.cxx.

References util::begin(), pmtana::CheckIndex(), and util::end().

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  }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
bool CheckIndex(const std::vector< short > &wf, const size_t &begin, size_t &end)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
const std::string & pmtana::PMTPulseRecoBase::Name ( ) const
inherited

Name getter.

Definition at line 22 of file PMTPulseRecoBase.cxx.

References pmtana::PMTPulseRecoBase::_name.

24  {
25  return _name;
26  }
std::string _name
Unique name.
bool pmtana::PMTPulseRecoBase::Reconstruct ( const pmtana::Waveform_t wf,
const pmtana::PedestalMean_t mean_v,
const pmtana::PedestalSigma_t sigma_v 
)
inherited

A core method: this executes the algorithm and stores reconstructed parameters in the pulse_param struct object.

Definition at line 36 of file PMTPulseRecoBase.cxx.

References pmtana::PMTPulseRecoBase::_status, and pmtana::PMTPulseRecoBase::RecoPulse().

40  {
41  _status = this->RecoPulse(wf, mean_v, sigma_v);
42  return _status;
43  }
bool _status
Status after pulse reconstruction.
virtual bool RecoPulse(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)=0
bool pmtana::AlgoThreshold::RecoPulse ( const pmtana::Waveform_t wf,
const pmtana::PedestalMean_t mean_v,
const pmtana::PedestalSigma_t sigma_v 
)
protectedvirtual

Implementation of AlgoThreshold::reco() method.

Implements pmtana::PMTPulseRecoBase.

Definition at line 52 of file AlgoThreshold.cxx.

References _end_adc_thres, _nsigma_end, _nsigma_start, pmtana::PMTPulseRecoBase::_pulse, pmtana::PMTPulseRecoBase::_pulse_v, pmtana::PMTPulseRecoBase::_risetime_calc_ptr, _start_adc_thres, pmtana::pulse_param::area, util::counter(), pmtana::pulse_param::peak, pmtana::pulse_param::ped_mean, pmtana::pulse_param::ped_sigma, Reset(), pmtana::pulse_param::reset_param(), pmtana::pulse_param::t_end, pmtana::pulse_param::t_max, pmtana::pulse_param::t_rise, pmtana::pulse_param::t_start, and value.

56  {
57  bool fire = false;
58 
59  double counter = 0;
60 
61  double ped_mean = mean_v.front();
62  double ped_rms = sigma_v.front();
63 
64  //double threshold = ( _adc_thres > (_nsigma * ped_rms) ? _adc_thres : (_nsigma * ped_rms) );
65  auto start_threshold =
66  (_start_adc_thres > (_nsigma_start * ped_rms) ? _start_adc_thres : (_nsigma_start * ped_rms));
67  auto end_threshold =
68  (_end_adc_thres > (_nsigma_end * ped_rms) ? _end_adc_thres : (_nsigma_end * ped_rms));
69 
70  // threshold += ped_mean
71 
72  start_threshold += ped_mean;
73  end_threshold += ped_mean;
74 
75  Reset();
76 
77  for (auto const& value : wf) {
78 
79  if (!fire && ((double)value) >= start_threshold) {
80 
81  // Found a new pulse
82 
83  fire = true;
84 
85  _pulse.ped_mean = ped_mean;
86  _pulse.ped_sigma = ped_rms;
87 
88  //vic: i move t_start back one, this helps with porch
89 
90  _pulse.t_start = counter - 1 > 0 ? counter - 1 : counter;
91  //std::cout << "counter: " << counter << " tstart : " << _pulse.t_start << "\n";
92  }
93 
94  if (fire && ((double)value) < end_threshold) {
95 
96  // Found the end of a pulse
97 
98  fire = false;
99 
100  //vic: i move t_start forward one, this helps with tail
101  _pulse.t_end = counter < wf.size() ? counter : counter - 1;
102 
103  if (_risetime_calc_ptr)
104  _pulse.t_rise = _risetime_calc_ptr->RiseTime(
105  {wf.begin() + _pulse.t_start, wf.begin() + _pulse.t_end},
106  {mean_v.begin() + _pulse.t_start, mean_v.begin() + _pulse.t_end},
107  true);
108 
109  _pulse_v.push_back(_pulse);
110 
112  }
113 
114  //std::cout << "\tFire=" << fire << std::endl;
115 
116  if (fire) {
117 
118  // Add this adc count to the integral
119 
120  _pulse.area += ((double)value - (double)ped_mean);
121 
122  if (_pulse.peak < ((double)value - (double)ped_mean)) {
123 
124  // Found a new maximum
125 
126  _pulse.peak = ((double)value - (double)ped_mean);
127 
128  _pulse.t_max = counter;
129  }
130  }
131 
132  counter++;
133  }
134 
135  if (fire) {
136 
137  // Take care of a pulse that did not finish within the readout window.
138 
139  fire = false;
140 
141  _pulse.t_end = counter - 1;
142 
143  if (_risetime_calc_ptr)
144  _pulse.t_rise = _risetime_calc_ptr->RiseTime(
145  {wf.begin() + _pulse.t_start, wf.begin() + _pulse.t_end},
146  {mean_v.begin() + _pulse.t_start, mean_v.begin() + _pulse.t_end},
147  true);
148 
149  _pulse_v.push_back(_pulse);
150 
152  }
153 
154  return true;
155  }
pulse_param _pulse
A subject pulse_param object to be filled with the last reconstructed pulse parameters.
void Reset()
Implementation of AlgoThreshold::reset() method.
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:295
double value
Definition: spectrum.C:18
std::unique_ptr< pmtana::RiseTimeCalculatorBase > _risetime_calc_ptr
Tool for rise time calculation.
double _nsigma_start
A variable holder for a multiplicative factor for the pedestal standard deviation to define the thres...
Definition: AlgoThreshold.h:64
pulse_param_array _pulse_v
A container array of pulse_param struct objects to store (possibly multiple) reconstructed pulse(s)...
double _start_adc_thres
A variable holder for a user-defined absolute ADC threshold value.
Definition: AlgoThreshold.h:59
void pmtana::AlgoThreshold::Reset ( )
virtual

Implementation of AlgoThreshold::reset() method.

Reimplemented from pmtana::PMTPulseRecoBase.

Definition at line 45 of file AlgoThreshold.cxx.

References pmtana::PMTPulseRecoBase::Reset().

Referenced by AlgoThreshold(), and RecoPulse().

47  {
49  }
virtual void Reset()
A method to be called event-wise to reset parameters.
bool pmtana::PMTPulseRecoBase::Status ( ) const
inherited

Status getter.

Definition at line 29 of file PMTPulseRecoBase.cxx.

References pmtana::PMTPulseRecoBase::_status.

31  {
32  return _status;
33  }
bool _status
Status after pulse reconstruction.

Member Data Documentation

double pmtana::AlgoThreshold::_end_adc_thres
protected

Definition at line 60 of file AlgoThreshold.h.

Referenced by AlgoThreshold(), and RecoPulse().

double pmtana::AlgoThreshold::_nsigma_end
protected

Definition at line 65 of file AlgoThreshold.h.

Referenced by AlgoThreshold(), and RecoPulse().

double pmtana::AlgoThreshold::_nsigma_start
protected

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

Definition at line 64 of file AlgoThreshold.h.

Referenced by AlgoThreshold(), and RecoPulse().

pulse_param pmtana::PMTPulseRecoBase::_pulse
protectedinherited
double pmtana::AlgoThreshold::_start_adc_thres
protected

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

Definition at line 59 of file AlgoThreshold.h.

Referenced by AlgoThreshold(), and RecoPulse().


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