We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
FoVBackgroundMaker parameter error not accessible
After the running the `FoVBackgroundMaker`, the error on the fitted parameters is not accessible.

**To reproduce**
Try `print(dataset.background_model.spectral_model.norm.error)` inside the `Data Reduction Loop` in `analysis_2` notebook. It is always `0`

**Reason**
It seems that the error is available at this stage, 
https://github.com/gammapy/gammapy/blob/df3db33e34233369512d57cca5341a7b645802d6/gammapy/makers/background/fov.py#L180

but the info is lost outside the `with models.restore_status` block, eg: in line 187.
I did not understand why, though.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `gammapy/makers/background/fov.py`
Content:
```
1 # Licensed under a 3-clause BSD style license - see LICENSE.rst
2 """FoV background estimation."""
3 import logging
4 import numpy as np
5 from gammapy.maps import Map
6 from gammapy.modeling import Fit
7 from gammapy.modeling.models import FoVBackgroundModel, Model
8 from ..core import Maker
9 
10 
11 __all__ = ["FoVBackgroundMaker"]
12 
13 log = logging.getLogger(__name__)
14 
15 
16 class FoVBackgroundMaker(Maker):
17     """Normalize template background on the whole field-of-view.
18 
19     The dataset background model can be simply scaled (method="scale") or fitted (method="fit")
20     on the dataset counts.
21 
22     The normalization is performed outside the exclusion mask that is passed on init.
23 
24     If a SkyModel is set on the input dataset and method is 'fit', it' parameters
25     are frozen during the fov normalization fit.
26 
27     If the requirement (greater than) of either min_counts or min_npred_background is not satisfied,
28     the background will not be normalised
29 
30     Parameters
31     ----------
32     method : str in ['fit', 'scale']
33         the normalization method to be applied. Default 'scale'.
34     exclusion_mask : `~gammapy.maps.WcsNDMap`
35         Exclusion mask
36     spectral_model : SpectralModel or str
37         Reference norm spectral model to use for the `FoVBackgroundModel`, if none is defined
38         on the dataset. By default, use pl-norm.
39     min_counts : int
40         Minimum number of counts required outside the exclusion region
41     min_npred_background : float
42        Minimum number of predicted background counts required outside the exclusion region
43     """
44 
45     tag = "FoVBackgroundMaker"
46     available_methods = ["fit", "scale"]
47 
48     def __init__(
49         self,
50         method="scale",
51         exclusion_mask=None,
52         spectral_model="pl-norm",
53         min_counts=0,
54         min_npred_background=0,
55     ):
56         self.method = method
57         self.exclusion_mask = exclusion_mask
58         self.min_counts = min_counts
59         self.min_npred_background = min_npred_background
60 
61         if isinstance(spectral_model, str):
62             spectral_model = Model.create(tag=spectral_model, model_type="spectral")
63 
64         if not spectral_model.is_norm_spectral_model:
65             raise ValueError("Spectral model must be a norm spectral model")
66 
67         self.default_spectral_model = spectral_model
68 
69     @property
70     def method(self):
71         """Method"""
72         return self._method
73 
74     @method.setter
75     def method(self, value):
76         """Method setter"""
77         if value not in self.available_methods:
78             raise ValueError(
79                 f"Not a valid method for FoVBackgroundMaker: {value}."
80                 f" Choose from {self.available_methods}"
81             )
82 
83         self._method = value
84 
85     def make_default_fov_background_model(self, dataset):
86         """Add fov background model to the model definition
87 
88         Parameters
89         ----------
90         dataset : `~gammapy.datasets.MapDataset`
91             Input map dataset.
92 
93         Returns
94         -------
95         dataset : `~gammapy.datasets.MapDataset`
96             Map dataset including background model
97 
98         """
99         bkg_model = FoVBackgroundModel(
100             dataset_name=dataset.name, spectral_model=self.default_spectral_model.copy()
101         )
102 
103         if dataset.models is None:
104             dataset.models = bkg_model
105         else:
106             dataset.models = dataset.models + bkg_model
107 
108         return dataset
109 
110     def make_exclusion_mask(self, dataset):
111         """Project input exclusion mask to dataset geom
112 
113         Parameters
114         ----------
115         dataset : `~gammapy.datasets.MapDataset`
116             Input map dataset.
117 
118         Returns
119         -------
120         mask : `~gammapy.maps.WcsNDMap`
121             Projected exclusion mask
122         """
123         geom = dataset._geom
124         if self.exclusion_mask:
125             mask = self.exclusion_mask.interp_to_geom(geom=geom)
126         else:
127             mask = Map.from_geom(geom=geom, data=1, dtype=bool)
128         return mask
129 
130     def run(self, dataset, observation=None):
131         """Run FoV background maker.
132 
133         Fit the background model norm
134 
135         Parameters
136         ----------
137         dataset : `~gammapy.datasets.MapDataset`
138             Input map dataset.
139 
140         """
141         mask_fit = dataset.mask_fit
142 
143         dataset.mask_fit = self.make_exclusion_mask(dataset)
144 
145         if dataset.background_model is None:
146             dataset = self.make_default_fov_background_model(dataset)
147 
148         if self.method == "fit":
149             dataset = self.make_background_fit(dataset)
150         else:
151             # always scale the background first
152             dataset = self.make_background_scale(dataset)
153 
154         dataset.mask_fit = mask_fit
155         return dataset
156 
157     @staticmethod
158     def make_background_fit(dataset):
159         """Fit the FoV background model on the dataset counts data
160 
161         Parameters
162         ----------
163         dataset : `~gammapy.datasets.MapDataset`
164             Input dataset.
165 
166         Returns
167         -------
168         dataset : `~gammapy.datasets.MapDataset`
169             Map dataset with fitted background model
170         """
171         # freeze all model components not related to background model
172 
173         models = dataset.models
174 
175         with models.restore_status(restore_values=False):
176             models.select(tag="sky-model").freeze()
177 
178             fit = Fit([dataset])
179             fit_result = fit.run()
180             if not fit_result.success:
181                 log.warning(
182                     f"FoVBackgroundMaker failed. Fit did not converge for {dataset.name}. "
183                     f"Setting mask to False."
184                 )
185                 dataset.mask_safe.data[...] = False
186 
187         return dataset
188 
189     def make_background_scale(self, dataset):
190         """Fit the FoV background model on the dataset counts data
191 
192         Parameters
193         ----------
194         dataset : `~gammapy.datasets.MapDataset`
195             Input dataset.
196 
197         Returns
198         -------
199         dataset : `~gammapy.datasets.MapDataset`
200             Map dataset with scaled background model
201 
202         """
203         mask = dataset.mask
204         count_tot = dataset.counts.data[mask].sum()
205         bkg_tot = dataset.npred_background().data[mask].sum()
206 
207         if count_tot <= self.min_counts:
208             log.warning(
209                 f"FoVBackgroundMaker failed. Only {int(count_tot)} counts outside exclusion mask for {dataset.name}. "
210                 f"Setting mask to False."
211             )
212             dataset.mask_safe.data[...] = False
213         elif bkg_tot <= self.min_npred_background:
214             log.warning(
215                 f"FoVBackgroundMaker failed. Only {int(bkg_tot)} background counts outside exclusion mask for {dataset.name}. "
216                 f"Setting mask to False."
217             )
218             dataset.mask_safe.data[...] = False
219         else:
220             value = count_tot / bkg_tot
221             err = np.sqrt(count_tot) / bkg_tot
222             dataset.models[f"{dataset.name}-bkg"].spectral_model.norm.value = value
223             dataset.models[f"{dataset.name}-bkg"].spectral_model.norm.error = err
224 
225         return dataset
226
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/gammapy/makers/background/fov.py b/gammapy/makers/background/fov.py
--- a/gammapy/makers/background/fov.py
+++ b/gammapy/makers/background/fov.py
@@ -170,7 +170,7 @@
         """
         # freeze all model components not related to background model
 
-        models = dataset.models
+        models = dataset.models.select(tag="sky-model")
 
         with models.restore_status(restore_values=False):
             models.select(tag="sky-model").freeze()

{"golden_diff": "diff --git a/gammapy/makers/background/fov.py b/gammapy/makers/background/fov.py\n--- a/gammapy/makers/background/fov.py\n+++ b/gammapy/makers/background/fov.py\n@@ -170,7 +170,7 @@\n         \"\"\"\n         # freeze all model components not related to background model\n \n-        models = dataset.models\n+        models = dataset.models.select(tag=\"sky-model\")\n \n         with models.restore_status(restore_values=False):\n             models.select(tag=\"sky-model\").freeze()\n", "issue": "FoVBackgroundMaker parameter error not accessible\nAfter the running the `FoVBackgroundMaker`, the error on the fitted parameters is not accessible.\r\n\r\n**To reproduce**\r\nTry `print(dataset.background_model.spectral_model.norm.error)` inside the `Data Reduction Loop` in `analysis_2` notebook. It is always `0`\r\n\r\n**Reason**\r\nIt seems that the error is available at this stage, \r\nhttps://github.com/gammapy/gammapy/blob/df3db33e34233369512d57cca5341a7b645802d6/gammapy/makers/background/fov.py#L180\r\n\r\nbut the info is lost outside the `with models.restore_status` block, eg: in line 187.\r\nI did not understand why, though.\n", "before_files": [{"content": "# Licensed under a 3-clause BSD style license - see LICENSE.rst\n\"\"\"FoV background estimation.\"\"\"\nimport logging\nimport numpy as np\nfrom gammapy.maps import Map\nfrom gammapy.modeling import Fit\nfrom gammapy.modeling.models import FoVBackgroundModel, Model\nfrom ..core import Maker\n\n\n__all__ = [\"FoVBackgroundMaker\"]\n\nlog = logging.getLogger(__name__)\n\n\nclass FoVBackgroundMaker(Maker):\n    \"\"\"Normalize template background on the whole field-of-view.\n\n    The dataset background model can be simply scaled (method=\"scale\") or fitted (method=\"fit\")\n    on the dataset counts.\n\n    The normalization is performed outside the exclusion mask that is passed on init.\n\n    If a SkyModel is set on the input dataset and method is 'fit', it' parameters\n    are frozen during the fov normalization fit.\n\n    If the requirement (greater than) of either min_counts or min_npred_background is not satisfied,\n    the background will not be normalised\n\n    Parameters\n    ----------\n    method : str in ['fit', 'scale']\n        the normalization method to be applied. Default 'scale'.\n    exclusion_mask : `~gammapy.maps.WcsNDMap`\n        Exclusion mask\n    spectral_model : SpectralModel or str\n        Reference norm spectral model to use for the `FoVBackgroundModel`, if none is defined\n        on the dataset. By default, use pl-norm.\n    min_counts : int\n        Minimum number of counts required outside the exclusion region\n    min_npred_background : float\n       Minimum number of predicted background counts required outside the exclusion region\n    \"\"\"\n\n    tag = \"FoVBackgroundMaker\"\n    available_methods = [\"fit\", \"scale\"]\n\n    def __init__(\n        self,\n        method=\"scale\",\n        exclusion_mask=None,\n        spectral_model=\"pl-norm\",\n        min_counts=0,\n        min_npred_background=0,\n    ):\n        self.method = method\n        self.exclusion_mask = exclusion_mask\n        self.min_counts = min_counts\n        self.min_npred_background = min_npred_background\n\n        if isinstance(spectral_model, str):\n            spectral_model = Model.create(tag=spectral_model, model_type=\"spectral\")\n\n        if not spectral_model.is_norm_spectral_model:\n            raise ValueError(\"Spectral model must be a norm spectral model\")\n\n        self.default_spectral_model = spectral_model\n\n    @property\n    def method(self):\n        \"\"\"Method\"\"\"\n        return self._method\n\n    @method.setter\n    def method(self, value):\n        \"\"\"Method setter\"\"\"\n        if value not in self.available_methods:\n            raise ValueError(\n                f\"Not a valid method for FoVBackgroundMaker: {value}.\"\n                f\" Choose from {self.available_methods}\"\n            )\n\n        self._method = value\n\n    def make_default_fov_background_model(self, dataset):\n        \"\"\"Add fov background model to the model definition\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input map dataset.\n\n        Returns\n        -------\n        dataset : `~gammapy.datasets.MapDataset`\n            Map dataset including background model\n\n        \"\"\"\n        bkg_model = FoVBackgroundModel(\n            dataset_name=dataset.name, spectral_model=self.default_spectral_model.copy()\n        )\n\n        if dataset.models is None:\n            dataset.models = bkg_model\n        else:\n            dataset.models = dataset.models + bkg_model\n\n        return dataset\n\n    def make_exclusion_mask(self, dataset):\n        \"\"\"Project input exclusion mask to dataset geom\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input map dataset.\n\n        Returns\n        -------\n        mask : `~gammapy.maps.WcsNDMap`\n            Projected exclusion mask\n        \"\"\"\n        geom = dataset._geom\n        if self.exclusion_mask:\n            mask = self.exclusion_mask.interp_to_geom(geom=geom)\n        else:\n            mask = Map.from_geom(geom=geom, data=1, dtype=bool)\n        return mask\n\n    def run(self, dataset, observation=None):\n        \"\"\"Run FoV background maker.\n\n        Fit the background model norm\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input map dataset.\n\n        \"\"\"\n        mask_fit = dataset.mask_fit\n\n        dataset.mask_fit = self.make_exclusion_mask(dataset)\n\n        if dataset.background_model is None:\n            dataset = self.make_default_fov_background_model(dataset)\n\n        if self.method == \"fit\":\n            dataset = self.make_background_fit(dataset)\n        else:\n            # always scale the background first\n            dataset = self.make_background_scale(dataset)\n\n        dataset.mask_fit = mask_fit\n        return dataset\n\n    @staticmethod\n    def make_background_fit(dataset):\n        \"\"\"Fit the FoV background model on the dataset counts data\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input dataset.\n\n        Returns\n        -------\n        dataset : `~gammapy.datasets.MapDataset`\n            Map dataset with fitted background model\n        \"\"\"\n        # freeze all model components not related to background model\n\n        models = dataset.models\n\n        with models.restore_status(restore_values=False):\n            models.select(tag=\"sky-model\").freeze()\n\n            fit = Fit([dataset])\n            fit_result = fit.run()\n            if not fit_result.success:\n                log.warning(\n                    f\"FoVBackgroundMaker failed. Fit did not converge for {dataset.name}. \"\n                    f\"Setting mask to False.\"\n                )\n                dataset.mask_safe.data[...] = False\n\n        return dataset\n\n    def make_background_scale(self, dataset):\n        \"\"\"Fit the FoV background model on the dataset counts data\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input dataset.\n\n        Returns\n        -------\n        dataset : `~gammapy.datasets.MapDataset`\n            Map dataset with scaled background model\n\n        \"\"\"\n        mask = dataset.mask\n        count_tot = dataset.counts.data[mask].sum()\n        bkg_tot = dataset.npred_background().data[mask].sum()\n\n        if count_tot <= self.min_counts:\n            log.warning(\n                f\"FoVBackgroundMaker failed. Only {int(count_tot)} counts outside exclusion mask for {dataset.name}. \"\n                f\"Setting mask to False.\"\n            )\n            dataset.mask_safe.data[...] = False\n        elif bkg_tot <= self.min_npred_background:\n            log.warning(\n                f\"FoVBackgroundMaker failed. Only {int(bkg_tot)} background counts outside exclusion mask for {dataset.name}. \"\n                f\"Setting mask to False.\"\n            )\n            dataset.mask_safe.data[...] = False\n        else:\n            value = count_tot / bkg_tot\n            err = np.sqrt(count_tot) / bkg_tot\n            dataset.models[f\"{dataset.name}-bkg\"].spectral_model.norm.value = value\n            dataset.models[f\"{dataset.name}-bkg\"].spectral_model.norm.error = err\n\n        return dataset\n", "path": "gammapy/makers/background/fov.py"}], "after_files": [{"content": "# Licensed under a 3-clause BSD style license - see LICENSE.rst\n\"\"\"FoV background estimation.\"\"\"\nimport logging\nimport numpy as np\nfrom gammapy.maps import Map\nfrom gammapy.modeling import Fit\nfrom gammapy.modeling.models import FoVBackgroundModel, Model\nfrom ..core import Maker\n\n\n__all__ = [\"FoVBackgroundMaker\"]\n\nlog = logging.getLogger(__name__)\n\n\nclass FoVBackgroundMaker(Maker):\n    \"\"\"Normalize template background on the whole field-of-view.\n\n    The dataset background model can be simply scaled (method=\"scale\") or fitted (method=\"fit\")\n    on the dataset counts.\n\n    The normalization is performed outside the exclusion mask that is passed on init.\n\n    If a SkyModel is set on the input dataset and method is 'fit', it' parameters\n    are frozen during the fov normalization fit.\n\n    If the requirement (greater than) of either min_counts or min_npred_background is not satisfied,\n    the background will not be normalised\n\n    Parameters\n    ----------\n    method : str in ['fit', 'scale']\n        the normalization method to be applied. Default 'scale'.\n    exclusion_mask : `~gammapy.maps.WcsNDMap`\n        Exclusion mask\n    spectral_model : SpectralModel or str\n        Reference norm spectral model to use for the `FoVBackgroundModel`, if none is defined\n        on the dataset. By default, use pl-norm.\n    min_counts : int\n        Minimum number of counts required outside the exclusion region\n    min_npred_background : float\n       Minimum number of predicted background counts required outside the exclusion region\n    \"\"\"\n\n    tag = \"FoVBackgroundMaker\"\n    available_methods = [\"fit\", \"scale\"]\n\n    def __init__(\n        self,\n        method=\"scale\",\n        exclusion_mask=None,\n        spectral_model=\"pl-norm\",\n        min_counts=0,\n        min_npred_background=0,\n    ):\n        self.method = method\n        self.exclusion_mask = exclusion_mask\n        self.min_counts = min_counts\n        self.min_npred_background = min_npred_background\n\n        if isinstance(spectral_model, str):\n            spectral_model = Model.create(tag=spectral_model, model_type=\"spectral\")\n\n        if not spectral_model.is_norm_spectral_model:\n            raise ValueError(\"Spectral model must be a norm spectral model\")\n\n        self.default_spectral_model = spectral_model\n\n    @property\n    def method(self):\n        \"\"\"Method\"\"\"\n        return self._method\n\n    @method.setter\n    def method(self, value):\n        \"\"\"Method setter\"\"\"\n        if value not in self.available_methods:\n            raise ValueError(\n                f\"Not a valid method for FoVBackgroundMaker: {value}.\"\n                f\" Choose from {self.available_methods}\"\n            )\n\n        self._method = value\n\n    def make_default_fov_background_model(self, dataset):\n        \"\"\"Add fov background model to the model definition\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input map dataset.\n\n        Returns\n        -------\n        dataset : `~gammapy.datasets.MapDataset`\n            Map dataset including background model\n\n        \"\"\"\n        bkg_model = FoVBackgroundModel(\n            dataset_name=dataset.name, spectral_model=self.default_spectral_model.copy()\n        )\n\n        if dataset.models is None:\n            dataset.models = bkg_model\n        else:\n            dataset.models = dataset.models + bkg_model\n\n        return dataset\n\n    def make_exclusion_mask(self, dataset):\n        \"\"\"Project input exclusion mask to dataset geom\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input map dataset.\n\n        Returns\n        -------\n        mask : `~gammapy.maps.WcsNDMap`\n            Projected exclusion mask\n        \"\"\"\n        geom = dataset._geom\n        if self.exclusion_mask:\n            mask = self.exclusion_mask.interp_to_geom(geom=geom)\n        else:\n            mask = Map.from_geom(geom=geom, data=1, dtype=bool)\n        return mask\n\n    def run(self, dataset, observation=None):\n        \"\"\"Run FoV background maker.\n\n        Fit the background model norm\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input map dataset.\n\n        \"\"\"\n        mask_fit = dataset.mask_fit\n\n        dataset.mask_fit = self.make_exclusion_mask(dataset)\n\n        if dataset.background_model is None:\n            dataset = self.make_default_fov_background_model(dataset)\n\n        if self.method == \"fit\":\n            dataset = self.make_background_fit(dataset)\n        else:\n            # always scale the background first\n            dataset = self.make_background_scale(dataset)\n\n        dataset.mask_fit = mask_fit\n        return dataset\n\n    @staticmethod\n    def make_background_fit(dataset):\n        \"\"\"Fit the FoV background model on the dataset counts data\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input dataset.\n\n        Returns\n        -------\n        dataset : `~gammapy.datasets.MapDataset`\n            Map dataset with fitted background model\n        \"\"\"\n        # freeze all model components not related to background model\n\n        models = dataset.models.select(tag=\"sky-model\")\n\n        with models.restore_status(restore_values=False):\n            models.select(tag=\"sky-model\").freeze()\n\n            fit = Fit([dataset])\n            fit_result = fit.run()\n            if not fit_result.success:\n                log.warning(\n                    f\"FoVBackgroundMaker failed. Fit did not converge for {dataset.name}. \"\n                    f\"Setting mask to False.\"\n                )\n                dataset.mask_safe.data[...] = False\n\n        return dataset\n\n    def make_background_scale(self, dataset):\n        \"\"\"Fit the FoV background model on the dataset counts data\n\n        Parameters\n        ----------\n        dataset : `~gammapy.datasets.MapDataset`\n            Input dataset.\n\n        Returns\n        -------\n        dataset : `~gammapy.datasets.MapDataset`\n            Map dataset with scaled background model\n\n        \"\"\"\n        mask = dataset.mask\n        count_tot = dataset.counts.data[mask].sum()\n        bkg_tot = dataset.npred_background().data[mask].sum()\n\n        if count_tot <= self.min_counts:\n            log.warning(\n                f\"FoVBackgroundMaker failed. Only {int(count_tot)} counts outside exclusion mask for {dataset.name}. \"\n                f\"Setting mask to False.\"\n            )\n            dataset.mask_safe.data[...] = False\n        elif bkg_tot <= self.min_npred_background:\n            log.warning(\n                f\"FoVBackgroundMaker failed. Only {int(bkg_tot)} background counts outside exclusion mask for {dataset.name}. \"\n                f\"Setting mask to False.\"\n            )\n            dataset.mask_safe.data[...] = False\n        else:\n            value = count_tot / bkg_tot\n            err = np.sqrt(count_tot) / bkg_tot\n            dataset.models[f\"{dataset.name}-bkg\"].spectral_model.norm.value = value\n            dataset.models[f\"{dataset.name}-bkg\"].spectral_model.norm.error = err\n\n        return dataset\n", "path": "gammapy/makers/background/fov.py"}]}