Commit a6aedae3c1b3d82bd14bdb6621adb56a2f871335

Authored by Iftach Sadeh
Committed by Jürgen Knödlseder
1 parent 11df2d07

faster edisp

in case `edisp=True`, only use it in practice once the flux calculation is near convergence
Showing 1 changed file with 21 additions and 1 deletions
cscripts/cssens.py
@@ -371,6 +371,11 @@ class cssens(ctools.csobservation): @@ -371,6 +371,11 @@ class cssens(ctools.csobservation):
371 npix = 200 371 npix = 200
372 binsz = 0.05 372 binsz = 0.05
373 373
  374 + # keep track of the original value of edisp
  375 + edisp_orig = self['edisp'].boolean()
  376 + # set edisp off for the first iterations
  377 + self['edisp'] = False
  378 +
374 # Set flux ratio precision required for convergence to 5% 379 # Set flux ratio precision required for convergence to 5%
375 ratio_precision = 0.05 380 ratio_precision = 0.05
376 381
@@ -539,7 +544,18 @@ class cssens(ctools.csobservation): @@ -539,7 +544,18 @@ class cssens(ctools.csobservation):
539 self._log_value(gammalib.TERSE, 'Converged flux ratio', ratio) 544 self._log_value(gammalib.TERSE, 'Converged flux ratio', ratio)
540 self._log_value(gammalib.TERSE, 'Regression coefficient', 545 self._log_value(gammalib.TERSE, 'Regression coefficient',
541 regcoeff) 546 regcoeff)
542 - break 547 +
  548 + # if the flux has converged, check if the original value of
  549 + # edisp was set, and is not what has fo far been used
  550 + if edisp_orig and not self['edisp'].boolean():
  551 + # set edisp on and continue the calculation
  552 + self['edisp'] = True
  553 +
  554 + value = 'set edisp on after initial convergence withouth it'
  555 + self._log_value(gammalib.TERSE, 'Converged result', value)
  556 + else:
  557 + # finish the calculation after convergence
  558 + break
543 else: 559 else:
544 self._log_value(gammalib.TERSE, 'Not converged', 'Flux is zero') 560 self._log_value(gammalib.TERSE, 'Not converged', 'Flux is zero')
545 break 561 break
@@ -553,6 +569,10 @@ class cssens(ctools.csobservation): @@ -553,6 +569,10 @@ class cssens(ctools.csobservation):
553 ' Test ended after %d iterations.' % max_iter) 569 ' Test ended after %d iterations.' % max_iter)
554 break 570 break
555 571
  572 + # make sure edisp is set correctly before the count cuts
  573 + if edisp_orig and not self['edisp'].boolean():
  574 + self['edisp'] = True
  575 +
556 n_bck_evts = None 576 n_bck_evts = None
557 for iterations in range(max_iter): 577 for iterations in range(max_iter):
558 pass_evt_cut, n_bck_evts = self._sim_evt_excess( 578 pass_evt_cut, n_bck_evts = self._sim_evt_excess(