AHELP for CIAO 4.15 Sherpa

# calc_model_sum

Context: utilities

## Synopsis

Sum up the fitted model over a pass band.

## Syntax

```calc_model_sum(lo=None, hi=None, id=None, bkg_id=None)

lo - number, optional
hi - number, optional
id - int or str, optional
bkg_id - int or str, optional```

## Description

Sum up M(E) over a range of bins, where M(E) is the per-bin model value after it has been convolved with any instrumental response (e.g. RMF and ARF or PSF). This is intended for one-dimensional data sets: use `calc_model_sum2d` for two-dimensional data sets. The `calc_source_sum` function is used to calculate the sum of the model before any instrumental response is applied.

## Examples

### Example 1

Calculate the model evaluated over the full data set (all points or pixels of the independent axis) for the default data set, and compare it to the sum for th first background component:

```>>> tsrc = calc_model_sum()
>>> tbkg = calc_model_sum(bkg_id=1)```

### Example 2

Sum up the model over the data range 0.5 to 2 for the default data set, and compared to the data over the same range:

```>>> calc_model_sum(0.5, 2)
404.97796489631639
>>> calc_data_sum(0.5, 2)
745.0```

### Example 3

Calculate the model sum, evaluated over the range 20 to 22 Angstroms, for the first background component of the "histate" data set:

```>>> set_analysis("histate", "wavelength")
>>> calc_model_sum(20, 22, "histate", bkg_id=1)```

### Example 4

In the following example, a small data set is created, covering the axis range of -5 to 5, and an off-center gaussian model created (centered at 1). The model is evaluated over the full data grid and then a subset of pixels. As the summation is done over those points in the data set that lie within the requested range, the sum for lo=-2 to hi=1 is the same as that for lo=-1.5 to hi=1.5:

```>>> load_arrays('test', [-5, -2.5, 0, 2.5, 5], [2, 5, 12, 7, 3])
>>> set_source('test', gauss1d.gmdl)
>>> gmdl.pos = 1
>>> gmdl.fwhm = 2.4
>>> gmdl.ampl = 10
>>> calc_model_sum(id='test')
9.597121089731253
>>> calc_model_sum(-2, 1, id='test')
6.179472329646446
>>> calc_model_sum(-1.5, 1.5, id='test')
6.179472329646446```

### PARAMETERS

The parameters for this function are:

Parameter Definition
lo If both are None or both are set then sum up over the given band. If only one is set then use the model value in the selected bin. The units for `lo` and `hi` are given by the current analysis setting.
hi If both are None or both are set then sum up over the given band. If only one is set then use the model value in the selected bin. The units for `lo` and `hi` are given by the current analysis setting.
id Use the source expression associated with this data set. If not given then the default identifier is used, as returned by `get_default_id` .
bkg_id If set, use the model associated with the given background component rather than the source model.

### Return value

The return value from this function is:

signal -- The model value (sum or individual bin).

### Notes

The units of lo and hi are determined by the analysis setting for the data set (e.g. `get_analysis` ). The summation occurs over those points in the data set that lie within this range, not the range itself.

Any existing filter on the data set - e.g. as created by `ignore` or `notice` - is ignored by this function.

The units of the answer depend on the model components used in the source expression and the axis or axes of the data set.

## Bugs

See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

data
get_bkg_chisqr_plot, get_bkg_delchi_plot, get_bkg_fit_plot, get_bkg_model_plot, get_bkg_plot, get_bkg_ratio_plot, get_bkg_resid_plot, get_bkg_source_plot
info
list_model_ids, show_bkg_model, show_bkg_source
modeling
add_model, add_user_pars, clean, create_model_component, delete_bkg_model, delete_model, delete_model_component, get_model, get_model_autoassign_func, get_model_component, get_model_component_image, get_model_component_plot, get_model_plot, get_num_par, get_num_par_frozen, get_num_par_thawed, get_order_plot, get_par, get_pileup_model, get_source, get_source_component_image, get_source_component_plot, get_source_contour, get_source_image, get_source_plot, get_xsabund, get_xscosmo, get_xsxsect, get_xsxset, image_model, image_model_component, image_source, image_source_component, integrate, link, load_table_model, load_template_interpolator, load_template_model, load_user_model, normal_sample, reset, save_model, save_source, set_bkg_model, set_bkg_source, set_full_model, set_model, set_model_autoassign_func, set_pileup_model, set_source, set_xsabund, set_xscosmo, set_xsxsect, set_xsxset, t_sample, uniform_sample
plotting
get_cdf_plot, get_pdf_plot, get_pvalue_plot, get_pvalue_results, plot_cdf, plot_model, plot_model_component, plot_pdf, plot_pvalue, plot_scatter, plot_source, plot_source_component, plot_trace
psfs
saving
save_delchi, save_resid
tools::response
modelflux
tools::statistics
aprates
utilities
calc_chisqr, calc_data_sum, calc_energy_flux, calc_photon_flux, calc_source_sum, calc_stat, eqwidth, gamma, igam, igamc, incbet, lgam
visualization
contour_model, contour_ratio, contour_resid