// @(#)root/minuit2:$Id$ // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 /********************************************************************** * * * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * * * **********************************************************************/ #include "GaussFcn.h" #include "GaussDataGen.h" #include "Minuit2/FunctionMinimum.h" #include "Minuit2/MnUserParameterState.h" #include "Minuit2/MnPrint.h" #include "Minuit2/MnMigrad.h" #include "Minuit2/MnMinos.h" #include "Minuit2/MnContours.h" #include "Minuit2/MnPlot.h" #include "Minuit2/MinosError.h" #include "Minuit2/ContoursError.h" #include using namespace ROOT::Minuit2; int main() { // generate the data (100 data points) GaussDataGen gdg(100); std::vector pos = gdg.Positions(); std::vector meas = gdg.Measurements(); std::vector var = gdg.Variances(); // create FCN function GaussFcn fFCN(meas, pos, var); // create initial starting values for parameters double x = 0.; double x2 = 0.; double norm = 0.; double dx = pos[1]-pos[0]; double area = 0.; for(unsigned int i = 0; i < meas.size(); i++) { norm += meas[i]; x += (meas[i]*pos[i]); x2 += (meas[i]*pos[i]*pos[i]); area += dx*meas[i]; } double mean = x/norm; double rms2 = x2/norm - mean*mean; double rms = rms2 > 0. ? sqrt(rms2) : 1.; { // demonstrate minimal required interface for minimization // create Minuit parameters without names // starting values for parameters std::vector init_par; init_par.push_back(mean); init_par.push_back(rms); init_par.push_back(area); // starting values for initial uncertainties std::vector init_err; init_err.push_back(0.1); init_err.push_back(0.1); init_err.push_back(0.1); // create minimizer (default constructor) VariableMetricMinimizer fMinimizer; // Minimize FunctionMinimum min = fMinimizer.Minimize(fFCN, init_par, init_err); // output std::cout<<"minimum: "< e0 = Minos(0); std::pair e1 = Minos(1); std::pair e2 = Minos(2); // output std::cout<<"1-sigma Minos errors: "< e0 = Minos(0); std::pair e1 = Minos(1); std::pair e2 = Minos(2); // output std::cout<<"3-sigma Minos errors with limits: "< > cont = contours(0, 1, 20); //95% confidence level for 2 parameters Contour // (rich interface) fFCN.SetErrorDef(5.99); ContoursError cont4 = contours.Contour(0, 1, 20); // plot the contours MnPlot plot; cont.insert(cont.end(), cont4().begin(), cont4().end()); plot(min.UserState().Value("mean"), min.UserState().Value("sigma"), cont); // print out one Contour std::cout<