1 Introduction

The anomalous magnetic moment of the muon, \(a_\mu \), is one of the most important observables in particle physics. Its importance stems from the fact that it is one of the most precisely measured physical quantities and that it is very sensitive to new physics as well as the strong, weak and electromagnetic interactions of the Standard Model (SM). The significance of \({a_\mu }\) has increased further in the wake of the recent release of the first results from the Fermilab Muon \(g-2\) experiment [1]. This collaboration found, in combination with the results from the Brookhaven National Laboratory [2], an experimental value of

$$\begin{aligned} a_\mu ^\text {Exp} = (11659206.1\pm 4.1)\times 10^{-10}. \end{aligned}$$
(1)

The SM prediction from the Muon \(g-2\) Theory Initiative White Paper [3] is

$$\begin{aligned} a_\mu ^{{\text {SM}}} = (11659181.0\pm 4.3)\times 10^{-10}, \end{aligned}$$
(2)

which combines quantum electrodynamic contributions [4, 5], electroweak contributions [6, 7], hadronic vacuum- polarization [8,9,10,11,12,13,14] and light-by-light contributions [15,16,17,18,19,20,21,22,23,24,25,26,27,28,29].Footnote 1 The experimental measurement differs from the SM prediction by \(4.2\sigma \) which suggests a beyond the Standard Model (BSM) contribution of

$$\begin{aligned} a_\mu ^{{\text {BSM}}}= (25.1\pm 5.9)\times 10^{-10}. \end{aligned}$$
(3)

The high precision in both the experimental measurement and the SM theoretical prediction requires BSM contributions to be known with a similar level of accuracy.

The Two-Higgs Doublet Model (2HDM) is one of the simplest and most widely studied extensions of the SM (see e.g. Ref. [42] for a review or the relevant chapters of Ref. [43]). Although the 2HDM has been studied for many decades and the only Higgs boson discovered is closely SM-like [44, 45], interest in this model has not waned, and recent progress has been achieved e.g. on LHC interpretations [46,47,48,49,50], B-physics [51,52,53,54,55], theoretical constraints [56,57,58,59,60], electroweak phase transitions in the early universe [61,62,63,64,65], precision calculations of Higgs decays [66,67,68,69,70,71,72,73,74]. Remarkably, the 2HDM is one of the very few single field extensions of the Standard Model that can explain the deviation between \({a_\mu ^\text {Exp}}\) and \({a_\mu ^{{\text {SM}}}}\) [75] while satisfying existing constraints from collider physics searches and other observables.

A second Higgs doublet that can couple to SM fermions generically induces large tree-level flavour changing neutral currents at odds with experiment. Due to this 2HDM s are often classified according to the discrete symmetries imposed to conserve flavour, giving four types [76]: type I [77], type II [78], type X (often called the lepton specific 2HDM) [79, 80] and type Y (sometimes refereed to as the flipped 2HDM) [81, 82]. Large flavour changing neutral currents can also be avoided by assuming an alignment in flavour space between the Yukawa matrices of the two doublets, giving the so-called flavour-aligned 2HDM (FA2HDM) [83, 84]. After the first results of the LHC, Ref. [85] systematically investigated the phenomenology of all 2HDM versions with discrete symmetries and showed that among them, only the type X variant is able to provide significant contributions to \({a_\mu }\). The type X explanation of the deviation between \({a_\mu ^\text {Exp}}\) and \({a_\mu ^{{\text {SM}}}}\) has been further explored in Refs. [86,87,88,89,90,91,92,93,94,95,96,97,98,99]. The more general flavour-aligned 2HDM and its contributions to \({a_\mu }\) were studied in Refs. [75, 100,101,102,103,104]. Other variants, including more general realisations that allow for Higgs-mediated flavour violation were investigated in Refs. [105,106,107,108,109,110,111,112].

Phenomenological investigations of BSM physics are greatly enhanced by the use of precise software tools. These tools can automate the calculation of precision corrections, or provide numerical methods to quickly and reliably solve related problems. For example in the 2HDM one is often concerned that a particular benchmark point respects measured limits of electroweak oblique parameters, or that the new couplings and bosons do not provide contributions to Higgs decays which violate collider constraints. For the 2HDM a widely used software package is 2HDMC [113], which provides calculations of the spectrum, decays, oblique S, T and U parameters as well as a calculation of the 2HDM new physics contributions to \({a_\mu }\). There also exists the tool ScannerS [114] which can place theoretical, experimental, dark matter, and electroweak phase transition constraints on extended scalar sectors, including the 2HDM. A more precise calculation of the decays is available from the 2HDM decay dedicated code 2HDECAY [115], while PROPHECY4F [116] provides a package which focuses on calculating \(h\rightarrow WW/ZZ\rightarrow 4f\) decays. Additionally, the tools HiggsBounds [117,118,119,120,121] and [122,123,124] allow one to place constraints on the Higgs sectors of BSM physics through the measured behaviour of Higgs bosons from collider search experiments.

Higher precision calculations for the spectrum, decays and other observables in the 2HDM are also available for arbitrary user-defined extensions of the SM through codes such as SARAH/SPheno [125,126,127,128,129,130] and FlexibleSUSY [131,132,133,134] (with decays recently added in FlexibleDecay [134]) where model files for the 2HDM are already distributed. Additionally, both packages provide one-loop contributions to \({a_\mu ^{{\text {BSM}}}}\). For two-loop contributions to \({a_\mu ^{{\text {BSM}}}}\) in the MSSM, FlexibleSUSY links to the dedicated tool GM2Calc [135]. For the 2HDM there was no such option until now. Here we extend GM2Calc with the 2HDM to provide a program which includes state of the art two-loop level contributions of Ref. [102] to the anomalous magnetic moment of the muon.

The 2HDM contributions implemented in GM2Calc version 2 include the one-loop contributions, the two-loop fermionic corrections (including the well-known Barr-Zee diagrams), and the complete set of bosonic two-loop corrections. The one-loop contributions are of the order \(\mathcal {O}(m_\mu ^4)\) and therefore usually subdominant. The two-loop contributions arise at \(\mathcal {O}(m_\mu ^2)\) and are implemented at this order. Ref. [102] has assumed the flavour-aligned 2HDM with vanishing couplings \(\lambda _{6,7}\), but here we relax this assumption and allow the more general case. The 2HDM version of GM2Calc 2 allows the user to input deviations from the aligned limit, as well as select any one of the 2HDM types I, II, X or Y. Just like version 1, GM2Calc 2 allows the user to input parameter information using an SLHA-like [136, 137] input file. We also provide interfaces in C, C++, Python and Mathematica to make it easy to link to other public codes. Furthermore, GM2Calc 2 (hereafter GM2Calc) can be used as a standalone tool for studies of \(a_\mu \) in the 2HDM, or to explore the 2HDM phenomenology more broadly it can be used in combination with other codes via the SLHA interface. For example, GM2Calc can be called alongside FlexibleSUSY, or in combination with other standalone tools like 2HDECAY or alongside the 2HDMC package, replacing its native calculation of the anomalous magnetic moment of the muon. The MSSM calculation is already available in GAMBIT [138, 139] and it should be straightforward to extend this to also use the 2HDM calculation in future versions.

The rest of this paper is divided into the following sections. Section 2 provides a pedagogical introduction to the 2HDM, giving the Lagrangian both before and after electroweak symmetry breaking, and defining the Yukawa couplings in the various types of the 2HDM. There we give the one- and two-loop contributions to \({a_\mu ^{{\text {BSM}}}}\), and the uncertainty estimate for the calculation. Section 3 describes various ways to use the 2HDM in GM2Calc. It also shows how to interface GM2Calc using C++, C, Python and Mathematica. Finally, Sect. 4 demonstrates various possible ways GM2Calc can be applied to calculate the BSM contributions to the anomalous magnetic moment of the muon in the 2HDM.

2 Review of 2HDM and implemented contributions to \({a_\mu }\)

2.1 The Model

The Two-Higgs Doublet Model (2HDM) extends the Standard Model (SM) with an additional scalar \({\text {SU}(2)}\) doublet. We denote the two complex Higgs \({\text {SU}(2)}\) doublets in the 2HDM as \(\Phi _i\) (\(i=1,2\)),

$$\begin{aligned} \Phi _i = \begin{pmatrix} a_i ^+ \\ \frac{1}{\sqrt{2}} \left( v_i + b_i + \text {i}c_i \right) \end{pmatrix}, \end{aligned}$$
(4)

where \(b_i\) and \(c_i\) are real scalar fields and \(a_i^+\) are complex scalar fields. Each Higgs doublet acquires a real non-zero vacuum expectation value (VEV), \(v_i\), which satisfy

$$\begin{aligned} \tan \beta&= \frac{v_2}{v_1},\quad v^2 = v_1^2 + v_2^2, \end{aligned}$$
(5)

with \(0 \le \beta \le \pi /2\) and \({v \approx 246\,\text {GeV}}\), which implies \(v_1 = v\cos \beta \) and \(v_2 = v\sin \beta \). The extended Lagrangian includes the Higgs potential \(\mathcal {L}_{\text {Scalar}}\) and the Yukawa interaction part \(\mathcal {L}_{\text {Yuk}}\),

$$\begin{aligned} \mathcal {L}&\ni \mathcal {L}_\text {Scalar} + \mathcal {L}_\text {Yuk} . \end{aligned}$$
(6)

The most general form of Higgs potential is

