00001 // 00002 // $Id: Chisq_Constrainer.h,v 1.2 2011/10/13 09:49:48 snaumann Exp $ 00003 // 00004 // File: hitfit/Chisq_Constrainer.h 00005 // Purpose: Minimize a chisq subject to a set of constraints. 00006 // Based on the SQUAW algorithm. 00007 // Created: Jul, 2000, sss, based on run 1 mass analysis code. 00008 // 00009 // For full details on the algorithm, see 00010 // 00011 // @phdthesis{sssthesis, 00012 // author = "Scott Snyder", 00013 // school = "State University of New York at Stony Brook", 00014 // month = may, 00015 // year = "1995 (unpublished)"} 00016 // @comment{ note = "available from {\tt https://www-d0.fnal.gov/publications\_talks/thesis/ snyder/thesis-ps.html}" 00017 // } 00018 // 00019 // CMSSW File : interface/Chisq_Constrainer.h 00020 // Original Author : Scott Stuart Snyder <snyder@bnl.gov> for D0 00021 // Imported to CMSSW by Haryo Sumowidagdo <Suharyo.Sumowidagdo@cern.ch> 00022 00067 #ifndef HITFIT_CHISQ_CONSTRAINER_H 00068 #define HITFIT_CHISQ_CONSTRAINER_H 00069 00070 #include "TopQuarkAnalysis/TopHitFit/interface/Base_Constrainer.h" 00071 #include "TopQuarkAnalysis/TopHitFit/interface/matutil.h" 00072 #include <iosfwd> 00073 00074 00075 namespace hitfit { 00076 00077 00078 class Defaults; 00079 00080 00085 class Chisq_Constrainer_Args 00086 // 00087 // Purpose: Hold on to parameters for the Chisq_Constrainer class. 00088 // 00089 // Parameters controlling the operation of the fitter: 00090 // bool printfit - If true, print a trace of the fit to cout. 00091 // bool use_G - If true, check the chisq formula by computing 00092 // chisq directly from G. This requires that G_i 00093 // be invertable. 00094 // 00095 // Parameters affecting the fit: 00096 // float constraint_sum_eps - Convergence threshold for sum of constraints. 00097 // float chisq_diff_eps - onvergence threshold for change in chisq. 00098 // int maxit - Maximum number of iterations permitted. 00099 // int max_cut - Maximum number of cut steps permitted. 00100 // float cutsize - Fraction by which to cut steps. 00101 // float min_tot_cutsize - Smallest fractional cut step permitted. 00102 // 00103 // Parameters affecting testing modes: 00104 // float chisq_test_eps - When use_G is true, the maximum relative 00105 // difference permitted between the two chisq 00106 // calculations. 00107 // 00108 { 00109 public: 00110 // Constructor. Initialize from a Defaults object. 00111 00129 Chisq_Constrainer_Args (const Defaults& defs); 00130 00131 // Retrieve parameter values. 00132 00136 bool printfit () const; 00137 00141 bool use_G () const; 00142 00146 double constraint_sum_eps () const; 00147 00151 double chisq_diff_eps () const; 00152 00156 unsigned maxit () const; 00157 00161 unsigned max_cut () const; 00162 00166 double cutsize () const; 00167 00171 double min_tot_cutsize () const; 00172 00176 double chisq_test_eps () const; 00177 00178 // Arguments for subobjects. 00179 00183 const Base_Constrainer_Args& base_constrainer_args () const; 00184 00185 00186 private: 00187 // Hold on to parameter values. 00188 00192 bool _printfit; 00193 00199 bool _use_G; 00200 00204 double _constraint_sum_eps; 00205 00209 double _chisq_diff_eps; 00210 00214 int _maxit; 00215 00219 int _max_cut; 00220 00224 double _cutsize; 00225 00229 double _min_tot_cutsize; 00230 00235 double _chisq_test_eps; 00236 00237 00241 const Base_Constrainer_Args _base_constrainer_args; 00242 }; 00243 00244 00245 //************************************************************************* 00246 00247 00253 class Chisq_Constrainer 00254 // 00255 // Purpose: Minimize a chisq subject to a set of constraints. 00256 // Based on the SQUAW algorithm. 00257 // 00258 : public Base_Constrainer 00259 { 00260 public: 00261 // Constructor, destructor. 00262 // ARGS holds the parameter settings for this instance. 00263 00270 Chisq_Constrainer (const Chisq_Constrainer_Args& args); 00271 00275 virtual ~Chisq_Constrainer () {} 00276 00277 // Do the fit. 00278 // Call the number of well-measured variables Nw, the number of 00279 // poorly-measured variables Np, and the number of constraints Nc. 00280 // Inputs: 00281 // CONSTRAINT_CALCULATOR is the object that will be used to evaluate 00282 // the constraints. 00283 // XM(Nw) and YM(Np) are the measured values of the well- and 00284 // poorly-measured variables, respectively. 00285 // X(Nw) and Y(Np) are the starting values for the fit. 00286 // G_I(Nw,Nw) is the error matrix for the well-measured variables. 00287 // Y(Np,Np) is the inverse error matrix for the poorly-measured variables. 00288 // 00289 // Outputs: 00290 // X(Nw) and Y(Np) is the point at the minimum. 00291 // PULLX(Nw) and PULLY(Np) are the pull quantities. 00292 // Q(Nw,Nw), R(Np,Np), and S(Nw,Np) are the final error matrices 00293 // between all the variables. 00294 // 00295 // The return value is the final chisq. Returns a value < 0 if the 00296 // fit failed to converge. 00297 00350 virtual double fit (Constraint_Calculator& constraint_calculator, 00351 const Column_Vector& xm, 00352 Column_Vector& x, 00353 const Column_Vector& ym, 00354 Column_Vector& y, 00355 const Matrix& G_i, 00356 const Diagonal_Matrix& Y, 00357 Column_Vector& pullx, 00358 Column_Vector& pully, 00359 Matrix& Q, 00360 Matrix& R, 00361 Matrix& S); 00362 00363 // Print out any internal state to S. 00369 virtual std::ostream& print (std::ostream& s) const; 00370 00371 00372 private: 00373 // Parameter settings. 00377 const Chisq_Constrainer_Args _args; 00378 }; 00379 00380 } // namespace hitfit 00381 00382 00383 #endif // not HITFIT_CHISQ_CONSTRAINER_H 00384 00385