Commit 5d9790f3b4839c85831433d18d3bc7555a0a094b

Authored by Jürgen Knödlseder
2 parents c5dfb295 c093864a

Merge branch 'integration' into devel

Showing 1 changed file with 26 additions and 9 deletions
cscripts/csphagen.py
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 # Computes the PHA spectra for source/background and ARF/RMF files using the 3 # Computes the PHA spectra for source/background and ARF/RMF files using the
4 # reflected region method 4 # reflected region method
5 # 5 #
6 -# Copyright (C) 2017-2019 Luigi Tibaldo 6 +# Copyright (C) 2017-2020 Luigi Tibaldo
7 # 7 #
8 # This program is free software: you can redistribute it and/or modify 8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by 9 # it under the terms of the GNU General Public License as published by
@@ -374,7 +374,7 @@ class csphagen(ctools.csobservation): @@ -374,7 +374,7 @@ class csphagen(ctools.csobservation):
374 # Determine number of background regions to skip 374 # Determine number of background regions to skip
375 N_skip = self['bkgregskip'].integer() 375 N_skip = self['bkgregskip'].integer()
376 N_start = 1 + N_skip 376 N_start = 1 + N_skip
377 - N_lim = 1 + 2*N_skip 377 + N_lim = 1 + 2 * N_skip
378 378
379 # Compute the angular separation of reflected regions wrt 379 # Compute the angular separation of reflected regions wrt
380 # camera center. The factor 1.05 ensures background regions 380 # camera center. The factor 1.05 ensures background regions
@@ -397,26 +397,36 @@ class csphagen(ctools.csobservation): @@ -397,26 +397,36 @@ class csphagen(ctools.csobservation):
397 # regions 397 # regions
398 else: 398 else:
399 399
400 - # Log appending of reflected regions  
401 - msg = ' Use %d reflected regions.' % (N-N_lim)  
402 - self._log_string(gammalib.NORMAL, msg)  
403 -  
404 # Append reflected regions 400 # Append reflected regions
405 - alpha = 360.0 / N  
406 - for s in range(N_start, N - N_skip):  
407 - dphi = s * alpha 401 + alpha = 360.0 / N
  402 + dphi_max = 360.0 - alpha * (1 + N_skip)
  403 + dphi = alpha * (1 + N_skip)
  404 + while dphi <= dphi_max:
408 ctr_dir = pnt_dir.clone() 405 ctr_dir = pnt_dir.clone()
409 ctr_dir.rotate_deg(posang + dphi, offset) 406 ctr_dir.rotate_deg(posang + dphi, offset)
410 region = gammalib.GSkyRegionCircle(ctr_dir, self._rad) 407 region = gammalib.GSkyRegionCircle(ctr_dir, self._rad)
411 if self._has_exclusion: 408 if self._has_exclusion:
412 if self._excl_reg.overlaps(region): 409 if self._excl_reg.overlaps(region):
  410 +
  411 + # Signal region overlap
413 msg = ' Reflected region overlaps with '\ 412 msg = ' Reflected region overlaps with '\
414 'exclusion region.' 413 'exclusion region.'
415 self._log_string(gammalib.EXPLICIT, msg) 414 self._log_string(gammalib.EXPLICIT, msg)
  415 +
  416 + # If region overlaps with exclusion region
  417 + # try to increment by 10% of angular step
  418 + dphi += 0.1 * alpha
  419 +
416 else: 420 else:
417 regions.append(region) 421 regions.append(region)
  422 + dphi += alpha
418 else: 423 else:
419 regions.append(region) 424 regions.append(region)
  425 + dphi += alpha
  426 +
  427 + # Log number of reflected regions
  428 + msg = ' Use %d reflected regions.' % (regions.size())
  429 + self._log_string(gammalib.NORMAL, msg)
420 430
421 # Return reflected regions 431 # Return reflected regions
422 return regions 432 return regions
@@ -670,6 +680,13 @@ class csphagen(ctools.csobservation): @@ -670,6 +680,13 @@ class csphagen(ctools.csobservation):
670 # Set On/Off observation ID 680 # Set On/Off observation ID
671 onoff.id(obs.id()) 681 onoff.id(obs.id())
672 682
  683 + # Otherwise log observation skipped
  684 + else:
  685 + msg = ' Skip because the number %d of regions ' \
  686 + 'for background estimation is smaller than ' \
  687 + '"bkgregmin"=%d.' % (bkg_reg.size(), self['bkgregmin'].integer())
  688 + self._log_string(gammalib.NORMAL, msg)
  689 +
673 # Construct dictionary with results 690 # Construct dictionary with results
674 result = {'onoff' : onoff, 691 result = {'onoff' : onoff,
675 'bkg_reg' : bkg_reg, 692 'bkg_reg' : bkg_reg,