This is a fixed-text formatted version of a Jupyter notebook.

# Computation of the CTA sensitivity¶

## Introduction¶

This notebook explains how to derive the CTA sensitivity for a point-like IRF at a fixed zenith angle and fixed offset. The significativity is computed for the 1D analysis (On-OFF regions) and the LiMa formula.

We will be using the following Gammapy classes:

## Setup¶

In [1]:

%matplotlib inline
import matplotlib.pyplot as plt

In [2]:

from gammapy.irf import CTAPerf
from gammapy.spectrum import SensitivityEstimator

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-b9f53885d5c3> in <module>
----> 1 from gammapy.irf import CTAPerf
2 from gammapy.spectrum import SensitivityEstimator

ImportError: cannot import name 'CTAPerf' from 'gammapy.irf' (/Users/deil/work/code/gammapy-docs/build/dev/gammapy/gammapy/irf/__init__.py)


In [3]:

filename = "$GAMMAPY_EXTRA/datasets/cta/perf_prod2/point_like_non_smoothed/South_5h.fits.gz" irf = CTAPerf.read(filename)  --------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-3-b41a41c65272> in <module> 1 filename = "$GAMMAPY_EXTRA/datasets/cta/perf_prod2/point_like_non_smoothed/South_5h.fits.gz"

NameError: name 'CTAPerf' is not defined


## Compute sensitivity¶

Choose a few parameters, then run the sentitivity computation.

In [4]:

sensitivity_estimator = SensitivityEstimator(irf=irf, livetime="5h")
sensitivity_estimator.run()

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-6e82811d30c1> in <module>
----> 1 sensitivity_estimator = SensitivityEstimator(irf=irf, livetime="5h")
2 sensitivity_estimator.run()

NameError: name 'SensitivityEstimator' is not defined


## Results¶

The results are given as an Astropy table.

In [5]:

# Show the results table
sensitivity_estimator.results_table

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-4efcdd92d4bb> in <module>
1 # Show the results table
----> 2 sensitivity_estimator.results_table

NameError: name 'sensitivity_estimator' is not defined

In [6]:

# Save it to file (could use e.g. format of CSV or ECSV or FITS)
# sensitivity_estimator.results_table.write('sensitivity.ecsv', format='ascii.ecsv')

In [7]:

# Plot the sensitivity curve
t = sensitivity_estimator.results_table

is_s = t["criterion"] == "significance"
plt.plot(
t["energy"][is_s],
t["e2dnde"][is_s],
"s-",
color="red",
label="significance",
)

is_g = t["criterion"] == "gamma"
plt.plot(
t["energy"][is_g], t["e2dnde"][is_g], "*-", color="blue", label="gamma"
)

plt.loglog()
plt.xlabel("Energy ({})".format(t["energy"].unit))
plt.ylabel("Sensitivity ({})".format(t["e2dnde"].unit))
plt.legend();

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-7-1c25fd00268d> in <module>
1 # Plot the sensitivity curve
----> 2 t = sensitivity_estimator.results_table
3
4 is_s = t["criterion"] == "significance"
5 plt.plot(

NameError: name 'sensitivity_estimator' is not defined


## Exercises¶

• Also compute the sensitivity for a 20 hour observation
• Compare how the sensitivity differs between 5 and 20 hours by plotting the ratio as a function of energy.
In [8]: