1 an introduction to x-ray spectral fitting i: getting started with xspec other material xspec...

37
1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual: http://heasarc.gsfc.nasa.gov/docs/xanadu/x spec/ • “X-ray school” lecture notes: http://xrayschool.gsfc.nasa.gov/docs/xrays chool/ • Local pages:

Upload: christal-sharp

Post on 19-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

1

An Introduction toX-ray Spectral Fitting I:

Getting started with XSPEC

Other material• XSPEC manual:

• http://heasarc.gsfc.nasa.gov/docs/xanadu/xspec/

• “X-ray school” lecture notes:• http://xrayschool.gsfc.nasa.gov/docs/xrayschool/

• Local pages:•http://www/star.le.ac.uk/~sav2/stats

Page 2: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

2

Syllabus

Part I:• What is spectral fitting? Why?• How to compare data and model• Running XSPEC• Fitting a model to data• Fitting non X-ray data (e.g. optical)• Simulating dataPart II:• How to test the fit• Confidence regions (uncertainties)• Comparing different models• Few count/bin spectra• Reference material

Page 3: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

3

Why spectral fitting?1) The recorded spectrum is not the true

spectrum of the source:• instrumental response • errors (uncertainties, e.g. Poisson noise)

2) To test a physical model (e.g. blackbody) against data and make statistical inferences.

Page 4: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

4

The detector response

