示例#1
0
def write_run_card(model, model_name, run_card_path):

    ext_params = [s_parameter(param) for param in  model.all_parameters if (s_parameter(param).is_external())]
    
    # length of the 'index'-fields in output
    nci        = max([max([len(str(index)) for index in param.lha_indices()]) for param in ext_params])
    # length of the 'value'-fields in output
    ncv        = max([len(str(param.raw_value())) for param in ext_params])
    
    blocks     = dict()
    for param in ext_params:
        cur_block = param.lha_block().lower()
        if not cur_block in blocks:
            blocks[cur_block]=[par for par in ext_params if par.lha_block().lower()==cur_block]

    ufo_params = ""

    for block,param_list in blocks.iteritems():
        if (block.lower() == "decay"): continue # in order to comply with weird default ufo param_card format
        ufo_params += "block {0}\n".format(block)
        ufo_params += "".join([table_format(nci,param.lha_indices(),
                                            ncv, param.raw_value(),
                                            param.name()) for param in param_list])
        ufo_params += "\n"

    # in order to comply with weird default ufo param_card format
    if "decay" in blocks:
        for param in blocks["decay"]:
            ufo_params += "decay "+table_format(nci, param.lha_indices(), ncv, param.raw_value(), param.name())
        
    with open(run_card_path, "w") as outfile:
        outfile.write(run_card_template.substitute(model=model, model_name=model_name, ufo_params=ufo_params))
示例#2
0
def write_run_card(model, model_name, run_card_path):

    ext_params = [s_parameter(param) for param in  model.all_parameters if (s_parameter(param).is_external())]
    
    # length of the 'index'-fields in output
    nci        = max([max([len(str(index)) for index in param.lha_indices()]) for param in ext_params])
    # length of the 'value'-fields in output
    ncv        = max([len(str(param.raw_value())) for param in ext_params])
    
    blocks     = dict()
    for param in ext_params:
        cur_block = param.lha_block().lower()
        if not cur_block in blocks:
            blocks[cur_block]=[par for par in ext_params if par.lha_block().lower()==cur_block]

    ufo_params = ""

    for block,param_list in blocks.iteritems():
        if (block.lower() == "decay"): continue # in order to comply with weird default ufo param_card format
        ufo_params += "block {0}\n".format(block)
        ufo_params += "".join([table_format(nci,param.lha_indices(),
                                            ncv, param.raw_value(),
                                            param.name()) for param in param_list])
        ufo_params += "\n"

    # in order to comply with weird default ufo param_card format
    if "decay" in blocks:
        for param in blocks["decay"]:
            ufo_params += "decay "+table_format(nci, param.lha_indices(), ncv, param.raw_value(), param.name())

    # generate a helpful template for a user specification of coupling orders 
    order_statement = 'Order (' + ','.join(['*' for order in model.all_orders]) + ')'
    order_comment   = '# Syntax: "Order (' + ','.join([order.name for order in model.all_orders]) + ');"'
        
    with open(run_card_path, "w") as outfile:
        outfile.write(run_card_template.substitute(model=model, 
                                                   model_name=model_name, 
                                                   ufo_params=ufo_params,
                                                   order_statement=order_statement,
                                                   order_comment=order_comment))
示例#3
0
def write_run_card(model, model_name, run_card_path):

    ext_params = [
        s_parameter(param) for param in model.all_parameters
        if (s_parameter(param).is_external())
    ]
    blocks = dict()
    for param in ext_params:
        cur_block = param.lha_block().lower()
        if not cur_block in blocks:
            blocks[cur_block] = [
                par for par in ext_params
                if par.lha_block().lower() == cur_block
            ]

    ufo_params = ""

    for block, param_list in blocks.iteritems():
        if (block.lower() == "decay"):
            continue  # in order to comply with weird default ufo param_card format
        ufo_params += "block {0}\n\t".format(block)
        ufo_params += "\n\t".join([
            " ".join([str(ind) for ind in param.lha_indices()]) + " " +
            str(param.raw_value()) for param in param_list
        ])
        ufo_params += "\n"

    # in order to comply with weird default ufo param_card format
    if "decay" in blocks:
        for param in blocks["decay"]:
            ufo_params += "\ndecay {0} {1}".format(param.lha_indices()[0],
                                                   str(param.raw_value()))

    with open(run_card_path, "w") as outfile:
        outfile.write(
            run_card_template.substitute(model=model,
                                         model_name=model_name,
                                         ufo_params=ufo_params))
