ATLAS Offline Software
Loading...
Searching...
No Matches
AtlasUtils.h File Reference
#include <stdio.h>
#include <cmath>
#include <iostream>
#include "TLatex.h"
#include "TGraphErrors.h"
#include "TMarker.h"
#include "TPave.h"
#include "TGraphAsymmErrors.h"
#include "TH1.h"
#include "TLine.h"

Go to the source code of this file.

Functions

void ATLAS_LABEL (Double_t x, Double_t y, Color_t color=1)
TGraphErrors * myTGraphErrorsDivide (TGraphErrors *g1, TGraphErrors *g2)
TGraphAsymmErrors * myTGraphErrorsDivide (TGraphAsymmErrors *g1, TGraphAsymmErrors *g2)
TGraphAsymmErrors * myMakeBand (TGraphErrors *g0, TGraphErrors *g1, TGraphErrors *g2)
void myAddtoBand (TGraphErrors *g1, TGraphAsymmErrors *g2)
TGraphErrors * TH1TOTGraph (TH1 *h1)
void myText (Double_t x, Double_t y, Color_t color, char *text)
void myBoxText (Double_t x, Double_t y, Double_t boxsize, Int_t mcolor, char *text)
void myMarkerText (Double_t x, Double_t y, Int_t color, Int_t mstyle, char *text)

Detailed Description

Author
mark sutton
Date
Fri 11 Jan 2019 07:06:38 CET

Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

Definition in file AtlasUtils.h.

Function Documentation

◆ ATLAS_LABEL()

void ATLAS_LABEL ( Double_t x,
Double_t y,
Color_t color = 1 )
inline

Definition at line 29 of file AtlasUtils.h.

30{
31 TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize);
32 l.SetNDC();
33 l.SetTextFont(72);
34 l.SetTextColor(color);
35 l.DrawLatex(x,y,"ATLAS");
36}
#define y
#define x
l
Printing final latex table to .tex output file.

◆ myAddtoBand()

void myAddtoBand ( TGraphErrors * g1,
TGraphAsymmErrors * g2 )
inline

Definition at line 211 of file AtlasUtils.h.

211 {
212
213 Double_t x1=0., y1=0., y2=0., y0=0;
214 //Double_t dx1=0.;
215 //Double_t dum;
216
217 if (g1->GetN()!=g2->GetN())
218 std::cout << " graphs have not the same # of elements " << std::endl;
219
220 Double_t* EYhigh = g2-> GetEYhigh();
221 Double_t* EYlow = g2-> GetEYlow();
222
223 for (Int_t i=0; i<g1->GetN(); i++) {
224 g1->GetPoint(i, x1,y1);
225 g2->GetPoint(i, x1,y2);
226
227 if (y1==0) y1=1;
228 if (y2==0) y2=1;
229
230 // if (i==g1->GetN()-1) x2=x1;
231 // else g2->GetPoint(i+1,x2,dum);
232 // if (i==0) x3=x1;
233 // else g2->GetPoint(i-1,x3,dum);
234
235 Double_t eyh=0., eyl=0.;
236 //if (y1<y2) {y2=y1; y1=tmp;}
237 //Double_t y3=1.;
238
239 //printf("%d: y1=%f y2=%f Eyhigh= %f Eylow= %f \n",i,y1,y2,EYhigh[i],EYlow[i]);
240
241 y0=y1-y2;
242 if (y0!=0) {
243 if (y0>0){
244 eyh=EYhigh[i];
245 eyh=sqrt(eyh*eyh+y0*y0);
246 //printf("high: %d: y0=%f eyh=%f \n",i,y0,eyh);
247 g2->SetPointEYhigh(i,eyh);
248 } else {
249 eyl=EYlow[i];
250 eyl=sqrt(eyl*eyl+y0*y0);
251 // printf("low: %d: y0=%f eyl=%f \n",i,y0,eyl);
252 g2->SetPointEYlow (i,eyl);
253 }
254 }
255 }
256 return;
257
258}

◆ myBoxText()

void myBoxText ( Double_t x,
Double_t y,
Double_t boxsize,
Int_t mcolor,
char * text )
inline

Definition at line 301 of file AtlasUtils.h.

301 {
302
303 Double_t tsize=0.06;
304
305 TLatex l; l.SetTextAlign(12); //l.SetTextSize(tsize);
306 l.SetNDC();
307 l.DrawLatex(x,y,text);
308
309 Double_t y1=y-0.25*tsize;
310 Double_t y2=y+0.25*tsize;
311 Double_t x2=x-0.3*tsize;
312 Double_t x1=x2-boxsize;
313
314 printf("x1= %f x2= %f y1= %f y2= %f \n",x1,x2,y1,y2);
315
316 TPave *mbox= new TPave(x1,y1,x2,y2,0,"NDC");
317
318 mbox->SetFillColor(mcolor);
319 mbox->SetFillStyle(1001);
320 mbox->Draw();
321
322 TLine mline;
323 mline.SetLineWidth(4);
324 mline.SetLineColor(1);
325 mline.SetLineStyle(1);
326 Double_t ytmp=(y1+y2)/2.;
327 mline.DrawLineNDC(x1,ytmp,x2,y);
328
329}

