def check_sm_higgs_BRin2hdm(H, A):
    mH = H
    mA = A
    mhc = max(mH, mA)

    sqrts = 13000
    type = 2
    tb = 0.5
    mh = 125.
    mZ = 91.1876
    cba = 0.01
    mode = 'H'
    outputFile = "out.dat"
    
    tb_list = [] 
    results = {
                'BRhtoss': [],
                'BRhtocc': [],
                'BRhtobb': [],
                'BRhtoee': [],
                'BRhtomumu': [],
                'BRhtotautau': [],
                'BRhtogg': [],
                'BRhtoZZ': [],
                'BRhtoWW': [],
                'BRhtoZga': [],
                'BRhtogluglu': [],}
    
    while tb < 60.:
        m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
        tb_list.append(tb)
    
        beta=math.atan(tb)
        alpha=math.atan(tb)-math.acos(cba)
        sba = math.sin(math.atan(tb)-alpha)
        
        test = Calc2HDM(mode = 'H', sqrts = sqrts, type = type, tb = tb, m12 = m12, mh = mh, mH = mH, mA = mA, mhc = mhc, sba = sba, outputFile = outputFile)
        
        test.setm12(m12)
        test.settb(tb)
        test.setsba(sba)
        test.setmA(mA)
        test.setmH(mH)
        test.computeBR()
    
        results['BRhtoss'].append(test.htossBR)
        results['BRhtocc'].append(test.htoccBR)
        results['BRhtobb'].append(test.htobbBR)
        results['BRhtoee'].append(test.htoeeBR)
        results['BRhtomumu'].append(test.htomumuBR)
        results['BRhtotautau'].append(test.htotautauBR)
        results['BRhtogg'].append(test.htoggBR) # gamma-gamma
        results['BRhtoZZ'].append(test.htoZZBR)
        results['BRhtoWW'].append(test.htoWWBR)
        results['BRhtoZga'].append(test.htoZgaBR)
        results['BRhtogluglu'].append(test.htoglugluBR)

        tb+=1.5
        
    return results, tb_list
for mH in xrange(125, 1010, 10):
    for mA in xrange(90, 1010, 10):
        if mA >= mH:
            mode = 'A'
        else:
            mode = 'H'
        mhc = max(mH, mA)
        m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
        print mode
        x = Calc2HDM(mode=mode,
                     sqrts=sqrts,
                     type=type,
                     tb=tb,
                     m12=m12,
                     mh=mh,
                     mH=mH,
                     mA=mA,
                     mhc=mhc,
                     sba=sba,
                     outputFile=outputFile,
                     muR=1.,
                     muF=1.)
        x.setpdf('NNPDF30_lo_as_0130_nf_4')
        x.computeBR()
        xsec, err_integration, err_muRm, err_muRp = x.getXsecFromSusHi()
        if mode == 'H':
            #print "xsec, HtoZABR, AtobbBR ", xsec, x.HtoZABR, x.AtobbBR
            sigmaBR = xsec * x.HtoZABR * x.AtobbBR * ZtollBR
        else:
            #print "xsec, AtoZHBR, HtobbBR ", xsec, x.AtoZHBR, x.HtobbBR
            sigmaBR = xsec * x.AtoZHBR * x.HtobbBR * ZtollBR
Exemple #3
0
beta = math.atan(tb)
cba = 0.01
alpha = math.atan(tb) - math.acos(cba)
sba = math.sin(math.atan(tb) - alpha)

print 'sba : ', sba

outputFile = "out.dat"

test = Calc2HDM(mode='H',
                sqrts=sqrts,
                type=type,
                tb=tb,
                m12=m12,
                mh=mh,
                mH=mH,
                mA=mA,
                mhc=mhc,
                sba=sba,
                outputFile=outputFile)
test.computeBR()

xsec = test.getXsecFromSusHi()

mA_list = []
xsectot_list = []
HtoZABR_list = []
AtobbBR_list = []

