1 |
#include <iostream>
|
2 |
#include <vector>
|
3 |
#include <sys/stat.h>
|
4 |
|
5 |
#include <TCut.h>
|
6 |
#include <TROOT.h>
|
7 |
#include <TCanvas.h>
|
8 |
#include <TMath.h>
|
9 |
#include <TColor.h>
|
10 |
#include <TPaveText.h>
|
11 |
#include <TRandom.h>
|
12 |
#include <TH1.h>
|
13 |
#include <TH2.h>
|
14 |
#include <TF1.h>
|
15 |
#include <TSQLResult.h>
|
16 |
#include <TProfile.h>
|
17 |
#include <TLegendEntry.h>
|
18 |
|
19 |
using namespace std;
|
20 |
|
21 |
namespace TriLeptons {
|
22 |
float Rsfof_CorrectionFactor=-1;
|
23 |
float Rsfof_CorrectionFactor_Error=-1;
|
24 |
}
|
25 |
|
26 |
string IdentifierForUnderlinedEntry(string Entry) {
|
27 |
if(Contains(Entry,"t_bar_t__")) return "ttbar";
|
28 |
if(Contains(Entry,"Single_top__")) return "SingleTop";
|
29 |
if(Contains(Entry,"W_Jets__")) return "W+Jets";
|
30 |
if(Contains(Entry,"WZ__")) return "WZ";
|
31 |
if(Contains(Entry,"Z_Jets")) return "Z+Jets";
|
32 |
if(Contains(Entry,"DATA")) return "Data";
|
33 |
if(Contains(Entry,"2l2q_")) return "ZZ->2l2q";
|
34 |
if(Contains(Entry,"4l_")) return "ZZ->4l";
|
35 |
return Entry;
|
36 |
}
|
37 |
|
38 |
void WZ_kin_plot(string variable, int nbins, float min, float high, string xlabel, TCut cut, string saveas) {
|
39 |
TCanvas *can = new TCanvas("can","can");
|
40 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
41 |
pad->cd();
|
42 |
|
43 |
THStack stack = allsamples.DrawStack("stack",variable,nbins,min,high,xlabel, "events", cut,mc, luminosity);
|
44 |
TH1F *hdata = SingleLeptonData.Draw("hdata",variable,nbins,min,high,xlabel, "events", cut,data, luminosity);
|
45 |
|
46 |
float StackMax=CollapseStack(stack)->GetMaximum();
|
47 |
if(StackMax>hdata->GetMaximum()) hdata->SetMaximum(1.2*StackMax);
|
48 |
hdata->Draw("e1");
|
49 |
stack.Draw("histo,same");
|
50 |
hdata->Draw("e1,same");
|
51 |
|
52 |
TLegend *kinleg = allsamples.allbglegend();
|
53 |
kinleg->Draw();
|
54 |
DrawPrelim();
|
55 |
|
56 |
float total=0;
|
57 |
float wz=0;
|
58 |
// cout << "Numbers with variable " << variable << " and cut " << cut << ": " << endl;
|
59 |
TIter nextSF = TIter(stack.GetHists());
|
60 |
TH1F *h;
|
61 |
stringstream spurity;
|
62 |
int bracecounter=0;
|
63 |
|
64 |
|
65 |
while ( h = (TH1F*)nextSF() ) {
|
66 |
// cout << IdentifierForUnderlinedEntry(h->GetName()) << " : " << h->Integral() << endl;
|
67 |
if(IdentifierForUnderlinedEntry(h->GetName())=="WZ") {
|
68 |
wz+=h->Integral();
|
69 |
total+=h->Integral();
|
70 |
} else {
|
71 |
if(IdentifierForUnderlinedEntry(h->GetName())!="Data") total+=h->Integral();
|
72 |
}
|
73 |
bracecounter++;
|
74 |
spurity << "#splitline{" << IdentifierForUnderlinedEntry(h->GetName()) << " : " << h->Integral() << "}{";
|
75 |
}
|
76 |
|
77 |
spurity << "#splitline{Purity: " << wz/total << "}{N(events): " << total << "}";
|
78 |
for(int i=0;i<bracecounter;i++) spurity << "}";
|
79 |
|
80 |
TPaveText *PurityPaveText = new TPaveText(0.60, 0.40,0.89, 0.6,"blNDC");
|
81 |
PurityPaveText->SetFillStyle(4000);
|
82 |
PurityPaveText->SetBorderSize(0);
|
83 |
PurityPaveText->SetFillColor(kWhite);
|
84 |
PurityPaveText->SetTextFont(42);
|
85 |
PurityPaveText->SetTextSize(0.021);
|
86 |
PurityPaveText->AddText(spurity.str().c_str());
|
87 |
//PurityPaveText->Draw();
|
88 |
|
89 |
|
90 |
// TText *purity = new TText(0.8,0.6,spurity.str().c_str());
|
91 |
// purity->Draw();
|
92 |
// cout << "DATA : " << hdata->Integral() << endl;
|
93 |
|
94 |
Save_With_Ratio(hdata,stack,pad->cd(),"WZ_study/"+saveas);
|
95 |
|
96 |
float sumData=0;
|
97 |
float sumMC=0;
|
98 |
TH1F *cstack = CollapseStack(stack);
|
99 |
|
100 |
for(int i=1;i<=hdata->GetNbinsX();i++) {
|
101 |
if(hdata->GetBinCenter(i)>=20 && hdata->GetBinCenter(i)<=70) {
|
102 |
sumData+=hdata->GetBinContent(i);
|
103 |
sumMC+=cstack->GetBinContent(i);
|
104 |
}
|
105 |
}
|
106 |
delete cstack;
|
107 |
cout << " [20,70] for " << saveas << " : " << sumData << " (data) vs " << sumMC << " (mc) " << endl;
|
108 |
|
109 |
CleanLegends();
|
110 |
delete hdata;
|
111 |
delete can;
|
112 |
}
|
113 |
|
114 |
void SF_vs_OF_plots(string variable, int nbins, float min, float high, string xlabel, TCut cut, TCut sf, TCut of, int mcordata, string saveas) {
|
115 |
TCanvas *can = new TCanvas("can","can");
|
116 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
117 |
pad->cd();
|
118 |
|
119 |
TLegend *kinleg = make_legend();
|
120 |
if(mcordata==data) kinleg->SetHeader("Data");
|
121 |
else kinleg->SetHeader("MC");
|
122 |
|
123 |
TH1F *sfdata;
|
124 |
TH1F *ofdata;
|
125 |
|
126 |
if(mcordata==data) {
|
127 |
ofdata = SingleLeptonData.Draw("ofdata",variable,nbins,min,high,xlabel, "events", cut&&of,mcordata, luminosity);
|
128 |
sfdata = SingleLeptonData.Draw("sfdata",variable,nbins,min,high,xlabel, "events", cut&&sf,mcordata, luminosity);
|
129 |
} else {
|
130 |
ofdata = allsamples.Draw("ofdata",variable,nbins,min,high,xlabel, "events", cut&&of,mcordata, luminosity);
|
131 |
sfdata = allsamples.Draw("sfdata",variable,nbins,min,high,xlabel, "events", cut&&sf,mcordata, luminosity);
|
132 |
}
|
133 |
|
134 |
float OFmax=ofdata->GetMaximum();
|
135 |
if(OFmax>sfdata->GetMaximum()) sfdata->SetMaximum(1.2*OFmax);
|
136 |
ofdata->SetLineColor(kRed);
|
137 |
sfdata->Draw("e1");
|
138 |
ofdata->Draw("histo,same");
|
139 |
sfdata->Draw("e1,same");
|
140 |
|
141 |
kinleg->AddEntry(sfdata,"Same flavor","p");
|
142 |
kinleg->AddEntry(ofdata,"Opposite flavor","l");
|
143 |
kinleg->Draw();
|
144 |
if(mcordata==data) DrawPrelim();
|
145 |
else DrawMCPrelim();
|
146 |
|
147 |
Save_With_Ratio(sfdata,ofdata,pad->cd(),"WZ_study/SF_vs_OF_plots/"+saveas);
|
148 |
delete sfdata;
|
149 |
delete ofdata;
|
150 |
delete can;
|
151 |
}
|
152 |
|
153 |
void write_report(TCut BasicCut, TCut cut, ofstream &report) {
|
154 |
THStack stack = allsamples.DrawStack("stack","tri_mll",10,0,1000,"m_{ll}", "events", BasicCut&&cut,mc, luminosity);
|
155 |
float total=0;
|
156 |
float wz=0;
|
157 |
TIter nextSF = TIter(stack.GetHists());
|
158 |
TH1F *h;
|
159 |
while ( h = (TH1F*)nextSF() ) {
|
160 |
cout << IdentifierForUnderlinedEntry(h->GetName()) << " : " << h->Integral() << endl;
|
161 |
if(IdentifierForUnderlinedEntry(h->GetName())=="WZ") {
|
162 |
wz+=h->Integral();
|
163 |
total+=h->Integral();
|
164 |
} else {
|
165 |
if(IdentifierForUnderlinedEntry(h->GetName())!="Data") total+=h->Integral();
|
166 |
}
|
167 |
report << h->Integral() << ";";
|
168 |
}
|
169 |
report << wz/total << ";\n";
|
170 |
report << flush;
|
171 |
|
172 |
}
|
173 |
|
174 |
vector<string> producecuts(string variablename, float cut1, float cut2, float cut3=-1, float cut4=-1, float cut5=-1, float cut6=-1, float cut7=-1, float cut8=-1, float cut9=-1, float cut10=-1, float cut11=-1 ) {
|
175 |
float allcuts[12] = {cut1,cut2,cut3,cut4,cut5,cut6,cut7,cut8,cut9,cut10,cut11};
|
176 |
vector<string> cuts;
|
177 |
for(int i = 0; i < 11; ++i ) {
|
178 |
if(allcuts[i]<0) continue;
|
179 |
stringstream nowcut;
|
180 |
nowcut << variablename << allcuts[i];
|
181 |
cuts.push_back(nowcut.str());
|
182 |
}
|
183 |
return cuts;
|
184 |
}
|
185 |
|
186 |
|
187 |
void OptimizeSelection(TCut BasicCut) {
|
188 |
ofstream report;
|
189 |
report.open ("report3.txt");
|
190 |
|
191 |
vector<string> mt = producecuts("tri_mT>",0,10,15,20,25,30,35,40,45,50);
|
192 |
vector<string> et = producecuts("met[4]>",0,10,20,30,40,50);
|
193 |
vector<string> mll = producecuts("abs(tri_mll-91.2)<",10000,5,10,15,20);
|
194 |
vector<string> mlll = producecuts("abs(tri_mlll-91)>",0,5,10,15,20,25,30,40,50);
|
195 |
|
196 |
for(int imt=0;imt<mt.size();imt++) {
|
197 |
for(int iet=0;iet<et.size();iet++) {
|
198 |
for(int imll=0;imll<mll.size();imll++) {
|
199 |
for(int imlll=0;imlll<mlll.size();imlll++) {
|
200 |
stringstream cut;
|
201 |
cut << mt[imt] << " && " << et[iet] << " && " << mll[imll] << " && " << mlll[imlll];
|
202 |
report << mt[imt] << ";" << et[iet] << ";" << mll[imll] << ";" << mlll[imlll] <<";";
|
203 |
// cout << "Cut is : " << cut.str() << endl;
|
204 |
write_report(BasicCut, TCut(cut.str().c_str()),report);
|
205 |
}
|
206 |
}
|
207 |
}
|
208 |
}
|
209 |
report.close();
|
210 |
}
|
211 |
|
212 |
void SF_OF_comparison(TCut BasicCut, TCut Selection) {
|
213 |
int nbins=38;
|
214 |
float mll_low=10;
|
215 |
float mll_hi=200;
|
216 |
|
217 |
// all MC samples
|
218 |
TH1F *sfmc = allsamples.Draw("sfmc" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF,mc , luminosity);
|
219 |
TH1F *ofmc = allsamples.Draw("ofmc" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF,mc , luminosity);
|
220 |
|
221 |
TCanvas *can = new TCanvas("can","can");
|
222 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
223 |
pad->cd();
|
224 |
if(ofmc->GetMaximum()>sfmc->GetMaximum()) sfmc->SetMaximum(1.3*ofmc->GetMaximum());
|
225 |
ofmc->SetLineColor(kRed);
|
226 |
TLegend *leg = make_legend();
|
227 |
leg->AddEntry(sfmc,"same flavor","P");
|
228 |
leg->AddEntry(ofmc,"opposite flavor","L");
|
229 |
leg->SetHeader("MC:");
|
230 |
sfmc->Draw("e1");
|
231 |
ofmc->Draw("histo,same");
|
232 |
sfmc->Draw("e1,same");
|
233 |
leg->Draw();
|
234 |
DrawMCPrelim();
|
235 |
|
236 |
Save_With_Ratio(sfmc,ofmc,pad->cd(),"WZ_study/OFSFcomparison_MC");
|
237 |
|
238 |
// WZ only
|
239 |
TH1F *sfwz = allsamples.Draw("sfwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF,mc , luminosity,allsamples.FindSample("WZJetsTo3"));
|
240 |
TH1F *ofwz = allsamples.Draw("ofwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF,mc , luminosity,allsamples.FindSample("WZJetsTo3"));
|
241 |
|
242 |
TPad *pad2 = new TPad("pad","pad",0,0,1,1);
|
243 |
pad2->cd();
|
244 |
if(ofwz->GetMaximum()>sfwz->GetMaximum()) sfwz->SetMaximum(1.3*ofwz->GetMaximum());
|
245 |
ofwz->SetLineColor(kRed);
|
246 |
sfwz->Draw("e1");
|
247 |
ofwz->Draw("histo,same");
|
248 |
sfwz->Draw("e1,same");
|
249 |
leg->SetHeader("WZ MC:");
|
250 |
leg->Draw();
|
251 |
DrawMCPrelim();
|
252 |
|
253 |
Save_With_Ratio(sfwz,ofwz,pad2->cd(),"WZ_study/OFSFcomparison_WZ");
|
254 |
|
255 |
// data
|
256 |
TH1F *sfdata = SingleLeptonData.Draw("sfdata","tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF,data, luminosity);
|
257 |
TH1F *ofdata = SingleLeptonData.Draw("ofdata","tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF,data, luminosity);
|
258 |
|
259 |
TPad *pad3 = new TPad("pad","pad",0,0,1,1);
|
260 |
pad3->cd();
|
261 |
if(ofdata->GetMaximum()>sfdata->GetMaximum()) sfdata->SetMaximum(1.3*ofdata->GetMaximum());
|
262 |
ofdata->SetLineColor(kRed);
|
263 |
sfdata->Draw("e1");
|
264 |
ofdata->Draw("histo,same");
|
265 |
sfdata->Draw("e1,same");
|
266 |
leg->SetHeader("Data:");
|
267 |
leg->Draw();
|
268 |
DrawPrelim();
|
269 |
|
270 |
Save_With_Ratio(sfdata,ofdata,pad3->cd(),"WZ_study/OFSFcomparison_data");
|
271 |
|
272 |
delete can;
|
273 |
|
274 |
dout << "SF events: " << sfdata->Integral() << " (mc : " << sfmc->Integral() << " , wz : " << sfwz->Integral() << " ) WZ purity: " << 100*sfwz->Integral()/sfmc->Integral() << " %" << endl;
|
275 |
dout << "OF events: " << ofdata->Integral() << " (mc : " << ofmc->Integral() << " , wz : " << ofwz->Integral() << " ) WZ purity: " << 100*ofwz->Integral()/ofmc->Integral() << " %" << endl;
|
276 |
|
277 |
dout << "RATIO : SF / OF = " << sfdata->Integral() / ofdata->Integral() << " +/- " << (sfdata->Integral()/ofdata->Integral()) * TMath::Sqrt(1/sfdata->Integral()+1/ofdata->Integral()) << " (stat) " << endl;
|
278 |
|
279 |
TriLeptons::Rsfof_CorrectionFactor=ofwz->Integral() / sfwz->Integral();
|
280 |
TriLeptons::Rsfof_CorrectionFactor_Error=(ofwz->Integral()/sfwz->Integral()) * TMath::Sqrt(1/sfwz->GetEntries()+1/ofwz->GetEntries());
|
281 |
delete sfdata;
|
282 |
delete ofdata;
|
283 |
delete sfwz;
|
284 |
delete ofwz;
|
285 |
|
286 |
}
|
287 |
|
288 |
void DrawMatchGenDistribution(string variable, int nbins, float low, float high, bool uselog, string xlabel, string SaveAs, TCut basecut) {
|
289 |
TLegend *leg = make_legend();
|
290 |
leg->SetY1(0.7);
|
291 |
TCanvas *can = new TCanvas("can","can");
|
292 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
293 |
pad->cd();
|
294 |
pad->SetLogy(uselog);
|
295 |
|
296 |
TCut IsMatch("(gentri_GoodWMatch&&gentri_GoodZMatch)");
|
297 |
TCut NoMatch("!(gentri_GoodWMatch&&gentri_GoodZMatch)");
|
298 |
|
299 |
TH1F *goodMatch = allsamples.Draw("goodMatch",variable,nbins,low,high,xlabel,"events",basecut&&IsMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
300 |
TH1F *noMatch = allsamples.Draw("noMatch", variable,nbins,low,high,xlabel,"events",basecut&&NoMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
301 |
|
302 |
noMatch->SetLineColor(TColor::GetColor("#FF0000"));//an evil red
|
303 |
goodMatch->SetLineColor(TColor::GetColor("#04B404")); // a nice green
|
304 |
|
305 |
// noMatch->Scale(1.0/noMatch->Integral());
|
306 |
// goodMatch->Scale(1.0/goodMatch->Integral());
|
307 |
|
308 |
if(noMatch->GetMaximum()>goodMatch->GetMaximum()) goodMatch->SetMaximum(1.3*noMatch->GetMaximum());
|
309 |
|
310 |
goodMatch->Draw("histo");
|
311 |
noMatch->Draw("histo,same");
|
312 |
|
313 |
leg->AddEntry(goodMatch,"correct match","l");
|
314 |
leg->AddEntry(noMatch,"incorrect match","l");
|
315 |
leg->Draw();
|
316 |
|
317 |
Save_With_Ratio(goodMatch,noMatch,pad->cd(),"WZ_study/GenMatchComparison/"+SaveAs);
|
318 |
|
319 |
delete goodMatch;
|
320 |
delete noMatch;
|
321 |
delete can;
|
322 |
}
|
323 |
|
324 |
void DrawMatchRecoDistribution(string variable, int nbins, float low, float high, bool uselog, string xlabel, string SaveAs, TCut basecut) {
|
325 |
TLegend *leg = make_legend();
|
326 |
leg->SetY1(0.7);
|
327 |
TCanvas *can = new TCanvas("can","can");
|
328 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
329 |
pad->cd();
|
330 |
pad->SetLogy(uselog);
|
331 |
|
332 |
TCut IsMatch("(tri_GoodWMatch&&tri_GoodZMatch)");
|
333 |
TCut NoMatch("!(tri_GoodWMatch&&tri_GoodZMatch)");
|
334 |
|
335 |
TH1F *goodMatch = allsamples.Draw("goodMatch",variable,nbins,low,high,xlabel,"events",basecut&&IsMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
336 |
TH1F *noMatch = allsamples.Draw("noMatch", variable,nbins,low,high,xlabel,"events",basecut&&NoMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
337 |
|
338 |
noMatch->SetLineColor(TColor::GetColor("#FF0000"));//an evil red
|
339 |
goodMatch->SetLineColor(TColor::GetColor("#04B404")); // a nice green
|
340 |
|
341 |
// noMatch->Scale(1.0/noMatch->Integral());
|
342 |
// goodMatch->Scale(1.0/goodMatch->Integral());
|
343 |
|
344 |
if(noMatch->GetMaximum()>goodMatch->GetMaximum()) goodMatch->SetMaximum(1.3*noMatch->GetMaximum());
|
345 |
|
346 |
goodMatch->Draw("histo");
|
347 |
noMatch->Draw("histo,same");
|
348 |
|
349 |
leg->AddEntry(goodMatch,"correct match","l");
|
350 |
leg->AddEntry(noMatch,"incorrect match","l");
|
351 |
leg->Draw();
|
352 |
DrawPrelim();
|
353 |
|
354 |
Save_With_Ratio(goodMatch,noMatch,pad->cd(),"WZ_study/RecoMatchComparison/"+SaveAs);
|
355 |
|
356 |
delete goodMatch;
|
357 |
delete noMatch;
|
358 |
delete can;
|
359 |
}
|
360 |
|
361 |
void GenSFOFCalculator(string title, TCut Cut) {
|
362 |
TH1F *histoSF = allsamples.Draw("histoSF","gentri_mll",1,0,1000,"processing","events",Cut&&TCut("abs(gentri_id2)==abs(gentri_id3)"),mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
363 |
TH1F *histoOF = allsamples.Draw("histoOF","gentri_mll",1,0,1000,"processing","events",Cut&&TCut("abs(gentri_id2)!=abs(gentri_id3)"),mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
364 |
cout << title << endl;
|
365 |
cout << " " << (const char*) Cut << endl;
|
366 |
cout << " SF: \t" << histoSF->Integral() << " +/- " << sqrt(histoSF->GetEntries())*(histoSF->Integral()/histoSF->GetEntries()) << endl;
|
367 |
cout << " OF: \t" << histoOF->Integral() << " +/- " << sqrt(histoOF->Integral())*(histoOF->Integral()/histoOF->GetEntries()) << endl;
|
368 |
cout << " SF/OF: \t" << histoSF->Integral() / histoOF->Integral() << " +/- " << histoSF->GetEntries() / histoOF->GetEntries() * sqrt(1.0/histoSF->GetEntries() + 1.0 / histoOF->GetEntries()) << endl;
|
369 |
|
370 |
delete histoSF;
|
371 |
delete histoOF;
|
372 |
}
|
373 |
|
374 |
void reco_SF_OF_comparison(TCut Base, TCut Selection) {
|
375 |
|
376 |
bool dolog=true;
|
377 |
bool nolog=false;
|
378 |
|
379 |
DrawMatchRecoDistribution("tri_mlll",60,0,300,dolog,"m_{lll}","TrileptonMass",Base);
|
380 |
DrawMatchRecoDistribution("tri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","LeadingDileptonMass",Base);
|
381 |
DrawMatchRecoDistribution("tri_mT",50,0,100,nolog,"m_{T}","MT",Base);
|
382 |
DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass",Base);
|
383 |
DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_SF",Base&&TCut("abs(tri_id2)==abs(tri_id3)"));
|
384 |
DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_OF",Base&&TCut("abs(tri_id2)!=abs(tri_id3)"));
|
385 |
DrawMatchRecoDistribution("genMET",60,0,300,dolog,"gen MET","MET",Base);
|
386 |
DrawMatchRecoDistribution("abs(tri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","genID1",Base);
|
387 |
DrawMatchRecoDistribution("abs(tri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","genID2",Base);
|
388 |
DrawMatchRecoDistribution("abs(tri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","genID3",Base);
|
389 |
DrawMatchRecoDistribution("abs(tri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","genMID1",Base);
|
390 |
DrawMatchRecoDistribution("abs(tri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","genMID2",Base);
|
391 |
DrawMatchRecoDistribution("abs(tri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","genMID3",Base);
|
392 |
|
393 |
DrawMatchRecoDistribution("tri_mlll",60,0,300,dolog,"m_{lll}","FullSelection/TrileptonMass",Base&&Selection);
|
394 |
DrawMatchRecoDistribution("tri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","FullSelection/LeadingDileptonMass",Base&&Selection);
|
395 |
DrawMatchRecoDistribution("tri_mT",50,0,100,nolog,"m_{T}","FullSelection/MT",Base&&Selection);
|
396 |
DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass",Base&&Selection);
|
397 |
DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_SF",Base&&TCut("abs(tri_id2)==abs(tri_id3)")&&Selection);
|
398 |
DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_OF",Base&&TCut("abs(tri_id2)!=abs(tri_id3)")&&Selection);
|
399 |
DrawMatchRecoDistribution("genMET",60,0,300,dolog,"gen MET","FullSelection/MET",Base&&Selection);
|
400 |
DrawMatchRecoDistribution("abs(tri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","FullSelection/genID1",Base&&Selection);
|
401 |
DrawMatchRecoDistribution("abs(tri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","FullSelection/genID2",Base&&Selection);
|
402 |
DrawMatchRecoDistribution("abs(tri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","FullSelection/genID3",Base&&Selection);
|
403 |
DrawMatchRecoDistribution("abs(tri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","FullSelection/genMID1",Base&&Selection);
|
404 |
DrawMatchRecoDistribution("abs(tri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","FullSelection/genMID2",Base&&Selection);
|
405 |
DrawMatchRecoDistribution("abs(tri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","FullSelection/genMID3",Base&&Selection);
|
406 |
}
|
407 |
|
408 |
void generator_SF_OF_comparison() {
|
409 |
/*we want to analyze the cuts at generator level (and their impact), plus understand how bad matching can affect the selection.
|
410 |
we want to know the distributions for correctly and incorrectly matched W/Z for the following variables:
|
411 |
- M_{lll}
|
412 |
- M_{ll}
|
413 |
- M_{T}
|
414 |
- M_{l_{2}l_{3}}
|
415 |
- MET
|
416 |
*/
|
417 |
TCut genBase("genNleptons>=3 && gentri_pt1>30 && gentri_pt2>20 && gentri_pt3>20");
|
418 |
TCut genParticleBase("genNleptons>=3 && pgentri_pt1>30 && pgentri_pt2>20 && pgentri_pt3>20");
|
419 |
|
420 |
TCut Selection("abs(gentri_mlll-91)>30 && genMET>30 && abs(gentri_mll-91)<10 && gentri_mT > 40");
|
421 |
TCut genParticleSelection("abs(pgentri_mlll-91)>30 && genMET>30 && abs(pgentri_mll-91)<10 && abs(pgentri_submll-91)>20 && pgentri_mT > 40");
|
422 |
|
423 |
bool dolog=true;
|
424 |
bool nolog=false;
|
425 |
|
426 |
DrawMatchGenDistribution("gentri_mlll",60,0,300,dolog,"m_{lll}","TrileptonMass",genBase);
|
427 |
DrawMatchGenDistribution("gentri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","LeadingDileptonMass",genBase);
|
428 |
DrawMatchGenDistribution("gentri_mT",50,0,100,nolog,"m_{T}","MT",genBase);
|
429 |
DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass",genBase);
|
430 |
DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_SF",genBase&&TCut("abs(gentri_id2)==abs(gentri_id3)"));
|
431 |
DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_OF",genBase&&TCut("abs(gentri_id2)!=abs(gentri_id3)"));
|
432 |
DrawMatchGenDistribution("genMET",60,0,300,dolog,"gen MET","MET",genBase);
|
433 |
DrawMatchGenDistribution("abs(gentri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","genID1",genBase);
|
434 |
DrawMatchGenDistribution("abs(gentri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","genID2",genBase);
|
435 |
DrawMatchGenDistribution("abs(gentri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","genID3",genBase);
|
436 |
DrawMatchGenDistribution("abs(gentri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","genMID1",genBase);
|
437 |
DrawMatchGenDistribution("abs(gentri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","genMID2",genBase);
|
438 |
DrawMatchGenDistribution("abs(gentri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","genMID3",genBase);
|
439 |
|
440 |
DrawMatchGenDistribution("gentri_mlll",60,0,300,dolog,"m_{lll}","FullSelection/TrileptonMass",genBase&&Selection);
|
441 |
DrawMatchGenDistribution("gentri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","FullSelection/LeadingDileptonMass",genBase&&Selection);
|
442 |
DrawMatchGenDistribution("gentri_mT",50,0,100,nolog,"m_{T}","FullSelection/MT",genBase&&Selection);
|
443 |
DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass",genBase&&Selection);
|
444 |
DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_SF",genBase&&TCut("abs(gentri_id2)==abs(gentri_id3)")&&Selection);
|
445 |
DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_OF",genBase&&TCut("abs(gentri_id2)!=abs(gentri_id3)")&&Selection);
|
446 |
DrawMatchGenDistribution("genMET",60,0,300,dolog,"gen MET","FullSelection/MET",genBase&&Selection);
|
447 |
DrawMatchGenDistribution("abs(gentri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","FullSelection/genID1",genBase&&Selection);
|
448 |
DrawMatchGenDistribution("abs(gentri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","FullSelection/genID2",genBase&&Selection);
|
449 |
DrawMatchGenDistribution("abs(gentri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","FullSelection/genID3",genBase&&Selection);
|
450 |
DrawMatchGenDistribution("abs(gentri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","FullSelection/genMID1",genBase&&Selection);
|
451 |
DrawMatchGenDistribution("abs(gentri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","FullSelection/genMID2",genBase&&Selection);
|
452 |
DrawMatchGenDistribution("abs(gentri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","FullSelection/genMID3",genBase&&Selection);
|
453 |
|
454 |
return;
|
455 |
|
456 |
|
457 |
GenSFOFCalculator("Basic selection",genBase);
|
458 |
GenSFOFCalculator("Basic selection, correct Z",genBase&&TCut("gentri_GoodZMatch"));
|
459 |
GenSFOFCalculator("Basic selection, wrong Z",genBase&&TCut("!gentri_GoodZMatch"));
|
460 |
GenSFOFCalculator("Outside |m_{23}-Z|<20",genBase&&TCut("abs(gentri_submll-91)>20"));
|
461 |
GenSFOFCalculator("Outside |m_{23}-Z|<20, Correct Z", genBase&&TCut("abs(gentri_submll-91)>20&&gentri_GoodZMatch"));
|
462 |
GenSFOFCalculator("Outside |m_{23}-Z|<20, Wrong Z", genBase&&TCut("abs(gentri_submll-91)>20&&!gentri_GoodZMatch"));
|
463 |
GenSFOFCalculator("Outside |m_{23}-Z|<20, Correct W", genBase&&TCut("abs(gentri_submll-91)>20&&gentri_GoodWMatch"));
|
464 |
GenSFOFCalculator("Outside |m_{23}-Z|<20, Wrong W", genBase&&TCut("abs(gentri_submll-91)>20&&!gentri_GoodWMatch"));
|
465 |
GenSFOFCalculator("Outside |m_{23}-Z|<20, Correct Z, correct W", genBase&&TCut("abs(gentri_submll-91)>20&&gentri_GoodZMatch&&gentri_GoodWMatch"));
|
466 |
GenSFOFCalculator("Outside |m_{23}-Z|<20, Wrong Z or W", genBase&&TCut("abs(gentri_submll-91)>20&&!(gentri_GoodZMatch&&gentri_GoodWMatch)"));
|
467 |
GenSFOFCalculator("Full selection, Correct Z and W", genBase&&Selection&&TCut("abs(gentri_submll-91)>20&&(gentri_GoodZMatch&&gentri_GoodWMatch)"));
|
468 |
GenSFOFCalculator("Full selection, Wrong Z or W", genBase&&Selection&&TCut("abs(gentri_submll-91)>20&&!(gentri_GoodZMatch&&gentri_GoodWMatch)"));
|
469 |
// GenSFOFCalculator("Full selection", genBase&&Selection);
|
470 |
// GenSFOFCalculator("Full selection with genParticles", genBase&&genParticleSelection&&TCut("abs(gentri_submll-91)>20"));
|
471 |
|
472 |
|
473 |
}
|
474 |
|
475 |
|
476 |
void AlgorithmTest(TCut BasicCut, TCut Selection) {
|
477 |
TCut Pure("tri_GoodWMatch && tri_GoodZMatch");
|
478 |
|
479 |
int nbins=38;
|
480 |
float mll_low=10;
|
481 |
float mll_hi=200;
|
482 |
|
483 |
TCanvas *can = new TCanvas("can","can");
|
484 |
TH1F *sfwz = allsamples.Draw("sfwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
485 |
TH1F *ofwz = allsamples.Draw("ofwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
486 |
|
487 |
TH1F *sfwzpure = allsamples.Draw("sfwzpure","tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF&&Pure,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
488 |
TH1F *ofwzpure = allsamples.Draw("ofwzpure","tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF&&Pure,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
489 |
|
490 |
delete can;
|
491 |
|
492 |
dout << "SF WZ events: " << sfwz->Integral() << " (correctly combined WZ: " << sfwzpure->Integral() << ")" << endl;
|
493 |
dout << "OF WZ events: " << ofwz->Integral() << " (correctly combined WZ: " << ofwzpure->Integral() << ")" << endl;
|
494 |
|
495 |
dout << "RATIO : SF / OF = " << sfwz->Integral() / ofwz->Integral() << " +/- " << sfwz->Integral()/ofwz->Integral() * sqrt(1/sfwz->GetEntries() + 1/ofwz->GetEntries()) << endl;
|
496 |
dout << " PURE: SF / OF = " << sfwzpure->Integral() / ofwzpure->Integral() << " +/- " << sfwzpure->Integral()/ofwzpure->Integral() * sqrt(1/sfwzpure->GetEntries() + 1/ofwzpure->GetEntries()) << endl;
|
497 |
dout << "PURITY: " << endl;
|
498 |
dout << " SF : " << 100.0*sfwzpure->Integral()/sfwz->Integral() << " +/- " << 100.0*sfwzpure->Integral()/sfwz->Integral() * sqrt(1/sfwzpure->GetEntries() + 1/sfwz->GetEntries()) <<endl;
|
499 |
dout << " OF : " << 100.0*ofwzpure->Integral()/ofwz->Integral() << " +/- " << 100.0*ofwzpure->Integral()/ofwz->Integral() * sqrt(1/ofwzpure->GetEntries() + 1/ofwz->GetEntries()) <<endl;
|
500 |
|
501 |
|
502 |
delete sfwz;
|
503 |
delete ofwz;
|
504 |
delete sfwzpure;
|
505 |
delete ofwzpure;
|
506 |
}
|
507 |
|
508 |
void GetResult(TCut BasicCut, TCut Selection) {
|
509 |
if(TriLeptons::Rsfof_CorrectionFactor<0 || TriLeptons::Rsfof_CorrectionFactor_Error<0) SF_OF_comparison(BasicCut,Selection);
|
510 |
int nbins=38;
|
511 |
float mll_low=10;
|
512 |
float mll_hi=200;
|
513 |
|
514 |
TCanvas *can = new TCanvas("can","can");
|
515 |
TH1F *sfwz = SingleLeptonData.Draw("sfwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF,data,luminosity);
|
516 |
TH1F *ofwz = SingleLeptonData.Draw("ofwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF,data,luminosity);
|
517 |
|
518 |
delete can;
|
519 |
|
520 |
dout << " ****** FINAL RESULT ****** " << endl;
|
521 |
dout << "SF events: " << sfwz->Integral() << " +/- " << sqrt(sfwz->Integral()) << endl;
|
522 |
dout << "OF events: " << ofwz->Integral() << " +/- " << sqrt(ofwz->Integral()) << endl;
|
523 |
|
524 |
dout << "Correction factor : " << TriLeptons::Rsfof_CorrectionFactor << " +/- " << TriLeptons::Rsfof_CorrectionFactor_Error << endl;
|
525 |
|
526 |
float rawstatuncert=sfwz->Integral()/ofwz->Integral() * sqrt(1/sfwz->GetEntries() + 1/ofwz->GetEntries());
|
527 |
float rawresult=sfwz->Integral() / ofwz->Integral();
|
528 |
dout << "UNCORRECTED RATIO : SF / OF = " << rawresult << " +/- " << rawstatuncert << endl;
|
529 |
dout << "CORRECTED RATIO : SF / OF = " << TriLeptons::Rsfof_CorrectionFactor * rawresult << " +/- " << (TriLeptons::Rsfof_CorrectionFactor * rawresult) * sqrt(rawstatuncert*rawstatuncert/(rawresult*rawresult) + ( TriLeptons::Rsfof_CorrectionFactor_Error * TriLeptons::Rsfof_CorrectionFactor_Error )/(TriLeptons::Rsfof_CorrectionFactor * TriLeptons::Rsfof_CorrectionFactor));
|
530 |
|
531 |
|
532 |
delete sfwz;
|
533 |
delete ofwz;
|
534 |
// delete can;
|
535 |
}
|
536 |
|
537 |
|
538 |
void PredictionFailurePlot(string truthvariable, string predictionvariable, int nbins, float min, float max, TCut PredictionCut, TCut TruthCut, string saveas, string xlabel) {
|
539 |
TLegend *leg = make_legend();
|
540 |
leg->SetY1(0.7);
|
541 |
TCanvas *can = new TCanvas("can","can");
|
542 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
543 |
pad->cd();
|
544 |
// pad->SetLogy(1);
|
545 |
|
546 |
TH1F *Prediction = allsamples.Draw("Prediction",predictionvariable,nbins,min,max,xlabel,"events",PredictionCut,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
547 |
TH1F *MCTruth = allsamples.Draw("MCTruth", truthvariable, nbins,min,max,xlabel,"events",TruthCut ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
548 |
|
549 |
Prediction->SetLineColor(TColor::GetColor("#FF0000"));//an evil red
|
550 |
MCTruth->SetLineColor(TColor::GetColor("#04B404")); // a nice green
|
551 |
|
552 |
// if(Prediction->GetMaximum()>MCTruth->GetMaximum()) MCTruth->SetMaximum(1.3*Prediction->GetMaximum());
|
553 |
|
554 |
if(MCTruth->GetMaximum()>Prediction->GetMaximum()) {
|
555 |
MCTruth->SetMaximum(MCTruth->GetMaximum()*1.2);
|
556 |
MCTruth->DrawNormalized("histo");
|
557 |
Prediction->DrawNormalized("histo,same");
|
558 |
} else {
|
559 |
Prediction->SetMaximum(Prediction->GetMaximum()*1.2);
|
560 |
Prediction->DrawNormalized("histo");
|
561 |
MCTruth->DrawNormalized("histo,same");
|
562 |
}
|
563 |
|
564 |
|
565 |
leg->AddEntry(Prediction,"prediction (norm.)","l");
|
566 |
leg->AddEntry(MCTruth,"MC truth (norm.)","l");
|
567 |
leg->Draw();
|
568 |
DrawMCPrelim();
|
569 |
Save_With_Ratio(MCTruth,Prediction,pad->cd(),"WZ_study/PredictionMethodFailure/"+saveas);
|
570 |
|
571 |
delete Prediction;
|
572 |
delete MCTruth;
|
573 |
delete can;
|
574 |
|
575 |
|
576 |
|
577 |
}
|
578 |
|
579 |
void WhyDoesThePredictionMethodFail(TCut PredictionCut, TCut TruthCut) {
|
580 |
PredictionFailurePlot("tri_submll","tri_badsubmll",50,0,200,PredictionCut,TruthCut,"SubMll","m_{23}");
|
581 |
PredictionFailurePlot("tri_mT","tri_badmT",50,0,200,PredictionCut,TruthCut,"MT","m_{T}");
|
582 |
PredictionFailurePlot("tri_mll","tri_badmll",25,0,200,PredictionCut,TruthCut,"Mll","m_{12}");
|
583 |
}
|
584 |
|
585 |
|
586 |
void ComputeNewMiscombinationRate(TCut origSelection, TCut sBasicCut) {
|
587 |
TCanvas *can = new TCanvas("can","can");
|
588 |
|
589 |
string sSelection= (const char*)origSelection;
|
590 |
sSelection= ReplaceAll(sSelection,"tri_","tri_bad");
|
591 |
sSelection= ReplaceAll(sSelection,"tri_badmlll","tri_mlll");
|
592 |
cout << "modified " << (const char*)origSelection << " to " << sSelection << endl;
|
593 |
|
594 |
TCut FlavorBlindSelection((sSelection+(string)"&&(abs(tri_id2)!=abs(tri_id3))").c_str()); // making sure we select OF events
|
595 |
TCut CorrectSelection (origSelection && TCut("(abs(tri_id2)!=abs(tri_id3))")); // making sure we select OF events
|
596 |
TCut OFZ ("tri_mll!=tri_badmll");
|
597 |
|
598 |
TH1F *WZ_OF_OFZ = allsamples.Draw("WZ_OFZ" ,"tri_badsubmll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", FlavorBlindSelection&&OFZ ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
599 |
TH1F *WZ_OF_any = allsamples.Draw("WZ_OF_any" ,"tri_badsubmll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", FlavorBlindSelection ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
600 |
|
601 |
TH1F *data_OF_OFZ = SingleLeptonData.Draw("data_OFZ" ,"tri_badsubmll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", FlavorBlindSelection&&OFZ ,data,luminosity);
|
602 |
TH1F *data_OF_any = SingleLeptonData.Draw("data_OF_any" ,"tri_badsubmll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", FlavorBlindSelection ,data,luminosity);
|
603 |
|
604 |
dout << "Miscombination rate in WZ sample with selection in place : " << 100 * WZ_OF_OFZ->Integral() / WZ_OF_any->Integral() << " +/- " << 100*(WZ_OF_OFZ->Integral() / WZ_OF_any->Integral())* sqrt( 1.0/WZ_OF_OFZ->GetEntries() + 1.0/WZ_OF_any->GetEntries())<< " % (" << WZ_OF_OFZ->Integral() << " / " << WZ_OF_any->Integral() << ")" << endl;
|
605 |
dout << "Miscombination rate in DATA with selection in place : " << 100 * data_OF_OFZ->Integral() / data_OF_any->Integral() << " +/- " << 100*(data_OF_OFZ->Integral() / data_OF_any->Integral()) * sqrt( 1.0/data_OF_OFZ->Integral() + 1.0/data_OF_any->Integral() ) << " % (" << data_OF_OFZ->Integral() << " / " << data_OF_any->Integral() << ")" << endl;
|
606 |
|
607 |
delete WZ_OF_any;
|
608 |
delete WZ_OF_OFZ;
|
609 |
delete can;
|
610 |
}
|
611 |
|
612 |
void ComputeMiscombinationRate(TCut origSelection, TCut sBasicCut) {
|
613 |
/* TCanvas *can = new TCanvas("can","can");
|
614 |
//idea: use the flavor-blind version of the algorithm to obtain the yields in our signal region.
|
615 |
string sSelection= (const char*)origSelection;
|
616 |
sSelection= ReplaceAll(sSelection,"tri_","tri_bad");
|
617 |
sSelection= ReplaceAll(sSelection,"tri_badmlll","tri_mlll");
|
618 |
cout << "modified " << (const char*)origSelection << " to " << sSelection << endl;
|
619 |
|
620 |
TCut BadSelection((sSelection+(string)"&&abs(tri_id2)!=abs(tri_id3)").c_str()); // making sure we select OF events
|
621 |
TCut GoodSelection(origSelection && TCut("abs(tri_id2)!=abs(tri_id3)")); // making sure we select OF events
|
622 |
|
623 |
TCut BasicCut(sBasicCut&&TCut("tri_id2!=tri_id3"));
|
624 |
|
625 |
TCut TruthBad("!(tri_GoodZMatch&&tri_GoodZMatch)");
|
626 |
TCut MethodBad("!(tri_id2==tri_badid2&&tri_id3==tri_badid3)");
|
627 |
|
628 |
for(int icut=0;icut<2;icut++) {
|
629 |
TCut Goodused;
|
630 |
TCut Badused;
|
631 |
if(icut==0) {
|
632 |
Goodused=BasicCut;
|
633 |
Badused =BasicCut;
|
634 |
cout << "Preselection only: " << endl;
|
635 |
cout << " used : " << (const char*) Goodused << endl;
|
636 |
} else {
|
637 |
Goodused=BasicCut&&GoodSelection;
|
638 |
Badused =BasicCut&&BadSelection;
|
639 |
cout << "Full selection: " << endl;
|
640 |
cout << " Good used : " << (const char*) Goodused << endl;
|
641 |
cout << " Bad used : " << (const char*) Goodused << endl;
|
642 |
}
|
643 |
|
644 |
TH1F *Truth_badcomb = allsamples.Draw("Truth_badcomb" ,"tri_submll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", Goodused ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
645 |
TH1F *Truth_all = allsamples.Draw("Truth_all" ,"tri_submll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", Goodused ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
646 |
|
647 |
TH1F *Events_WZ = allsamples.Draw("Events_WZ" ,"tri_submll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", Goodused ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
648 |
TH1F *bad_WZ = allsamples.Draw("bad_WZ" ,"tri_submll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", Goodused&&TruthBad ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
649 |
TH1F *MethodBad_WZ = allsamples.Draw("MethodBad_WZ" ,"tri_submll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", Badused&&MethodBad,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
650 |
TH1F *MethodBad_WZg= allsamples.Draw("MethodBad_WZg","tri_submll",1,0.0,1000.0,"m_{l_{2}l_{3}} [GeV]", "events", Badused,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
|
651 |
|
652 |
cout << " ********** WZ **********" << endl;
|
653 |
cout << " N events : " << Events_WZ->Integral() << "\t (mc events: " << Events_WZ->GetEntries() << ")" << endl;
|
654 |
cout << " Bad combinations: " << bad_WZ->Integral() << "\t (mc events: " << bad_WZ->GetEntries() << ")" << endl;
|
655 |
cout << " Predicted bad com.: " << MethodBad_WZ->Integral() << " / " << MethodBad_WZg->Integral() << "\t (mc events: " << MethodBad_WZ->GetEntries() << ")" << endl;
|
656 |
|
657 |
|
658 |
delete Events_WZ;
|
659 |
delete bad_WZ;
|
660 |
delete MethodBad_WZ;
|
661 |
delete MethodBad_WZg;
|
662 |
}
|
663 |
delete can;
|
664 |
|
665 |
WhyDoesThePredictionMethodFail(BasicCut&&MethodBad,BasicCut&&TruthBad);
|
666 |
*/
|
667 |
}
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
void CarryOutWZStudy() {
|
673 |
|
674 |
WZ_kin_plot("mll",40,0,200,"m_{Z} [GeV]",TCut("id1==id2 && pfJetGoodNum40>=3 && abs(mll-91.2)<20 && pt1>30 && pt2>20 && abs(eta1)<2.4 && abs(eta2)<2.4"),"Crosscheck_Lumi");
|
675 |
WZ_kin_plot("mll",40,0,200,"m_{Z} [GeV]",TCut("id1==id2 && id1==0 && pfJetGoodNum40>=3 && abs(mll-91.2)<20 && pt1>30 && pt2>20 && abs(eta1)<2.4 && abs(eta2)<2.4"),"Crosscheck_Lumi_ee");
|
676 |
WZ_kin_plot("mll",40,0,200,"m_{Z} [GeV]",TCut("id1==id2 && id1==1 && pfJetGoodNum40>=3 && abs(mll-91.2)<20 && pt1>30 && pt2>20 && abs(eta1)<2.4 && abs(eta2)<2.4"),"Crosscheck_Lumi_mm");
|
677 |
|
678 |
TCut BasicCut("tri_MatchFound&&leptonNum>2&&tri_pt1>30&&tri_pt2>20&&tri_pt3>20");
|
679 |
TCut Selection("abs(tri_mlll-91)>30 && tri_mT>40 && met[4] > 30 && abs(tri_mll-91)<10 && tri_submll > 10 && abs(tri_submll-91)>5");
|
680 |
|
681 |
//OptimizeSelection(BasicCut);
|
682 |
|
683 |
//ComputeMiscombinationRate(Selection, BasicCut);
|
684 |
|
685 |
// ComputeNewMiscombinationRate(Selection, BasicCut);
|
686 |
|
687 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut,"Inclusive/Zmass");
|
688 |
WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut,"Inclusive/TrileptonMass");
|
689 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut,"Inclusive/mT");
|
690 |
WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut,"Inclusive/MET");
|
691 |
WZ_kin_plot("tri_pt1",40,0,400,"p_{T}^{1} [GeV]",BasicCut,"Inclusive/Pt1");
|
692 |
WZ_kin_plot("tri_pt2",40,0,400,"p_{T}^{2} [GeV]",BasicCut,"Inclusive/Pt2");
|
693 |
WZ_kin_plot("tri_pt3",40,0,400,"p_{T}^{3} [GeV]",BasicCut,"Inclusive/Pt3");
|
694 |
/*
|
695 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/Zmass");
|
696 |
WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/TrileptonMass");
|
697 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/mT");
|
698 |
WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/MET");
|
699 |
|
700 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/Zmass");
|
701 |
WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/TrileptonMass");
|
702 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/mT");
|
703 |
WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/MET");
|
704 |
|
705 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut,"CutFlow/Zmass__0_CutOnNothing");
|
706 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/Zmass__1_CutOn_MT");
|
707 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30"),"CutFlow/Zmass__2_CutOn_MT_n_Mll");
|
708 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30"),"CutFlow/Zmass__3_CutOn_MT_n_Mll_n_Met");
|
709 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30&&abs(tri_mll-91)<10"),"CutFlow/Zmass__4_CutOn_MT_n_Mll_n_Met_MllWindow");
|
710 |
|
711 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut,"CutFlow/MT__0_CutOnNothing");
|
712 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/MT__1_CutOn_MT");
|
713 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30"),"CutFlow/MT__2_CutOn_MT_n_Mll");
|
714 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30"),"CutFlow/MT__3_CutOn_MT_n_Mll_n_Met");
|
715 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30&&abs(tri_mll-91)<10"),"CutFlow/MT__4_CutOn_MT_n_Mll_n_Met_MllWindow");
|
716 |
|
717 |
WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut,"CutFlow/MET__0_CutOnNothing");
|
718 |
WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/MET__1_CutOn_MT");
|
719 |
WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30"),"CutFlow/MET__2_CutOn_MT_n_Mll");
|
720 |
WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30"),"CutFlow/MET__3_CutOn_MT_n_Mll_n_Met");
|
721 |
WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40&&abs(tri_mlll-91)>30&&met[4]>30&&abs(tri_mll-91)<10"),"CutFlow/MET__4_CutOn_MT_n_Mll_n_Met_MllWindow");
|
722 |
|
723 |
*/
|
724 |
WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&Selection,"Zmass");
|
725 |
WZ_kin_plot("tri_mlll",40,0,400,"m_{lll} [GeV]",BasicCut&&Selection,"TrileptonMass");
|
726 |
WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&Selection,"mT");
|
727 |
WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&Selection,"MET");
|
728 |
WZ_kin_plot("tri_pt1",40,0,400,"p_{T}^{1} [GeV]",BasicCut&&Selection,"Pt1");
|
729 |
WZ_kin_plot("tri_pt2",40,0,400,"p_{T}^{2} [GeV]",BasicCut&&Selection,"Pt2");
|
730 |
WZ_kin_plot("tri_pt3",40,0,400,"p_{T}^{3} [GeV]",BasicCut&&Selection,"Pt3");
|
731 |
|
732 |
|
733 |
WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepSF,"mllsub_SF");
|
734 |
WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepOF,"mllsub_OF");
|
735 |
WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepSF&&TCut("tri_id2==0"),"mllsub_SF_ee");
|
736 |
WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepSF&&TCut("tri_id2==1"),"mllsub_SF_mm");
|
737 |
WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepOF&&TCut("tri_id2==0"),"mllsub_OF_em");
|
738 |
WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepOF&&TCut("tri_id2==1"),"mllsub_OF_me");
|
739 |
|
740 |
|
741 |
SF_OF_comparison(BasicCut,Selection);
|
742 |
// generator_SF_OF_comparison();
|
743 |
// reco_SF_OF_comparison(BasicCut,Selection);
|
744 |
|
745 |
SF_vs_OF_plots("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection,TriLepSF,TriLepOF,mc,"mllsub_MC");
|
746 |
SF_vs_OF_plots("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection,TriLepSF,TriLepOF,data,"mllsub_data");
|
747 |
AlgorithmTest(BasicCut,Selection);
|
748 |
GetResult(BasicCut,Selection);
|
749 |
|
750 |
|
751 |
}
|
752 |
|
753 |
void Make_Chi2_Resolution_Minimization(TGraph *gr) {
|
754 |
TCanvas *can2 = new TCanvas("can2","can2");
|
755 |
can2->cd();
|
756 |
gStyle->SetOptFit(0);
|
757 |
gr->Draw("AP*");
|
758 |
gr->GetXaxis()->SetTitle("MET scale factor");
|
759 |
gr->GetYaxis()->SetTitle("#chi^{2}");
|
760 |
gr->GetXaxis()->CenterTitle();
|
761 |
gr->GetYaxis()->CenterTitle();
|
762 |
gr->Draw("AP*");
|
763 |
gr->Fit("pol3");
|
764 |
TF1 *fit = (TF1*)gr->GetFunction("pol3");
|
765 |
fit->SetLineWidth(2);
|
766 |
fit->SetLineColor(kBlue);
|
767 |
gr->Draw("AP*");
|
768 |
DrawPrelim();
|
769 |
CompleteSave(can2,"WZ_study/DYResolution/Result_Chi2");
|
770 |
delete can2;
|
771 |
}
|
772 |
|
773 |
void ExtractDYMissingResolution() {
|
774 |
|
775 |
TCanvas *can = new TCanvas("can","can");
|
776 |
|
777 |
TH1F *histoSF = SingleLeptonData.Draw("histoSF","met[4]",50,0,100,"MET [GeV]","events",TCut("id1==id2&&mll>0&&pfJetGoodNum40>=2"),data,luminosity);
|
778 |
TH1F *histoOF = SingleLeptonData.Draw("histoOF","met[4]",50,0,100,"MET [GeV]","events",TCut("id1!=id2&&mll>0&&pfJetGoodNum40>=2"),data,luminosity);
|
779 |
THStack histoMC = allsamples.DrawStack("histoMC","met[4]",50,0,100,"MET [GeV]","events",TCut("id1==id2&&mll>0&&pfJetGoodNum40>=2"),mc,luminosity);
|
780 |
TFile *f = new TFile("file.root","RECREATE");
|
781 |
|
782 |
TH1F *MC_wo_DY = CollapseStack(histoMC);
|
783 |
TIter nextSF = TIter(histoMC.GetHists());
|
784 |
TH1F *h;
|
785 |
while ( h = (TH1F*)nextSF() ) {
|
786 |
if(Contains(h->GetName(),"Z_Jets")) {
|
787 |
MC_wo_DY->Add(h,-1);
|
788 |
}
|
789 |
}
|
790 |
MC_wo_DY->Write();
|
791 |
|
792 |
|
793 |
int ntests=150;
|
794 |
TH1F *DYres[ntests];
|
795 |
|
796 |
float min_chi2=-1;
|
797 |
int best_index=-1;
|
798 |
stringstream allresults;
|
799 |
TGraph *gr = new TGraph();
|
800 |
for(int i=0;i<ntests;i++) {
|
801 |
|
802 |
float smearby=0.15*i/((float)ntests);
|
803 |
|
804 |
stringstream drawvariable;
|
805 |
drawvariable << "((" << 1+smearby << ")*met[4])";
|
806 |
cout << "Going to use the variable " << drawvariable.str() << endl;
|
807 |
stringstream name;
|
808 |
name << "histo_DY_" << i;
|
809 |
DYres[i] = allsamples.Draw(name.str().c_str(),drawvariable.str(),50,0,100,"MET [GeV]","events",TCut("id1==id2&&mll>0&&pfJetGoodNum40>=2"),mc,luminosity, allsamples.FindSample("DYJets"));
|
810 |
DYres[i]->Write();
|
811 |
|
812 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
813 |
pad->cd();
|
814 |
|
815 |
DrawPrelim();
|
816 |
MC_wo_DY->SetFillColor(kWhite);
|
817 |
MC_wo_DY->SetLineColor(kBlue);
|
818 |
TLegend *leg = make_legend();
|
819 |
leg->SetY1(0.8);
|
820 |
leg->AddEntry(histoSF,"data","pl");
|
821 |
leg->AddEntry(MC_wo_DY,"MC","l");
|
822 |
|
823 |
TH1F *sum = (TH1F*)MC_wo_DY->Clone("sum");
|
824 |
sum->Add(DYres[i]);
|
825 |
sum->Draw("histo");
|
826 |
histoSF->Draw("e1,same");
|
827 |
stringstream Result;
|
828 |
|
829 |
Double_t chi2;
|
830 |
Int_t ndf,igood;
|
831 |
Double_t res=0.0;
|
832 |
Double_t chi2prob = MarcosChi2TestX(histoSF,sum,chi2,ndf,igood,"UW");
|
833 |
Result << "#splitline{Smeared by : " << std::setprecision(3) << 100*smearby << " %}{#splitline{#chi^{2} / NDF : " << std::setprecision(3) << chi2 << " / " << ndf << "}{ #chi^{2} prob : " << std::setprecision(3) << chi2prob << "}}";
|
834 |
|
835 |
allresults << "\n" << smearby << ";" << chi2;
|
836 |
gr->SetPoint(i,smearby,chi2);
|
837 |
|
838 |
if(min_chi2<0||chi2<min_chi2) {
|
839 |
min_chi2=chi2;
|
840 |
best_index=i;
|
841 |
}
|
842 |
|
843 |
TPaveText *PurityPaveText = new TPaveText(0.60, 0.40,0.89, 0.6,"blNDC");
|
844 |
PurityPaveText->SetFillStyle(4000);
|
845 |
PurityPaveText->SetBorderSize(0);
|
846 |
PurityPaveText->SetFillColor(kWhite);
|
847 |
PurityPaveText->SetTextFont(42);
|
848 |
PurityPaveText->SetTextSize(0.042);
|
849 |
PurityPaveText->AddText(Result.str().c_str());
|
850 |
PurityPaveText->Draw();
|
851 |
DrawPrelim();
|
852 |
leg->Draw();
|
853 |
|
854 |
|
855 |
stringstream savethis;
|
856 |
savethis << "WZ_study/DYResolution/Response" << 100*smearby << "Percent";
|
857 |
|
858 |
Save_With_Ratio(histoSF,sum,pad->cd(),savethis.str());
|
859 |
}
|
860 |
|
861 |
gr->SetTitle("Chi2Diagram");
|
862 |
gr->SetName("Chi2Diagram");
|
863 |
|
864 |
|
865 |
dout << "Result summary: " << endl;
|
866 |
dout << allresults.str() << endl;
|
867 |
|
868 |
nextSF = TIter(histoMC.GetHists());
|
869 |
THStack stack;
|
870 |
while ( h = (TH1F*)nextSF() ) {
|
871 |
if(!Contains(h->GetName(),"Z_Jets")) {
|
872 |
stack.Add(h);
|
873 |
}
|
874 |
}
|
875 |
|
876 |
|
877 |
TPad *pad = new TPad("pad","pad",0,0,1,1);
|
878 |
pad->cd();
|
879 |
|
880 |
DYres[best_index]->SetFillColor(kYellow);
|
881 |
DYres[best_index]->SetLineColor(kYellow);
|
882 |
|
883 |
stack.Add(DYres[best_index]);
|
884 |
stack.Draw();
|
885 |
histoSF->Draw("e1,same");
|
886 |
DrawPrelim();
|
887 |
Save_With_Ratio(histoSF,CollapseStack(stack),pad->cd(),"WZ_study/DYResolution/Result");
|
888 |
|
889 |
TFile *fr = new TFile("rumba.root","RECREATE");
|
890 |
gr->Write();
|
891 |
fr->Close();
|
892 |
|
893 |
delete can;
|
894 |
|
895 |
Make_Chi2_Resolution_Minimization(gr);
|
896 |
|
897 |
}
|
898 |
|
899 |
void WZstudy() {
|
900 |
// ExtractDYMissingResolution();
|
901 |
|
902 |
cutWeight=TCut("(weight*(weight<1000)*(is_data*tri_MatchFound+(!is_data)*(0.96*(tri_id1==1)+0.90*(tri_id1==0))))");
|
903 |
switch_overunderflow(true);
|
904 |
cout << "Essential cut is " << (const char*) essentialcut << endl;
|
905 |
cout << "Going to set essential cut to new triggers" << endl;
|
906 |
TCut essential_bkp = essentialcut;
|
907 |
essentialcut=TCut("mll>5||mll<6");
|
908 |
cout << "Essential cut is now " << (const char*) essentialcut << endl;
|
909 |
|
910 |
CarryOutWZStudy();
|
911 |
|
912 |
|
913 |
cout << "Essential cut is now " << (const char*) essentialcut << endl;
|
914 |
essentialcut = essential_bkp;
|
915 |
cout << "Essential cut is now " << (const char*) essentialcut << " (restored)" << endl;
|
916 |
switch_overunderflow(false);
|
917 |
|
918 |
}
|
919 |
|