CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 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.

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

Destructor.

Definition at line 247 of file Base_Constrainer.h.

247 {}

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, vdt::x, and detailsBasic3DVector::y.

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

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

197 {
198  s << "Base_Constrainer parameters:\n";
199  s << " test_gradient: " << _args.test_gradient()
200  << " test_step: " << _args.test_step()
201  << " test_eps: " << _args.test_eps() << "\n";
202  return s;
203 }
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 215 of file Base_Constrainer.cc.

226 {
227  return f.print (s);
228 }
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 356 of file Base_Constrainer.h.

Referenced by Vispa.Main.Application.Application::_readCommandLineAttributes().