def run_dijet(edges, args):
    with open(args.denominator, 'r') as denom_file:
        denom = get_denom_dict(denom_file)
    with open(args.cross_sections, 'r') as xsec_file:
        xsecs = CrossSections(xsec_file, denom)

    parts = {}
    hist = 0
    for ds in args.datasets:
        dsid = get_dsid(ds)
        print("Current dataset is", dsid)
        if not is_dijet(dsid):
            continue
        if xsecs.datasets[dsid]['denominator'] == 0:
            continue
        weight = xsecs.get_weight(dsid)
        this_dsid = get_hist(ds, edges) * weight
        parts[dsid] = np.array(this_dsid)
        hist += this_dsid

    draw_hist(hist,
              edges,
              args.out_dir,
              parts,
              file_name='calculated_dijet.pdf')
    save_hist(hist, edges, args.out_dir, 'calculated_jetpt.h5', 'dijet')
def run_higgs_reweighted(edges, args):
    hist = 0
    parts = {}
    out_dir = args.out_dir
    with File('%s/calculated_jetpt.h5' % out_dir, 'r') as h5file:
        num = h5file['dijet']['hist']
        denom = h5file['higgs']['hist']
        ratio = np.zeros_like(num)
        valid = np.asarray(denom) > 0.0
        ratio[valid] = num[valid] / denom[
            valid]  # this is the histograms ratio
    for ds in args.datasets:
        dsid = get_dsid(ds)
        if not is_dihiggs(dsid):
            continue

        this_dsid = get_hist_reweighted(ds, edges, ratio)
        parts[dsid] = np.array(this_dsid)
        hist += this_dsid

    draw_hist(hist,
              edges,
              args.out_dir,
              parts,
              file_name='calculated_higgs_reweight.pdf')
Пример #3
0
def run_higgs(edges, args):
    hist = 0
    parts = {}
    for ds in args.datasets:
        dsid = get_dsid(ds)
        if not is_dihiggs(dsid):
            continue

        this_dsid = get_hist(ds, edges)
        parts[dsid] = np.array(this_dsid)
        hist += this_dsid

    draw_hist(hist, edges, args.out_dir, parts, file_name='higgs.pdf')
    save_hist(hist, edges, args.out_dir, 'jetpt.h5', 'higgs')
def run_wz(edges, args):
    hist = 0
    parts = {}
    for ds in args.datasets:
        dsid = get_dsid(ds)
        if not is_wz(dsid):
            continue

        this_dsid = get_hist(ds, edges)
        parts[dsid] = np.array(this_dsid)
        hist += this_dsid

    draw_hist(hist, edges, args.out_dir, parts, file_name='calculated_wz.pdf')
    save_hist(hist, edges, args.out_dir, 'calculated_jetpt.h5', 'wz')
Пример #5
0
def create_wz_reweights(edges, args):
    """ 
    Calculates correct weighting ratio for pt from histogram files. Then applies this to each dataset
    """
    out_dir = args.out_dir
    with File('%s/jetpt.h5' % out_dir, 'r') as h5file:
        num = h5file['dijet']['hist']
        denom = h5file['wz']['hist']
        ratio = np.zeros_like(num)
        valid = np.asarray(denom) > 0.0
        ratio[valid] = num[valid] / denom[valid]  # This is the ratio I need
    for ds in args.datasets:
        dsid = get_dsid(ds)
        if not is_wz(dsid):
            continue
        create_reweights_from_ratio(ds, edges, ratio)
Пример #6
0
def build_summary_dataset(datasets, args):
    with open(args.denominator, 'r') as denom_file:
        denom = get_denom_dict(denom_file)
    with open(args.cross_sections, 'r') as xsec_file:
        xsecs = CrossSections(xsec_file, denom)

    samples = defaultdict(lambda: defaultdict(list))
    for ds_name in datasets:
        dsid = get_dsid(ds_name)
        if is_dijet(dsid):
            if xsecs.datasets[dsid]['denominator'] == 0:
                continue
            sample, total_entries = sample_slice(ds_name, args.sample_size)
            upweight = total_entries / sample['fat_jet'].shape[0]
            weight = xsecs.get_weight(dsid) * upweight
            sample['fat_jet']['mcEventWeight'] *= weight
            for object_name, obj in sample.items():
                samples['dijet'][object_name].append(obj)
        elif is_dihiggs(dsid):
            sample, total_entries = sample_slice(ds_name, args.sample_size)
            upweight = total_entries / sample['fat_jet'].shape[0]
            pt = sample['fat_jet']['pt']
            ratio, edges = get_ratio(args.ratio_dir)
            indices = np.digitize(pt, edges) - 1
            weight = ratio[indices] * upweight
            sample['fat_jet']['mcEventWeight'] = weight
            for object_name, obj in sample.items():
                samples['higgs'][object_name].append(obj)
        else:
            print(f'skipping {dsid}!')
            continue

    # merge things
    merged_samples = defaultdict(dict)
    for phys_proc_name, obj_dict in samples.items():
        for obj_name, samp_list in obj_dict.items():
            merged = np.concatenate(samp_list, 0)
            merged_samples[phys_proc_name][obj_name] = merged

    if args.plots_dir:
        draw_hist(merged_samples, ['higgs', 'dijet'], args.plots_dir)