# Fitting a Histogram Using Another Histogram

**URL:** <https://root-forum.cern.ch/t/fitting-a-histogram-using-another-histogram/64049>\
**Category:** Newbie\
**Created:** [August 19, 2025, 6:15pm UTC](https://root-forum.cern.ch/t/fitting-a-histogram-using-another-histogram/64049 "2025-08-19T18:15:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aclarke](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@aclarke](https://root-forum.cern.ch/u/aclarke)\
**Post date:** [August 19, 2025, 6:15pm UTC](https://root-forum.cern.ch/t/fitting-a-histogram-using-another-histogram/64049/1 "2025-08-19T18:15:20Z")

</div>

Hello, I have been attempting to fit a histogram using another histogram which represents a probability distribution. My fit function is of the form fitval = std::round(par[0] \* dist-\>Interpolate(x[0])); . Whenever I try to fit using this function I run into an invalid fit status error, in particular I have been running into the status = 3 error recently, which, from what I understand, means the EDM is above maximum. So far, I have tried adding more bins to my probability distribution and smoothing the histogram, but I am still running into errors. Does anyone know how to fix this? I am guessing this has something to do with my fit function not having a well defined derivative.

Thanks

---

<div class="post-metadata">

**Author:** ![devajith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/devajith/32/37165_2.png) [@devajith](https://root-forum.cern.ch/u/devajith)\
**Post date:** [August 19, 2025, 7:43pm UTC](https://root-forum.cern.ch/t/fitting-a-histogram-using-another-histogram/64049/2 "2025-08-19T19:43:34Z")

</div>

Hi @aclarke,

Welcome to the ROOT Forum.

Let me add our RooFit expert @jonas in the loop. In the meantime, it would be helpful if you can add snippets of the code you are trying to run and the error messages you are seeing.

Cheers,

Dev

---

<div class="post-metadata">

**Author:** ![aclarke](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@aclarke](https://root-forum.cern.ch/u/aclarke)\
**Post date:** [August 19, 2025, 7:56pm UTC](https://root-forum.cern.ch/t/fitting-a-histogram-using-another-histogram/64049/3 "2025-08-19T19:56:58Z")

</div>

Hello,  
Here is an example of the error messages I’m seeing:

* * *

```auto
     Invalid FitResult (status = 3 )

```

* * *

Minimizer is Minuit2 / Migrad  
MinFCN = 15078.8  
Chi2 = 30157.6  
NDf = 999  
Edm = 0.0094626  
NCalls = 78  
p0 = 36.4999 +/- 0.019146  
Warning in : Abnormal termination of minimization.

* * *

Here is the relevant code:  
Double\_t fitfunc2(Double\_t \*x, Double\_t \* par)  
{  
Double\_t fitval = 0;  
fitval = std::round(par[0] \* dist-\>Interpolate(x[0]));  
return fitval;  
}  
while (ti!=l1.end())  
{

auto tj = ti;

//tj++; //tj starts as ti+1  
delete temphist;  
temphist = new TH1D(“dist”, “Photon Cluster Time Distribution; time(ns); Counts”, 1000, 0, 6e-6);  
//photons-\>Fill((\*tj).realtime-(\*ti).realtime);  
while (((\*tj).realtime - (\*ti).realtime) \< 6e-6)  
{  
temphist-\>Fill((\*tj).realtime - (\*ti).realtime);  
tj++;  
}  
if(temphist-\>GetEntries() \>= 10)  
{  
func-\>SetParameters(temphist-\>GetEntries());  
temphist-\>Fit(“fitfunc2”, “LI”);  
}…  
dist is also a TH1D.