while mA < mH - 90:
def ggH_VS_bbH():
    with open('inflexionPoints.txt', 'w+') as outf:
        outf.write(
            "Values of tb where xsc[ggfusion] < xsc[b-associated prouction]\n")
        for H, A in (grid['fullsim']):
            outf.write('MH-{}_MA-{}\n'.format(H, A))
            mH = H
            mA = A
            mhc = max(mH, mA)

            sqrts = 13000
            type = 2
            tb = 0.5
            mh = 125.
            mZ = 91.1876
            cba = 0.01
            mode = 'H'
            outputFile = "out.dat"

            tb_list = []
            xsec_ggH_list = []
            xsec_bbH_list = []
            subprocess_gg_nlo_list = []
            subprocess_qg_nlo_list = []
            subprocess_qq_nlo_list = []

            HtoZABR_list = []
            AtobbBR_list = []

            while tb < 20.5:
                m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
                tb_list.append(tb)

                beta = math.atan(tb)
                alpha = math.atan(tb) - math.acos(cba)
                sba = math.sin(math.atan(tb) - alpha)

                test = Calc2HDM(mode='H',
                                sqrts=sqrts,
                                type=type,
                                tb=tb,
                                m12=m12,
                                mh=mh,
                                mH=mH,
                                mA=mA,
                                mhc=mhc,
                                sba=sba,
                                outputFile=outputFile)

                test.setm12(m12)
                test.settb(tb)
                test.setsba(sba)
                test.setmA(mA)
                test.setmH(mH)
                test.computeBR()

                xsec_ggH, err_integration_ggH, err_muRm_ggH, err_muRp_ggH, xsec_bbH, err_integration_bbH = test.getXsecFromSusHi(
                )

                xsec_ggH_X_BR = xsec_ggH * test.HtoZABR * test.AtobbBR
                xsec_bbH_X_BR = xsec_bbH * test.HtoZABR * test.AtobbBR

                if xsec_ggH_X_BR < xsec_bbH_X_BR:
                    outf.write("    tb : {}\n".format(tb))
                    outf.write("    BR(A-> bb ): {}\n".format(test.AtobbBR))
                    outf.write("    BR(H-> ZA ): {}\n".format(test.HtoZABR))
                    outf.write(
                        "    cross-section ggH: {} pb\n".format(xsec_ggH))
                    outf.write(
                        "    cross-section bbH: {} pb\n".format(xsec_bbH))
                    outf.write("\n")

                xsec_bbH_list.append(xsec_bbH_X_BR)
                xsec_ggH_list.append(xsec_ggH_X_BR)

                HtoZABR_list.append(test.HtoZABR)
                AtobbBR_list.append(test.AtobbBR)

                tb += 0.1

            ToPlotsggfusion["MH-%s_MA-%s" % (H, A)] = xsec_ggH_list
            ToPlotsbbproduction["MH-%s_MA-%s" % (H, A)] = xsec_bbH_list
    np.save('data/ggHxsc_X_BR_21signal_2hdm2_func-tb.npy', ToPlotsggfusion)
    np.save('data/bbHxsc_X_BR_21signal_2hdm2_func-tb.npy', ToPlotsbbproduction)
    return ToPlotsggfusion, ToPlotsbbproduction
