-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonly_normal_Minimizer.cpp
90 lines (64 loc) · 2.14 KB
/
only_normal_Minimizer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// GradMinimizer: test RooGradMinimizer class
//
// call from command line like, for instance:
// root -l 'GradMinimizer.cpp()'
R__LOAD_LIBRARY(libRooFit)
#include <iostream>
// #include <exception>
using namespace RooFit;
void only_normal_Minimizer() {
// produce the same random stuff every time
gRandom->SetSeed(1);
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);
mu->setVal(-2.9);
auto nll = pdf->createNLL(*data);
// save initial values for the start of all minimizations
RooArgSet values = RooArgSet(*mu, *pdf, *nll);
std::cout << std::endl << std::endl;
values.Print("v");
mu->Print("v");
std::cout << std::endl << std::endl;
// RooArgSet* savedValues = dynamic_cast<RooArgSet*>(values.snapshot());
// if (savedValues == nullptr) {
// throw std::runtime_error("params->snapshot() cannot be casted to RooArgSet!");
// }
// std::cout << "trying nominal calculation" << std::endl;
RooMinimizer m0(*nll);
m0.setPrintLevel(0);
m0.setVerbose();
m0.migrad();
std::cout << std::endl << std::endl;
values.Print("v");
mu->Print("v");
std::cout << std::endl << std::endl;
// // m0.hesse();
// // m0.minos();
// std::cout << "nominal mu fit is," << mu->getVal() << std::endl;
// // reset initial values
// std::cout << std::endl << std::endl;
// values.Print("v");
// mu->Print("v");
// std::cout << "\n === reset initial values === \n" << std::endl;
// values = *savedValues;
// values.Print("v");
// mu->Print("v");
// std::cout << std::endl << std::endl;
// std::cout << "trying GradMinimizer" << std::endl;
// RooGradMinimizer m1(*nll);
// m1.setVerbose();
// std::cout << "RooGradMinimizer created" << std::endl;
// m1.migrad();
// m1.hesse();
// std::cout << "hesse done" << std::endl;
// m1.minos();
// std::cout << "minos done" << std::endl;
// std::cout << std::endl << std::endl;
// values.Print("v");
// mu->Print("v");
// std::cout << std::endl << std::endl;
}