Commit 9b0ca426e8462dbdb3575e64eb512c02a363f181

Authored by Jürgen Knödlseder
1 parent 75b1cd42

Adapt csresspec to handle correctly all types of CTA background models

Showing 1 changed file with 19 additions and 10 deletions
cscripts/csresspec.py
... ... @@ -550,7 +550,7 @@ class csresspec(ctools.csobservation):
550 550  
551 551 return table
552 552  
553   - def _residuals_OnOff(self,obs,obs_id):
  553 + def _residuals_OnOff(self, obs, obs_id):
554 554 """
555 555 Calculate residual for OnOff observation
556 556  
... ... @@ -614,27 +614,36 @@ class csresspec(ctools.csobservation):
614 614 # Calculate models of individual components if requested
615 615 if self['components'].boolean():
616 616 for component in obs.models():
617   - # If background pass
618   - # We always add the background at the end so that
619   - # we accommodate WSTAT for which the background is not
620   - # mandatory in the model
621   - if component.classname() == 'GCTAModelIrfBackground':
  617 +
  618 + # If the component is a background model then pass. We always
  619 + # add the background at the end so that we accommodate WSTAT
  620 + # for which the background is not mandatory in the model
  621 + if component.classname() == 'GCTAModelAeffBackground' or \
  622 + component.classname() == 'GCTAModelBackground' or \
  623 + component.classname() == 'GCTAModelCubeBackground' or \
  624 + component.classname() == 'GCTAModelIrfBackground' or \
  625 + component.classname() == 'GCTAModelRadialAcceptance':
622 626 pass
623   - # Otherwise calculate gamma component and append to Table
  627 +
  628 + # ... otherwise calculate gamma component and append to Table
624 629 else:
625 630 self._log_value(gammalib.NORMAL,
626 631 'Computing model for component',
627 632 component.name())
  633 +
628 634 # Create observation container for individual components
629 635 model_cont = gammalib.GModels()
630 636 model_cont.append(component)
  637 +
631 638 # Calculate gamma model
632 639 model = onoff.model_gamma(model_cont)
633 640 model = model.counts_spectrum()
  641 +
634 642 # Append to table
635 643 table = self._append_column(table, component.name(),
636 644 model)
637   - # Add background already calculated
  645 +
  646 + # Add now the background that is already calculated
638 647 self._log_value(gammalib.NORMAL,
639 648 'Computing model for component',
640 649 'Background')
... ... @@ -712,11 +721,11 @@ class csresspec(ctools.csobservation):
712 721  
713 722 # If 3D observation
714 723 if obs[0].classname() == 'GCTAObservation':
715   - table = self._residuals_3D(obs,obs_id)
  724 + table = self._residuals_3D(obs, obs_id)
716 725  
717 726 # otherwise, if On/Off
718 727 elif obs[0].classname() == 'GCTAOnOffObservation':
719   - table = self._residuals_OnOff(obs,obs_id)
  728 + table = self._residuals_OnOff(obs, obs_id)
720 729  
721 730 # Append results table to output file
722 731 self._fits.append(table)
... ...