def ZABR(type2hdm=2,
         func_of_cba=False,
         func_of_tb=False,
         func_of_mA=False,
         func_of_mH=False):
    sqrts = 13000
    type = type2hdm
    mh = 125.
    mZ = 91.1876
    if func_of_tb:
        cba = 0.01
        sba = math.sqrt(1 - pow(cba, 2))
        dicvars = {'tb': []}
        mH = 300.
        mA = 200.
    elif func_of_cba:
        tb = 1.5
        dicvars = {'cba': []}
        mH = 300.
        mA = 200.
    elif func_of_mA:
        cba = 0.01
        sba = math.sqrt(1 - pow(cba, 2))
        tb = 1.5
        dicvars = {'mA': []}
    elif func_of_mH:
        cba = 0.01
        sba = math.sqrt(1 - pow(cba, 2))
        tb = 1.5
        dicvars = {'mH': []}

    outputpath = '/home/ucl/cp3/kjaffel/scratch/Calculators42HDM_outputs'
    cwd = os.getcwd()
    if not os.path.exists(outputpath):
        os.makedirs(outputpath)
    results = {
        'BRHtoZA': [],
        'BRHtoZga': [],
        'BRHtobb': [],
        'BRHtoss': [],
        'BRHtocc': [],
        'BRHtoee': [],
        'BRHtomumu': [],
        'BRHtohh': [],
        'BRHtoWW': [],
        'BRHtoZZ': [],
        'BRHtott': [],
        'BRHtotautau': [],
        'BRHtogg': [],
        'BRHtogluglu': [],
        'BRAtobb': [],
        'BRAtoee': [],
        'BRAtomumu': [],
        'BRAtoss': [],
        'BRAtocc': [],
        'BRAtotautau': [],
        'BRAtogluglu': [],
        'BRAtoZh': [],
        'BRAtoZga': [],
        'BRAtogg': []
    }
    results.update(dicvars)
    print(results)
    xaxis = (np.arange(0.13, math.pi, 0.01) if func_of_cba else
             (np.arange(0.01, 20.1, 0.001) if func_of_tb else
              (np.arange(30., 1100., 10.) if func_of_mA else
               (np.arange(120., 1190., 10.)))))
    for x in xaxis:
        if func_of_tb:
            tb = x
            results['tb'].append(tb)
        elif func_of_cba:
            cba = math.cos(x)
            if x >= 0 and x <= math.pi / 2:
                sba = math.sin(x)
            elif x > math.pi / 2 and x <= math.pi:
                sba = math.sin(x - math.pi)
            results['cba'].append(cba)
        elif func_of_mA:
            mA = x
            mH = mA + mZ
            results['mA'].append(mA)
        elif func_of_mH:
            mH = x
            mA = mH - mZ
            results['mH'].append(mH)

        if mA > mH:
            logger.info("MA_{} > MH_{} switching to A->ZH mode!".format(
                mA, mH))
            mode = 'A'
        elif mH >= mA and mH > 125.:
            logger.info("MA_{} =< MH_{} switching to H->ZA mode!".format(
                mA, mH))
            mode = 'H'
        elif mH >= mA and mH <= 125.:
            logger.info(
                "MA_{} >= MH_{} && H <= 125. GeV switching to h->ZH mode!".
                format(mA, mH))
            mode = 'h'

        if options.debug:
            outputFile = 'out_mH-{}_mA-{}_tb-{}_cba-{}.dat'.format(
                mass_to_string(mH), mass_to_string(mA), mass_to_string(tb),
                mass_to_string(cba))
        else:
            outputFile = 'out.dat'

        mhc = max(mH, mA)
        m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
        res = Calc2HDM(mode=mode,
                       sqrts=sqrts,
                       type=type,
                       tb=tb,
                       m12=m12,
                       mh=mh,
                       mH=mH,
                       mA=mA,
                       mhc=mhc,
                       sba=sba,
                       outputFile=outputFile,
                       muR=1.,
                       muF=1.)
        res.setpdf('NNPDF31_nnlo_as_0118_mc_hessian_pdfas')
        res.computeBR()

        results['BRHtoss'].append(res.HtossBR)
        results['BRHtocc'].append(res.HtoccBR)
        results['BRHtobb'].append(res.HtobbBR)
        results['BRHtott'].append(res.HtottBR)
        results['BRHtoee'].append(res.HtoeeBR)
        results['BRHtomumu'].append(res.HtomumuBR)
        results['BRHtotautau'].append(res.HtotautauBR)
        results['BRHtogg'].append(res.HtoggBR)  # gamma-gamma
        results['BRHtoZZ'].append(res.HtoZZBR)
        results['BRHtoWW'].append(res.HtoWWBR)
        results['BRHtoZga'].append(res.HtoZgaBR)
        results['BRHtogluglu'].append(res.HtoglugluBR)
        results['BRHtohh'].append(res.HtohhBR)
        results['BRHtoZA'].append(res.HtoZABR)

        results['BRAtoss'].append(res.AtossBR)
        results['BRAtocc'].append(res.AtoccBR)
        results['BRAtobb'].append(res.AtobbBR)
        results['BRAtoee'].append(res.AtoeeBR)
        results['BRAtomumu'].append(res.AtomumuBR)
        results['BRAtotautau'].append(res.AtotautauBR)
        results['BRAtogg'].append(res.AtoggBR)
        results['BRAtoZga'].append(res.AtoZgaBR)
        results['BRAtogluglu'].append(res.AtoglugluBR)
        results['BRAtoZh'].append(res.AtoZhBR)

        if options.debug:
            shutil.move(os.path.join(CMSSW_Calculators42HDM, outputFile),
                        os.path.join(outputpath, outputFile))
            shutil.move(
                os.path.join(CMSSW_Calculators42HDM,
                             outputFile.replace('.dat', '.log')), outputpath)
    var = (cba if func_of_tb else (tb))
    if func_of_tb or func_of_cba:
        jsonf = 'BR_mH-%s_mA-%s_2hdmtype-%s_%s-%s_function_of_%s.json' % (
            mass_to_string(mH), mass_to_string(mA), type2hdm,
            ('cba' if func_of_tb else
             ('tb')), float_to_str(var, 2), ('tb' if func_of_tb else ('cba')))
    else:
        jsonf = 'BR_2hdmtype-%s_tb-%s_cba-%s_function_of_%s.json' % (  #('mA' if func_of_mH else ('mH')),
            #      mass_to_string(mA) if func_of_mH else( mass_to_string(mH)),
            type2hdm,
            float_to_str(tb, 2),
            float_to_str(cba, 2),
            ('mA' if func_of_mA else ('mH')))
    print(jsonf)
    with open(jsonf, 'w+') as f:
        json.dump(results, f)
    return jsonf
