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 
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
writedatasetfile.args
args
Definition: writedatasetfile.py:18
hitfit::Column_Vector
CLHEP::HepVector Column_Vector
Definition: matutil.h:63
hitfit
Definition: Base_Constrainer.h:43
hitfit::Chisq_Constrainer_Args::_base_constrainer_args
const Base_Constrainer_Args _base_constrainer_args
Definition: Chisq_Constrainer.h:234
hitfit::Chisq_Constrainer
Minimize a subject to a set of constraints. Based on the SQUAW algorithm.
Definition: Chisq_Constrainer.h:244
hitfit::Chisq_Constrainer_Args::Chisq_Constrainer_Args
Chisq_Constrainer_Args(const Defaults &defs)
Constructor, creates an instance of Chisq_Constrainer_Args from a Defaults object.
Definition: Chisq_Constrainer.cc:57
hitfit::Chisq_Constrainer_Args::_chisq_diff_eps
double _chisq_diff_eps
Definition: Chisq_Constrainer.h:203
hitfit::Chisq_Constrainer_Args::_maxit
int _maxit
Definition: Chisq_Constrainer.h:208
hitfit::Chisq_Constrainer_Args::_constraint_sum_eps
double _constraint_sum_eps
Definition: Chisq_Constrainer.h:198
hitfit::Chisq_Constrainer::_args
const Chisq_Constrainer_Args _args
Definition: Chisq_Constrainer.h:366
hitfit::Chisq_Constrainer_Args::maxit
unsigned maxit() const
Definition: Chisq_Constrainer.cc:112
hitfit::Chisq_Constrainer_Args::cutsize
double cutsize() const
Definition: Chisq_Constrainer.cc:130
hitfit::Chisq_Constrainer_Args::_use_G
bool _use_G
Definition: Chisq_Constrainer.h:193
alignCSCRings.s
s
Definition: alignCSCRings.py:92
matutil.h
Define matrix types for the HitFit package, and supply a few additional operations.
Base_Constrainer.h
Abstract base classes for the fitter classes.
hitfit::Chisq_Constrainer_Args::chisq_diff_eps
double chisq_diff_eps() const
Definition: Chisq_Constrainer.cc:103
hitfit::Chisq_Constrainer_Args::_printfit
bool _printfit
Definition: Chisq_Constrainer.h:186
hitfit::Base_Constrainer
Base class for constrained fitter.
Definition: Base_Constrainer.h:211
hitfit::Chisq_Constrainer::fit
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
Definition: Chisq_Constrainer.cc:291
hitfit::Chisq_Constrainer_Args::_cutsize
double _cutsize
Definition: Chisq_Constrainer.h:218
hitfit::Chisq_Constrainer_Args::_chisq_test_eps
double _chisq_test_eps
Definition: Chisq_Constrainer.h:229
hitfit::Chisq_Constrainer_Args::max_cut
unsigned max_cut() const
Definition: Chisq_Constrainer.cc:121
hitfit::Chisq_Constrainer::~Chisq_Constrainer
~Chisq_Constrainer() override
Definition: Chisq_Constrainer.h:265
hitfit::Constraint_Calculator
Abstract base class for evaluating constraints. Users derive from this class and implement the eval()...
Definition: Base_Constrainer.h:130
hitfit::Chisq_Constrainer_Args::_min_tot_cutsize
double _min_tot_cutsize
Definition: Chisq_Constrainer.h:223
hitfit::Chisq_Constrainer_Args
Hold on to parameters for the Chisq_Constrainer class.
Definition: Chisq_Constrainer.h:80
hitfit::Chisq_Constrainer::Chisq_Constrainer
Chisq_Constrainer(const Chisq_Constrainer_Args &args)
Definition: Chisq_Constrainer.cc:282
hitfit::Chisq_Constrainer_Args::_max_cut
int _max_cut
Definition: Chisq_Constrainer.h:213
hitfit::Chisq_Constrainer_Args::chisq_test_eps
double chisq_test_eps() const
Definition: Chisq_Constrainer.cc:148
hitfit::Matrix
CLHEP::HepMatrix Matrix
Definition: matutil.h:62
hitfit::Chisq_Constrainer_Args::base_constrainer_args
const Base_Constrainer_Args & base_constrainer_args() const
Definition: Chisq_Constrainer.cc:157
hitfit::Chisq_Constrainer_Args::use_G
bool use_G() const
Definition: Chisq_Constrainer.cc:85
hitfit::Base_Constrainer_Args
Hold on to parameters for the Base_Constrainer class.
Definition: Base_Constrainer.h:54
hitfit::Defaults
Define an interface for getting parameter settings.
Definition: Defaults.h:57
BeamSpotPI::Y
Definition: BeamSpotPayloadInspectorHelper.h:32
S
Definition: CSCDBL1TPParametersExtended.h:16
hitfit::Chisq_Constrainer_Args::printfit
bool printfit() const
Definition: Chisq_Constrainer.cc:76
hitfit::Chisq_Constrainer_Args::min_tot_cutsize
double min_tot_cutsize() const
Definition: Chisq_Constrainer.cc:139
hitfit::Chisq_Constrainer_Args::constraint_sum_eps
double constraint_sum_eps() const
Definition: Chisq_Constrainer.cc:94
dttmaxenums::R
Definition: DTTMax.h:29
hitfit::Diagonal_Matrix
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:64
hitfit::Chisq_Constrainer::print
std::ostream & print(std::ostream &s) const override
Print the state of this instance of Chisq_Constrainer.
Definition: Chisq_Constrainer.cc:623