def setup_param_card(param_card_path, model_config, df=None, index=None): import check_param_card as param_card_mod # param_card param_card = param_card_mod.ParamCard(param_card_path) for par, opts in model_config['mg5_parameters'].iteritems(): if not 'value' in opts: param_card[opts['block']].param_dict[( opts['lhaid'], )].value = df.loc[index, par] else: param_card[opts['block']].param_dict[( opts['lhaid'], )].value = opts['value'] param_card.write(param_card_path)
def get_param_card(process_dir, param_card_path): process_internal_dir = os.path.join(process_dir, 'bin', 'internal') # - MadGraph5 root directory if MG5_root_dir not in sys.path: sys.path.append(MG5_root_dir) # - MadGraph5 root directory if process_internal_dir not in sys.path: sys.path.append(process_internal_dir) import check_param_card as param_card_mod # param_card param_card = param_card_mod.ParamCard(param_card_path) return param_card
def getParameters(process, model, blocks): """ Find all parameters belonging to blocks and then cross-check with the param card. There may be fewer parameters in the param card if a restrict card was used. """ param_card = param_card_mod.ParamCard( os.path.join(MG_DIR, process, "Cards", "param_card.dat")) params = [] for param in model.all_parameters: block = param.lhablock if block in blocks: #check that this block exists in param card assert block.lower() in param_card.keys( ) #block names appear in lower case in param card #if this param in param card if (param.lhacode[0], ) in param_card[block.lower()].keys(): params.append(param.name) return params
os.mkdir(args.output) # Copy the rwgt directory subprocess.check_call(['tar', '-xf', args.rw_module, '-C', args.output]) subprocess.check_call(['cp', args.config, '%s/config.json' % args.output]) sys.path.append('%s/%s' % (os.environ['PWD'], os.environ['MG_DIR'])) sys.path.append(os.path.join(os.environ['MG_DIR'], process, 'bin', 'internal')) import check_param_card as param_card_mod cfg = tools.GetConfigFile(args.config) param_card_path = 'cards/%s/param_card.dat' % process print '>> Parsing %s' % param_card_path param_card = param_card_mod.ParamCard(param_card_path) pars = cfg['parameters'] initvals = [X['sm'] for X in pars] current_i = 0 param_card.write('%s/param_card_%i.dat' % (args.output, current_i)) current_i += 1 for i in xrange(len(pars)): vals = list(initvals) vals[i] = (pars[i]['val'] + initvals[i]) / 2. for ix, x in enumerate(pars): param_card[x['block']].param_dict[(x['index'],)].value = vals[ix]
parser = argparse.ArgumentParser() parser.add_argument('--process', '-p', default='ggF') parser.add_argument('--output', '-o', default='config.json') parser.add_argument('--block', default='newcoup') parser.add_argument('--default-value', type=float, default=None) parser.add_argument('--limit-pars', type=str, default=None) parser.add_argument('--default-value-inactive', type=float, default=None) args = parser.parse_args() sys.path.append( os.path.join(os.environ['MG_DIR'], args.process, 'bin', 'internal')) import check_param_card as param_card_mod param_card = param_card_mod.ParamCard('%s/%s/Cards/param_card.dat' % (os.environ['MG_DIR'], args.process)) # then to modify an entry of such object you can do ids = [X[0] for X in param_card[args.block].keys()] print ids limit_pars = list(ids) if args.limit_pars is not None: limit_pars = [int(X) for X in args.limit_pars.split(',')] for i in ids: par = param_card[args.block].param_dict[(i, )] if args.default_value is not None and i in limit_pars: par.value = args.default_value if i not in limit_pars and args.default_value_inactive is not None: par.value = args.default_value_inactive