-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkBestFitPoint.C
101 lines (83 loc) · 2.71 KB
/
checkBestFitPoint.C
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
91
92
93
94
95
96
97
98
99
100
101
// Quick Macro to make plots of the LH around the best fitted point
// For LH Plots, n-sigma along x axis
int npoints = 15;
int nsigma = 5;
RooAbsReal *nll;
RooWorkspace *w;
RooStats::ModelConfig *mc_s;
TGraph *graphLH(std::string nuisname, double err ){
w->loadSnapshot("bestfitall"); // SetTo BestFit values as start
// Get The parameter we want
RooRealVar *nuis =(RooRealVar*) w->var(nuisname.c_str());
double bf = nuis->getVal();
double nll_0=nll->getVal();
TGraph *gr = new TGraph(2*npoints+1);
for (int i=-1*npoints;i<=npoints;i++){
nuis->setVal(bf+err*( ((float)i)*nsigma/npoints));
double nll_v = nll->getVal();
gr->SetPoint(i+npoints,nuis->getVal(),nll_v-nll_0);
}
gr->SetTitle("");
gr->GetYaxis()->SetTitle("NLL - obs data");
gr->GetYaxis()->SetTitleOffset(1.1);
gr->GetXaxis()->SetTitleSize(0.05);
gr->GetYaxis()->SetTitleSize(0.05);
gr->GetXaxis()->SetTitle(nuisname.c_str());
gr->SetLineColor(4);
gr->SetLineWidth(2);
gr->SetMarkerStyle(21);
gr->SetMarkerSize(0.6);
return gr;
}
void checkBestFitPoint(std::string workspace, std::string fitFile, bool splusb){
// Open the ws file...
TFile *fd_=0;
TFile *fw_=0;
gSystem->Load("$CMSSW_BASE/lib/$SCRAM_ARCH/libHiggsAnalysisCombinedLimit.so");
gROOT->SetBatch(true);
gStyle->SetOptFit(0);
gStyle->SetOptStat(0);
gStyle->SetPalette(1,0);
fw_ = TFile::Open(workspace.c_str());
w = (RooWorkspace*) fw_->Get("w");
w->Print();
RooDataSet *data = (RooDataSet*) w->data("data_obs");
if (splusb) {
mc_s = (RooStats::ModelConfig*)w->genobj("ModelConfig");
} else {
mc_s = (RooStats::ModelConfig*)w->genobj("ModelConfig_bonly");
}
std::cout << "make nll"<<std::endl;
nll = mc_s->GetPdf()->createNLL(
*data,RooFit::Constrain(*mc_s->GetNuisanceParameters())
,RooFit::Extended(mc_s->GetPdf()->canBeExtended()));
// Now get the best fit result
fd_ = TFile::Open(fitFile.c_str());
RooFitResult *fit;
if (splusb) {
fit =(RooFitResult*)fd_->Get("fit_s");
} else {
fit =(RooFitResult*)fd_->Get("fit_b");
}
RooArgSet fitargs = fit->floatParsFinal();
std::cout << "Got the best fit values" <<std::endl;
w->saveSnapshot("bestfitall",fitargs,true);
TString filename;
if (splusb) {
filename = "minimum_s.pdf";
} else {
filename = "minimum_b.pdf";
}
// Now make the plots!
TCanvas *c = new TCanvas("c","",600,600);
c->SaveAs((filename+"["));
TIterator* iter(fitargs->createIterator());
for (TObject *a = iter->Next(); a != 0; a = iter->Next()) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
std::string name = rrv->GetName();
TGraph *gr = graphLH(name,rrv->getError());
gr->Draw("ALP");
c->SaveAs((filename+"["));
}
c->SaveAs((filename+"]"));
}