cosimoNigro / agnpy

Modelling jetted Active Galactic Nuclei radiative processes with python
https://agnpy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
48 stars 33 forks source link

Providing a fit tutorial for a BL Lac SED #68

Closed cosimoNigro closed 2 years ago

cosimoNigro commented 3 years ago

We decided not to include any fit wrapper in the code but to simply show in a couple of tutorial notebooks how to implement one using sherpa. Sherpa has several minimisation routines and data handling utilities. We should have a working example with Synchrotron + SSC for a BL Lac, I started it in this notebook using the famous 2011 MWL observations of Mrk421.

The fit is not converging and it has to be fixed.

jsitarek commented 3 years ago

I'm working on making the one for FSRQ EC fit and going through this example for SSC fit of Mrk I realized that you are not using SSA in the synchrotron fit. Even while it does not change the result in this particular case (see the figure below ) and makes the fiting procedure probably a tiny bit faster, for such an example I think it would be best to include explicit SSA by " ssa=True" in the calc function ssa_in_ssc_fit

cosimoNigro commented 3 years ago

Hi @jsitarek yesterday finally managed to get the fit converging with sherpa. The trick was to define the function to be minimised with the logarithm of the parameters that vary over several orders of magnitude (e.g. normalisation, Lorentz factors of the electron distribution k_e, gamma_0). Only fitting the parameters of the LogParabola electron distribution (minimum and maximum Lorentz factor fixed though) takes only ~7 sec! Check the updated notebook.

Of course the fit can be improved in several ways, using a different minimiser from sherpa (e.g. MC minimisation) or including secondary effects like SSA. I am keeping this issue open until when we are completely satisfied with the Mrk 421 SED fit. In the next iteration I will try to understand better the sherpa minimisers and I will include the SSA.

cosimoNigro commented 3 years ago

The notebook added in the new docs.

cosimoNigro commented 2 years ago

It's been a while that we have proper examples for fitting, so I am closing this.