CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Private Attributes | Friends

hitfit::Base_Constrainer Class Reference

Base class for $\chi^{2}$ constrained fitter. More...

#include <Base_Constrainer.h>

Inheritance diagram for hitfit::Base_Constrainer:
hitfit::Chisq_Constrainer

List of all members.

Public Member Functions

 Base_Constrainer (const Base_Constrainer_Args &args)
virtual double fit (Constraint_Calculator &constraint_calculator, const Column_Vector &xm, Column_Vector &x, const Column_Vector &ym, Column_Vector &y, const Matrix &G_i, const Diagonal_Matrix &Y, Column_Vector &pullx, Column_Vector &pully, Matrix &Q, Matrix &R, Matrix &S)=0
 Perform the $\chi^{2}$ constrained fit.
virtual std::ostream & print (std::ostream &s) const
 Print out internal state to output stream.
virtual ~Base_Constrainer ()

Protected Member Functions

bool call_constraint_fcn (Constraint_Calculator &constraint_calculator, const Column_Vector &x, const Column_Vector &y, Row_Vector &F, Matrix &Bx, Matrix &By) const
 Helper function to evaluate constraints. This takes care of checking what the user function returns againts numerical derivatives, it that was requested.

Private Attributes

const Base_Constrainer_Args _args

Friends

std::ostream & operator<< (std::ostream &s, const Base_Constrainer &f)
 Output stream operator, print the content of this Base_Constrainer to an output stream.

Detailed Description

Base class for $\chi^{2}$ constrained fitter.

Definition at line 229 of file Base_Constrainer.h.


Constructor & Destructor Documentation

hitfit::Base_Constrainer::Base_Constrainer ( const Base_Constrainer_Args args)

Constructor.

Parameters:
argsContains the parameter settings for this instance.

Definition at line 175 of file Base_Constrainer.cc.

  : _args (args)
{
}
virtual hitfit::Base_Constrainer::~Base_Constrainer ( ) [inline, virtual]

Destructor.

Definition at line 247 of file Base_Constrainer.h.

{}

Member Function Documentation

bool hitfit::Base_Constrainer::call_constraint_fcn ( Constraint_Calculator constraint_calculator,
const Column_Vector x,
const Column_Vector y,
Row_Vector F,
Matrix Bx,
Matrix By 
) const [protected]

Helper function to evaluate constraints. This takes care of checking what the user function returns againts numerical derivatives, it that was requested.

Purpose
Call the constraint function for the point (x,y). Return F, Bx, By, and a boolean flag saying if the point is acceptable. If test_gradient is on, we verify the gradients returned by also computing them numerically.
Parameters:
constraint_calculatorthe User-supplied object to evaluate the constraints.
xVector of well-measured quantities where we evaluate the constraints. Has dimension of Nw.
yVector of poorly-measured quantities where we evaluate the the constraints. Has dimension of Np.
FResults of the constraint functions.
BxGradients of F with respect to x, has dimension (Nw,Nc).
ByGradients of F with respect to y, has dimension (Np,Nc).
Input:
constraint_calculator, x, y.
Output:
F, Bx, By.
Return:
true if the point (x,y) is accepted.
false if the point (x,y) is rejected

Definition at line 231 of file Base_Constrainer.cc.

References gather_cfg::cout, F(), i, j, x, and detailsBasic3DVector::y.

Referenced by hitfit::Chisq_Constrainer::fit().

