LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
AlgoSlidingWindow.cxx
Go to the documentation of this file.
1 //
3 // AlgoSlidingWindow source
4 //
6 
7 #ifndef ALGOSLIDINGWINDOW_CXX
8 #define ALGOSLIDINGWINDOW_CXX
9 
10 #include "AlgoSlidingWindow.h"
11 
12 namespace pmtana{
13 
14  //*********************************************************************
15  AlgoSlidingWindow::AlgoSlidingWindow(const std::string name)
16  : PMTPulseRecoBase(name)
17  //*********************************************************************
18  {}
19 
20  //*********************************************************************
22  //AlgoSlidingWindow::AlgoSlidingWindow(const ::fcllite::PSet &pset,
23  const std::string name)
24  : PMTPulseRecoBase(name)
25  //*********************************************************************
26  {
27 
28  _adc_thres = pset.get<float>("ADCThreshold");
29 
30  _end_adc_thres = pset.get<float>("EndADCThreshold");
31 
32  _nsigma = pset.get<float>("NSigmaThreshold");
33 
34  _end_nsigma = pset.get<float>("EndNSigmaThreshold");
35 
36  _verbose = pset.get<bool>("Verbosity");
37 
38  _num_presample = pset.get<size_t>("NumPreSample");
39 
40  Reset();
41 
42  }
43 
44  //***************************************************************
46  //***************************************************************
47  {}
48 
49  //***************************************************************
51  //***************************************************************
52  {
54  }
55 
56  //***************************************************************
58  const pmtana::PedestalMean_t& mean_v,
59  const pmtana::PedestalSigma_t& sigma_v)
60  //***************************************************************
61  {
62 
63  bool fire = false;
64 
65  bool in_tail = false;
66 
67  double pulse_start_threshold=0;
68  double pulse_tail_threshold =0;
69 
70  double pulse_start_baseline =0;
71 
72  //double threshold = ( _adc_thres > (_nsigma * _ped_rms) ? _adc_thres : (_nsigma * _ped_rms) );
73 
74  //threshold += _ped_mean;
75 
76  Reset();
77 
78  for(size_t i=0; i<wf.size(); ++i) {
79 
80  auto const& value = wf[i];
81 
82  float start_threshold = mean_v.at(i);
83 
84  if(sigma_v.at(i) * _nsigma < _adc_thres) start_threshold += _adc_thres;
85  else start_threshold += sigma_v.at(i) * _nsigma;
86 
87  // End pulse if significantly high peak found (new pulse)
88  if( (!fire || in_tail) && (double)value > start_threshold ) {
89 
90 
91  // If there's a pulse, end it
92  if(in_tail) {
93  _pulse.t_end = i - 1;
94 
95  _pulse_v.push_back(_pulse);
96 
98 
99  if(_verbose)
100  std::cout << "\033[93mPulse End\033[00m: "
101  << "baseline: " << mean_v[i] << " ... " << " ... adc: " << value << " T=" << i << std::endl;
102  }
103 
104  //
105  // Found a new pulse ... try to get a few samples prior to this
106  //
107 
108  pulse_start_threshold = start_threshold;
109  pulse_start_baseline = mean_v.at(i);
110 
111  pulse_tail_threshold = pulse_start_baseline;
112  if(sigma_v.at(i) * _end_nsigma < _end_adc_thres) pulse_tail_threshold += _end_adc_thres;
113  else pulse_tail_threshold += sigma_v.at(i) * _end_nsigma;
114 
115  int last_pulse_end_index = 0;
116  if(_pulse_v.size()) last_pulse_end_index = _pulse_v.back().t_end;
117  int buffer_num_index = (int)i - last_pulse_end_index;
118  if(buffer_num_index > (int)_num_presample) buffer_num_index = _num_presample;
119 
120  if(buffer_num_index<0) {
121  std::cerr << "\033[95m[ERROR]\033[00m Logic error! Negative buffer_num_index..." << std::endl;
122  throw std::exception();
123  }
124 
125  _pulse.t_start = i - buffer_num_index;
126  _pulse.ped_mean = pulse_start_baseline;
127  _pulse.ped_sigma = sigma_v.at(i);
128 
129  for(size_t pre_index=_pulse.t_start; pre_index<i; ++pre_index) {
130 
131  auto const& pre_adc = wf[pre_index];
132  if(pre_adc > pulse_start_baseline) continue;
133 
134  _pulse.area += pre_adc - pulse_start_baseline;
135 
136  }
137 
138  if(_verbose)
139  std::cout << "\033[93mPulse Start\033[00m: "
140  << "baseline: " << mean_v[i]
141  << " ... threshold: " << start_threshold
142  << " ... adc: " << value
143  << " T=" << i << std::endl;
144 
145  fire = true;
146  in_tail = false;
147  }
148 
149  if( fire && ((double)value) < pulse_start_threshold ) {
150  fire = false;
151  in_tail = true;
152  }
153 
154  if( (fire || in_tail) && ((double)value) < pulse_tail_threshold ){
155 
156  // Found the end of a pulse
157  _pulse.t_end = i - 1;
158 
159  _pulse_v.push_back(_pulse);
160 
162 
163  if(_verbose)
164  std::cout << "\033[93mPulse End\033[00m: "
165  << "baseline: " << mean_v[i] << " ... " << " ... adc: " << value << " T=" << i << std::endl;
166 
167  fire = false;
168  in_tail = false;
169 
170  }
171 
172  if(fire || in_tail){
173 
174  // Add this adc count to the integral
175  double adc_above_baseline = ((double)value - (double)pulse_start_baseline);
176 
177  //_pulse.area += ((double)value - (double)mean_v.at(i));
178  _pulse.area += adc_above_baseline;
179 
180  if(_pulse.peak < adc_above_baseline) {
181 
182  // Found a new maximum
183  _pulse.peak = adc_above_baseline;
184 
185  _pulse.t_max = i;
186 
187  }
188 
189  }
190 
191  }
192 
193  if(fire || in_tail){
194 
195  // Take care of a pulse that did not finish within the readout window.
196 
197  fire = false;
198  in_tail = false;
199 
200  _pulse.t_end = wf.size() - 1;
201 
202  _pulse_v.push_back(_pulse);
203 
205 
206  }
207 
208  return true;
209 
210  }
211 
212 }
213 
214 #endif
std::vector< double > PedestalSigma_t
virtual void Reset()
A method to be called event-wise to reset parameters.
float _nsigma
A variable holder for a multiplicative factor for the pedestal standard deviation to define the thres...
virtual ~AlgoSlidingWindow()
Default destructor.
AlgoSlidingWindow(const std::string name="SlidingWindow")
Default constructor.
bool RecoPulse(const pmtana::Waveform_t &, const pmtana::PedestalMean_t &, const pmtana::PedestalSigma_t &)
Implementation of AlgoSlidingWindow::reco() method.
pulse_param _pulse
A subject pulse_param object to be filled with the last reconstructed pulse parameters.
T get(std::string const &key) const
Definition: ParameterSet.h:231
std::vector< short > Waveform_t
std::string value(boost::any const &)
Class definition file of AlgoSlidingWindow.
void Reset()
Implementation of AlgoSlidingWindow::reset() method.
float _adc_thres
A variable holder for a user-defined absolute ADC threshold value.
std::vector< double > PedestalMean_t
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