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 211 of file Base_Constrainer.h.

Constructor & Destructor Documentation

◆ Base_Constrainer()

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

Constructor.

Parameters
argsContains the parameter settings for this instance.

Definition at line 156 of file Base_Constrainer.cc.

163  : _args(args) {}
const Base_Constrainer_Args _args

◆ ~Base_Constrainer()

virtual hitfit::Base_Constrainer::~Base_Constrainer ( )
inlinevirtual

Destructor.

Definition at line 229 of file Base_Constrainer.h.

229 {}

Member Function Documentation

◆ call_constraint_fcn()

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

References gather_cfg::cout, F(), mps_fire::i, dqmiolumiharvest::j, heppy_batch::val, and x.

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

234  {
235  // Call the user's function.
236  bool val = constraint_calculator.eval(x, y, F, Bx, By);
237 
238  // If we're not doing gradients numerically, we're done.
239  if (!_args.test_gradient())
240  return val;
241 
242  // Bail if the point was rejected.
243  if (!val)
244  return false;
245 
246  int Nw = x.num_row();
247  int Np = y.num_row();
248  int Nc = F.num_col();
249 
250  // Numerically check Bx.
251  for (int i = 1; i <= Nc; i++) {
252  // Step a little along variable I.
253  Column_Vector step_x(Nw, 0);
254  step_x(i) = _args.test_step();
255  Column_Vector new_x = x + step_x;
256 
257  // Evaluate the constraints at the new point.
258  Matrix new_Bx(Nw, Nc);
259  Matrix new_By(Np, Nc);
260  Row_Vector new_F(Nc);
261  if (!constraint_calculator.eval(new_x, y, new_F, new_Bx, new_By))
262  return false;
263 
264  // Calculate what we expect the constraints to be at this point,
265  // given the user's gradients.
266  Row_Vector test_F = F + step_x.T() * Bx;
267 
268  // Check the results.
269  for (int j = 1; j <= Nc; j++) {
270  if (test_different(test_F(j), new_F(j), F(j), _args.test_eps())) {
271  cout << "bad gradient x " << i << " " << j << "\n";
272  cout << x;
273  cout << y;
274  cout << new_x;
275  cout << F;
276  cout << new_F;
277  cout << Bx;
278  cout << (test_F - new_F);
279  abort();
280  }
281  }
282  }
283 
284  // Numerically check By.
285  for (int i = 1; i <= Np; i++) {
286  // Step a little along variable I.
287  Column_Vector step_y(Np, 0);
288  step_y(i) = _args.test_step();
289  Column_Vector new_y = y + step_y;
290 
291  // Evaluate the constraints at the new point.
292  Matrix new_Bx(Nw, Nc);
293  Matrix new_By(Np, Nc);
294  Row_Vector new_F(Nc);
295  if (!constraint_calculator.eval(x, new_y, new_F, new_Bx, new_By))
296  return false;
297 
298  // Calculate what we expect the constraints to be at this point,
299  // given the user's gradients.
300  Row_Vector test_F = F + step_y.T() * By;
301 
302  // Check the results.
303  for (int j = 1; j <= Nc; j++) {
304  if (test_different(test_F(j), new_F(j), F(j), _args.test_eps())) {
305  cout << "bad gradient y " << i << " " << j << "\n";
306  cout << x;
307  cout << y;
308  cout << new_y;
309  cout << F;
310  cout << new_F;
311  cout << Bx;
312  cout << (test_F - new_F);
313  abort();
314  }
315  }
316  }
317 
318  // Done!
319  return true;
320  }
CLHEP::HepVector Column_Vector
Definition: matutil.h:63
CLHEP::HepMatrix Matrix
Definition: matutil.h:62
const Base_Constrainer_Args _args
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163

◆ fit()

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().

◆ print()

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

References alignCSCRings::s.

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

175  {
176  s << "Base_Constrainer parameters:\n";
177  s << " test_gradient: " << _args.test_gradient() << " test_step: " << _args.test_step()
178  << " test_eps: " << _args.test_eps() << "\n";
179  return s;
180  }
const Base_Constrainer_Args _args

Friends And Related Function Documentation

◆ operator<<

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

202  {
203  return f.print(s);
204  }
double f[11][100]

Member Data Documentation

◆ _args

const Base_Constrainer_Args hitfit::Base_Constrainer::_args
private

Parameter settings for this instance of Base_Constrainer.

Definition at line 337 of file Base_Constrainer.h.