Commit 95da80d050b1dee885dee789a1747b955e183556

Authored by Jürgen Knödlseder
1 parent 5f4af19a

Add support for energy dispersion.

scripts/cspull.py
@@ -94,11 +94,12 @@ class cspull(GApplication): @@ -94,11 +94,12 @@ class cspull(GApplication):
94 94
95 # Create default parfile 95 # Create default parfile
96 pars = GApplicationPars() 96 pars = GApplicationPars()
97 - pars.append(GApplicationPar("srcmdl","f","a","$GAMMALIB/share/models/crab.xml","","","Source model")) 97 + pars.append(GApplicationPar("srcmdl","f","a","$CTOOLS/share/models/crab.xml","","","Source model"))
98 pars.append(GApplicationPar("outfile","f","a","pull.dat","","","Output file name")) 98 pars.append(GApplicationPar("outfile","f","a","pull.dat","","","Output file name"))
99 pars.append(GApplicationPar("ntrials","i","a","10","","","Number of trials")) 99 pars.append(GApplicationPar("ntrials","i","a","10","","","Number of trials"))
100 pars.append(GApplicationPar("caldb","s","h","","","","Calibration database")) 100 pars.append(GApplicationPar("caldb","s","h","","","","Calibration database"))
101 pars.append(GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) 101 pars.append(GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
  102 + pars.append(GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?"))
102 pars.append(GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)")) 103 pars.append(GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)"))
103 pars.append(GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)")) 104 pars.append(GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)"))
104 pars.append(GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)")) 105 pars.append(GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)"))
@@ -126,6 +127,7 @@ class cspull(GApplication): @@ -126,6 +127,7 @@ class cspull(GApplication):
126 self.m_ntrials = self["ntrials"].integer() 127 self.m_ntrials = self["ntrials"].integer()
127 self.m_caldb = self["caldb"].string() 128 self.m_caldb = self["caldb"].string()
128 self.m_irf = self["irf"].string() 129 self.m_irf = self["irf"].string()
  130 + self.m_edisp = self["edisp"].boolean()
129 self.m_ra = self["ra"].real() 131 self.m_ra = self["ra"].real()
130 self.m_dec = self["dec"].real() 132 self.m_dec = self["dec"].real()
131 self.m_emin = self["emin"].real() 133 self.m_emin = self["emin"].real()
@@ -268,6 +270,7 @@ class cspull(GApplication): @@ -268,6 +270,7 @@ class cspull(GApplication):
268 seed=seed, \ 270 seed=seed, \
269 binsz=self.m_binsz, \ 271 binsz=self.m_binsz, \
270 npix=self.m_npix, \ 272 npix=self.m_npix, \
  273 + edisp=self.m_edisp, \
271 log=self.m_log, debug=self.m_debug) 274 log=self.m_log, debug=self.m_debug)
272 275
273 # Determine number of events in simulation 276 # Determine number of events in simulation
@@ -283,7 +286,8 @@ class cspull(GApplication): @@ -283,7 +286,8 @@ class cspull(GApplication):
283 self.log("\n") 286 self.log("\n")
284 287
285 # Fit model 288 # Fit model
286 - like = obsutils.fit(obs, log=self.m_log, debug=self.m_debug) 289 + like = obsutils.fit(obs, edisp=self.m_edisp, \
  290 + log=self.m_log, debug=self.m_debug)
287 291
288 # Store results 292 # Store results
289 logL = like.opt().value() 293 logL = like.opt().value()
scripts/obsutils.py
@@ -25,7 +25,8 @@ import gammalib @@ -25,7 +25,8 @@ import gammalib
25 # ===================== # 25 # ===================== #
26 # Simulate observations # 26 # Simulate observations #
27 # ===================== # 27 # ===================== #
28 -def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200): 28 +def sim(obs, log=False, debug=False, edisp=False, seed=0, nbins=0,
  29 + binsz=0.05, npix=200):
