ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/tools/plotXsec.C
Revision: 1.4
Committed: Thu Feb 24 00:15:04 2011 UTC (14 years, 2 months ago) by jengbou
Content type: text/plain
Branch: MAIN
CVS Tags: gregj-20110224, gregj-20110223-v1, HEAD
Changes since 1.3: +2 -28 lines
Log Message:
update

File Contents

# User Rev Content
1 jengbou 1.1 #include "TCanvas.h"
2     #include "TFile.h"
3     #include "TH1.h"
4     #include "TH2.h"
5     #include "TGraphAsymmErrors.h"
6     #include "TLatex.h"
7     #include "TLegend.h"
8     #include "TStyle.h"
9     #include "TLine.h"
10     #include "TBox.h"
11     #include "TMarker.h"
12     #include "TopStyle/tdrstyle.C"
13     #include "TopStyle/CMSTopStyle.cc"
14     #include <map>
15     #include <vector>
16     #include <sstream>
17     #include <iostream>
18    
19     using namespace std;
20    
21     bool overwriteAll = false;
22    
23     void plotXsec() {
24     CMSTopStyle style;
25     setTDRStyle();
26     style.setupICHEPv1();
27     std::map<TString,TGraph*> gmap;
28     std::vector<TLatex*> tvect;
29    
30     gStyle->SetPadTopMargin(0.08);
31     gStyle->SetPadLeftMargin(0.05);
32     //gStyle->SetMarkerStyle(24);
33     gStyle->SetTextFont(62);
34    
35     TCanvas *c1 = new TCanvas("c1","x-sec summary",200,10,800,700);
36    
37     int nbinsx_ = 35;
38     double xmin_ = 0., xmax_ = 350.;
39 jengbou 1.3 double ymin_ = 0.5,ymax_ = 6.1;
40 jengbou 1.1
41     TH2 *hr = new TH2F("frame","",nbinsx_,xmin_,xmax_,1,ymin_,ymax_);
42     hr->GetXaxis()->CenterTitle(kTRUE);
43     hr->SetXTitle("#sigma (pp #rightarrow t#bar{t}) [pb]");
44     hr->GetXaxis()->SetTitleOffset(0.95);
45     //hr->SetYTitle("Experiments");
46     gPad->SetTicks(1,0);
47     hr->GetXaxis()->SetNdivisions(115);
48     hr->GetXaxis()->SetLabelSize(0.04);
49     //hr->GetYaxis()->SetNdivisions(101);
50     hr->GetYaxis()->SetBinLabel(1,"");
51     hr->Draw();
52    
53     gmap["th_band"] = new TGraph(2);
54     gmap["th_band"]->SetFillColor(5);
55     gmap["th_band"]->SetFillStyle(3005);
56     gmap["th_band"]->SetLineColor(5);
57     gmap["th_band"]->SetMarkerStyle(24);
58     // gmap["th_band"]->SetLineWidth(3634);
59     // gmap["th_band"]->SetPoint(0,189.,0.5);
60     // gmap["th_band"]->SetPoint(1,189.,4.5);
61     // gmap["th_band"]->Draw("");
62    
63 jengbou 1.3 const Int_t np = 5; // modify ymax_ accordingly
64     Int_t iColor[np] = {1,28,9,4,2};
65     Int_t iMark [np] = {20,21,22,23,20};
66    
67     Float_t nexp[np] = {1,2,3,4,5};
68 jengbou 1.4 Float_t xsec[np] = {157.5,145.0,194.0,156.0,153.7}; // x-sec
69 jengbou 1.3 Float_t stath[np] = { 0. , 31. , 72. , 12. , 17. }; // stat err high
70     Float_t statl[np] = { 0. , 31. , 72. , 12. , 17. }; // stat err low
71     Float_t systh[np] = { 23.2, 42. , 24. , 28. , 28. }; // syst err high
72 jengbou 1.4 Float_t systl[np] = { 24.4, 27. , 24. , 35. , 24. }; // syst err low
73 jengbou 1.3 Float_t lumi[np] = { 0. , 0. , 21. , 17. , 19. }; // lumi err
74 jengbou 1.1
75     Float_t errh[np];
76     Float_t errl[np];
77     for (int i = 0; i < np; ++i) {
78     errh[i] = sqrt(stath[i]*stath[i] + systh[i]*systh[i]);
79     errl[i] = sqrt(statl[i]*statl[i] + systl[i]*systl[i]);
80     }
81     Float_t err0[np] = {0.,0.,0.,0.};
82    
83     // Theory prediction
84     TBox* th_band = new TBox(157.5-24.4,ymin_ + 0.1,157.5+23.2,ymax_ - 0.1);
85     th_band->SetFillColor(5);
86     //th_band->SetFillStyle(3005);
87     th_band->Draw("same");
88    
89     gPad->RedrawAxis();
90    
91     gmap["Summary"] = new TGraphAsymmErrors(np,xsec,nexp,errl,errh,err0,err0);
92     //gmap["Summary"]->SetLineColor(kBlue);
93     gmap["Summary"]->SetLineWidth(2);
94     gmap["Summary"]->SetMarkerColor(kBlue);
95     gmap["Summary"]->SetMarkerSize(1.1);
96     // gmap["Summary"]->SetMarkerStyle(20);
97     gmap["Summary"]->Draw("sameP");
98     for (int i = 0; i < np; ++i) {
99     TMarker *m = new TMarker(xsec[i],nexp[i],iMark[i]);
100     m->SetMarkerSize(2);
101     m->SetMarkerColor(iColor[i]);
102     m->Draw();
103     }
104    
105     TLatex *header0 = new TLatex(xmin_ + 10,ymax_+0.1,"CMS Preliminary"); //header->SetTextColor(1);
106     header0->SetTextSize(0.034);
107     header0->Draw();
108    
109 jengbou 1.3 TLatex *header1 = new TLatex(0.8*xmax_,ymax_+0.1,"February 2010"); //header->SetTextColor(1);
110 jengbou 1.1 header1->SetTextSize(0.028);
111     header1->Draw();
112    
113 jengbou 1.3 tvect.push_back(new TLatex(xmin_+1,nexp[0]+0.1,"Theory (MCFM)"));
114     tvect.push_back(new TLatex(xmin_+1,nexp[1]+0.1,"ATLAS Combined (L = 3 pb^{-1})"));
115     tvect.push_back(new TLatex(xmin_+1,nexp[2]+0.1,"CMS Dilepton (L = 3 pb^{-1})"));
116     TLatex* myTxt0 = new TLatex(xmin_+1,nexp[3]+0.1,"CMS #mu+jets (L = 36 pb^{-1})");
117     TLatex* myTxt1 = new TLatex(xmin_+1,nexp[4]+0.1,"CMS #mu+jets+btag (L = 36 pb^{-1})");
118     myTxt0->SetTextColor(iColor[3]);
119     myTxt1->SetTextColor(iColor[4]);
120 jengbou 1.1 tvect.push_back(myTxt0);
121 jengbou 1.3 tvect.push_back(myTxt1);
122 jengbou 1.1
123     TString xsec_[np];
124     for (int i = 0; i < np; ++i){
125     std::ostringstream ss_[6];
126     ss_[0].precision(1); ss_[0].setf(ios::fixed,ios::floatfield);
127     ss_[0] << xsec[i];
128     xsec_[i] = ss_[0].str();
129     // Stat
130     if ( stath[i] > 0.) {
131     if (stath[i] == statl[i]) {
132     ss_[1] << stath[i];
133     xsec_[i] = xsec_[i] + " #pm " + ss_[1].str() + " (stat.)";
134     }
135     else {
136     ss_[1] << stath[i];
137     ss_[2] << statl[i];
138     xsec_[i] = xsec_[i] + " #splitline{+" + ss_[1].str() + "}{- " + ss_[2].str() + "} (stat.)";
139     }
140     }
141     // Syst
142     if ( systh[i] > 0.) {
143     if (systh[i] == systl[i]) {
144     ss_[3] << systh[i];
145     xsec_[i] = xsec_[i] + " #pm " + ss_[3].str() + " (syst.)";
146     }
147     else {
148     ss_[3] << systh[i];
149     ss_[4] << systl[i];
150     xsec_[i] = xsec_[i] + " #splitline{+" + ss_[3].str() + "}{- " + ss_[4].str() + "} (syst.)";
151     }
152     }
153     // Lumi
154     if ( lumi[i] > 0.) {
155     ss_[5] << lumi[i];
156     xsec_[i] = xsec_[i] + " #pm " + ss_[5].str() + " (lumi.)";
157     }
158     }
159    
160     tvect.push_back(new TLatex((xmax_-xmin_)*0.6,nexp[0]+0.1,xsec_[0]));
161     tvect.push_back(new TLatex((xmax_-xmin_)*0.6,nexp[1]+0.1,xsec_[1]));
162     tvect.push_back(new TLatex((xmax_-xmin_)*0.6,nexp[2]+0.1,xsec_[2]));
163 jengbou 1.3 TLatex *myTxt2 = new TLatex((xmax_-xmin_)*0.6,nexp[3]+0.1,xsec_[3]);
164     TLatex *myTxt3 = new TLatex((xmax_-xmin_)*0.6,nexp[4]+0.1,xsec_[4]);
165     myTxt2->SetTextColor(iColor[3]);
166     myTxt3->SetTextColor(iColor[4]);
167     tvect.push_back(myTxt2);
168     tvect.push_back(myTxt3);
169 jengbou 1.1
170     for (unsigned int i = 0; i < tvect.size(); i++) {
171     if (i < np) tvect[i]->SetX((xmax_-xmin_)*0.05);
172     tvect[i]->SetTextSize(0.024);
173     //tvect[i]->SetTextAlign(11);
174     tvect[i]->Draw();
175     }
176    
177     TLegend *leg0 = new TLegend(0.6,0.82,0.9,0.9);
178     leg0->SetFillColor(0);
179     leg0->SetFillStyle(0);
180     // leg0->AddEntry(th_band,"MCFM (m_{top} = 172.5 GeV/c^{2})","f");
181     leg0->AddEntry(th_band,"MCFM","f");
182     leg0->Draw();
183    
184     gPad->Update();
185    
186     std::cout << "\nSave plots? (y/n)" << std::endl;
187     char incmd;
188     if (overwriteAll) incmd='y';
189     else cin.get(incmd);
190     if (incmd != 'y' && incmd != 'Y') return;
191    
192     c1->SaveAs("Summary_Xsec_new.pdf");
193     c1->SaveAs("Summary_Xsec_new.png");
194    
195     return;
196     }