def compute_widths_BR_and_lambdas(mH,
                                  mA,
                                  mh,
                                  tb,
                                  process=None,
                                  pdfName="DEFAULT",
                                  saveprocessinfos=False):
    xsec_ggH = 0.
    xsec_bbH = 0.
    err_integration_ggH = 0.
    err_integration_bbH = 0.

    mb = 4.92  # mb(OS) pole mass
    mb__tilde__ = 4.92  # mb~
    MZ = 9.118760e+01

    if mA > mH:
        print("MA_{} > MH_{} switching to A->ZH mode!".format(mA, mH))
        mode = 'A'
    elif mH >= mA and mH > 125.:
        print("MA_{} =< MH_{} switching to H->ZA mode!".format(mA, mH))
        mode = 'H'
    elif mH >= mA and mH <= 125.:
        print(
            "MA_{} >= MH_{} && H <= 125. GeV switching to h->ZH mode!".format(
                mA, mH))
        mode = 'h'

    sqrts = 13000
    type = 2
    mh = mh
    cba = 0.01  #  cos( beta -alpha) " should not be changed: that's the alignement limit
    alpha = math.atan(tb) - math.acos(cba)
    sinbma = math.sin(math.atan(tb) - alpha)
    #sinbma = math.sqrt(1 - pow(cba, 2))
    mhc = max(mH, mA)
    m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
    outputFile = 'madgraphInputs_mH-{}_mA-{}_tb-{}_mode{}.dat'.format(
        mass_to_string(mH), mass_to_string(mA), mass_to_string(tb), mode)
    cwd = os.getcwd()
    #os.chdir(os.path.join(CMSSW_Calculators42HDM, 'out'))
    os.chdir(CMSSW_Calculators42HDM)
    if process == 'ggH':
        muR = mH / 2
        muF = muR
    elif process == 'bbH':
        muR = (mA + MZ + mb + mb__tilde__)
        muF = muR
    res = Calc2HDM(mode=mode,
                   sqrts=sqrts,
                   type=type,
                   tb=tb,
                   m12=m12,
                   mh=mh,
                   mH=mH,
                   mA=mA,
                   mhc=mhc,
                   sba=sinbma,
                   outputFile=outputFile,
                   muR=muR,
                   muF=muF)
    # A PDF is used, so alpha_s(MZ) is going to be modifie
    # I set the lhapdf to NNPDF31_nnlo_as_0118_nf_4_mc_hessian because it's the same lhapdf used in the default seeting by the genproductions
    # make sure to change it If you're planing to use 5FS PDFSETS !!
    res.setpdf('NNPDF31_nnlo_as_0118_nf_4_mc_hessian')
    res.computeBR()
    wH = float(res.Hwidth)
    wA = float(res.Awidth)
    l2 = float(res.lambda_2)
    l3 = float(res.lambda_3)
    lR7 = float(res.lambda_7)
    AtoZhBR = res.AtoZhBR
    AtoZHBR = res.AtoZHBR
    AtobbBR = res.AtobbBR
    HtoZABR = res.HtoZABR
    HtobbBR = res.HtobbBR
    wh3tobb = res.wh3tobb
    wh2tobb = res.wh2tobb

    if saveprocessinfos:
        sushiCardName = '{}_{}_{}_{}_{}'.format(mass_to_string(mH),
                                                mass_to_string(mA),
                                                mass_to_string(tb),
                                                mass_to_string(muR),
                                                mass_to_string(muF))
        #xsec_ggH, err_integration_ggH, err_muRm_ggH, err_muRp_ggH, xsec_bbH, err_integration_bbH, mb_MSscheme_muR=  res.getXsecFromSusHi(sushiCardName=sushiCardName, return_xsc_byComputationOrder = False)

    os.chdir(cwd)
    return wH, wA, wh2tobb, wh3tobb, l2, l3, lR7, sinbma, tb, xsec_ggH, err_integration_ggH, xsec_bbH, err_integration_bbH, HtoZABR, AtobbBR, AtoZHBR, HtobbBR