29 """ 30 """
30 Simulate events for all observations in the container. 31 Simulate events for all observations in the container.
31 32
@@ -33,7 +34,8 @@ def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200): @@ -33,7 +34,8 @@ def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200):
33 obs - Observation container 34 obs - Observation container
34 Keywords: 35 Keywords:
35 log - Create log file(s) 36 log - Create log file(s)
36 - debug - Create screen dump 37 + debug - Create console dump?
  38 + edisp - Apply energy dispersion?
37 seed - Seed value for simulations (default: 0) 39 seed - Seed value for simulations (default: 0)
38 nbins - Number of energy bins (default: 0=unbinned) 40 nbins - Number of energy bins (default: 0=unbinned)
39 binsz - Pixel size for binned simulation (deg/pixel) 41 binsz - Pixel size for binned simulation (deg/pixel)
@@ -50,6 +52,9 @@ def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200): @@ -50,6 +52,9 @@ def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200):
50 # Optionally switch-on debugging model 52 # Optionally switch-on debugging model
51 if debug: 53 if debug:
52 sim["debug"].boolean(True) 54 sim["debug"].boolean(True)
  55 +
  56 + # Optionally apply energy dispersion
  57 + sim["edisp"].boolean(edisp)
53 58
54 # Run ctobssim application. This will loop over all observations in the 59 # Run ctobssim application. This will loop over all observations in the
55 # container and simulation the events for each observation. Note that 60 # container and simulation the events for each observation. Note that
@@ -122,7 +127,7 @@ def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200): @@ -122,7 +127,7 @@ def sim(obs, log=False, debug=False, seed=0, nbins=0, binsz=0.05, npix=200):
122 # ================ # 127 # ================ #
123 # Fit observations # 128 # Fit observations #
124 # ================ # 129 # ================ #
125 -def fit(obs, log=False, debug=False): 130 +def fit(obs, log=False, debug=False, edisp=False):
126 """ 131 """
127 Perform maximum likelihood fitting of observations in the container. 132 Perform maximum likelihood fitting of observations in the container.
128 133
@@ -131,6 +136,7 @@ def fit(obs, log=False, debug=False): @@ -131,6 +136,7 @@ def fit(obs, log=False, debug=False):
131 Keywords: 136 Keywords:
132 log - Create log file(s) 137 log - Create log file(s)
133 debug - Create screen dump 138 debug - Create screen dump
  139 + edisp - Apply energy dispersion?
134 """ 140 """
135 # Allocate ctlike application 141 # Allocate ctlike application
136 like = ctools.ctlike(obs) 142 like = ctools.ctlike(obs)
@@ -143,6 +149,9 @@ def fit(obs, log=False, debug=False): @@ -143,6 +149,9 @@ def fit(obs, log=False, debug=False):
143 if debug: 149 if debug:
144 like["debug"].boolean(True) 150 like["debug"].boolean(True)
145 151
  152 + # Optionally apply energy dispersion
  153 + like["edisp"].boolean(edisp)
  154 +
146 # Run ctlike application. 155 # Run ctlike application.
147 like.run() 156 like.run()
148 157
@@ -266,7 +275,7 @@ def modmap(obs, eref=0.1, proj="TAN", coord="GAL", xval=0.0, yval=0.0, \ @@ -266,7 +275,7 @@ def modmap(obs, eref=0.1, proj="TAN", coord="GAL", xval=0.0, yval=0.0, \
266 # ======================= # 275 # ======================= #
267 def set(pntdir, tstart=0.0, duration=1800.0, deadc=0.95, \ 276 def set(pntdir, tstart=0.0, duration=1800.0, deadc=0.95, \
268 emin=0.1, emax=100.0, rad=5.0, \ 277 emin=0.1, emax=100.0, rad=5.0, \
269 - irf="cta_dummy_irf", caldb=""): 278 + irf="cta_dummy_irf", caldb="$CTOOLS/share/caldb/data/cta/dummy"):
270 """ 279 """
271 Returns a single CTA observation. By looping over this function we can 280 Returns a single CTA observation. By looping over this function we can
272 add CTA observations to the observation container. 281 add CTA observations to the observation container.