for path, subdirs, histos in layout_file.walk(class_pattern='TH1F'): # Skip folders w/o histograms if not histos: continue for histo in histos: key = [ x for x in path.split('/') if x != 'all' and x != 'pass' ] + [histo] keys_to_plot.append(tuple(key)) for key in keys_to_plot: path = os.path.join(*key) sys.stdout.write("Fake rates for %s\n" % path) for sample, sample_info in data_views.iteritems(): num_view = views.PathModifierView(sample_info['unweighted_view'], make_path_mangler('pass')) all_view = views.PathModifierView(sample_info['unweighted_view'], make_path_mangler('all')) num_entries = num_view.Get(path).Integral() all_entries = all_view.Get(path).Integral() eff, eff_down, eff_up = 0, 0, 0 if all_entries: eff, eff_down, eff_up = efficiency(num_entries, all_entries) eff, eff_down, eff_up = (eff * 100, 100 * eff_down, 100 * eff_up) sys.stdout.write( "%s: %i/%i = %0.2f%% +%0.2f -%0.2f\n" % (sample, num_entries, all_entries, eff, eff_up, eff_down))
for path, subdirs, histos in layout_file.walk(class_pattern='TH1F'): # Skip folders w/o histograms if not histos: continue for histo in histos: key = [ x for x in path.split('/') if x != 'all' and x != 'pass' ] + [ histo ] keys_to_plot.append(tuple(key)) for key in keys_to_plot: path = os.path.join(*key) sys.stdout.write("Fake rates for %s\n" % path) for sample, sample_info in data_views.iteritems(): num_view = views.PathModifierView( sample_info['unweighted_view'], make_path_mangler('pass')) all_view = views.PathModifierView( sample_info['unweighted_view'], make_path_mangler('all')) num_entries = num_view.Get(path).Integral() all_entries = all_view.Get(path).Integral() eff, eff_down, eff_up = 0, 0, 0 if all_entries: eff, eff_down, eff_up = efficiency(num_entries, all_entries) eff, eff_down, eff_up = (eff*100, 100*eff_down, 100*eff_up) sys.stdout.write("%s: %i/%i = %0.2f%% +%0.2f -%0.2f\n" % ( sample, num_entries, all_entries, eff, eff_up, eff_down))
if not file: sys.stderr.write("Can't open file: %s\n" % args.file) sys.exit(2) histo = file.Get(args.path) if not histo: sys.stderr.write("Can't get histogram: %s\n" % args.path) sys.exit(3) total = 0 below_below = 0 below_above = 0 if histo.GetEntries(): total = histo.GetIntegral()[histo.GetNbinsX() + 1] below_above = 0 if args.above: below_above = histo.GetIntegral()[histo.FindBin(args.above)] below_below = 1 if args.below: below_below = histo.GetIntegral()[histo.FindBin(args.below)] passed = total - (below_above) * total - (1 - below_below) * total eff, up, down = efficiency(passed, total) sys.stdout.write("%s: %i/%i = %0.2g +%0.2g -%0.2g\n" % (a_file, int(passed), int(total), eff, up, down))
sys.exit(2) histo = file.Get(args.path) if not histo: sys.stderr.write("Can't get histogram: %s\n" % args.path) sys.exit(3) total = 0 below_below = 0 below_above = 0 if histo.GetEntries(): total = histo.GetIntegral()[histo.GetNbinsX()+1] below_above = 0 if args.above: below_above = histo.GetIntegral()[ histo.FindBin(args.above)] below_below = 1 if args.below: below_below = histo.GetIntegral()[ histo.FindBin(args.below)] passed = total - (below_above)*total- (1-below_below)*total eff, up, down = efficiency(passed, total) sys.stdout.write("%s: %i/%i = %0.2g +%0.2g -%0.2g\n" % ( a_file, int(passed), int(total), eff, up, down))