def test_sorted(): bins = [40, 60, 80, 99, 111] unsorted_bins = [80, 99, 111, 40, 60] b = binning.Sorted(bins, 'test') assert b.bins == bins b = binning.Sorted(unsorted_bins, 'test') assert b.bins == bins
def create_histograms(self, online_title, pileup_bins, n_bins, low, high, legend_title=""): """ This is not in an init function so that we can by-pass this in the case where we reload things from disk """ self.online_title = online_title self.pileup_bins = bn.Sorted(pileup_bins, "pileup", use_everything_bin=True) self.legend_title = legend_title name = ["rate_vs_threshold", self.online_name, "pu_{pileup}"] name = "__".join(name) title = " ".join([self.online_name, "vs.", "in PU bin: {pileup}"]) title = ";".join([title, self.online_title]) self.plots = HistogramCollection([self.pileup_bins], "Hist1D", n_bins, low, high, name=name, title=title) self.filename_format = name
def create_histograms( self, online_title, offline_title, versus_title, pileup_bins, res_n_bins, res_low, res_high, vs_n_bins, vs_low, vs_high): """ This is not in an init function so that we can by-pass this in the case where we reload things from disk """ self.online_title = online_title self.offline_title = offline_title self.versus_title = versus_title self.ymin = res_low self.ymax = res_high self.pileup_bins = bn.Sorted(pileup_bins, "pileup", use_everything_bin=True) nameTokens = [ "resolution_vs", self.versus_name, self.online_name, self.offline_name, "pu_{pileup}", ] name = "__".join(nameTokens) title = 'Resolution ({online_name} vs. {offline_name}) ' title += 'against {versus_name}' title = title.format( online_name=self.online_name, offline_name=self.offline_name, versus_name=self.versus_name, ) title += " in PU bin: {pileup}" title = ";".join([title, self.offline_title, self.online_title]) self.plots = HistogramCollection( [self.pileup_bins], "Hist2D", vs_n_bins, vs_low, vs_high, res_n_bins, res_low, res_high, name=name, title=title) self.filename_format = name
def create_histograms( self, online_title, offline_title, pileup_bins, n_bins, low, high=400., ): """ This is not in an init function so that we can by-pass this in the case where we reload things from disk """ self.online_title = online_title self.offline_title = offline_title self.pileup_bins = bn.Sorted( pileup_bins, "pileup", use_everything_bin=True, ) nameTokens = [ "onlineVsOffline", self.online_name, self.offline_name, "pu_{pileup}", ] name = "__".join(nameTokens) title = " ".join([ self.online_name, "vs.", self.offline_name, "in PU bin: {pileup}", ]) title = ";".join([title, self.offline_title, self.online_title]) if isinstance(low, np.ndarray): self.plots = HistogramCollection( [self.pileup_bins], "Hist2D", low, low, name=name, title=title, ) else: self.plots = HistogramCollection( [self.pileup_bins], "Hist2D", n_bins, low, high, n_bins, low, high, name=name, title=title, ) self.filename_format = name
def test_get_bin_edges(): bins = [40, 60, 80, 99, 111] b = binning.Sorted(bins, 'test') assert b.get_bin_upper(2) == bins[3] assert b.get_bin_lower(2) == bins[2] assert b.get_bin_lower(binning.Base.underflow) == binning.Base.underflow assert b.get_bin_lower(binning.Base.overflow) == binning.Base.overflow assert b.get_bin_lower(binning.Base.everything) == binning.Base.everything
def create_histograms(self, online_title, offline_title, pileup_bins, thresholds, n_bins, low, high=400, legend_title=""): """ This is not in an init function so that we can by-pass this in the case where we reload things from disk """ self.online_title = online_title self.offline_title = offline_title self.pileup_bins = bn.Sorted(pileup_bins, "pileup", use_everything_bin=True) self.thresholds = bn.GreaterThan(thresholds, "threshold") self.legend_title = legend_title name = ["efficiency", self.online_name, self.offline_name] name += ["thresh_{threshold}", "pu_{pileup}"] name = "__".join(name) title = " ".join([ self.online_name, " in PU bin: {pileup}", "and passing threshold: {threshold}" ]) self.filename_format = name def make_efficiency(labels): this_name = "efficiency" + name.format(**labels) this_title = title.format(**labels) '''Checking type of 'low' to see whether it's int (x-range minimum) or array (bin edges) for constructing TEfficiency''' if isinstance(low, np.ndarray): eff = asrootpy( ROOT.TEfficiency(this_name, this_title, n_bins, low)) self.x_max = 2000 else: eff = asrootpy( ROOT.TEfficiency(this_name, this_title, n_bins, low, high)) self.x_max = high eff.drawstyle = EfficiencyPlot.drawstyle return eff self.efficiencies = HistogramCollection( [self.pileup_bins, self.thresholds], make_efficiency)
from __future__ import print_function from nose.tools import assert_equal import cmsl1t.hist.hist_collection as hist import cmsl1t.hist.binning as binning import numpy as np from cmsl1t.hist.factory import HistFactory pileup = binning.Sorted([0, 10, 15, 20, 30, 999], "pileup") multi = binning.Overlapped([(0, 10), (100, 110), (5, 15)], "multi") regions = binning.EtaRegions() class dummy_factory(): instance_count = 0 def __init__(self, *vargs, **kwargs): dummy_factory.instance_count += 1 self.count = 0 self.value = 0 self.bin_labels = vargs def __call__(self): print("making histogram:", dummy_factory.instance_count, self.count) self.count += 1 def fill(self, weight=1): self.value += weight def test_dimension_sorted(): assert_equal(pileup.find_bins(-19), [binning.Base.underflow])