scikit-hep / probfit

Cost function builder. For fitting distributions.
http://probfit.readthedocs.io/
MIT License
50 stars 30 forks source link

Add example using ROOT histogram input #53

Closed kreczko closed 3 years ago

kreczko commented 10 years ago

Dear developers,

It would be fantastic if you could provide or help me with creating an example of how to transfer a ROOT histogram into a format that can be understood by probfit.

Currently my attempt is to modify the example for blh: https://github.com/iminuit/probfit/blob/master/doc/pyplots/costfunc/blh.py to fit to histogram data from ROOT.

The most simple change is: https://gist.github.com/kreczko/d02a68e5d3b396374ce7 where I histogram the example data and create a list from the histogram. However, the result is completely different.

Do you have any idea how to make it work?

kreczko commented 10 years ago

I've just seen that one has to provide the raw data, not histogramed (http://iminuit.github.io/probfit/api.html#binned-likelihood). Is there a particular reason for it? Is it possible to use a histogramed template to create toy MC that would be suitable?

alexpearce commented 7 years ago

I am right in thinking that 'ROOT' is a red herring here @kreczko? Getting ROOT histograms into numpy arrays is straightforward with something like root_numpy's hist2array.

So then this issue is more about being able to use a list of bin edges and contents with BinnedLH and BinnedChi2, right?

Is it possible to use a histogramed template to create toy MC that would be suitable?

Yes, that's possible. See this notebook for an example:

http://nbviewer.jupyter.org/gist/alexpearce/07cee3c5c19971bf15e9358e4f0bb195

Although there is one cell (number 91) that has what looks like a LaTeX-related error, coming from iminuit. My only guess is that it's due to the PDF having no independent parameters. @cdeil - could you imagine that being a problem for iminuit's LaTeX-producing code?

cdeil commented 7 years ago

@alexpearce - That IndexError from latex.py looks like a bug in iminuit.

Can you please open a separate issue in the iminuit tracker?

If you have time, try to create an even smaller test case that shows the error, and maybe try to poke around a bit and see if the issue also occurs for the normal print functions. If you don't have time, assign to me and I'll have a look when I have some time.

alexpearce commented 7 years ago

Reported as iminuit/iminuit#191. I'm working on the corresponding PR.

This issue is now just about adding support for passing histogram data to BinnedLH and BinnedChi2.

eduardo-rodrigues commented 3 years ago

This can be closed at this point given the iminuit related issue has been dealt with and the recent PyHEP ecosystem provides ways to deal with ROOT histogram manipulations and conversions.