$$\begin{aligned} \begin{aligned} -\mathcal {L}_\text {Scalar}&= m_{11}^2 \Phi _1^\dagger \Phi _1 + m_{22}^2 \Phi _2^\dagger \Phi _2 - \left[ m_{12}^2 \Phi _1^\dagger \Phi _2 + \text {h. c.}\right] \\&\quad + \frac{1}{2} \lambda _1 \left( \Phi _1^\dagger \Phi _1 \right) ^2 + \frac{1}{2} \lambda _2 \left( \Phi _2^\dagger \Phi _2 \right) ^2 \\&\quad + \lambda _3 \left( \Phi _1^\dagger \Phi _1 \right) \left( \Phi _2^\dagger \Phi _2 \right) + \lambda _4 \left( \Phi _1^\dagger \Phi _2 \right) \left( \Phi _2^\dagger \Phi _1 \right) \\&\quad + \left[ \frac{1}{2} \lambda _5 \left( \Phi _1^\dagger \Phi _2 \right) ^2 + \lambda _6 \left( \Phi _1^\dagger \Phi _1 \right) \left( \Phi _1^\dagger \Phi _2 \right) \right. \\&\quad \left. + \lambda _7 \left( \Phi _2^\dagger \Phi _2 \right) \left( \Phi _1^\dagger \Phi _2 \right) + \text {h. c.}\right] , \end{aligned} \end{aligned}$$
(7)

where \(\lambda _5\), \(\lambda _6\), \(\lambda _7\) and \(m_{12} ^2\) are real for the CP-conserving Higgs potential. The mass eigenstates of Higgs and Goldstone bosons h, H, A, \(H^+\), \(G^0\) and \(G^+\) are obtained as

$$\begin{aligned} \begin{pmatrix} h \\ H \end{pmatrix}&= Z_{\mathcal {H}^0} \mathcal {H}^0 ,&\begin{pmatrix} G^0 \\ A \end{pmatrix}&= Z_{\mathcal {A}} \mathcal {A} ,&\begin{pmatrix} G^+ \\ H^+ \end{pmatrix}&= Z_{\mathcal {H}^+} \mathcal {H}^+ , \end{aligned}$$
(8)

with

$$\begin{aligned} \mathcal {H}^0&= \begin{pmatrix} b_1 \\ b_2 \end{pmatrix},&\mathcal {A}&= \begin{pmatrix} c_1 \\ c_2 \end{pmatrix} ,&\mathcal {H}^+&= \begin{pmatrix} a_1^+ \\ a_2^+ \end{pmatrix}, \end{aligned}$$
(9)

from Eq. (7). The orthogonal matrices \(Z_{\mathcal {H}^0}\), \(Z_{\mathcal {A}}\) and \(Z_{\mathcal {H}^\pm }\) for Eq. (8) are given as

$$\begin{aligned} Z_{\mathcal {H}^0}&= \begin{pmatrix} -\sin \alpha &{} \cos \alpha \\ \cos \alpha &{} \sin \alpha \end{pmatrix} ,&Z_{\mathcal {A}}&= \begin{pmatrix} \cos \beta &{} \sin \beta \\ -\sin \beta &{} \cos \beta \end{pmatrix} ,\nonumber \\ Z_{\mathcal {H}^+}&= \begin{pmatrix} \cos \beta &{} \sin \beta \\ -\sin \beta &{} \cos \beta \end{pmatrix} . \end{aligned}$$
(10)

The corresponding mass square matrices \(M_{\mathcal {H}^0} ^2\), \(M_{\mathcal {A}} ^2\) and \(M_{\mathcal {H}^+} ^2\) for \(\mathcal {H}^0\), \(\mathcal {A}\) and \(\mathcal {H}^+\) in Eq. (9), respectively, are diagonalized as

$$\begin{aligned} M_{\mathcal {H}^0} ^2&= Z_{\mathcal {H}^0}^\dagger (M_{\mathcal {H}^0}^D) ^2 Z_{\mathcal {H}^0} ,&M_{\mathcal {A}} ^2&= Z_\mathcal {A}^\dagger (M_{\mathcal {A}}^D) ^2 Z_\mathcal {A} , \nonumber \\ M_{\mathcal {H}^+} ^2&= Z_{\mathcal {H}^+}^\dagger (M_{\mathcal {H}^+}^D) ^2 Z_{\mathcal {H}^+} . \end{aligned}$$
(11)

The Higgs boson mass eigenvalues are denoted as

$$\begin{aligned} M_{\mathcal {H}^0}^D&= {{\,\mathrm{diag}\,}}( m_h , m_H ), M_{\mathcal {A}}^D = {{\,\mathrm{diag}\,}}( m_{G^0} , m_A ), \nonumber \\ M_{\mathcal {H}^\pm }^D&= {{\,\mathrm{diag}\,}}( m_{G^\pm } , m_{H^\pm } ), \end{aligned}$$
(12)

where in Feynman gauge \(m_{G^+}=m_W\) and \(m_{G^0}=m_Z\). We chose the CP-even Higgs boson mixing angle \(\alpha \) such that \(-\pi /2 \le \beta - \alpha \le \pi /2\) [113].

The general form of the Yukawa interaction Lagrangian is given as

$$\begin{aligned} -\mathcal {L}_\text {Yuk}&= \Gamma _d ^0\overline{q_L ^0}\Phi _1 d_R ^0 + \Gamma _u ^0 \overline{q_L ^0}\Phi _1 ^{c} u_R ^0 + \Gamma _l ^0 \overline{l_L ^0}\Phi _1 e_R ^0\nonumber \\&\quad + \Pi ^0_d \overline{q_L ^0}\Phi _2 d_R ^0 + \Pi ^0_u \overline{q_L ^0}\Phi _2 ^{c} u_R ^0 + \Pi ^0_l \overline{l_L ^0}\Phi _2 e_R ^0 + \text {h. c.} \end{aligned}$$
(13)

where \(\Phi _i^{c} \equiv \text {i}\sigma ^2 \Phi _i^*\), and \(q_L ^0\), \(l_L ^0\), \(u_R ^0\), \(d_R ^0\), and \(e_R ^0\) are fermion gauge eigenstates.Footnote 2 In general the Yukawa coupling matrices, \(\Gamma _f ^0\) and \(\Pi ^0_f\) (\(f=u,d,l\)) are complex and non-diagonal \(3\times 3\) matrices which can not be simultaneously diagonalized, which produces flavour changing neutral currents (FCNC).

From the Yukawa interaction Lagrangian in Eq. (13) the \(3\times 3\) fermion mass matrices \(M_f\) (\(f=u,d,l\)) are obtained as

$$\begin{aligned} M_u&= \frac{1}{\sqrt{2}} \left( v_1 \Gamma _u ^0 + v_2 \Pi ^0_u \right) , \end{aligned}$$
(14)
$$\begin{aligned} M_d&= \frac{1}{\sqrt{2}} \left( v_1 \Gamma _d ^0 + v_2 \Pi ^0_d \right) , \end{aligned}$$
(15)
$$\begin{aligned} M_l&= \frac{1}{\sqrt{2}} \left( v_1 \Gamma _l ^0+ v_2 \Pi ^0_l \right) . \end{aligned}$$
(16)

The fermion mass matrices are diagonalized using singular value decomposition. The diagonal fermion mass matrices \(M_f^D\) (\(f=u,d,l\)) are given by

$$\begin{aligned} M_u&= V_u^\dagger M_u^D U_u , \quad \text { with } \quad M_u^D = {{\,\mathrm{diag}\,}}( m_u , m_c , m_t) , \end{aligned}$$
(17)
$$\begin{aligned} M_d&= V_d^\dagger M_d^D U_d , \quad \text { with }\quad M_d^D = {{\,\mathrm{diag}\,}}( m_d , m_s , m_b) , \end{aligned}$$
(18)
$$\begin{aligned} M_l&= V_l^\dagger M_l^D U_l , \quad \text { with } \quad M_l^D = {{\,\mathrm{diag}\,}}( m_e , m_\mu , m_\tau ) , \end{aligned}$$
(19)

where \(V_f\) and \(U_f\) are unitary matrices, and the corresponding fermion mass eigenstates \(f=u,d,l\) are obtained as

$$\begin{aligned} f _L&= V _f f_L ^0, \quad \text {and}\quad f _R =U _f f_R ^0 . \end{aligned}$$
(20)

By combining Eq. (5) and Eqs. (14)–(16), \(\Gamma _u ^0\), \(\Gamma _d ^0\) and \(\Gamma _l ^0\) can be expressed in terms of \(M_f\) and \({\Pi ^0_f}\) as

$$\begin{aligned} { \Gamma _f ^0 = \frac{\sqrt{2} M_f}{v\cos \beta } - \Pi ^0_f \tan \beta .} \end{aligned}$$
(21)

The Yukawa interaction Lagrangian Eq. (13) can be also written in the so-called Higgs basis, where only one Higgs doublet has non-zero VEV. This can be obtained by rotating \(\Phi _{1,2}\) and the Yukawa matrices as

$$\begin{aligned} \begin{pmatrix} \Phi _v \\ \Phi _\perp \end{pmatrix}&= \begin{pmatrix} \cos \beta &{} \sin \beta \\ -\sin \beta &{} \cos \beta \end{pmatrix} \begin{pmatrix} \Phi _1 \\ \Phi _2 \end{pmatrix}, \end{aligned}$$
(22)
$$\begin{aligned} \begin{pmatrix} \Sigma _f ^0\\ \rho ^0_f \end{pmatrix}&= \begin{pmatrix} \cos \beta &{} \sin \beta \\ -\sin \beta &{} \cos \beta \end{pmatrix} \begin{pmatrix} \Gamma _f ^0 \\ \Pi ^0_f \end{pmatrix} , \end{aligned}$$
(23)

such that only \(\Phi _v\) has the VEV v and \(\Sigma ^0_f\) are its Yukawa couplings. It contains the SM-like Goldstone bosons, whereas the second field \(\Phi _\perp \) contains non-SM Higgs bosons \(H^\pm \) and A, and its Yukawa couplings \(\rho ^0_f\) are important parameters in the 2HDM.Footnote 3 With this transformation the Yukawa interaction Lagrangian becomes

$$\begin{aligned} -\mathcal {L}_\text {Yuk}&= \Sigma _d ^0 \overline{q_L ^0}\Phi _v d_R ^0 + \Sigma _u ^0 \overline{q_L ^0}\Phi _v ^{c} u_R ^0 + \Sigma _l ^0 \overline{l_L ^0}\Phi _v e_R ^0\nonumber \\&\quad + \rho ^0_d \overline{q_L ^0}\Phi _\perp d_R ^0 + \rho ^0_u \overline{q_L ^0}\Phi _\perp ^{c} u_R ^0 + \rho ^0_l \overline{l_L ^0}\Phi _\perp e_R ^0 + \text {h. c.} \end{aligned}$$
(24)

