ROOT   Reference Guide
Searching...
No Matches
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
15namespace Minuit2 {
16
18 : fFCN(fcn), fParameters(par), fAmin(fcn(par.Params()))
19{
20}
21
22MnParameterScan::MnParameterScan(const FCNBase &fcn, const MnUserParameters &par, double fval)
23 : fFCN(fcn), fParameters(par), fAmin(fval)
24{
25}
26
27std::vector<std::pair<double, double>> MnParameterScan::
28operator()(unsigned int par, unsigned int maxsteps, double low, double high)
29{
30 // do the scan for parameter par between low and high values
31
32 // if(maxsteps > 101) maxsteps = 101;
33 std::vector<std::pair<double, double>> result;
34 result.reserve(maxsteps + 1);
35 std::vector<double> params = fParameters.Params();
36 result.push_back(std::pair<double, double>(params[par], fAmin));
37
38 if (low > high)
39 return result;
40 if (maxsteps < 2)
41 return result;
42
43 if (low == 0. && high == 0.) {
44 low = params[par] - 2. * fParameters.Error(par);
45 high = params[par] + 2. * fParameters.Error(par);
46 }
47
48 if (low == 0. && high == 0. && fParameters.Parameter(par).HasLimits()) {
50 low = fParameters.Parameter(par).LowerLimit();
52 high = fParameters.Parameter(par).UpperLimit();
53 }
54
55 if (fParameters.Parameter(par).HasLimits()) {
57 low = std::max(low, fParameters.Parameter(par).LowerLimit());
59 high = std::min(high, fParameters.Parameter(par).UpperLimit());
60 }
61
62 double x0 = low;
63 double stp = (high - low) / double(maxsteps - 1);
64 for (unsigned int i = 0; i < maxsteps; i++) {
65 params[par] = x0 + double(i) * stp;
66 double fval = fFCN(params);
67 if (fval < fAmin) {
68 fParameters.SetValue(par, params[par]);
69 fAmin = fval;
70 }
71 result.push_back(std::pair<double, double>(params[par], fval));
72 }
73
74 return result;
75}
76
77} // namespace Minuit2
78
79} // namespace ROOT
double
Interface (abstract class) defining the function to be minimized, which has to be implemented by the ...
Definition FCNBase.h:45
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