ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.6
Committed: Fri Aug 17 13:07:18 2012 UTC (12 years, 8 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.5: +24 -11 lines
Log Message:
Adapted range for Z lineshape scaling

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 buchmann 1.2 void ProduceMetPlotsWithCut(TCut cut, string name, float cutat) {
25 buchmann 1.1 TCanvas *tcan = new TCanvas("tcan","tcan");
26     cout << "Doing met plots" << endl;
27 buchmann 1.2 stringstream MetBaseCuts;
28     MetBaseCuts << "pt1>20&&pt2>20&&met[4]>" << cutat << "&&" << (const char*) cut;
29     TCut MetBaseCut(MetBaseCuts.str().c_str());
30 buchmann 1.1 TCut MetSignalRegion(MetBaseCut&&"mll>20&&mll<70&&pfJetGoodNum40>=3");
31     TCut MetControlRegion1(MetBaseCut&&"mll>20&&mll<70&&pfJetGoodNum40<=2");
32     TCut MetControlRegion2(MetBaseCut&&"mll>150&&pfJetGoodNum40<=2");
33    
34     //compute SF / OF rate in (CR1+CR2), should give 0.941 +/- 0.05
35    
36     TH1F *mllsig = allsamples.Draw("mllsig", "mll",60,20.0,320.0,"m_{ll} (GeV)","events",TCut(cutOSSF&&basiccut&&MetBaseCut&&"pfJetGoodNum40>=3"),data,PlottingSetup::luminosity);
37     TH1F *mllscon = allsamples.Draw("mllscon", "mll",60,20.0,320.0,"m_{ll} (GeV)","events",TCut(cutOSSF&&basiccut&&MetBaseCut&&"pfJetGoodNum40<=2"),data,PlottingSetup::luminosity);
38     TH1F *mllOsig = allsamples.Draw("mllOsig", "mll",60,20.0,320.0,"m_{ll} (GeV)","events",TCut(cutOSOF&&basiccut&&MetBaseCut&&"pfJetGoodNum40>=3"),data,PlottingSetup::luminosity);
39     TH1F *mllOscon = allsamples.Draw("mllOscon","mll",60,20,320,"m_{ll} (GeV)","events",TCut(cutOSOF&&basiccut&&MetBaseCut&&"pfJetGoodNum40<=2"),data,PlottingSetup::luminosity);
40    
41     mllOsig->SetLineColor(kRed);
42     mllOscon->SetLineColor(kRed);
43    
44 fronga 1.4 TH1F *zlineshape = allsamples.Draw("zlineshape","mll",60,20,320,"m_{ll} (GeV)","events",cutOSSF&&basiccut&&TCut("pfJetGoodNum40==1&&pt1>20&&pt2>20"),data,PlottingSetup::luminosity);
45     //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);
46     //scalefactor/=(zlineshape->GetBinContent(zlineshape->GetMaximumBin()-1)+zlineshape->GetBinContent(zlineshape->GetMaximumBin())+zlineshape->GetBinContent(zlineshape->GetMaximumBin()+1));
47     // Alternative scale factor: use 90+-5 GeV
48 buchmann 1.6 Int_t scaleBinLow = mllsig->FindBin(86);
49     Int_t scaleBinHigh = mllsig->FindBin(94);
50 fronga 1.4 float scalefactor = (mllsig->Integral(scaleBinLow,scaleBinHigh)-mllOsig->Integral(scaleBinLow,scaleBinHigh));
51     scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
52 buchmann 1.6
53     cout << "Bins for scaling : " << scaleBinLow << " : " << scaleBinHigh << endl;
54    
55 buchmann 1.3 zlineshape->Scale(scalefactor);
56     zlineshape->SetLineColor(kBlue);
57     zlineshape->SetLineStyle(2);
58    
59     TH1F *subtracted = (TH1F*)mllsig->Clone("subtracted");
60     TH1F *baseline = (TH1F*)mllOsig->Clone("baseline");
61     for(int i=1;i<=subtracted->GetNbinsX();i++) {
62     subtracted->SetBinContent(i,mllsig->GetBinContent(i)-mllOsig->GetBinContent(i));
63     baseline->SetBinContent(i,0);
64     }
65    
66     TH1F *prediction = (TH1F*)mllOsig->Clone("prediction");
67     prediction->Add(zlineshape);
68     prediction->SetLineColor(TColor::GetColor("#CF35CA"));
69    
70 fronga 1.4 mllsig->GetYaxis()->SetRangeUser(0,mllsig->GetMaximum()*1.2);
71 buchmann 1.1 mllsig->Draw();
72 buchmann 1.3 TGraphErrors *stat3j = MakeErrorGraph(prediction);
73 buchmann 1.1 stat3j->Draw("2,same");
74 buchmann 1.3 prediction->Draw("histo,same");
75 buchmann 1.1 mllOsig->Draw("histo,same");
76 buchmann 1.3 zlineshape->Draw("histo,same");
77 buchmann 1.1 mllsig->Draw("same");
78     DrawPrelim();
79    
80     TBox *srbox = new TBox(20,0,70,mllsig->GetMaximum());
81     srbox->SetFillStyle(0);
82     srbox->SetLineColor(TColor::GetColor("#298A08"));
83     srbox->SetLineWidth(3);
84    
85     TH1F *emptyh = new TH1F("emptyh","emptyh",1,0,1);
86     emptyh->SetLineColor(kWhite);
87     emptyh->SetFillColor(kWhite);
88     emptyh->SetLineWidth(0);
89    
90     TLegend *leg = make_legend();
91     leg->SetX1(0.54);
92 buchmann 1.2 stringstream MetHeader;
93     MetHeader << "MET>" << cutat << " GeV";
94     leg->SetHeader(((string)"N_{jets}#geq 3, "+MetHeader.str()).c_str());
95 buchmann 1.1 leg->AddEntry(mllsig,"Data","PL");
96 buchmann 1.3 leg->AddEntry(prediction,"All bg","L");
97 buchmann 1.1 leg->AddEntry(mllOsig,"bg without Z","L");
98 buchmann 1.3 leg->AddEntry(zlineshape,"Z lineshape","L");
99 buchmann 1.1 leg->AddEntry(stat3j,"stat. uncert.","F");
100     leg->AddEntry(srbox,"SR","F");
101     leg->Draw();
102    
103     srbox->Draw();
104    
105     stringstream saveasSig;
106 buchmann 1.3 saveasSig << "MetPlots/mll_sig" << cutat << "__" << name;
107 buchmann 1.1 CompleteSave(tcan,saveasSig.str());
108    
109 fronga 1.4 mllsig->SetMinimum(0.2);
110 buchmann 1.6
111 fronga 1.4 mllsig->SetMaximum(mllsig->GetMaximum()*4.0);
112     srbox->SetY2(mllsig->GetMaximum());
113 buchmann 1.6
114 buchmann 1.1 tcan->SetLogy(1);
115     stringstream saveasSig2;
116 buchmann 1.3 saveasSig2 << "MetPlots/mll_sig_ZLINESHAPE_" << cutat << "__" << name;
117    
118 buchmann 1.1 CompleteSave(tcan,saveasSig2.str());
119     tcan->SetLogy(0);
120    
121 buchmann 1.3 for(int i=1;i<subtracted->GetNbinsX();i++) {
122     subtracted->SetBinContent(i,subtracted->GetBinContent(i)-zlineshape->GetBinContent(i));
123     }
124    
125     TGraphErrors *subtrerr = MakeErrorGraph(baseline);
126     subtracted->Draw();
127     subtrerr->Draw("2,same");
128     subtracted->Draw("same");
129     DrawPrelim();
130     TLegend *DiffLeg = make_legend();
131 fronga 1.5 DiffLeg->SetX1(0.3);
132 buchmann 1.3 DiffLeg->AddEntry(subtracted,"observed - predicted","PL");
133     DiffLeg->AddEntry(subtrerr,"stat. uncert on prediction","F");
134 fronga 1.5 DiffLeg->AddEntry(emptyh," ","");
135     DiffLeg->AddEntry(emptyh," ","");
136 buchmann 1.3 DiffLeg->Draw();
137    
138     stringstream saveasSigSub;
139     saveasSigSub << "MetPlots/mll_sig_SUBTRACTED_" << cutat << "__" << name;
140    
141     CompleteSave(tcan,saveasSigSub.str());
142 fronga 1.5
143     // Now add errors in quadrature
144     TGraphErrors *subtrerr2 = (TGraphErrors*)subtrerr->Clone("subtrerr2");
145     for(int i=0;i<subtrerr2->GetN();i++) {
146     subtrerr2->SetPoint(i,subtracted->GetBinCenter(i),subtracted->GetBinContent(i));
147     subtrerr2->SetPointError(i,subtrerr2->GetErrorX(i),TMath::Sqrt(subtrerr2->GetErrorY(i)*subtrerr2->GetErrorY(i)+subtracted->GetBinError(i)*subtracted->GetBinError(i)));
148     }
149     TLine* l = new TLine(subtracted->GetBinLowEdge(1),0.,subtracted->GetBinLowEdge(subtracted->GetNbinsX()-1)+subtracted->GetBinWidth(1),0.);
150     l->SetLineWidth(subtracted->GetLineWidth());
151     subtracted->Draw();
152     subtrerr2->Draw("2,same");
153     l->Draw("same");
154     subtracted->Draw("same");
155     DrawPrelim();
156     TLegend *DiffLeg2 = make_legend();
157     DiffLeg2->SetX1(0.3);
158     DiffLeg2->AddEntry(subtracted,"observed - predicted","PL");
159     DiffLeg2->AddEntry(subtrerr2,"stat. uncert on prediction","F");
160     DiffLeg2->AddEntry(emptyh," ","");
161     DiffLeg2->AddEntry(emptyh," ","");
162     DiffLeg2->SetFillStyle(0);
163     DiffLeg2->Draw();
164    
165     stringstream saveasSigSub2;
166     saveasSigSub2 << "MetPlots/mll_sig_SUBTRACTED_quadr_" << cutat << "__" << name;
167    
168     CompleteSave(tcan,saveasSigSub2.str());
169    
170 buchmann 1.3
171    
172 buchmann 1.6 scalefactor = (mllscon->Integral(scaleBinLow,scaleBinHigh)-mllOscon->Integral(scaleBinLow,scaleBinHigh));
173     scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
174     zlineshape->Scale(scalefactor);
175    
176     TH1F *control_prediction = (TH1F*)mllOscon->Clone("control_prediction");
177     control_prediction->Add(zlineshape);
178     control_prediction->SetLineColor(TColor::GetColor("#CF35CA"));
179 buchmann 1.3
180 buchmann 1.6 control_prediction->GetYaxis()->SetRangeUser(0,control_prediction->GetMaximum()*1.3);
181     control_prediction->Draw();
182     TGraphErrors *stat2j = MakeErrorGraph(control_prediction);
183 buchmann 1.1 stat2j->Draw("2,same");
184 buchmann 1.6 control_prediction->Draw("histo,same");
185 buchmann 1.1 mllscon->Draw("same");
186 buchmann 1.6 zlineshape->Draw("histo,same");
187 buchmann 1.1 DrawPrelim();
188    
189 buchmann 1.6 TBox *cr1box = new TBox(20,0,70,control_prediction->GetMaximum());
190 buchmann 1.1 cr1box->SetFillStyle(0);
191     cr1box->SetLineColor(TColor::GetColor("#0404B4"));
192     cr1box->SetLineWidth(3);
193    
194 buchmann 1.6 TBox *cr2box = new TBox(150,0,320,control_prediction->GetMaximum());
195 buchmann 1.1 cr2box->SetFillStyle(0);
196     cr2box->SetLineColor(TColor::GetColor("#0404B4"));
197     cr2box->SetLineWidth(3);
198     cr2box->SetLineStyle(2);
199    
200     TLegend *legc = make_legend();
201     legc->SetX1(0.54);
202 buchmann 1.2 legc->SetHeader(((string)"N_{jets}#leq 2, "+MetHeader.str()).c_str());
203 buchmann 1.1 legc->AddEntry(mllsig,"Data","PL");
204 buchmann 1.6 legc->AddEntry(control_prediction,"All bg","L");
205     legc->AddEntry(zlineshape,"Z lineshape","L");
206 buchmann 1.1 legc->AddEntry(mllOsig,"bg without Z","L");
207     legc->AddEntry(stat3j,"stat. uncert.","F");
208     legc->AddEntry(cr1box,"CR1","F");
209     legc->AddEntry(cr2box,"CR2","F");
210     legc->Draw();
211    
212     cr1box->Draw();
213     cr2box->Draw();
214    
215     stringstream saveasCon;
216 buchmann 1.3 saveasCon << "MetPlots/mll_con" << cutat << "__" << name;
217 buchmann 1.1 CompleteSave(tcan,saveasCon.str());
218    
219    
220    
221     delete emptyh;
222     delete cr1box;
223     delete cr2box;
224     delete srbox;
225     delete legc;
226     delete leg;
227     delete mllscon;
228     delete mllOscon;
229     delete mllsig;
230     delete mllOsig;
231 buchmann 1.6 delete tcan;
232 buchmann 1.1 }
233    
234     void DoMetPlots() {
235 buchmann 1.3 ProduceMetPlotsWithCut(TCut("mll>0"),"",100);
236 buchmann 1.2 // ProduceMetPlotsWithCut(TCut("mll>0&&pfJetGoodNumBtag==0"),"bTagVeto",100);
237     // ProduceMetPlotsWithCut(TCut("mll>0&&pfJetGoodNumBtag>0"),"AtLeastOneBJet",100);
238 buchmann 1.1 }