In this way, the fermion masses are purely generated from the Higgs doublet \(\Phi _v\), and the fermion mass matrices in Eqs. (14)–(16) become

$$\begin{aligned} M_u&= \frac{v}{\sqrt{2}}\Sigma _u ^0 ,&M_d&= \frac{v}{\sqrt{2}}\Sigma _d ^0 ,&M_l&= \frac{v}{\sqrt{2}}\Sigma _l ^0, \end{aligned}$$
(25)

which implies \(V_f \Sigma _f^0 U_f^\dagger = \sqrt{2}M_f^D/v\). In parallel to Eqs. (17)–(19) we may define Yukawa matrices in the basis of mass eigenstates as (\(f=u,d,l\))

$$\begin{aligned} \Pi _f&\equiv V _f \Pi ^0_f U _f ^\dagger ,&\Sigma _f&\equiv V_f \Sigma _f ^0 U _f ^\dagger , \end{aligned}$$
(26a)
$$\begin{aligned} \Gamma _f&\equiv V _f \Gamma _f^0 U _f ^\dagger ,&\rho _f&\equiv V _f \rho ^0_f U _f ^\dagger . \end{aligned}$$
(26b)

Importantly, in the Higgs basis the \(\Sigma _f ^0\) are diagonalized by the singular value decomposition involving \(V_f\) and \(U_f\), but in general the \({\rho ^0_f}\) are not. This implies that Higgs-mediated FCNCs are induced by the coupling with the zero-VEV Higgs doublet \(\Phi _\perp \).

From Eqs. (17)–(19), (23), and (25) we obtain

$$\begin{aligned} \Pi _f&= \sqrt{2}\frac{M_f ^D}{v} \sin \beta + \rho _f \cos \beta , \end{aligned}$$
(27)

where \(\Pi _f \equiv V _f \Pi ^0_f U _f ^\dagger \) and \({\rho _f \equiv V _f \rho ^0_f U _f ^\dagger }\). The \(\rho _f\) matrices contain non-zero off-diagonal components, which reflects that in general the two types of Yukawa coupling matrices \(\Gamma _f ^0\) and \(\Pi ^0_f\) can not be simultaneously diagonalized in the 2HDM. The \(\rho _f\) term in Eq. (27) can induce Higgs-mediated flavour-changing neutral currents (FCNC) at the tree-level. GM2Calc implements several variants of the 2HDM with or without Higgs-mediated FCNC:

  • The four well-known types with \(Z_2\) symmetry: type I, type II, type X, type Y,

  • the flavour-aligned 2HDM (FA2HDM) [83, 84], which also avoids tree-level Higgs-mediated FCNC and contains the four previous types as special cases,

  • the 2HDM with general Yukawa structures.

We will now describe these variants of the 2HDM. The most common way to avoid FCNC is to impose a \(Z_2\) symmetry, which leads to four different types of Yukawa interactions in which specific subsets of Yukawa couplings vanish. In the type I model all quarks and charged leptons couple to \(\Phi _2\), so we set

$$\begin{aligned} \Gamma _u ^0 = \Gamma _d ^0 = \Gamma _l ^0= 0. \end{aligned}$$
(28)

In the type II model all up-type quarks couple to \(\Phi _2\), while the down-type quarks and charged leptons couple to \(\Phi _1\), so we set

$$\begin{aligned} {\Gamma _u ^0= \Pi ^0_d = \Pi ^0_l = 0.} \end{aligned}$$
(29)

In the type X model all quarks couple to \(\Phi _2\), while the charged leptons couple to \(\Phi _1\), so we set

$$\begin{aligned} {\Gamma _u ^0 = \Gamma _d ^0 = \Pi ^0_l = 0.} \end{aligned}$$
(30)

In the type Y model the up-type quarks and charged leptons couple to \(\Phi _2\), while the down-type quarks couple to \(\Phi _1\), so we set

$$\begin{aligned} {\Gamma _u ^0 = \Pi ^0_d = \Gamma _l ^0 = 0.} \end{aligned}$$
(31)

In all these cases, trivially \(\Gamma _f ^0\) and \({\Pi ^0_f}\) can be diagonalized simultaneously, and Higgs-mediated FCNC is avoided.

In the flavour-aligned Two-Higgs Doublet Model (FA2HDM) [83, 84] it is assumed that the \(\Pi ^0_f\) matrices are proportional to the \(\Gamma _f ^0\) matrices, and we set

