ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.7
Committed: Thu Aug 23 16:31:31 2012 UTC (12 years, 8 months ago) by fronga
Content type: text/plain
Branch: MAIN
Changes since 1.6: +162 -58 lines
Log Message:
Significantly pimped up the MET plots.
Now includes data/MC comparison (TODO: ratio plots!?).
Also includes MET150 region.

Marco-Andrea: please check for memory abuse ;)

File Contents

# User Rev Content
1 buchmann 1.1 #include <iostream>
2    
3     using namespace std;
4    
5     TGraphErrors* MakeErrorGraph(TH1F *histo) {
6    
7     float dx[histo->GetNbinsX()];
8     float dy[histo->GetNbinsX()];
9     float x[histo->GetNbinsX()];
10     float y[histo->GetNbinsX()];
11     for(int i=1;i<=histo->GetNbinsX();i++) {
12     x[i-1]=histo->GetBinCenter(i);
13     y[i-1]=histo->GetBinContent(i);
14     if(i>1) dx[i-1]=(histo->GetBinCenter(i)-histo->GetBinCenter(i-1))/2.0;
15     else dx[i-1]=(histo->GetBinCenter(i+1)-histo->GetBinCenter(i))/2.0;
16     dy[i-1]=histo->GetBinError(i);
17     }
18    
19     TGraphErrors *gr = new TGraphErrors(histo->GetNbinsX(),x,y,dx,dy);
20     gr->SetFillColor(TColor::GetColor("#2E9AFE"));
21     return gr;
22     }
23    
24 fronga 1.7 void ProduceMetPlotsWithCut(TCut cut, string name, float cutat, int njets, bool doMC = false ) {
25 buchmann 1.1 TCanvas *tcan = new TCanvas("tcan","tcan");
26     cout << "Doing met plots" << endl;
27 buchmann 1.2 stringstream MetBaseCuts;
28 fronga 1.7 MetBaseCuts << "met[4]>" << cutat << "&&" << cut.GetTitle();
29     stringstream snjets;
30     snjets << njets;
31 buchmann 1.2 TCut MetBaseCut(MetBaseCuts.str().c_str());
32 fronga 1.7 TCut nJetsSignal(("pfJetGoodNum40>="+snjets.str()).c_str());
33     TCut nJetsControl(("pfJetGoodNum40<"+snjets.str()).c_str());
34 buchmann 1.1
35     //compute SF / OF rate in (CR1+CR2), should give 0.941 +/- 0.05
36 fronga 1.7
37     // Create histograms
38     //int nbins = 30;
39     int nbins = 60;
40     float xmin=20., xmax = 320.;
41     TH1F *mllsig = allsamples.Draw("mllsig", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal),data,PlottingSetup::luminosity);
42     TH1F *mllscon = allsamples.Draw("mllscon", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsControl),data,PlottingSetup::luminosity);
43     TH1F *mllOsig = allsamples.Draw("mllOsig", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsSignal),data,PlottingSetup::luminosity);
44     TH1F *mllOscon = allsamples.Draw("mllOscon","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsControl),data,PlottingSetup::luminosity);
45    
46     THStack* mcMllsig;
47     THStack* mcMllscon, *mcMllOsig, *mcMllOscon;
48     if ( doMC ) {
49     name += "_mc";
50     mcMllsig = new THStack(allsamples.DrawStack("mcMllsig", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsSignal),mc,PlottingSetup::luminosity));
51     mcMllscon = new THStack(allsamples.DrawStack("mcMllscon", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSSF&&MetBaseCut&&nJetsControl),mc,PlottingSetup::luminosity));
52     mcMllOsig = new THStack(allsamples.DrawStack("mcMllOsig", "mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsSignal),mc,PlottingSetup::luminosity));
53     mcMllOscon= new THStack(allsamples.DrawStack("mcMllOscon","mll",nbins,xmin,xmax,"m_{ll} [GeV]","events",TCut(cutOSOF&&MetBaseCut&&nJetsControl),mc,PlottingSetup::luminosity));
54     }
55 buchmann 1.1
56     mllOsig->SetLineColor(kRed);
57     mllOscon->SetLineColor(kRed);
58    
59 fronga 1.7 TH1F *zlineshape = allsamples.Draw("zlineshape","mll",nbins,xmin,xmax,"m_{ll} (GeV)","events",cutOSSF&&TCut("pfJetGoodNum40==1")&&cut,data,PlottingSetup::luminosity);
60 fronga 1.4 //float scalefactor=(mllsig->GetBinContent(mllsig->GetMaximumBin()-1)+mllsig->GetBinContent(mllsig->GetMaximumBin())+mllsig->GetBinContent(mllsig->GetMaximumBin()+1)-mllOsig->GetBinContent(mllsig->GetMaximumBin()-1)-mllOsig->GetBinContent(mllsig->GetMaximumBin())-mllOsig->GetBinContent(mllsig->GetMaximumBin())+1);
61     //scalefactor/=(zlineshape->GetBinContent(zlineshape->GetMaximumBin()-1)+zlineshape->GetBinContent(zlineshape->GetMaximumBin())+zlineshape->GetBinContent(zlineshape->GetMaximumBin()+1));
62     // Alternative scale factor: use 90+-5 GeV
63 buchmann 1.6 Int_t scaleBinLow = mllsig->FindBin(86);
64     Int_t scaleBinHigh = mllsig->FindBin(94);
65 fronga 1.4 float scalefactor = (mllsig->Integral(scaleBinLow,scaleBinHigh)-mllOsig->Integral(scaleBinLow,scaleBinHigh));
66     scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
67 buchmann 1.6
68     cout << "Bins for scaling : " << scaleBinLow << " : " << scaleBinHigh << endl;
69    
70 buchmann 1.3 zlineshape->Scale(scalefactor);
71     zlineshape->SetLineColor(kBlue);
72     zlineshape->SetLineStyle(2);
73    
74     TH1F *subtracted = (TH1F*)mllsig->Clone("subtracted");
75     TH1F *baseline = (TH1F*)mllOsig->Clone("baseline");
76     for(int i=1;i<=subtracted->GetNbinsX();i++) {
77     subtracted->SetBinContent(i,mllsig->GetBinContent(i)-mllOsig->GetBinContent(i));
78     baseline->SetBinContent(i,0);
79     }
80    
81     TH1F *prediction = (TH1F*)mllOsig->Clone("prediction");
82     prediction->Add(zlineshape);
83     prediction->SetLineColor(TColor::GetColor("#CF35CA"));
84 fronga 1.7
85     TH1F *control_prediction = (TH1F*)mllOscon->Clone("control_prediction");
86     control_prediction->SetLineColor(TColor::GetColor("#CF35CA"));
87    
88     // FIX Y RANGE TO EASE COMPARISON
89     mllsig->SetMaximum(120);
90     mllOsig->SetMaximum(120);
91     mllOscon->SetMaximum(280);
92     subtracted->SetMaximum(50);
93     subtracted->SetMinimum(-30);
94    
95 buchmann 1.3
96 fronga 1.7 // 1.- Signal region comparison
97     TGraphErrors *stat3j;
98     ////mllsig->GetYaxis()->SetRangeUser(0,mllsig->GetMaximum()*1.2);
99 buchmann 1.1 mllsig->Draw();
100 fronga 1.7 // Do not draw errors on prediction when overlaying MC.
101     if ( doMC ) {
102     mcMllsig->Draw("same");
103     } else {
104     stat3j = MakeErrorGraph(prediction);
105     stat3j->Draw("2,same");
106     mllOsig->Draw("histo,same");
107     zlineshape->Draw("histo,same");
108     }
109 buchmann 1.3 prediction->Draw("histo,same");
110 buchmann 1.1 mllsig->Draw("same");
111     DrawPrelim();
112    
113     TBox *srbox = new TBox(20,0,70,mllsig->GetMaximum());
114     srbox->SetFillStyle(0);
115     srbox->SetLineColor(TColor::GetColor("#298A08"));
116     srbox->SetLineWidth(3);
117    
118 fronga 1.7 TLegend *leg;
119     if ( doMC ) {
120     leg = allsamples.allbglegend();
121     } else {
122     leg = make_legend();
123     }
124 buchmann 1.1 leg->SetX1(0.54);
125 buchmann 1.2 stringstream MetHeader;
126     MetHeader << "MET>" << cutat << " GeV";
127 fronga 1.7 leg->SetHeader(((string)"N_{jets}#geq"+snjets.str()+", "+MetHeader.str()).c_str());
128     if (!doMC) leg->AddEntry(mllsig,"Data","PL");
129     leg->AddEntry(prediction,"All bg prediction","L");
130     if (!doMC) {
131     leg->AddEntry(mllOsig,"bg without Z","L");
132     leg->AddEntry(zlineshape,"Z lineshape","L");
133     leg->AddEntry(stat3j,"stat. uncert.","F");
134     }
135 buchmann 1.1 leg->AddEntry(srbox,"SR","F");
136     leg->Draw();
137    
138     srbox->Draw();
139    
140     stringstream saveasSig;
141 buchmann 1.3 saveasSig << "MetPlots/mll_sig" << cutat << "__" << name;
142 buchmann 1.1 CompleteSave(tcan,saveasSig.str());
143    
144 fronga 1.7 // 2.- Signal region comparison - LOG scale
145     mllsig->SetMinimum(0.2); // FIX Y RANGE TO EASE COMPARISON
146     //mllsig->SetMaximum(mllsig->GetMaximum()*4.0);
147 fronga 1.4 srbox->SetY2(mllsig->GetMaximum());
148 buchmann 1.6
149 buchmann 1.1 tcan->SetLogy(1);
150     stringstream saveasSig2;
151 buchmann 1.3 saveasSig2 << "MetPlots/mll_sig_ZLINESHAPE_" << cutat << "__" << name;
152    
153 buchmann 1.1 CompleteSave(tcan,saveasSig2.str());
154     tcan->SetLogy(0);
155    
156 fronga 1.7
157     // 3.- Signal region, background subtracted
158 buchmann 1.3 for(int i=1;i<subtracted->GetNbinsX();i++) {
159     subtracted->SetBinContent(i,subtracted->GetBinContent(i)-zlineshape->GetBinContent(i));
160     }
161    
162     TGraphErrors *subtrerr = MakeErrorGraph(baseline);
163     subtracted->Draw();
164     subtrerr->Draw("2,same");
165     subtracted->Draw("same");
166     DrawPrelim();
167     TLegend *DiffLeg = make_legend();
168 fronga 1.5 DiffLeg->SetX1(0.3);
169 fronga 1.7 DiffLeg->SetFillStyle(0);
170 buchmann 1.3 DiffLeg->AddEntry(subtracted,"observed - predicted","PL");
171     DiffLeg->AddEntry(subtrerr,"stat. uncert on prediction","F");
172 fronga 1.7 DiffLeg->AddEntry((TObject*)0,"","");
173     DiffLeg->AddEntry((TObject*)0,"","");
174 buchmann 1.3 DiffLeg->Draw();
175    
176     stringstream saveasSigSub;
177     saveasSigSub << "MetPlots/mll_sig_SUBTRACTED_" << cutat << "__" << name;
178    
179     CompleteSave(tcan,saveasSigSub.str());
180 fronga 1.5
181 fronga 1.7 // 4.- Signal region, background subtracted, errors added in quadrature
182 fronga 1.5 TGraphErrors *subtrerr2 = (TGraphErrors*)subtrerr->Clone("subtrerr2");
183     for(int i=0;i<subtrerr2->GetN();i++) {
184     subtrerr2->SetPoint(i,subtracted->GetBinCenter(i),subtracted->GetBinContent(i));
185     subtrerr2->SetPointError(i,subtrerr2->GetErrorX(i),TMath::Sqrt(subtrerr2->GetErrorY(i)*subtrerr2->GetErrorY(i)+subtracted->GetBinError(i)*subtracted->GetBinError(i)));
186     }
187     TLine* l = new TLine(subtracted->GetBinLowEdge(1),0.,subtracted->GetBinLowEdge(subtracted->GetNbinsX()-1)+subtracted->GetBinWidth(1),0.);
188     l->SetLineWidth(subtracted->GetLineWidth());
189     subtracted->Draw();
190     subtrerr2->Draw("2,same");
191     l->Draw("same");
192     subtracted->Draw("same");
193     DrawPrelim();
194     TLegend *DiffLeg2 = make_legend();
195     DiffLeg2->SetX1(0.3);
196 fronga 1.7 DiffLeg2->SetFillStyle(0);
197 fronga 1.5 DiffLeg2->AddEntry(subtracted,"observed - predicted","PL");
198     DiffLeg2->AddEntry(subtrerr2,"stat. uncert on prediction","F");
199 fronga 1.7 DiffLeg2->AddEntry((TObject*)0,"","");
200     DiffLeg2->AddEntry((TObject*)0,"","");
201 fronga 1.5 DiffLeg2->Draw();
202    
203     stringstream saveasSigSub2;
204     saveasSigSub2 << "MetPlots/mll_sig_SUBTRACTED_quadr_" << cutat << "__" << name;
205    
206     CompleteSave(tcan,saveasSigSub2.str());
207    
208 buchmann 1.3
209    
210 fronga 1.7 // 5.- Control region comparison
211 buchmann 1.6 scalefactor = (mllscon->Integral(scaleBinLow,scaleBinHigh)-mllOscon->Integral(scaleBinLow,scaleBinHigh));
212     scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
213     zlineshape->Scale(scalefactor);
214     control_prediction->Add(zlineshape);
215 fronga 1.7 control_prediction->SetMaximum(280); // FIX Y RANGE TO EASE COMPARISON
216    
217     //control_prediction->GetYaxis()->SetRangeUser(0,control_prediction->GetMaximum()*1.3);
218     TGraphErrors *stat2j;
219     control_prediction->Draw("hist");
220     if(doMC) {
221     mcMllscon->Draw("same");
222     } else {
223     stat2j = MakeErrorGraph(control_prediction);
224     stat2j->Draw("2,same");
225     mllOscon->Draw("same,hist");
226     zlineshape->Draw("histo,same");
227     }
228 buchmann 1.6 control_prediction->Draw("histo,same");
229 buchmann 1.1 mllscon->Draw("same");
230     DrawPrelim();
231    
232 buchmann 1.6 TBox *cr1box = new TBox(20,0,70,control_prediction->GetMaximum());
233 buchmann 1.1 cr1box->SetFillStyle(0);
234     cr1box->SetLineColor(TColor::GetColor("#0404B4"));
235     cr1box->SetLineWidth(3);
236    
237 buchmann 1.6 TBox *cr2box = new TBox(150,0,320,control_prediction->GetMaximum());
238 buchmann 1.1 cr2box->SetFillStyle(0);
239     cr2box->SetLineColor(TColor::GetColor("#0404B4"));
240     cr2box->SetLineWidth(3);
241     cr2box->SetLineStyle(2);
242    
243 fronga 1.7 TLegend *legc;
244     if ( doMC ) {
245     legc = allsamples.allbglegend();
246     } else {
247     legc = make_legend();
248     }
249 buchmann 1.1 legc->SetX1(0.54);
250 fronga 1.7 legc->SetHeader(((string)"N_{jets} < "+snjets.str()+", "+MetHeader.str()).c_str());
251     if ( !doMC ) legc->AddEntry(mllscon,"Data","PL");
252 buchmann 1.6 legc->AddEntry(control_prediction,"All bg","L");
253 fronga 1.7 if ( !doMC ) {
254     legc->AddEntry(zlineshape,"Z lineshape","L");
255     legc->AddEntry(mllOscon,"bg without Z","L");
256     legc->AddEntry(stat2j,"stat. uncert.","F");
257     }
258 buchmann 1.1 legc->AddEntry(cr1box,"CR1","F");
259     legc->AddEntry(cr2box,"CR2","F");
260     legc->Draw();
261    
262     cr1box->Draw();
263     cr2box->Draw();
264    
265     stringstream saveasCon;
266 buchmann 1.3 saveasCon << "MetPlots/mll_con" << cutat << "__" << name;
267 buchmann 1.1 CompleteSave(tcan,saveasCon.str());
268 fronga 1.7
269     // 6. - Opposite-flavour data/MC comparison
270     if ( doMC ) {
271     mllOsig->SetLineColor(kBlack);
272     mllOsig->Draw();
273     mcMllOsig->Draw("same");
274     mllOsig->Draw("same");
275     TLegend *legsdm = allsamples.allbglegend();
276     legsdm->SetHeader(((string)"N_{jets}#geq"+snjets.str()+", "+MetHeader.str()+", OF").c_str());
277     legsdm->SetX1(0.54);
278     legsdm->Draw();
279     stringstream saveasSigOF;
280     saveasSigOF << "MetPlots/mll_sig_of_" << cutat << "__" << name;
281     CompleteSave(tcan,saveasSigOF.str());
282    
283     mllOscon->SetLineColor(kBlack);
284     mllOscon->Draw();
285     mcMllOscon->Draw("same");
286     mllOscon->Draw("same");
287     TLegend *legcdm = allsamples.allbglegend();
288     legcdm->SetHeader(((string)"N_{jets}<"+snjets.str()+", "+MetHeader.str()+", OF").c_str());
289     legcdm->SetX1(0.54);
290     legcdm->Draw();
291     stringstream saveasConOF;
292     saveasConOF << "MetPlots/mll_con_of_" << cutat << "__" << name;
293     CompleteSave(tcan,saveasConOF.str());
294    
295     delete legsdm;
296     delete legcdm;
297    
298     delete mcMllscon;
299     delete mcMllOscon;
300     delete mcMllsig;
301     delete mcMllOsig;
302     }
303 buchmann 1.1
304     delete cr1box;
305     delete cr2box;
306     delete srbox;
307     delete legc;
308     delete leg;
309 fronga 1.7 delete DiffLeg;
310     delete DiffLeg2;
311    
312 buchmann 1.1 delete mllscon;
313     delete mllOscon;
314     delete mllsig;
315     delete mllOsig;
316 fronga 1.7 delete zlineshape;
317 buchmann 1.6 delete tcan;
318 buchmann 1.1 }
319    
320     void DoMetPlots() {
321 fronga 1.7 float metCuts[] = { 100., 150. };
322     int jetCuts[] = { 3, 2 };
323     string leptCuts[] = { "pt1>20&&pt2>20&&abs(eta1)<1.4&&abs(eta2)<1.4",
324     "pt1>20&&pt2>10"
325     };
326     bool nomc(0),domc(1);
327     for ( int i=0; i<2; ++i ) {
328     ProduceMetPlotsWithCut(TCut(("mll>20&&"+leptCuts[i]).c_str()),"",metCuts[i], jetCuts[i],nomc);
329     ProduceMetPlotsWithCut(TCut(("mll>20&&"+leptCuts[i]).c_str()),"",metCuts[i], jetCuts[i],domc);
330     if (!PlottingSetup::is53reco) { // Old 5_2
331     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag==0&&"+leptCuts[i]).c_str()),"bTagVeto30",metCuts[i], jetCuts[i]);
332     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag>0&&"+leptCuts[i]).c_str()),"AtLeastOneBJet30",metCuts[i], jetCuts[i]);
333     } else {
334     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag30==0&&"+leptCuts[i]).c_str()),"bTagVeto30",metCuts[i], jetCuts[i],nomc);
335     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag30>0&&"+leptCuts[i]).c_str()),"AtLeastOneBJet30",metCuts[i], jetCuts[i],nomc);
336     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag30==0&&"+leptCuts[i]).c_str()),"bTagVeto30",metCuts[i], jetCuts[i],domc);
337     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag30>0&&"+leptCuts[i]).c_str()),"AtLeastOneBJet30",metCuts[i], jetCuts[i],domc);
338     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag40==0&&"+leptCuts[i]).c_str()),"bTagVeto40",metCuts[i], jetCuts[i]);
339     ProduceMetPlotsWithCut(TCut(("mll>20&&pfJetGoodNumBtag40>0&&"+leptCuts[i]).c_str()),"AtLeastOneBJet40",metCuts[i], jetCuts[i]);
340     }
341     }
342 buchmann 1.1 }