ROOT   Reference Guide
MnParameterScan.cxx
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
11#include "Minuit2/FCNBase.h"
12
13namespace ROOT {
14
15 namespace Minuit2 {
16
17
18MnParameterScan::MnParameterScan(const FCNBase& fcn, const MnUserParameters& par) : fFCN(fcn), fParameters(par), fAmin(fcn(par.Params())) {}
19
20MnParameterScan::MnParameterScan(const FCNBase& fcn, const MnUserParameters& par, double fval) : fFCN(fcn), fParameters(par), fAmin(fval) {}
21
22std::vector<std::pair<double, double> > MnParameterScan::operator()(unsigned int par, unsigned int maxsteps, double low, double high) {
23 // do the scan for parameter par between low and high values
24
25 //if(maxsteps > 101) maxsteps = 101;
26 std::vector<std::pair<double, double> > result; result.reserve(maxsteps+1);
27 std::vector<double> params = fParameters.Params();
28 result.push_back(std::pair<double, double>(params[par], fAmin));
29
30 if(low > high) return result;
31 if(maxsteps < 2) return result;
32
33 if(low == 0. && high == 0.) {
34 low = params[par] - 2.*fParameters.Error(par);
35 high = params[par] + 2.*fParameters.Error(par);
36 }
37
38 if(low == 0. && high == 0. && fParameters.Parameter(par).HasLimits()) {
40 low = fParameters.Parameter(par).LowerLimit();
42 high = fParameters.Parameter(par).UpperLimit();
43 }
44
47 low = std::max(low, fParameters.Parameter(par).LowerLimit());
49 high = std::min(high, fParameters.Parameter(par).UpperLimit());
50 }
51
52 double x0 = low;
53 double stp = (high - low)/double(maxsteps - 1);
54 for(unsigned int i = 0; i < maxsteps; i++) {
55 params[par] = x0 + double(i)*stp;
56 double fval = fFCN(params);
57 if(fval < fAmin) {
58 fParameters.SetValue(par, params[par]);
59 fAmin = fval;
60 }
61 result.push_back(std::pair<double, double>(params[par], fval));
62 }
63
64 return result;
65}
66
67 } // namespace Minuit2
68
69} // namespace ROOT
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition: FCNBase.h:47
std::vector< std::pair< double, double > > operator()(unsigned int par, unsigned int maxsteps=41, double low=0., double high=0.)
MnParameterScan(const FCNBase &, const MnUserParameters &)
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
double Error(unsigned int) const
std::vector< double > Params() const