def plot2HDM_bottomYukawa_coupling(masstoscan=None,
                                   tanbeta=None,
                                   fullresummation=False):
    fig = plt.figure(figsize=(8, 6))
    ax = fig.add_subplot(111)
    Colors = [
        'forestgreen', 'pink', 'crimson', 'indigo', 'limegreen', 'blueviolet',
        'plum', 'magenta', 'purple', 'hotpink', 'mediumseagreen',
        'springgreen', 'aquamarine', 'turquoise', 'aqua', 'mediumslateblue',
        'orchid', 'deeppink', 'darkturquoise', 'teal', 'mediumslateblue'
    ]

    for idx, tb in enumerate(tanbeta):
        masses = []
        yb_Acouplings = []
        yb_Hcouplings = []
        ymb_Acouplings = []
        ymb_Hcouplings = []

        yb_Acouplings_ver2 = []
        Partialwidth_h1tobb = []
        m = 125.
        while m < 1500.:
            type = 2
            sqrts = 13000

            muR = 9.118800e+01
            muF = 9.118800e+01

            cba = 0.01  #  cos( beta -alpha) " should not be changed: that's the alignement limit
            alpha = math.atan(tb) - math.acos(cba)
            sinbma = math.sin(math.atan(tb) -
                              alpha)  # OR sinbma = math.sqrt(1 - pow(cba, 2))
            beta = math.atan(tb)

            mZ = 9.118760e+01
            mH = (m if masstoscan == 'h2' else (m + mZ))
            mA = (m if masstoscan == 'h3' else (m - mZ))
            mh = 125.
            if mA > mH:
                mode = 'A'
            elif mH >= mA and mH > 125.:
                mode = 'H'
            elif mH >= mA and mH <= 125.:
                mode = 'h'
            mhc = max(mH, mA)
            m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))

            outputFile = 'out.dat'

            res = Calc2HDM(mode=mode,
                           sqrts=sqrts,
                           type=type,
                           tb=tb,
                           m12=m12,
                           mh=mh,
                           mH=mH,
                           mA=mA,
                           mhc=mhc,
                           sba=sinbma,
                           outputFile=outputFile,
                           muR=muR,
                           muF=muF)
            res.setpdf('NNPDF31_nnlo_as_0118_nf_4_mc_hessian')
            res.computeBR()

            #xsec_ggH, err_integration_ggH, err_muRm_ggH, err_muRp_ggH, xsec_bbH, err_integration_bbH =  res.getXsecFromSusHi()
            with open(
                    './Scan/NNPDF31_nnlo_as_0118_nf_4_mc_hessian/{}_{}_{}_{}_{}_{}.out'
                    .format(
                        str(mH).replace('.', 'p'),
                        str(mA).replace('.', 'p'), mass_to_string(muR,
                                                                  digits=3),
                        mass_to_string(muF, digits=3),
                        mass_to_string(tb, digits=1),
                        '0p999'), 'r') as sushi_outFile:
                for line in sushi_outFile:
                    if '# g_b' in line:
                        g_b = float(line.split()[1])

            wh3tobb = res.wh3tobb
            wh2tobb = res.wh2tobb

            yb_H, ymb_H, yb_A, ymb_A = Block_YUKAWA(mh1=mh,
                                                    mh2=mH,
                                                    mh3=mA,
                                                    tanbeta=tb,
                                                    sinbma=sinbma,
                                                    wh2tobb=wh2tobb,
                                                    wh3tobb=wh3tobb)
            yb_A_ver2 = Block_YUKAWA_ver2(tanbeta=tb, sinbma=sinbma, g_b=g_b)

            print((math.cos(alpha) / math.cos(beta)), tb,
                  tb / (math.cos(alpha) / math.cos(beta)), 'okaaaaaaaaa')
            yb_Hcouplings.append(yb_H * (math.cos(alpha) / math.cos(beta)))
            yb_Acouplings.append(yb_A * tb)

            ymb_Hcouplings.append(ymb_H)
            ymb_Acouplings.append(ymb_A)

            #yb_Acouplings_ver2.append(yb_A_ver2)
            #Partialwidth_h1tobb.append(wh1tobb)

            masses.append(m)
            m += 50.

        print(yb_Acouplings, ymb_Acouplings)
        print(yb_Hcouplings, ymb_Hcouplings)
        print(masses)
        if fullresummation:
            plt.plot(masses,
                     ymb_Acouplings,
                     color=Colors[idx],
                     linewidth=3.5,
                     marker='o',
                     label=r'$m^{Y, A}_{b}: tan\beta = %s$' % tb)
            plt.plot(masses,
                     ymb_Hcouplings,
                     color=Colors[idx + 2],
                     linewidth=2.,
                     marker='s',
                     label=r'$m^{Y, H}_{b}: tan\beta = %s$' % tb)
        else:
            plt.plot(masses,
                     yb_Acouplings,
                     color=Colors[idx],
                     linewidth=3.5,
                     marker='o',
                     label=r'$Y^{A}_{b}: tan\beta = %s$' % tb)
            plt.plot(masses,
                     yb_Hcouplings,
                     color=Colors[idx + 2],
                     linewidth=2.,
                     marker='s',
                     label=r'$Y^{H}_{b}: tan\beta = %s$' % tb)

        #plt.plot(masses,yb_Acouplings_ver2, color=Colors[idx+5], marker='<', label=r'$Y^{A}_{b} ver2: tan\beta = %s$'%tb)
        #ax.axhspan((4.088E-03- 0.73*4.088E-03/100.) , (4.088E-03+ 0.73*4.088E-03/100.), color=Colors[idx+4], label='r$\Gamma(h_{SM}=125'))
        #plt.plot(masses,Partialwidth_h1tobb, color=Colors[idx], marker='o', label=r'$\Gamma(h_{SM}=125 \rightarrow bb), tan\beta = {}$'.format(tb))

    ylabel = ('m^{ Y,\phi}_{b}' if fullresummation else
              ('Y^{\phi}_{b} =  \sqrt{2}  m^{ Y,\phi}_{b}g^{ \phi }_{f}/vev'))
    plt.ylabel(r'Bottom-Yukawa  coupling $%s$' % ylabel, fontsize=12.)
    plt.xlabel(r'$M_{} [GeV]$'.format('A' if masstoscan == 'h3' else 'H'),
               fontsize=12.)
    #plt.yscale('log')
    plt.title(
        r'$2HDM-typeII: M_{H^\pm}=M_{H}, M_{H}=M_{A}+M_{Z}, cos(\beta-\alpha)= 0.01, mh= 125. GeV $',
        fontsize=10.)
    plt.xlim(min(masses), max(masses))
    plt.legend()
    fig.savefig('PLOTS/bottomyukawa_coupling_{}_func_{}mass.png'.format(
        ('ymb' if fullresummation else ('yb')), masstoscan))
    plt.gcf().clear()
