File indexing completed on 2026-04-07 08:15:40
0001
0002 #include <Rtypes.h>
0003 #include <TGraphAsymmErrors.h>
0004 #include <TGraphErrors.h>
0005 #include <TH1.h>
0006 #include <TLatex.h>
0007 #include <TLine.h>
0008 #include <TMarker.h>
0009 #include <TPave.h>
0010
0011 #include <iostream>
0012 #include <format>
0013
0014 void ATLAS_LABEL(Double_t x,Double_t y,Color_t color)
0015 {
0016 TLatex l;
0017 l.SetNDC();
0018 l.SetTextFont(72);
0019 l.SetTextColor(color);
0020 l.DrawLatex(x,y,"ATLAS");
0021 }
0022
0023 TGraphErrors* myTGraphErrorsDivide(TGraphErrors* g1,TGraphErrors* g2) {
0024
0025 const Int_t debug=0;
0026
0027 if (!g1) std::cout << "**myTGraphErrorsDivide: g1 does not exist !" << std::endl;
0028 if (!g2) std::cout << "**myTGraphErrorsDivide: g2 does not exist !" << std::endl;
0029
0030
0031 Int_t n1=g1->GetN();
0032 Int_t n2=g2->GetN();
0033
0034 if (n1!=n2) {
0035 std::cout << "**myTGraphErrorsDivide: vector do not have same number of entries !" << std::endl;
0036 }
0037
0038 TGraphErrors* g3= new TGraphErrors();
0039
0040 Double_t x1=0.;
0041 Double_t y1=0.;
0042 Double_t x2=0.;
0043 Double_t y2=0.;
0044 Double_t dx1=0.;
0045 Double_t dy1=0.;
0046 Double_t dy2=0.;
0047
0048 Int_t iv=0;
0049 for (Int_t i1=0; i1<n1; i1++) {
0050 for (Int_t i2=0; i2<n2; i2++) {
0051
0052
0053 g1->GetPoint(i1,x1,y1);
0054 g2->GetPoint(i2,x2,y2);
0055 if (x1!=x2) {
0056
0057 }else{
0058
0059 dx1 = g1->GetErrorX(i1);
0060 if (y1!=0) dy1 = g1->GetErrorY(i1)/y1;
0061 if (y2!=0) dy2 = g2->GetErrorY(i2)/y2;
0062
0063 if (debug)
0064 std::cout << std::format("**myTGraphErrorsDivide: {} x1={} x2={} y1={} y2={}",iv,x1,x2,y1,y2) << std::endl;;
0065
0066 if (y2!=0.) g3->SetPoint(iv, x1,y1/y2);
0067 else g3->SetPoint(iv, x1,y2);
0068
0069 Double_t e=0.;
0070 if (y1!=0 && y2!=0) e=std::sqrt(dy1*dy1+dy2*dy2)*(y1/y2);
0071 g3->SetPointError(iv,dx1,e);
0072
0073
0074 if (debug) {
0075
0076
0077
0078
0079 }
0080 iv++;
0081 }
0082
0083 }
0084 }
0085 return g3;
0086
0087 }
0088
0089
0090 TGraphAsymmErrors* myTGraphErrorsDivide(TGraphAsymmErrors* g1,TGraphAsymmErrors* g2) {
0091
0092 const Int_t debug=1;
0093
0094 TGraphAsymmErrors* g3= new TGraphAsymmErrors();
0095 Int_t n1=g1->GetN();
0096 Int_t n2=g2->GetN();
0097
0098 if (n1!=n2) {
0099 std::cout << " vectors do not have same number of entries !" << std::endl;;
0100 return g3;
0101 }
0102
0103 Double_t x1=0.;
0104 Double_t y1=0.;
0105 Double_t x2=0.;
0106 Double_t y2=0.;
0107 Double_t dx1h=0.;
0108 Double_t dx1l=0.;
0109 Double_t dy1h=0.;
0110 Double_t dy1l=0.;
0111 Double_t dy2h=0.;
0112 Double_t dy2l=0.;
0113
0114
0115
0116 Double_t* EXhigh1 = g1->GetEXhigh();
0117 Double_t* EXlow1 = g1->GetEXlow();
0118 Double_t* EYhigh1 = g1->GetEYhigh();
0119 Double_t* EYlow1 = g1->GetEYlow();
0120
0121
0122
0123
0124
0125 Double_t* EYhigh2 = g2->GetEYhigh();
0126 Double_t* EYlow2 = g2->GetEYlow();
0127 for (Int_t i=0; i<g1->GetN(); i++) {
0128 g1->GetPoint(i,x1,y1);
0129 g2->GetPoint(i,x2,y2);
0130 dx1h = EXhigh1[i];
0131 dx1l = EXlow1[i];
0132 if (y1!=0.) dy1h = EYhigh1[i]/y1;
0133 else dy1h = 0.;
0134 if (y2!=0.) dy2h = EYhigh2[i]/y2;
0135 else dy2h = 0.;
0136 if (y1!=0.) dy1l = EYlow1 [i]/y1;
0137 else dy1l = 0.;
0138 if (y2!=0.) dy2l = EYlow2 [i]/y2;
0139 else dy2l = 0.;
0140
0141
0142
0143 if (debug)
0144 std::cout << std::format("{} dy1={} {} dy2={} {} sqrt= {} {}",i,dy1l,dy1h,dy2l,dy2h,
0145 std::sqrt(dy1l*dy1l+dy2l*dy2l), std::sqrt(dy1h*dy1h+dy2h*dy2h)) << std::endl;
0146
0147 if (y2!=0.) g3->SetPoint(i, x1,y1/y2);
0148 else g3->SetPoint(i, x1,y2);
0149 Double_t el=0.; Double_t eh=0.;
0150
0151 if (y1!=0. && y2!=0.) el=std::sqrt(dy1l*dy1l+dy2l*dy2l)*(y1/y2);
0152 if (y1!=0. && y2!=0.) eh=std::sqrt(dy1h*dy1h+dy2h*dy2h)*(y1/y2);
0153
0154 if (debug) std::cout << std::format("dx1h={} dx1l={} el={} eh={}",dx1h,dx1l,el,eh) << std::endl;
0155 g3->SetPointError(i,dx1l,dx1h,el,eh);
0156
0157 }
0158 return g3;
0159
0160 }
0161
0162
0163
0164 TGraphAsymmErrors* myMakeBand(TGraphErrors* g0, TGraphErrors* g1,TGraphErrors* g2) {
0165
0166
0167
0168 TGraphAsymmErrors* g3= new TGraphAsymmErrors();
0169
0170 Double_t x1=0.;
0171 Double_t y1=0.;
0172 Double_t x2=0.;
0173 Double_t y2=0.;
0174 Double_t y0=0;
0175 Double_t x3=0.;
0176
0177 Double_t dum;
0178 for (Int_t i=0; i<g1->GetN(); i++) {
0179 g0->GetPoint(i, x1,y0);
0180 g1->GetPoint(i, x1,y1);
0181 g2->GetPoint(i, x1,y2);
0182
0183
0184
0185
0186 if (i==g1->GetN()-1) x2=x1;
0187 else g2->GetPoint(i+1,x2,dum);
0188
0189 if (i==0) x3=x1;
0190 else g2->GetPoint(i-1,x3,dum);
0191
0192 Double_t tmp=y2;
0193 if (y1<y2) {y2=y1; y1=tmp;}
0194
0195 Double_t y3=y0;
0196 g3->SetPoint(i,x1,y3);
0197
0198 Double_t binwl=(x1-x3)/2.;
0199 Double_t binwh=(x2-x1)/2.;
0200 if (binwl==0.) binwl= binwh;
0201 if (binwh==0.) binwh= binwl;
0202 g3->SetPointError(i,binwl,binwh,(y3-y2),(y1-y3));
0203
0204 }
0205 return g3;
0206
0207 }
0208
0209 void myAddtoBand(TGraphErrors* g1, TGraphAsymmErrors* g2) {
0210
0211 Double_t x1=0.;
0212 Double_t y1=0.;
0213 Double_t y2=0.;
0214 Double_t y0=0;
0215
0216
0217
0218 if (g1->GetN()!=g2->GetN())
0219 std::cout << " graphs have not the same # of elements " << std::endl;
0220
0221 Double_t* EYhigh = g2-> GetEYhigh();
0222 Double_t* EYlow = g2-> GetEYlow();
0223
0224 for (Int_t i=0; i<g1->GetN(); i++) {
0225 g1->GetPoint(i, x1,y1);
0226 g2->GetPoint(i, x1,y2);
0227
0228 if ( y1==0 || y2==0 ) {
0229 std::cerr << "check these points very carefully : myAddtoBand() : point " << i << std::endl;
0230 }
0231
0232
0233
0234
0235
0236
0237
0238
0239 Double_t eyh=0.;
0240 Double_t eyl=0.;
0241
0242
0243
0244
0245
0246 y0=y1-y2;
0247 if (y0!=0) {
0248 if (y0>0){
0249 eyh=EYhigh[i];
0250 eyh=std::sqrt(eyh*eyh+y0*y0);
0251
0252 g2->SetPointEYhigh(i,eyh);
0253 } else {
0254 eyl=EYlow[i];
0255 eyl=std::sqrt(eyl*eyl+y0*y0);
0256
0257 g2->SetPointEYlow (i,eyl);
0258 }
0259 }
0260 }
0261 return;
0262
0263 }
0264
0265 TGraphErrors* TH1TOTGraph(TH1 *h1){
0266
0267
0268 if (!h1) std::cout << "TH1TOTGraph: histogram not found !" << std::endl;
0269
0270 TGraphErrors* g1= new TGraphErrors();
0271
0272 Double_t x;
0273 Double_t y;
0274 Double_t ex;
0275 Double_t ey;
0276 for (Int_t i=1 ; i<=h1->GetNbinsX(); i++) {
0277 y=h1->GetBinContent(i);
0278 ey=h1->GetBinError(i);
0279 x=h1->GetBinCenter(i);
0280 ex=h1->GetBinWidth(i)/2.;
0281
0282
0283
0284 g1->SetPoint(i-1,x,y);
0285 g1->SetPointError(i-1,ex,ey);
0286
0287 }
0288
0289
0290
0291 return g1;
0292 }
0293
0294 void myText(Double_t x,Double_t y,Color_t color, const char *text, Double_t tsize) {
0295
0296 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0297 l.SetNDC();
0298 l.SetTextColor(color);
0299 l.DrawLatex(x,y,text);
0300 }
0301
0302
0303 void myBoxText(Double_t x, Double_t y,Double_t boxsize,Int_t mcolor,Int_t bstyle,Int_t lcolor,Int_t lstyle, const char *text)
0304 {
0305
0306 Double_t tsize=0.04;
0307
0308 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0309 l.SetNDC();
0310 l.DrawLatex(x,y,text);
0311
0312 Double_t y1=y-0.25*tsize;
0313 Double_t y2=y+0.25*tsize;
0314 Double_t x2=x-0.3*tsize;
0315 Double_t x1=x2-boxsize;
0316
0317 std::cout << std::format("x1= {} x2= {} y1= {} y2= {}",x1,x2,y1,y2) << std::endl;
0318
0319 TPave *mbox= new TPave(x1,y1,x2,y2,0,"NDC");
0320
0321 mbox->SetFillColor(mcolor);
0322
0323 mbox->SetFillStyle(bstyle);
0324 mbox->Draw();
0325
0326 TLine mline;
0327 mline.SetLineWidth(2);
0328 mline.SetLineColor(lcolor);
0329 mline.SetLineStyle(lstyle);
0330
0331
0332
0333
0334
0335 mline.DrawLineNDC(x1,y1,x2,y1);
0336 mline.DrawLineNDC(x1,y2,x2,y2);
0337 mline.DrawLineNDC(x1,y1,x1,y2);
0338 mline.DrawLineNDC(x2,y1,x2,y2);
0339
0340 }
0341
0342
0343 void myMarkerText(Double_t x,Double_t y,Int_t color,Int_t mstyle, const char *text,Float_t msize, Double_t tsize)
0344 {
0345 TMarker *marker = new TMarker(x-(0.55*tsize),y,8);
0346 marker->SetMarkerColor(color); marker->SetNDC();
0347 marker->SetMarkerStyle(mstyle);
0348 marker->SetMarkerSize(msize);
0349 marker->Draw();
0350
0351 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0352 l.SetNDC();
0353 l.DrawLatex(x,y,text);
0354
0355 Double_t y1=y-0.5*tsize;
0356 Double_t y2=y+0.5*tsize;
0357 Double_t x2=x-0.15*tsize;
0358 Double_t x1=x-0.95*tsize;
0359
0360 TLine mline;
0361 mline.SetLineWidth(2);
0362 mline.SetLineColor(color);
0363 mline.SetLineStyle(1);
0364
0365 Double_t x_new=(x1+x2)/2.;
0366
0367 double size_y = 0.3*tsize;
0368
0369
0370
0371
0372 mline.DrawLineNDC(x_new,y2-size_y,x_new,y2);
0373 mline.DrawLineNDC(x_new,y1,x_new,y1+size_y);
0374 }
0375
0376 void myMarkerLineText(Double_t x, Double_t y,Float_t msize,Int_t mcolor,Int_t mstyle,Int_t lcolor,Int_t lstyle, const char *text, Double_t tsize, bool EX0)
0377 {
0378
0379 TMarker *marker = new TMarker(x-(0.55*tsize),y,8);
0380 marker->SetMarkerColor(mcolor); marker->SetNDC();
0381 marker->SetMarkerStyle(mstyle);
0382 marker->SetMarkerSize(msize);
0383
0384 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0385 l.SetNDC();
0386 l.DrawLatex(x,y,text);
0387
0388 Double_t y1=y-0.5*tsize;
0389 Double_t y2=y+0.5*tsize;
0390 Double_t x2=x-0.15*tsize;
0391 Double_t x1=x-0.95*tsize;
0392
0393 TLine mline;
0394 mline.SetLineWidth(2);
0395 mline.SetLineColor(lcolor);
0396 mline.SetLineStyle(lstyle);
0397 Double_t y_new=(y1+y2)/2.;
0398 Double_t x_new=(x1+x2)/2.;
0399
0400 double size_y = 0.3*tsize;
0401 double size_x = 0.28*tsize;
0402
0403 if (msize!=0) {
0404 if (!EX0) {
0405 mline.DrawLineNDC(x1, y_new,x1+size_x,y_new);
0406 mline.DrawLineNDC(x2-size_x,y_new,x2, y_new);
0407 }
0408 mline.DrawLineNDC(x_new,y2-size_y,x_new,y2);
0409 mline.DrawLineNDC(x_new,y1,x_new,y1+size_y);
0410 } else {
0411 mline.DrawLineNDC(x-0.95*tsize,y_new,x-0.15*tsize,y_new);
0412 }
0413 marker->Draw();
0414
0415 }
0416
0417
0418
0419 void mySmallMarkerLineText(Double_t x, Double_t y,Float_t msize,Int_t mcolor,Int_t mstyle,Int_t lcolor,Int_t lstyle, const char *text)
0420 {
0421 Double_t tsize=0.03;
0422 TMarker *marker = new TMarker(x-(0.55*tsize),y,8);
0423 marker->SetMarkerColor(mcolor); marker->SetNDC();
0424 marker->SetMarkerStyle(mstyle);
0425 marker->SetMarkerSize(msize);
0426
0427
0428 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0429 l.SetNDC();
0430 l.DrawLatex(x,y,text);
0431
0432 Double_t y1=y-0.5*tsize;
0433 Double_t y2=y+0.5*tsize;
0434 Double_t x2=x-0.15*tsize;
0435 Double_t x1=x-0.95*tsize;
0436
0437 TLine mline;
0438 mline.SetLineWidth(2);
0439 mline.SetLineColor(lcolor);
0440 mline.SetLineStyle(lstyle);
0441 Double_t y_new=(y1+y2)/2.;
0442 Double_t x_new=(x1+x2)/2.;
0443 double size_y = 0.22*tsize;
0444 double size_x = 0.22*tsize;
0445 if (msize!=0) {
0446 mline.DrawLineNDC(x1,y_new,x1+size_x,y_new);
0447 mline.DrawLineNDC(x2-size_x,y_new,x2,y_new);
0448 mline.DrawLineNDC(x_new,y2-size_y,x_new,y2);
0449 mline.DrawLineNDC(x_new,y1,x_new,y1+size_y);
0450 } else {
0451 mline.DrawLineNDC(x-0.95*tsize,y_new,x-0.15*tsize,y_new);
0452 }
0453 marker->Draw();
0454 }
0455
0456
0457
0458 void myOnlyBoxText(Double_t x, Double_t y,Double_t ,Int_t mcolor,Int_t lcolor,Int_t lstyle, const char *text, Double_t tsize, Int_t bstyle)
0459 {
0460
0461
0462 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0463 l.SetNDC();
0464 l.DrawLatex(x,y,text);
0465
0466 Double_t y1=y-0.25*tsize;
0467 Double_t y2=y+0.25*tsize;
0468 Double_t x2=x-0.15*tsize;
0469 Double_t x1=x-0.95*tsize;
0470
0471 std::cout << std::format("x1= {} x2= {} y1= {} y2= {}",x1,x2,y1,y2) << std::endl;
0472
0473 TPave *mbox= new TPave(x1,y1,x2,y2,0,"NDC");
0474
0475 mbox->SetFillColor(mcolor);
0476 mbox->SetFillStyle(bstyle);
0477 mbox->Draw();
0478
0479 TLine mline;
0480 mline.SetLineWidth(1);
0481 mline.SetLineColor(lcolor);
0482
0483 mline.SetLineStyle(lstyle);
0484
0485
0486 mline.DrawLineNDC(x1,y1,x2,y1);
0487 mline.DrawLineNDC(x1,y2,x2,y2);
0488 mline.DrawLineNDC(x1,y1,x1,y2);
0489 mline.DrawLineNDC(x2,y1,x2,y2);
0490
0491 }
0492
0493 void mySmallBoxText(Double_t x, Double_t y,Double_t boxsize,Int_t mcolor,Int_t lcolor,Int_t lstyle, const char *text)
0494 {
0495
0496 Double_t tsize=0.03;
0497
0498 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0499 l.SetNDC();
0500 l.DrawLatex(x,y,text);
0501
0502 Double_t y1=y-0.25*tsize;
0503 Double_t y2=y+0.25*tsize;
0504 Double_t x2=x-0.3*tsize;
0505 Double_t x1=x2-boxsize;
0506
0507 std::cout << std::format("x1= {} x2= {} y1= {} y2= {}",x1,x2,y1,y2) << std::endl;
0508
0509 TPave *mbox= new TPave(x1,y1,x2,y2,0,"NDC");
0510
0511 mbox->SetFillColor(mcolor);
0512 mbox->SetFillStyle(3015);
0513 mbox->Draw();
0514
0515 TLine mline;
0516 mline.SetLineWidth(2);
0517 mline.SetLineColor(lcolor);
0518 mline.SetLineStyle(lstyle);
0519
0520 mline.DrawLineNDC(x1,y1,x2,y1);
0521 mline.DrawLineNDC(x1,y2,x2,y2);
0522 mline.DrawLineNDC(x1,y1,x1,y2);
0523 mline.DrawLineNDC(x2,y1,x2,y2);
0524
0525 }
0526
0527
0528 void myBoxTextAlpha(Double_t x, Double_t y,Double_t boxsize,Int_t mcolor, Double_t falpha,Int_t lcolor,Int_t lstyle, const char *text)
0529 {
0530
0531 Double_t tsize=0.04;
0532
0533 TLatex l; l.SetTextAlign(12); l.SetTextSize(tsize);
0534 l.SetNDC();
0535 l.DrawLatex(x,y,text);
0536
0537 Double_t y1=y-0.25*tsize;
0538 Double_t y2=y+0.25*tsize;
0539 Double_t x2=x-0.3*tsize;
0540 Double_t x1=x2-boxsize;
0541
0542 std::cout << std::format("x1= {} x2= {} y1= {} y2= {}",x1,x2,y1,y2) << std::endl;
0543
0544 TPave *mbox= new TPave(x1,y1,x2,y2,0,"NDC");
0545
0546 mbox->SetFillColorAlpha(mcolor,falpha);
0547
0548
0549 mbox->Draw();
0550
0551 TLine mline;
0552 mline.SetLineWidth(2);
0553 mline.SetLineColor(lcolor);
0554 mline.SetLineStyle(lstyle);
0555
0556
0557
0558
0559
0560 mline.DrawLineNDC(x1,y1,x2,y1);
0561 mline.DrawLineNDC(x1,y2,x2,y2);
0562 mline.DrawLineNDC(x1,y1,x1,y2);
0563 mline.DrawLineNDC(x2,y1,x2,y2);
0564
0565 }