Berkeley Nuclear Data Software
WFOperations.hpp
Go to the documentation of this file.
1 #include "WFPlotter.h"
2 
3 
4 
5 template <class T > float WFOperations::
6  estimateBaseline(T* a_wf,
7  uint a_num
8  )
9 {
10  //sum the samples
11  float sum = std::accumulate(a_wf, a_wf+a_num,0.0);
12  float numFl = a_num;
13  return sum / numFl;
14 }
15 
16 
19 template <class T> float WFOperations::
20  estimateBaseline(T* a_wf,
21  uint a_num,
22  float& a_sigma
23  )
24 {
25  float mean = estimateBaseline(a_wf,a_num);
26  float accum = 0.0;
27  for(uint iS = 0; iS < a_num;iS++)
28  {
29  float sampleVal = static_cast<float>( a_wf[iS] );
30  accum+=(sampleVal-mean)*(sampleVal-mean);
31  }
32  a_sigma=sqrt(accum/static_cast<float>(a_num));
33  return mean;
34 }
35 
39 template <class T> void WFOperations::
40  estimateBaselineDel(T* a_wf,
41  uint a_num,
42  float a_baseline,
43  float& a_Dmax
44  )
45 {
46  float mean = a_baseline;
47  float maxDel = 0.0;
48  for(uint iS = 0; iS < a_num;iS++)
49  {
50  float sampleVal = static_cast<float>( a_wf[iS] );
51  float diff = sampleVal-mean;
52  if(diff>maxDel)
53  {
54  maxDel = diff;
55  }
56  }
57  a_Dmax = maxDel;
58  return;
59 }
60 
64 template <class T> float WFOperations::
65  estimateBaselineDel(T* a_wf,
66  uint a_num,
67  float& a_Dmax
68  )
69 {
70  float mean = estimateBaseline(a_wf,a_num);
71  estimateBaselineDel(a_wf,a_num,mean,a_Dmax);
72  return mean;
73 }
74 //this function returns the interpolated sample value that occurs before the
75 //max at the specified fractional height
76 template <class T> float WFOperations::
77  getCFD(T* a_wf,
78  uint a_num,
79  float a_mean,
80  float a_frac,
81  bool a_negPulse
82  )
83 {
84  return 0;
85 }
86 
87 //this function returns the sample number corresponding to a leading edge
88 //trigger
89 template <class T> int WFOperations::findSampleLeadingEdgeTrig(T* a_wf,
90  uint a_num,
91  float a_baseline,
92  float a_threshold
93  )
94 {
95  for(uint iS=0; iS<a_num; iS++)
96  {
97  float sampleVal = static_cast<float>( a_wf[iS] );
98  if(abs(sampleVal-a_baseline)>a_threshold)
99  {
100  return iS;
101  }
102  }
103  return 0;
104 }
105 
106 template <class T> float WFOperations::integrateTrace(T* a_wf,
107  float a_baseline,
108  int a_startSample,
109  int a_stopSample,
110  bool a_negPulse)
111 {
112  float returnIntegral=0;
113  for(int iS=a_startSample; iS<a_stopSample+1; iS++)
114  {
115  float sampleVal = static_cast<float>( a_wf[iS] );
116  returnIntegral += sampleVal-a_baseline;
117  }
118  if(a_negPulse)
119  {
120  returnIntegral = -returnIntegral;
121  }
122  return returnIntegral;
123 }
124 
125 
128  template <class T> std::vector<std::pair<int,int>>
130  uint a_num,
131  float a_baseline,
132  float a_max
133  )
134 {
135  std::vector<std::pair<int,int>> results;
136  int start = 0;
137  int stop = 0;
138  //-1 on the stop condition to allow for checking the next sample
139  for(int iS = 0; iS < a_num-1;iS++)
140  {
141  if(a_wf[iS] - a_baseline> a_max)
142  {
143  start = iS;
144  int iSOv = iS+1;
145  for(;iSOv<a_num;iSOv++)
146  {
147  if(a_wf[iSOv] - a_baseline < a_max)
148  {
149  break;
150  }
151  }
152  stop = iSOv;
153  iS = iSOv;
154  results.push_back(std::make_pair(start,stop));
155  }
156  }
157  return results;
158 }
161  template <class T> std::vector<std::pair<int,int>>
163  uint a_num,
164  float a_baseline,
165  float a_max
166  )
167 {
168  std::vector<std::pair<int,int>> results;
169  int start = 0;
170  int stop = 0;
171  //-1 on the stop condition to allow for checking the next sample
172  for(int iS = 0; iS < a_num-1;iS++)
173  {
174  //magnitude of the negative deviation (positve )
175  if(a_baseline - a_wf[iS] > a_max)
176  {
177  start = iS;
178  int iSOv = iS+1;
179  for(;iSOv<a_num;iSOv++)
180  {
181  if(a_baseline - a_wf[iSOv] < a_max)
182  {
183  break;
184  }
185  }
186  stop = iSOv;
187  iS = iSOv;
188  results.push_back(std::make_pair(start,stop));
189  }
190  }
191  return results;
192 }
193 
195  template <class T> std::vector<std::complex<double>> WFOperations::
196  getWfFFT(T* a_wf,
197  int a_range)
198 {
200  std::vector<double> wfVec(a_wf, a_wf+a_range);
201 
202  unsigned long n = a_range;
204  int m = log2(n);
205  std::vector< std::complex < double > > f(n);
206  std::vector< std::complex < double > > fHat(n);
207 
209  for(int i = 0; i < a_range; i++)
210  {
211  f[i] = {wfVec[i], 0};
212  }
213  FFT1DBRI op(m);
214  op.forwardFFTCC(fHat,f);
215  double norm = 1.0/(double)sqrt(n);
216  for( auto & eL : fHat )
217  {
218  eL*=norm;
219  }
220  return fHat;
221 }
Definition: FFT1DBRI.H:11
virtual void forwardFFTCC(std::vector< std::complex< double > > &a_fHat, const std::vector< std::complex< double > > &f) const
Definition: FFT1DBRI.cpp:21
static unsigned long upper_power_of_two(unsigned long v)
Definition: NSDPhysicsCalcs.h:496
static std::vector< std::pair< int, int > > overThreshold(T *a_wf, uint a_num, float a_baseline, float a_max)
Definition: WFOperations.hpp:129
static float getCFD(T *a_wf, uint a_num, float a_mean, float a_frac, bool a_negPulse)
Definition: WFOperations.hpp:77
static std::vector< std::complex< double > > getWfFFT(T *a_wf, int a_range)
For FFT stuff - Added 01/30/24.
Definition: WFOperations.hpp:196
static int findSampleLeadingEdgeTrig(T *a_wf, uint a_num, float a_baseline, float a_threshold)
Definition: WFOperations.hpp:89
static float estimateBaseline(T *a_wf, uint a_num)
this function averages the number of samples specified
Definition: WFOperations.hpp:6
static std::vector< std::pair< int, int > > underThreshold(T *a_wf, uint a_num, float a_baseline, float a_max)
Definition: WFOperations.hpp:162
static float integrateTrace(T *a_wf, float a_baseline, int a_startSample, int a_stopSample, bool a_negPulse)
Definition: WFOperations.hpp:106
static void estimateBaselineDel(T *a_wf, uint a_num, float a_baseline, float &a_Dmax)
Definition: WFOperations.hpp:40