CMS 3D CMS Logo

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