ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/WZStudy.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/WZStudy.C (file contents):
Revision 1.1 by buchmann, Thu Oct 11 09:11:50 2012 UTC vs.
Revision 1.5 by buchmann, Wed Nov 28 17:51:30 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines