-
Hi! Until now, I've been using uproot like this:
or using other functions, like Now I have a TH1 histogram with an associated fit. Executing the same block of code from above gives me access to the histogram itself, but not to the fit. I've tried looking at documentation, but apart from the basic usage of reading histograms I could not find anything else pertaining to this topic. The most similar thread I found here was this, but it had a different problem. In the end, I'd like to be able to manipulate the fit function (that is, chose how to plot the fit line -- color, line thickness, etc.., but not altering the fit itself and/or its parameters), as well as the histogram (same plotting parameters). If you also have better suggestions to the histogram part from above, I am a very good listener :) I attach such an example dummy root file with a Gaussian histogram and gaus fit. For reference, the code used to generate the histogram:
Thank you so very much for reading this! I am available for any questions... I am using ROOT Version: 6.24/06 Built for linuxx8664gcc // uproot 5.1.2 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I don't know if anyone has done this before, and we haven't written a nice interface to extract fitted values, but the fit results appear to be in the Uproot deserialization, if you dig. >>> import uproot
>>> h = uproot.open("output.root:histogram_with_improved_fit") # the histogram
>>> f = h.member("fFunctions")[0] # the fit function
>>> f.member("fFormula").member("fFormula") # fit function as a string
<TString '[Constant]*exp(-0.5*((x-[Mean])/[Sigma])*((x-[Mean])/[Sigma]))' at 0x7f76607bfa70>
>>> f.member("fFormula").member("fParams") # mapping from name to index
<STLMap {'Constant': 0, 'Mean': 1, 'Sigma': 2} at 0x7f76606bd4e0>
>>> f.member("fFormula").member("fClingParameters") # fitted parameters
<STLVector [3998.1535358600363, ..., 0.9969355099011799] at 0x7f76606bd5a0>
>>> f.member("fParErrors") # uncertainty in the fit
<STLVector [15.817986532882609, ..., 0.0024257088650948555] at 0x7f7660514850>
>>> f.member("fChisquare") # goodness of fit
74.87458329375289
>>> f.member("fNDF")
57
>>> import matplotlib.pyplot as plt
>>> plt.plot(list(f.member("fSave"))) # view the saved fit
[<matplotlib.lines.Line2D object at 0x7f7658c31a20>]
>>> plt.show() (Uproot's In principle, this could be wrapped up in a nice interface. The boost-histogram and hist libraries don't deal in fitted curves, but they can take metadata. Maybe the fit results can be attached to a Cc: @HDembinski and @henryiii |
Beta Was this translation helpful? Give feedback.
I don't know if anyone has done this before, and we haven't written a nice interface to extract fitted values, but the fit results appear to be in the Uproot deserialization, if you dig.