Logo ROOT   6.08/07
Reference Guide
DemoFumili.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 
10 #include "GaussDataGen.h"
11 #include "GaussianModelFunction.h"
16 #include "Minuit2/MnPrint.h"
17 #include "Minuit2/MnMigrad.h"
18 
19 #include <iostream>
20 
21 using namespace ROOT::Minuit2;
22 
23 int main() {
24 
25  // generate the data (100 data points)
26  GaussDataGen gdg(100);
27 
28  std::vector<double> pos = gdg.Positions();
29  std::vector<double> meas = gdg.Measurements();
30  std::vector<double> var = gdg.Variances();
31 
32 
33 
34  // Estimate initial starting values for parameters
35  double x = 0.;
36  double x2 = 0.;
37  double norm = 0.;
38  double dx = pos[1]-pos[0];
39  double area = 0.;
40  for(unsigned int i = 0; i < meas.size(); i++) {
41  norm += meas[i];
42  x += (meas[i]*pos[i]);
43  x2 += (meas[i]*pos[i]*pos[i]);
44  area += dx*meas[i];
45  }
46  double mean = x/norm;
47  double rms2 = x2/norm - mean*mean;
48  double rms = rms2 > 0. ? sqrt(rms2) : 1.;
49 
50 
51  // create parameters
52  MnUserParameters upar;
53  upar.Add("mean", mean, 0.1);
54  upar.Add("sigma", rms, 0.1);
55  upar.Add("area", area, 0.1);
56 
57 
58 
59  // create FCN function for Fumili using model function
60  GaussianModelFunction modelFunction;
61  FumiliStandardChi2FCN fFCN(modelFunction, meas, pos, var);
62 
63  {
64 
65  std::cout << "Minimize using FUMILI : \n" << std::endl;
66  MnFumiliMinimize fumili(fFCN, upar);
67 
68 
69  // Minimize
70  FunctionMinimum min = fumili();
71 
72  // output
73  std::cout<<"minimum: "<<min<<std::endl;
74  }
75 
76  {
77 
78  std::cout << "Minimize using MIGRAD : \n" << std::endl;
79  MnMigrad migrad(fFCN, upar);
80 
81  // Minimize
82  FunctionMinimum min = migrad();
83 
84  // output
85  std::cout<<"minimum: "<<min<<std::endl;
86  }
87 
88 
89  return 0;
90 }
API class for minimization using Variable Metric technology ("MIGRAD"); allows for user interaction: ...
Definition: MnMigrad.h:31
bool Add(const std::string &, double, double)
Add free Parameter Name, Value, Error.
double sqrt(double)
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
Sample implementation of a parametric function.
Class implementing the standard chi square function, which is the sum of the squares of the figures-o...
std::vector< double > Variances() const
Definition: GaussDataGen.h:30
int main()
Definition: DemoFumili.cxx:23
std::vector< double > Measurements() const
Definition: GaussDataGen.h:29
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
std::vector< double > Positions() const
Definition: GaussDataGen.h:28
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
API class for minimization using Fumili technology; allows for user interaction: set/change parameter...