CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Utility.cc
Go to the documentation of this file.
2 #include <algorithm>
3 
4 // ----------------------------------------------------------------------------
5 //
7  : x_(),
8  y_(),
9  e_(),
10  ss_(0.),
11  sx_(0.),
12  sy_(0.)
13 {;}
14 
15 // ----------------------------------------------------------------------------
16 //
17 void sistrip::LinearFit::add( const float& x,
18  const float& y ) {
19  float e = 1.; // default
20  x_.push_back(x);
21  y_.push_back(y);
22  e_.push_back(e);
23  float wt = 1. / sqrt(e);
24  ss_ += wt;
25  sx_ += x*wt;
26  sy_ += y*wt;
27 }
28 
29 // ----------------------------------------------------------------------------
30 //
31 void sistrip::LinearFit::add( const float& x,
32  const float& y,
33  const float& e ) {
34  if ( e > 0. ) {
35  x_.push_back(x);
36  y_.push_back(y);
37  e_.push_back(e);
38  float wt = 1. / sqrt(e);
39  ss_ += wt;
40  sx_ += x*wt;
41  sy_ += y*wt;
42  }
43 }
44 
45 // ----------------------------------------------------------------------------
46 //
48 
49  float s2 = 0.;
50  float b = 0;
51  for ( uint16_t i = 0; i < x_.size(); i++ ) {
52  float t = ( x_[i] - sx_/ss_ ) / e_[i];
53  s2 += t*t;
54  b += t * y_[i] / e_[i];
55  }
56 
57  // Set parameters
58  params.n_ = x_.size();
59  params.b_ = b / s2;
60  params.a_ = ( sy_ - sx_ * params.b_ ) / ss_;
61  params.erra_ = sqrt( ( 1. + (sx_*sx_) / (ss_*s2) ) / ss_ );
62  params.errb_ = sqrt( 1. / s2 );
63 
64  /*
65  params.chi2_ = 0.;
66  *q=1.0;
67  if (mwt == 0) {
68  for (i=1;i<=ndata;i++)
69  *chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
70  sigdat=sqrt((*chi2)/(ndata-2));
71  *sigb *= sigdat;
72  */
73 
74 }
75 
76 // ----------------------------------------------------------------------------
77 //
79  : s_(0.),
80  x_(0.),
81  xx_(0.),
82  vec_()
83 {;}
84 
85 // ----------------------------------------------------------------------------
86 //
87 void sistrip::MeanAndStdDev::add( const float& x,
88  const float& e ) {
89  if ( e > 0. ) {
90  float wt = 1. / sqrt(e);
91  s_ += wt;
92  x_ += x*wt;
93  xx_ += x*x*wt;
94  } else {
95  s_++;
96  x_ += x;
97  xx_ += x*x;
98  }
99  vec_.push_back(x);
100 }
101 
102 // ----------------------------------------------------------------------------
103 //
105  if ( s_ > 0. ) {
106  float m = x_/s_;
107  float t = xx_/s_ - m*m;
108  if ( t > 0. ) { t = sqrt(t); }
109  else { t = 0.; }
110  params.mean_ = m;
111  params.rms_ = t;
112  }
113  if ( !vec_.empty() ) {
114  sort( vec_.begin(), vec_.end() );
115  uint16_t index = vec_.size()%2 ? vec_.size()/2 : vec_.size()/2-1;
116  params.median_ = vec_[index];
117  }
118 }
int i
Definition: DBlmapReader.cc:9
tuple s2
Definition: indexGen.py:106
T sqrt(T t)
Definition: SSEVec.h:46
void add(const float &value_x, const float &value_y)
Definition: Utility.cc:17
double b
Definition: hdecay.h:120
void add(const float &value, const float &error)
Definition: Utility.cc:87
void fit(Params &fit_params)
Definition: Utility.cc:47
x
Definition: VDTMath.h:216
void fit(Params &fit_params)
Definition: Utility.cc:104