0

)()(),()( dEESEAEiRTiC

As an observer, what you get is counts per detector channel, C(i):

T is the observation length (in s)

A(E) is the effective area of the telescope + detector (in cm2).

R(i,E) is the redistribution: the probability of photon with energy E being recorded in channel i.

S(E) is the true spectrum

(in units of photons/s/cm2/keV)

Page 5: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

5

Redistribution: line spreadNo detector is perfect. In real life the spectrum you get out is not exactly what you put in. This plot shows the energy redistribution of an EPIC camera from XMM-Newton. This is the detector output from a monochromatic (6.4 keV) input.This limits the energy resolution.

Page 6: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

6

The response matrixThe response (or redistribution) matrix R(i, E) gives the probability that a photon with energy E will be detected in channel i.

E

i ESEiRC )(),(~

Page 7: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

7

Effective area

The effective collecting area of the telescope and detector as function of energy. Product of :• detector efficiency, • mirror reflectivity, • mirror geometrical cross-section…

Page 8: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

8

“uncertainties”: X-ray data

X-ray detectors record individual X-ray events – “counts” – per detector channel. These are subject to Poisson (counting) statistics, i.e. the number of counts is drawn from the distribution:

eC

CpC

!)|(

This gives the probability of observing exactly C (integer) counts if μ is the expected number (true flux).

As the number of counts increases this distribution converges to the familiar Gaussian distribution with a mean of μi and a one sigma “error” of μi.

For an observed number of counts Ci we assign the familiar standard deviation Ci.

Page 9: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

9

Poisson vs. GaussComparison of Poisson distribution (dotted) with Gaussian distribution (solid curve) having the same mean and variance. Rule of thumb: Poisson distribution is usually ‘close enough’ to Gaussian when μ >20.

Common practice to bin data such that there are ~20 ct/bin in a spectrum, e.g. using “grppha”

μ=5

μ=10

μ=20

μ=50

Page 10: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

10

The forward fitting methodCannot invert the observed counts-channel spectrum to useful flux-energy spectrum –

no unique solution, very noisy, etc…

So convert the model instead!

Define model

Change modelparameters

Compare to data

Calculate model

Convolve with response

Page 11: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

11

Fit statistics: How to compare data and model

The most used measure of the “goodness” of a fit is Pearson’s chi-square statistic – χ2 – which measures the variance (sum of squares) of the “residuals” (i.e. data minus model)

2

1

2

)(

)()(

N

i i

iiC

where σ(i) is the error on the counts in channel i and μ(i) is the folded model, i.e. including detector response.A smaller χ2 means a better fit (i.e. smaller data-model differences).

Page 12: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

12

Pearson’s χ2 statistic

2

1

2

)(

)()(

N

i i

iiD

Page 13: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

13

Multi-mission spectral fitting packages

• XSPEC (from GSFC/NASA)– Part of HEAsoft– Been around since 1983/1986– The de facto standard – Many spectral models

• Sherpa (from CXC)– http://cxc.harvard.edu/sherpa– Part of CIAO (for Chandra)– Uses XSPEC model library– Some advanced stats routines– Multi-dimensional fitting

• ISIS (from MIT)– http://space.mit.edu/CXC/ISIS– Distributed computation– Highly programmable– Uses XSPEC model library

• SPEX (from SRON)– Specialised for high-resolution plasma modelling

Page 14: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

14

Using XSPEC

• Loading data• Generating a model• Fitting the model to data• Saving what you have done• Plotting your results• Using multiple datasets• Simulating data• Examples of real data

Page 15: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

15

Input files

The data:• Source spectrum gives the counts per

channel (*.pha)• Background spectrum (*.pha)

The instrument:• Detector “response matrix” –

conversion from photons at energies to counts in channels (*.rmf)

• “Ancillary” response file (*.arf) –effective area of detector

NB: Sometimes: rmf+arf = *.rsp

Page 16: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

16

First steps with XSPEC

• lhea-setup-new (initialise)

• xspec (start XSPEC)

data spec.pha (load spectrum)

back back.pha (background)

resp resp.rmf(redist. matrix)

arf resp.arf (ancillary resp.)

cpd /xs (set plot device)

setplot energy (plot in keV)

ignore **-0.5 10.0-** plot data (plot data)

show (data info)(NB: The initialisation command may change)

Page 17: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

17

“Raw” X-ray spectral data

Page 18: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

18

Non X-ray data• XSPEC can be used to fit any binned,

1-dimensional dataset– optical spectra, power spectrum, …

• Use the tool flx2xsp to convert from ASCII file to XSPEC files

• Input ASCII file in 4 columns• E_low(i)• E_high(i)• Flux(i) i.e. flux density * [E_high-E_low]• Error(i)

• Ensure bins are contiguous• i.e. E_high(i) = E_low(i+1)

• Output is a spectrum (*.pha) and a ‘dummy’ response file (*.rsp) ready to load into XSPEC

• Although XSPEC works in energy units, your data do not need to be in energy bins… (rename the axis)

Page 19: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

19

X-ray spectral models

• Additive models – emission components, e.g. blackbody or emission line.

• Multiplicative models – modifies the emission spectrum, e.g. absorption by neutral gas

X-ray spectral models are built up from smaller components. There are two main types of model component:

)( 23121 AmAmmM

Page 20: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

20

Example modelsFrequently used additive models:• Power law (pow)• Blackbody (bb)• Bremsstrahlung (bremss)• Collisional plasma (mekal)• Gaussian emission line (gaus)• More detailed models such as Compton

scattering, thermal accretion disc, …

Frequently used multiplicative models:• Photoelectric absorption due to neutral gas,

e.g. in our Galaxy (wabs, phabs, TBabs)• Photoelectric absorption due to ionized

(“warm”) gas (absori)• Individual photoelectric edges (edge) and

absorption lines (gabs)• Exponential roll-over (expabs)

Page 21: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

21

Building a model model wabs*(pow)

– wabs = neutral absorption (NH)

– pow = power law (Γ, N)

editmod wabs*(pow+gaus) gaus = Gaussian (E, σ, N)

plot model

Page 22: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

22

Fitting a model

Adjust model parameters to minimise χ2

>fitPlot data (in log-space) and Δχ residuals

>plot ldata del

Page 23: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

23

XSPEC12>model mekal

Input parameter value, delta, min, bot, top, and max values for ... 1 0.01 0.0808 0.0808 79.9 79.9mekal:kT>9 0.01 1 -0.01 1e-06 1e-05 1e+19 1e+20mekal:nH> 1 -0.01 0 0 1000 1000mekal:Abundanc>0.5 0.001 0 -0.01 0 0 10 10mekal:redshift>0.25 1 switchmekal:switch> 1 0.01 0 0 1e+24 1e+24mekal:norm>

=================================================Model mekal<1> Source No.: 1 Active/OnModel Model Component Parameter Unit Value par comp 1 1 mekal kT keV 9.00000 +/- 0.0 2 1 mekal nH cm-3 1.00000 frozen 3 1 mekal Abundanc 0.500000 +/- 0.0 4 1 mekal redshift 0.250000 frozen 5 1 mekal switch 1 frozen 6 1 mekal norm 1.00000 +/- 0.0 _______________________________________________________

Chi-Squared = 3.966551e+08 using 750 PHA bins. Reduced chi-squared = 530997.4 for 747 degrees of freedom Null hypothesis probability = 0.000000e+00

Page 24: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

24

XSPEC12>fit

Chi-Squared Lvl Par # 1 3 6 819.316 -3 7.02352 0.308761 0.0105194 802.042 -4 7.09851 0.347419 0.0105871 802.042 -5 7.09814 0.347367 0.0105868 ================================================= Variances and Principal Axes 1 3 6 2.95E-09 | 0.00 0.00 -1.00 1.44E-02 | -1.00 0.02 0.00 4.44E-04 | -0.02 -1.00 0.00-----------------------------------------================================================= Covariance Matrix 1 2 3 1.443e-02 -2.200e-04 -6.073e-06 -2.200e-04 4.479e-04 -1.034e-06 -6.073e-06 -1.034e-06 8.361e-09 ------------------------------------------=================================================Model mekal<1> Source No.: 1 Active/OnModel Model Component Parameter Unit Value par comp 1 1 mekal kT keV 7.098 +/- 0.1201 2 1 mekal nH cm-3 1.00000 frozen 3 1 mekal Abundanc 0.3474 +/- 2.116E-02 4 1 mekal redshift 0.2500 frozen 5 1 mekal switch 1 frozen 6 1 mekal norm 1.059E-02 +/-9.144E-05 _______________________________________________________

Chi-Squared = 802.04 using 750 PHA bins. Reduced chi-squared = 1.0737 for 747 degrees of freedom Null hypothesis probability = 7.962138e-02

Page 25: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

25

Searching χ2-space

The parameters of the model θi are varied and the combination that gives the lowest χ2 is the “best fit”. XSPEC uses a ‘local’ search algorithm to find the minimum of the space defined by χ2(θ).Can get lost in local minima. WARNING: Start in a sensible place and experiment with different initial positions.

Page 26: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

26

Searching χ2-space

The parameters of the model θi are varied and the combination that gives the lowest χ2 is the “best fit”. XSPEC uses a ‘local’ search algorithm to find the minimum of the space defined by χ2(θ).Can get lost in local minima. WARNING: Start in a sensible place and experiment with different initial positions.

Page 27: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

27

χ2 minimisation issues

The problem: find min[χ2(θ)] with as few iterations as possible. (Imagine searching 10-dimensional parameter space!)

1) Calculate χ2 at present position. 2) Calculate gradient χ2 based on finite differences i.e.

