Last modified: 13 Jul 2010

URL: https://cxc.cfa.harvard.edu/sherpa/threads/aciss_grating_sim_src_model/

Simulating Chandra ACIS-S LETG Spectra with Sherpa: Establishing the Source Model Expression

Sherpa Threads (CIAO 4.11 Sherpa v1)


Overview

Synopsis:

The thread "Simulating Chandra ACIS-S LETG Spectra with Sherpa" illustrates the use of the Sherpa fake_pha command to simulate a spectrum of a point source with the ACIS-S/LETG detector/grating configuration aboard Chandra, using a source model tailored to an existing ACIS-S/HETG data set. This thread details the steps taken to define this source model expression.

Last Update: 13 Jul 2010 - updated for CIAO 4.2 Sherpa v2: removal of S-Lang version of thread.


Contents


Defining the Instrument Response for the Real Data

We begin by loading the ACIS-S/HETG data sets which will serve as the guide for our simulated ACIS-S/LETG data. The Sherpa command load_pha will automatically establish the instrument responses and backgrounds associated with each of the four spectral orders, provided their associated filenames are recorded in the header of the PHA files (if not, they should be loaded manually with the load_arf and load_rmf commands).

sherpa> load_pha(1, "459_heg_m1_bin10.pha")
sherpa> load_pha(2, "459_heg_p1_bin10.pha")
sherpa> load_pha(3, "459_meg_m1_bin10.pha")
sherpa> load_pha(4, "459_meg_p1_bin10.pha")

sherpa> load_arf(1, "459_heg_m1.arf")
sherpa> load_arf(2, "459_heg_p1.arf")
sherpa> load_arf(3, "459_meg_m1.arf")
sherpa> load_arf(4, "459_meg_p1.arf")

sherpa> load_arf(1, "459_heg_m1.arf", bkg_id=1)
sherpa> load_arf(1, "459_heg_m1.arf", bkg_id=2)

sherpa> load_arf(2, "459_heg_p1.arf", bkg_id=1)
sherpa> load_arf(2, "459_heg_p1.arf", bkg_id=2)

sherpa> load_arf(3, "459_meg_m1.arf", bkg_id=1)
sherpa> load_arf(3, "459_meg_m1.arf", bkg_id=2)

sherpa> load_arf(4, "459_meg_p1.arf", bkg_id=1)
sherpa> load_arf(4, "459_meg_p1.arf", bkg_id=2)

Sherpa now refers to the spectra as follows:

  • HEG, -1 order = dataset 1
  • HEG, +1 order = dataset 2
  • MEG, -1 order = dataset 3
  • MEG, +1 order = dataset 4

The current definition of the instrument response, along with information about the loaded data sets, may be examined using the commands show_data and show_bkg:

sherpa> show_data()
Data Set: 1
Filter: 0.5775-12.3676 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_heg_m1_bin10.pha
channel        = Float64[8192]
counts         = Float64[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 1.0
areascal       = 1.0
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = [1, 2]

ARF Data Set: 1:1
header   = 
{header information omitted for brevity}
name     = 459_heg_m1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38565.2847986

Data Set: 2
Filter: 0.5775-12.3676 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_heg_p1_bin10.pha
channel        = Float64[8192]
counts         = Float64[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 1.0
areascal       = 1.0
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = [1, 2]

ARF Data Set: 2:1
header   = 
{header information omitted for brevity}
name     = 459_heg_p1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38563.0133422

Data Set: 3
Filter: 0.2957-12.3370 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_meg_m1_bin10.pha
channel        = Float64[8192]
counts         = Float64[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 1.0
areascal       = 1.0
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = [1, 2]

ARF Data Set: 3:1
header   = 
{header information omitted for brevity}
name     = 459_meg_m1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38565.2855739

Data Set: 4
Filter: 0.2957-12.3370 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_meg_p1_bin10.pha
channel        = Float64[8192]
counts         = Float64[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 1.0
areascal       = 1.0
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = [1, 2]

ARF Data Set: 4:1
header   = 
{header information omitted for brevity}
name     = 459_meg_p1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38563.0141169


sherpa> show_bkg()
Background Data Set: 1:1
Filter: 0.5775-12.3676 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_heg_m1_bin10.pha
channel        = Float64[8192]
counts         = Int16[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 4.0188284
areascal       = None
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = []

Background ARF Data Set: 1:1
header   = 
{header information omitted for brevity}
name     = 459_heg_m1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38565.2847986

Background Data Set: 1:2
Filter: 0.5775-12.3676 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_heg_m1_bin10.pha
channel        = Float64[8192]
counts         = Int16[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 4.0188284
areascal       = None
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = []

Background ARF Data Set: 1:2
header   = 
{header information omitted for brevity}
name     = 459_heg_m1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38565.2847986

Background Data Set: 2:2
Filter: 0.5775-12.3676 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_heg_p1_bin10.pha
channel        = Float64[8192]
counts         = Int16[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 4.0188284
areascal       = None
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = []

Background ARF Data Set: 2:2
header   = 
{header information omitted for brevity}
name     = 459_heg_p1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38563.0133422

Background Data Set: 3:2
Filter: 0.2957-12.3370 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_meg_m1_bin10.pha
channel        = Float64[8192]
counts         = Int16[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 4.0188284
areascal       = None
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = []

Background ARF Data Set: 3:2
header   = 
{header information omitted for brevity}
name     = 459_meg_m1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38565.2855739

Background Data Set: 4:2
Filter: 0.2957-12.3370 Energy (keV)
Noticed Channels: 1-8192
header         = 
{header information omitted for brevity}
name           = 459_meg_p1_bin10.pha
channel        = Float64[8192]
counts         = Int16[8192]
staterror      = None
syserror       = None
bin_lo         = Float64[8192]
bin_hi         = Float64[8192]
grouping       = Int16[8192]
quality        = Int16[8192]
exposure       = 38564.6089269
backscal       = 4.0188284
areascal       = None
grouped        = True
subtracted     = False
units          = energy
rate           = True
plot_fac       = 0
response_ids   = [1]
background_ids = []

Background ARF Data Set: 4:2
header   = 
{header information omitted for brevity}
name     = 459_meg_p1.arf
energ_lo = Float64[8192]
energ_hi = Float64[8192]
specresp = Float64[8192]
bin_lo   = Float64[8192]
bin_hi   = Float64[8192]
exposure = 38563.0141169

To visualize the four orders of data in wavelength space before establishing a source model expression to fit, we ensure that the units field of each data set is set to "wavelength" with the set_analysis command, and then plot the orders with the plot command:

sherpa> set_analysis("wave")

sherpa> plot("data", 1, "data", 2, "data", 3, "data", 4)

The resulting plot is shown in Figure 1

Figure 1: Plotting the four orders

[Plot of ACIS HEG and MEG +/- 1 orders for 3C 273]
[Print media version: Plot of ACIS HEG and MEG +/- 1 orders for 3C 273]

Figure 1: Plotting the four orders

Plot of ACIS HEG and MEG +/- 1 orders for 3C 273

Now that Sherpa data sets and associated instrument responses for the ACIS-S/HETG data have been established, we are ready to define the source and background model expressions which best describe this data. The resulting source model will be applied to the simulated ACIS-S/LETG data in the section "Running the Simulation with fake_pha" of the thread "Simulating Chandra ACIS-S LETG Spectra with Sherpa."


Filtering the Data

To get the best fit to the data, we first choose to filter the data in wavelength space to exclude data above 15.0 Angstroms and below 1.0 Angstrom.

sherpa> show_filter()
Data Set Filter: 1
1.0025-21.4675 Wavelength (Angstrom)

Data Set Filter: 2
1.0025-21.4675 Wavelength (Angstrom)

Data Set Filter: 3
1.0050-41.9350 Wavelength (Angstrom)

Data Set Filter: 4
1.0050-41.9350 Wavelength (Angstrom)

sherpa> ignore()
sherpa> notice(1.0, 15.)

sherpa> show_filter()
Data Set Filter: 1
1.0025-14.9925 Wavelength (Angstrom)

Data Set Filter: 2
1.0025-14.9925 Wavelength (Angstrom)

Data Set Filter: 3
1.0050-14.9850 Wavelength (Angstrom)

Data Set Filter: 4
1.0050-14.9850 Wavelength (Angstrom)

sherpa> plot("data", 1, "data", 2, "data", 3, "data", 4)

A plot of the four orders filtered in wavelength space is shown in Figure 2.

Figure 2: Filtering the data sets

[Plot of filtered ACIS HEG and MEG +/- 1 orders for 3C 273 Cygni in energy space]
[Print media version: Plot of filtered ACIS HEG and MEG +/- 1 orders for 3C 273 Cygni in energy space]

Figure 2: Filtering the data sets

Plot of ACIS HEG and MEG +/- 1 orders of 3C 273, restricted to the wavelength range 1.0 - 15.0 Angstroms.


Defining the Source and Background Models

We plan on simultaneously fitting the background data (rather than subtracting it), so we need to create a model expression for the source and the background. We model this source with a broken power law (bpl1d) absorbed by the interstellar medium (atten). The background will be modeled by a one-dimensional power law (powlaw1d), also absorbed by the ISM (the same atten model).

First, we set up the model components with create_model_component, and set some initial parameter values. The absorption model is referred to as "abs1", the broken power law as "bpow1", and the 1-D power law as "pow1d":

sherpa> create_model_component("atten", "abs1")
sherpa> abs1.integrate = "false"
sherpa> abs1.hcol = 1e+20
sherpa> abs1.heiRatio = 0.1
sherpa> abs1.heiiRatio = 0.01

sherpa> create_model_component("bpl1d", "bpow1")
sherpa> bpow1.gamma1 = 0
sherpa> bpow1.gamma2 = 0
sherpa> bpow1.eb = 7.99625
sherpa> freeze(bpow1.ref)
sherpa> bpow1.ampl = 0.001

sherpa> create_model_component("powlaw1d","pow1d")
sherpa> pow1d.gamma = 1
sherpa> pow1d.ampl = 1e-5

We freeze the normalization parameters for bpow1 and pow1d (bpow1.ref and pow1d.ref) without changing the default values. For the bpow1 and pow1d parameters for which we did set initial values, we could have used the Sherpa guess() function to estimate reasonable starting values, based on the data input to the Sherpa session. To have Sherpa automatically query for initial parameter values when a model is established, set 'paramprompt(True)' (it is 'False' by default).

The model parameter values can be listed with print() command (note that show_model/show_source is appropriate once the full model expression has been assigned to the data with set_source:

sherpa> print(abs1)
atten.abs1
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   abs1.hcol     thawed        1e+20        1e+17        1e+24
   abs1.heiRatio thawed          0.1            0            1
   abs1.heiiRatio thawed         0.01            0            1

sherpa> print(bpow1)
bpl1d.bpow1
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   bpow1.gamma1  thawed            0          -10           10
   bpow1.gamma2  thawed            0          -10           10
   bpow1.eb      thawed      7.99625            0        1e+03
   bpow1.ref     frozen            1     -3.4e+38      3.4e+38
   bpow1.ampl    thawed        0.001        1e-20      3.4e+38

sherpa> print(pow1d)
powlaw1d.pow1d
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   pow1d.gamma  thawed            1          -10           10
   pow1d.ref    frozen            1     -3.4e+38      3.4e+38
   pow1d.ampl   thawed        1e-05            0      3.4e+38

Next we modify the initial parameter value for abs1.hcol:

sherpa> abs1.hcol = 1.81e20
sherpa> freeze(abs1)

The hydrogen column density (hcol) is set to the Galactic value. All the abs1 parameters are then frozen, which means they will not be allowed to vary during the fit.

Now that the model components have been established, the product of abs1 and bpow1 is assigned as the source model for all data sets :

sherpa> set_model(1, abs1*bpow1)
sherpa> set_model(2, abs1*bpow1)
sherpa> set_model(3, abs1*bpow1)
sherpa> set_model(4, abs1*bpow1)

while the background model is set as the product of abs1 and pow1d:

sherpa> set_bkg_model(1, abs1*pow1d, 1)
sherpa> set_bkg_model(1, abs1*pow1d, 2)
sherpa> set_bkg_model(2, abs1*pow1d, 1)
sherpa> set_bkg_model(2, abs1*pow1d, 2)
sherpa> set_bkg_model(3, abs1*pow1d, 1)
sherpa> set_bkg_model(3, abs1*pow1d, 2)
sherpa> set_bkg_model(4, abs1*pow1d, 1)
sherpa> set_bkg_model(4, abs1*pow1d, 2)

The source and background model definitions can be listed with show_model and show_bkg_model:

sherpa> show_model()
Model: 1
apply_arf((38564.6089269 * ((atten.abs1 * bpl1d.bpow1) + scale_factor * ((atten.abs1 * powlaw1d.pow1d) + (atten.abs1 * powlaw1d.pow1d)))))
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   abs1.hcol    frozen     1.81e+20        1e+17        1e+24           
   abs1.heiRatio frozen          0.1            0            1           
   abs1.heiiRatio frozen         0.01            0            1           
   bpow1.gamma1 thawed            0          -10           10           
   bpow1.gamma2 thawed            0          -10           10           
   bpow1.eb     thawed      7.99625            0         1000           
   bpow1.ref    frozen            1 -3.40282e+38  3.40282e+38           
   bpow1.ampl   thawed        0.001        1e-20  3.40282e+38           
   pow1d.gamma  thawed            1          -10           10           
   pow1d.ref    frozen            1 -3.40282e+38  3.40282e+38           
   pow1d.ampl   thawed        1e-05            0  3.40282e+38           

Model: 2
{same as above}

Model: 3
{same as above}

Model: 4
{same as above}

sherpa> show_bkg_model()
Background Model: 1:1
apply_arf((38564.6089269 * (atten.abs1 * powlaw1d.pow1d)))
   Param        Type          Value          Min          Max      Units
   -----        ----          -----          ---          ---      -----
   abs1.hcol    frozen     1.81e+20        1e+17        1e+24           
   abs1.heiRatio frozen          0.1            0            1           
   abs1.heiiRatio frozen         0.01            0            1           
   pow1d.gamma  thawed            1          -10           10           
   pow1d.ref    frozen            1 -3.40282e+38  3.40282e+38           
   pow1d.ampl   thawed        1e-05            0  3.40282e+38          

Background Model: 1:2
{same as above}

Background Model: 2:1
{same as above}

Background Model: 2:2
{same as above}

Background Model: 3:1
{same as above}

Background Model: 3:2
{same as above}

Background Model: 4:1
{same as above}

Background Model: 4:2
{same as above}

Examining Method & Statistic Settings

Next we check the current method and statistics settings:

sherpa> show_method()
Optimization Method: LevMar
name    = levmar
ftol    = 1.19209289551e-07
xtol    = 1.19209289551e-07
gtol    = 1.19209289551e-07
maxfev  = None
epsfcn  = 1.19209289551e-07
factor  = 100.0
verbose = 0

sherpa> show_stat()
Statistic: Chi2Gehrels
Chi Squared with Gehrels variance

The Sherpa default fitting statistic and optimization method are Chi2Gehrels and LevMar, respectively. For this fit, we will use the Neldermead method and the CStat statistic - Chi2Gehrels could bias the fit results and yield an artificially low reduced statistic for this data, and the CStat (and Cash) statistic is appropriate for simultaneously fitting source and background data. For a list of all the available methods and statistic settings, see the Sherpa Statistics and Optimization Methods pages.

To change the current method and statistic, we use set_method and set_stat

sherpa> set_method("neldermead")
sherpa> set_stat("cstat") 

Fitting

The data sets are now fit:

sherpa> fit()
Datasets              = 1, 2, 3, 4
Method                = neldermead
Statistic             = cstat
Initial fit statistic = 100816
Final fit statistic   = 5976.06 at function evaluation 1527
Data points           = 5052
Degrees of freedom    = 5046
Probability [Q-value] = 1.06549e-18
Reduced statistic     = 1.18432
Change in statistic   = 94840
   bpow1.gamma1   0.424711
   bpow1.gamma2   0.0496577
   bpow1.eb       10.62
   bpow1.ampl     0.00548927
   pow1d.gamma    0.331504
   pow1d.ampl     8.87632e-05

To plot the fits:

sherpa> plot("fit", 1, "fit", 2, "fit", 3, "fit", 4)
WARNING: unable to calculate errors using current statistic: cstat
WARNING: unable to calculate errors using current statistic: cstat
WARNING: unable to calculate errors using current statistic: cstat
WARNING: unable to calculate errors using current statistic: cstat

sherpa> current_plot("all")
sherpa> set_plot_title("3C 273 (ObsID 459)")

sherpa> current_plot("plot1")
sherpa> add_label(10, 0.1, "HEG -1")
sherpa> set_label(["color","green"])
sherpa> current_plot("plot2")
sherpa> add_label(10, 0.1, "HEG +1")
sherpa> set_label(["color","green"])
sherpa> current_plot("plot3")
sherpa> add_label(10, 0.15, "MEG -1")
sherpa> set_label(["color","green"])
sherpa> current_plot("plot4")
sherpa> add_label(10, 0.15, "MEG +1")
sherpa> set_label(["color","green"])

The ChIPS commands are used to add a title and labels to the drawing area. The plot is shown in Figure 3.

Figure 3: Results of Simultaneous Fit

[Labeled plots of the simultaneous fit on ACIS HEG and MEG +/- 1 orders of 3C 273]
[Print media version: Labeled plots of the simultaneous fit on ACIS HEG and MEG +/- 1 orders of 3C 273]

Figure 3: Results of Simultaneous Fit

Labeled plots of the simultaneous fit on ACIS HEG and MEG +/- 1 orders of 3C 273.

Note that the cstat statistic does not calculate errors for the data points. Since it is useful to do so, we change the fit statistic to something suitable for calculating errors, and view the residuals of the fit with the plot_fit_delchi command:

sherpa> set_stat('chi2xspecvar')
sherpa> plot_fit_delchi()

This plot is shown in Figure 4.

Figure 4: Fit and residuals for the HEG -1 order spectrum

[Plot of the fit and residuals for the HEG -1 order spectrum]
[Print media version: Plot of the fit and residuals for the HEG -1 order spectrum]

Figure 4: Fit and residuals for the HEG -1 order spectrum

After creating a plot, it may be saved as a PostScript file; in this example, "all.ps" is returned:


Examining Fit Results

In CIAO 3.4, the GOODNESS command was used to get the chi-squared goodness-of-fit. This information is now reported with the best-fit values after a fit; it is no longer necessary to run a separate command. However, the commands get_fit_results and show_fit are also available for accessing this information after the fit has been performed.

sherpa> show_fit()
Optimization Method: NelderMead
name         = simplex
ftol         = 1.19209289551e-07
maxfev       = None
initsimplex  = 0
finalsimplex = 9
step         = None
iquad        = 1
verbose      = 0

Statistic: Chi2XspecVar
Chi Squared with data variance (XSPEC style)

Fit:Datasets              = 1, 2, 3, 4
Method                = neldermead
Statistic             = cstat
Initial fit statistic = 100816
Final fit statistic   = 5976.06 at function evaluation 1527
Data points           = 5052
Degrees of freedom    = 5046
Probability [Q-value] = 1.06549e-18
Reduced statistic     = 1.18432
Change in statistic   = 94840
   bpow1.gamma1   0.424711
   bpow1.gamma2   0.0496577
   bpow1.eb       10.62
   bpow1.ampl     0.00548927
maxfev       = None
initsimplex  = 0
finalsimplex = 9
step         = None
iquad        = 1
verbose      = 0

Statistic: Chi2XspecVar
Chi Squared with data variance (XSPEC style)

Fit:Datasets              = 1, 2, 3, 4
Method                = neldermead
Statistic             = cstat
Initial fit statistic = 100816
Final fit statistic   = 5976.06 at function evaluation 1527
Data points           = 5052
Degrees of freedom    = 5046
Probability [Q-value] = 1.06549e-18
Reduced statistic     = 1.18432
Change in statistic   = 94840
   bpow1.gamma1   0.424711
   bpow1.gamma2   0.0496577
   bpow1.eb       10.62
   bpow1.ampl     0.00548927
   pow1d.gamma    0.331504
   pow1d.ampl     8.87632e-05

The number of bins in the fit (Data points), the number of degrees of freedom (i.e. the number of bins minus the number of free parameters), and the final fit statistic value are reported. If the chosen statistic is one of the chi-square statistics, as in this example, the reduced statistic, i.e. the statistic value divided by the number of degrees of freedom, and the probability (Q-value) are included as well.

The calc_chisqr command calculates the statistic contribution per bin; in this example, the results for data set 1 are returned:

sherpa> calc_chisqr()

array([ 0.,  0.,  0., 0., ... , 1.17970306e-06,   9.99029138e-01,   8.38311915e-08, 2.42387626e-08,   3.06732525e-09,   1.39226106e-09, 1.18170110e-10,   4.34535088e-11,   1.37691508e-12])

The confidence (conf), covariance (covar) and projection (proj) commands can be used to estimate confidence intervals for the thawed parameters:

sherpa> set_stat("cstat")
sherpa> conf()
bpow1.ampl -: WARNING: The confidence level lies within (5.395765e-03, 5.442
519e-03)
bpow1.ampl lower bound: -7.01316e-05
pow1d.ampl lower bound: -5.50067e-06
bpow1.gamma1 -: WARNING: The confidence level lies within (4.157534e-01, 4.2
02320e-01)
bpow1.gamma1 lower bound:       -0.00671795
bpow1.gamma2 lower bound:       -0.063624
bpow1.eb lower bound:   -0.318358
pow1d.gamma lower bound:        -0.0324928
bpow1.eb upper bound:   0.281198
bpow1.gamma2 upper bound:       0.0683777
pow1d.gamma upper bound:        0.0323259
pow1d.ampl upper bound: 5.84175e-06
bpow1.ampl upper bound: 7.30538e-05
bpow1.gamma1 upper bound:       0.00706784
Datasets              = 1, 2, 3, 4
Confidence Method     = confidence
Fitting Method        = neldermead
Statistic             = cstat
confidence 1-sigma (68.2689%) bounds:
   Param            Best-Fit  Lower Bound  Upper Bound
   -----            --------  -----------  -----------
   bpow1.gamma1     0.424711  -0.00671795   0.00706784
   bpow1.gamma2    0.0496577    -0.063624    0.0683777
   bpow1.eb            10.62    -0.318358     0.281198
   bpow1.ampl     0.00548927 -7.01316e-05  7.30538e-05
   pow1d.gamma      0.331504   -0.0324928    0.0323259
   pow1d.ampl    8.87632e-05 -5.50067e-06  5.84175e-06

Saving and Quitting the Session

Before exiting Sherpa, you may wish to save the session in order to return to the analysis at a later point:

The save function records all the information about the current session to the binary file 459_fitting_session.save, and the save_all function records the session settings to an editable ASCII file.

To restore the session that was saved to the binary file 459_fitting_session.save or ASCII file 459_fitting_session.ascii:

sherpa> restore("session1.save")
sherpa> execfile("session1.ascii")

Finally, quit the session:

sherpa> quit

History

02 Apr 2009 Created for CIAO/Sherpa 4.1
15 Jan 2010 updated for CIAO 4.2
13 Jul 2010 updated for CIAO 4.2 Sherpa v2: removal of S-Lang version of thread.