◆ myMakeBand()

TGraphAsymmErrors * myMakeBand ( TGraphErrors * g0,
TGraphErrors * g1,
TGraphErrors * g2 )
inline

Definition at line 169 of file AtlasUtils.h.

169 {
170 // default is g0
171 //const Int_t debug=0;
172
173 TGraphAsymmErrors* g3= new TGraphAsymmErrors();
174
175 Double_t x1=0., y1=0., x2=0., y2=0., y0=0, x3=0.;
176 //Double_t dx1=0.;
177 Double_t dum;
178 for (Int_t i=0; i<g1->GetN(); i++) {
179 g0->GetPoint(i, x1,y0);
180 g1->GetPoint(i, x1,y1);
181 g2->GetPoint(i, x1,y2);
182
183 // if (y1==0) y1=1;
184 //if (y2==0) y2=1;
185
186 if (i==g1->GetN()-1) x2=x1;
187 else g2->GetPoint(i+1,x2,dum);
188
189 if (i==0) x3=x1;
190 else g2->GetPoint(i-1,x3,dum);
191
192 Double_t tmp=y2;
193 if (y1<y2) {y2=y1; y1=tmp;}
194 //Double_t y3=1.;
195 Double_t y3=y0;
196 g3->SetPoint(i,x1,y3);
197
198 Double_t binwl=(x1-x3)/2.;
199 Double_t binwh=(x2-x1)/2.;
200 if (binwl==0.) binwl= binwh;
201 if (binwh==0.) binwh= binwl;
202 g3->SetPointError(i,binwl,binwh,(y3-y2),(y1-y3));
203
204 }
205 return g3;
206
207}

◆ myMarkerText()

void myMarkerText ( Double_t x,
Double_t y,
Int_t color,
Int_t mstyle,
char * text )
inline

Definition at line 332 of file AtlasUtils.h.

332 {
333
334 // printf("**myMarker: text= %s\ m ",text);
335
336 Double_t tsize=0.06;
337 TMarker *marker = new TMarker(x-(0.4*tsize),y,8);
338 marker->SetMarkerColor(color); marker->SetNDC();
339 marker->SetMarkerStyle(mstyle);
340 marker->SetMarkerSize(2.0);
341 marker->Draw();
342
343 TLatex l; l.SetTextAlign(12); //l.SetTextSize(tsize);
344 l.SetNDC();
345 l.DrawLatex(x,y,text);
346}

◆ myText()

void myText ( Double_t x,
Double_t y,
Color_t color,
char * text )
inline

Definition at line 291 of file AtlasUtils.h.

291 {
292
293 //Double_t tsize=0.05;
294 TLatex l; //l.SetTextAlign(12); l.SetTextSize(tsize);
295 l.SetNDC();
296 l.SetTextColor(color);
297 l.DrawLatex(x,y,text);
298}

◆ myTGraphErrorsDivide() [1/2]

TGraphAsymmErrors * myTGraphErrorsDivide ( TGraphAsymmErrors * g1,
TGraphAsymmErrors * g2 )
inline

Definition at line 100 of file AtlasUtils.h.

100 {
101
102 const Int_t debug=0;
103
104 TGraphAsymmErrors* g3= new TGraphAsymmErrors();
105 Int_t n1=g1->GetN();
106 Int_t n2=g2->GetN();
107
108 if (n1!=n2) {
109 printf(" vectors do not have same number of entries ! \n");
110 return g3;
111 }
112
113 Double_t x1=0., y1=0., x2=0., y2=0.;
114 Double_t dx1h=0., dx1l=0.;
115 Double_t dy1h=0., dy1l=0.;
116 Double_t dy2h=0., dy2l=0.;
117
118 Double_t* X1 = g1->GetX();
119 Double_t* Y1 = g1->GetY();
120 Double_t* EXhigh1 = g1->GetEXhigh();
121 Double_t* EXlow1 = g1->GetEXlow();
122 Double_t* EYhigh1 = g1->GetEYhigh();
123 Double_t* EYlow1 = g1->GetEYlow();
124
125 Double_t* X2 = g2->GetX();
126 Double_t* Y2 = g2->GetY();
127 Double_t* EXhigh2 = g2->GetEXhigh();
128 Double_t* EXlow2 = g2->GetEXlow();
129 Double_t* EYhigh2 = g2->GetEYhigh();
130 Double_t* EYlow2 = g2->GetEYlow();
131
132 for (Int_t i=0; i<g1->GetN(); i++) {
133 g1->GetPoint(i,x1,y1);
134 g2->GetPoint(i,x2,y2);
135 dx1h = EXhigh1[i];
136 dx1l = EXlow1[i];
137 if (y1!=0.) dy1h = EYhigh1[i]/y1;
138 else dy1h = 0.;
139 if (y2!=0.) dy2h = EYhigh2[i]/y2;
140 else dy2h = 0.;
141 if (y1!=0.) dy1l = EYlow1 [i]/y1;
142 else dy1l = 0.;
143 if (y2!=0.) dy2l = EYlow2 [i]/y2;
144 else dy2l = 0.;
145
146 //if (debug)
147 //printf("%d x1=%f x2=%f y1=%f y2=%f \n",i,x1,x2,y1,y2);
148 if (debug)
149 printf("%d dy1=%f %f dy2=%f %f sqrt= %f %f \n",i,dy1l,dy1h,dy2l,dy2h,
150 sqrt(dy1l*dy1l+dy2l*dy2l),sqrt(dy1h*dy1h+dy2h*dy2h));
151
152 if (y2!=0.) g3->SetPoint(i, x1,y1/y2);
153 else g3->SetPoint(i, x1,y2);
154 Double_t el=0.; Double_t eh=0.;
155
156 if (y1!=0. && y2!=0.) el=sqrt(dy1l*dy1l+dy2l*dy2l)*(y1/y2);
157 if (y1!=0. && y2!=0.) eh=sqrt(dy1h*dy1h+dy2h*dy2h)*(y1/y2);
158
159 if (debug) printf("dx1h=%f dx1l=%f el=%f eh=%f \n",dx1h,dx1l,el,eh);
160 g3->SetPointError(i,dx1h,dx1l,el,eh);
161
162 }
163 return g3;
164
165}
const bool debug

