示例#1
0
optparser.add_argument('--cvars', action='store_true', default=False,
                       help='Combined variables')
group = optparser.add_mutually_exclusive_group()
group.add_argument('--cuts_both', action='store_true', default=False,
                   help='Cuts common to both signal & background')
group.add_argument('--cuts_bkg', action='store_true', help='Background only cuts')
group.add_argument('--cuts_sig', action='store_true', help='Signal only cuts')
opts = optparser.parse_args()

import sys
import os
if not os.path.exists(opts.conf):
    sys.exit('File not found: {}'.format(opts.conf))

from tmvaconfig import ConfigFile
conf = ConfigFile(opts.conf)
n = conf.read()

# filter out when not a match or invalid
sessions = filter(lambda s: is_match(s, opts.sessions), conf.sessions())

if not sessions:
    sys.exit('No matching sessions!')
print ' '.join(sessions)

if not (opts.cvars or opts.nvars or opts.cuts_both or opts.cuts_sig
        or opts.cuts_bkg):
    sys.exit(0)

# helper
one_per_line = lambda i: '\n'.join(i)
示例#2
0
optparser = argparse.ArgumentParser(formatter_class=RawArgDefaultFormatter,
                                    description=__doc__)
optparser.add_argument('filename', help='Input ROOT file')
optparser.add_argument('-s', '--session', required=True, help='Session name')
optparser.add_argument('-o', '--out', required=True, help='Output ROOT file')
optparser.add_argument('-n', '--name', required=True, help='Input tree name')
options = optparser.parse_args()

import sys
import os
if not os.path.exists(options.filename):
    sys.exit('File not found: {}'.format(options.filename))

from tmvaconfig import ConfigFile
conf = ConfigFile('TMVA.conf')
if conf.read() > 0:             # read config
    session = conf.get_session_config(options.session)
print '::: Applying {} MVAs: {}\n{}'.format(len(session.methods),
                                            session.methods, '='*50)
print session
print ':::'

from fixes import ROOT
ROOT.gROOT.SetBatch(True)

# instantiate TMVA
ROOT.TMVA.Tools.Instance()
# reader
reader = ROOT.TMVA.Reader('!Color:!Silent')
示例#3
0
from fixes import ROOT
ROOT.gROOT.SetBatch(batch)
ROOT.gStyle.SetOptTitle(title)


## read signal and background trees, define cuts
from ROOT import TFile
if istmva:             # TMVA output
    rfile = TFile.Open(filename, 'read')
    tree = rfile.Get(tree)
    istmva = 'classID=={}'.format(int(bkgeff))
else:
    rfile = TFile.Open(filename, 'read')
    tree = rfile.Get(tree)
    from tmvaconfig import ConfigFile
    conf = ConfigFile(conf)
    if conf.read() > 0:
        session = conf.get_session_config(session)
        if not session:
            sys.exit('No matching sessions found')
    else:
        sys.exit('No sesions found!')
    istmva = str(session.cut_bkg if bkgeff else session.cut_sig)

# common cuts
truthmatch = 'abs(lab0_TRUEID) == 531' if truthmatch else ''
refcut = '{}&&{}'.format(truthmatch, istmva)

# classifier cuts
mva_cuts = [0.1*i for i in intervals]
示例#4
0
                   default=False,
                   help='Cuts common to both signal & background')
group.add_argument('--cuts_bkg',
                   action='store_true',
                   help='Background only cuts')
group.add_argument('--cuts_sig', action='store_true', help='Signal only cuts')
opts = optparser.parse_args()

import sys
import os
if not os.path.exists(opts.conf):
    sys.exit('File not found: {}'.format(opts.conf))

from tmvaconfig import ConfigFile

conf = ConfigFile(opts.conf)
n = conf.read()

# filter out when not a match or invalid
sessions = filter(lambda s: is_match(s, opts.sessions), conf.sessions())

if not sessions:
    sys.exit('No matching sessions!')
print ' '.join(sessions)

if not (opts.cvars or opts.nvars or opts.cuts_both or opts.cuts_sig
        or opts.cuts_bkg):
    sys.exit(0)

# helper
one_per_line = lambda i: '\n'.join(i)
示例#5
0
optparser = argparse.ArgumentParser(formatter_class=RawArgDefaultFormatter,
                                    description=__doc__)
optparser.add_argument('filename', help='Input ROOT file')
optparser.add_argument('-s', '--session', required=True, help='Session name')
optparser.add_argument('-o', '--out', required=True, help='Output ROOT file')
optparser.add_argument('-n', '--name', required=True, help='Input tree name')
options = optparser.parse_args()

import sys
import os
if not os.path.exists(options.filename):
    sys.exit('File not found: {}'.format(options.filename))

from tmvaconfig import ConfigFile

conf = ConfigFile('TMVA.conf')
if conf.read() > 0:  # read config
    session = conf.get_session_config(options.session)
print '::: Applying {} MVAs: {}\n{}'.format(len(session.methods),
                                            session.methods, '=' * 50)
print session
print ':::'

from fixes import ROOT

ROOT.gROOT.SetBatch(True)

# instantiate TMVA
ROOT.TMVA.Tools.Instance()
# reader
reader = ROOT.TMVA.Reader('!Color:!Silent')
示例#6
0
import argparse
from utils import _import_args

optparser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
                                    description=__doc__)
optparser.add_argument('conffile', nargs='?', default='TMVA.conf', help='TMVA config file')
optparser.add_argument('-s', dest='session', help='Session name (maybe glob)')
options = optparser.parse_args()
locals().update(_import_args(options))

import sys, os
if conffile and not os.path.exists(conffile):
    sys.exit('File not found: {}'.format(conffile))

from tmvaconfig import TMVAType, TMVAconfig, ConfigFile
conf = ConfigFile(conffile)
n = conf.read()

print '# sessions'
# print all sessions
if not session:
    for s in conf.sessions():
        print s,
    sys.exit(0)

# find requested session
if reduce(lambda i,j: i or j, map(lambda x: x in session, '*?')): # glob
    from fnmatch import fnmatchcase
    for s in conf.sessions():
        if fnmatchcase(s, session): print s,
else:                           # exact
示例#7
0
optparser.add_argument('--bkgtree', default='BkgTree',
                       help='Background tree name')
optparser.add_argument('-o', dest='out', required=True, help='Output file')
optparser.add_argument('-c', dest='conf', default='TMVA.conf',
                       help='TMVA config file')
optparser.add_argument('-n', dest='norm', action='store_true',
                       help='Normalise (ensure similar order) sample sizes')
options = optparser.parse_args()

# variables for future proofing
wdir = 'weights'                # weights directory

import sys
from tmvaconfig import TMVAType, ConfigFile
# read config
conf = ConfigFile(options.conf)
if conf.read() > 0:
    session = conf.get_session_config(options.session)
else:
    sys.exit('No usable sessions in config file')
if not session:
    sys.exit('Couldn\'t find session in config file')
print '::: Training {} MVAs: {}\n{}'.format(len(session.methods),
                                            session.methods, '='*50)
print session
print ':::'

from fixes import ROOT
ROOT.gROOT.SetBatch(True)

# files & trees