Integration histogram

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Dear everyone,

I am looking for a way of using the TF1 integration on a TH1 object. In other words, I would like to transform a TH1 object in to a TF1 one. Do you know if it is possible in Root ?

Thank you in advance,


Why don’t you use the Integral method(s) of TH1 ?

Because I would like to test more evolved integration method.

  // create the histogram
  static TH1D *h = new TH1D("h", "h", 100, -5., 5.);
  h->FillRandom("gaus", 1000);
  // use linear interpolation based on the two nearest bin centers
  TF1 *fI = new TF1("fI",
                    [&](double *x, double*){ return h->Interpolate(x[0]); },
                    h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax(), 0);
  fI->SetNpx(5 * h->GetNbinsX());
  // use raw content of bins
  TF1 *fC = new TF1("fC",
                    [&](double *x, double*){ return h->GetBinContent(h->FindFixBin(x[0])); },
                    h->GetXaxis()->GetXmin(), h->GetXaxis()->GetXmax(), 0);
  fC->SetNpx(5 * h->GetNbinsX());
  // draw everytning
  h->Draw("SAME E");
1 Like

Thank you very much !

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