ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
testUserFunc.cxx
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Author: L. Moneta 10/2005
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2005 ROOT Foundation, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 
11 #include "TApplication.h"
12 #include "TH1.h"
13 #include "TF1.h"
14 #include "TRandom3.h"
15 #include "Math/MinimizerOptions.h"
16 #include "TMath.h"
17 
18 #include <iostream>
19 
20 double myfunc( double * x, double * p) {
21 
22  return p[0]*TMath::Gaus(x[0],p[1],p[2]);
23 }
24 
25 void testUserFunc(std::string type="Minuit2", int n = 1000) {
26 
27 
28 
29  gRandom = new TRandom3();
30 
31 
33 
34 
35 
36  TH1D * h1 = new TH1D("h1","fit histo 1",100, -5, 5. );
37 
38 // gStyle->SetOptStat(1111111);
39 // gStyle->SetOptFit(1111111);
40 
41 
42 
43 
44  for (int i = 0; i < n; ++i) {
45  h1->Fill( gRandom->Gaus(0,1) );
46  }
47 
48  TF1 * f = new TF1("f",myfunc,-10,10,3);
49  double p[3] = { 100.0, 0.0, 1.0 } ;
50  f->SetParameters(p);
51 
52  h1->Fit(f);
53  // try fix a parameter
54  //TVirtualFitter * fitter = TVirtualFitter::GetFitter();
55  //std::cout << typeid(*fitter).name() << std::endl;
56  //fitter->FixParameter(2);
57  f->FixParameter(2,1.0);
58 
59  h1->Fit(f,"V");
60 
61  h1->Draw();
62 
63 
64 
65 }
66 
67 #ifndef __CINT__
68 int main(int argc, char **argv)
69 {
70  if (argc > 1) {
71  TApplication theApp("App", &argc, argv);
72  testUserFunc( );
73  theApp.Run();
74  }
75  else
76  testUserFunc( );
77  return 0;
78 }
79 #endif
80 
81 //#ifndef __CINT__
82 //int main() {
83 // testUserFunc( );
84 //}
85 //#endif
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:432
Random number generator class based on M.
Definition: TRandom3.h:29
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
TFile * f
Double_t x[n]
Definition: legend1.C:17
virtual void Run(Bool_t retrn=kFALSE)
Main application eventloop. Calls system dependent eventloop via gSystem.
TH1F * h1
Definition: legend1.C:5
void testUserFunc(std::string type="Minuit2", int n=1000)
virtual void FixParameter(Int_t ipar, Double_t value)
Fix the value of a parameter The specified value will be used in a fit operation. ...
Definition: TF1.cxx:1253
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:613
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Calculate a gaussian function with mean and sigma.
Definition: TMath.cxx:453
int type
Definition: TGX11.cxx:120
double myfunc(double *x, double *p)
1-Dim function class
Definition: TF1.h:149
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
Definition: TApplication.h:45
static void SetDefaultMinimizer(const char *type, const char *algo=0)
const Int_t n
Definition: legend1.C:16
int main(int argc, char **argv)