-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.C
232 lines (207 loc) · 6.36 KB
/
draw.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "TLine.h"
#include "TLatex.h"
#include "TGraphErrors.h"
#include "TGraphAsymmErrors.h"
#include "TBox.h"
#include "TArrow.h"
#include "iostream"
void drawHistBox(double x1=0., double x2=1., double y1=0., double y2=1., int lineWidth=3333, int lineStyle=1, int lineColor=1)
//void drawHistBox(double x1, double x2, double y1, double y2, int lineWidth)
{
TLine *l1 = new TLine(x1,y1,x2,y1);
l1->SetLineWidth(lineWidth/1000);
l1->SetLineStyle(lineStyle);
l1->SetLineColor(lineColor);
l1->Draw("same");
TLine *l2 = new TLine(x1,y2,x2,y2);
l2->SetLineWidth((lineWidth%1000)/100);
l2->SetLineStyle(lineStyle);
l2->SetLineColor(lineColor);
l2->Draw("same");
TLine *l3 = new TLine(x1,y1,x1,y2);
l3->SetLineWidth((lineWidth%100)/10);
l3->SetLineStyle(lineStyle);
l3->SetLineColor(lineColor);
l3->Draw("same");
TLine *l4 = new TLine(x2,y1,x2,y2);
l4->SetLineWidth(lineWidth%10);
l4->SetLineStyle(lineStyle);
l4->SetLineColor(lineColor);
l4->Draw("same");
}
void drawText(double x1=0., double y1=0., const char* text="test", int textFont=42, double textSize=0.05, double textAngle=0, int textColor=1)
//void drawText(double x1, double y1, const char* text, int textFont, double textSize, double textAngle)
{
TLatex *tex = new TLatex(x1, y1, text);
tex->SetTextFont(textFont);
tex->SetTextSize(textSize);
tex->SetTextAngle(textAngle);
tex->SetTextColor(textColor);
tex->Draw("same");
}
void drawLine(double x1=0., double y1=0., double x2=0., double y2=1., int lineWidth=1, int lineStyle=1, int lineColor=1)
//void drawLine(double x1, double y1, double x2, double y2, int lineWidth, int lineStyle, int lineColor)
{
TLine *la = new TLine(x1,y1,x2,y2);
la->SetLineWidth(lineWidth);
la->SetLineStyle(lineStyle);
la->SetLineColor(lineColor);
la->Draw("same");
}
void drawArrow(double x1=0., double y1=0., double x2=0., double y2=1., double arrowSize=0.05, double angle=45, int lineWidth=1, int lineStyle=1, int lineColor=1, char *option = "|>")
//void drawLine(double x1, double y1, double x2, double y2, int lineWidth, int lineStyle, int lineColor)
{
TArrow *la = new TArrow(x1,y1,x2,y2,arrowSize,option);
la->SetAngle(angle);
la->SetLineWidth(lineWidth);
la->SetLineStyle(lineStyle);
la->SetLineColor(lineColor);
la->Draw();
}
void drawSysError(TGraphErrors *gr, double xoffset=0.05, double yoffset=0.03, int lineColor=1, bool logx=0, bool logy=0)
{
if(!gr) {
std::cout << "No TGraphErrors, return!" << std::endl;
return;
}
for(int i=0;i<gr->GetN();i++) {
double x0 = gr->GetX()[i];
double y0 = gr->GetY()[i];
double ye = gr->GetEY()[i];
if(fabs(ye/y0)<1e-4) continue;
double x1 = x0-xoffset;
double x2 = x0+xoffset;
double y1 = y0-ye;
double y2 = y0+ye;
double y11 = y1+yoffset;
double y22 = y2-yoffset;
if(logx) {
x1 = x0*(1-xoffset);
x2 = x0*(1+xoffset);
}
if(logy) {
y11 = y1*(1+yoffset);
y22 = y2*(1-yoffset);
}
TLine *la = new TLine(x1,y1,x2,y1);
la->SetLineWidth(2);
la->SetLineColor(lineColor);
la->Draw("same");
TLine *la1 = new TLine(x1,y1,x1,y11);
la1->SetLineWidth(1);
la1->SetLineColor(lineColor);
la1->Draw("same");
TLine *la2 = new TLine(x2,y1,x2,y11);
la2->SetLineWidth(1);
la2->SetLineColor(lineColor);
la2->Draw("same");
TLine *lb = new TLine(x1,y2,x2,y2);
lb->SetLineWidth(2);
lb->SetLineColor(lineColor);
lb->Draw("same");
TLine *lb1 = new TLine(x1,y2,x1,y22);
lb1->SetLineWidth(1);
lb1->SetLineColor(lineColor);
lb1->Draw("same");
TLine *lb2 = new TLine(x2,y2,x2,y22);
lb2->SetLineWidth(1);
lb2->SetLineColor(lineColor);
lb2->Draw("same");
}
}
void drawSysBox(TGraphErrors *gr, double xoffset=0.05, int boxColor=1, bool logx=0)
{
if(!gr) {
std::cout << "No TGraphErrors, return!" << std::endl;
return;
}
for(int i=0;i<gr->GetN();i++) {
double x0 = gr->GetX()[i];
double y0 = gr->GetY()[i];
double ye = gr->GetEY()[i];
double x1 = x0-xoffset;
double x2 = x0+xoffset;
if(logx) {
x1 = x0*(1-xoffset);
x2 = x0*(1+xoffset);
}
TBox *box = new TBox(x1,y0-ye,x2,y0+ye);
box->SetFillColor(boxColor);
box->SetLineColor(boxColor);
box->Draw("same");
}
}
void drawSysBoxInRange(TGraphErrors *gr, double xoffset=0.05, int boxColor=1, bool logx=0, double ymin=-1e9, double ymax=1e9)
{
if(!gr) {
std::cout << "No TGraphErrors, return!" << std::endl;
return;
}
for(int i=0;i<gr->GetN();i++) {
double x0 = gr->GetX()[i];
double y0 = gr->GetY()[i];
double ye = gr->GetEY()[i];
double x1 = x0-xoffset;
double x2 = x0+xoffset;
if(logx) {
x1 = x0*(1-xoffset);
x2 = x0*(1+xoffset);
}
double ylow = y0-ye;
if(ylow<ymin) ylow = ymin;
double yup = y0+ye;
if(yup>ymax) yup = ymax;
TBox *box = new TBox(x1,ylow,x2,yup);
box->SetFillColor(boxColor);
box->SetLineColor(boxColor);
box->Draw("same");
}
}
void drawSysBox(TGraphAsymmErrors *gr, double xoffset=0.05, int boxColor=1, bool logx=0)
{
if(!gr) {
std::cout << "No TGraphErrors, return!" << std::endl;
return;
}
for(int i=0;i<gr->GetN();i++) {
double x0 = gr->GetX()[i];
double y0 = gr->GetY()[i];
double yel = gr->GetEYlow()[i];
double yeh = gr->GetEYhigh()[i];
double x1 = x0-xoffset;
double x2 = x0+xoffset;
if(logx) {
x1 = x0*(1-xoffset);
x2 = x0*(1+xoffset);
}
TBox *box = new TBox(x1,y0-yel,x2,y0+yeh);
box->SetFillColor(boxColor);
box->SetLineColor(boxColor);
box->Draw("same");
}
}
void drawColorBox(double x1, double y1, double x2, double y2, int fillColor=5, float alpha=0.5)
{
TBox *box = new TBox(x1,y1,x2,y2);
box->SetFillColorAlpha(fillColor, alpha);
box->SetLineColorAlpha(fillColor, alpha);
box->Draw("same");
}
void setGraphMarker(TGraphErrors *gr, int markerStyle=20, int markerColor=1, double markerSize=1.5)
{
gr->SetMarkerStyle(markerStyle);
gr->SetMarkerColor(markerColor);
gr->SetMarkerSize(markerSize);
}
void setGraphLine(TGraph *gr, int lineStyle=1, int lineColor=1, int lineWidth=2)
{
gr->SetLineStyle(lineStyle);
gr->SetLineColor(lineColor);
gr->SetLineWidth(lineWidth);
}
void setGraphFill(TGraphErrors *gr, int fillStyle=1, int fillColor=1, double fillAlpha=1)
{
gr->SetFillStyle(fillStyle);
gr->SetFillColorAlpha(fillColor, fillAlpha);
gr->SetMarkerSize();
}