Ejemplo n.º 1
0
 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'))
Ejemplo n.º 2
0
    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'))
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
    # get tree and perform branch name mappings if necessary
    factory.AddSignalTree(tree_s, 1.0)
    factory.AddBackgroundTree(tree_b, 1.0)

    # apply event weights if necessary
    if session.bkgwt:
        factory.SetBackgroundWeightExpression(session.bkgwt)
    if session.sigwt:
        # FIXME: correct weights for ignored events, since sweights:
        # MVA weight = sw - (∑sw(M<5310 && M>5430))/entries(M<5310 && M>5430)
        factory.SetSignalWeightExpression(session.sigwt)

    # selection cuts, if any
    session.training_opts += ['!V']
    factory.PrepareTrainingAndTestTree(ROOT.TCut(''),
                                       ':'.join(session.training_opts))

    # book methods
    map(lambda method: factory.BookMethod(TMVAType(method), method, '!H:!V:' +
                                          ':'.join(getattr(session, method))),
        session.methods)

    # train, test, evaluate
    factory.TrainAllMethods()
    factory.TestAllMethods()
    factory.EvaluateAllMethods()
    ofile.Close()

    print '::: Training MVAs done!'
Ejemplo n.º 5
0
def get_estimate(mva, cut, tree=tree):
    cut = ROOT.TCut('{}>{}'.format(mva, cut))
    # NOTE: only process 200,000 entries
    tree.Draw('{0}>>h{0}'.format(mva), cut, 'goff', options.maxentries)
    hist = ROOT.gDirectory.Get('h{}'.format(mva))
    return hist.GetEntries()
Ejemplo n.º 6
0
 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'))
Ejemplo n.º 7
0
 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'))
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 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'))