CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes | Friends
hitfit::Base_Constrainer Class Referenceabstract

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

#include <Base_Constrainer.h>

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

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. More...
 
virtual std::ostream & print (std::ostream &s) const
 Print out internal state to output stream. More...
 
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. More...
 

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. More...
 

Detailed Description

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

Definition at line 228 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 174 of file Base_Constrainer.cc.

181  : _args (args)
182 {
183 }
const Base_Constrainer_Args _args
virtual hitfit::Base_Constrainer::~Base_Constrainer ( )
inlinevirtual

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 230 of file Base_Constrainer.cc.

References _args, gather_cfg::cout, F(), mps_fire::i, hitfit::Base_Constrainer_Args::test_eps(), hitfit::Base_Constrainer_Args::test_gradient(), hitfit::Base_Constrainer_Args::test_step(), and heppy_batch::val.

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

259 {
260  // Call the user's function.
261  bool val = constraint_calculator.eval (x, y, F, Bx, By);
262 
263  // If we're not doing gradients numerically, we're done.
264  if (!_args.test_gradient())
265  return val;
266 
267  // Bail if the point was rejected.
268  if (!val)
269  return false;
270 
271  int Nw = x.num_row();
272  int Np = y.num_row();
273  int Nc = F.num_col();
274 
275  // Numerically check Bx.
276  for (int i=1; i<=Nc; i++) {
277  // Step a little along variable I.
278  Column_Vector step_x (Nw, 0);
279  step_x(i) = _args.test_step();
280  Column_Vector new_x = x + step_x;
281 
282  // Evaluate the constraints at the new point.
283  Matrix new_Bx (Nw, Nc);
284  Matrix new_By (Np, Nc);
285  Row_Vector new_F (Nc);
286  if (! constraint_calculator.eval (new_x, y, new_F, new_Bx, new_By))
287  return false;
288 
289  // Calculate what we expect the constraints to be at this point,
290  // given the user's gradients.
291  Row_Vector test_F = F + step_x.T() * Bx;
292 
293  // Check the results.
294  for (int j=1; j<=Nc; j++) {
295  if (test_different (test_F(j), new_F(j), F(j), _args.test_eps())) {
296  cout << "bad gradient x " << i << " " << j << "\n";
297  cout << x;
298  cout << y;
299  cout << new_x;
300  cout << F;
301  cout << new_F;
302  cout << Bx;
303  cout << (test_F - new_F);
304  abort ();
305  }
306  }
307  }
308 
309  // Numerically check By.
310  for (int i=1; i<=Np; i++) {
311  // Step a little along variable I.
312  Column_Vector step_y (Np, 0);
313  step_y(i) = _args.test_step();
314  Column_Vector new_y = y + step_y;
315 
316  // Evaluate the constraints at the new point.
317  Matrix new_Bx (Nw, Nc);
318  Matrix new_By (Np, Nc);
319  Row_Vector new_F (Nc);
320  if (! constraint_calculator.eval (x, new_y, new_F, new_Bx, new_By))
321  return false;
322 
323  // Calculate what we expect the constraints to be at this point,
324  // given the user's gradients.
325  Row_Vector test_F = F + step_y.T() * By;
326 
327  // Check the results.
328  for (int j=1; j<=Nc; j++) {
329  if (test_different (test_F(j), new_F(j), F(j), _args.test_eps())) {
330  cout << "bad gradient y " << i << " " << j << "\n";
331  cout << x;
332  cout << y;
333  cout << new_y;
334  cout << F;
335  cout << new_F;
336  cout << Bx;
337  cout << (test_F - new_F);
338  abort ();
339  }
340  }
341  }
342 
343  // Done!
344  return true;
345 }
CLHEP::HepVector Column_Vector
Definition: matutil.h:66
CLHEP::HepMatrix Matrix
Definition: matutil.h:65
const Base_Constrainer_Args _args
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
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.

Referenced by trackingPlots.Iteration::modules().

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 186 of file Base_Constrainer.cc.

References _args, alignCSCRings::s, hitfit::Base_Constrainer_Args::test_eps(), hitfit::Base_Constrainer_Args::test_gradient(), and hitfit::Base_Constrainer_Args::test_step().

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

196 {
197  s << "Base_Constrainer parameters:\n";
198  s << " test_gradient: " << _args.test_gradient()
199  << " test_step: " << _args.test_step()
200  << " test_eps: " << _args.test_eps() << "\n";
201  return s;
202 }
const Base_Constrainer_Args _args

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 214 of file Base_Constrainer.cc.

225 {
226  return f.print (s);
227 }
double f[11][100]

Member Data Documentation

const Base_Constrainer_Args hitfit::Base_Constrainer::_args
private

Parameter settings for this instance of Base_Constrainer.

Definition at line 355 of file Base_Constrainer.h.

Referenced by Vispa.Main.Application.Application::_readCommandLineAttributes(), call_constraint_fcn(), and print().