$$\begin{aligned} \Pi ^0_f&= {\left\{ \begin{array}{ll} \xi _u^{*} \Gamma _u ^0, &{} \text {if }f=u, \\ \xi _{d,l} \Gamma _{d,l} ^0, &{} \text {if }f=d,l, \\ \end{array}\right. }&\text {with}&\xi _f&= \frac{\zeta _f + \tan \beta }{1 - \zeta _f\tan \beta } , \end{aligned}$$
(32)

where \(\zeta _f\) are the alignment parameters which are constrained by experimental results and used in phenomenological studies. Note that the aligned model contains the type I, II, X and Y models as special cases when the alignment parameters \(\zeta _f\) take the values given in Table 1.

We can summarize the fundamental Yukawa coupling matrices \(\rho _f\) (\(f=u,d,l\)) for the different 2HDM variants and in different parametrizations as follows:

$$\begin{aligned} { \rho _f = {\left\{ \begin{array}{ll} \frac{\sqrt{2} M_f^D}{v} \zeta ^{(*)}_f &{}\text {for type I, II, Y, Y }\\ &{} \text {(using Table}\,1\mathrm{)} \\ &{}\text {and for the exact }{\text {FA2HDM}},\\ \frac{\sqrt{2} M_f^D}{v} \zeta ^{(*)}_f +\Delta _f &{} \text {for the general}\, {\text {2HDM}}\ \\ &{} \text {in}\, {\text {FA2HDM}}\ \text { parametrization,} \\ \frac{\Pi _f}{\cos \beta } - \frac{\sqrt{2} M_f^D}{v}\tan \beta &{} \text {for the general }{\text {2HDM}}\, \\ &{} \text { in }\Pi \text { parametrization.} \\ \end{array}\right. }} \end{aligned}$$
(33)

Here the \(\zeta _f\) are the parameters introduced in Eq. (32) and Table 1, and the \((*)\) notation indicates the conjugate is present for the case \(f=u\) and not present for \(f=d,l\). GM2Calc offers two parametrizations for the general 2HDM. The “FA2HDM parametrization” starts from the FA2HDM and allows to directly modify the \(\rho _f\) by additional matrices \(\Delta _f\), which represents the deviation from the flavour-aligned (or type I, II, X, Y) limit. The second “\(\Pi \) parametrization” starts from Eq. (27) and allows to directly specify the fundamental Yukawa matrices \(\Pi _f\).

Table 1 Values of the alignment parameters \(\zeta _f\) for different types of Two-Higgs Doublet Models

After suitable unitary transformations, the Yukawa interaction in the Lagrangian of Eq. (13) takes the following form:

$$\begin{aligned} { \begin{aligned} -\mathcal {L}_\text {Yuk,int}&= H ^+ \bigg [\bar{u} \left( y_d^{H^{\pm }}P_{\text {R}}+ y_u^{H^{\pm }}P_{\text {L}}\right) d + \bar{\nu } y_l^{H^{\pm }} P_{\text {R}}l \bigg ] \\&\quad + \sum _{f=u,d,l} \left( \sum _{S=h,H}\,S{\bar{f}} y_f ^{S} P_{\text {R}}f - \text {i}\,A{\bar{f}} y_f ^{A} P_{\text {R}}f \right) \\&\quad + \text {h. c.}, \end{aligned}} \end{aligned}$$
(34)

with the CKM matrix \({V_{\text {CKM}}= V_u V_d^{\dagger }}\) and the fermion mass eigenstates \(f=f_L + f_R\), \((f=u,d,l)\), defined in Eq. (20). The coupling matrices \(y_f^S\) are defined as [102]:

$$\begin{aligned} y_f^h&= \frac{M_f^D}{v} \sin (\beta - \alpha ) + \frac{\rho _f}{\sqrt{2}} \cos (\beta -\alpha ), \end{aligned}$$
(35)
$$\begin{aligned} y_f^H&= \frac{M_f^D}{v} \cos (\beta - \alpha ) - \frac{\rho _f}{\sqrt{2}} \sin (\beta - \alpha ), \end{aligned}$$
(36)
$$\begin{aligned} y_f^A&= {\left\{ \begin{array}{ll} \frac{\rho _u}{\sqrt{2}} &{} \text {if }f=u, \\ - \frac{\rho _{d,l}}{\sqrt{2}} &{} \text {if }f=d,l, \\ \end{array}\right. } \end{aligned}$$
(37)

and the coupling between the charged Higgs and each of the fermions is:

$$\begin{aligned} y_f^{H^{\pm }}&= {\left\{ \begin{array}{ll} -\rho _u^\dagger V_{\text {CKM}}&{} \text {if }f=u,\\ V_{\text {CKM}}\rho _d &{} \text {if }f=d,\\ \rho _l &{} \text {if }f=l, \\ \end{array}\right. } \end{aligned}$$
(38)

where \(\rho _f\) is given in Eq. (33).

2.2 Implemented contributions to \({a_\mu }\)

Relevant 2HDM contributions to \({a_\mu }\) arise at the one-loop and the two-loop level. The one-loop contributions are suppressed by two additional powers of the muon Yukawa coupling and thus of \({\mathcal {O}(m_\mu ^4)}\); they are typically subleading unless some of the non-SM-like Higgs bosons have very small mass around a few GeV. The two-loop contributions can be classified into fermionic and bosonic contributions. They arise at the \({\mathcal {O}(m_\mu ^2)}\) and are typically dominant. An important subclass of two-loop contributions are the so-called Barr–Zee diagrams, which contain a \(\gamma \gamma \)-Higgs one-loop subdiagram. These diagrams have been studied extensively [140,141,142,143,144] and fully calculated in Ref. [100]. The full set of two-loop bosonic and fermionic diagrams (at \({\mathcal {O}(m_\mu ^2)}\)) has been computed in Ref. [102] (see also Ref. [103] for further phenomenological discussions of the individual contributions). GM2Calc implements the full set of one-loop BSM contributions \(a_\mu ^{1\ell }\) of \({\mathcal {O}(m_\mu ^4)}\) and the two-loop BSM contributions \(a_\mu ^{2\ell }\) of \({\mathcal {O}(m_\mu ^2)}\) in the 2HDM from Ref. [102]. The full BSM contribution in the 2HDM (i.e. the difference between the 2HDM and the SM contributions) calculated by GM2Calc is therefore the sum

$$\begin{aligned} {a_\mu ^{{\text {BSM}}}=a_\mu ^{1\ell }+a_\mu ^{2\ell }.} \end{aligned}$$
(39)

In the following subsections we provide the explicit analytic results implemented in GM2Calc.

2.2.1 One-loop contributions

The one-loop BSM contributions to \({a_\mu ^{1\ell }}\) in the 2HDM is of \({\mathcal {O}(m_\mu ^4)}\) and are given by

$$\begin{aligned} a_\mu ^{1\ell }&= \frac{1}{8\pi ^2} \Bigg \{ \sum _{i=1}^3 \Bigg [ \sum _{S=h,H,A} \frac{m_\mu ^2}{m_S^2} A_S(i, m_l, m_S^2, y_l^S)\nonumber \\&\quad + \frac{m_\mu ^2}{m_{H^\pm }^2} A_{H^\pm }(i, 0, m_{H^\pm }^2, y_l^{H^\pm }) \Bigg ] \nonumber \\&\quad - \frac{m_\mu ^2}{m_{h_{{\text {SM}}}}^2} A_h(2, m_l, m_{h_{{\text {SM}}}}^2, \mathbb {1}) \Bigg \}, \end{aligned}$$
(40)

with \(m_l = (m_e, m_\mu , m_\tau )\), \(m_\nu = (m_{\nu _e}, m_{\nu _\mu }, m_{\nu _\tau })\) and

$$\begin{aligned}&A_h(i,m_l,m_S^2,y_l^S) ={} A_S^+(i,m_l,m_S^2,y_l^S), \end{aligned}$$
(41)
$$\begin{aligned}&A_H(i,m_l,m_S^2,y_l^S) ={} A_S^+(i,m_l,m_S^2,y_l^S), \end{aligned}$$
(42)
$$\begin{aligned}&A_A(i,m_l,m_S^2,y_l^S) ={} A_S^-(i,m_l,m_S^2,y_l^S), \nonumber \\&A_S^\pm (i,m_l,m_S^2,y_l^S) \nonumber \\&\quad = \frac{1}{24} \left( \left| (y_l^S)_{i2}\right| ^2 + \left| (y_l^S)_{2i}\right| ^2 \right) F_1^C\left( \frac{(m_l)^2_i}{m_S^2}\right) \end{aligned}$$
(43)
$$\begin{aligned}&\qquad \pm \frac{1}{3} \Re \mathfrak {e}\left[ (y_l^S)_{i2}^* (y_l^S)_{2i}^*\right] \frac{(m_l)_i}{m_\mu } F_2^C\left( \frac{(m_l)^2_i}{m_S^2}\right) , \end{aligned}$$
(44)
$$\begin{aligned}&A_{H^\pm }(i, m_\nu , m_S^2, y_l^S) \nonumber \\&\quad = -\frac{1}{48} \left| (y_l^S)_{i2}\right| ^2 \left[ F_1^N \left( \frac{m_{\nu _\mu }^2}{m_S^2}\right) + F_1^N\left( \frac{(m_\nu )_i^2}{m_S^2}\right) \right] . \end{aligned}$$
(45)

Note, that the one-loop contribution from the SM Higgs boson \({{h_{{\text {SM}}}}}\) is subtracted in Eq. (40) and is therefore not included in \({a_\mu ^{1\ell }}\). The loop functions \(F_1^C\), \(F_2^C\) and \(F_1^N\) are given by

$$\begin{aligned} F_1^C(x)&= \frac{2}{(x - 1)^4}\left( 2 + 3x - 6x^2 + x^3 + 6x\ln x\right) , \nonumber \\ F_1^C(0)&=4, F_1^C(1)=1, \end{aligned}$$
(46)
$$\begin{aligned} F_2^C(x)&= \frac{3}{2(1 - x)^3}\left( -3 + 4x - x^2 - 2\ln x\right) , \nonumber \\ F_2^C(1)&=1, F_2^C(\infty )=0, \end{aligned}$$
(47)
$$\begin{aligned} F_1^N(x)&= \frac{2}{(x - 1)^4}\left( 1 - 6x + 3x^2 + 2x^3 - 6x^2\ln x\right) , \nonumber \\ F_1^N(0)&=2, F_1^N(1)=1, F_1^N(\infty )=0. \end{aligned}$$
(48)

2.2.2 Two-loop contributions

The two-loop contributions of \({\mathcal {O}(m_\mu ^2)}\) are divided into fermionic and bosonic loop contributions according to Ref. [102] as

$$\begin{aligned} {a_\mu ^{{2\ell }} = a_\mu ^{\text {B}}+ a_\mu ^{\text {F}}, } \end{aligned}$$
(49)

where the very small contribution from the shift of the Fermi constant, \({a_\mu ^{\Delta r\text {-shift}}}\), is neglected. We generalize the fermionic two-loop contributions from Ref. [102] in the general 2HDM to the case of CKM mixing as follows:

$$\begin{aligned} a_\mu ^{\text {F}}&= a_\mu ^{\text {F,N}} + a_\mu ^{\text {F,C}} , \end{aligned}$$
(50)
$$\begin{aligned} a_\mu ^{\text {F,N}}&= \sum _{f=u,d,l} \sum _{i=1}^3 \frac{\alpha _{\text {em}}^2 m_\mu ^2}{4\pi ^2 m_W^2 s_W^2} \nonumber \\&\quad \times \left[ \sum _{S=h,H,A} f_f^S(m_S,(m_f)_i) \frac{\Re \mathfrak {e}\left[ (y_f^S)_{ii}^* (y_l^S)_{22}\right] v^2}{(m_f)_i m_\mu }\right. \nonumber \\&\quad \left. - f_f^{{h_{{\text {SM}}}}}(m_{{h_{{\text {SM}}}}},(m_f)_i) \right] , \end{aligned}$$
(51)
$$\begin{aligned} a_\mu ^{\text {F,C}}&= \sum _{i,j=1}^3 \frac{\alpha _{\text {em}}^2 m_\mu ^2}{32\pi ^2 m_W^2 s_W^4} \nonumber \\&\quad \times \Bigg [ f_u^{H^\pm }(m_{H^\pm },(m_u)_i,(m_d)_j)\nonumber \\&\quad \times \frac{\Re \mathfrak {e}\left[ (y_u^{H^\pm })_{ij}^* (V_{\text {CKM}})_{ij}(y_l^{H^\pm })_{22}\right] v^2}{2 (m_u)_i m_\mu } \nonumber \\&\quad +f_d^{H^\pm }(m_{H^\pm },(m_d)_j,(m_u)_i)\nonumber \\&\quad \times \frac{\Re \mathfrak {e}\left[ (y_d^{H^\pm })_{ij}^* (V_{\text {CKM}})_{ij}(y_l^{H^\pm })_{22}\right] v^2}{2 (m_d)_j m_\mu } \nonumber \\&\quad +f_l^{H^\pm }(m_{H^\pm },(m_l)_i,0) \frac{\Re \mathfrak {e}\left[ (y_l^{H^\pm })_{ij}^* \delta _{ij}(y_l^{H^\pm })_{22}\right] v^2}{2 (m_l)_i m_\mu } \Bigg ]. \end{aligned}$$
(52)

Note, that the two-loop contribution from the SM Higgs boson \({{h_{{\text {SM}}}}}\) is subtracted in Eq. (51) and is therefore not included in \({a_\mu ^{2\ell }}\). The loop functions \(f_f^S\) (\({S=h,H,A,{h_{{\text {SM}}}}}\)) are defined as:

$$\begin{aligned} f_f^S(m_S,m_f)= & {} q_f^2 N^c_f \frac{m_f^2}{m_S^2} \mathcal {F}_S (m_S,m_f)\nonumber \\&- q_f N^c_f \frac{g^l_v g^f_v}{s_W^2 c_W^2} \frac{m_f^2}{m_S^2- m_Z^2}\nonumber \\&\times \left[ \mathcal {F}_S (m_S,m_f) - \mathcal {F}_S (m_Z,m_f)\right] , \end{aligned}$$
(53)
$$\begin{aligned} \mathcal {F}_S(m_S,m_f)= & {} {\left\{ \begin{array}{ll} -2 + \ln \bigg (\frac{m_S^2}{m_f^2}\bigg ) - \bigg (\frac{m_S^2-2m_f^2}{m_S^2}\bigg )\\ \qquad \frac{\Phi (m_S,m_f,m_f)}{m_S^2-4m_f^2}, &{} S=h,H,{h_{{\text {SM}}}},\\ \frac{\Phi (m_S,m_f,m_f)}{m_S^2-4m_f^2}, &{} S=A,\\ \end{array}\right. }\nonumber \\ \end{aligned}$$
(54)

where \(N^c_f = (1,3,3)\), \(g^f_v = T^3_f/2 - s_W^2 q_f\), \(T^3_f = (-1/2,-1/2,1/2)\) and \(q_f=(-1,-1/3,2/3)\) for \(f=(l,d,u)\). The loop function \(f_f^{H^\pm }\) is defined as:

$$\begin{aligned} f_f^{H^\pm }(m_{H^\pm },m_f,m_{f'}) = {\left\{ \begin{array}{ll} \frac{m_l^2}{m_{H^\pm }^2-m_W^2} \left[ \mathcal {F}_l^{H\pm }\bigg (\frac{m_l^2}{m_{H\pm }^2}\bigg ) - \mathcal {F}_l^{H^\pm }\bigg (\frac{m_l^2}{m_W^2}\bigg )\right] , &{} f=l, f'=\nu , \\ 3\frac{m_d^2}{m_{H^\pm }^2-m_W^2} \left[ \mathcal {F}_d^{H\pm }\bigg (\frac{m_d^2}{m_{H\pm }^2},\frac{m_u^2}{m_{H\pm }^2}\bigg ) -\mathcal {F}_d^{H^\pm }\bigg (\frac{m_d^2}{m_W^2},\frac{m_u^2}{m_W^2}\bigg )\right] , &{} f=d, f'=u, \\ 3\frac{m_u^2}{m_{H^\pm }^2-m_W^2} \left[ \mathcal {F}_u^{H\pm }\bigg (\frac{m_d^2}{m_{H\pm }^2},\frac{m_u^2}{m_{H\pm }^2}\bigg ) - \mathcal {F}_u^{H^\pm }\bigg (\frac{m_d^2}{m_W^2},\frac{m_u^2}{m_W^2}\bigg )\right] , &{} f=u, f'=d, \end{array}\right. } \end{aligned}$$
(55)

where \(f'_j\) is the \(\text {SU}(2)_L\) partner of generation j of the fermion \(f_i\) from generation i, and

$$\begin{aligned} \mathcal {F}_l^{H^\pm }(x_l)&= x_l + x_l (x_l-1) \left[ {{\,\mathrm{Li_2}\,}}\bigg (1-\frac{1}{x_l}\bigg ) -\frac{\pi ^2}{6}\right] \nonumber \\&\quad + \left( x_l-\frac{1}{2}\right) \ln (x_l),\end{aligned}$$
(56)
$$\begin{aligned} \mathcal {F}_d^{H^\pm }(x_d,x_u)&= -\,(x_u+x_d) + \left[ \frac{\overline{c}}{y} - \frac{c(x_u-x_d)}{y}\right] \nonumber \\&\quad \times \Phi (x_d,x_u,1) \nonumber \\&\quad + c\left[ {{\,\mathrm{Li_2}\,}}(1-x_d/x_u) - \frac{1}{2} \ln {(x_u)} \ln {(x_d/x_u)}\right] \nonumber \\&\quad + (s+x_d)\ln {(x_d)} + (s-x_u)\ln {(x_u)}, \end{aligned}$$
(57)
$$\begin{aligned} \mathcal {F}_u^{H^\pm }(x_d,x_u)&= \mathcal {F}_d^{H^\pm }(x_d,x_u) (q_u \rightarrow 2+q_u, q_d \rightarrow 2+q_d) \nonumber \\&\quad -\frac{4}{3} \frac{(x_u-x_d-1)}{y} \Phi (x_d,x_u,1) \nonumber \\&\quad - \frac{1}{3} \left[ \ln ^2{(x_d)} - \ln ^2{(x_u)}\right] , \end{aligned}$$
(58)

and

$$\begin{aligned} c&= (x_u - x_d)^2 - q_u x_u + q_d x_d, \end{aligned}$$
(59)
$$\begin{aligned} \overline{c}&= (x_u - q_u) x_u - (x_d + q_d) x_d, \end{aligned}$$
(60)
$$\begin{aligned} y&= (x_u - x_d)^2 - 2 (x_u + x_d) + 1, \end{aligned}$$
(61)
$$\begin{aligned} s&= \frac{q_u+q_d}{4}. \end{aligned}$$
(62)

The loop function \(\Phi (m_1^2,m_2^2,m_3^2)\) [145] is defined as:

$$\begin{aligned}&\Phi (m_1^2,m_2^2,m_3^2) = \frac{\lambda }{2} \bigg [2\ln {(\alpha _+)}\ln {(\alpha _-)} \nonumber \\&\qquad - \ln {\bigg (\frac{m_1^2}{m_3^2}\bigg )}\ln {\bigg (\frac{m_2^2}{m_3^2}\bigg )} \nonumber \\&\qquad - 2{{\,\mathrm{Li_2}\,}}{(\alpha _+)} - 2{{\,\mathrm{Li_2}\,}}{(\alpha _-)} + \frac{\pi ^2}{3}\bigg ], \end{aligned}$$
(63)
$$\begin{aligned}&\alpha _{\pm } = \frac{m_3^2 \pm m_1^2 \mp m_2^2 - \lambda }{2m_3^2}, \end{aligned}$$
(64)
$$\begin{aligned}&\lambda = \sqrt{m_1^4 + m_2^4 + m_3^4 - 2m_1^2 m_2^2 - 2m_2^2 m_3^2 -2 m_3^2 m_1^2}. \end{aligned}$$
(65)

The bosonic two-loop contributions to the general 2HDM are composed of three parts as follows:

$$\begin{aligned} { a_\mu ^{\text {B}}= a_\mu ^{\text {B,EW add}} + a_\mu ^{\text {B,Yuk}} + a_\mu ^{\text {B,non-Yuk}}.} \end{aligned}$$
(66)

The two terms \({a_\mu ^{\text {B,EW add}}}\) and \({a_\mu ^{\text {B,nonYuk}}}\) correspond to diagrams with the SM-like Higgs boson and diagrams without the new Yukawa couplings, respectively. They are typically subdominant, and full details on their definition and phenomenological impact are given in Refs. [102, 103]. The Yukawa contribution is given by

$$\begin{aligned} a_\mu ^{\text {B,Yuk}}&= \frac{\alpha _{\text {em}}^2}{574\pi ^2c_W^4s_W^4} \frac{m_\mu ^2}{m_Z^2} \nonumber \\&\quad \bigg \{ a_{0,0}^{0} + a_{0,z}^{0} \left( \tan \beta -\frac{1}{\tan \beta }\right) \zeta _l + a_{5,0}^{0} \Lambda _5 \nonumber \\&\quad + a_{5,z}^{0} \left( \tan \beta -\frac{1}{\tan \beta }\right) \Lambda _{567} \zeta _l \nonumber \\&\quad + \left[ a_{0,0}^{1} \left( \tan \beta -\frac{1}{\tan \beta }\right) + a_{0,z}^{1} \zeta _l \right. \nonumber \\&\quad \left. + a_{5,0}^{1} \left( \tan \beta -\frac{1}{\tan \beta }\right) \Lambda _{567}\right. \nonumber \\&\quad \left. + a_{5,z}^{1} \Lambda _5 \zeta _l\right] \cos (\beta - \alpha )\bigg \}, \end{aligned}$$
(67)
$$\begin{aligned} \Lambda _5&= \frac{2m_{12}^2}{v^2\sin \beta \cos \beta }, \end{aligned}$$
(68)
$$\begin{aligned} \Lambda _{567}&= \Lambda _5+\frac{1}{\tan \beta -\frac{1}{\tan \beta }}\left( \frac{\lambda _6}{\sin ^2\beta }-\frac{\lambda _7}{\cos ^2\beta }\right) , \end{aligned}$$
(69)

where the equations for \(a_{\lambda ,t}^{\eta }\) (with the common prefactor put in the front of the above Eq. (67)) are given in the appendix of Ref. [102]. Compared to this reference, the expression has been generalized to include \(\lambda _6\) and \(\lambda _7\).Footnote 4 These bosonic contributions are implemented in the realistic approximation of small \(\cos (\beta -\alpha )\), and only terms up to linear order in \(\cos (\beta -\alpha )\) are taken into account. In this scenario the boson h has the tree-level couplings of the SM Higgs boson [146]. Furthermore, the bosonic contributions are derived only for the flavour-aligned 2HDM. Referring to the different cases of Yukawa couplings in Eq. (33), the bosonic corrections apply for the cases of the discrete symmetries, for the FA2HDM, and also for the general 2HDM in FA2HDM parametrization (assuming the \(\Delta _f\) matrices are small). In contrast, we set \(\zeta _l=0\) in Eq. (67) in the case of the general 2HDM in \(\Pi \) parametrization since in this case the bosonic corrections are not applicable in this form.

The bosonic two-loop contributions are also available in the GM2Calc source code and in the form of a Mathematica file.

2.2.3 Running couplings

Among the fermionic two-loop contributions, the diagrams with an internal top quark, bottom quark or tau lepton loop give the dominant contribution to \({a_\mu ^{{\text {BSM}}}}\). These diagrams are proportional to the values of the fermion masses in the loop. So long as there is no three-loop calculation available in the 2HDM, it is formally irrelevant which renormalization scheme to use for the fermion masses in the loop. In GM2Calc two possible definitions of these fermion masses are implemented:

$$\begin{aligned} \text {Input masses:}&\quad m_t, m_b^{\overline{\text {MS}}}(m_b^{\overline{\text {MS}}}), m_\tau \end{aligned}$$
(72)
$$\begin{aligned} \text {Running masses:}&\quad m_t^{\overline{\text {MS}}}(Q), m_b^{\overline{\text {MS}}}(Q), m_\tau ^{\overline{\text {MS}}}(Q) \end{aligned}$$
(73)

In the “input masses” scheme, the top quark pole mass \(m_t\), the \({{\overline{\text {MS}}}}\) bottom quark mass in the SM with five active quark flavours, \({m_b^{\overline{\text {MS}}}}\), at the renormalization scale \({Q=m_b^{\overline{\text {MS}}}}\), and the tau lepton pole mass \(m_\tau \) are used in the loops. These masses are typically used as input for spectrum generators [136, 137]. In the “running masses” scheme, the running \({{\overline{\text {MS}}}}\) top quark mass \({m_t^{\overline{\text {MS}}}(Q)}\), the \({{\overline{\text {MS}}}}\) bottom quark mass \({m_b^{\overline{\text {MS}}}(Q)}\) and the \({{\overline{\text {MS}}}}\) tau lepton mass \({m_\tau ^{\overline{\text {MS}}}(Q)}\) are used in the loops. The renormalization scale Q is set to the mass of the Higgs boson in the Feynman diagram. The “running masses” scheme is also used in 2HDMC [113]. The difference between these two schemes is shown in Sect. 4.

2.2.4 Uncertainty estimate

We provide an uncertainty estimate for \({a_\mu ^{{2\ell }}}\) as follows:

$$\begin{aligned} \delta a_\mu ^{{2\ell }}&= \delta a_\mu ^{{2\ell },\Delta r} + \delta a_\mu ^{{2\ell },m_\mu ^4} + \delta a_\mu ^{{3\ell }}, \end{aligned}$$
(74)

where

$$\begin{aligned} \delta a_\mu ^{{2\ell },\Delta r}&= 2\times 10^{-12}, \end{aligned}$$
(75)
$$\begin{aligned} \delta a_\mu ^{{2\ell },m_\mu ^4}&= \left| a_\mu ^{{1\ell }}\;\Delta \alpha _{\text {em}}\right| , \end{aligned}$$
(76)
$$\begin{aligned} \delta a_\mu ^{{3\ell }}&= \left| a_\mu ^{{2\ell }}\;\Delta \alpha _{\text {em}}\right| , \end{aligned}$$
(77)

and

$$\begin{aligned} \Delta \alpha _{\text {em}}= -\frac{4\alpha _{\text {em}}}{\pi } \ln \left( \frac{m_\text {NP}}{m_\mu }\right) , m_\text {NP} = \min \{m_H, m_A, m_{H^\pm }\}. \end{aligned}$$
(78)

The term \({\delta a_\mu ^{{2\ell },\Delta r}}\) accounts for the fact that the two-loop contribution \({a_\mu ^{\Delta r\text {-shift}}}\) has been neglected in Eq. (49). In Refs. [102, 147] it was shown that in the relevant parameter space \({|a_\mu ^{\Delta r\text {-shift}}| \le 2\times 10^{-12}}\), which we use as an upper bound in the uncertainty estimate. The term \({\delta a_\mu ^{{2\ell },m_\mu ^4}}\) estimates missing two-loop terms of \({\mathcal {O}(m_\mu ^4)}\) using the known universal two-loop QED logarithmic contributions [148]. The term \({a_\mu ^{{3\ell }}}\) is an estimate for the expected three-loop contributions. From experience the QED contributions are among the largest contributions at each loop level. For this reason we use again the known universal logarithmic QED contributions from Ref. [148] to provide an estimate for the unknown three-loop contributions.

3 Program details and usage

3.1 Quick start

GM2Calc can be downloaded from https://gm2calc.hepforge.org/ or https://github.com/GM2Calc/GM2Calc, for example asFootnote 5

figure e

To build GM2Calc run the following commands:

figure f

To calculate \({a_\mu ^{{\text {BSM}}}}\) in the 2HDM with GM2Calc from the command line, run

figure g

Here, is the name of the file that contains the input parameters.Footnote 6

3.2 Requirements

To build GM2Calc the following programs and libraries are required:

3.3 Running GM2Calc from the command line

GM2Calc can be run from the command line with an SLHA-like [136, 137] input file as

figure l

where is the name of the SLHA-like input file. Alternatively, the input parameters can be piped in an SLHA-like format into GM2Calc as

figure n

The calculated value for \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) is written to the standard output. Depending on the input options and parameters, the output may contain the following block with \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\):

figure o

The SLHA-like format for the input parameters is defined in the following subsections.

3.3.1 General options

In the SLHA-like input the selection of the configuration flags for GM2Calc can be given in the block as defined in Ref. [135]. An example block reads as follows:

figure r

The entry defines the output format. If , a single number is printed to the . This number is the value of \({a_\mu ^{{\text {BSM}}}}\) or the uncertainty \({\delta a_\mu }\), depending on the value of : If , the value of \({a_\mu ^{{\text {BSM}}}}\) is printed. If , the value of \({\delta a_\mu }\) is printed. If , a detailed output, suitable for debugging, is printed. If , the value of \({a_\mu ^{{\text {BSM}}}}\) is written to the output block entry . If , the value of \({a_\mu ^{{\text {BSM}}}}\) is written to the output block entry . If (default), the value of \({a_\mu ^{{\text {BSM}}}}\) is written to the output block entry .

The entry defines the loop order of the calculation, which can be set to or . The default value is (recommended), which corresponds to the two-loop calculation of \({a_\mu ^{{\text {BSM}}}}\).

The entry disables/enables the resummation of \(\tan \beta \) in the MSSM. By default \(\tan \beta \) resummation is enabled, which corresponds to . To disable \(\tan \beta \) resummation, set . When the calculation is performed in the 2HDM, the value of is ignored.

The next two options are useful for debugging. By setting the entry (default: ), the output of GM2Calc can be forced, even if a physical problem (e.g. a tachyon) has occurred. Warning: If a physical problem has occurred, the output cannot be trusted. Forcing the output should only be used for debugging. By setting the entry (default: ), additional information about the model parameters and the calculation is printed.

With the entry the calculation of the uncertainty \({\delta a_\mu }\), c.f. Eq. (74), can be disabled/enabled ( or ).

The entry (default: ) is new in GM2Calc 2.0.0 and controls the definition of the fermion masses that are inserted into the fermionic two-loop contribution \({a_\mu ^{\text {F}}}\), see Sect. 2.2.3. If , the input masses (72) are used. If , the running masses (73) are used. The difference between these two schemes is shown in Sect. 4.

3.3.2 Standard Model input parameters

The Standard Model input parameters are read from the , and blocks. Example blocks that define the Standard Model input parameters may read:

figure bb

The entries of the and are defined in Refs. [136, 137]. In the block entry the mass of the Standard Model Higgs boson can be given. Unset parameters in the and blocks are assigned default values. Unset parameters in the block are assumed to be zero.

3.3.3 Two-Higgs Doublet Model input parameters

We allow the specification of the 2HDM input parameters in two different “bases”, see Table 2. The basis parameters are defined as in [113]. In the “gauge basis” the Lagrangian parameters, \(\lambda _{1, \ldots , 7}\) are used as input. In the “mass basis” the Higgs boson masses and the mixing parameter \(\sin (\beta -\alpha )\) are used as input, instead of the Lagrangian parameters \(\lambda _{1, \ldots , 5}\), but \(\lambda _6\) and \(\lambda _7\) can still be used. All available input parameters are listed in Table 3.

Table 2 2HDM input parameters for different basis (\(f=u,d,l\))
Table 3 2HDM input parameters for the SLHA and Mathematica interface

Mass basis input parameters The “mass basis” input parameters are read from the and blocks for compatibility with 2HDMC [113]. The following shows an example input in the “mass basis” for the type II 2HDM:

figure cy

Unset parameters in the and blocks are assumed to be zero, except for \(\tan \beta \) which will raise an error. Entry 24 of the is used to select the type of 2HDM. Specifically the integer values \(1, \ldots , 6\) for the Yukawa type correspond to: 1 = type I, 2 = type II, 3 = type X, 4 = type Y, 5 = Flavour-Aligned, 6 = general 2HDM. The input entries 21, 22, and 23 in the block can be used to set the values of \(\zeta _u\), \(\zeta _d\) and \(\zeta _l\) in the Flavour-Aligned 2HDM, and are ignored for all other types. Additional blocks for the general case are described below.

Gauge basis input parameters Alternatively, the input can be given in the “gauge basis” in a format compatible with 2HDMC [113]. In the “gauge basis” the 2HDM parameters must be given in the block. The available “gauge basis” input parameters are listed in Table 3. The following shows an example input in the “gauge basis”:

figure de

Two parametrizations for the general 2HDM are implemented, see Eq. (33). The first option is a deviation from the FA2HDM (or types I, II, X, Y), parametrized by the additional matrices \(\Delta _f\). Thus, after choosing Yukawa type = 1, ..., 5, i.e. type I, II, X, Y and FA2HDM, the matrices \(\Delta _u\), \(\Delta _d\) and \(\Delta _l\) can be optionally given in the following dedicated blocks:

figure df

The other option for the general 2HDM corresponds to the \(\Pi \) parametrization, implemented when setting Yukawa type = 6. In this case, the input parameters \(\Delta _u\), \(\Delta _d\) and \(\Delta _l\) are ignored and the real parts of the matrices \(\Pi _u\), \(\Pi _d\) and \(\Pi _l\) can be given in the following dedicated blocks:

figure dg

The input parameters \(\Pi _u\), \(\Pi _d\) and \(\Pi _l\) are ignored when choosing Yukawa type = 1, ..., 5, i.e. type I, II, X, Y and FA2HDM.

The SLHA-like interface described so far is very convenient and intuitive to use and it does not require any prior knowledge of programming languages to run GM2Calc this way. The execution time for this is also very short, around \(5\,\text {ms}\) per point on current laptops.Footnote 7 Nevertheless even faster execution times and easy interfacing with other existing calculators and sampling algorithms are enabled through our C++ (\(0.05\,\text {ms}\)), C (\(0.05\,\text {ms}\)), Mathematica (\(0.5\,\text {ms}\)) and Python (\(0.08\,\text {ms}\)) interfaces. In the following subsections we describe how to use each of these interfaces.

3.4 Running GM2Calc from within C++

GM2Calc provides a C++ programming interface, which allows for calculating of \({a_\mu ^{{\text {BSM}}}}\) in the 2HDM up to the two-loop level. The following C++ source code snippet shows a two-loop example calculation in the 2HDM of type II with input parameters defined in the “mass basis”, see Table 2. This example source code can be compiled as follows (assuming GM2Calc has been compiled to a shared library on a UNIX-like operating system with installed):

figure dk

Here is the file that contains the above listed source code. The variable contains the path to the GM2Calc root directory and contains the path to the Eigen library header files. Running the created executable yields

figure dp

In line 12 of the example source code an object of type is created, which contains the input parameters in the mass basis, see Table 2. The mass basis input parameters are set in lines 13–31. Note that the Yukawa type is set to type II in line 13, which implies that given values of \(\zeta _f\) are ignored and internally fixed to the values given in Table 1. Additionally the inputs \(\Pi _f\) and \(\Delta _f\) are unused for this type, and ignored. In line 34 an object of type is created that contains all SM input parameters. The SM input parameters are set to reasonable default values from the PDG [154]. In lines 35–39 the values for \({\alpha _{\text {em}}(m_Z)}\), \(m_t\), \({m_c^{\overline{\text {MS}}}(2\,\text {GeV})}\), \({m_b^{\overline{\text {MS}}}(m_b^{\overline{\text {MS}}})}\) and \(m_\tau \) are set to specific values. In line 42 an object of type is created, which contains the options to customize the calculation of \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\). In line 43 the “running masses” scheme is chosen, see Sect. 2.2.3. In line 47 the 2HDM model is created, given the 2HDM and SM input parameters and the configuration options defined above. The value of \({a_\mu ^{{\text {BSM}}}= a_\mu ^{1\ell }+ a_\mu ^{2\ell }}\) is calculated in lines 50–51. The corresponding uncertainty \({\delta a_\mu }\) is calculated in line 54–55. The values \({a_\mu ^{{\text {BSM}}}}\) and \(\delta a_\mu \) are printed in line 57. Note that the 2HDM model should be created within a block, because the constructor of the 2HDM class throws an exception if a physical problem occurs (e.g. a tachyon) or an input parameter has been set to an invalid value, see Table 3.

Alternatively, the 2HDM input parameters can be given in the “gauge basis”, i.e. in terms of the Lagrangian parameters, see Table 2. The following C++ source code snippet shows a corresponding example two-loop calculation in the 2HDM of type II, where the input parameters are defined in the “gauge basis”. In line 12 an object of type is created, which is filled with the gauge basis input parameters in lines 13–25. With the defined gauge basis input parameters the calculation of \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) continues as in the mass basis example above.

3.5 Running GM2Calc from within C

Alternatively to the C++ programming interface detailed in Sect. 3.4, GM2Calc also provides a C programming interface. The following C source code snippet shows a two-loop example calculation in the 2HDM of type II with input parameters defined in the “mass basis”, see Table 2. This example source code can be compiled as follows (assuming GM2Calc has been compiled to a shared library on a UNIX-like operating system with installed):

figure dz

Here is the file that contains the above listed source code.

The C example source code is very similar to the mass basis C++ example. In line 12 an object of type is created and filled with the mass basis input parameters in lines 13–32. The Yukawa type of the model is defined in line 13 to be type II. In line 35 an object of type is created, which contains the SM input parameters. The SM input parameters are set to their default values in line 36. In lines 37–41 the values of \({\alpha _{\text {em}}(m_Z)}\), \(m_t\), \({m_c^{\overline{\text {MS}}}(2\,\text {GeV})}\), \({m_b^{\overline{\text {MS}}}(m_b^{\overline{\text {MS}}})}\) and \(m_\tau \) are set to specific values. In line 44 a config object of type is created which contains options to customize the calculation. These options are set to default values in line 45. In line 48 a null-pointer to a 2HDM model of type is created. In line 49 the 2HDM model is created and the pointer is set to point to the model. If an error occurrs, the pointer is set to 0 and the returned variable is set to a value that is not . If no error has occurred, the example continues to calculate \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) in lines 53–58, respectively. The result is printed in line 60. In line 65 the memory reserved for the 2HDM model is freed.

Alternatively, the 2HDM input parameters can be given in the “gauge basis”, similarly to the gauge basis C++ example. The following C source code snippet shows a corresponding example two-loop calculation in the 2HDM of type II, where the input parameters are defined in the “gauge basis”. In line 12 an object of type is created, which is filled with the gauge basis input parameters in lines 13–26. In line 43 the 2HDM model is created, using the gauge basis input parameters. The calculation of \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) is performed in lines 47–52, as in the “mass basis” example above.

3.6 Running GM2Calc from within Mathematica

GM2Calc can be run from within Mathematica using the interface. The following source code snippet shows an example calculation of \({a_\mu ^{{\text {BSM}}}}\) and its uncertainty at the two-loop level using input parameters given in the “gauge basis”. In line 1 GM2Calc’s executable , which is created when building GM2Calc, is loaded into the Mathematica session. In lines 4–6 two configuration options to customize the calculation are set: The calculation shall be performed at the two-loop level using the “running masses” scheme defined in Sect. 2.2.3. In lines 9–29 the SM input parameters are defined. Unset parameters are set to reasonable default values, see . In lines 32–46 the values of \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) are calculated using the function , which takes the gauge basis input parameters as arguments, see Table 3. The result is printed in line 48.

