runctlike.py

dirty script to test - Sanchez David, 07/22/2014 04:27 PM

Download (2.94 KB)

 
1
import gammalib as gl
2
import obsutils as obsu
3
import os
4
import ctools as ct
5

    
6
if __name__=="__main__":
7
    #Create one observation (run)
8
    #-----------------------------------------------------
9
    obstime = 360
10
    ra_degree=83.633212         #Crab position from NED
11
    dec_degree=22.014460 
12
    radius=8
13
    offset_degree=-1            #Observing offset in dec from Crab in deg
14
    pntdir = gl.GSkyDir()
15
    pntdir.radec_deg(ra_degree, dec_degree+offset_degree) 
16
    ob = obsu.set_obs(pntdir,tstart=0.0,duration=obstime,deadc=0.95, \
17
                  emin=0.1, emax=100.0, rad=radius, irf="irf_file.fits",\
18
                  caldb="$PWD/caldb/data/cta/aar/bcf/DESY20140105_50h/")
19
    ob.id("run_1")
20

    
21
    #----------------------------------------------------
22
    # Create background model
23
    #----------------------------------------------------
24
    spec = gl.GModelSpectralPlaw(1,0,gl.GEnergy(1.0,"TeV"))
25
    filename="$PWD/caldb/data/cta/aar/bcf/DESY20140105_50h/irf_file.fits"
26
    bck = gl.GCTAModelIrfBackground(spec)
27
    bck.name("Background_run_1")
28
    bck.instruments("CTA")
29

    
30
    #----------------------------------------------------
31
    # Create crab model
32
    #----------------------------------------------------
33
    #~ crabdir = gl.GSkyDir()
34
    #~ crabdir.radec_deg(ra_degree, dec_degree)
35
    #~ crab_spatial = gl.GModelSpatialPointSource(crabdir)
36
    #~ crab_spectrum = gl.GModelSpectralPlaw(3.45e-17, -2.63,gl.GEnergy(1,"TeV") ) #from HESS 2006
37
#~ 
38
    #~ crab = gl.GModelSky(crab_spatial, crab_spectrum)
39
    #~ crab.name("CrabNebula")
40
    #~ crab.ids("")
41
    
42
    #----------------------------------------------------
43
    # Create GObservations and add models
44
    #----------------------------------------------------
45
    obs = gl.GObservations()
46
    obs.append(ob)
47
    # obs.models("/home/sanchez/work/CTA/ctools/CrabNebula.xml")
48
    obs.models("/home/sanchez/work/CTA/ctools/crab.xml")
49
    #~ obs.models().append(bck)
50
    #~ obs.models().append(crab)
51

    
52
    #----------------------------------------------------
53
    # Simulation
54
    #----------------------------------------------------
55
    obssim = obsu.sim(obs, log=False, debug=False, edisp=False, seed=0)
56
    # obssim[0
57
    import analysisutils as ana
58
    analyser = ana.Analyser()
59
    analyser.set_obs(obssim)
60
    # analyser.ctbin()
61
    #----------------------------------------------------
62
    # Fit
63
    #----------------------------------------------------
64

    
65
    analyser.fit()
66
    like = analyser.like
67
    n = "CrabNebula"
68
    analyser.PrintResults(n)
69
    # like = obsu.fit(obssim,log=True, debug=False, edisp=False)
70
    print "TS = ",like.obs().models()[n].ts()
71
    print 
72
#    print like.obs().models()
73
    emin = ob.events().ebounds().emin().TeV()
74
    emax = ob.events().ebounds().emax().TeV()
75
    
76
    # res = analyser.GetSrcParams(n)
77

    
78
    res_ebin = ana.MakeEbin(analyser,6,n)
79
    res_ebin.Print()    
80

    
81
    from plotutils import SpectrumPlotter
82
    spec = SpectrumPlotter(n,like,res_ebin,emin,emax,SED=False)
83
    spec.draw()