1 |
#include <algorithm>
|
2 |
#include <iostream>
|
3 |
#include <map>
|
4 |
#include <vector>
|
5 |
#include <sstream>
|
6 |
#include "TChain.h"
|
7 |
#include "TChainElement.h"
|
8 |
#include "TDirectory.h"
|
9 |
#include "TFile.h"
|
10 |
#include "TProfile.h"
|
11 |
#include "TTree.h"
|
12 |
#include "TH1F.h"
|
13 |
#include "TH2F.h"
|
14 |
#include "TMath.h"
|
15 |
#include "TCut.h"
|
16 |
#include "TRandom3.h"
|
17 |
#include "TCanvas.h"
|
18 |
#include "THStack.h"
|
19 |
#include "TLegend.h"
|
20 |
#include "TLatex.h"
|
21 |
#include "TLine.h"
|
22 |
#include <iomanip>
|
23 |
|
24 |
|
25 |
using namespace std;
|
26 |
|
27 |
TH1F* cloneHist( TH1F* hin ){
|
28 |
|
29 |
TH1F *hout = new TH1F(hin->GetTitle(),hin->GetName(),
|
30 |
hin->GetNbinsX(), hin->GetXaxis()->GetXmin() , hin->GetXaxis()->GetXmax() );
|
31 |
|
32 |
for( unsigned int ibin = 1 ; ibin < hin->GetNbinsX() ; ibin++ ){
|
33 |
float val = hin->GetBinContent( ibin );
|
34 |
hout->SetBinContent( ibin , val );
|
35 |
}
|
36 |
|
37 |
return hout;
|
38 |
|
39 |
}
|
40 |
|
41 |
void plotMVAOutput( bool printgif = false ){
|
42 |
|
43 |
//gROOT->ProcessLine(".x selection.h");
|
44 |
|
45 |
//char* path = "Trainings/H130_WWTo2L2Nu/output";
|
46 |
//char* path = "Trainings/H130_WWTo2L2Nu_WJetsToLNu/output";
|
47 |
char* path = "Trainings/H130_allbkg_4vars/output";
|
48 |
|
49 |
//char* mvaname = "MVA_PDERS";
|
50 |
//char* mvaname = "MVA_MLPBNN";
|
51 |
//char* mvaname = "MVA_BDT";
|
52 |
//char* mvaname = "LikelihoodPCA";
|
53 |
|
54 |
vector<char*> mvanames;
|
55 |
mvanames.push_back("BDT");
|
56 |
mvanames.push_back("MLPBNN");
|
57 |
const unsigned int nmva = mvanames.size();
|
58 |
|
59 |
int rebin = 10;
|
60 |
int colors[] = { 5 , 2 , 4 , 3 , 7 , 8 , 6 , 9 , 10};
|
61 |
|
62 |
vector<char*> samples;
|
63 |
samples.push_back("WWTo2L2Nu");
|
64 |
samples.push_back("GluGluToWWTo4L");
|
65 |
samples.push_back("WZ");
|
66 |
samples.push_back("ZZ");
|
67 |
samples.push_back("TTJets");
|
68 |
samples.push_back("tW");
|
69 |
samples.push_back("WJetsToLNu");
|
70 |
samples.push_back("DY");
|
71 |
const unsigned int nsamples = samples.size();
|
72 |
|
73 |
char* higgssample = "Higgs130";
|
74 |
//char* higgssample = "Higgs160";
|
75 |
//char* higgssample = "Higgs200";
|
76 |
|
77 |
TCanvas *can[nmva];
|
78 |
|
79 |
|
80 |
for( unsigned int imva = 0 ; imva < nmva ; ++imva ){
|
81 |
|
82 |
|
83 |
TFile* file = new TFile();
|
84 |
TH1F* hist = new TH1F();
|
85 |
TH1F* bkghist = new TH1F();
|
86 |
THStack* bkgstack = new THStack("bkgstack","bkgstack");
|
87 |
TLegend *leg = new TLegend(0.3,0.7,0.5,0.9);
|
88 |
leg->SetBorderSize(1);
|
89 |
leg->SetFillColor(0);
|
90 |
|
91 |
//loop over backgrounds
|
92 |
for( unsigned int i = 0 ; i < nsamples ; ++i ){
|
93 |
|
94 |
file = TFile::Open(Form("%s/%s.root",path,samples.at(i)));
|
95 |
hist = cloneHist( (TH1F*) file->Get( Form("MVA_%s",mvanames.at(imva) ) ) );
|
96 |
|
97 |
hist->SetFillColor(colors[i]);
|
98 |
|
99 |
leg->AddEntry(hist,samples.at(i),"f");
|
100 |
|
101 |
if( i == 0 ) bkghist = (TH1F*) hist->Clone();
|
102 |
else bkghist -> Add(hist);
|
103 |
|
104 |
hist->Rebin( rebin );
|
105 |
bkgstack->Add(hist);
|
106 |
|
107 |
}
|
108 |
|
109 |
//higgs sample
|
110 |
file = TFile::Open(Form("%s/%s.root",path,higgssample));
|
111 |
TH1F* higgshist = cloneHist( (TH1F*) file->Get( Form("MVA_%s",mvanames.at(imva) ) ) );
|
112 |
higgshist->SetLineWidth(2);
|
113 |
leg->AddEntry(higgshist,higgssample,"l");
|
114 |
|
115 |
|
116 |
|
117 |
float bkg = 0;
|
118 |
float sig = 0;
|
119 |
float minbkg = 1.48;
|
120 |
//float minbkg = 1.10;
|
121 |
float cut = 0.;
|
122 |
|
123 |
for( int ibin = 1 ; ibin < bkghist->GetNbinsX() ; ibin++ ){
|
124 |
|
125 |
bkg = bkghist->Integral( ibin , 10000 );
|
126 |
sig = higgshist->Integral( ibin , 10000 );
|
127 |
|
128 |
if( bkg < minbkg ){
|
129 |
cut = bkghist->GetBinCenter(ibin);
|
130 |
cout << endl;
|
131 |
cout << "S/B " << sig/bkg << endl;
|
132 |
cout << "Sig " << sig << endl;
|
133 |
cout << "Bkg " << bkg << endl;
|
134 |
cout << "cut value " << cut << endl;
|
135 |
break;
|
136 |
}
|
137 |
|
138 |
}
|
139 |
|
140 |
float cutsig = sig;
|
141 |
float cutbkg = bkg;
|
142 |
|
143 |
float maxfom = -1;
|
144 |
float maxfom_sig = -1;
|
145 |
float maxfom_bkg = -1;
|
146 |
float cutval = -1;
|
147 |
|
148 |
|
149 |
for( int ibin = 1 ; ibin < bkghist->GetNbinsX() ; ibin++ ){
|
150 |
|
151 |
bkg = bkghist->Integral( ibin , 10000 );
|
152 |
sig = higgshist->Integral( ibin , 10000 );
|
153 |
|
154 |
float fom = sig / sqrt( sig + bkg + pow( 0.35 * bkg , 2 ) );
|
155 |
|
156 |
if( fom > maxfom ){
|
157 |
maxfom = fom;
|
158 |
maxfom_sig = sig;
|
159 |
maxfom_bkg = bkg;
|
160 |
cutval = bkghist->GetBinCenter(ibin);
|
161 |
}
|
162 |
|
163 |
}
|
164 |
|
165 |
cout << endl;
|
166 |
cout << "Max FOM " << maxfom << endl;
|
167 |
cout << "Sig " << maxfom_sig << endl;
|
168 |
cout << "Bkg " << maxfom_bkg << endl;
|
169 |
cout << "cut value " << cutval << endl;
|
170 |
|
171 |
|
172 |
bkghist->Rebin( rebin );
|
173 |
higgshist->Rebin( rebin );
|
174 |
|
175 |
can[imva] = new TCanvas(Form("can_%i",imva),Form("can_%i",imva),800,600);
|
176 |
can[imva]->cd();
|
177 |
|
178 |
//gPad->SetLogy();
|
179 |
bkghist->GetXaxis()->SetTitle(Form("%s output",mvanames.at(imva)));
|
180 |
bkghist->Draw();
|
181 |
bkgstack->Draw("same");
|
182 |
higgshist->Scale(10.);
|
183 |
higgshist->Draw("same");
|
184 |
bkghist->Draw("axissame");
|
185 |
//leg->Draw();
|
186 |
|
187 |
TLatex *t = new TLatex();
|
188 |
t->SetNDC();
|
189 |
t->SetTextColor(2);
|
190 |
t->DrawLatex(0.2,0.85,Form("FOM: %.2f",maxfom));
|
191 |
t->SetTextColor(1);
|
192 |
t->DrawLatex(0.2,0.80,Form("Sig: %.2f",maxfom_sig));
|
193 |
t->DrawLatex(0.2,0.75,Form("Bkg: %.2f",maxfom_bkg));
|
194 |
|
195 |
t->SetTextColor(4);
|
196 |
t->DrawLatex(0.2,0.55,Form("S/B: %.2f",cutsig/cutbkg));
|
197 |
t->SetTextColor(1);
|
198 |
t->DrawLatex(0.2,0.50,Form("Sig: %.2f",cutsig));
|
199 |
t->DrawLatex(0.2,0.45,Form("Bkg: %.2f",cutbkg));
|
200 |
|
201 |
TLine line;
|
202 |
line.SetLineColor(2);
|
203 |
line.DrawLine( cutval , bkghist->GetMinimum() , cutval , 1.05 * bkghist->GetMaximum() );
|
204 |
line.SetLineColor(4);
|
205 |
line.DrawLine( cut , bkghist->GetMinimum() , cut , 1.05 * bkghist->GetMaximum() );
|
206 |
|
207 |
if( printgif ) can[imva]->Print(Form("plots/%s.gif",mvanames.at(imva)));
|
208 |
}
|
209 |
}
|