Alternatively, the calculation can be performed using input parameters given in the “mass basis”. The following source code snippet shows an example calculation of \({a_\mu ^{{\text {BSM}}}}\) and its uncertainty at the two-loop level using input parameters given in the “mass basis”. The calculation of \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) is performed in lines 32–51 with the function , which takes the mass basis input parameters as arguments, see Table 3. The result is printed in line 53.

3.7 Running GM2Calc from within Python

Newly implemented in GM2Calc 2.0.0 is the ability to interface with Python using the package . An example calculation using the interface is shown in the code snippet below, working in the “mass basis”. Note similarity between the above code and the C++ and C interfaces. Line 3 is to make sure that this example which is written using Python 3-style functions can still work in Python 2. Line 4 imports the interface script which loads the and packages, as well as the header and library locations. This interface file is originally in the subdirectory. After performing

figure ey

the interface script will be copied into the subdirectory , and it will be filled with the path information for the GM2Calc headers, library, and the path. The interface can be imported from there by other Python scripts, or moved to an appropriate location where the user has their own Python scripts. Lines 6–11 load the relevant header files, and line 13 loads the GM2Calc shared library. In lines 16–20 the necessary namespaces from C++ are loaded into Python. In line 23 the 2HDM object is initialized, while on line 24 the 2HDM is specified to be type II. Lines 25–36 involve setting the values for simple attributes in the basis. Lines 36–42 assign values to the attributes, however since these are meant to be ignored, they are just set to 0. Lines 44–49 initialize an object and ensures it has the appropriate parameters. Line 51 initializes the object, which is used to flag the use of running coupling in the next line. Line 56 initializes a object using the , , and information. Lines 58–63 prints out the values of \({a_\mu ^{{\text {BSM}}}}\) and \({\delta a_\mu }\) which are calculated using the interface functions , , and . Alternatively an error message will be printed out on line 63 should a problem arise.

