How to put a TLine to background

Dear Users,

I have been a little stuck on trying to plot a horizontal line TLine behind a 1D histogram hist (TH1D object). My code lines look as follows:

canvas = TCanvas("Histogram", "Histogram", 100, 200, 700, 500)
canvas.cd()
hist.Draw("hist")
line = TLine(0, 10, 100, 10)
line.Draw()

This plots the line in front of the histogram; how do I put it behind? I have tried setting line.Draw() before hist.Draw("hist") but this just draws a new histogram without the line. Rewriting hist.Draw("hist same") draws a blank image.

void histline()
{
   auto h1 = new TH1F("h1","h1",100,-3,3);
   h1->FillRandom("gaus",100000);
   h1->SetFillStyle(1001);
   h1->SetFillColor(kBlue+2);
   h1->Draw();
   auto line = new TLine(-2.5, 1500, 2.5, 1500);
   line->SetLineColor(kRed);
   line->SetLineWidth(6);
   line->Draw();
   h1->Draw("SAME");
}

Thank you very much!

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