Convert from TGraph to histogram

You’re welcome.

One more thing: In the macro I sent you the value of Result depends on the number of bins. I am not sure that’s something you want. For example with NumberOfBins = 50 you get Result = 8.86793 and with NumberOfBins = 100 you get Result = 18.7001. Somehow you will need to normalize the computation of Result in order to make it independent of the number of bins.

Dear Olivier,
Yes, I noticed that.
I got the values I was looking for when I increased the number of bins to 6000.
I do not know if that is the right thing to do

Regards,
Gideon

I guess no, you should normalize according to the bin width.

Please how do i do that?

Once again that’s your analysis and you should know.

One possible way would be:

[...]
   double BinWidth = (XHigh-XLow)/NumberOfBins;
   auto   h  = new TH1D("h","h",NumberOfBins,XLow,XHigh);

   double BinContent, BinCenter, Result = 0;

   for (int Bin=1; Bin<=NumberOfBins; Bin++) {
      BinCenter  = h->GetBinCenter(Bin);
      BinContent = gr->Eval(BinCenter);
      Result = Result + 17.3388*BinContent*BinWidth;
      h->SetBinContent(Bin, BinContent);
   }
[...]

Thanks Olivier

Regards,
Gideon