CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Chisq_Constrainer.h
Go to the documentation of this file.
1 //
2 // $Id: Chisq_Constrainer.h,v 1.2 2011/10/13 09:49:48 snaumann Exp $
3 //
4 // File: hitfit/Chisq_Constrainer.h
5 // Purpose: Minimize a chisq subject to a set of constraints.
6 // Based on the SQUAW algorithm.
7 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
8 //
9 // For full details on the algorithm, see
10 //
11 // @phdthesis{sssthesis,
12 // author = "Scott Snyder",
13 // school = "State University of New York at Stony Brook",
14 // month = may,
15 // year = "1995 (unpublished)"}
16 // @comment{ note = "available from {\tt http://www-d0.fnal.gov/publications\_talks/thesis/ snyder/thesis-ps.html}"
17 // }
18 //
19 // CMSSW File : interface/Chisq_Constrainer.h
20 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
21 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
22 
67 #ifndef HITFIT_CHISQ_CONSTRAINER_H
68 #define HITFIT_CHISQ_CONSTRAINER_H
69 
72 #include <iosfwd>
73 
74 
75 namespace hitfit {
76 
77 
78 class Defaults;
79 
80 
86 //
87 // Purpose: Hold on to parameters for the Chisq_Constrainer class.
88 //
89 // Parameters controlling the operation of the fitter:
90 // bool printfit - If true, print a trace of the fit to cout.
91 // bool use_G - If true, check the chisq formula by computing
92 // chisq directly from G. This requires that G_i
93 // be invertable.
94 //
95 // Parameters affecting the fit:
96 // float constraint_sum_eps - Convergence threshold for sum of constraints.
97 // float chisq_diff_eps - onvergence threshold for change in chisq.
98 // int maxit - Maximum number of iterations permitted.
99 // int max_cut - Maximum number of cut steps permitted.
100 // float cutsize - Fraction by which to cut steps.
101 // float min_tot_cutsize - Smallest fractional cut step permitted.
102 //
103 // Parameters affecting testing modes:
104 // float chisq_test_eps - When use_G is true, the maximum relative
105 // difference permitted between the two chisq
106 // calculations.
107 //
108 {
109 public:
110  // Constructor. Initialize from a Defaults object.
111 
129  Chisq_Constrainer_Args (const Defaults& defs);
130 
131  // Retrieve parameter values.
132 
136  bool printfit () const;
137 
141  bool use_G () const;
142 
146  double constraint_sum_eps () const;
147 
151  double chisq_diff_eps () const;
152 
156  unsigned maxit () const;
157 
161  unsigned max_cut () const;
162 
166  double cutsize () const;
167 
171  double min_tot_cutsize () const;
172 
176  double chisq_test_eps () const;
177 
178  // Arguments for subobjects.
179 
184 
185 
186 private:
187  // Hold on to parameter values.
188 
192  bool _printfit;
193 
199  bool _use_G;
200 
205 
210 
214  int _maxit;
215 
219  int _max_cut;
220 
224  double _cutsize;
225 
230 
236 
237 
242 };
243 
244 
245 //*************************************************************************
246 
247 
254 //
255 // Purpose: Minimize a chisq subject to a set of constraints.
256 // Based on the SQUAW algorithm.
257 //
258  : public Base_Constrainer
259 {
260 public:
261  // Constructor, destructor.
262  // ARGS holds the parameter settings for this instance.
263 
271 
275  virtual ~Chisq_Constrainer () {}
276 
277  // Do the fit.
278  // Call the number of well-measured variables Nw, the number of
279  // poorly-measured variables Np, and the number of constraints Nc.
280  // Inputs:
281  // CONSTRAINT_CALCULATOR is the object that will be used to evaluate
282  // the constraints.
283  // XM(Nw) and YM(Np) are the measured values of the well- and
284  // poorly-measured variables, respectively.
285  // X(Nw) and Y(Np) are the starting values for the fit.
286  // G_I(Nw,Nw) is the error matrix for the well-measured variables.
287  // Y(Np,Np) is the inverse error matrix for the poorly-measured variables.
288  //
289  // Outputs:
290  // X(Nw) and Y(Np) is the point at the minimum.
291  // PULLX(Nw) and PULLY(Np) are the pull quantities.
292  // Q(Nw,Nw), R(Np,Np), and S(Nw,Np) are the final error matrices
293  // between all the variables.
294  //
295  // The return value is the final chisq. Returns a value < 0 if the
296  // fit failed to converge.
297 
350  virtual double fit (Constraint_Calculator& constraint_calculator,
351  const Column_Vector& xm,
352  Column_Vector& x,
353  const Column_Vector& ym,
354  Column_Vector& y,
355  const Matrix& G_i,
356  const Diagonal_Matrix& Y,
357  Column_Vector& pullx,
358  Column_Vector& pully,
359  Matrix& Q,
360  Matrix& R,
361  Matrix& S);
362 
363  // Print out any internal state to S.
369  virtual std::ostream& print (std::ostream& s) const;
370 
371 
372 private:
373  // Parameter settings.
378 };
379 
380 } // namespace hitfit
381 
382 
383 #endif // not HITFIT_CHISQ_CONSTRAINER_H
384 
385 
const Base_Constrainer_Args & base_constrainer_args() const
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
Chisq_Constrainer(const Chisq_Constrainer_Args &args)
Base class for constrained fitter.
Chisq_Constrainer_Args(const Defaults &defs)
Constructor, creates an instance of Chisq_Constrainer_Args from a Defaults object.
const Base_Constrainer_Args _base_constrainer_args
Minimize a subject to a set of constraints. Based on the SQUAW algorithm.
virtual std::ostream & print(std::ostream &s) const
Print the state of this instance of Chisq_Constrainer.
Hold on to parameters for the Chisq_Constrainer class.
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)
Abstract base classes for the fitter classes.
Hold on to parameters for the Base_Constrainer class.
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:68
dictionary args
Define an interface for getting parameter settings.
Definition: Defaults.h:62
const Chisq_Constrainer_Args _args
Definition: DDAxes.h:10