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.5 by buchmann, Wed Nov 28 17:51:30 2012 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");
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 88 | Line 96 | void WZ_kin_plot(string variable, int nb
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;
# Line 109 | Line 148 | void write_report(TCut BasicCut, TCut cu
148  
149   }
150  
151 < vector<string> producecuts(string variablename, float cut1, float cut2, float cut3, float cut4, float cut5, float cut6 ) {
152 <  float allcuts[6] = {cut1,cut2,cut3,cut4,cut5,cut5};
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 < 6; ++i ) {
154 >  for(int i = 0; i < 11; ++i ) {
155      if(allcuts[i]<0) continue;
156      stringstream nowcut;
157      nowcut << variablename << allcuts[i];
# Line 126 | Line 165 | void OptimizeSelection(TCut BasicCut) {
165    ofstream report;
166    report.open ("report3.txt");
167    
168 <  vector<string> mt   = producecuts("tri_mT>",0,10,20,30,40,50);
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,10,20,-1,-1,-1);
171 <  vector<string> mlll = producecuts("abs(tri_mlll-91)>",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++) {
# Line 147 | Line 186 | void OptimizeSelection(TCut BasicCut) {
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 +  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 +  // 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 +  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 + 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 +  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();
326 +  
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");
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    
154 //  OptimizeSelection(BasicCut);
155  /*
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");
# Line 197 | Line 694 | void CarryOutWZStudy() {
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 <  
697 >  
698  
699 <  TCut SF("tri_id1==tri_id2");
700 <  TCut OF("tri_id1!=tri_id2");
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 <  TH1F *sfdata = allsamples.Draw("sfdata","tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&SF,data, luminosity);
717 <  TH1F *ofdata = allsamples.Draw("ofdata","tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&OF,data, luminosity);
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 <  // all MC samples
209 <  TH1F *sfmc   = allsamples.Draw("sfmc"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&SF,mc  , luminosity);
210 <  TH1F *ofmc   = allsamples.Draw("ofmc"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&OF,mc  , luminosity);
741 >  TCanvas *can = new TCanvas("can","can");
742    
743 <  // WZ only
744 <  TH1F *sfwz   = allsamples.Draw("sfwz"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&SF,mc  , luminosity,allsamples.FindSample("WZJetsTo3"));
745 <  TH1F *ofwz   = allsamples.Draw("ofwz"  ,"tri_mll",30,75,105,"m_{Z} [GeV]", "events", BasicCut&&Selection&&OF,mc  , luminosity,allsamples.FindSample("WZJetsTo3"));
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 <  dout << "SF events: " << sfdata->Integral() << "   (mc : " << sfmc->Integral() << " , wz : " << sfwz->Integral() << " )   WZ purity: " << 100*sfwz->Integral()/sfmc->Integral() << " %" << endl;
749 <  dout << "OF events: " << ofdata->Integral() << "   (mc : " << ofmc->Integral() << " , wz : " << ofwz->Integral() << " )   WZ purity: " << 100*ofwz->Integral()/ofmc->Integral() << " %" << endl;
748 >  TH1F *MC_wo_DY = CollapseStack(histoMC);
749 >  TIter nextSF = TIter(histoMC.GetHists());
750 >  TH1F *h;
751 >  while ( h = (TH1F*)nextSF() ) {
752 >    if(Contains(h->GetName(),"Z_Jets")) {
753 >      MC_wo_DY->Add(h,-1);
754 >    }
755 >  }
756 >  MC_wo_DY->Write();
757 >    
758    
759 <  dout << "RATIO : SF / OF = " << sfdata->Integral() / ofdata->Integral() << " +/- " << (sfdata->Integral()/ofdata->Integral()) * TMath::Sqrt(1/sfdata->Integral()+1/ofdata->Integral()) << " (stat) " << endl;
760 <  */
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 +  
830 +  
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 +    if(!Contains(h->GetName(),"Z_Jets")) {
838 +      stack.Add(h);
839 +    }
840 +  }
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 +  stack.Add(DYres[best_index]);
850 +  stack.Draw();
851 +  histoSF->Draw("e1,same");
852 +  DrawPrelim();
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    
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;
# Line 241 | 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