Detector Response Matrix (DRM) Implementation
#Convolution Approximations
#Performance
#Usage
#User Performance Studies
Here is a description of the binned likelihood calculation.
Detector Response Matrix (DRM) Implementation
The DRM is the matrix that transforms a binned counts spectrum from true energies to measured energies:
Latex |
---|
\begin{equation}
n_{k^\prime} = \sum_k D_{kk^\prime} n_k \nonumber
\end{equation}
|
where
Latex |
---|
$n_{k^\prime}$ |
Latex |
---|
$k^\prime$ |
Latex |
---|
$n^k$ |
Latex |
---|
$k$ |
Latex |
---|
\begin{equation}
D_{kk^\prime} = \frac{\int d\theta d\phi \left[\int_{\Delta E_{k^\prime}} dE^\prime D(E^\prime; E_k, \theta, \phi)\right] A(E_k, \theta, \phi) lt(\theta, \phi)}{\int d\theta d\phi A(E_k, \theta, \phi) lt(\theta, \phi)} \nonumber
\end{equation}
|
Here
Latex |
---|
$D(E^\prime; E, \theta, \phi$) |
Latex |
---|
$A(E, \theta, \phi)$ |
Latex |
---|
$lt(\theta, \phi)$ |
Latex |
---|
$E_k$ |
Latex |
---|
$k$ |
Latex |
---|
$k^\prime$ |
In principle, the DRM should be evaluated at each sky pixel position in the binned counts map, but we make the approximation that the DRM does not change much over the counts map region and just evaluate it at the map center and assume it applies everywhere on the map. This is supported by these plots of the energy dispersion evaluated at various points on the sky for a one-day survey mode integration:
Convolution Approximations
The model counts cubes used by the binned analysis are 2D spatial arrays of sky pixels with a counts spectrum at each pixel location forming the third dimension. When energy dispersion is neglected, the model counts spectrum is a function of true energy, but with the other aspects of the instrument response applied (i.e., effective area and PSF). To complete the forward-folding of the model counts, we simply need to apply the DRM to the true counts spectrum at each pixel. Unfortunately, there are two constraints that prevent us from doing this:
- To save execution time, the log-likelihood is evaluated using only the pixels that have non-zero data counts (as opposed to model counts). This can be seen in the expression for the Poisson log-likelihood,
Latex \begin{equation} \log{\cal L} = \sum_j \left[n_j\log\theta_j - \theta_j\right] \nonumber \end{equation}
where
is the observed count in pixelLatex $n_j$
andLatex $j$
is the model counts for that pixel. In the current implementation, this means that model counts are only computed for those non-zero pixels. For sparse datasets (e.g., short integration times or at higher energies), this speeds up the calculation substantially: at least an order of magnitude for 1 day integrations. Applying the DRM to each pixel counts spectrum would require the model calcuation to be made for every pixel in the counts cube, even if it is empty. However, assuming binned analysis is generally used for longer observations, and most pixels are occupied, this may not be a real limitation.Latex $\theta_j$
- A more serious problem is applying the DRM convolution to the true counts spectrum at each pixel location. If the number of energy bins is
, the convolution is anLatex $n_e$
operation. ForLatex ${\cal O}(n_e^2)$
, this results in about a factor of 900 slow down in computing the expected pixel counts that go into the log-likelihood.Latex $n_e = 30$
Since we need to compute the total predicted counts for each component, we have the total counts spectrum in true energy space (This is easily obtained for each source by integrating each energy plane over angle in the associated source map and multiplying by the spectral function.) We can then convolve the spatially integrated true energy counts spectrum with the DRM to obtain the overall measured energy counts spectrum. We form the ratio of the convolved model counts to unconvolved model counts in each energy bin. When computing the contribution to the log-likelihood from each pixel
Latex |
---|
$j$ |
Performance
Composition Setup |
---|
Deck of Cards | ||
---|---|---|
| ||
Card | ||
---|---|---|
| ||
I've simulated a single point source with indices 1.25, 1.50, 2.00, 2.50, 3.00, generating 70-100k events for each case for a week long observation with idealized +/-50 deg rocking and fit those data with and without energy dispersion handling enabled:
The blue model curves and residual points correspond to the fit with energy dispersion turned off, while the red curves and residual points correspond to energy dispersion turned on. The corresponding data files have columns of
Emin | Emax | obs. counts | model counts w/ edisp | model counts w/out edisp |
The input spectra to gtobssim covered 20 to 1e6 MeV and the energy range selection for the binned analysis was 30 to 3e5 MeV, with 40 logarithmically spaced bins.
Photon index best-fit values
MC index | edisp handling | no edisp handling |
---|---|---|
1.25 | -1.253 +/- 1.86e-03 | -1.260 +/- 1.86e-03 |
1.50 | -1.505 +/- 2.19e-03 | -1.516 +/- 2.19e-03 |
2.00 | -2.007 +/- 3.20e-03 | -2.031 +/- 3.20e-03 |
2.50 | -2.525 +/- 4.17e-03 | -2.557 +/- 4.03e-03 |
3.00 | -3.036 +/- 4.97e-03 | -3.063 +/- 4.74e-03 |
Card |
---|
Card | ||
---|---|---|
| ||
For these tests, a point source with an exponentially cut-off power-law spectrum is modeled and fit for different values of the photon index. The cutoff energy is fixed at 1 GeV, and values of photon index = 1.25, 1.5, 2.0, 2.5, 3.0 are used. These tests are similar to those shown in fig. 68 of v1r0 of the LAT performance paper.
Simulations are performed for P7SOURCE_V6 and DC1A IRFs and these simulations are analyzed with and without the energy dispersion handling turned on for the standard gtobssim output and without the energy dispersion handling but using the MC values for the ENERGY column which is attained simply by swapping the labels on the ENERGY and MCENERGY columns in the FT1 file. Note that this swap was done prior to making an energy range selection.
- Input XML model to gtobssim
The flux for each source was adjusted so that 100000 events are generated for a week long idealized survey mode observation using P7SOURCE_V6.Code Block <source_library title="cutoff_pl_source"> <source name="cutoff_pl_source_3"> <spectrum escale="MeV" flux="20" particle_name="gamma"> <SpectrumClass name="FileSpectrum" params = "flux=1, specFile=Cutoff_PowerLaw_-3.00.txt"/> <celestial_dir ra="266.4" dec="-28.9"/> </spectrum> </source> <source name="cutoff_pl_source_2.5"> <spectrum escale="MeV" flux="7.8" particle_name="gamma"> <SpectrumClass name="FileSpectrum" params = "flux=1, specFile=Cutoff_PowerLaw_-2.50.txt"/> <celestial_dir ra="266.4" dec="-28.9"/> </spectrum> </source> <source name="cutoff_pl_source_2"> <spectrum escale="MeV" flux="3" particle_name="gamma"> <SpectrumClass name="FileSpectrum" params = "flux=1, specFile=Cutoff_PowerLaw_-2.00.txt"/> <celestial_dir ra="266.4" dec="-28.9"/> </spectrum> </source> <source name="cutoff_pl_source_1.5"> <spectrum escale="MeV" flux="1.14" particle_name="gamma"> <SpectrumClass name="FileSpectrum" params = "flux=1, specFile=Cutoff_PowerLaw_-1.50.txt"/> <celestial_dir ra="266.4" dec="-28.9"/> </spectrum> </source> <source name="cutoff_pl_source_1.25"> <spectrum escale="MeV" flux="0.73" particle_name="gamma"> <SpectrumClass name="FileSpectrum" params = "flux=1, specFile=Cutoff_PowerLaw_-1.25.txt"/> <celestial_dir ra="266.4" dec="-28.9"/> </spectrum> </source> </source_library>
- The template spectra were generated with this python script, using the PLSuperExpCutoff model that is available from pyLikelihood. This same model was used in the spectral fitting to ensure consistency.
Results
- P7SOURCE_V6
The red and green points substantially agree, as one would hope, and the trend is towards a harder measured spectra, as expected. However, there seems to be a residual bias in the edisp-on and MC results towards harder spectra.edisp-off
edisp handling turned off
edisp-on
edisp handling turned on
MC
edisp handling turned off, but using MCENERGY values
- DC1A (source fluxes were adjust to produce 200000 events)
Here the differences between the three cases is much smaller, but edisp-on and MC still agree better. The same residual bias persists.Card
Figure 68 of the instrument performance paper (v1r0) shows the "fractional" error on the photon index for a power-law and cutoff power-law model for different input indices:Card label Comparison with Instrument Performance Paper Figure
Using the same data that went into those simulations, here are the comparisons using energy dispersion handling:In each plot, the black points are obtained from refitting the data without energy dispersion handling (consistent with the paper figure), and the red points are the results obtained with energy dispersion turned on.Card Card label Soft power-law source, isotropic diffuse background - The xml model that was input to gtobssim
Code Block <source_library title="soft_source"> <source flux="1" name="soft_source"> <spectrum escale="MeV"> <particle name="gamma"> <power_law emax="1000000.0" emin="20.0" gamma="2.5"/> </particle> <celestial_dir dec="-28.9" ra="266.4"/> </spectrum> </source> <source name="test_isotropic"> <spectrum escale="MeV"> <SpectrumClass name="Isotropic" params="100, 2.1, 20., 2e5"/> <use_spectrum frame="galaxy"/> </spectrum> </source> </source_library>
- The model used in the binned analysis
Code Block <?xml version="1.0" ?> <source_library title="source library"> <source name="test_source" type="PointSource"> <!-- point source units are cm^-2 s^-1 MeV^-1 --> <spectrum type="PowerLaw2"> <parameter free="1" max="1000.0" min="1e-05" name="Integral" scale="1e-06" value="1.0"/> <parameter free="1" max="-1.0" min="-5.0" name="Index" scale="1.0" value="-2.0"/> <parameter free="0" max="200000.0" min="20.0" name="LowerLimit" scale="1.0" value="20.0"/> <parameter free="0" max="200000.0" min="20.0" name="UpperLimit" scale="1.0" value="2e5"/> </spectrum> <spatialModel type="SkyDirFunction"> <parameter free="0" max="360.0" min="-360.0" name="RA" scale="1.0" value="266.4"/> <parameter free="0" max="90.0" min="-90.0" name="DEC" scale="1.0" value="-28.9"/> </spatialModel> </source> <source name="Extragalactic Diffuse" type="DiffuseSource"> <spectrum type="PowerLaw2"> <parameter free="1" max="1000.0" min="0.0" name="Integral" scale="1e-06" value="1.0"/> <parameter free="1" max="-1.0" min="-5.0" name="Index" scale="1.0" value="-2.1"/> <parameter free="0" max="200000.0" min="20.0" name="LowerLimit" scale="1.0" value="20.0"/> <parameter free="0" max="200000.0" min="20.0" name="UpperLimit" scale="1.0" value="200000.0"/> </spectrum> <spatialModel type="ConstantValue"> <parameter free="0" max="10.0" min="0.0" name="Value" scale="1.0" value="1.0"/> <parameter free="0" max="10.0" min="0.0" name="Value" scale="1.0" value="1.0"/> </spatialModel> </source> </source_library>
- Distributions from simulations. The leftmost plot in each row is the parameter distribution obtained from the standard analysis with the energy dispersion handling turned off. The middle plot has energy dispersion handling turned on. The rightmost plot uses the MC energy values in the analysis and has energy dispersion handling turned off.
- Photon Index of the soft point source.
- Photon Index of the isotropic component.
Card Card label Exponential cut-off with isotropic diffuse
- Photon Index of the soft point source.
- Input model to gtobssim:
Code Block <source_library title="cutoff_pl_source"> <source name="cutoff_pl_source"> <spectrum escale="MeV" flux="1" particle_name="gamma"> <SpectrumClass name="FileSpectrum" params = "flux=1e-2, specFile=$(rootdir)/Cutoff_PowerLaw.txt"/> <celestial_dir ra="266.4" dec="-28.9"/> </spectrum> </source> <source name="test_isotropic"> <spectrum escale="MeV"> <SpectrumClass name="Isotropic" params="100, 2.1, 20., 2e5"/> <use_spectrum frame="galaxy"/> </spectrum> </source> </source_library>
- Likelihood model
Code Block <?xml version="1.0" ?> <source_library title="source library"> <source name="test_source" type="PointSource"> <!-- point source units are cm^-2 s^-1 MeV^-1 --> <spectrum type="PLSuperExpCutoff"> <parameter free="1" max="1e3" min="1e-5" name="Prefactor" scale="1e-07" value="1.0"/> <parameter free="1" max="0.0" min="-5.0" name="Index1" scale="1.0" value="-1.7"/> <parameter free="0" max="1000.0" min="50.0" name="Scale" scale="1.0" value="200.0"/> <parameter free="1" max="30000.0" min="500.0" name="Cutoff" scale="1.0" value="3000.0"/> <parameter free="0" max="5.0" min="0.0" name="Index2" scale="1.0" value="1.0"/> </spectrum> <spatialModel type="SkyDirFunction"> <parameter free="0" max="360.0" min="-360.0" name="RA" scale="1.0" value="266.4"/> <parameter free="0" max="90.0" min="-90.0" name="DEC" scale="1.0" value="-28.9"/> </spatialModel> </source> <source name="Extragalactic Diffuse" type="DiffuseSource"> <spectrum type="PowerLaw2"> <parameter free="1" max="1e3" min="1e-5" name="Integral" scale="1e-06" value="1.0"/> <parameter free="1" max="-1.0" min="-5.0" name="Index" scale="1.0" value="-2.1"/> <parameter free="0" max="200000.0" min="20.0" name="LowerLimit" scale="1.0" value="20.0"/> <parameter free="0" max="200000.0" min="20.0" name="UpperLimit" scale="1.0" value="2e5"/> </spectrum> <spatialModel type="ConstantValue"> <parameter free="0" max="10.0" min="0.0" name="Value" scale="1.0" value="1.0"/> </spatialModel> </source> </source_library>
- Distributions
- Photon index (Index1) of the exponentially cutoff power-law of the point source.
- Cutoff energy of the point source.
- Photon index of the isotropic component.
Card Deck of Cards
- Photon index (Index1) of the exponentially cutoff power-law of the point source.
Usage
To enable the energy dispersion handling (in ST-09-26-00 and later), set the USE_BL_EDISP environment variable:
Code Block |
---|
% setenv USE_BL_EDISP
|
To disable it, unset the env var:
Code Block |
---|
% unsetenv USE_BL_EDISP
|
This functionality can also be turned on and off in python at runtime:
Code Block |
---|
>>> import os
>>> os.environ['USE_BL_EDISP'] = "1" # The precise value doesn't matter
>>> del os.environ['USE_BL_EDISP'] # In a script, this should probably be enclosed in a try/except block
|
In ST-09-28-00 and later, energy dispersion handling may be turned on in python for individual binned analysis objects:
Code Block |
---|
>>> like = binnedAnalysis(...)
>>> like.logLike.set_edisp_flag(True) # Turn on energy dispersion handling
>>> print like.logLike.use_edisp() # Check if edisp handling is turned on
>>> like.logLike.set_edisp_flag(False) # Turn off
|
This will allow binned analysis objects within a single python script to have energy dispersion handling turned on or off independently, whereas the environment variable switch will affect all analysis objects within the script the same way.
User Performance Studies
- A closer look at the energy dispersion - Stefan
- Energy dispersion studies using the smoothly broken powerlaw model - Jim
Energy Dispersion approximations
- Current (ST-09-25-02 and earlier) latResponse::Edisp2 does not interpolate the energy dispersion parameters from the IRF tables. This is because the parameters do not vary smoothly from bin to bin in log10(E)-cos(theta) space.
Wiki Markup It does apply a scale factor to the fractional energy difference, (Emeas - E)/E, that is a continuous function of log10(E) and cos(theta):\\ scaleFactor = p0\*log10(E)\*\*2 + p1\*cos(theta)\*\*2 + p2\*log10(E) + p3\*cos(theta) + p4\*log10(E)\*cos(theta) + p5\\ The p\[0-5\] are determined empirically (and hardcoded since P6 at least!) to make the 68% containment "radius" in energy space be approximately 1, independent of energy.
- In order to have a properly normalized energy dispersion function, application of this scale factor forces the standard implementation to renormalize the Edisp2 function for every function call that requests a log10(E)-cos(theta) pair that differs from the previous function call. This is computationally costly, but it did not matter much for just making performance plots (presumably, this would impact running gtrspgen.)
- The calls to Edisp2 are contained within the DRM generation, and that step can take a substantial amount of time. In order to speed that up, the scaleFactor(log10(E), cos(theta)) function is only evaluated at the grid points, the normalization parameters in the Edisp tables are adjusted, and when function calls to Edisp2 are made, the nearest log10(E)-cos(theta) grid points are used, just as for the Edisp parameters themselves.
- Here is the impact on one of the standard performance plots:
black=Front, red=Back, both with scaleFactor as a continuous function of log10(E), cos(theta); green=Front, red=Back, both with scaleFactor evaluated at the nearest log10(E)-cos(theta) grid point.
Detector Response Matrix (DRM) implementation
Convolution approximations
...