CMS 3D CMS Logo

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 
66 #ifndef HITFIT_CHISQ_CONSTRAINER_H
67 #define HITFIT_CHISQ_CONSTRAINER_H
68 
71 #include <iosfwd>
72 
73 
74 namespace hitfit {
75 
76 
77 class Defaults;
78 
79 
85 //
86 // Purpose: Hold on to parameters for the Chisq_Constrainer class.
87 //
88 // Parameters controlling the operation of the fitter:
89 // bool printfit - If true, print a trace of the fit to cout.
90 // bool use_G - If true, check the chisq formula by computing
91 // chisq directly from G. This requires that G_i
92 // be invertable.
93 //
94 // Parameters affecting the fit:
95 // float constraint_sum_eps - Convergence threshold for sum of constraints.
96 // float chisq_diff_eps - onvergence threshold for change in chisq.
97 // int maxit - Maximum number of iterations permitted.
98 // int max_cut - Maximum number of cut steps permitted.
99 // float cutsize - Fraction by which to cut steps.
100 // float min_tot_cutsize - Smallest fractional cut step permitted.
101 //
102 // Parameters affecting testing modes:
103 // float chisq_test_eps - When use_G is true, the maximum relative
104 // difference permitted between the two chisq
105 // calculations.
106 //
107 {
108 public:
109  // Constructor. Initialize from a Defaults object.
110 
128  Chisq_Constrainer_Args (const Defaults& defs);
129 
130  // Retrieve parameter values.
131 
135  bool printfit () const;
136 
140  bool use_G () const;
141 
145  double constraint_sum_eps () const;
146 
150  double chisq_diff_eps () const;
151 
155  unsigned maxit () const;
156 
160  unsigned max_cut () const;
161 
165  double cutsize () const;
166 
170  double min_tot_cutsize () const;
171 
175  double chisq_test_eps () const;
176 
177  // Arguments for subobjects.
178 
183 
184 
185 private:
186  // Hold on to parameter values.
187 
191  bool _printfit;
192 
198  bool _use_G;
199 
204 
209 
213  int _maxit;
214 
218  int _max_cut;
219 
223  double _cutsize;
224 
229 
235 
236 
241 };
242 
243 
244 //*************************************************************************
245 
246 
253 //
254 // Purpose: Minimize a chisq subject to a set of constraints.
255 // Based on the SQUAW algorithm.
256 //
257  : public Base_Constrainer
258 {
259 public:
260  // Constructor, destructor.
261  // ARGS holds the parameter settings for this instance.
262 
270 
274  ~Chisq_Constrainer () override {}
275 
276  // Do the fit.
277  // Call the number of well-measured variables Nw, the number of
278  // poorly-measured variables Np, and the number of constraints Nc.
279  // Inputs:
280  // CONSTRAINT_CALCULATOR is the object that will be used to evaluate
281  // the constraints.
282  // XM(Nw) and YM(Np) are the measured values of the well- and
283  // poorly-measured variables, respectively.
284  // X(Nw) and Y(Np) are the starting values for the fit.
285  // G_I(Nw,Nw) is the error matrix for the well-measured variables.
286  // Y(Np,Np) is the inverse error matrix for the poorly-measured variables.
287  //
288  // Outputs:
289  // X(Nw) and Y(Np) is the point at the minimum.
290  // PULLX(Nw) and PULLY(Np) are the pull quantities.
291  // Q(Nw,Nw), R(Np,Np), and S(Nw,Np) are the final error matrices
292  // between all the variables.
293  //
294  // The return value is the final chisq. Returns a value < 0 if the
295  // fit failed to converge.
296 
349  double fit (Constraint_Calculator& constraint_calculator,
350  const Column_Vector& xm,
351  Column_Vector& x,
352  const Column_Vector& ym,
353  Column_Vector& y,
354  const Matrix& G_i,
355  const Diagonal_Matrix& Y,
356  Column_Vector& pullx,
357  Column_Vector& pully,
358  Matrix& Q,
359  Matrix& R,
360  Matrix& S) override;
361 
362  // Print out any internal state to S.
368  std::ostream& print (std::ostream& s) const override;
369 
370 
371 private:
372  // Parameter settings.
377 };
378 
379 } // namespace hitfit
380 
381 
382 #endif // not HITFIT_CHISQ_CONSTRAINER_H
383 
384 
const Base_Constrainer_Args & base_constrainer_args() const
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:66
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.
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.
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.
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:67
Define an interface for getting parameter settings.
Definition: Defaults.h:61
const Chisq_Constrainer_Args _args