Skip to content

Commit

Permalink
Merge pull request #209 from icecube/fix205
Browse files Browse the repository at this point in the history
Add `update_detsigyield_service=False` option to `change_source()`.
  • Loading branch information
tomaskontrimas authored Feb 6, 2024
2 parents 4022be0 + d079109 commit 6c3e66f
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions skyllh/core/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,20 @@ def do_trial_with_given_pseudo_data(

def change_shg_mgr(
self,
shg_mgr):
shg_mgr,
update_detsigyield_service=True):
"""If the SourceHypoGroupManager instance changed, this method needs to
be called to propagate the change to all components of the analysis.
Parameters
----------
shg_mgr : instance of SourceHypoGroupManager
The new instance of SourceHypoGroupManager.
update_detsigyield_service : bool
The option whether to update SourceHypoGroupManager of
`detsigyield_service` property. It can be set to false for runtime
optimization when the detector signal yield does not change for the
new source. Default is True.
"""
for evt_selection_method in self._event_selection_method_list:
if evt_selection_method is not None:
Expand All @@ -721,7 +727,7 @@ def change_shg_mgr(
shg_mgr=shg_mgr,
pmm=self._pmm)

if self._detsigyield_service is not None:
if self._detsigyield_service is not None and update_detsigyield_service:
self._detsigyield_service.change_shg_mgr(
shg_mgr=shg_mgr)

Expand Down Expand Up @@ -1390,22 +1396,29 @@ def add_dataset(

def change_shg_mgr(
self,
shg_mgr):
shg_mgr,
update_detsigyield_service=True):
"""If the SourceHypoGroupManager instance changed, this method needs to
be called to propagate the change to all components of the analysis.
Parameters
----------
shg_mgr : instance of SourceHypoGroupManager
The new instance of SourceHypoGroupManager.
update_detsigyield_service : bool
The option whether to update SourceHypoGroupManager of
`detsigyield_service` property. It can be set to false for runtime
optimization when the detector signal yield does not change for the
new source. Default is True.
"""
if self._llhratio is None:
raise RuntimeError(
'The LLH ratio function has to be constructed '
'before the `change_shg_mgr` method can be called!')

super().change_shg_mgr(
shg_mgr=shg_mgr)
shg_mgr=shg_mgr,
update_detsigyield_service=update_detsigyield_service)

# Change the source hypo group manager of the LLH ratio function
# instance.
Expand Down Expand Up @@ -1714,14 +1727,20 @@ def construct_llhratio(

def change_source(
self,
source):
source,
update_detsigyield_service=True):
"""Changes the source of the analysis to the given source. It makes the
necessary changes to all the objects of the analysis.
Parameters
----------
source : instance of SourceModel
The instance of SourceModel describing the new source.
update_detsigyield_service : bool
The option whether to update SourceHypoGroupManager of
`detsigyield_service` property. It can be set to false for runtime
optimization when the detector signal yield does not change for the
new source. Default is True.
"""
if not isinstance(source, SourceModel):
raise TypeError(
Expand All @@ -1734,7 +1753,8 @@ def change_source(
self._shg_mgr.shg_list[0].source_list[0] = source

self.change_shg_mgr(
shg_mgr=self._shg_mgr)
shg_mgr=self._shg_mgr,
update_detsigyield_service=update_detsigyield_service)

def calculate_fluxmodel_scaling_factor(
self,
Expand Down

0 comments on commit 6c3e66f

Please sign in to comment.