## How can I plot an unfolded source spectrum in flux units, independent of a model spectrum?

The primary function of software packages like Sherpa is to solve the integral equation (instrument response) which relates the total counts produced in a given pulse-height bin in a spectrum to the incident source spectrum. Therefore, once you have a pulse-height spectrum and the appropriate RMF and ARF instrument response, you can use Sherpa to fold the source data through an assumed model to determine the "true" source flux. This means that unfolding the source spectrum to plot it in flux units, for example (Sherpa Plotting FAQ #2), is dependent upon a model spectrum.

In order to unfold a spectrum in a model-independent way, we assume a constant source model set to unity, as shown in the following script:

#Assuming source and background data and corresponding responses have

subtract()

set_source(polynom1d.truespec)
truespec=1.

photon=get_ratio_plot().y # ph/s/cm2/keV
photerr=get_ratio_plot().yerr

energy=get_ratio_plot().x # keV

from sherpa.astro.utils import _charge_e as q # ~1.6e-9 ergs/1 keV photon (nist.gov)

spec=photon*q*energy**2
specerr=photerr*q*energy**2

save_arrays("plot_flux.dat",[energy,spec,specerr],["keV","FLUX","FLUXerr"],ascii=True)

add_curve(energy,spec,specerr) # plot nu F_nu-type plot
set_plot_xlabel("Energy (keV)")
set_plot_ylabel(r"\nu F_{\nu} (ergs s^{-1} cm^{-2})")
limits(Y_AXIS, 0, "auto")
log_scale(Y_AXIS)