Repository: gammapy/gammapy

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.


Discussion:

Resolving patch:
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 @@ def make_background_fit(dataset):
         """
         # 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()


Test patch:
diff --git a/gammapy/makers/background/tests/test_fov.py b/gammapy/makers/background/tests/test_fov.py
--- a/gammapy/makers/background/tests/test_fov.py
+++ b/gammapy/makers/background/tests/test_fov.py
@@ -71,19 +71,6 @@ def test_fov_bkg_maker_incorrect_method():
         FoVBackgroundMaker(method="bad")
 
 
-@requires_data()
-@requires_dependency("iminuit")
-def test_fov_bkg_maker_fit(obs_dataset, exclusion_mask):
-    fov_bkg_maker = FoVBackgroundMaker(method="fit", exclusion_mask=exclusion_mask)
-
-    test_dataset = obs_dataset.copy(name="test-fov")
-    dataset = fov_bkg_maker.run(test_dataset)
-
-    model = dataset.models[f"{dataset.name}-bkg"].spectral_model
-    assert_allclose(model.norm.value, 0.830789, rtol=1e-4)
-    assert_allclose(model.tilt.value, 0.0, rtol=1e-4)
-
-
 @requires_data()
 def test_fov_bkg_maker_scale(obs_dataset, exclusion_mask, caplog):
     fov_bkg_maker = FoVBackgroundMaker(method="scale", exclusion_mask=exclusion_mask)
@@ -119,18 +106,33 @@ def test_fov_bkg_maker_scale_nocounts(obs_dataset, exclusion_mask, caplog):
 @requires_data()
 @requires_dependency("iminuit")
 def test_fov_bkg_maker_fit(obs_dataset, exclusion_mask):
+    fov_bkg_maker = FoVBackgroundMaker(method="fit", exclusion_mask=exclusion_mask)
+
+    dataset1 = obs_dataset.copy(name="test-fov")
+    dataset = fov_bkg_maker.run(dataset1)
+
+    model = dataset.models[f"{dataset.name}-bkg"].spectral_model
+    assert_allclose(model.norm.value, 0.83077, rtol=1e-4)
+    assert_allclose(model.norm.error, 0.02069, rtol=1e-2)
+    assert_allclose(model.tilt.value, 0.0, rtol=1e-4)
+    assert_allclose(model.tilt.error, 0.0, rtol=1e-2)
+    assert_allclose(fov_bkg_maker.default_spectral_model.tilt.value, 0.0)
+    assert_allclose(fov_bkg_maker.default_spectral_model.norm.value, 1.0)
+
     spectral_model = PowerLawNormSpectralModel()
     spectral_model.tilt.frozen = False
     fov_bkg_maker = FoVBackgroundMaker(
         method="fit", exclusion_mask=exclusion_mask, spectral_model=spectral_model
     )
 
-    test_dataset = obs_dataset.copy(name="test-fov")
-    dataset = fov_bkg_maker.run(test_dataset)
+    dataset2 = obs_dataset.copy(name="test-fov")
+    dataset = fov_bkg_maker.run(dataset2)
 
     model = dataset.models[f"{dataset.name}-bkg"].spectral_model
     assert_allclose(model.norm.value, 0.901523, rtol=1e-4)
+    assert_allclose(model.norm.error, 0.6088, rtol=1e-2)
     assert_allclose(model.tilt.value, 0.071069, rtol=1e-4)
+    assert_allclose(model.tilt.error, 0.5866, rtol=1e-2)
     assert_allclose(fov_bkg_maker.default_spectral_model.tilt.value, 0.0)
     assert_allclose(fov_bkg_maker.default_spectral_model.norm.value, 1.0)