CMS 3D CMS Logo

Classes | Public Member Functions | Private Attributes

sistrip::LinearFit Class Reference

#include <Utility.h>

List of all members.

Classes

class  Params

Public Member Functions

void add (const float &value_x, const float &value_y)
void add (const float &value_x, const float &value_y, const float &error_y)
void fit (Params &fit_params)
 LinearFit ()
 ~LinearFit ()

Private Attributes

std::vector< float > e_
float ss_
float sx_
float sy_
std::vector< float > x_
std::vector< float > y_

Detailed Description

Definition at line 11 of file Utility.h.


Constructor & Destructor Documentation

LinearFit::LinearFit ( )

Definition at line 6 of file Utility.cc.

  : x_(),
    y_(),
    e_(),
    ss_(0.),
    sx_(0.),
    sy_(0.) 
{;}
sistrip::LinearFit::~LinearFit ( ) [inline]

Definition at line 17 of file Utility.h.

{;}

Member Function Documentation

void LinearFit::add ( const float &  value_x,
const float &  value_y 
)

Definition at line 17 of file Utility.cc.

References mathSSE::sqrt().

Referenced by OptoScanAlgorithm::analyse().

                                               {
  float e = 1.; // default
  x_.push_back(x);
  y_.push_back(y);
  e_.push_back(e);
  float wt = 1. / sqrt(e); 
  ss_ += wt;
  sx_ += x*wt;
  sy_ += y*wt;
}
void LinearFit::add ( const float &  value_x,
const float &  value_y,
const float &  error_y 
)

Definition at line 31 of file Utility.cc.

References mathSSE::sqrt().

                                               {
  if ( e > 0. ) { 
    x_.push_back(x);
    y_.push_back(y);
    e_.push_back(e);
    float wt = 1. / sqrt(e); 
    ss_ += wt;
    sx_ += x*wt;
    sy_ += y*wt;
  } 
}
void LinearFit::fit ( Params fit_params)

Definition at line 47 of file Utility.cc.

References sistrip::LinearFit::Params::a_, b, sistrip::LinearFit::Params::b_, sistrip::LinearFit::Params::erra_, sistrip::LinearFit::Params::errb_, i, sistrip::LinearFit::Params::n_, indexGen::s2, mathSSE::sqrt(), and matplotRender::t.

Referenced by OptoScanAlgorithm::analyse().

                                           {

  float s2 = 0.;
  float b = 0;
  for ( uint16_t i = 0; i < x_.size(); i++ ) {
    float t = ( x_[i] - sx_/ss_ ) / e_[i]; 
    s2 += t*t;
    b += t * y_[i] / e_[i];
  }
  
  // Set parameters
  params.n_ = x_.size();
  params.b_ = b / s2;
  params.a_ = ( sy_ - sx_ * params.b_ ) / ss_;
  params.erra_ = sqrt( ( 1. + (sx_*sx_) / (ss_*s2) ) / ss_ );
  params.errb_ = sqrt( 1. / s2 );
  
  /*
    params.chi2_ = 0.;
    *q=1.0;
    if (mwt == 0) {
    for (i=1;i<=ndata;i++)
    *chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
    sigdat=sqrt((*chi2)/(ndata-2));
    *sigb *= sigdat;
    */    
  
}

Member Data Documentation

std::vector<float> sistrip::LinearFit::e_ [private]

Definition at line 48 of file Utility.h.

float sistrip::LinearFit::ss_ [private]

Definition at line 49 of file Utility.h.

float sistrip::LinearFit::sx_ [private]

Definition at line 50 of file Utility.h.

float sistrip::LinearFit::sy_ [private]

Definition at line 51 of file Utility.h.

std::vector<float> sistrip::LinearFit::x_ [private]

Definition at line 46 of file Utility.h.

std::vector<float> sistrip::LinearFit::y_ [private]

Definition at line 47 of file Utility.h.