Multiplying bin content of TH1F by a constant number

Hello all,

I have TH1F histogram and need to multiply each bin content by a number and draw it as a new histogram. I tried it using Multiply(histogram, number) but it didn’t work. I checked on terminal just by drawing a random histogram h1 and h2=2h1 and h2.Draw(), works in the terminal but not in the script. I’m looking forward to solving this issue. Thanks for your help in advance.

Cheers,
Neeraj

void mul()
{
   TH1F *h1 = new TH1F("h1","h1",100,-5.,5.);
   h1->FillRandom("gaus");
   TH1F *h2 = (TH1F *)h1->Clone("h2");
   h2->SetTitle("h2");
   h2->Scale(0.5);

   TCanvas *c = new TCanvas("c","c",800,300);
   c->Divide(2,1);
   c->cd(1); h1->Draw("hist");
   c->cd(2); h2->Draw("hist");
}

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