Logo ROOT   6.08/07
Reference Guide
GaussFcn2.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 "GaussFcn2.h"
11 #include "GaussFunction.h"
12 
13 #include <iostream>
14 #include <assert.h>
15 
16 namespace ROOT {
17 
18  namespace Minuit2 {
19 
20 
21 double GaussFcn2::operator()(const std::vector<double>& par) const {
22 
23  assert(par.size() == 6);
24 
25  GaussFunction gauss1 = GaussFunction(par[0], par[1], par[2]);
26  GaussFunction gauss2 = GaussFunction(par[3], par[4], par[5]);
27 
28  double chi2 = 0.;
29  int nmeas = fMeasurements.size();
30  for(int n = 0; n < nmeas; n++) {
31  chi2 += ((gauss1(fPositions[n]) + gauss2(fPositions[n]) - fMeasurements[n])*(gauss1(fPositions[n]) + gauss2(fPositions[n]) - fMeasurements[n])/fMVariances[n]);
32  }
33 
34  return chi2;
35 }
36 
38 
39  // calculate initial Value of chi2
40 
41  int nmeas = fMeasurements.size();
42  double x = 0.;
43  double x2 = 0.;
44  double norm = 0.;
45  double dx = fPositions[1]-fPositions[0];
46  double c = 0.;
47  for(int i = 0; i < nmeas; i++) {
48  norm += fMeasurements[i];
49  x += (fMeasurements[i]*fPositions[i]);
50  x2 += (fMeasurements[i]*fPositions[i]*fPositions[i]);
51  c += dx*fMeasurements[i];
52  }
53  double mean = x/norm;
54  double rms2 = x2/norm - mean*mean;
55 
56 // std::cout<<"FCN initial mean: "<<mean<<std::endl;
57 // std::cout<<"FCN initial sigma: "<<sqrt(rms2)<<std::endl;
58 
59  std::vector<double> par;
60  par.push_back(mean); par.push_back(sqrt(rms2)); par.push_back(c);
61  par.push_back(mean); par.push_back(sqrt(rms2)); par.push_back(c);
62 
63  fMin = (*this)(par);
64 // std::cout<<"GaussFcnHistoData2 initial chi2: "<<fMin<<std::endl;
65 
66 }
67 
68 
69  } // namespace Minuit2
70 
71 } // namespace ROOT
double par[1]
Definition: unuranDistr.cxx:38
virtual double operator()(const std::vector< double > &) const
The meaning of the vector of parameters is of course defined by the user, who uses the values of thos...
Definition: GaussFcn2.cxx:21
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
return c
std::vector< double > fMVariances
Definition: GaussFcn2.h:48
std::vector< double > fPositions
Definition: GaussFcn2.h:47
std::vector< double > fMeasurements
Definition: GaussFcn2.h:46
double sqrt(double)
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
virtual void Init()
Definition: GaussFcn2.cxx:37
double norm(double *x, double *p)
Definition: unuranDistr.cxx:40
const Int_t n
Definition: legend1.C:16