ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/WZStudy.C
Revision: 1.8
Committed: Thu Jan 24 08:18:18 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.7: +30 -15 lines
Log Message:
Updated WZ studies to new saving format

File Contents

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