-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGaussMinimizer.cpp
63 lines (39 loc) · 1.44 KB
/
GaussMinimizer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// GaussMinimizer: test RooGaussMinimizer class
//
// call from command line like, for instance:
// root -l 'GaussMinimizer.cpp()'
R__LOAD_LIBRARY(libRooFit)
#include <iostream>
using namespace RooFit;
void GaussMinimizer() {
RooWorkspace w = RooWorkspace();
w.factory("Gaussian::g(x[-5,5],mu[-3,3],sigma[1])");
auto x = w.var("x");
RooAbsPdf * pdf = w.pdf("g");
RooRealVar * mu = w.var("mu");
RooDataSet * data = pdf->generate(RooArgSet(*x), 10000);
auto nll = pdf->createNLL(*data);
// set mu to same value at the start of all minimizations
mu->setVal(-2.9);
std::cout << "trying nominal calculation" << std::endl;
RooMinimizer m0(*nll);
m0.migrad();
mu->setVal(-2.9); // this does nothing
m0.hesse();
mu->setVal(-2.9); // this does nothing
m0.minos();
std::cout << "nominal mu fit is," << mu->getVal() << std::endl;
// set mu to same value at the start of both minimizations
mu->setVal(-2.9);
std::cout << "trying GaussMinimizer" << std::endl;
RooGaussMinimizer m1(*nll);
m1.migrad();
std::cout << "migrad worked with mu of " << mu->getVal() << std::endl;
mu->setVal(-2.9); // this does nothing
m1.hesse();
std::cout << "hesse worked with mu of " << mu->getVal() << std::endl;
mu->setVal(-2.9); // this does nothing
m1.minos();
std::cout << "minos worked with mu of " << mu->getVal() << std::endl;
std::cout << "Made and minimised an nll with 2 Gradient Function" << std::endl;
}