# The HRC-I Background Spectra Files

## Overview

Last Update: 10 Jun 2010 - new for CIAO 4.2/CALDB 4.3.0

Synopsis:

The HRC calibration team has released a set of background spectra from the HRC-I. These spectra describe the particle background of the detector and vary slowly with time which means that they can be used to improve the signal-to-noise of HRC-I imaging data.

Purpose:

Optimal selection of the PI range for HRC-I imaging data.

To create an HRC-I background event file tailored to a specific observation for imaging or spatial analyses, follow the HRC-I Background Event Files thread instead.

you are analyzing HRC-I imaging data and want to reduce the background level in the data. This can significantly improve signal-to-noise for extended sources and may be useful for point source analysis (e.g.fields with many point sources).

• CALDB v4.3.0 (10 Jun 2010):

The HRC background files were first released in CALDB 4.3.0.

The background spectra file are included in the main CALDB tarfile.

## Get Started

Sample ObsID used: 9700 (HRC-I, Cas A)

File types needed: evt2; asol1; bpix1; dtf1

This thread uses the hrc_bkgrnd_lookup script.

The script is part of the CIAO Scripts distribution. The CIAO scripts package should be the following version or newer:

unix% cat $ASCDS_CONTRIB/VERSION.CIAO_scripts 09 June 2010  Please check that you have at least this version of the scripts package installed before continuing. If you do not have the scripts installed or need to update to a newer version, refer to the Scripts page. ## Obtain the Response Files: ARF and RMF This analysis requires an ARF and RMF. This section of the thread provides the necessary commands; refer to the ahelp files for asphist and mkarf for details. The HRC-I RMF distributed in the CALDB is used; we link it from the working directory for easier access: unix% ln -s$CALDB/data/chandra/hrc/rmf/hrciD1999-07-22samprmfN0001.fits rmf.fits


Next we create an asphist histogram, which is a binned representation of aspect motion during the observation. In many cases, there will be more than one aspect solution file (pcad_asol1.fits) for an observation. All the files must be input to the infile parameter, either as a list or as a stack. Here we use:

unix% cat pcad_asol1.lis

evtfile=hrcf09700_evt2.fits dtffile=hrcf09700_000N001_dtf1.fits


The aspect histogram is used as input to mkarf, which creates the ARF file. The source location is given as (16384.5,16384.5), the aimpoint of the HRC-I detector.

unix% pset ardlib AXAF_HRC-I_BADPIX_FILE=hrcf09700_new_bpix1.fits

unix% mkarf "9700_asphist.fits[ASPHIST]" 9700_arf.fits \
sourcepixelx=16384.5 sourcepixely=16384.5 \
engrid="grid(rmf.fits[cols ENERG_LO,ENERG_HI])" \
obsfile=hrcf09700_evt2.fits detsubsys=HRC-I mode=h


The resulting ARF file is named 9700_arf.fits.

## Choosing the Correct File

### Naming scheme

The HRC background datasets are stored in the CALDB at $CALDB/data/chandra/hrc/pibgspec/. They are indexed by time and aimpoint: unix% ls -1$CALDB/data/chandra/hrc/pibgspec/
hrciD1999-10-04pibgspecN0001.fits
hrciD2000-12-12pibgspecN0001.fits
hrciD2002-01-26pibgspecN0001.fits
hrciD2003-02-22pibgspecN0001.fits
hrciD2004-11-25pibgspecN0001.fits
hrciD2005-10-17pibgspecN0001.fits
hrciD2006-09-20pibgspecN0001.fits
hrciD2007-09-17pibgspecN0001.fits
hrciD2008-09-07pibgspecN0001.fits
hrciD2009-09-24pibgspecN0001.fits


The naming scheme is hrciD<date>pibgspecN<version>.fits.

### Using hrc_bkgrnd_lookup

The hrc_bkgrnd_lookup script makes it easy to find an HRC-I background file that matches your data. The script takes an input event file and what background filetype is desired - event or spectrum - and returns the background file:

unix% hrc_bkgrnd_lookup hrcf09700_evt2.fits spectrum
/soft/ciao/CALDB/data/chandra/hrc/pibgspec/hrciD2007-09-17pibgspecN0001.fits


In addition to being printed to the screen, the background filename is also stored in the outfile parameter:

unix% pget hrc_bkgrnd_lookup outfile
/soft/ciao/CALDB/data/chandra/hrc/pibgspec/hrciD2007-09-17pibgspecN0001.fits


The background file won't be edited, so we can simply link it from the working directory for easier access:

unix% ln -s \$CALDB/data/chandra/hrc/pibgspec/hrciD2007-09-17pibgspecN0001.fits .


## Compute the cumulative background distribution

The background spectra is used to estimate the reduction in the background signal that the PI filtering will achieve.

unix% sherpa
-----------------------------------------------------
Welcome to Sherpa: CXC's Modeling and Fitting Package
-----------------------------------------------------
CIAO 4.2 Sherpa version 2 Tuesday, July 6, 2010

