Draw lines and color background

Hello, I wrote this macro starting from an old macro that I wrote with @couet 's help
I should get something like this

i.e. the green and orange box, and the red horizontal and vertical lines but, as you see, in the following plot, I don’t get them

histodrawbgk.cpp (2.4 KB)
Histo.root (10.4 KB)

Thank you

I did not look at your macro but, from the plots you posted, I see that the axis coordinates are very different in the new plot. Are you sure the boxes and lines drawn in your macro have the correct coordinates in the new axis system?

Hi @cout yes, the axes range are different because they are not same data (!
And yes, I changed the coordinates of lines and boxes in the macro

int x1=1660;
int x2=1720;
double tmin=1660;
double tpeakmin=1684;
double tpeakmax=1686;
double tmax=1720;
 auto b1 = new TBox(x1,0,x2,30);
        b1->SetFillColorAlpha(kGreen-4,0.5);
        b1->Draw();
        auto b2 = new TBox(tpeakmin,0,tpeakmax,30);
        b2->SetFillColorAlpha(kOrange,0.5);
        b2->Draw();
        auto lh = new TLine(tpeakmin,30,tpeakmax,30);
        lh->SetLineColor(kRed);
        lh->SetLineWidth(3.);
        lh->Draw();
        auto lv1 = new TLine(tpeakmin,1,tpeakmin,200000);
        lv1->SetLineColor(kRed);
        lv1->SetLineWidth(3.);
        lv1->Draw();
        auto lv2 = new TLine(tpeakmax,1,tpeakmax,200000);
        lv2->SetLineColor(kRed);
        lv2->SetLineWidth(3.);
        lv2->Draw();

Your histo is not transparent, and the Draw order matters.

You should draw the histogram first … it defines the coordinates:

      TCanvas *c01 = new TCanvas("c01","histo",1280,1024);
      c01->SetLogy();
      histo->Draw();
.... etc 

Thank you the both @couet and @dastudillo that was the problem.
I’ve last question
I set the x range

histo->GetXaxis()->SetRange(x1,x2);

being

int x1=1660;
int x2=1720;

but it looks like that the plot starts before than 1660

histodrawbgk.cpp (2.6 KB)

I guess you should use SetRangeUser instead.

Thank you @couet
using SetRangeUser it solved!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.