class test_Tsplice(unittest.TestCase): def setUp(self): self.rfile = ROOT.TFile.Open('/tmp/testtree.root') self.tree = self.rfile.Get('testtree') self.nentries = self.tree.GetEntries() # total no of elements in data self.ndata = nplotted(self.tree, 'data') self.splice = Tsplice(self.tree) def tearDown(self): self.rfile.Close() def test_get_entries(self): tree = self.splice.make_splice('sz_gt_3', ROOT.TCut('sz>3')) # 2/3 self.assertEqual(self.splice.get_entries(), nplotted(tree, 'sz')) def test_reset(self): self.splice.make_splice('sz_gt_5', ROOT.TCut('sz>5')) # zero self.assertEqual(nplotted(self.splice.reset(), 'sz'), self.nentries) def test_make_splice(self): cut = ROOT.TCut('foo>10') nexpected = nplotted(self.splice.reset(), 'foo', cut) tree = self.splice.make_splice('foo_gt_10', cut) self.assertEqual(nexpected, nplotted(tree, 'foo')) cut = ROOT.TCut('bar<0') nexpected = nplotted(self.splice.reset(), 'bar', cut) tree = self.splice.make_splice('nve_bar', cut) self.assertEqual(nexpected, nplotted(tree, 'bar')) def test_set_splice(self): cut = ROOT.TCut('bar>0') self.splice.make_splice('pve_bar', cut) nexpected = nplotted(self.splice.reset(), 'bar', cut) tree = self.splice.set_splice(self.splice.elists['pve_bar']) self.assertEqual(nexpected, nplotted(tree, 'bar')) def test_get_splice(self): cut = ROOT.TCut('sz==4') self.splice.make_splice('sz_eq_4', cut) nexpected = nplotted(self.splice.reset(), 'sz', cut) tree = self.splice.get_splice('sz_eq_4') self.assertEqual(nexpected, nplotted(tree, 'sz')) def test_elistarray_splice(self): # entries with 5 elements in data are guaranteed to pass, for # other entries, it passes when the passing element is < size, # which happens 3/5 times (when it is b/w 0-2), it is always # found for size = 5. Therefore, it is found for at least 4/5 # entries. cut = ROOT.TCut('(data[]%5)>3') tree = self.splice.make_splice('data_mod_5', cut, listtype='entrylistarray') expected = nplotted(tree, 'data') # print self.ndata, self.nentries, expected, 4*self.nentries/5 self.assertLess(expected, self.ndata) self.assertLess(expected, self.nentries) self.assertGreater(expected, 4 * self.nentries / 5) def test_append(self): """Also tests layered=False""" cut = ROOT.TCut('bar<0') self.splice.make_splice('bar', cut) cut = ROOT.TCut('bar>=0') # this should add the rest of the entries tree = self.splice.make_splice('bar', cut, append=True) self.assertEqual(self.nentries, nplotted(tree, 'bar')) def test_layered(self): splice = Tsplice(self.splice.reset(), layered=True) splice.make_splice('pos_bar', 'bar>0') tree = splice.make_splice('data_gt_500', 'data>500') self.assertLess(nplotted(tree, 'bar'), 0.5 * self.nentries)
class test_Tsplice(unittest.TestCase): def setUp(self): self.rfile = ROOT.TFile.Open('/tmp/testtree.root') self.tree = self.rfile.Get('testtree') self.nentries = self.tree.GetEntries() # total no of elements in data self.ndata = nplotted(self.tree, 'data') self.splice = Tsplice(self.tree) def tearDown(self): self.rfile.Close() def test_get_entries(self): tree = self.splice.make_splice('sz_gt_3', ROOT.TCut('sz>3')) # 2/3 self.assertEqual(self.splice.get_entries(), nplotted(tree, 'sz')) def test_reset(self): self.splice.make_splice('sz_gt_5', ROOT.TCut('sz>5')) # zero self.assertEqual(nplotted(self.splice.reset(), 'sz'), self.nentries) def test_make_splice(self): cut = ROOT.TCut('foo>10') nexpected = nplotted(self.splice.reset(), 'foo', cut) tree = self.splice.make_splice('foo_gt_10', cut) self.assertEqual(nexpected, nplotted(tree, 'foo')) cut = ROOT.TCut('bar<0') nexpected = nplotted(self.splice.reset(), 'bar', cut) tree = self.splice.make_splice('nve_bar', cut) self.assertEqual(nexpected, nplotted(tree, 'bar')) def test_set_splice(self): cut = ROOT.TCut('bar>0') self.splice.make_splice('pve_bar', cut) nexpected = nplotted(self.splice.reset(), 'bar', cut) tree = self.splice.set_splice(self.splice.elists['pve_bar']) self.assertEqual(nexpected, nplotted(tree, 'bar')) def test_get_splice(self): cut = ROOT.TCut('sz==4') self.splice.make_splice('sz_eq_4', cut) nexpected = nplotted(self.splice.reset(), 'sz', cut) tree = self.splice.get_splice('sz_eq_4') self.assertEqual(nexpected, nplotted(tree, 'sz')) def test_elistarray_splice(self): # entries with 5 elements in data are guaranteed to pass, for # other entries, it passes when the passing element is < size, # which happens 3/5 times (when it is b/w 0-2), it is always # found for size = 5. Therefore, it is found for at least 4/5 # entries. cut = ROOT.TCut('(data[]%5)>3') tree = self.splice.make_splice('data_mod_5', cut, listtype='entrylistarray') expected = nplotted(tree, 'data') # print self.ndata, self.nentries, expected, 4*self.nentries/5 self.assertLess(expected, self.ndata) self.assertLess(expected, self.nentries) self.assertGreater(expected, 4*self.nentries/5) def test_append(self): """Also tests layered=False""" cut = ROOT.TCut('bar<0') self.splice.make_splice('bar', cut) cut = ROOT.TCut('bar>=0') # this should add the rest of the entries tree = self.splice.make_splice('bar', cut, append=True) self.assertEqual(self.nentries, nplotted(tree, 'bar')) def test_layered(self): splice = Tsplice(self.splice.reset(), layered=True) splice.make_splice('pos_bar', 'bar>0') tree = splice.make_splice('data_gt_500', 'data>500') self.assertLess(nplotted(tree, 'bar'), 0.5*self.nentries)
def test_layered(self): splice = Tsplice(self.splice.reset(), layered=True) splice.make_splice('pos_bar', 'bar>0') tree = splice.make_splice('data_gt_500', 'data>500') self.assertLess(nplotted(tree, 'bar'), 0.5 * self.nentries)
def test_layered(self): splice = Tsplice(self.splice.reset(), layered=True) splice.make_splice('pos_bar', 'bar>0') tree = splice.make_splice('data_gt_500', 'data>500') self.assertLess(nplotted(tree, 'bar'), 0.5*self.nentries)