示例#4
0
def write_run_card(model, model_name, run_card_path):

    ext_params = [s_parameter(param) for param in  model.all_parameters if (s_parameter(param).is_external())]
    blocks     = dict()
    for param in ext_params:
        cur_block = param.lha_block().lower()
        if not cur_block in blocks:
            blocks[cur_block]=[par for par in ext_params if par.lha_block().lower()==cur_block]

    ufo_params = ""

    for block,param_list in blocks.iteritems():
        if (block.lower() == "decay"): continue # in order to comply with weird default ufo param_card format
        ufo_params += "block {0}\n\t".format(block)
        ufo_params += "\n\t".join([" ".join([str(ind) for ind in param.lha_indices()])+" "+str(param.raw_value()) for param in param_list])
        ufo_params += "\n"

    # in order to comply with weird default ufo param_card format
    if "decay" in blocks:
        for param in blocks["decay"]:
            ufo_params += "\ndecay {0} {1}".format(param.lha_indices()[0], str(param.raw_value()))
        
    with open(run_card_path, "w") as outfile:
        outfile.write(run_card_template.substitute(model=model, model_name=model_name, ufo_params=ufo_params))
示例#5
0
def write_model(model, model_name, model_file_name):

    para_init = ""
    part_init = ""

    external_parameters = [s_parameter(param) for param in  model.all_parameters if (s_parameter(param).is_external())]
    internal_parameters = [s_parameter(param) for param in  model.all_parameters if (s_parameter(param).is_internal())]

    # external parameter initialization
    for param in external_parameters:
        statement = "    double "+param.name()+" = p_dataread->GetEntry<double>(\""+str(param.lha_block())+"\", "
        if len(param.lha_indices()) == 1:
            statement += str(param.lha_indices()[0])
        if len(param.lha_indices()) == 2:
            statement += str(param.lha_indices()[0])+", "+str(param.lha_indices()[1])
        statement+=");"
        para_init += "\n"+statement

    # internal parameter initialization and calculation
    for param in internal_parameters:
        if param.is_complex():
            statement = "    Complex "+param.name()+" = "+param.cpp_value()+";"
        else:
            statement = "    double "+param.name()+" = ToDouble("+param.cpp_value()+");"
        para_init += "\n"+statement
        para_init += "\n    DEBUG_VAR({0});".format(param.name())

    # fill particle list
    for s_part in [ s_particle(p) for p in model.all_particles ]:
        kfcode = s_part.kf_code()
        # don't explicitly need to add antiparticles
        if kfcode < 0: 
            continue
        massive = 0 if (s_part.ufo_particle.mass is model.parameters.ZERO) else 1
        part_init += ("\n    ATOOLS::s_kftable["+str(s_part.kf_code())+"] = new ATOOLS::Particle_Info("+ 
                      str(s_part.kf_code())+", "+                                 # kf_code
                      str(1000.0)+", "+                                           # mass
                      str(0.0)+", "+                                              # width
                      str(s_part.charge_times_three())+", "+                      # 3*(electrical_charge)
                      str(s_part.color())+", "+                                   # strong charge
                      str(s_part.spin_times_two())+", "+                          # 2*spin
                      str(s_part.self_conjugate())+", "+                          # self_conjugate
                      str(1)+", "+                                                # is active
                      str(0)+", "+                                                # stable
                      str(massive)+", "+                                          # massive
                      "\""+str(s_part.name())+"\", "+                             # name
                      "\""+str(s_part.antiname())+"\", "+                         # antiname
                      "\""+str(s_part.texname())+"\", "+                          # texname
                      "\""+str(s_part.antitexname())+"\");")                      # antitexname

        wstring = s_part.width().name() if s_part.width().is_external() else s_part.width().cpp_value()
        mstring = s_part.mass().name()  if s_part.mass().is_external()  else s_part.mass().cpp_value()
        para_init += "\n    ATOOLS::Flavour({0}).SetWidth(ToDouble({1}));".format(kfcode,wstring)
        para_init += "\n    ATOOLS::Flavour({0}).SetMass(ToDouble({1}));".format(kfcode,mstring)
        para_init += "\n    ATOOLS::Flavour({0}).SetHadMass(ToDouble({1}));".format(kfcode,mstring)

    # coupling initialization and calculation
    for coup in model.all_couplings:
        s_coup = s_coupling(coup)
        para_init += "\n    p_complexconstants->insert(std::make_pair(std::string(\""+s_coup.name()+"\"),"+s_coup.cpp_value()+"));"
        para_init += "\n    DEBUG_VAR((*p_complexconstants)[\"{0}\"]);".format(s_coup.name())

    model.all_orders.sort(key=attrgetter('hierarchy'))
    hierarchy     = [order.name for order in model.all_orders]
    declarations  = ""
    calls         = ""
    vertices      = list(sum([split_by_orders(vert, hierarchy) for vert in model.all_vertices],[]))
    vertices      = [vert for vert in vertices if not (vert.has_ghosts() or vert.has_goldstones()) ]
    i             = 0

    while (len(vertices) > 0):
        sub_vert_list = []
        id_string = "vertices_{0}".format(i)
        while ((len(sub_vert_list)<10) and len(vertices) > 0):
            sub_vert_list.append(vertices.pop())

        v_collection  = vertex_collection(sub_vert_list, id_string)
        declarations += v_collection.implementation_string()
        calls        += v_collection.call_string()
        i            += 1
    
    # write out model
    with open(model_file_name, "w") as outfile:
        outfile.write(model_template.substitute(model_name=model_name, particle_init=part_init, param_init=para_init,
                                                declarations = declarations, calls = calls))