sherpa> d = get_data()
sherpa> pi = d.channel-1.0
sherpa> bgcumul = np.cumsum(d.counts)
sherpa> bgcdf = bgcumul * 1.0 / bgcumul[-1]

sherpa> set_plot_xlabel("PI")
sherpa> set_plot_ylabel(r"\Sigma (counts \leq PI) / \Sigma counts")
sherpa> set_plot_title(d.name.split("/")[-1])


Note that the calculation for bgcdf assumes that d.counts is >= 0, which should be safe here.

## Compute the cumulative distributions for model spectra

In order to select the PI range we use a soft and hard spectrum to determine the lower and upper limits. For this thread we use an absorbed power law for both cases, varying the absorption and slope to maximize the flux at low or high energies, although other approaches are possible (in particular using a model similar to that of the source).

### Set up an ARF and RMF

We use the background model which we have already loaded to define the channel grid, and add an ARF and RMF to it.

sherpa> load_arf("9700_arf.fits")
sherpa> set_analysis("channel")


The set_analysis call is to ensure that the following modeling is done in PI channels rather than energy or wavelength units.

### Set up the "soft" model

sherpa> set_source(xswabs.abs1*powlaw1d.pl)
sherpa> abs1.NH = 0.001
sherpa> pl.gamma = 2.5
sherpa> plot_model(overplot=False)


The add_window call is used so that the original plot is not deleted by the call to plot_model.

### Calculate the cumulative distribution

sherpa> scumul = np.cumsum(get_model_plot().y)
sherpa> scdf = scumul / max(scumul)

sherpa> current_window("win1")
sherpa> add_curve(pi, scdf, ["symbol.style", "none", "line.color", "red"])


Here we add the cumulative distribution for the soft model to the original plot, so that it can be compared to the background spectra.

### Set up the "hard" model

sherpa> abs1.nh = 10
sherpa> pl.gamma = 1
sherpa> current_window("win2")
sherpa> plot_model(overplot=True)
sherpa> set_histogram(["line.color", "blue"])


### Calculate the cumulative distribution

sherpa> hcumul = np.cumsum(get_model_plot().y)
sherpa> hcdf = hcumul / max(hcumul)
sherpa> current_window("win1")
sherpa> add_curve(pi, hcdf, ["symbol.style", "none", "line.color", "blue"])


## Calculate the PI range

Various strategies could be employed to optimize the PI range. Ideally, we seek to maximize background reduction while minimizing loss of source events. In practice, the trade-off requires testing many different PI ranges and adopting one that suits best. One strategy is to require a certain amount of reduction in background, compute the appropriate PI range, and then estimate the magnitude of source event loss for a specific source model. Alternately, one could set forth an acceptable amount of source loss (sensible ranges are 1 to 10 per cent), compute the appropriate PI range, and then check how much of an improvement results in the background.

This thread follows the latter strategy. We will use a conservative strategy, and look to exclude 5% of source events, split equally over the low and high PI ranges. If xfrac is the fraction of events to exclude and is set to 5%, then we have

sherpa> xfrac = 0.05
sherpa> pimin = np.interp(xfrac/2, scdf, pi)
sherpa> pimax = np.interp(1-xfrac/2, hcdf, pi)
sherpa> lo = int(pimin)
sherpa> hi = int(pimax) + 1

sherpa> print ("PI range: %d to %d" % (lo,hi))
PI range: 48 to 293


Here we chose to round the minimum limit down and the maximum limit up; routines in the Python math module, such as floor and ceil can be used to implement different rounding strategies.

The lo to hi range can then be used to filter the level=2 event file when creating images.

## Calculating the background reduction

The PI range can be viewed by saying:

sherpa> current_window("win1")


and the fraction of the background that is excluded by these limits is calculated by:

sherpa> blo = np.interp(lo, pi, bgcdf)
sherpa> bhi = 1.0 - np.interp(hi, pi, bgcdf)
sherpa> bfrac = bhi + blo

sherpa> print("Fraction of background excluded is %g" % bfrac)
Fraction of background excluded is 0.245608


Filtering on the range PI=48:293 will reduce the background by ~25% while only losing ~5% of x-ray events.

## Apply the PI Filter

The PI range 48:293 is applied to the file in a Data Model filter:

unix% punlearn dmcopy
unix% dmcopy "hrcf09700_evt2.fits[pi=48:293]" hrcf09700_evt2_pi_flt.fits


A background annulus is defined around the source to check the number of "good" events in the filtered and unfiltered files:

unix% cat bkg.reg
# Region file format: CIAO version 1.0
annulus(16368.483,16336.472,2731.4111,4097.1167)

unix% dmstat "hrcf09700_evt2.fits[sky=region(bkg.reg)][cols pi]" ver=0
unix% pget dmstat out_good
54713

unix% dmstat "hrcf09700_evt2_pi_flt.fits[sky=region(bkg.reg)][cols pi]" ver=0
unix% pget dmstat out_good
42567


The percent change between the files is ~22% [(54713-42567)/54713 = 22], which is close to the 24% reduction we expected.

## History

 10 Jun 2010 new for CIAO 4.2/CALDB 4.3.0