◆ myTGraphErrorsDivide() [2/2]

TGraphErrors * myTGraphErrorsDivide ( TGraphErrors * g1,
TGraphErrors * g2 )
inline

Definition at line 38 of file AtlasUtils.h.

38 {
39
40 const Int_t debug=0;
41
42 if (!g1) printf("**myTGraphErrorsDivide: g1 does not exist ! \n");
43 if (!g2) printf("**myTGraphErrorsDivide: g2 does not exist ! \n");
44
45
46 Int_t n1=g1->GetN();
47 Int_t n2=g2->GetN();
48
49 if (n1!=n2) {
50 printf("**myTGraphErrorsDivide: vector do not have same number of entries ! \n");
51 }
52
53 TGraphErrors* g3= new TGraphErrors();
54
55 Double_t x1=0., y1=0., x2=0., y2=0.;
56 Double_t dx1=0.,dy1=0., dy2=0.;
57
58 Int_t iv=0;
59 for (Int_t i1=0; i1<n1; i1++) {
60 for (Int_t i2=0; i2<n2; i2++) {
61 //if (debug) printf("**myTGraphErrorsDivide: %d %d ! \n",i1,i2);
62
63 g1->GetPoint(i1,x1,y1);
64 g2->GetPoint(i2,x2,y2);
65 if (x1!=x2) {
66 //printf("**myTGraphErrorsDivide: %d x1!=x2 %f %f ! \n",iv,x1,x2);
67 }else{
68 //if (debug) printf("**myTGraphErrorsDivide: %d x1=x2 %f %f ! \n",iv,x1,x2);
69 dx1 = g1->GetErrorX(i1);
70 if (y1!=0) dy1 = g1->GetErrorY(i1)/y1;
71 if (y2!=0) dy2 = g2->GetErrorY(i2)/y2;
72
73 if (debug)
74 printf("**myTGraphErrorsDivide: %d x1=%f x2=%f y1=%f y2=%f \n",iv,x1,x2,y1,y2);
75
76 if (y2!=0.) g3->SetPoint(iv, x1,y1/y2);
77 else g3->SetPoint(iv, x1,y2);
78
79 Double_t e=0.;
80 if (y1!=0 && y2!=0) e=std::sqrt(dy1*dy1+dy2*dy2)*(y1/y2);
81 g3->SetPointError(iv,dx1,e);
82
83
84 if (debug) {
85 //Double_t g3y, g3x,g3e;
86 //g3->GetPoint(iv, g3y,g3x);
87 //g3e=g3->GetErrorY(iv);
88 //printf("%d g3y= %f g3e=%f \n",iv,g3y,g3e);
89 }
90 iv++;
91 }
92 // printf("**myTGraphErrorsDivide: ...next \n");
93 }
94 }
95 return g3;
96
97}

◆ TH1TOTGraph()

TGraphErrors * TH1TOTGraph ( TH1 * h1)
inline

Definition at line 262 of file AtlasUtils.h.

262 {
263
264
265 if (!h1) std::cout << "TH1TOTGraph: histogram not found !" << std::endl;
266
267 TGraphErrors* g1= new TGraphErrors();
268
269 Double_t x, y, ex, ey;
270 for (Int_t i=0; i<h1->GetNbinsX(); i++) {
271 y=h1->GetBinContent(i);
272 ey=h1->GetBinError(i);
273 x=h1->GetBinCenter(i);
274 ex=h1->GetBinWidth(i);
275
276 // cout << " x,y = " << x << " " << y << " ex,ey = " << ex << " " << ey << endl;
277
278 g1->SetPoint(i,x,y);
279 g1->SetPointError(i,ex,ey);
280
281 }
282
283 //g1->Print();
284
285 return g1;
286}