3) Adjust parameter θi θi+1 in direction of lower χ2

χ2(θ)θ

Pii

iiii

i

,,2,12

)()( 222

Page 28: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

28

χ2 minimisation issues

Make sure you set parameter step sizes to sensible values!

> newpar 1> par1> 2.00 0.01 0.00 0.00 10.00 10.00

χ2(θ)θ

Parameter value θParameter step size ∆θHard & soft minimumSoft & hard maximum

-∆θ +∆θ

Page 29: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

29

χ2 minimisation issues

Watch out for local minima!

a) Try fitting same model from different initial positions

b) Perturb the current fit using the “error” command

(This last options forces the parameter “uphill” in χ2 which may push it over and into a better maximum”)

χ2(θ)θ

Page 30: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

30

Why is XSPEC so slow?

E

ESEAEiRTi )()(),()(

2

1

2

)(

)()(

N

i i

iiC

Pii

iiii

i

,,2,12

)()( 222

At each iteration XSPEC calculates the gradient of the fit statistic χ2 using:

which requires 2P evaluations of χ2

each of which requires a model calculation S(E) followed by a matrix multiplication:

So with a 10242 response matrix R and a 6 parameter model that means >107 calculations per iteration (assuming the model is trivial)!

Page 31: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

31

Making plots (using IP)

>ip (interactive plotter, uses QDP)

>la x <x-axis label>>la y <y-axis label>>la f <filename>>la t <title>>time <on/off>>font <normal/roman/script>>cs <font size, e.g. 1.2>>lw <line width, e.g. 3>>plot >hardcopy /ps, (or /gif etc…)>exit

>

Page 32: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

32

Multiple spectra

XSPEC can fit several spectra simultaneously with the same model. This might be useful if you have, for example, simultaneous observations with Chandra and XMM and you want to use BOTH spectra to constrain the model.

>data 1:1 spec1.pha>resp 1:1 resp1.rmf>data 2:2 spec2.pha>resp 2:2 resp2.rmf

Page 33: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

33

Simulating data

You may need to simulate (“fake”) some data, to see how a given model would look during an observation. First define the model and, for a no-background simulation, use:

> fakeit none

Then enter the response file name(s), the exposure time (in sec) and the output filename.

If you want to include a background spectrum (e.g. bkg.pha) in your simulation:

> fakeit bkg.pha

Page 34: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

34

Miscellaneous commands

> save files <filename.xcm>> save model <filename.xcm>> save all <filename.xcm>

> delcomp <no.> (delete model comp.)

> freeze <no.> (stop a param. varying)

> thaw <no.> (un-freeze param.)

> newpar <no.> (modify param.)

> flux <Elo> <Ehi> (flux in E band)

> cosmo <H0 , q0 , Λ0> (set cosmology)

> lum <Elo> <Ehi> <reshift>

> setplot <en, wave, chan, …>> plot <d,ld,del,chi,res,uf,m,…>> exit (quit XSPEC)

Page 35: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

35

γ-ray Burst: GRB 031203

>model wabs*pow>fit

χ2=160.1 for ν=174 (Prej=29%)

Page 36: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

36

Seyfert galaxy: Mrk 79

>model wabs*(pow+bb+gaus)>freeze 7 (stop line width

varying)

>fitχ2=492.0 for ν=485 (Prej=68%)

Page 37: 1 An Introduction to X-ray Spectral Fitting I: Getting started with XSPEC Other material XSPEC manual:

37

Do try this at home…

A worked example showing exactly how to:

• Load data• Set-up a model• Adjust the parameters• Get a good fit• Make plots• Get confidence regions• Examine contour plots

http://www.star.le.ac.uk/~sav2/stats