macro VECFIT * * Sample least squares fitting using MINUIT with PAW (command vec/fit). * Glen Cowan, 5 December 1999 * Derived from http://www-d0.fnal.gov/~hirosky/paw_hints/fit_example.kumac * on error goto error_exit * * Read in data from file, create vectors for fit parameters and errors. * vec/read x,y,dy vecfit_data.dat npar = 5 vec/cr par([npar]) r vec/cr dpar([npar]) r vec/cr covmat([npar],[npar]) vec/cr fit_info(3) r * * Plot the points and set up arrays for plotting fitted function * title 'Test fit with MINUIT called from PAW' set xsiz 30.0 set ysiz 20.0 set xmgl 12.0 set xmgr 1.0 set ymgu 2.0 set ymgl 2.0 set gsiz 0.4 set asiz 0.4 set vsiz 0.4 set xlab 1.5 set ylab 1.0 set ygti 0.5 opt liny opt linx xmin = 0 xmax = 20 ymin = 0 ymax = 35 null [xmin] [xmax] [ymin] [ymax] hplot/err x y ? dy $VLEN(x) atit 'x' 'y' nplot = 100 vec/cr xplot([nplot]) vec/cr fplot([nplot]) * * Do the fit. * 'name' command assigns arbitrary names to parameters. * 'call 1' calls fcn_paw with iflag=1 (for function initialization). * 'exit' command calls fcn_paw with iflag=3. * application hminuit exit name 1 a0 name 2 a1 name 3 a2 name 4 a3 name 5 a4 call 1 mini mino exit vec/fit x y dy fcn_vecfit.f 'ZME' [npar] par * * Plot fitted function, put parameter values on plot, print covariance matrix * graph $VLEN(xplot) xplot fplot c selnt 1 | cm coordinates set chhe 0.35 xtext = 1. ytop = 17. delta_y = 1. ytext = [ytop] itx [xtext] [ytext] [h]^2! = $EVAL(fit_info(1)) ytext = [ytext] - [delta_y] itx [xtext] [ytext] N?points! = $EVAL(fit_info(2)) ytext = [ytext] - [delta_y] itx [xtext] [ytext] N?par! = $EVAL(fit_info(3)) do i = 1, [npar] ytext = [ytext] - [delta_y] itx [xtext] [ytext] P$EVAL([i]) = $EVAL(par([i])) "a# $EVAL(dpar([i])) enddo mess 'Covariance matrix:' vec/print covmat * goto EXIT error_exit: message *** vecfit.kumac exits with error *** * EXIT: RETURN