Another example of the Python interface is shown below, this time using the “gauge basis”: In line 23 we instead initialize a object. To define the attribute , we need to circumvent Python’s reserved keywords. This is done by defining a \(7\times 1\) in line 26. This is initialized to 0 before assigned the appropriate entires elementwise on lines 28–34. Then the method can be used to interface the values to the C++ code. Then the other values can be defined on lines 36–53, and finally the result for \({a_\mu ^{{\text {BSM}}}}\) is printed on line 65.

4 Applications

4.1 Parameter scan in the type II and X models

As an application we perform a 2-dimensional parameter scan over \(m_A\) and \(\tan \beta \) for the type II and type X 2HDM models, similarly to Ref. [85]. However, in contrast to Ref. [85] we include the two-loop bosonic contributions and use the updated value of \({a_\mu ^{{\text {BSM}}}= (25.1 \pm 5.9)\times 10^{-10}}\) from Eq. (3). The following C++ source code shows the program to perform the scan. The function calculates \({a_\mu ^{{\text {BSM}}}}\) in the 2HDM at the two-loop level for a given value of \(m_A\) and \(\tan \beta \) and a specified Yukawa type. The remaining 2HDM input parameters in the mass basis are set to \(m_h=126\,\text {GeV}\), \(m_H=m_{H^\pm }=200\,\text {GeV}\), \(\sin (\beta -\alpha )=1\), \(\lambda _6=\lambda _7=0\), \(m_{12}^2=m_H^2/\tan \beta + (m_h^2 - \lambda _1 v^2)/\tan ^3\beta \) and \(\lambda _1=\sqrt{4\pi }\). In the function the loop over \(m_A\) and \(\tan \beta \) is performed and \({a_\mu ^{{\text {BSM}}}}\) is calculated for the type II and type X 2HDM and the result is written to the standard output. The 2-dimensional output is shown in Fig. 1 for the two types of the 2HDM.

