ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Jeng/tools/plotXsec.C
Revision: 1.3
Committed: Fri Feb 18 16:18:42 2011 UTC (14 years, 2 months ago) by jengbou
Content type: text/plain
Branch: MAIN
Changes since 1.2: +36 -4 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 <<<<<<< plotXsec.C
64     const Int_t np = 5; // modify ymax_ accordingly
65     Int_t iColor[np] = {1,28,9,4,2};
66     Int_t iMark [np] = {20,21,22,23,20};
67    
68     Float_t nexp[np] = {1,2,3,4,5};
69     Float_t xsec[np] = {157.5,145.0,194.0,156.0,167.3}; // x-sec
70     Float_t stath[np] = { 0. , 31. , 72. , 12. , 17. }; // stat err high
71     Float_t statl[np] = { 0. , 31. , 72. , 12. , 17. }; // stat err low
72     Float_t systh[np] = { 23.2, 42. , 24. , 28. , 28. }; // syst err high
73     Float_t systl[np] = { 24.4, 27. , 24. , 35. , 25. }; // syst err low
74     Float_t lumi[np] = { 0. , 0. , 21. , 17. , 19. }; // lumi err
75     =======
76 jengbou 1.1 const Int_t np = 4;
77     Int_t iColor[np] = {1,2,9,4};
78     Int_t iMark [np] = {20,21,22,23};
79    
80     Float_t nexp[np] = {1,2,3,4};
81 jengbou 1.2 Float_t xsec[np] = {157.5,145.0,194.0,158.1}; // x-sec
82     Float_t stath[np] = { 0. , 31. , 72. , 12. }; // stat err high
83     Float_t statl[np] = { 0. , 31. , 72. , 12. }; // stat err low
84     Float_t systh[np] = { 23.2, 42. , 24. , 35. }; // syst err high
85     Float_t systl[np] = { 24.4, 27. , 24. , 35. }; // syst err low
86     Float_t lumi[np] = { 0. , 0. , 21. , 17. }; // lumi err
87 jengbou 1.3 >>>>>>> 1.2
88 jengbou 1.1
89     Float_t errh[np];
90     Float_t errl[np];
91     for (int i = 0; i < np; ++i) {
92     errh[i] = sqrt(stath[i]*stath[i] + systh[i]*systh[i]);
93     errl[i] = sqrt(statl[i]*statl[i] + systl[i]*systl[i]);
94     }
95     Float_t err0[np] = {0.,0.,0.,0.};
96    
97     // Theory prediction
98     TBox* th_band = new TBox(157.5-24.4,ymin_ + 0.1,157.5+23.2,ymax_ - 0.1);
99     th_band->SetFillColor(5);
100     //th_band->SetFillStyle(3005);
101     th_band->Draw("same");
102    
103     gPad->RedrawAxis();
104    
105     gmap["Summary"] = new TGraphAsymmErrors(np,xsec,nexp,errl,errh,err0,err0);
106     //gmap["Summary"]->SetLineColor(kBlue);
107     gmap["Summary"]->SetLineWidth(2);
108     gmap["Summary"]->SetMarkerColor(kBlue);
109     gmap["Summary"]->SetMarkerSize(1.1);
110     // gmap["Summary"]->SetMarkerStyle(20);
111     gmap["Summary"]->Draw("sameP");
112     for (int i = 0; i < np; ++i) {
113     TMarker *m = new TMarker(xsec[i],nexp[i],iMark[i]);
114     m->SetMarkerSize(2);
115     m->SetMarkerColor(iColor[i]);
116     m->Draw();
117     }
118    
119     TLatex *header0 = new TLatex(xmin_ + 10,ymax_+0.1,"CMS Preliminary"); //header->SetTextColor(1);
120     header0->SetTextSize(0.034);
121     header0->Draw();
122    
123 jengbou 1.3 <<<<<<< plotXsec.C
124     TLatex *header1 = new TLatex(0.8*xmax_,ymax_+0.1,"February 2010"); //header->SetTextColor(1);
125     =======
126 jengbou 1.2 TLatex *header1 = new TLatex(0.8*xmax_,ymax_+0.1,"December 2010"); //header->SetTextColor(1);
127 jengbou 1.3 >>>>>>> 1.2
128 jengbou 1.1 header1->SetTextSize(0.028);
129     header1->Draw();
130    
131 jengbou 1.3 <<<<<<< plotXsec.C
132     tvect.push_back(new TLatex(xmin_+1,nexp[0]+0.1,"Theory (MCFM)"));
133     tvect.push_back(new TLatex(xmin_+1,nexp[1]+0.1,"ATLAS Combined (L = 3 pb^{-1})"));
134     tvect.push_back(new TLatex(xmin_+1,nexp[2]+0.1,"CMS Dilepton (L = 3 pb^{-1})"));
135     TLatex* myTxt0 = new TLatex(xmin_+1,nexp[3]+0.1,"CMS #mu+jets (L = 36 pb^{-1})");
136     TLatex* myTxt1 = new TLatex(xmin_+1,nexp[4]+0.1,"CMS #mu+jets+btag (L = 36 pb^{-1})");
137     myTxt0->SetTextColor(iColor[3]);
138     myTxt1->SetTextColor(iColor[4]);
139     =======
140 jengbou 1.1 tvect.push_back(new TLatex(xmin_+10,nexp[0]+0.1,"Theory (MCFM)"));
141     tvect.push_back(new TLatex(xmin_+10,nexp[1]+0.1,"ATLAS Combined (L = 3 pb^{-1})"));
142     tvect.push_back(new TLatex(xmin_+10,nexp[2]+0.1,"CMS Dilepton (L = 3 pb^{-1})"));
143 jengbou 1.2 TLatex* myTxt0 = new TLatex(xmin_+10,nexp[3]+0.1,"CMS #mu+Jets (L = 36 pb^{-1})");
144 jengbou 1.1 myTxt0->SetTextColor(iColor[3]);
145 jengbou 1.3 >>>>>>> 1.2
146 jengbou 1.1 tvect.push_back(myTxt0);
147 jengbou 1.3 tvect.push_back(myTxt1);
148 jengbou 1.1
149     TString xsec_[np];
150     for (int i = 0; i < np; ++i){
151     std::ostringstream ss_[6];
152     ss_[0].precision(1); ss_[0].setf(ios::fixed,ios::floatfield);
153     ss_[0] << xsec[i];
154     xsec_[i] = ss_[0].str();
155     // Stat
156     if ( stath[i] > 0.) {
157     if (stath[i] == statl[i]) {
158     ss_[1] << stath[i];
159     xsec_[i] = xsec_[i] + " #pm " + ss_[1].str() + " (stat.)";
160     }
161     else {
162     ss_[1] << stath[i];
163     ss_[2] << statl[i];
164     xsec_[i] = xsec_[i] + " #splitline{+" + ss_[1].str() + "}{- " + ss_[2].str() + "} (stat.)";
165     }
166     }
167     // Syst
168     if ( systh[i] > 0.) {
169     if (systh[i] == systl[i]) {
170     ss_[3] << systh[i];
171     xsec_[i] = xsec_[i] + " #pm " + ss_[3].str() + " (syst.)";
172     }
173     else {
174     ss_[3] << systh[i];
175     ss_[4] << systl[i];
176     xsec_[i] = xsec_[i] + " #splitline{+" + ss_[3].str() + "}{- " + ss_[4].str() + "} (syst.)";
177     }
178     }
179     // Lumi
180     if ( lumi[i] > 0.) {
181     ss_[5] << lumi[i];
182     xsec_[i] = xsec_[i] + " #pm " + ss_[5].str() + " (lumi.)";
183     }
184     }
185    
186     tvect.push_back(new TLatex((xmax_-xmin_)*0.6,nexp[0]+0.1,xsec_[0]));
187     tvect.push_back(new TLatex((xmax_-xmin_)*0.6,nexp[1]+0.1,xsec_[1]));
188     tvect.push_back(new TLatex((xmax_-xmin_)*0.6,nexp[2]+0.1,xsec_[2]));
189 jengbou 1.3 TLatex *myTxt2 = new TLatex((xmax_-xmin_)*0.6,nexp[3]+0.1,xsec_[3]);
190     TLatex *myTxt3 = new TLatex((xmax_-xmin_)*0.6,nexp[4]+0.1,xsec_[4]);
191     myTxt2->SetTextColor(iColor[3]);
192     myTxt3->SetTextColor(iColor[4]);
193     tvect.push_back(myTxt2);
194     tvect.push_back(myTxt3);
195 jengbou 1.1
196     for (unsigned int i = 0; i < tvect.size(); i++) {
197     if (i < np) tvect[i]->SetX((xmax_-xmin_)*0.05);
198     tvect[i]->SetTextSize(0.024);
199     //tvect[i]->SetTextAlign(11);
200     tvect[i]->Draw();
201     }
202    
203     TLegend *leg0 = new TLegend(0.6,0.82,0.9,0.9);
204     leg0->SetFillColor(0);
205     leg0->SetFillStyle(0);
206     // leg0->AddEntry(th_band,"MCFM (m_{top} = 172.5 GeV/c^{2})","f");
207     leg0->AddEntry(th_band,"MCFM","f");
208     leg0->Draw();
209    
210     gPad->Update();
211    
212     std::cout << "\nSave plots? (y/n)" << std::endl;
213     char incmd;
214     if (overwriteAll) incmd='y';
215     else cin.get(incmd);
216     if (incmd != 'y' && incmd != 'Y') return;
217    
218     c1->SaveAs("Summary_Xsec_new.pdf");
219     c1->SaveAs("Summary_Xsec_new.png");
220    
221     return;
222     }