## 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 been loaded into Sherpa: 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) add_window() add_curve(energy,photon,photerr) # plot ph/s/cm**2/keV spectrum set_plot_xlabel("Energy (keV)") set_plot_ylabel("photons s^{-1} cm^{-2} keV^{-1}") limits(Y_AXIS, 0, "auto") log_scale(Y_AXIS) save_arrays("plot_flux.dat",[energy,photon,photerr],["keV","FLUX","FLUXerr"],ascii=True)

The unfolded spectrum is calculated with the plot_ratio() command, and obtained via get_ratio_plot().y, in units of photons/s/cm2/keV. The plot_ratio() command plots the ratio of a data set to its assigned source model; in this case, the observed spectrum is divided by the summation of the product of the responses, since we have assumed a constant source model set to unity.

To convert photons flux units to energy flux units, we define a conversion factor q ~ 1.6e-9 ergs/1 keV photon, based on the electron charge value obtained from the National Institute of Standards and Technology (NIST).