Esempio n. 1
0
 def test_gen_load(self):
     aliases = gen.fs_content()
     zjets_cutflow = gen.filter(aliases, {
         "name": "cutflow",
         "sample": "zjets"
     })
     wrp = gen.load(zjets_cutflow).next()
     self.assertTrue(isinstance(wrp.histo, TH1F))
     self.assertAlmostEqual(wrp.histo.Integral(), 2889.0)
def gen_mixer_input(input_dict):
        for d in input_dict:
            yield   op.norm_to_integral(
                    op.merge(
                    list(
                    gen.load(
                    gen.filter(
                    gen.fs_content(),
                    d
                    )))))
Esempio n. 3
0
 def test_gen_sort(self):
     aliases = list(gen.fs_content())
     tmplt = gen.filter(aliases, {"analyzer": "fakeTemplate"})
     sorted = list(gen.sort(tmplt))
     s_name = map(lambda x: x.name, sorted)
     s_sample = map(lambda x: x.sample, sorted)
     s_is_data = map(lambda x: x.is_data, sorted)
     self.assertTrue(s_sample.index("ttgamma") < s_sample.index("zjets"))
     self.assertTrue(s_name.index("sihihEB") < s_name.index("sihihEE"))
     self.assertTrue(s_is_data.index(False) < s_is_data.index(True))
Esempio n. 4
0
 def test_gen_sort(self):
     aliases = list(gen.fs_content())
     tmplt = gen.filter(aliases, {"analyzer": "fakeTemplate"})
     sorted = list(gen.sort(tmplt))
     s_name = map(lambda x: x.name, sorted)
     s_sample = map(lambda x: x.sample, sorted)
     s_is_data = map(lambda x: x.is_data, sorted)
     self.assertTrue(s_sample.index("ttgamma") < s_sample.index("zjets"))
     self.assertTrue(s_name.index("sihihEB") < s_name.index("sihihEE"))
     self.assertTrue(s_is_data.index(False) < s_is_data.index(True))
Esempio n. 5
0
    def test_gen_filter(self):
        import re

        aliases = list(gen.fs_content())
        data = gen.filter(aliases, {"is_data": True})
        tmplt = gen.filter(aliases, {"analyzer": "fakeTemplate"})
        crtlplt = gen.filter(aliases, {"analyzer": re.compile("CrtlFilt*")})
        crtlplt2 = gen.filter(aliases, {"analyzer": [re.compile("CrtlFilt*")]})
        ttgam_cf = gen.filter(aliases, {"name": "cutflow", "sample": ["ttgamma", "tt"]})
        self.assertEqual(gen.consume_n_count(data), 52)
        self.assertEqual(gen.consume_n_count(tmplt), 9)
        self.assertEqual(gen.consume_n_count(crtlplt), 39)
        self.assertEqual(gen.consume_n_count(crtlplt2), 39)
        self.assertEqual(gen.consume_n_count(ttgam_cf), 2)
Esempio n. 6
0
    def test_gen_group(self):
        from_fs = gen.fs_content()
        filtered = gen.filter(from_fs, {"name": "histo"})
        sorted = gen.sort(filtered)
        grouped = gen.group(sorted)
        group_list = []
        for group in grouped:
            group_list.append(list(group))

        # length: 3 samples: 3 histos per group
        self.assertEqual(len(group_list), 26)
        for g in group_list:
            self.assertEqual(len(g), 3)
            self.assertEqual(g[0].analyzer, g[1].analyzer)
            self.assertEqual(g[0].analyzer, g[2].analyzer)
Esempio n. 7
0
    def test_gen_group(self):
        from_fs = gen.fs_content()
        filtered = gen.filter(from_fs, {"name": "histo"})
        sorted = gen.sort(filtered)
        grouped = gen.group(sorted)
        group_list = []
        for group in grouped:
            group_list.append(list(group))

        # length: 3 samples: 3 histos per group
        self.assertEqual(len(group_list), 26)
        for g in group_list:
            self.assertEqual(len(g), 3)
            self.assertEqual(g[0].analyzer, g[1].analyzer)
            self.assertEqual(g[0].analyzer, g[2].analyzer)
