Kali95
June 25, 2019, 8:31am
1
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,
Kali95
couet
June 25, 2019, 8:43am
2
Why don’t you use the Integral method(s) of TH1 ?
Kali95
June 25, 2019, 8:45am
3
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);
h->SetLineColor(kBlue);
// 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());
fI->SetLineColor(kGreen);
// 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());
fC->SetLineColor(kRed);
// draw everytning
fC->Draw();
fI->Draw("SAME");
h->Draw("SAME E");
}
1 Like
system
Closed
July 9, 2019, 9:21am
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.