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,7 +550,7 @@ class csresspec(ctools.csobservation):
550 550
551 return table 551 return table
552 552
553 - def _residuals_OnOff(self,obs,obs_id): 553 + def _residuals_OnOff(self, obs, obs_id):
554 """ 554 """
555 Calculate residual for OnOff observation 555 Calculate residual for OnOff observation
556 556
@@ -614,27 +614,36 @@ class csresspec(ctools.csobservation): @@ -614,27 +614,36 @@ class csresspec(ctools.csobservation):
614 # Calculate models of individual components if requested 614 # Calculate models of individual components if requested
615 if self['components'].boolean(): 615 if self['components'].boolean():
616 for component in obs.models(): 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 pass 626 pass
623 - # Otherwise calculate gamma component and append to Table 627 +
  628 + # ... otherwise calculate gamma component and append to Table
624 else: 629 else:
625 self._log_value(gammalib.NORMAL, 630 self._log_value(gammalib.NORMAL,
626 'Computing model for component', 631 'Computing model for component',
627 component.name()) 632 component.name())
  633 +
628 # Create observation container for individual components 634 # Create observation container for individual components
629 model_cont = gammalib.GModels() 635 model_cont = gammalib.GModels()
630 model_cont.append(component) 636 model_cont.append(component)
  637 +
631 # Calculate gamma model 638 # Calculate gamma model
632 model = onoff.model_gamma(model_cont) 639 model = onoff.model_gamma(model_cont)
633 model = model.counts_spectrum() 640 model = model.counts_spectrum()
  641 +
634 # Append to table 642 # Append to table
635 table = self._append_column(table, component.name(), 643 table = self._append_column(table, component.name(),
636 model) 644 model)
637 - # Add background already calculated 645 +
  646 + # Add now the background that is already calculated
638 self._log_value(gammalib.NORMAL, 647 self._log_value(gammalib.NORMAL,
639 'Computing model for component', 648 'Computing model for component',
640 'Background') 649 'Background')
@@ -712,11 +721,11 @@ class csresspec(ctools.csobservation): @@ -712,11 +721,11 @@ class csresspec(ctools.csobservation):
712 721
713 # If 3D observation 722 # If 3D observation
714 if obs[0].classname() == 'GCTAObservation': 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 # otherwise, if On/Off 726 # otherwise, if On/Off
718 elif obs[0].classname() == 'GCTAOnOffObservation': 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 # Append results table to output file 730 # Append results table to output file
722 self._fits.append(table) 731 self._fits.append(table)