Commit 95da80d050b1dee885dee789a1747b955e183556
1 parent
5f4af19a
Add support for energy dispersion.
Showing
2 changed files
with
19 additions
and
6 deletions
scripts/cspull.py
| ... | ... | @@ -94,11 +94,12 @@ class cspull(GApplication): |
| 94 | 94 | |
| 95 | 95 | # Create default parfile |
| 96 | 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 | 98 | pars.append(GApplicationPar("outfile","f","a","pull.dat","","","Output file name")) |
| 99 | 99 | pars.append(GApplicationPar("ntrials","i","a","10","","","Number of trials")) |
| 100 | 100 | pars.append(GApplicationPar("caldb","s","h","","","","Calibration database")) |
| 101 | 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 | 103 | pars.append(GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)")) |
| 103 | 104 | pars.append(GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)")) |
| 104 | 105 | pars.append(GApplicationPar("emin","r","a","0.1","0.0","","Lower energy limit (TeV)")) |
| ... | ... | @@ -126,6 +127,7 @@ class cspull(GApplication): |
| 126 | 127 | self.m_ntrials = self["ntrials"].integer() |
| 127 | 128 | self.m_caldb = self["caldb"].string() |
| 128 | 129 | self.m_irf = self["irf"].string() |
| 130 | + self.m_edisp = self["edisp"].boolean() | |
| 129 | 131 | self.m_ra = self["ra"].real() |
| 130 | 132 | self.m_dec = self["dec"].real() |
| 131 | 133 | self.m_emin = self["emin"].real() |
| ... | ... | @@ -268,6 +270,7 @@ class cspull(GApplication): |
| 268 | 270 | seed=seed, \ |
| 269 | 271 | binsz=self.m_binsz, \ |
| 270 | 272 | npix=self.m_npix, \ |
| 273 | + edisp=self.m_edisp, \ | |
| 271 | 274 | log=self.m_log, debug=self.m_debug) |
| 272 | 275 | |
| 273 | 276 | # Determine number of events in simulation |
| ... | ... | @@ -283,7 +286,8 @@ class cspull(GApplication): |
| 283 | 286 | self.log("\n") |
| 284 | 287 | |
| 285 | 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 | 292 | # Store results |
| 289 | 293 | logL = like.opt().value() | ... | ... |
scripts/obsutils.py
| ... | ... | @@ -25,7 +25,8 @@ import gammalib |
| 25 | 25 | # ===================== # |
| 26 | 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 | 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 | 34 | obs - Observation container |
| 34 | 35 | Keywords: |
| 35 | 36 | log - Create log file(s) |
| 36 | - debug - Create screen dump | |
| 37 | + debug - Create console dump? | |
| 38 | + edisp - Apply energy dispersion? | |
| 37 | 39 | seed - Seed value for simulations (default: 0) |
| 38 | 40 | nbins - Number of energy bins (default: 0=unbinned) |
| 39 | 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 | 52 | # Optionally switch-on debugging model |
| 51 | 53 | if debug: |
| 52 | 54 | sim["debug"].boolean(True) |
| 55 | + | |
| 56 | + # Optionally apply energy dispersion | |
| 57 | + sim["edisp"].boolean(edisp) | |
| 53 | 58 | |
| 54 | 59 | # Run ctobssim application. This will loop over all observations in the |
| 55 | 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 | 127 | # ================ # |
| 123 | 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 | 132 | Perform maximum likelihood fitting of observations in the container. |
| 128 | 133 | |
| ... | ... | @@ -131,6 +136,7 @@ def fit(obs, log=False, debug=False): |
| 131 | 136 | Keywords: |
| 132 | 137 | log - Create log file(s) |
| 133 | 138 | debug - Create screen dump |
| 139 | + edisp - Apply energy dispersion? | |
| 134 | 140 | """ |
| 135 | 141 | # Allocate ctlike application |
| 136 | 142 | like = ctools.ctlike(obs) |
| ... | ... | @@ -143,6 +149,9 @@ def fit(obs, log=False, debug=False): |
| 143 | 149 | if debug: |
| 144 | 150 | like["debug"].boolean(True) |
| 145 | 151 | |
| 152 | + # Optionally apply energy dispersion | |
| 153 | + like["edisp"].boolean(edisp) | |
| 154 | + | |
| 146 | 155 | # Run ctlike application. |
| 147 | 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 | 275 | # ======================= # |
| 267 | 276 | def set(pntdir, tstart=0.0, duration=1800.0, deadc=0.95, \ |
| 268 | 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 | 280 | Returns a single CTA observation. By looping over this function we can |
| 272 | 281 | add CTA observations to the observation container. | ... | ... |