Bug #2862

csbkgmodel breaks when passed observations from multiple instruments

Added by Cardenzana Josh over 5 years ago. Updated over 5 years ago.

Status:ClosedStart date:03/26/2019
Priority:NormalDue date:
Assigned To:Cardenzana Josh% Done:

100%

Category:-
Target version:1.6.2
Duration:

Description

I came across this bug while trying to jointly fit some VERITAS and HESS data recently. csbkgmodel allows passing an observation XML file with observations from multiple instruments. However, because there is a fitting portion of the script it will break when it tries to fit the generated background models to the list of observations. This appears to be because it doesn’t remove the observations from instruments not selected by the `instrument` parameter, which don’t have a corresponding model in the generated list of background models. This can be easily fixed by just removing those observations from `self.obs()` that are not associated with `instrument`:

        ...
        # Set instrument name
        self._instrument = self._get_instrument()

        # ===== new code
        # Remove observations from other instruments
        # This for-loop loops backwards through the observations
        for i in range(self.obs().size()-1, -1, -1):
            if self.obs()[i].instrument() != self._instrument:
                self.obs().remove(i)
        # ===== end new code

        # Query input parameters
        ...

Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen over 5 years ago

  • Target version set to 1.6.2

#2 Updated by Cardenzana Josh over 5 years ago

  • Status changed from New to Pull request
  • % Done changed from 0 to 90

I’ve added the following bit of code in the 'csbkgmodel.run()' method:

# Remove observations from wrong instruments
obs = self.obs()
for i in range(obs.size()-1, -1, -1):
    if obs[i].instrument() != self._instrument:
        obs.remove(i)

# Log observations to be used
self._log_value(gammalib.NORMAL, 'Obs matching instrument', self.obs().size())

This ensures all observations not associated with the user specified instrument are removed before the models are generated. The loop is a reverse loop to ensure that there’s no skipping of the observations as entries are removed from the obs container. Alternatively, this bit of code could be put after the for-loop in 'csbkgmodel._get_instrument()' with the same effect, but I wasn’t sure if that keeps the spirit of the '_get_instrument()' method which is called by '_get_parameters()'.

There is also a new test in 'test_csbkgmodel.py’ to make sure this works.

Pull request:
Repo: https://cta-gitlab.irap.omp.eu/jcardenzana/ctools.git
Branch: 2862_multi_inst_csbkgmodel

#3 Updated by Knödlseder Jürgen over 5 years ago

  • Status changed from Pull request to Closed
  • % Done changed from 90 to 100

Merged into bugfix-1.6.2.

Also available in: Atom PDF