Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
AtlasExample.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook -js
4/// Show how ATLAS Style looks like. It is based on a style file from BaBar.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author M.Sutton
10
11const Int_t GMAX=864;
12
13const int nren=3;
14static const double mur[nren] = {1.0,0.25,4.0};
15static const double muf[nren] = {1.0,0.25,4.0};
16const unsigned int NUMPDF=41;
17
18TGraphErrors* GetGraph(Int_t ir, Int_t ifs,Int_t icut, Int_t ipdf);
19void AddtoBand(TGraphErrors* g1, TGraphAsymmErrors* g2);
21
22void AtlasExample()
23{
24 gROOT->SetStyle("ATLAS");
25
26 Int_t icol1=5;
27 Int_t icol2=5;
28
29 auto canvas = new TCanvas("canvas","single inclusive jets",50,50,600,600);
30 canvas->SetLogy();
31
32 Double_t ymin = 1.e-3; Double_t ymax = 2e7;
33 Double_t xmin = 60.00; Double_t xmax = 3500.;
34 auto frame = canvas->DrawFrame(xmin,ymin,xmax,ymax);
35 frame->SetYTitle("d#sigma_{jet}/dE_{T,jet} [fb/GeV]");
36 frame->SetXTitle("E_{T,jet} [GeV]");
37 frame->GetYaxis()->SetTitleOffset(1.4);
38 frame->GetXaxis()->SetTitleOffset(1.4);
39
40 const Int_t ncut=1;
41 TGraphErrors *data[ncut];
42
43 for (Int_t icut=0; icut<ncut; icut++) { // loop over cuts
44 TGraphErrors *g1[nren][ncut];
45 for (Int_t ir=0; ir<nren; ir++) { // loop over ren scale
46 g1[ir][icut] = GetGraph(ir,ir,icut,0);
47 if (!g1[ir][icut]) {
48 cout << " g1 not found " << endl;
49 return;
50 }
51 g1[ir][icut]->SetLineColor(1);
52 g1[ir][icut]->SetMarkerStyle(0);
53 }
54
55 char daname[100];
56 sprintf(daname,"data_%d",icut);
57 data[icut] = (TGraphErrors*)g1[0][icut]->Clone(daname);
58 data[icut]->SetMarkerStyle(20);
59 data[icut]->SetMarkerColor(1);
60
61 // Just invent some data
62 for (Int_t i=0; i< data[icut]->GetN(); i++) {
63 Double_t x1,y1,e,dx1=0.;
64 data[icut]->GetPoint(i,x1,y1);
65 Double_t r1 = 0.4*(gRandom->Rndm(1)+2);
66 Double_t r2 = 0.4*(gRandom->Rndm(1)+2);
67 Double_t y;
68 if (icut==0) y = r1*y1+r1*r2*r2*x1/50000.;
69 else y = r1*y1;
70 e = sqrt(y*1000)/200;
71 data[icut]->SetPoint(i, x1,y);
72 data[icut]->SetPointError(i,dx1,e);
73 }
74
75 TGraphAsymmErrors* scale[ncut];
76 TGraphAsymmErrors* scalepdf[ncut];
77
78 scale[icut] = MakeBand(g1[0][icut],g1[1][icut],g1[2][icut]);
79 scalepdf[icut]=(TGraphAsymmErrors* ) scale[icut]->Clone("scalepdf");
80
81 TGraphErrors *gpdf[NUMPDF][ncut];
82 for (Int_t ipdf=0; ipdf<NUMPDF; ipdf++) {
83 gpdf[ipdf][icut]= GetGraph(0,0,icut,ipdf);
84 if (!gpdf[ipdf][icut]) {
85 cout << " gpdf not found " << endl;
86 return;
87 }
88 gpdf[ipdf][icut]->SetLineColor(2);
89 gpdf[ipdf][icut]->SetLineStyle(1);
90 gpdf[ipdf][icut]->SetMarkerStyle(0);
91 AddtoBand(gpdf[ipdf][icut],scalepdf[icut]);
92 }
93
94 scalepdf[icut]->SetFillColor(icol2);
95 scalepdf[icut]->Draw("zE2");
96 scalepdf[icut]->SetLineWidth(3);
97 scale[icut]->SetFillColor(icol1);
98 scale[icut]->Draw("zE2");
99 g1[0][icut]->SetLineWidth(3);
100 g1[0][icut]->Draw("z");
101 data[icut]->Draw("P");
102 }
103
104 auto t = new TLatex; t->SetNDC();
105 t->DrawLatex(0.3, 0.85, "#sqrt{s}= 14 TeV");
106 t->DrawLatex(0.57, 0.85, "|#eta_{jet}|<0.5");
107
108 auto l = new TLegend(0.45,0.65,0.8,0.8,"","NDC");
109 l->SetBorderSize(0.);
110 l->SetTextFont(42);
111 l->AddEntry("data_0", "Data 2009", "ep");
112 l->AddEntry("scalepdf", "NLO QCD", "lf");
113 l->Draw();
114}
115
116TGraphErrors* GetGraph(Int_t ir, Int_t ifs,Int_t icut, Int_t ipdf)
117{
118 const char *cuts[5] =
119 {"0.0 <= |eta| < 0.5",
120 "0.5 <= |eta| < 1.0",
121 "1.0 <= |eta| < 1.5",
122 "1.5 <= |eta| < 2.0",
123 "2.0 <= |eta| < 3.0"};
124
125 const double mur[] = {1.0,0.25,4.0};
126 const double muf[] = {1.0,0.25,4.0};
127
129 TFile *file = TFile::Open("http://root.cern.ch/files/AtlasGraphs.root", "CACHEREAD");
130
131 char gname[100];
132 char tname[100];
133
134 if (ipdf>=0)
135 sprintf(tname," E_T (mu_r=%g, mu_f=%g);%s Pdf: %d",mur[ir],muf[ifs],cuts[icut],ipdf);
136 else
137 sprintf(tname," E_T %s Ms= %d",cuts[icut],-ipdf);
138
139 TGraphErrors* g1 = 0;
140
141 for (int i=1; i<=GMAX; i++) {
142 sprintf(gname,"full_%d",i);
143 g1 = (TGraphErrors*) file->Get(gname);
144 if (!g1) {
145 cout << gname << " not found " << endl;
146 return nullptr;
147 }
148
149 const char *title = g1->GetTitle();
150
151 if (strcmp(title,tname)==0) break;
152 g1 = 0;
153 }
154
155 if (!g1) return nullptr;
156 return g1;
157}
158
160
162
163 Double_t x1 = 0., y1 = 0., x2 = 0., y2 = 0., y0 = 0, x3 = 0.;
164 Double_t dum;
165 for (Int_t i=0; i<g1->GetN(); i++) {
166 g0->GetPoint(i, x1, y0);
167 g1->GetPoint(i, x1, y1);
168 g2->GetPoint(i, x1, y2);
169
170 if (i==g1->GetN()-1) x2=x1;
171 else g2->GetPoint(i+1,x2,dum);
172
173 if (i==0) x3=x1;
174 else g2->GetPoint(i-1,x3,dum);
175
176 Double_t tmp = y2;
177 if (y1 < y2) {
178 y2 = y1;
179 y1 = tmp;
180 }
181 g3->SetPoint(i,x1,y0);
182
183 Double_t binwl = (x1-x3)/2.;
184 Double_t binwh = (x2-x1)/2.;
185 if (binwl == 0.) binwl = binwh;
186 if (binwh == 0.) binwh = binwl;
187 g3->SetPointError(i, binwl, binwh, y0-y2, y1-y0);
188
189 }
190 return g3;
191}
192
193void AddtoBand(TGraphErrors* g1, TGraphAsymmErrors* g2) {
194
195 Double_t x1=0., y1=0., y2=0., y0=0;
196
197 if (g1->GetN()!=g2->GetN())
198 cout << " graphs don't have the same number of elements " << endl;
199
200 Double_t* EYhigh = g2-> GetEYhigh();
201 Double_t* EYlow = g2-> GetEYlow();
202
203 for (Int_t i=0; i<g1->GetN(); i++) {
204 g1->GetPoint(i, x1, y1);
205 g2->GetPoint(i, x1, y2);
206
207 if ( y1==0 || y2==0 )
208 cerr << "check these points very carefully : AddtoBand() : point " << i << endl;
209
210 Double_t eyh=0., eyl=0.;
211
212 y0 = y1-y2;
213 if (y0 != 0) {
214 if (y0 > 0) {
215 eyh = EYhigh[i];
216 eyh = sqrt(eyh*eyh+y0*y0);
217 g2->SetPointEYhigh(i, eyh);
218 } else {
219 eyl = EYlow[i];
220 eyl = sqrt(eyl*eyl+y0*y0);
221 g2->SetPointEYlow (i, eyl);
222 }
223 }
224 }
225}
#define e(i)
Definition RSha256.hxx:103
static const double x2[5]
static const double x1[5]
static const double x3[11]
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:404
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
The Canvas class.
Definition TCanvas.h:23
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:326
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4025
TGraph with asymmetric error bars.
virtual void SetPointEYlow(Int_t i, Double_t eyl)
Set EYlow for point i.
virtual void SetPointError(Double_t exl, Double_t exh, Double_t eyl, Double_t eyh)
Set ex and ey values for point pointed by the mouse.
virtual void SetPointEYhigh(Int_t i, Double_t eyh)
Set EYhigh for point i.
A TGraphErrors is a TGraph with error bars.
virtual void SetPointError(Double_t ex, Double_t ey)
Set ex and ey values for point pointed by the mouse.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2298
Int_t GetN() const
Definition TGraph.h:125
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition TGraph.cxx:769
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
Definition TGraph.cxx:1601
To draw Mathematical Formula.
Definition TLatex.h:18
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual Double_t Rndm()
Machine independent random number generator.
Definition TRandom.cxx:552
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:813
Double_t y[n]
Definition legend1.C:17
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Definition file.py:1
auto * l
Definition textangle.C:4