Multiplying histogram by function

Dear Rooters
I have created histogram

TH1F *hgamma = new TH1F(“hgamma”,“hgamma”,3000,0.5,3000.5);

and filled this histogram from a list file.

if I want to multiply this histogram by a constant value and fill in another histogram, I will perform
hgammaProduced=4464(*hgamma);

but in case I want to multiply by a user defined function, where this function depends on x-value

TF1 eff = new TF1(“eff”,"(0.004464exp(-0.00754*x)+0.001064)*0.55",0,3000);

multiplying this histogram to the function implies to multiply the histogram( with x axis divided as bins) , with a function where x axis is just continuous values.
how can I multiply by setting the x -value in the function as the value of the bin center in order to perform the multiplication process.

cheers
Noor

Hi noor,

This should work

Double_t scale_bin=0;
for(int i=0;i<=hgamma->GetNbinsx();i++)
{
scale_bin= eff->Eval(hgamma->GetBinCenter(i));
hgamma->SetBinContent(i,scale_bin*hgamma->GetBinContent(i));
}


Cheers,
Stefano

TH1::Add
TH1::Divide
TH1::Multiply

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