def Calculators42HDM(list_masses,
                     list_tb,
                     return_scaledXSC=False,
                     return_totalwidth=False):
    sqrts = 13000  #center-of-mass energy in GeV
    type = 2
    mh = 125.
    mZ = 91.1876
    cba = 0.01

    widths = {}
    xsec_times_BR = {}
    xsec = {}
    for tb in list_tb:
        results1 = {
            'Hwidth': [],
            'H+width': [],
            'hwidth': [],
            'Awidth': [],
            'mH': [],
            'mA': []
        }
        results2 = {
            'gg-fusion': [],
            'bb-associated_production': [],
            'mH': [],
            'mA': []
        }
        results3 = {
            'gg-fusion': [],
            'bb-associated_production': [],
            'mH': [],
            'mA': []
        }

        for m in list_masses:
            if options.scan == "mA":
                mA = m
                mH = mZ + mA
            else:
                mH = m
                mA = mH - mZ

            results1['mA'].append(mA)
            results1['mH'].append(mH)
            results2['mA'].append(mA)
            results2['mH'].append(mH)
            results3['mA'].append(mA)
            results3['mH'].append(mH)

            if mA > mH:
                logger.info("MA_{} >= MH_{} switching to A->ZH mode!".format(
                    mA, mH))
                mode = 'A'
            elif mH >= mA and mH > 125.:
                logger.info("MA_{} =< MH_{} switching to H->ZA mode!".format(
                    mA, mH))
                mode = 'H'
            elif mH >= mA and mH <= 125.:
                mode = 'h'
                logger.info('mode h')

            mhc = max(mH, mA)
            m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
            if (pow(mhc, 2) * tb / (1 + pow(tb, 2))) < 0:
                logger.warning('m12 is negative ! ')
            sba = math.sqrt(1 - pow(cba, 2))
            if options.debug:
                outputFile = 'out_mH-{}_mA-{}_tb-{}.dat'.format(
                    mass_to_string(mH), mass_to_string(mA), mass_to_string(tb))
            else:
                outputFile = 'out.dat'

            cwd = os.getcwd()
            os.chdir(CMSSW_Calculators42HDM)

            res = Calc2HDM(mode=mode,
                           sqrts=sqrts,
                           type=type,
                           tb=tb,
                           m12=m12,
                           mh=mh,
                           mH=mH,
                           mA=mA,
                           mhc=mhc,
                           sba=sba,
                           outputFile=outputFile,
                           muR=1.,
                           muF=1.)
            res.setpdf('NNPDF31_nnlo_as_0118_mc_hessian_pdfas')
            res.settb(tb)
            res.setmA(mA)
            res.setmH(mH)
            res.computeBR()

            results1['Hwidth'].append(res.Hwidth)
            results1['H+width'].append(res.chargedHwidth)
            results1['hwidth'].append(res.hwidth)
            results1['Awidth'].append(res.Awidth)

            os.chdir(CMSSW_Calculators42HDM)
            xsec_ggh, err_integration_ggh, err_muRm_ggh, err_muRp_ggh, xsec_bbh, err_integration_bbh = res.getXsecFromSusHi(
            )

            if mode == 'H':  # H->ZA
                BR = res.HtoZABR * res.AtobbBR
            elif mode == 'A':  # A->ZH
                BR = res.AtoZHBR * res.HtobbBR
            elif mode == 'h':  # A->Zh
                BR = res.AtoZhBR * res.htobbBR

            results2['gg-fusion'].append(xsec_ggh * BR)
            results2['bb-associated_production'].append(xsec_bbh * BR)

            results3['gg-fusion'].append(xsec_ggh)
            results3['bb-associated_production'].append(xsec_bbh)

        widths[tb] = results1
        xsec_times_BR[tb] = results2
        xsec[tb] = results3
        print(80 * '*')
    mass_rng = 'from{}to{}'.format(float_to_str(list_masses.min(), 2),
                                   float_to_str(list_masses.max(), 2))
    tb_rng = 'from{}to{}'.format(float_to_str(list_tb.min(), 2),
                                 float_to_str(list_tb.max(), 2))
    json_Totalwidth = 'data/totalwidth_2HDM-type{}_cosbeta-alpha-{}_func_of_tb-{}_{}-{}.json'.format(
        type, float_to_str(cba, 2), tb_rng, options.scan.upper(), mass_rng)
    json_Totalxsc = 'data/totalxsc_2HDM-type{}_cosbeta-alpha-{}_func_of_tb-{}_{}-{}.json'.format(
        type, float_to_str(cba, 2), tb_rng, options.scan.upper(), mass_rng)
    json_TotalxscXbr = 'data/totalxscXbr_2HDM-type{}_cosbeta-alpha-{}_func_of_tb-{}_{}-{}.json'.format(
        type, float_to_str(cba, 2), tb_rng, options.scan.upper(), mass_rng)
    with open(json_Totalwidth, 'w+') as f:
        json.dump(widths, f)
    with open(json_TotalxscXbr, 'w+') as f:
        json.dump(xsec_times_BR, f)
    with open(json_Totalxsc, 'w+') as f:
        json.dump(xsec, f)

    return ((json_TotalxscXbr if return_scaledXSC else
             (json_Totalxsc)) if not return_totalwidth else (json_Totalwidth))
