CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Chisq_Constrainer.h
Go to the documentation of this file.
1 //
2 //
3 // File: hitfit/Chisq_Constrainer.h
4 // Purpose: Minimize a chisq subject to a set of constraints.
5 // Based on the SQUAW algorithm.
6 // Created: Jul, 2000, sss, based on run 1 mass analysis code.
7 //
8 // For full details on the algorithm, see
9 //
10 // @phdthesis{sssthesis,
11 // author = "Scott Snyder",
12 // school = "State University of New York at Stony Brook",
13 // month = may,
14 // year = "1995 (unpublished)"}
15 // @comment{ note = "available from {\tt http://www-d0.fnal.gov/publications\_talks/thesis/ snyder/thesis-ps.html}"
16 // }
17 //
18 // CMSSW File : interface/Chisq_Constrainer.h
19 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0
20 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch>
21 
65 #ifndef HITFIT_CHISQ_CONSTRAINER_H
66 #define HITFIT_CHISQ_CONSTRAINER_H
67 
70 #include <iosfwd>
71 
72 namespace hitfit {
73 
74  class Defaults;
75 
81  //
82  // Purpose: Hold on to parameters for the Chisq_Constrainer class.
83  //
84  // Parameters controlling the operation of the fitter:
85  // bool printfit - If true, print a trace of the fit to cout.
86  // bool use_G - If true, check the chisq formula by computing
87  // chisq directly from G. This requires that G_i
88  // be invertable.
89  //
90  // Parameters affecting the fit:
91  // float constraint_sum_eps - Convergence threshold for sum of constraints.
92  // float chisq_diff_eps - onvergence threshold for change in chisq.
93  // int maxit - Maximum number of iterations permitted.
94  // int max_cut - Maximum number of cut steps permitted.
95  // float cutsize - Fraction by which to cut steps.
96  // float min_tot_cutsize - Smallest fractional cut step permitted.
97  //
98  // Parameters affecting testing modes:
99  // float chisq_test_eps - When use_G is true, the maximum relative
100  // difference permitted between the two chisq
101  // calculations.
102  //
103  {
104  public:
105  // Constructor. Initialize from a Defaults object.
106 
124  Chisq_Constrainer_Args(const Defaults& defs);
125 
126  // Retrieve parameter values.
127 
131  bool printfit() const;
132 
136  bool use_G() const;
137 
141  double constraint_sum_eps() const;
142 
146  double chisq_diff_eps() const;
147 
151  unsigned maxit() const;
152 
156  unsigned max_cut() const;
157 
161  double cutsize() const;
162 
166  double min_tot_cutsize() const;
167 
171  double chisq_test_eps() const;
172 
173  // Arguments for subobjects.
174 
179 
180  private:
181  // Hold on to parameter values.
182 
186  bool _printfit;
187 
193  bool _use_G;
194 
199 
204 
208  int _maxit;
209 
213  int _max_cut;
214 
218  double _cutsize;
219 
224 
230 
235  };
236 
237  //*************************************************************************
238 
245  //
246  // Purpose: Minimize a chisq subject to a set of constraints.
247  // Based on the SQUAW algorithm.
248  //
249  : public Base_Constrainer {
250  public:
251  // Constructor, destructor.
252  // ARGS holds the parameter settings for this instance.
253 
261 
265  ~Chisq_Constrainer() override {}
266 
267  // Do the fit.
268  // Call the number of well-measured variables Nw, the number of
269  // poorly-measured variables Np, and the number of constraints Nc.
270  // Inputs:
271  // CONSTRAINT_CALCULATOR is the object that will be used to evaluate
272  // the constraints.
273  // XM(Nw) and YM(Np) are the measured values of the well- and
274  // poorly-measured variables, respectively.
275  // X(Nw) and Y(Np) are the starting values for the fit.
276  // G_I(Nw,Nw) is the error matrix for the well-measured variables.
277  // Y(Np,Np) is the inverse error matrix for the poorly-measured variables.
278  //
279  // Outputs:
280  // X(Nw) and Y(Np) is the point at the minimum.
281  // PULLX(Nw) and PULLY(Np) are the pull quantities.
282  // Q(Nw,Nw), R(Np,Np), and S(Nw,Np) are the final error matrices
283  // between all the variables.
284  //
285  // The return value is the final chisq. Returns a value < 0 if the
286  // fit failed to converge.
287 
340  double fit(Constraint_Calculator& constraint_calculator,
341  const Column_Vector& xm,
342  Column_Vector& x,
343  const Column_Vector& ym,
344  Column_Vector& y,
345  const Matrix& G_i,
346  const Diagonal_Matrix& Y,
347  Column_Vector& pullx,
348  Column_Vector& pully,
349  Matrix& Q,
350  Matrix& R,
351  Matrix& S) override;
352 
353  // Print out any internal state to S.
359  std::ostream& print(std::ostream& s) const override;
360 
361  private:
362  // Parameter settings.
367  };
368 
369 } // namespace hitfit
370 
371 #endif // not HITFIT_CHISQ_CONSTRAINER_H
const Base_Constrainer_Args & base_constrainer_args() const
CLHEP::HepVector Column_Vector
Definition: matutil.h:63
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:62
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.
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) override
Hold on to parameters for the Chisq_Constrainer class.
Abstract base classes for the fitter classes.
Hold on to parameters for the Base_Constrainer class.
std::ostream & print(std::ostream &s) const override
Print the state of this instance of Chisq_Constrainer.
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:64
Define an interface for getting parameter settings.
Definition: Defaults.h:57
const Chisq_Constrainer_Args _args