{
  // Call the user's function.
  bool val = constraint_calculator.eval (x, y, F, Bx, By);

  // If we're not doing gradients numerically, we're done.
  if (!_args.test_gradient())
    return val;

  // Bail if the point was rejected.
  if (!val)
    return false;

  int Nw = x.num_row();
  int Np = y.num_row();
  int Nc = F.num_col();

  // Numerically check Bx.
  for (int i=1; i<=Nc; i++) {
    // Step a little along variable I.
    Column_Vector step_x (Nw, 0);
    step_x(i) = _args.test_step();
    Column_Vector new_x = x + step_x;

    // Evaluate the constraints at the new point.
    Matrix new_Bx (Nw, Nc);
    Matrix new_By (Np, Nc);
    Row_Vector new_F (Nc);
    if (! constraint_calculator.eval (new_x, y, new_F, new_Bx, new_By))
      return false;

    // Calculate what we expect the constraints to be at this point,
    // given the user's gradients.
    Row_Vector test_F = F + step_x.T() * Bx;

    // Check the results.
    for (int j=1; j<=Nc; j++) {
      if (test_different (test_F(j), new_F(j), F(j), _args.test_eps())) {
        cout << "bad gradient x " << i << " " << j << "\n";
        cout << x;
        cout << y;
        cout << new_x;
        cout << F;
        cout << new_F;
        cout << Bx;
        cout << (test_F - new_F);
        abort ();
      }
    }
  }

  // Numerically check By.
  for (int i=1; i<=Np; i++) {
    // Step a little along variable I.
    Column_Vector step_y (Np, 0);
    step_y(i) = _args.test_step();
    Column_Vector new_y = y + step_y;

    // Evaluate the constraints at the new point.
    Matrix new_Bx (Nw, Nc);
    Matrix new_By (Np, Nc);
    Row_Vector new_F (Nc);
    if (! constraint_calculator.eval (x, new_y, new_F, new_Bx, new_By))
      return false;

    // Calculate what we expect the constraints to be at this point,
    // given the user's gradients.
    Row_Vector test_F = F + step_y.T() * By;

    // Check the results.
    for (int j=1; j<=Nc; j++) {
      if (test_different (test_F(j), new_F(j), F(j), _args.test_eps())) {
        cout << "bad gradient y " << i << " " << j << "\n";
        cout << x;
        cout << y;
        cout << new_y;
        cout << F;
        cout << new_F;
        cout << Bx;
        cout << (test_F - new_F);
        abort ();
      }
    }
  }

  // Done!
  return true;
}
virtual double hitfit::Base_Constrainer::fit ( Constraint_Calculator constraint_calculator,
const Column_Vector xm,
Column_Vector x,
const Column_Vector ym,
Column_Vector y,
const Matrix G_i,
const Diagonal_Matrix Y,
Column_Vector pullx,
Column_Vector pully,
Matrix Q,
Matrix R,
Matrix S 
) [pure virtual]

Perform the $\chi^{2}$ constrained fit.

Parameters:
constraint_calculatorThe object that will be used to evaluate the constraints.
xmMeasured values of the well-measured variables, has dimension Nw.
xBefore the fit: starting value of the well-measured variables for the fit, has dimension Nw. After the fit: final values of the well-measured variables.
ymMeasured values of the poorly-measured variables, has dimension Np.
yBefore the fit: starting value of the poorly-measured variables for the fit, has dimension Np. After the fit: final values of the poorly-measured variables.
G_iError matrix for the well-measured variables, has dimension Nw,Nw.
YInverse error matrix for the poorly-measured variables, has dimension Np,Np.
pullxPull quantities for the well-measured variables, has dimension Nw.
pullyPull quantities for the poorly-measured variables, has dimension Np.
QError matrix for the well-measured variables, has dimension Nw,Nw.
RError matrix for the poorly-measured variables, has dimension Np,Np.
SError matrix for the correlation between well-measured variables and poorly-measured variables, has dimension Nw,Np.
Input:
constraint_calculator, xm, x, ym, y, G_i, y.
Output:
x, y, pullx, pully, Q, R, S.
Return:
$\chi^{2}$ of the fit. Should returns a negative value if the fit does not converge.

Implemented in hitfit::Chisq_Constrainer.

std::ostream & hitfit::Base_Constrainer::print ( std::ostream &  s) const [virtual]

Print out internal state to output stream.

Parameters:
sOutput stream to which to write.
Return:
The stream s;

Reimplemented in hitfit::Chisq_Constrainer.

Definition at line 187 of file Base_Constrainer.cc.

References alignCSCRings::s.

Referenced by hitfit::operator<<(), and hitfit::Chisq_Constrainer::print().

{
  s << "Base_Constrainer parameters:\n";
  s << " test_gradient: " << _args.test_gradient()
    << " test_step: " << _args.test_step()
    << " test_eps: " << _args.test_eps() << "\n";
  return s;
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const Base_Constrainer f 
) [friend]

Output stream operator, print the content of this Base_Constrainer to an output stream.

Parameters:
sThe output stream to which to write.
fThe instance of Base_Constrainer to be printed.

Definition at line 215 of file Base_Constrainer.cc.

{
  return f.print (s);
}

Member Data Documentation

Parameter settings for this instance of Base_Constrainer.

Reimplemented in hitfit::Chisq_Constrainer.

Definition at line 356 of file Base_Constrainer.h.