ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/WZStudy.C
Revision: 1.9
Committed: Fri Jan 25 14:01:31 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.8: +13 -10 lines
Log Message:
Added trigger matching to WZ analysis; enforced cleanup

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 buchmann 1.9 //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.9 delete sfdata;
274     delete ofdata;
275     delete sfwz;
276     delete ofwz;
277 buchmann 1.4
278     }
279    
280     void DrawMatchGenDistribution(string variable, int nbins, float low, float high, bool uselog, string xlabel, string SaveAs, TCut basecut) {
281     TLegend *leg = make_legend();
282     leg->SetY1(0.7);
283     TCanvas *can = new TCanvas("can","can");
284     TPad *pad = new TPad("pad","pad",0,0,1,1);
285     pad->cd();
286     pad->SetLogy(uselog);
287    
288     TCut IsMatch("(gentri_GoodWMatch&&gentri_GoodZMatch)");
289     TCut NoMatch("!(gentri_GoodWMatch&&gentri_GoodZMatch)");
290    
291     TH1F *goodMatch = allsamples.Draw("goodMatch",variable,nbins,low,high,xlabel,"events",basecut&&IsMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
292     TH1F *noMatch = allsamples.Draw("noMatch", variable,nbins,low,high,xlabel,"events",basecut&&NoMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
293    
294     noMatch->SetLineColor(TColor::GetColor("#FF0000"));//an evil red
295     goodMatch->SetLineColor(TColor::GetColor("#04B404")); // a nice green
296    
297     // noMatch->Scale(1.0/noMatch->Integral());
298     // goodMatch->Scale(1.0/goodMatch->Integral());
299    
300     if(noMatch->GetMaximum()>goodMatch->GetMaximum()) goodMatch->SetMaximum(1.3*noMatch->GetMaximum());
301    
302     goodMatch->Draw("histo");
303     noMatch->Draw("histo,same");
304    
305     leg->AddEntry(goodMatch,"correct match","l");
306     leg->AddEntry(noMatch,"incorrect match","l");
307     leg->Draw();
308    
309 buchmann 1.8 Save_With_Ratio(goodMatch,noMatch,pad->cd(),"WZ_study/GenMatchComparison/"+SaveAs);
310 buchmann 1.4
311     delete goodMatch;
312     delete noMatch;
313     delete can;
314     }
315    
316     void DrawMatchRecoDistribution(string variable, int nbins, float low, float high, bool uselog, string xlabel, string SaveAs, TCut basecut) {
317     TLegend *leg = make_legend();
318     leg->SetY1(0.7);
319     TCanvas *can = new TCanvas("can","can");
320     TPad *pad = new TPad("pad","pad",0,0,1,1);
321     pad->cd();
322     pad->SetLogy(uselog);
323    
324     TCut IsMatch("(tri_GoodWMatch&&tri_GoodZMatch)");
325     TCut NoMatch("!(tri_GoodWMatch&&tri_GoodZMatch)");
326    
327     TH1F *goodMatch = allsamples.Draw("goodMatch",variable,nbins,low,high,xlabel,"events",basecut&&IsMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
328     TH1F *noMatch = allsamples.Draw("noMatch", variable,nbins,low,high,xlabel,"events",basecut&&NoMatch,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
329    
330     noMatch->SetLineColor(TColor::GetColor("#FF0000"));//an evil red
331     goodMatch->SetLineColor(TColor::GetColor("#04B404")); // a nice green
332    
333     // noMatch->Scale(1.0/noMatch->Integral());
334     // goodMatch->Scale(1.0/goodMatch->Integral());
335    
336     if(noMatch->GetMaximum()>goodMatch->GetMaximum()) goodMatch->SetMaximum(1.3*noMatch->GetMaximum());
337    
338     goodMatch->Draw("histo");
339     noMatch->Draw("histo,same");
340    
341     leg->AddEntry(goodMatch,"correct match","l");
342     leg->AddEntry(noMatch,"incorrect match","l");
343     leg->Draw();
344     DrawPrelim();
345    
346 buchmann 1.8 Save_With_Ratio(goodMatch,noMatch,pad->cd(),"WZ_study/RecoMatchComparison/"+SaveAs);
347 buchmann 1.4
348     delete goodMatch;
349     delete noMatch;
350     delete can;
351     }
352    
353     void GenSFOFCalculator(string title, TCut Cut) {
354     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"));
355     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"));
356     cout << title << endl;
357     cout << " " << (const char*) Cut << endl;
358     cout << " SF: \t" << histoSF->Integral() << " +/- " << sqrt(histoSF->GetEntries())*(histoSF->Integral()/histoSF->GetEntries()) << endl;
359     cout << " OF: \t" << histoOF->Integral() << " +/- " << sqrt(histoOF->Integral())*(histoOF->Integral()/histoOF->GetEntries()) << endl;
360     cout << " SF/OF: \t" << histoSF->Integral() / histoOF->Integral() << " +/- " << histoSF->GetEntries() / histoOF->GetEntries() * sqrt(1.0/histoSF->GetEntries() + 1.0 / histoOF->GetEntries()) << endl;
361    
362     delete histoSF;
363     delete histoOF;
364     }
365    
366     void reco_SF_OF_comparison(TCut Base, TCut Selection) {
367    
368     bool dolog=true;
369     bool nolog=false;
370    
371     DrawMatchRecoDistribution("tri_mlll",60,0,300,dolog,"m_{lll}","TrileptonMass",Base);
372     DrawMatchRecoDistribution("tri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","LeadingDileptonMass",Base);
373     DrawMatchRecoDistribution("tri_mT",50,0,100,nolog,"m_{T}","MT",Base);
374     DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass",Base);
375     DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_SF",Base&&TCut("abs(tri_id2)==abs(tri_id3)"));
376     DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_OF",Base&&TCut("abs(tri_id2)!=abs(tri_id3)"));
377     DrawMatchRecoDistribution("genMET",60,0,300,dolog,"gen MET","MET",Base);
378     DrawMatchRecoDistribution("abs(tri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","genID1",Base);
379     DrawMatchRecoDistribution("abs(tri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","genID2",Base);
380     DrawMatchRecoDistribution("abs(tri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","genID3",Base);
381     DrawMatchRecoDistribution("abs(tri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","genMID1",Base);
382     DrawMatchRecoDistribution("abs(tri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","genMID2",Base);
383     DrawMatchRecoDistribution("abs(tri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","genMID3",Base);
384    
385     DrawMatchRecoDistribution("tri_mlll",60,0,300,dolog,"m_{lll}","FullSelection/TrileptonMass",Base&&Selection);
386     DrawMatchRecoDistribution("tri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","FullSelection/LeadingDileptonMass",Base&&Selection);
387     DrawMatchRecoDistribution("tri_mT",50,0,100,nolog,"m_{T}","FullSelection/MT",Base&&Selection);
388     DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass",Base&&Selection);
389     DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_SF",Base&&TCut("abs(tri_id2)==abs(tri_id3)")&&Selection);
390     DrawMatchRecoDistribution("tri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_OF",Base&&TCut("abs(tri_id2)!=abs(tri_id3)")&&Selection);
391     DrawMatchRecoDistribution("genMET",60,0,300,dolog,"gen MET","FullSelection/MET",Base&&Selection);
392     DrawMatchRecoDistribution("abs(tri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","FullSelection/genID1",Base&&Selection);
393     DrawMatchRecoDistribution("abs(tri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","FullSelection/genID2",Base&&Selection);
394     DrawMatchRecoDistribution("abs(tri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","FullSelection/genID3",Base&&Selection);
395     DrawMatchRecoDistribution("abs(tri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","FullSelection/genMID1",Base&&Selection);
396     DrawMatchRecoDistribution("abs(tri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","FullSelection/genMID2",Base&&Selection);
397     DrawMatchRecoDistribution("abs(tri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","FullSelection/genMID3",Base&&Selection);
398     }
399    
400     void generator_SF_OF_comparison() {
401     /*we want to analyze the cuts at generator level (and their impact), plus understand how bad matching can affect the selection.
402     we want to know the distributions for correctly and incorrectly matched W/Z for the following variables:
403     - M_{lll}
404     - M_{ll}
405     - M_{T}
406     - M_{l_{2}l_{3}}
407     - MET
408     */
409     TCut genBase("genNleptons>=3 && gentri_pt1>30 && gentri_pt2>20 && gentri_pt3>20");
410     TCut genParticleBase("genNleptons>=3 && pgentri_pt1>30 && pgentri_pt2>20 && pgentri_pt3>20");
411    
412     TCut Selection("abs(gentri_mlll-91)>30 && genMET>30 && abs(gentri_mll-91)<10 && gentri_mT > 40");
413     TCut genParticleSelection("abs(pgentri_mlll-91)>30 && genMET>30 && abs(pgentri_mll-91)<10 && abs(pgentri_submll-91)>20 && pgentri_mT > 40");
414    
415     bool dolog=true;
416     bool nolog=false;
417    
418     DrawMatchGenDistribution("gentri_mlll",60,0,300,dolog,"m_{lll}","TrileptonMass",genBase);
419     DrawMatchGenDistribution("gentri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","LeadingDileptonMass",genBase);
420     DrawMatchGenDistribution("gentri_mT",50,0,100,nolog,"m_{T}","MT",genBase);
421     DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass",genBase);
422     DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_SF",genBase&&TCut("abs(gentri_id2)==abs(gentri_id3)"));
423     DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","SubleadingDileptonMass_OF",genBase&&TCut("abs(gentri_id2)!=abs(gentri_id3)"));
424     DrawMatchGenDistribution("genMET",60,0,300,dolog,"gen MET","MET",genBase);
425     DrawMatchGenDistribution("abs(gentri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","genID1",genBase);
426     DrawMatchGenDistribution("abs(gentri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","genID2",genBase);
427     DrawMatchGenDistribution("abs(gentri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","genID3",genBase);
428     DrawMatchGenDistribution("abs(gentri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","genMID1",genBase);
429     DrawMatchGenDistribution("abs(gentri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","genMID2",genBase);
430     DrawMatchGenDistribution("abs(gentri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","genMID3",genBase);
431    
432     DrawMatchGenDistribution("gentri_mlll",60,0,300,dolog,"m_{lll}","FullSelection/TrileptonMass",genBase&&Selection);
433     DrawMatchGenDistribution("gentri_mll",60,0,300,dolog,"m_{l_{1}l_{2}}","FullSelection/LeadingDileptonMass",genBase&&Selection);
434     DrawMatchGenDistribution("gentri_mT",50,0,100,nolog,"m_{T}","FullSelection/MT",genBase&&Selection);
435     DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass",genBase&&Selection);
436     DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_SF",genBase&&TCut("abs(gentri_id2)==abs(gentri_id3)")&&Selection);
437     DrawMatchGenDistribution("gentri_submll",60,0,300,nolog,"m_{l_{2}l_{3}}","FullSelection/SubleadingDileptonMass_OF",genBase&&TCut("abs(gentri_id2)!=abs(gentri_id3)")&&Selection);
438     DrawMatchGenDistribution("genMET",60,0,300,dolog,"gen MET","FullSelection/MET",genBase&&Selection);
439     DrawMatchGenDistribution("abs(gentri_id1)",50,-0.5,49.5,nolog,"id(l_{1})","FullSelection/genID1",genBase&&Selection);
440     DrawMatchGenDistribution("abs(gentri_id2)",50,-0.5,49.5,nolog,"id(l_{2})","FullSelection/genID2",genBase&&Selection);
441     DrawMatchGenDistribution("abs(gentri_id3)",50,-0.5,49.5,nolog,"id(l_{3})","FullSelection/genID3",genBase&&Selection);
442     DrawMatchGenDistribution("abs(gentri_genMID1)",50,-0.5,49.5,nolog,"mother id(l_{1})","FullSelection/genMID1",genBase&&Selection);
443     DrawMatchGenDistribution("abs(gentri_genMID2)",50,-0.5,49.5,nolog,"mother id(l_{2})","FullSelection/genMID2",genBase&&Selection);
444     DrawMatchGenDistribution("abs(gentri_genMID3)",50,-0.5,49.5,nolog,"mother id(l_{3})","FullSelection/genMID3",genBase&&Selection);
445    
446     return;
447    
448    
449     GenSFOFCalculator("Basic selection",genBase);
450     GenSFOFCalculator("Basic selection, correct Z",genBase&&TCut("gentri_GoodZMatch"));
451     GenSFOFCalculator("Basic selection, wrong Z",genBase&&TCut("!gentri_GoodZMatch"));
452     GenSFOFCalculator("Outside |m_{23}-Z|<20",genBase&&TCut("abs(gentri_submll-91)>20"));
453     GenSFOFCalculator("Outside |m_{23}-Z|<20, Correct Z", genBase&&TCut("abs(gentri_submll-91)>20&&gentri_GoodZMatch"));
454     GenSFOFCalculator("Outside |m_{23}-Z|<20, Wrong Z", genBase&&TCut("abs(gentri_submll-91)>20&&!gentri_GoodZMatch"));
455     GenSFOFCalculator("Outside |m_{23}-Z|<20, Correct W", genBase&&TCut("abs(gentri_submll-91)>20&&gentri_GoodWMatch"));
456     GenSFOFCalculator("Outside |m_{23}-Z|<20, Wrong W", genBase&&TCut("abs(gentri_submll-91)>20&&!gentri_GoodWMatch"));
457     GenSFOFCalculator("Outside |m_{23}-Z|<20, Correct Z, correct W", genBase&&TCut("abs(gentri_submll-91)>20&&gentri_GoodZMatch&&gentri_GoodWMatch"));
458     GenSFOFCalculator("Outside |m_{23}-Z|<20, Wrong Z or W", genBase&&TCut("abs(gentri_submll-91)>20&&!(gentri_GoodZMatch&&gentri_GoodWMatch)"));
459     GenSFOFCalculator("Full selection, Correct Z and W", genBase&&Selection&&TCut("abs(gentri_submll-91)>20&&(gentri_GoodZMatch&&gentri_GoodWMatch)"));
460     GenSFOFCalculator("Full selection, Wrong Z or W", genBase&&Selection&&TCut("abs(gentri_submll-91)>20&&!(gentri_GoodZMatch&&gentri_GoodWMatch)"));
461     // GenSFOFCalculator("Full selection", genBase&&Selection);
462     // GenSFOFCalculator("Full selection with genParticles", genBase&&genParticleSelection&&TCut("abs(gentri_submll-91)>20"));
463    
464    
465     }
466    
467    
468     void AlgorithmTest(TCut BasicCut, TCut Selection) {
469     TCut Pure("tri_GoodWMatch && tri_GoodZMatch");
470    
471     int nbins=38;
472     float mll_low=10;
473     float mll_hi=200;
474    
475     TCanvas *can = new TCanvas("can","can");
476     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"));
477     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"));
478    
479     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"));
480     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"));
481    
482     delete can;
483    
484 buchmann 1.6 dout << "SF WZ events: " << sfwz->Integral() << " (correctly combined WZ: " << sfwzpure->Integral() << ")" << endl;
485     dout << "OF WZ events: " << ofwz->Integral() << " (correctly combined WZ: " << ofwzpure->Integral() << ")" << endl;
486 buchmann 1.4
487     dout << "RATIO : SF / OF = " << sfwz->Integral() / ofwz->Integral() << " +/- " << sfwz->Integral()/ofwz->Integral() * sqrt(1/sfwz->GetEntries() + 1/ofwz->GetEntries()) << endl;
488     dout << " PURE: SF / OF = " << sfwzpure->Integral() / ofwzpure->Integral() << " +/- " << sfwzpure->Integral()/ofwzpure->Integral() * sqrt(1/sfwzpure->GetEntries() + 1/ofwzpure->GetEntries()) << endl;
489     dout << "PURITY: " << endl;
490     dout << " SF : " << 100.0*sfwzpure->Integral()/sfwz->Integral() << " +/- " << 100.0*sfwzpure->Integral()/sfwz->Integral() * sqrt(1/sfwzpure->GetEntries() + 1/sfwz->GetEntries()) <<endl;
491     dout << " OF : " << 100.0*ofwzpure->Integral()/ofwz->Integral() << " +/- " << 100.0*ofwzpure->Integral()/ofwz->Integral() * sqrt(1/ofwzpure->GetEntries() + 1/ofwz->GetEntries()) <<endl;
492    
493    
494     delete sfwz;
495     delete ofwz;
496     delete sfwzpure;
497     delete ofwzpure;
498     }
499    
500     void GetResult(TCut BasicCut, TCut Selection) {
501     if(TriLeptons::Rsfof_CorrectionFactor<0 || TriLeptons::Rsfof_CorrectionFactor_Error<0) SF_OF_comparison(BasicCut,Selection);
502     int nbins=38;
503     float mll_low=10;
504     float mll_hi=200;
505    
506     TCanvas *can = new TCanvas("can","can");
507     TH1F *sfwz = allsamples.Draw("sfwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepSF,data,luminosity);
508     TH1F *ofwz = allsamples.Draw("ofwz" ,"tri_submll",nbins,mll_low,mll_hi,"m_{l_{2}l_{3}} [GeV]", "events", BasicCut&&Selection&&TriLepOF,data,luminosity);
509    
510     delete can;
511    
512     dout << " ****** FINAL RESULT ****** " << endl;
513     dout << "SF events: " << sfwz->Integral() << " +/- " << sqrt(sfwz->Integral()) << endl;
514     dout << "OF events: " << ofwz->Integral() << " +/- " << sqrt(ofwz->Integral()) << endl;
515    
516 buchmann 1.6 dout << "Correction factor : " << TriLeptons::Rsfof_CorrectionFactor << " +/- " << TriLeptons::Rsfof_CorrectionFactor_Error << endl;
517    
518 buchmann 1.4 float rawstatuncert=sfwz->Integral()/ofwz->Integral() * sqrt(1/sfwz->GetEntries() + 1/ofwz->GetEntries());
519     float rawresult=sfwz->Integral() / ofwz->Integral();
520     dout << "UNCORRECTED RATIO : SF / OF = " << rawresult << " +/- " << rawstatuncert << endl;
521     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));
522    
523    
524     delete sfwz;
525     delete ofwz;
526     // delete can;
527     }
528    
529    
530     void PredictionFailurePlot(string truthvariable, string predictionvariable, int nbins, float min, float max, TCut PredictionCut, TCut TruthCut, string saveas, string xlabel) {
531     TLegend *leg = make_legend();
532     leg->SetY1(0.7);
533     TCanvas *can = new TCanvas("can","can");
534     TPad *pad = new TPad("pad","pad",0,0,1,1);
535     pad->cd();
536     // pad->SetLogy(1);
537    
538     TH1F *Prediction = allsamples.Draw("Prediction",predictionvariable,nbins,min,max,xlabel,"events",PredictionCut,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
539     TH1F *MCTruth = allsamples.Draw("MCTruth", truthvariable, nbins,min,max,xlabel,"events",TruthCut ,mc,luminosity,allsamples.FindSample("WZJetsTo3"));
540    
541     Prediction->SetLineColor(TColor::GetColor("#FF0000"));//an evil red
542     MCTruth->SetLineColor(TColor::GetColor("#04B404")); // a nice green
543    
544     // if(Prediction->GetMaximum()>MCTruth->GetMaximum()) MCTruth->SetMaximum(1.3*Prediction->GetMaximum());
545    
546     if(MCTruth->GetMaximum()>Prediction->GetMaximum()) {
547     MCTruth->SetMaximum(MCTruth->GetMaximum()*1.2);
548     MCTruth->DrawNormalized("histo");
549     Prediction->DrawNormalized("histo,same");
550     } else {
551     Prediction->SetMaximum(Prediction->GetMaximum()*1.2);
552     Prediction->DrawNormalized("histo");
553     MCTruth->DrawNormalized("histo,same");
554     }
555    
556    
557     leg->AddEntry(Prediction,"prediction (norm.)","l");
558     leg->AddEntry(MCTruth,"MC truth (norm.)","l");
559     leg->Draw();
560     DrawMCPrelim();
561 buchmann 1.8 Save_With_Ratio(MCTruth,Prediction,pad->cd(),"WZ_study/PredictionMethodFailure/"+saveas);
562 buchmann 1.4
563     delete Prediction;
564     delete MCTruth;
565     delete can;
566    
567    
568    
569     }
570    
571     void WhyDoesThePredictionMethodFail(TCut PredictionCut, TCut TruthCut) {
572     PredictionFailurePlot("tri_submll","tri_badsubmll",50,0,200,PredictionCut,TruthCut,"SubMll","m_{23}");
573     PredictionFailurePlot("tri_mT","tri_badmT",50,0,200,PredictionCut,TruthCut,"MT","m_{T}");
574     PredictionFailurePlot("tri_mll","tri_badmll",25,0,200,PredictionCut,TruthCut,"Mll","m_{12}");
575     }
576    
577    
578     void ComputeNewMiscombinationRate(TCut origSelection, TCut sBasicCut) {
579     TCanvas *can = new TCanvas("can","can");
580    
581     string sSelection= (const char*)origSelection;
582     sSelection= ReplaceAll(sSelection,"tri_","tri_bad");
583     sSelection= ReplaceAll(sSelection,"tri_badmlll","tri_mlll");
584     cout << "modified " << (const char*)origSelection << " to " << sSelection << endl;
585    
586     TCut FlavorBlindSelection((sSelection+(string)"&&(abs(tri_id2)!=abs(tri_id3))").c_str()); // making sure we select OF events
587     TCut CorrectSelection (origSelection && TCut("(abs(tri_id2)!=abs(tri_id3))")); // making sure we select OF events
588     TCut OFZ ("tri_mll!=tri_badmll");
589    
590     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"));
591     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"));
592    
593 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);
594     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);
595    
596 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;
597     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;
598 buchmann 1.4
599     delete WZ_OF_any;
600     delete WZ_OF_OFZ;
601     delete can;
602     }
603    
604     void ComputeMiscombinationRate(TCut origSelection, TCut sBasicCut) {
605     /* TCanvas *can = new TCanvas("can","can");
606     //idea: use the flavor-blind version of the algorithm to obtain the yields in our signal region.
607     string sSelection= (const char*)origSelection;
608     sSelection= ReplaceAll(sSelection,"tri_","tri_bad");
609     sSelection= ReplaceAll(sSelection,"tri_badmlll","tri_mlll");
610     cout << "modified " << (const char*)origSelection << " to " << sSelection << endl;
611    
612     TCut BadSelection((sSelection+(string)"&&abs(tri_id2)!=abs(tri_id3)").c_str()); // making sure we select OF events
613     TCut GoodSelection(origSelection && TCut("abs(tri_id2)!=abs(tri_id3)")); // making sure we select OF events
614    
615     TCut BasicCut(sBasicCut&&TCut("tri_id2!=tri_id3"));
616    
617     TCut TruthBad("!(tri_GoodZMatch&&tri_GoodZMatch)");
618     TCut MethodBad("!(tri_id2==tri_badid2&&tri_id3==tri_badid3)");
619    
620     for(int icut=0;icut<2;icut++) {
621     TCut Goodused;
622     TCut Badused;
623     if(icut==0) {
624     Goodused=BasicCut;
625     Badused =BasicCut;
626     cout << "Preselection only: " << endl;
627     cout << " used : " << (const char*) Goodused << endl;
628     } else {
629     Goodused=BasicCut&&GoodSelection;
630     Badused =BasicCut&&BadSelection;
631     cout << "Full selection: " << endl;
632     cout << " Good used : " << (const char*) Goodused << endl;
633     cout << " Bad used : " << (const char*) Goodused << endl;
634     }
635    
636     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"));
637     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"));
638    
639     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"));
640     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"));
641     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"));
642     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"));
643    
644     cout << " ********** WZ **********" << endl;
645     cout << " N events : " << Events_WZ->Integral() << "\t (mc events: " << Events_WZ->GetEntries() << ")" << endl;
646     cout << " Bad combinations: " << bad_WZ->Integral() << "\t (mc events: " << bad_WZ->GetEntries() << ")" << endl;
647     cout << " Predicted bad com.: " << MethodBad_WZ->Integral() << " / " << MethodBad_WZg->Integral() << "\t (mc events: " << MethodBad_WZ->GetEntries() << ")" << endl;
648    
649    
650     delete Events_WZ;
651     delete bad_WZ;
652     delete MethodBad_WZ;
653     delete MethodBad_WZg;
654     }
655     delete can;
656    
657     WhyDoesThePredictionMethodFail(BasicCut&&MethodBad,BasicCut&&TruthBad);
658     */
659     }
660    
661    
662    
663    
664 buchmann 1.3 void CarryOutWZStudy() {
665 buchmann 1.9 TCut BasicCut("tri_MatchFound&&leptonNum>2&&tri_pt1>30&&tri_pt2>20&&tri_pt3>20");
666     TCut Selection("abs(tri_mlll-91)>30 && tri_mT>50 && met[4] > 30 && abs(tri_mll-91)<10 && tri_submll > 10 && abs(tri_submll-91)>5");
667 buchmann 1.7
668 buchmann 1.4 //OptimizeSelection(BasicCut);
669    
670     //ComputeMiscombinationRate(Selection, BasicCut);
671    
672 buchmann 1.8 // ComputeNewMiscombinationRate(Selection, BasicCut);
673 buchmann 1.9
674 buchmann 1.3 WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut,"Inclusive/Zmass");
675     WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut,"Inclusive/TrileptonMass");
676     WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut,"Inclusive/mT");
677     WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut,"Inclusive/MET");
678     WZ_kin_plot("tri_pt1",40,0,400,"p_{T}^{1} [GeV]",BasicCut,"Inclusive/Pt1");
679     WZ_kin_plot("tri_pt2",40,0,400,"p_{T}^{2} [GeV]",BasicCut,"Inclusive/Pt2");
680     WZ_kin_plot("tri_pt3",40,0,400,"p_{T}^{3} [GeV]",BasicCut,"Inclusive/Pt3");
681 buchmann 1.9 /*
682 buchmann 1.3 WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/Zmass");
683     WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/TrileptonMass");
684     WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/mT");
685     WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&TCut("abs(tri_mlll-91)>30"),"Mlll_cut/MET");
686    
687     WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/Zmass");
688     WZ_kin_plot("tri_mlll",40,0,400,"m_{ll} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/TrileptonMass");
689     WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/mT");
690     WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&TCut("abs(tri_mll-91)<10"),"Zwindow/MET");
691    
692     WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut,"CutFlow/Zmass__0_CutOnNothing");
693     WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/Zmass__1_CutOn_MT");
694     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");
695     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");
696     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");
697    
698     WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut,"CutFlow/MT__0_CutOnNothing");
699     WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/MT__1_CutOn_MT");
700     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");
701     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");
702     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");
703    
704     WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut,"CutFlow/MET__0_CutOnNothing");
705     WZ_kin_plot("met[4]",40,0,200,"MET [GeV]",BasicCut&&TCut("tri_mT>40"),"CutFlow/MET__1_CutOn_MT");
706     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");
707     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");
708     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");
709    
710 buchmann 1.9 */
711 buchmann 1.3 WZ_kin_plot("tri_mll",40,0,200,"m_{Z} [GeV]",BasicCut&&Selection,"Zmass");
712     WZ_kin_plot("tri_mlll",40,0,400,"m_{lll} [GeV]",BasicCut&&Selection,"TrileptonMass");
713     WZ_kin_plot("tri_mT",40,0,200,"m_{T} [GeV]",BasicCut&&Selection,"mT");
714     WZ_kin_plot("met[4]", 40,0,400,"raw PFMET [GeV]",BasicCut&&Selection,"MET");
715     WZ_kin_plot("tri_pt1",40,0,400,"p_{T}^{1} [GeV]",BasicCut&&Selection,"Pt1");
716     WZ_kin_plot("tri_pt2",40,0,400,"p_{T}^{2} [GeV]",BasicCut&&Selection,"Pt2");
717     WZ_kin_plot("tri_pt3",40,0,400,"p_{T}^{3} [GeV]",BasicCut&&Selection,"Pt3");
718 buchmann 1.4
719 buchmann 1.9
720 buchmann 1.4 WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepSF,"mllsub_SF");
721 buchmann 1.9 WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepOF,"mllsub_OF");
722 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");
723     WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepSF&&TCut("tri_id2==1"),"mllsub_SF_mm");
724     WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepOF&&TCut("tri_id2==0"),"mllsub_OF_em");
725     WZ_kin_plot("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection&&TriLepOF&&TCut("tri_id2==1"),"mllsub_OF_me");
726 buchmann 1.9
727 buchmann 1.4
728     SF_OF_comparison(BasicCut,Selection);
729     // generator_SF_OF_comparison();
730     // reco_SF_OF_comparison(BasicCut,Selection);
731    
732     SF_vs_OF_plots("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection,TriLepSF,TriLepOF,mc,"mllsub_MC");
733     SF_vs_OF_plots("tri_submll",40,0,200,"m_{l_{2}l_{3}} [GeV]",BasicCut&&Selection,TriLepSF,TriLepOF,data,"mllsub_data");
734     AlgorithmTest(BasicCut,Selection);
735     GetResult(BasicCut,Selection);
736    
737    
738     }
739    
740     void Make_Chi2_Resolution_Minimization(TGraph *gr) {
741     TCanvas *can2 = new TCanvas("can2","can2");
742     can2->cd();
743     gStyle->SetOptFit(0);
744     gr->Draw("AP*");
745     gr->GetXaxis()->SetTitle("MET scale factor");
746     gr->GetYaxis()->SetTitle("#chi^{2}");
747     gr->GetXaxis()->CenterTitle();
748     gr->GetYaxis()->CenterTitle();
749     gr->Draw("AP*");
750     gr->Fit("pol3");
751     TF1 *fit = (TF1*)gr->GetFunction("pol3");
752     fit->SetLineWidth(2);
753     fit->SetLineColor(kBlue);
754     gr->Draw("AP*");
755     DrawPrelim();
756     CompleteSave(can2,"WZ_study/DYResolution/Result_Chi2");
757     delete can2;
758     }
759 buchmann 1.3
760 buchmann 1.4 void ExtractDYMissingResolution() {
761 buchmann 1.3
762 buchmann 1.4 TCanvas *can = new TCanvas("can","can");
763    
764     TH1F *histoSF = allsamples.Draw("histoSF","met[4]",50,0,100,"MET [GeV]","events",TCut("id1==id2&&mll>0&&pfJetGoodNum40>=2"),data,luminosity);
765     TH1F *histoOF = allsamples.Draw("histoOF","met[4]",50,0,100,"MET [GeV]","events",TCut("id1!=id2&&mll>0&&pfJetGoodNum40>=2"),data,luminosity);
766     THStack histoMC = allsamples.DrawStack("histoMC","met[4]",50,0,100,"MET [GeV]","events",TCut("id1==id2&&mll>0&&pfJetGoodNum40>=2"),mc,luminosity);
767     TFile *f = new TFile("file.root","RECREATE");
768 buchmann 1.3
769 buchmann 1.4 TH1F *MC_wo_DY = CollapseStack(histoMC);
770     TIter nextSF = TIter(histoMC.GetHists());
771     TH1F *h;
772     while ( h = (TH1F*)nextSF() ) {
773     if(Contains(h->GetName(),"Z_Jets")) {
774     MC_wo_DY->Add(h,-1);
775     }
776     }
777     MC_wo_DY->Write();
778    
779    
780     int ntests=150;
781     TH1F *DYres[ntests];
782    
783     float min_chi2=-1;
784     int best_index=-1;
785     stringstream allresults;
786     TGraph *gr = new TGraph();
787     for(int i=0;i<ntests;i++) {
788    
789     float smearby=0.15*i/((float)ntests);
790    
791     stringstream drawvariable;
792     drawvariable << "((" << 1+smearby << ")*met[4])";
793     cout << "Going to use the variable " << drawvariable.str() << endl;
794     stringstream name;
795     name << "histo_DY_" << i;
796     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"));
797     DYres[i]->Write();
798    
799     TPad *pad = new TPad("pad","pad",0,0,1,1);
800     pad->cd();
801    
802     DrawPrelim();
803     MC_wo_DY->SetFillColor(kWhite);
804     MC_wo_DY->SetLineColor(kBlue);
805     TLegend *leg = make_legend();
806     leg->SetY1(0.8);
807     leg->AddEntry(histoSF,"data","pl");
808     leg->AddEntry(MC_wo_DY,"MC","l");
809    
810     TH1F *sum = (TH1F*)MC_wo_DY->Clone("sum");
811     sum->Add(DYres[i]);
812     sum->Draw("histo");
813     histoSF->Draw("e1,same");
814     stringstream Result;
815    
816     Double_t chi2;
817     Int_t ndf,igood;
818     Double_t res=0.0;
819     Double_t chi2prob = MarcosChi2TestX(histoSF,sum,chi2,ndf,igood,"UW");
820     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 << "}}";
821    
822     allresults << "\n" << smearby << ";" << chi2;
823     gr->SetPoint(i,smearby,chi2);
824    
825     if(min_chi2<0||chi2<min_chi2) {
826     min_chi2=chi2;
827     best_index=i;
828     }
829    
830     TPaveText *PurityPaveText = new TPaveText(0.60, 0.40,0.89, 0.6,"blNDC");
831     PurityPaveText->SetFillStyle(4000);
832     PurityPaveText->SetBorderSize(0);
833     PurityPaveText->SetFillColor(kWhite);
834     PurityPaveText->SetTextFont(42);
835     PurityPaveText->SetTextSize(0.042);
836     PurityPaveText->AddText(Result.str().c_str());
837     PurityPaveText->Draw();
838     DrawPrelim();
839     leg->Draw();
840    
841    
842     stringstream savethis;
843     savethis << "WZ_study/DYResolution/Response" << 100*smearby << "Percent";
844    
845 buchmann 1.8 Save_With_Ratio(histoSF,sum,pad->cd(),savethis.str());
846 buchmann 1.4 }
847    
848     gr->SetTitle("Chi2Diagram");
849     gr->SetName("Chi2Diagram");
850    
851    
852     dout << "Result summary: " << endl;
853     dout << allresults.str() << endl;
854 buchmann 1.3
855 buchmann 1.4 nextSF = TIter(histoMC.GetHists());
856     THStack stack;
857     while ( h = (TH1F*)nextSF() ) {
858     if(!Contains(h->GetName(),"Z_Jets")) {
859     stack.Add(h);
860     }
861     }
862 buchmann 1.3
863    
864 buchmann 1.4 TPad *pad = new TPad("pad","pad",0,0,1,1);
865     pad->cd();
866    
867     DYres[best_index]->SetFillColor(kYellow);
868     DYres[best_index]->SetLineColor(kYellow);
869 buchmann 1.1
870 buchmann 1.4 stack.Add(DYres[best_index]);
871     stack.Draw();
872     histoSF->Draw("e1,same");
873     DrawPrelim();
874 buchmann 1.8 Save_With_Ratio(histoSF,CollapseStack(stack),pad->cd(),"WZ_study/DYResolution/Result");
875 buchmann 1.1
876 buchmann 1.4 TFile *fr = new TFile("rumba.root","RECREATE");
877     gr->Write();
878     fr->Close();
879 buchmann 1.1
880 buchmann 1.4 delete can;
881 buchmann 1.1
882 buchmann 1.4 Make_Chi2_Resolution_Minimization(gr);
883    
884 buchmann 1.1 }
885    
886     void WZstudy() {
887 buchmann 1.4 // ExtractDYMissingResolution();
888 buchmann 1.1
889 buchmann 1.6 cutWeight=TCut("(weight*(weight<1000)*(is_data+(!is_data)))");
890 buchmann 1.1 switch_overunderflow(true);
891     cout << "Essential cut is " << (const char*) essentialcut << endl;
892     cout << "Going to set essential cut to new triggers" << endl;
893     TCut essential_bkp = essentialcut;
894 buchmann 1.3 essentialcut=TCut("mll>5||mll<6");
895 buchmann 1.1 cout << "Essential cut is now " << (const char*) essentialcut << endl;
896    
897     CarryOutWZStudy();
898    
899    
900     cout << "Essential cut is now " << (const char*) essentialcut << endl;
901     essentialcut = essential_bkp;
902     cout << "Essential cut is now " << (const char*) essentialcut << " (restored)" << endl;
903     switch_overunderflow(false);
904 buchmann 1.4
905 buchmann 1.1 }
906 buchmann 1.3