def compute_widths_BR_and_lambdas(mH, mA, mh, tb):
    global options
    global lhaid

    mode = 'H'
    if mA > mH:
        logger.info("MA_{} > MH_{} switching to A->ZH mode!".format(mA, mH))
        mode = 'A'
    elif mH >= mA and mH > 125.:
        logger.info("MA_{} =< MH_{} switching to H->ZA mode!".format(mA, mH))
        mode = 'H'
    elif mH >= mA and mH <= 125.:
        logger.info(
            "MA_{} >= MH_{} && H <= 125. GeV switching to h->ZH mode!".format(
                mA, mH))
        mode = 'h'
    sqrts = 13000
    type = 2
    mh = mh
    cba = 0.01  #  cos( beta -alpha) " should not be changed: that's the alignement limit
    alpha = math.atan(tb) - math.acos(cba)
    sinbma = math.sin(math.atan(tb) - alpha)
    #sinbma = math.sqrt(1 - pow(cba, 2))
    mhc = max(mH, mA)
    m12 = math.sqrt(pow(mhc, 2) * tb / (1 + pow(tb, 2)))
    outputFile = 'madgraphInputs_mH-{}_mA-{}_tb-{}.dat'.format(
        mass_to_string(mH), mass_to_string(mA), mass_to_string(tb))
    cwd = os.getcwd()
    #os.chdir(os.path.join(CMSSW_Calculators42HDM, 'out'))
    os.chdir(CMSSW_Calculators42HDM)
    res = Calc2HDM(mode=mode,
                   sqrts=sqrts,
                   type=type,
                   tb=tb,
                   m12=m12,
                   mh=mh,
                   mH=mH,
                   mA=mA,
                   mhc=mhc,
                   sba=sinbma,
                   outputFile=outputFile,
                   muR=1.,
                   muF=1.)

    if options.lhapdfsets == 'DEFAULT':
        logger.warning(
            'The following ** $DEFAULT_PDF_SETS ** is shortcuts to have the PDF sets automatically added to the run_card at run time to avoid specifying them directly\n. Be careful this is valid at both LO and NLO !\n'
        )
        lhaid = '$DEFAULT_PDF_SETS'
    elif options.lhapdfsets == 'NNPDF31':
        if options.scheme == '4FS':
            logger.info(
                '''No PDFSETS is given !**  LHA PDF set = NNPDF31  # Positive definite 4Flavor-scheme set will be used instead\n 
                            LHA Name = NNPDF31_nnlo_as_0118_nf_4_mc_hessian\n 
                            LHA ID = 325500\n 
                            make sure this is compatible with the generated process in the proc_card and lhaid in the run_card **\n'''
            )
            res.setpdf('NNPDF31_nnlo_as_0118_nf_4_mc_hessian')
            lhaid = 325500
        else:
            logger.info(
                '''No PDFSETS is given !**  LHA PDF set = NNPDF31  # Positive definite set will be used instead\n 
                            LHA Name = NNPDF31_nnlo_as_0118_mc_hessian_pdfas\n 
                            LHA ID = 325300\n 
                            make sure this is compatible with the generated process in the proc_card and lhaid in the run_card **\n'''
            )
            res.setpdf('NNPDF31_nnlo_as_0118_mc_hessian_pdfas')
            lhaid = 325300
    else:
        res.setpdf(options.lhapdfsets)
        lhaid = options.lhaid
        if lhaid is None:
            logger.error("CRITICAL: lhaid can't be NONE ")

    res.computeBR()
    wH = float(res.Hwidth)
    wA = float(res.Awidth)
    l2 = float(res.lambda_2)
    l3 = float(res.lambda_3)
    lR7 = float(res.lambda_7)
    AtoZhBR = res.AtoZhBR
    AtobbBR = res.AtobbBR
    HtoZABR = res.HtoZABR
    HtobbBR = res.HtobbBR
    os.chdir(cwd)
    return wH, wA, l2, l3, lR7, sinbma, tb  #, AtoZhBR, AtobbBR, HtoZABR, HtobbBR