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.3 by buchmann, Fri Oct 12 15:45:14 2012 UTC vs.
Revision 1.8 by buchmann, Thu Jan 24 08:18:18 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines