Draw lines and histograms in one canvas in loop

Hi, I want to draw a series of histograms in a loop. When I run one example, I can get the histogram like the figure shows.
Picture1

But when I use loop to generate 10 histograms, the result is as shown. There is no lines here.

Here is the structure of my code.

    TH1D h1("","Bi-214",1000,2500,3500);
    TH1D h2("","Tl-208",1000,2500,3500);
    TH1D h3("","Signal",1000,2500,3500);
    c1 =  TCanvas("","",900,900);
    c1.Divide(3,4);
    
    for (int loop = 1; loop<=10;loop++){
        double sgm = 2.996*loop/2.355;
        h3.DrawCopy();
        h2.DrawCopy("same");
        h1.DrawCopy("same");


        auto L1 = TLine(2996-sgm,0,2996-sgm,1);
        auto L2 = TLine(2996+sgm,0,2996+sgm,1);

        L1.Draw("same");
        L2.Draw("same");
        gPad->BuildLegend(0.6,0.7,0.9,0.94,"","l");
        c1.Update();
     }

Could anyone can help me? Thanks

{
    auto h1 = new TH1D("","Bi-214",1000,2500,3500);
    auto h2 = new TH1D("","Tl-208",1000,2500,3500);
    auto h3 = new TH1D("","Signal",1000,2500,3500);
    auto c1 = new TCanvas("","",900,900);
    c1->Divide(3,4);
    double sgm;

    for (int loop = 1; loop<=10;loop++){
        c1->cd(loop);
        sgm = 2.996*loop/2.355;
        h3->Draw();
        h2->Draw("same");
        h1->Draw("same");
        auto L1 = new TLine(2996-sgm,0,2996-sgm,1);
        auto L2 = new TLine(2996+sgm,0,2996+sgm,1);
        L1->Draw();
        L2->Draw();
        gPad->BuildLegend(0.6,0.7,0.9,0.94,"","l");
     }
}

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