Fig. 1
figure 1

Two-loop prediction of \({a_\mu ^{{\text {BSM}}}}\) in the 2HDM of type II (left) and type X (right) as a function of \(\tan \beta \) and \(m_A\) with \(m_h=126\,\text {GeV}\), \(m_H=m_{H^\pm }=200\,\text {GeV}\), \(\sin (\beta -\alpha )=1\), \(\lambda _6=\lambda _7=0\), \(m_{12}^2=m_H^2/\tan \beta + (m_h^2 - \lambda _1 v^2)/\tan ^3\beta \) and \(\lambda _1=\sqrt{4\pi }\). In the green, yellow and gray regions the 2HDM predicts the correct value of \({a_\mu ^{{\text {BSM}}}= (25.1 \pm 5.9)\times 10^{-10}}\) from Eq. (3) within one, two and three standard deviations, respectively

4.2 Size of fermionic and bosonic contributions

In the following we illustrate the calculation of the two-loop fermionic and bosonic contributions, \({a_\mu ^{\text {F}}}\) and \({a_\mu ^{\text {B}}}\), separately. For the illustration we perform a scan over \(m_A\) for the demo parameter scenario from 2HDMC [113], which is a type II 2HDM scenario where \(m_H= 400\,\text {GeV}\), \(m_{H^\pm }=440\,\text {GeV}\), \(\tan \beta =3\), \(\sin (\beta -\alpha )=0.999\), \(\lambda _6=\lambda _7=0\) and \(m_{12}^2=(200\,\text {GeV})^2\). The following C source code shows the program to perform the scan. The SM input parameters and the configuration options are set to their default values by passing 0 as the last two arguments to the function that creates the 2HDM model in line 39. The individual bosonic and fermionic contributions are calculated in lines 42–43 and written to the standard output in line 45.