Esempio n. 8
0
 def test_gen_filter(self):
     import re
     aliases = list(gen.fs_content())
     data = gen.filter(aliases, {"is_data": True})
     tmplt = gen.filter(aliases, {"analyzer": "fakeTemplate"})
     crtlplt = gen.filter(aliases, {"analyzer": re.compile("CrtlFilt*")})
     crtlplt2 = gen.filter(aliases, {"analyzer": [re.compile("CrtlFilt*")]})
     ttgam_cf = gen.filter(aliases, {
         "name": "cutflow",
         "sample": ["ttgamma", "tt"]
     })
     self.assertEqual(gen.consume_n_count(data), 52)
     self.assertEqual(gen.consume_n_count(tmplt), 9)
     self.assertEqual(gen.consume_n_count(crtlplt), 39)
     self.assertEqual(gen.consume_n_count(crtlplt2), 39)
     self.assertEqual(gen.consume_n_count(ttgam_cf), 2)
Esempio n. 9
0
    def run(self):
        wrps = gen.fs_content()
        wrps = gen.filter(
            wrps,
            {"analyzer": re.compile("CutFlow*")}
        )
        wrps = gen.filter_active_samples(wrps)
        wrps = sorted(wrps, key = sample_key_func)
        wrps = gen.load(wrps)
        grps = gen.group(wrps, sample_key_func)

        wrps = (self.combine_cutflow_histo(g) for g in grps)
        wrps = gen.pool_store_items(wrps)
        wrps = list(wrps)
        self.result = wrps
        count = len(wrps)
        self.message("INFO: "+self.name+" stored "+str(count)+" histos in pool.")
Esempio n. 10
0
    def test_gen_special_treat(self):
        sample = ["tt", "zjets"]
        name = "cutflow"

        class TreatCls(object):
            def __init__(self, test):
                self.test = test
                self.n_times_called = 0

            def __call__(self, alias):
                self.n_times_called += 1
                self.test.assertTrue(alias.sample in sample)
                self.test.assertEqual(alias.name, name)

        treat_func = TreatCls(self)
        treated = gen.callback(gen.fs_content(), treat_func, {"sample": sample, "name": name})
        self.assertEqual(gen.consume_n_count(treated), 150)
        self.assertEqual(treat_func.n_times_called, 2)
Esempio n. 11
0
    def test_gen_special_treat(self):
        sample = ["tt", "zjets"]
        name = "cutflow"

        class TreatCls(object):
            def __init__(self, test):
                self.test = test
                self.n_times_called = 0

            def __call__(self, alias):
                self.n_times_called += 1
                self.test.assertTrue(alias.sample in sample)
                self.test.assertEqual(alias.name, name)

        treat_func = TreatCls(self)
        treated = gen.callback(gen.fs_content(), treat_func, {
            "sample": sample,
            "name": name
        })
        self.assertEqual(gen.consume_n_count(treated), 150)
        self.assertEqual(treat_func.n_times_called, 2)
Esempio n. 12
0
 def test_gen_fs_content(self):
     aliases = list(gen.fs_content())
     self.assertEqual(len(aliases), 150)
Esempio n. 13
0
 def test_gen_load(self):
     aliases = gen.fs_content()
     zjets_cutflow = gen.filter(aliases, {"name": "cutflow", "sample": "zjets"})
     wrp = gen.load(zjets_cutflow).next()
     self.assertTrue(isinstance(wrp.histo, TH1F))
     self.assertAlmostEqual(wrp.histo.Integral(), 2889.0)
Esempio n. 14
0
 def test_gen_fs_content(self):
     aliases = list(gen.fs_content())
     self.assertEqual(len(aliases), 150)