示例#6
0
def write_model(model, model_name, model_file_name):

    para_init = ""
    part_init = ""

    external_parameters = [
        s_parameter(param) for param in model.all_parameters
        if (s_parameter(param).is_external())
    ]
    internal_parameters = [
        s_parameter(param) for param in model.all_parameters
        if (s_parameter(param).is_internal())
    ]

    # external parameter initialization
    for param in external_parameters:
        statement = "    double " + param.name(
        ) + " = p_dataread->GetEntry<double>(\"" + str(
            param.lha_block()) + "\", "
        if len(param.lha_indices()) == 1:
            statement += str(param.lha_indices()[0])
        if len(param.lha_indices()) == 2:
            statement += str(param.lha_indices()[0]) + ", " + str(
                param.lha_indices()[1])
        statement += ");"
        para_init += "\n" + statement

    # internal parameter initialization and calculation
    for param in internal_parameters:
        if param.is_complex():
            statement = "    Complex " + param.name(
            ) + " = " + param.cpp_value() + ";"
        else:
            statement = "    double " + param.name() + " = " + param.cpp_value(
            ) + ";"
        para_init += "\n" + statement
        para_init += "\n    DEBUG_VAR({0});".format(param.name())

    # fill particle list
    for s_part in [s_particle(p) for p in model.all_particles]:
        kfcode = s_part.kf_code()
        # don't explicitly need to add antiparticles
        if kfcode < 0:
            continue
        massive = 0 if (
            s_part.ufo_particle.mass is model.parameters.ZERO) else 1
        part_init += (
            "\n    ATOOLS::s_kftable[" + str(s_part.kf_code()) +
            "] = new ATOOLS::Particle_Info(" + str(s_part.kf_code()) +
            ", " +  # kf_code
            str(1000.0) + ", " +  # mass
            str(0.0) + ", " +  # width
            str(s_part.charge_times_three()) + ", " +  # 3*(electrical_charge)
            str(s_part.color()) + ", " +  # strong charge
            str(s_part.spin_times_two()) + ", " +  # 2*spin
            str(s_part.self_conjugate()) + ", " +  # self_conjugate
            str(1) + ", " +  # is active
            str(0) + ", " +  # stable
            str(massive) + ", " +  # massive
            "\"" + str(s_part.name()) + "\", " +  # name
            "\"" + str(s_part.antiname()) + "\", " +  # antiname
            "\"" + str(s_part.texname()) + "\", " +  # texname
            "\"" + str(s_part.antitexname()) + "\");")  # antitexname

        wstring = s_part.width().name() if s_part.width().is_external(
        ) else s_part.width().cpp_value()
        mstring = s_part.mass().name() if s_part.mass().is_external(
        ) else s_part.mass().cpp_value()
        para_init += "\n    ATOOLS::Flavour({0}).SetWidth({1});".format(
            kfcode, wstring)
        para_init += "\n    ATOOLS::Flavour({0}).SetMass({1});".format(
            kfcode, mstring)
        para_init += "\n    ATOOLS::Flavour({0}).SetHadMass({1});".format(
            kfcode, mstring)

    # coupling initialization and calculation
    for coup in model.all_couplings:
        s_coup = s_coupling(coup)
        para_init += "\n    p_complexconstants->insert(std::make_pair(std::string(\"" + s_coup.name(
        ) + "\")," + s_coup.cpp_value() + "));"
        para_init += "\n    DEBUG_VAR((*p_complexconstants)[\"{0}\"]);".format(
            s_coup.name())

    model.all_orders.sort(key=attrgetter('hierarchy'))
    hierarchy = [order.name for order in model.all_orders]
    declarations = ""
    calls = ""
    vertices = list(
        sum([split_by_orders(vert, hierarchy) for vert in model.all_vertices],
            []))
    vertices = [
        vert for vert in vertices
        if not (vert.has_ghosts() or vert.has_goldstones())
    ]
    i = 0

    while (len(vertices) > 0):
        sub_vert_list = []
        id_string = "vertices_{0}".format(i)
        while ((len(sub_vert_list) < 10) and len(vertices) > 0):
            sub_vert_list.append(vertices.pop())

        v_collection = vertex_collection(sub_vert_list, id_string)
        declarations += v_collection.implementation_string()
        calls += v_collection.call_string()
        i += 1

    # write out model
    with open(model_file_name, "w") as outfile:
        outfile.write(
            model_template.substitute(model_name=model_name,
                                      particle_init=part_init,
                                      param_init=para_init,
                                      declarations=declarations,
                                      calls=calls))
