simArp220_new.py
1 |
#! /usr/bin/env python
|
---|---|
2 |
# ==========================================================================
|
3 |
# This script simulates CTA observations of Arp220
|
4 |
#
|
5 |
# Author: Rolf Buehler (rolf.buehler@desy.de)
|
6 |
# Date: 20.3.2014
|
7 |
# ==========================================================================
|
8 |
import gammalib as gl |
9 |
import obsutils as obsu |
10 |
|
11 |
def simarp220(obstime=100.*3600.,write=False): |
12 |
""""Simulates and fits Arp220 & background for one run
|
13 |
@param [float] obstime Observation duration in seconds
|
14 |
@param [bool] write Write out simulated observations adn fit results
|
15 |
"""
|
16 |
|
17 |
#-----------------------------------------------------
|
18 |
#Create one observation (run)
|
19 |
#-----------------------------------------------------
|
20 |
ra_degree=233.7382 #Arp220 position from NED |
21 |
dec_degree=23.503
|
22 |
offset_degree=-0.5 #Observing offset in dec from Arp220 in deg |
23 |
pntdir = gl.GSkyDir() |
24 |
pntdir.radec_deg(ra_degree, dec_degree+offset_degree) |
25 |
|
26 |
# Calibration database and response
|
27 |
caldb = "aar"
|
28 |
irf = "DESY20140105_50h"
|
29 |
#caldb = "i"
|
30 |
#irf = "IFAE20120510_50h"
|
31 |
|
32 |
ob = obsu.set(pntdir,tstart=0.0,duration=obstime,deadc=0.95, \ |
33 |
emin=0.1, emax=10.0, rad=3.0, irf=irf, caldb=caldb) |
34 |
ob.id("run_1")
|
35 |
|
36 |
#----------------------------------------------------
|
37 |
# Create background model
|
38 |
#----------------------------------------------------
|
39 |
fixallpars=False
|
40 |
spec = gl.GModelSpectralPlaw(1,0,gl.GEnergy(1.0,"TeV")) |
41 |
bck = gl.GCTAModelInstBackground(spec) |
42 |
bck.name("Background")
|
43 |
bck.instruments("CTA")
|
44 |
if fixallpars :
|
45 |
for par in range(0,bck.size()): |
46 |
bck[par].fix() |
47 |
|
48 |
#----------------------------------------------------
|
49 |
# Create Arp220 model
|
50 |
#----------------------------------------------------
|
51 |
arp220dir = gl.GSkyDir() |
52 |
arp220dir.radec_deg(ra_degree, dec_degree) |
53 |
arp220_spatial = gl.GModelSpatialPointSource(arp220dir) |
54 |
|
55 |
arp220_spectrum = gl.GModelSpectralPlaw(1.0e-19, -2.2,gl.GEnergy(1,"TeV") ) |
56 |
arp220 = gl.GModelSky(arp220_spatial, arp220_spectrum) |
57 |
arp220.name("Arp220")
|
58 |
arp220.ids("")
|
59 |
|
60 |
#----------------------------------------------------
|
61 |
# Create GObservations and add models
|
62 |
#----------------------------------------------------
|
63 |
obs = gl.GObservations() |
64 |
obs.append(ob) |
65 |
obs.models().append(bck) |
66 |
obs.models().append(arp220) |
67 |
|
68 |
#----------------------------------------------------
|
69 |
# Simulate, fit and write out
|
70 |
#----------------------------------------------------
|
71 |
obssim = obsu.sim(obs, log=write, debug=False, edisp=False, seed=4, nbins=40, binsz=0.02) |
72 |
if write:
|
73 |
obssim.save("arp220_obs.xml")
|
74 |
obssim.models().save("arp220_sim.xml")
|
75 |
print "Creating counts map.." |
76 |
obsu.cntmap(obssim, proj="TAN", coord="EQU", xval=ra_degree, yval=dec_degree+offset_degree, \ |
77 |
binsz=0.02, nxpix=300, nypix=300, outname="arp220_cntmap.fits") |
78 |
print "Creating model map.." |
79 |
obsu.modmap(obssim, eref=0.1, proj="TAN", coord="EQU", xval=ra_degree, yval=dec_degree+offset_degree, \ |
80 |
binsz=0.02, nxpix=300, nypix=300, outname="arp220_modmap.fits") |
81 |
for ob in obssim: |
82 |
events = ob.events() |
83 |
events.save("arp220_events_run_1.fits")
|
84 |
print "Fitting.." |
85 |
obsu.fit(obssim,log=write, debug=True, edisp=False) |
86 |
|
87 |
if __name__ == '__main__': |
88 |
simarp220() |