CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Base_Constrainer.h
Go to the documentation of this file.
1 //
2 // $Id: Base_Constrainer.h,v 1.1 2011/05/26 09:46:52 mseidel Exp $
3 //
4 // File: hitfit/Base_Constrainer.h
5 // Purpose: Abstract base for the chisq fitter classes.
6 // This allows for different algorithms to be used.
7 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
8 //
9 // CMSSW File : interface/Base_Constrainer.h
10 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
11 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
12 
38 #ifndef HITFIT_BASE_CONSTRAINER_H
39 #define HITFIT_BASE_CONSTRAINER_H
40 
41 
43 #include <iosfwd>
44 
45 
46 namespace hitfit {
47 
48 class Defaults;
49 
50 
51 //*************************************************************************
52 
53 
60 //
61 // Purpose: Hold on to parameters for the Base_Constrainer class.
62 //
63 // Parameters:
64 // bool test_gradient - If true, check the constraint gradient calculations
65 // by also doing them numerically.
66 // float test_step - When test_gradient is true, the step size to use
67 // for numeric differentiation.
68 // float test_eps - When test_gradient is true, the maximum relative
69 // difference permitted between returned and
70 // numerically calculated gradients.
71 //
72 {
73 public:
74  // Constructor. Initialize from a Defaults object.
75 
85  Base_Constrainer_Args (const Defaults& defs);
86 
87  // Retrieve parameter values.
91  bool test_gradient () const;
92 
96  double test_step () const;
97 
101  double test_eps () const;
102 
103 
104 private:
105 
106  // Hold on to parameter values.
107 
113 
118  double _test_step;
119 
124  double _test_eps;
125 
126 };
127 
128 
129 //*************************************************************************
130 
131 
141 //
142 // Purpose: Abstract base class for evaluating constraints.
143 // Derive from this and implement the eval() method.
144 //
145 {
146 public:
147  // Constructor, destructor. Pass in the number of constraints.
148 
154 
159 
160  // Get back the number of constraints.
164  int nconstraints () const;
165 
166  // Evaluate constraints at the point described by X and Y (well-measured
167  // and poorly-measured variables, respectively). The results should
168  // be stored in F. BX and BY should be set to the gradients of F with
169  // respect to X and Y, respectively.
170  //
171  // Return true if the point X, Y is accepted.
172  // Return false if it is rejected (i.e., in an unphysical region).
173  // The constraints need not be evaluated in that case.
174 
205  virtual bool eval (const Column_Vector& x,
206  const Column_Vector& y,
207  Row_Vector& F,
208  Matrix& Bx,
209  Matrix& By) = 0;
210 
211 
212 private:
213  // The number of constraint functions.
218 
219 };
220 
221 
222 //*************************************************************************
223 
224 
230 //
231 // Purpose: Base class for chisq constrained fitter.
232 //
233 {
234 public:
235  // Constructor, destructor.
236  // ARGS holds the parameter settings for this instance.
237 
243 
247  virtual ~Base_Constrainer () {}
248 
249  // Do the fit.
250  // Call the number of well-measured variables Nw, the number of
251  // poorly-measured variables Np, and the number of constraints Nc.
252  // Inputs:
253  // CONSTRAINT_CALCULATOR is the object that will be used to evaluate
254  // the constraints.
255  // XM(Nw) and YM(Np) are the measured values of the well- and
256  // poorly-measured variables, respectively.
257  // X(Nw) and Y(Np) are the starting values for the fit.
258  // G_I(Nw,Nw) is the error matrix for the well-measured variables.
259  // Y(Np,Np) is the inverse error matrix for the poorly-measured variables.
260  //
261  // Outputs:
262  // X(Nw) and Y(Np) is the point at the minimum.
263  // PULLX(Nw) and PULLY(Np) are the pull quantities.
264  // Q(Nw,Nw), R(Np,Np), and S(Nw,Np) are the final error matrices
265  // between all the variables.
266  //
267  // The return value is the final chisq. Returns a value < 0 if the
268  // fit failed to converge.
269 
321  virtual double fit (Constraint_Calculator& constraint_calculator,
322  const Column_Vector& xm,
323  Column_Vector& x,
324  const Column_Vector& ym,
325  Column_Vector& y,
326  const Matrix& G_i,
327  const Diagonal_Matrix& Y,
328  Column_Vector& pullx,
329  Column_Vector& pully,
330  Matrix& Q,
331  Matrix& R,
332  Matrix& S) = 0;
333 
334  // Print out any internal state to S.
344  virtual std::ostream& print (std::ostream& s) const;
345 
346  // Print out internal state to S.
347  friend std::ostream& operator<< (std::ostream& s, const Base_Constrainer& f);
348 
349 
350 private:
351  // Parameter settings.
352 
357 
358 
359 protected:
360  // Helper function to evaluate the constraints.
361  // This takes care of checking what the user function returns against
362  // numerical derivatives, if that was requested.
363 
403  bool call_constraint_fcn (Constraint_Calculator& constraint_calculator,
404  const Column_Vector& x,
405  const Column_Vector& y,
406  Row_Vector& F,
407  Matrix& Bx,
408  Matrix& By) const;
409 };
410 
411 
412 } // namespace hitfit
413 
414 
415 #endif // not HITFIT_BASE_CONSTRAINER_H
416 
CLHEP::HepVector Column_Vector
Definition: matutil.h:67
Define matrix types for the HitFit package, and supply a few additional operations.
Abstract base class for evaluating constraints. Users derive from this class and implement the eval()...
CLHEP::HepMatrix Matrix
Definition: matutil.h:66
Constraint_Calculator(int nconstraints)
Base class for constrained fitter.
Base_Constrainer(const Base_Constrainer_Args &args)
friend std::ostream & operator<<(std::ostream &s, const Base_Constrainer &f)
Output stream operator, print the content of this Base_Constrainer to an output stream.
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 a...
double f[11][100]
Base_Constrainer_Args(const Defaults &defs)
Hold on to parameters for the Base_Constrainer class.
virtual bool eval(const Column_Vector &x, const Column_Vector &y, Row_Vector &F, Matrix &Bx, Matrix &By)=0
Evaluate constraints at the point described by x and y (well-measured and poorly-measured variables...
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:68
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 constrained fit.
const Base_Constrainer_Args _args
dictionary args
Define an interface for getting parameter settings.
Definition: Defaults.h:62
Definition: DDAxes.h:10
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
virtual std::ostream & print(std::ostream &s) const
Print out internal state to output stream.
Row-vector class. CLHEP doesn&#39;t have a row-vector class, so HitFit uses its own. This is only a simpl...
Definition: matutil.h:84