示例#7
0
def write_run_card(model, model_name, run_card_path):

    ext_params = [
        s_parameter(param) for param in model.all_parameters
        if (s_parameter(param).is_external())
    ]

    # length of the 'index'-fields in output
    nci = max([
        max([len(str(index)) for index in param.lha_indices()])
        for param in ext_params
    ])
    # length of the 'value'-fields in output
    ncv = max([len(str(param.raw_value())) for param in ext_params])

    blocks = dict()
    for param in ext_params:
        cur_block = param.lha_block().lower()
        if not cur_block in blocks:
            blocks[cur_block] = [
                par for par in ext_params
                if par.lha_block().lower() == cur_block
            ]

    yaml_indent = "  "

    ufo_params = ""

    for block, param_list in blocks.iteritems():
        if (block.lower() == "decay"):
            continue  # in order to comply with weird default ufo param_card format
        ufo_params += yaml_indent + "block {0}\n".format(block)
        ufo_params += "".join([
            yaml_indent + table_format(nci, param.lha_indices(), ncv,
                                       param.raw_value(), param.name())
            for param in param_list
        ])
        ufo_params += yaml_indent + "\n"

    # in order to comply with weird default ufo param_card format
    if "decay" in blocks:
        for param in blocks["decay"]:
            ufo_params += yaml_indent
            ufo_params += "decay "
            ufo_params += table_format(nci, param.lha_indices(), ncv,
                                       param.raw_value(), param.name())

    # generate a helpful template for a user specification of coupling orders
    order_statement = 'Order: {' + ','.join(
        [order.name + ': Any' for order in model.all_orders]) + '}'

    # collect all particles of the model for an example process section
    all_particles = [s_particle(p) for p in model.all_particles]
    all_particles = ",".join([
        str(p.kf_code()) for p in all_particles
        if not (p.is_goldstone() or p.is_ghost())
    ])

    with open(run_card_path, "w") as outfile:
        outfile.write(
            run_card_template.substitute(model=model,
                                         model_name=model_name,
                                         ufo_params=ufo_params,
                                         order_statement=order_statement,
                                         all_particles=all_particles))