ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/MetPlotting.C
Revision: 1.4
Committed: Thu Aug 16 12:54:31 2012 UTC (12 years, 8 months ago) by fronga
Content type: text/plain
Branch: MAIN
Changes since 1.3: +13 -23 lines
Log Message:
Small refinements in MET plotting.

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     Int_t scaleBinLow = mllsig->FindBin(85);
49     Int_t scaleBinHigh = mllsig->FindBin(95);
50     float scalefactor = (mllsig->Integral(scaleBinLow,scaleBinHigh)-mllOsig->Integral(scaleBinLow,scaleBinHigh));
51     scalefactor /= zlineshape->Integral(scaleBinLow,scaleBinHigh);
52 buchmann 1.3 zlineshape->Scale(scalefactor);
53     zlineshape->SetLineColor(kBlue);
54     zlineshape->SetLineStyle(2);
55    
56     TH1F *subtracted = (TH1F*)mllsig->Clone("subtracted");
57     TH1F *baseline = (TH1F*)mllOsig->Clone("baseline");
58     for(int i=1;i<=subtracted->GetNbinsX();i++) {
59     subtracted->SetBinContent(i,mllsig->GetBinContent(i)-mllOsig->GetBinContent(i));
60     baseline->SetBinContent(i,0);
61     }
62    
63     TH1F *prediction = (TH1F*)mllOsig->Clone("prediction");
64     prediction->Add(zlineshape);
65     prediction->SetLineColor(TColor::GetColor("#CF35CA"));
66    
67 fronga 1.4 mllsig->GetYaxis()->SetRangeUser(0,mllsig->GetMaximum()*1.2);
68 buchmann 1.1 mllsig->Draw();
69 buchmann 1.3 TGraphErrors *stat3j = MakeErrorGraph(prediction);
70 buchmann 1.1 stat3j->Draw("2,same");
71 buchmann 1.3 prediction->Draw("histo,same");
72 buchmann 1.1 mllOsig->Draw("histo,same");
73 buchmann 1.3 zlineshape->Draw("histo,same");
74 buchmann 1.1 mllsig->Draw("same");
75     DrawPrelim();
76    
77     TBox *srbox = new TBox(20,0,70,mllsig->GetMaximum());
78     srbox->SetFillStyle(0);
79     srbox->SetLineColor(TColor::GetColor("#298A08"));
80     srbox->SetLineWidth(3);
81    
82     TH1F *emptyh = new TH1F("emptyh","emptyh",1,0,1);
83     emptyh->SetLineColor(kWhite);
84     emptyh->SetFillColor(kWhite);
85     emptyh->SetLineWidth(0);
86    
87     TLegend *leg = make_legend();
88     leg->SetX1(0.54);
89 buchmann 1.2 stringstream MetHeader;
90     MetHeader << "MET>" << cutat << " GeV";
91     leg->SetHeader(((string)"N_{jets}#geq 3, "+MetHeader.str()).c_str());
92 buchmann 1.1 leg->AddEntry(mllsig,"Data","PL");
93 buchmann 1.3 leg->AddEntry(prediction,"All bg","L");
94 buchmann 1.1 leg->AddEntry(mllOsig,"bg without Z","L");
95 buchmann 1.3 leg->AddEntry(zlineshape,"Z lineshape","L");
96 buchmann 1.1 leg->AddEntry(stat3j,"stat. uncert.","F");
97     leg->AddEntry(srbox,"SR","F");
98     leg->Draw();
99    
100     srbox->Draw();
101    
102     stringstream saveasSig;
103 buchmann 1.3 saveasSig << "MetPlots/mll_sig" << cutat << "__" << name;
104 buchmann 1.1 CompleteSave(tcan,saveasSig.str());
105    
106 fronga 1.4 mllsig->SetMinimum(0.2);
107     mllsig->SetMaximum(mllsig->GetMaximum()*4.0);
108     srbox->SetY2(mllsig->GetMaximum());
109    
110 buchmann 1.1 tcan->SetLogy(1);
111     stringstream saveasSig2;
112 buchmann 1.3 saveasSig2 << "MetPlots/mll_sig_ZLINESHAPE_" << cutat << "__" << name;
113    
114 buchmann 1.1 CompleteSave(tcan,saveasSig2.str());
115     tcan->SetLogy(0);
116    
117 buchmann 1.3 for(int i=1;i<subtracted->GetNbinsX();i++) {
118     subtracted->SetBinContent(i,subtracted->GetBinContent(i)-zlineshape->GetBinContent(i));
119     }
120    
121     TGraphErrors *subtrerr = MakeErrorGraph(baseline);
122     subtracted->Draw();
123     subtrerr->Draw("2,same");
124     subtracted->Draw("same");
125     DrawPrelim();
126     TLegend *DiffLeg = make_legend();
127     DiffLeg->SetX1(0.54);
128     DiffLeg->AddEntry(subtracted,"observed - predicted","PL");
129     DiffLeg->AddEntry(subtrerr,"stat. uncert on prediction","F");
130     DiffLeg->AddEntry(emptyh," ","F");
131     DiffLeg->AddEntry(emptyh," ","F");
132     DiffLeg->Draw();
133    
134     stringstream saveasSigSub;
135     saveasSigSub << "MetPlots/mll_sig_SUBTRACTED_" << cutat << "__" << name;
136    
137     CompleteSave(tcan,saveasSigSub.str());
138    
139    
140     /*
141    
142 buchmann 1.1 mllscon->GetYaxis()->SetRangeUser(0,mllscon->GetMaximum()*1.3);
143     mllscon->Draw();
144     TGraphErrors *stat2j = MakeErrorGraph(mllOscon);
145     stat2j->Draw("2,same");
146     mllOscon->Draw("histo,same");
147     mllscon->Draw("same");
148     DrawPrelim();
149    
150     TBox *cr1box = new TBox(20,0,70,mllscon->GetMaximum());
151     cr1box->SetFillStyle(0);
152     cr1box->SetLineColor(TColor::GetColor("#0404B4"));
153     cr1box->SetLineWidth(3);
154    
155     TBox *cr2box = new TBox(150,0,320,mllscon->GetMaximum());
156     cr2box->SetFillStyle(0);
157     cr2box->SetLineColor(TColor::GetColor("#0404B4"));
158     cr2box->SetLineWidth(3);
159     cr2box->SetLineStyle(2);
160    
161     TLegend *legc = make_legend();
162     legc->SetX1(0.54);
163 buchmann 1.2 legc->SetHeader(((string)"N_{jets}#leq 2, "+MetHeader.str()).c_str());
164 buchmann 1.1 legc->AddEntry(mllsig,"Data","PL");
165     legc->AddEntry(mllOsig,"bg without Z","L");
166     legc->AddEntry(stat3j,"stat. uncert.","F");
167     legc->AddEntry(cr1box,"CR1","F");
168     legc->AddEntry(cr2box,"CR2","F");
169     legc->Draw();
170    
171     cr1box->Draw();
172     cr2box->Draw();
173    
174     stringstream saveasCon;
175 buchmann 1.3 saveasCon << "MetPlots/mll_con" << cutat << "__" << name;
176 buchmann 1.1 CompleteSave(tcan,saveasCon.str());
177    
178    
179    
180     delete emptyh;
181     delete cr1box;
182     delete cr2box;
183     delete srbox;
184     delete legc;
185     delete leg;
186     delete mllscon;
187     delete mllOscon;
188     delete mllsig;
189     delete mllOsig;
190 buchmann 1.3 delete tcan;*/
191 buchmann 1.1 }
192    
193     void DoMetPlots() {
194 buchmann 1.3 ProduceMetPlotsWithCut(TCut("mll>0"),"",100);
195 buchmann 1.2 // ProduceMetPlotsWithCut(TCut("mll>0&&pfJetGoodNumBtag==0"),"bTagVeto",100);
196     // ProduceMetPlotsWithCut(TCut("mll>0&&pfJetGoodNumBtag>0"),"AtLeastOneBJet",100);
197 buchmann 1.1 }