Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
AtlasExample.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook -js
4/// \preview
5/// Show how ATLAS Style looks like. It is based on a style file from BaBar.
6///
7/// \macro_image
8/// \macro_code
9///
10/// \author M.Sutton
11
12const Int_t GMAX = 864;
13
14const int nren = 3;
15static const double mur[nren] = {1.0, 0.25, 4.0};
16static const double muf[nren] = {1.0, 0.25, 4.0};
17const unsigned int NUMPDF = 41;
18
19TGraphErrors *GetGraph(Int_t ir, Int_t ifs, Int_t icut, Int_t ipdf);
20void AddtoBand(TGraphErrors *g1, TGraphAsymmErrors *g2);
22
23void AtlasExample()
24{
25 gROOT->SetStyle("ATLAS");
26
27 Int_t icol1 = 5;
28 Int_t icol2 = 5;
29
30 auto canvas = new TCanvas("canvas", "single inclusive jets", 50, 50, 600, 600);
31 canvas->SetLogy();
32
33 Double_t ymin = 1.e-3;
34 Double_t ymax = 2e7;
35 Double_t xmin = 60.00;
36 Double_t xmax = 3500.;
37 auto frame = canvas->DrawFrame(xmin, ymin, xmax, ymax);
38 frame->SetYTitle("d#sigma_{jet}/dE_{T,jet} [fb/GeV]");
39 frame->SetXTitle("E_{T,jet} [GeV]");
40 frame->GetYaxis()->SetTitleOffset(1.4);
41 frame->GetXaxis()->SetTitleOffset(1.4);
42
43 const Int_t ncut = 1;
44 TGraphErrors *data[ncut];
45
46 for (Int_t icut = 0; icut < ncut; icut++) { // loop over cuts
47 TGraphErrors *g1[nren][ncut];
48 for (Int_t ir = 0; ir < nren; ir++) { // loop over ren scale
49 g1[ir][icut] = GetGraph(ir, ir, icut, 0);
50 if (!g1[ir][icut]) {
51 cout << " g1 not found " << endl;
52 return;
53 }
54 g1[ir][icut]->SetLineColor(1);
55 g1[ir][icut]->SetMarkerStyle(0);
56 }
57
58 char daname[100];
59 sprintf(daname, "data_%d", icut);
60 data[icut] = (TGraphErrors *)g1[0][icut]->Clone(daname);
61 data[icut]->SetMarkerStyle(20);
62 data[icut]->SetMarkerColor(1);
63
64 // Just invent some data
65 for (Int_t i = 0; i < data[icut]->GetN(); i++) {
66 Double_t x1, y1, e, dx1 = 0.;
67 data[icut]->GetPoint(i, x1, y1);
68 Double_t r1 = 0.4 * (gRandom->Rndm(1) + 2);
69 Double_t r2 = 0.4 * (gRandom->Rndm(1) + 2);
70 Double_t y;
71 if (icut == 0)
72 y = r1 * y1 + r1 * r2 * r2 * x1 / 50000.;
73 else
74 y = r1 * y1;
75 e = sqrt(y * 1000) / 200;
76 data[icut]->SetPoint(i, x1, y);
77 data[icut]->SetPointError(i, dx1, e);
78 }
79
80 TGraphAsymmErrors *scale[ncut];
81 TGraphAsymmErrors *scalepdf[ncut];
82
83 scale[icut] = MakeBand(g1[0][icut], g1[1][icut], g1[2][icut]);
84 scalepdf[icut] = (TGraphAsymmErrors *)scale[icut]->Clone("scalepdf");
85
86 TGraphErrors *gpdf[NUMPDF][ncut];
87 for (Int_t ipdf = 0; ipdf < NUMPDF; ipdf++) {
88 gpdf[ipdf][icut] = GetGraph(0, 0, icut, ipdf);
89 if (!gpdf[ipdf][icut]) {
90 cout << " gpdf not found " << endl;
91 return;
92 }
93 gpdf[ipdf][icut]->SetLineColor(2);
94 gpdf[ipdf][icut]->SetLineStyle(kSolid);
95 gpdf[ipdf][icut]->SetMarkerStyle(0);
96 AddtoBand(gpdf[ipdf][icut], scalepdf[icut]);
97 }
98
99 scalepdf[icut]->SetFillColor(icol2);
100 scalepdf[icut]->Draw("zE2");
101 scalepdf[icut]->SetLineWidth(3);
102 scale[icut]->SetFillColor(icol1);
103 scale[icut]->Draw("zE2");
104 g1[0][icut]->SetLineWidth(3);
105 g1[0][icut]->Draw("z");
106 data[icut]->Draw("P");
107 }
108
109 TLatex t;
110 t.SetNDC();
111 t.DrawLatex(0.3, 0.85, "#sqrt{s}= 14 TeV");
112 t.DrawLatex(0.57, 0.85, "|#eta_{jet}|<0.5");
113
114 auto l = new TLegend(0.45, 0.65, 0.8, 0.8, "", "NDC");
115 l->SetBorderSize(0.);
116 l->SetTextFont(42);
117 l->AddEntry("data_0", "Data 2009", "ep");
118 l->AddEntry("scalepdf", "NLO QCD", "lf");
119 l->Draw();
120}
121
122TGraphErrors *GetGraph(Int_t ir, Int_t ifs, Int_t icut, Int_t ipdf)
123{
124 const char *cuts[5] = {"0.0 <= |eta| < 0.5", "0.5 <= |eta| < 1.0", "1.0 <= |eta| < 1.5", "1.5 <= |eta| < 2.0",
125 "2.0 <= |eta| < 3.0"};
126
127 const double mur[] = {1.0, 0.25, 4.0};
128 const double muf[] = {1.0, 0.25, 4.0};
129
131 TFile *file = TFile::Open("http://root.cern/files/AtlasGraphs.root", "CACHEREAD");
132
133 char gname[100];
134 char tname[100];
135
136 if (ipdf >= 0)
137 sprintf(tname, " E_T (mu_r=%g, mu_f=%g);%s Pdf: %d", mur[ir], muf[ifs], cuts[icut], ipdf);
138 else
139 sprintf(tname, " E_T %s Ms= %d", cuts[icut], -ipdf);
140
141 TGraphErrors *g1 = 0;
142
143 for (int i = 1; i <= GMAX; i++) {
144 sprintf(gname, "full_%d", i);
145 g1 = (TGraphErrors *)file->Get(gname);
146 if (!g1) {
147 cout << gname << " not found " << endl;
148 return nullptr;
149 }
150
151 const char *title = g1->GetTitle();
152
153 if (strcmp(title, tname) == 0)
154 break;
155 g1 = 0;
156 }
157
158 if (!g1)
159 return nullptr;
160 return g1;
161}
162
164{
165
167
168 Double_t x1 = 0., y1 = 0., x2 = 0., y2 = 0., y0 = 0, x3 = 0.;
169 Double_t dum;
170 for (Int_t i = 0; i < g1->GetN(); i++) {
171 g0->GetPoint(i, x1, y0);
172 g1->GetPoint(i, x1, y1);
173 g2->GetPoint(i, x1, y2);
174
175 if (i == g1->GetN() - 1)
176 x2 = x1;
177 else
178 g2->GetPoint(i + 1, x2, dum);
179
180 if (i == 0)
181 x3 = x1;
182 else
183 g2->GetPoint(i - 1, x3, dum);
184
185 Double_t tmp = y2;
186 if (y1 < y2) {
187 y2 = y1;
188 y1 = tmp;
189 }
190 g3->SetPoint(i, x1, y0);
191
192 Double_t binwl = (x1 - x3) / 2.;
193 Double_t binwh = (x2 - x1) / 2.;
194 if (binwl == 0.)
195 binwl = binwh;
196 if (binwh == 0.)
197 binwh = binwl;
198 g3->SetPointError(i, binwl, binwh, y0 - y2, y1 - y0);
199 }
200 return g3;
201}
202
203void AddtoBand(TGraphErrors *g1, TGraphAsymmErrors *g2)
204{
205
206 Double_t x1 = 0., y1 = 0., y2 = 0., y0 = 0;
207
208 if (g1->GetN() != g2->GetN())
209 cout << " graphs don't have the same number of elements " << endl;
210
211 Double_t *EYhigh = g2->GetEYhigh();
212 Double_t *EYlow = g2->GetEYlow();
213
214 for (Int_t i = 0; i < g1->GetN(); i++) {
215 g1->GetPoint(i, x1, y1);
216 g2->GetPoint(i, x1, y2);
217
218 if (y1 == 0 || y2 == 0)
219 cerr << "check these points very carefully : AddtoBand() : point " << i << endl;
220
221 Double_t eyh = 0., eyl = 0.;
222
223 y0 = y1 - y2;
224 if (y0 != 0) {
225 if (y0 > 0) {
226 eyh = EYhigh[i];
227 eyh = sqrt(eyh * eyh + y0 * y0);
228 g2->SetPointEYhigh(i, eyh);
229 } else {
230 eyl = EYlow[i];
231 eyl = sqrt(eyl * eyl + y0 * y0);
232 g2->SetPointEYlow(i, eyl);
233 }
234 }
235 }
236}
#define e(i)
Definition RSha256.hxx:103
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kSolid
Definition TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
float xmin
float ymin
float xmax
float ymax
#define gROOT
Definition TROOT.h:406
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 SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
The Canvas class.
Definition TCanvas.h:23
TObject * Get(const char *namecycle) override
Return pointer to object identified by namecycle.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
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:4086
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4623
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.
Double_t * GetEYhigh() const override
Double_t * GetEYlow() const override
A TGraphErrors is a TGraph with error bars.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2347
Int_t GetN() const
Definition TGraph.h:132
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:833
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:1535
To draw Mathematical Formula.
Definition TLatex.h:18
TLatex * DrawLatex(Double_t x, Double_t y, const char *text)
Make a copy of this object with the new parameters And copy object attributes.
Definition TLatex.cxx:1943
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:292
Double_t Rndm() override
Machine independent random number generator.
Definition TRandom.cxx:559
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Definition TText.cxx:823
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)
TLine l
Definition textangle.C:4