def run_higgs_reweighted(edges, args, output_file): hist = 0 parts = {} out_dir = args.out_dir with File(f'{out_dir}/jetpt.h5', '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] if output_file: with File(glob(args.datasets[0] + '/*.h5')[0], 'r') as old_file: out_ds = OutputDataset(output_file, old_file, 'higgs', args.output_fields) else: out_ds = None for ds in args.datasets: dsid = get_dsid(ds) if not is_dihiggs(dsid, restricted=True): continue if args.verbose: print(f'processing {ds} as higgs') this_dsid = get_hist_reweighted(ds, edges, ratio, all_events, out_ds) parts[dsid] = np.array(this_dsid) hist += this_dsid draw_hist(hist, edges, args.out_dir, parts, file_name='higgs_reweight.pdf')
def run_dijet(edges, args, output_file): 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) if output_file: with File(glob(args.datasets[0] + '/*.h5')[0], 'r') as old_file: out_ds = OutputDataset(output_file, old_file, 'dijet', args.output_fields) else: out_ds = None parts = {} hist = 0 for ds in args.datasets: dsid = get_dsid(ds) if not is_dijet(dsid, restricted=True): continue if args.verbose: print(f'processing {ds} as dijet') if xsecs.datasets[dsid]['denominator'] == 0: continue weight = xsecs.get_weight(dsid) this_dsid = get_hist(ds, edges, all_events, out_ds, weight) parts[dsid] = np.array(this_dsid) hist += this_dsid draw_hist(hist, edges, args.out_dir, parts, file_name='dijet.pdf') save_hist(hist, edges, args.out_dir, 'jetpt.h5', 'dijet')
def run(): args = get_args() counts = Counter() for ds in args.datasets: dsid = get_dsid(ds) for fpath in glob(f'{ds}/*.h5'): counts[dsid] += get_counts(fpath, is_dijet=is_dijet(dsid)) if args.out_file: out = open(args.out_file, 'w') else: out = sys.stdout json.dump(dict(counts), out, indent=2)
def get_process(edges, process, args, discriminant, selection): input_hists = args.input_hist_dir hist = 0 for ds in args.datasets: dsid = get_dsid(ds) if not SELECTORS[process](dsid): continue if args.verbose: print(f'running on {ds} as {process}') this_dsid = get_hist_reweighted(ds, edges, f'{input_hists}/jetpt.h5', discriminant, selection) hist += this_dsid return hist
def run_sample(edges, process, args): hist = 0 parts = {} selector = truth_match(EVENT_LABELS[process]) for ds in args.datasets: dsid = get_dsid(ds) if not SELECTORS[process](dsid, restricted=True): continue if args.verbose: print(f'processing {ds} as {process}') this_dsid = get_hist(ds, edges, selector) parts[dsid] = np.array(this_dsid) hist += this_dsid draw_hist(hist, edges, args.out_dir, parts, file_name=f'{process}.pdf') save_hist(hist, edges, args.out_dir, 'jetpt.h5', process)
def get_dijet(edges, args, discriminant=get_mv2, selection=mass_window_higgs): 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) input_hists = args.input_hist_dir hist = 0 for ds in args.datasets: dsid = get_dsid(ds) if not is_dijet(dsid, restricted=True): continue if xsecs.datasets[dsid]['denominator'] == 0: continue if args.verbose: print(f'running on {ds}') weight = xsecs.get_weight(dsid) this_dsid = get_hist_reweighted(ds, edges, f'{input_hists}/jetpt.h5', discriminant, selection) * weight hist += this_dsid return hist