NSCL DDAS  1.0
Support for XIA DDAS at the NSCL
 All Classes Namespaces Files Functions Variables Macros Pages
BaseLineProcessor.hpp
1 // BaseLineProcessor.hpp
2 //
3 // Author : Jeromy Tompkins
4 // Date : 8/14/2013
5 
6 #ifndef BASELINEPROCESSOR_H
7 #define BASELINEPROCESSOR_H
8 
9 #include "Trace.hpp"
10 #include <cmath>
11 #include "Exceptions.h"
12 #include <TObject.h>
13 
14 namespace TrAnal
15 {
16 
19 {
20  public:
21  double mean;
22  double stdev;
23 
24  // ROOT dict generation
26  ClassDef(BaseLineProcResult,1);
28 };
29 
30 
32 
36 template<class T>
37 double ComputeMean(const TrIterator<T>& begin, const TrIterator<T>& end)
38 {
39 
40  double sum=0;
41  double n=0;
42  TrIterator<T> it=begin;
43  while (it<end)
44  {
45  // access element
46  sum += *it;
47  ++n;
48 
49  // increment iterator
50  ++it;
51  }
52 
53  return sum/n;
54 }
55 
57 
68 template<class T>
69 double ComputeStDev(const TrIterator<T>& begin, const TrIterator<T>& end, double mean)
70 {
71 
72  double stdev2 =0;
73  double tmpdiff = 0;
74 
75  double n=0;
76 
77  TrIterator<T> it=begin;
78  while ( it<end )
79  {
80  tmpdiff = (*it-mean);
81  stdev2 += ::pow(tmpdiff,2.0);
82  ++n;
83 
84  ++it;
85  }
86 
87  return ::sqrt(stdev2 / (n - 1.0));
88 }
89 
91 
96 template<class T>
97 BaseLineProcResult ComputeBaseLine(const TrIterator<T>& begin, const TrIterator<T>& end)
98 {
99  double mean = ComputeMean<T>(begin, end);
100  double stdev = ComputeStDev<T>(begin, end, mean);
101 
102  BaseLineProcResult res;
103  res.mean = mean;
104  res.stdev = stdev;
105  return res;
106 }
107 
108 } // end namespace
109 #endif
TrIterator template class.
Definition: TrIterator.hpp:24
double stdev
std. dev. of values within range
Definition: BaseLineProcessor.hpp:22
Result of the ComputeBaseline function.
Definition: BaseLineProcessor.hpp:18
Definition: AlgoIterator.hpp:12
double mean
mean of values within range
Definition: BaseLineProcessor.hpp:21