Fig. 2
figure 2

Different contributions to \({a_\mu ^{{\text {BSM}}}}\) in the 2HDM. In the left panels we show scenarios from the type II 2HDM as a function of \(m_A\) with \(m_H= 400\,\text {GeV}, m_{H^\pm }=440\,\text {GeV}\), \(\tan \beta =3\), \(\sin (\beta -\alpha )=0.999\), \(\lambda _6=\lambda _7=0\) and \(m_{12}^2=(200\,\text {GeV})^2\). In the right panels we show FA2HDM scenarios with \(m_h = 125\,\text {GeV}\), \(m_H=150\,\text {GeV}\), \(m_{H^\pm }=150\,\text {GeV}\), \(\sin (\beta -\alpha )=0.999\), \(\lambda _6=0\), \(\lambda _7=0\), \(\tan \beta = 2\), \(m_{12}^2\) is fixed to avoid \(h\rightarrow AA\) decays using a polynomial equation shown in the related source code, \(\zeta _u=\zeta _d = -0.1\), \(\zeta _l = 50\) based on scenarios found for Fig. 10 of Ref. [103]. In the top panels we show fermionic (red solid line) and bosonic (blue dashed-dotted line) two-loop contributions separately. The top right panel also shows a purple region over the values of \(m_A\) where it is possible to explain Eq. (3). In the bottom panels we compare the fermionic two-loop contributions, when the running 3rd generation fermion masses shown in (73) are used (red solid line) and when the 3rd generation input masses from (72) are used (green dashed line). The red and green bands show the corresponding uncertainties. The bottom left panel also shows two-loop fermionic contributions calculated from 2HDMC as a black dotted line. *This is not a vanilla 2HDMC calculation, the SM-Higgs-like two-loop contributions have been removed, and the two-loop charged Higgs Barr–Zee contributions have been added as explained in the text

In the top left panel of Fig. 2 we show the results for the fermionic (red solid line) and bosonic (blue dashed-dotted line) contributions as a function of \(m_A\) for this demo scenario from 2HDMC. For the shown parameter space the fermionic contributions decrease, while the bosonic contributions increase for increasing \(m_A\). Furthermore, the bosonic contributions are negative, while the fermionic contributions are positive, which leads to a partial cancellation of the two contributions. However, as is generally the case for the type II 2HDM scenarios that are not already excluded by other constraints, the scenarios we plot here cannot explain the large deviation between the Standard Model prediction and experiment given in Eq. (3).

If instead we consider the FA2HDM scenarios, as in the top right panel of Fig. 2 it is now possible to explain large deviations. Here we fix the following parameters \(m_h = 125\,\text {GeV}\), \(m_H=150\,\text {GeV}\), \(m_{H^\pm }=150\,\text {GeV}\), \(\sin (\beta -\alpha )=0.999\), \(\lambda _6=0\), \(\lambda _7=0\), \(\tan \beta = 2\), \(\zeta _u=\zeta _d=-0.1\), \(\zeta _l = 50\) based on results used for Fig. 10 of Ref. [103]. It should be noticed that, once the masses for the charged and CP-even scalar are close together and below around 300 GeV, electroweak as well as unitarity and perturbativity constraints can be evaded for arbitrarily low values of \(m_A\) [85]. The input parameters here are chosen accordingly. Since \({m_A < m_{h_{\text {SM}}}/2}\), it is possible for \(h \rightarrow A A\) decays to occur unless we enforce the coupling \(C_{hAA}=0\).Footnote 8 This fixes the value of \(\lambda _1\) according to Eq. (12) in Ref. [103], which can be set in the mass basis using \(m_{12}^2\) and applying the relations in Eqs. (2.12)–(2.13) in Ref. [102]. This leads to the fitted 2nd-order polynomial relation with a dependence on \(m_A\) seen in the source code below.

These scenarios have a very light pseudoscalar mass, but LHC limits are much weaker compared to the type II case and can be evaded for these scenarios. The two-loop fermion contributions rise rapidly as the pseudoscalar mass decreases, dominating over the two-loop bosonic contributions, though the latter are just large enough to have an impact on constraints from \({a_\mu }\). Note that for higher values of \(m_A\) it is possible to get larger bosonic contributions as can be seen in Fig. 10 of Ref. [103]. In the scenarios we plot here the one-loop contributions, which are not shown in Fig. 2, have a negative effect on the contributions, with a size of approximately one-third of the two-loop fermionic contributions. Thus it can be seen that \({a_\mu ^{{\text {BSM}}}}\) can be explained with a very low \(m_A\) for the values of \(m_A\) in the purple region. The scan for this scenario can be performed with the following C source code:

4.3 Running fermion masses

In this subsection we study the effect of using the input vs. running fermion masses in the two-loop fermionic contributions as described in Sect. 2.2.3, and compare the results with 2HDMC. The following Mathematica source code shows a program to perform a scan over \(m_A\) using the same type II 2HDM parameter region as in Sect. 4.2. The function calculates the two-loop fermionic contribution \(a_\mu ^{\text {F}}\) and the uncertainty \(\delta a_\mu \) for a given value of \(m_A\) and the mass basis input parameters defined above. In line 20 the usage of running fermion masses is disabled and the calculation is performed in the subsequent line. Similarly, in line 24 the usage of running fermion masses is enabled and the calculation is performed in the subsequent line. The results are collected in the variable and are exported to a file in line 31. We also used a very similar script to do the same calculations for the FA2HDM scenarios discussed in Sect. 4.2.

The effect of using running fermion masses in the two-loop fermionic contributions is shown in Fig. 2 for the type II (bottom left panel) and flavour aligned (bottom right panel) scenarios matching those described in the previous section. The red solid line shows the value of \({a_\mu ^{\text {F}}}\) when the running masses (73) are used, i.e. the 3rd generation fermion masses are run to the scale of the Higgs boson in the two-loop fermionic Barr-Zee Feynman diagrams. Note that although the vertical axes are slightly different, the red lines shown in the bottom panels are identical to the red lines from the corresponding panels immediately above them, which were discussed in the previous section. The green dashed lines show the value of \({a_\mu ^{\text {F}}}\) when input fermion masses listed in (72) are used. In both scenarios that we look at the value of \({a_\mu ^{\text {F}}}\) is smaller when running masses are used, though the difference is only distinguishable for the type II case where the size of the contributions is much smaller. The reason for this is that due to the negative fermion mass \(\beta \) functions the running masses are numerically smaller than the corresponding input masses in the shown scenarios, which leads to a systematic reduction of the fermionic two-loop contributions.

In addition to the red solid and green dashed lines from GM2Calc, as the scenario in question is a benchmark point for 2HDMC [113], we show in the bottom left panel of Fig. 2 the corresponding result obtained with 2HDMC 1.8.0 as black dotted line. Note that at the two-loop level 2HDMC includes only fermionic contributions to \({a_\mu ^{{\text {BSM}}}}\). Furthermore, 2HDMC does not subtract the contributions from the SM Higgs boson and does not include the two-loop contributions from the charged Higgs boson. Therefore to obtain this black dotted line we have thus subtracted the two-loop SM Higgs contributions from the 2HDMC result and added the two-loop contributions from the charged Higgs boson. Since 2HDMC inserts running fermion masses into the fermionic contributions, the black dotted line can be compared to the red solid line in the figure. There is a small deviation between these two lines, which originates from the inclusion of fermionic Barr-Zee diagrams with an internal Z boson in GM2Calc, which are not included in 2HDMC.

In the bottom panels of Fig. 2 we also show the uncertainties calculated with (74) as lighter shaded regions of the corresponding color about the red and green lines. In the bottom left panel the red and green lines both lie within the uncertainty estimate for the alternative prediction (shaded green and shaded red regions respectively) for all values of \(m_A\) plotted. This is also true in the bottom right panel though there is no visible distinction between the red and green lines or their uncertainties here. Since the difference between the lines is of higher order, this indicates that our uncertainty estimate is working as expected and accounts for the expected higher order corrections.

5 Summary

We have presented version 2 of GM2Calc, with its new capability to calculate the BSM contributions to the anomalous magnetic moment of the muon in the 2HDM. The contributions include all the one-loop diagrams, two-loop fermionic Bar-Zee diagrams, as well as the bosonic two-loop contributions. The new version of GM2Calc provides the calculation of the 2HDM contributions with a precision of up to \(\mathcal {O}(m_\mu ^4)\) at one-loop and \(\mathcal {O}(m_\mu ^2)\) at two-loop level along with an estimate of uncertainty of the evaluation. GM2Calc performs this state of the art precision calculation at high speed, with execution times that can be as short as \(\mathcal {O}(0.05\,\text {ms})\) per point, allowing for rapid sampling of the parameter space. GM2Calc is easy to configure and run. The user can select well-known types of the 2HDM, specifically type I, II, X, Y as well as the flavour-aligned version (FA2HDM), or the fully general 2HDM. For the latter the user can specify the inputs as deviations away from the flavour alignment of the FA2HDM (or from type I, II, X, and Y) or by directly specifying the more fundamental Yukawa matrices, \(\Pi _f\) defined in Eq. (27). The user can also decide whether they will give inputs in the gauge basis using \(\lambda _{1,\ldots ,7}\) or the mass basis using \(m_{h,H,A,H^\pm }\), \(\lambda _{6,7}\), and \(\sin (\beta -\alpha )\). The input parameters and settings can be specified in an SLHA-like input file, mirroring the original MSSM version. Additionally, GM2Calc can be interfaced to other programs using C++, C, Mathematica, or Python, the latter being a new interface developed for GM2Calc 2.

For each of these interfaces we presented simple and easy to follow usage examples in Sect. 3, that are straightforward to adapt. In Sect. 4 we have also presented some applications and results, demonstrating different features of the code. In each of these we show the source code in the manual and also provide them as supplementary files. GM2Calc is actively developed on GitHub and users with any questions may contact the authors through our GitHub page or directly by email.