usnistgov / mass

Microcalorimeter pulse-analysis software
MIT License
6 stars 0 forks source link

Line fitters should fit the signal integral, not the signal amplitude #202

Closed joefowler closed 3 years ago

joefowler commented 3 years ago

Original report by Joseph Fowler (Bitbucket: joe_fowler, ).


When we use the Mass line fitters, the “amplitude” parameter is hard to interpret. It is basically the signal integral, but rescaled to be proportional to the bin width in eV.

This is dumb. If it’s like an integral, it ought to be the signal integral and not depend on bin widths.

Consider the following demo, in which we have 100,000 signal photons distributed as a Mn K-alpha shape (with energy resolution 5 eV) plus 500 background photons per eV. We then fit the data histogrammed with 1.00 eV bins (_left panel_), then with 0.50 eV bins (_right_). Notice that the amplitude is exactly 100,000±383 in the first case, but it’s 49,997±191 in the second. Also, the background counts are also given as per-bin numbers rather than per-eV numbers.

I’m pretty sure we should replace “ampl” with “integral” for better interpretability and to reduce confusion, so that both fits shown here would yield integral=100,000. I’m leaning to the idea that BG should also be per-eV, but on that point I am open to debate.

Code to generate this plot:

import mass
line = mass.MnKAlpha
bgperev = 500
Nsignal = 100000
sig = line.rvs(Nsignal, instrument_gaussian_fwhm=5)
bg = np.random.uniform(5850, 5950, 100*bgperev)
plt.clf()
_, axes = plt.subplots(1, 2)
for ax, nbins in zip(axes, (100, 200)):
    s, b = np.histogram(np.hstack((bg, sig)), nbins, [5850, 5950])
    e = b[:-1] + 0.5*(b[1]-b[0])

    model = line.model()
    params = model.guess(s, bin_centers=e)
    resultA = model.fit(s, params, bin_centers=e)
    # Repeat but with dPH/dE held at 1.
    params = resultA.params.copy()
    params["dph_de"].set(1.0, vary=False)
    resultB = model.fit(s, params, bin_centers=e)
    print(resultB.fit_report())
    resultB.plotm(ax=ax)

This is relevant to the new Voigt fitter imagined in #201.

joefowler commented 3 years ago

Original comment by Joseph Fowler (Bitbucket: joe_fowler, ).


Actually, maybe the meaning of “background” should stay the way it is: as background counts per bin. I am trying to use the principle of least confusion here, and that might be what it demands.

joefowler commented 3 years ago

Original comment by Joseph Fowler (Bitbucket: joe_fowler, ).


LineModel objects rescale the "integral" parameter correctly

Rescaling accounts for both bin width and the dph_de factor. Fixes #202.

joefowler commented 1 year ago

Original comment by Joseph Fowler (Bitbucket: joe_fowler, ).


Removing milestone: v0.7 (automated comment)