TF1/2 GetHistogram -> how integral histogram visualizatio

Hi,

another question related to 2D histograms and integrals :wink:

OK, I can get a function’s (either TF1 or TF2) visualization as histogram with TF1->GetHistogram() – but as far as I can follow the code [TF1:Paint ~line 2754] the function’s center value in the particular bin is used to fill the bin, or? Instead, I would like to use the integral of the function in the particular bin as value to be filled as bin content – for example to tackle a bit better quite different gradients in a bin (if the binning is too coarse at extreme values or so).

So, is there a way to get a ‘integral bin visualization’ of a function in Root?
If something like that exist, it would be great and would cure my today’s headache a bit :wink:

Cheers & Thanks,
Thomas

Hi,
you can use TF1::DrawIntegral() which draws a TGraph with the function integral evaluated at each function point (bin center)

Lorenzo

I thought that DrawIntegral() returns overall integral of the function, or?

What I am looking for is a way to draw the function itself in a histogram.
GetHistogram() fills the function’s value at a bin center as bin content. But I would like to fill the integral of the function in a bin as bin content – similar as for fits when using option ‘I’.

Hi,

such function it does not exist but it is trivial for a user to implement and fill the histogram. Just do for example:

   TF1 * f1 = new TF1("f","sin(x)",0,10);
   TH1 * h1 = new TH1D(*((TH1D*) f1->GetHistogram()) );
   for (int i = 1; i <= h1->GetNbinsX(); ++i) 
      h1->SetBinContent(i, f1->Integral( h1->GetXaxis()->GetBinLowEdge(i), h1->GetXaxis()->GetBinUpEdge(i) )/h1->GetBinWidth(i) );

Best Regards

Lorenzo

Hi,

integrating binwise works fine – many thanks :slight_smile: