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 
41 #include <iosfwd>
42 
43 namespace hitfit {
44 
45  class Defaults;
46 
47  //*************************************************************************
48 
55  //
56  // Purpose: Hold on to parameters for the Base_Constrainer class.
57  //
58  // Parameters:
59  // bool test_gradient - If true, check the constraint gradient calculations
60  // by also doing them numerically.
61  // float test_step - When test_gradient is true, the step size to use
62  // for numeric differentiation.
63  // float test_eps - When test_gradient is true, the maximum relative
64  // difference permitted between returned and
65  // numerically calculated gradients.
66  //
67  {
68  public:
69  // Constructor. Initialize from a Defaults object.
70 
80  Base_Constrainer_Args(const Defaults& defs);
81 
82  // Retrieve parameter values.
86  bool test_gradient() const;
87 
91  double test_step() const;
92 
96  double test_eps() const;
97 
98  private:
99  // Hold on to parameter values.
100 
106 
111  double _test_step;
112 
117  double _test_eps;
118  };
119 
120  //*************************************************************************
121 
131  //
132  // Purpose: Abstract base class for evaluating constraints.
133  // Derive from this and implement the eval() method.
134  //
135  {
136  public:
137  // Constructor, destructor. Pass in the number of constraints.
138 
144 
149 
150  // Get back the number of constraints.
154  int nconstraints() const;
155 
156  // Evaluate constraints at the point described by X and Y (well-measured
157  // and poorly-measured variables, respectively). The results should
158  // be stored in F. BX and BY should be set to the gradients of F with
159  // respect to X and Y, respectively.
160  //
161  // Return true if the point X, Y is accepted.
162  // Return false if it is rejected (i.e., in an unphysical region).
163  // The constraints need not be evaluated in that case.
164 
195  virtual bool eval(const Column_Vector& x, const Column_Vector& y, Row_Vector& F, Matrix& Bx, Matrix& By) = 0;
196 
197  private:
198  // The number of constraint functions.
203  };
204 
205  //*************************************************************************
206 
212  //
213  // Purpose: Base class for chisq constrained fitter.
214  //
215  {
216  public:
217  // Constructor, destructor.
218  // ARGS holds the parameter settings for this instance.
219 
225 
229  virtual ~Base_Constrainer() {}
230 
231  // Do the fit.
232  // Call the number of well-measured variables Nw, the number of
233  // poorly-measured variables Np, and the number of constraints Nc.
234  // Inputs:
235  // CONSTRAINT_CALCULATOR is the object that will be used to evaluate
236  // the constraints.
237  // XM(Nw) and YM(Np) are the measured values of the well- and
238  // poorly-measured variables, respectively.
239  // X(Nw) and Y(Np) are the starting values for the fit.
240  // G_I(Nw,Nw) is the error matrix for the well-measured variables.
241  // Y(Np,Np) is the inverse error matrix for the poorly-measured variables.
242  //
243  // Outputs:
244  // X(Nw) and Y(Np) is the point at the minimum.
245  // PULLX(Nw) and PULLY(Np) are the pull quantities.
246  // Q(Nw,Nw), R(Np,Np), and S(Nw,Np) are the final error matrices
247  // between all the variables.
248  //
249  // The return value is the final chisq. Returns a value < 0 if the
250  // fit failed to converge.
251 
303  virtual double fit(Constraint_Calculator& constraint_calculator,
304  const Column_Vector& xm,
305  Column_Vector& x,
306  const Column_Vector& ym,
307  Column_Vector& y,
308  const Matrix& G_i,
309  const Diagonal_Matrix& Y,
310  Column_Vector& pullx,
311  Column_Vector& pully,
312  Matrix& Q,
313  Matrix& R,
314  Matrix& S) = 0;
315 
316  // Print out any internal state to S.
326  virtual std::ostream& print(std::ostream& s) const;
327 
328  // Print out internal state to S.
329  friend std::ostream& operator<<(std::ostream& s, const Base_Constrainer& f);
330 
331  private:
332  // Parameter settings.
333 
338 
339  protected:
340  // Helper function to evaluate the constraints.
341  // This takes care of checking what the user function returns against
342  // numerical derivatives, if that was requested.
343 
383  bool call_constraint_fcn(Constraint_Calculator& constraint_calculator,
384  const Column_Vector& x,
385  const Column_Vector& y,
386  Row_Vector& F,
387  Matrix& Bx,
388  Matrix& By) const;
389  };
390 
391 } // namespace hitfit
392 
393 #endif // not HITFIT_BASE_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::Base_Constrainer::fit
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)=0
Perform the constrained fit.
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
hitfit::Base_Constrainer_Args::test_eps
double test_eps() const
Definition: Base_Constrainer.cc:123
hitfit::Base_Constrainer::~Base_Constrainer
virtual ~Base_Constrainer()
Definition: Base_Constrainer.h:229
hitfit::Constraint_Calculator::~Constraint_Calculator
virtual ~Constraint_Calculator()
Definition: Base_Constrainer.h:148
hitfit::Constraint_Calculator::nconstraints
int nconstraints() const
Definition: Base_Constrainer.cc:143
hitfit::Base_Constrainer_Args::Base_Constrainer_Args
Base_Constrainer_Args(const Defaults &defs)
Definition: Base_Constrainer.cc:94
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
hitfit::Constraint_Calculator::_nconstraints
int _nconstraints
Definition: Base_Constrainer.h:202
alignCSCRings.s
s
Definition: alignCSCRings.py:92
matutil.h
Define matrix types for the HitFit package, and supply a few additional operations.
hitfit::Base_Constrainer_Args::_test_eps
double _test_eps
Definition: Base_Constrainer.h:117
hitfit::Constraint_Calculator::eval
virtual bool eval(const Column_Vector &x, const Column_Vector &y, Row_Vector &F, Matrix &Bx, Matrix &By)=0
Evaluate constraints at the point described by x and y (well-measured and poorly-measured variables,...
hitfit::Base_Constrainer_Args::test_step
double test_step() const
Definition: Base_Constrainer.cc:114
hitfit::Base_Constrainer::call_constraint_fcn
bool call_constraint_fcn(Constraint_Calculator &constraint_calculator, const Column_Vector &x, const Column_Vector &y, Row_Vector &F, Matrix &Bx, Matrix &By) const
Helper function to evaluate constraints. This takes care of checking what the user function returns a...
Definition: Base_Constrainer.cc:206
hitfit::Base_Constrainer
Base class for constrained fitter.
Definition: Base_Constrainer.h:211
hitfit::Constraint_Calculator
Abstract base class for evaluating constraints. Users derive from this class and implement the eval()...
Definition: Base_Constrainer.h:130
hitfit::Base_Constrainer_Args::_test_gradient
bool _test_gradient
Definition: Base_Constrainer.h:105
hitfit::Base_Constrainer_Args::test_gradient
bool test_gradient() const
Definition: Base_Constrainer.cc:105
hitfit::Base_Constrainer::operator<<
friend std::ostream & operator<<(std::ostream &s, const Base_Constrainer &f)
Output stream operator, print the content of this Base_Constrainer to an output stream.
Definition: Base_Constrainer.cc:191
hitfit::Constraint_Calculator::Constraint_Calculator
Constraint_Calculator(int nconstraints)
Definition: Base_Constrainer.cc:134
hitfit::Base_Constrainer::Base_Constrainer
Base_Constrainer(const Base_Constrainer_Args &args)
Definition: Base_Constrainer.cc:156
hitfit::Matrix
CLHEP::HepMatrix Matrix
Definition: matutil.h:62
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
hitfit::Base_Constrainer::_args
const Base_Constrainer_Args _args
Definition: Base_Constrainer.h:337
S
Definition: CSCDBL1TPParametersExtended.h:16
hitfit::Base_Constrainer::print
virtual std::ostream & print(std::ostream &s) const
Print out internal state to output stream.
Definition: Base_Constrainer.cc:165
hitfit::Base_Constrainer_Args::_test_step
double _test_step
Definition: Base_Constrainer.h:111
dttmaxenums::R
Definition: DTTMax.h:29
hitfit::Diagonal_Matrix
CLHEP::HepDiagMatrix Diagonal_Matrix
Definition: matutil.h:64
hitfit::Row_Vector
Row-vector class. CLHEP doesn't have a row-vector class, so HitFit uses its own. This is only a simpl...
Definition: matutil.h:79