Commit d8468231c1f053ccad8be1d1a3cc54e016b45f8d
1 parent
39bd6536
Add obsutils.sim() unit test for On/Off observations
Showing
3 changed files
with
67 additions
and
3 deletions
cscripts/csphagen.py
| ... | ... | @@ -226,7 +226,7 @@ class csphagen(ctools.csobservation): |
| 226 | 226 | emax = self._ebounds.emax() * 1.2 |
| 227 | 227 | if emin.TeV() < self['etruemin'].real(): |
| 228 | 228 | emin = gammalib.GEnergy(self['etruemin'].real(), 'TeV') |
| 229 | - if emax.TeV() < self['etruemax'].real(): | |
| 229 | + if emax.TeV() > self['etruemax'].real(): | |
| 230 | 230 | emax = gammalib.GEnergy(self['etruemax'].real(), 'TeV') |
| 231 | 231 | |
| 232 | 232 | # Determine number of energy bins | ... | ... |
test/test_csphagen.py
| ... | ... | @@ -339,7 +339,7 @@ class Test(test): |
| 339 | 339 | # Return |
| 340 | 340 | return |
| 341 | 341 | |
| 342 | - def _check_rmf(self, filename, bins, etruebins=114): | |
| 342 | + def _check_rmf(self, filename, bins, etruebins=102): | |
| 343 | 343 | """ |
| 344 | 344 | Check RMF file |
| 345 | 345 | """ |
| ... | ... | @@ -386,7 +386,7 @@ class Test(test): |
| 386 | 386 | # OGIP files |
| 387 | 387 | self._check_pha(filenameroot + '_pha_on.fits', bins) |
| 388 | 388 | self._check_pha(filenameroot + '_pha_off.fits', bins) |
| 389 | - self._check_arf(filenameroot + '_arf.fits', 114) | |
| 389 | + self._check_arf(filenameroot + '_arf.fits', 102) | |
| 390 | 390 | self._check_rmf(filenameroot + '_rmf.fits', bins) |
| 391 | 391 | |
| 392 | 392 | # Optionally check for regions | ... | ... |
test/test_obsutils.py
| ... | ... | @@ -60,6 +60,8 @@ class Test(test): |
| 60 | 60 | self.append(self._test_sim_stacked_edisp, |
| 61 | 61 | 'Test obsutils.sim() function in stacked mode with energy ' |
| 62 | 62 | 'dispersion') |
| 63 | + self.append(self._test_sim_onoff, | |
| 64 | + 'Test obsutils.sim() function in On/Off mode') | |
| 63 | 65 | self.append(self._test_sim_log, |
| 64 | 66 | 'Test obsutils.sim() function with logging switched on') |
| 65 | 67 | self.append(self._test_set_obs, |
| ... | ... | @@ -231,6 +233,68 @@ class Test(test): |
| 231 | 233 | # Return |
| 232 | 234 | return |
| 233 | 235 | |
| 236 | + # Test sim() function in On/Off mode | |
| 237 | + def _test_sim_onoff(self): | |
| 238 | + """ | |
| 239 | + Test sim() function in On/Off mode | |
| 240 | + """ | |
| 241 | + # Set-up observation container | |
| 242 | + pnt = gammalib.GSkyDir() | |
| 243 | + pnt.radec_deg(83.63, 22.51) | |
| 244 | + obs = gammalib.GObservations() | |
| 245 | + run = obsutils.set_obs(pnt, duration=100.0, emin=1.0, emax=10.0, obsid='0') | |
| 246 | + obs.append(run) | |
| 247 | + pnt.radec_deg(83.63, 21.51) | |
| 248 | + run = obsutils.set_obs(pnt, duration=100.0, emin=1.0, emax=10.0, obsid='1') | |
| 249 | + obs.append(run) | |
| 250 | + obs.models(gammalib.GModels(self._model)) | |
| 251 | + | |
| 252 | + # Simulate stacked observations | |
| 253 | + res = obsutils.sim(obs, onsrc='Crab', nbins=5) | |
| 254 | + | |
| 255 | + # Check simulation results | |
| 256 | + self.test_value(res.size(), 2, 'Check number of observations') | |
| 257 | + self.test_value(res.models().size(), 2, 'Check number of models') | |
| 258 | + self.test_value(res.nobserved(), 46, 'Check number of observed events') | |
| 259 | + self.test_value(res.npred(), 0.0, 'Check number of predicted events') | |
| 260 | + self.test_value(res[0].on_spec().ebounds().emin().TeV(), 1.0, | |
| 261 | + 'Check minimum energy of On spectrum') | |
| 262 | + self.test_value(res[0].on_spec().ebounds().emax().TeV(), 10.0, | |
| 263 | + 'Check minimum energy of On spectrum') | |
| 264 | + self.test_value(res[0].on_spec().ebounds().size(), 5, | |
| 265 | + 'Check number of energy bins of On spectrum') | |
| 266 | + self.test_value(res[0].on_spec().counts(), 24, | |
| 267 | + 'Check number of events in of On spectrum') | |
| 268 | + self.test_value(res[0].off_spec().ebounds().emin().TeV(), 1.0, | |
| 269 | + 'Check minimum energy of Off spectrum') | |
| 270 | + self.test_value(res[0].off_spec().ebounds().emax().TeV(), 10.0, | |
| 271 | + 'Check minimum energy of Off spectrum') | |
| 272 | + self.test_value(res[0].off_spec().ebounds().size(), 5, | |
| 273 | + 'Check number of energy bins of Off spectrum') | |
| 274 | + self.test_value(res[0].off_spec().counts(), 2, | |
| 275 | + 'Check number of events in of Off spectrum') | |
| 276 | + self.test_value(res[0].arf().ebounds().emin().TeV(), 0.5, | |
| 277 | + 'Check minimum energy of ARF') | |
| 278 | + self.test_value(res[0].arf().ebounds().emax().TeV(), 12.0, | |
| 279 | + 'Check minimum energy of ARF') | |
| 280 | + self.test_value(res[0].arf().ebounds().size(), 42, | |
| 281 | + 'Check number of energy bins of ARF') | |
| 282 | + self.test_value(res[0].rmf().etrue().emin().TeV(), 0.5, | |
| 283 | + 'Check minimum true energy of RMF') | |
| 284 | + self.test_value(res[0].rmf().etrue().emax().TeV(), 12.0, | |
| 285 | + 'Check minimum true energy of RMF') | |
| 286 | + self.test_value(res[0].rmf().etrue().size(), 42, | |
| 287 | + 'Check number of true energy bins of RMF') | |
| 288 | + self.test_value(res[0].rmf().emeasured().emin().TeV(), 1.0, | |
| 289 | + 'Check minimum reconstructed energy of RMF') | |
| 290 | + self.test_value(res[0].rmf().emeasured().emax().TeV(), 10.0, | |
| 291 | + 'Check minimum reconstructed energy of RMF') | |
| 292 | + self.test_value(res[0].rmf().emeasured().size(), 5, | |
| 293 | + 'Check number of reconstructed energy bins of RMF') | |
| 294 | + | |
| 295 | + # Return | |
| 296 | + return | |
| 297 | + | |
| 234 | 298 | # Test sim() function with logging switched on |
| 235 | 299 | def _test_sim_log(self): |
| 236 | 300 | """ | ... | ... |