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') # files
if options.tree: tree = options.tree else: tree = 'TestTree' if options.istmva else 'DecayTree' rfile = ROOT.TFile.Open(options.rfile, 'read') tree = rfile.Get(tree) # sig, bkg, and other cuts if istmva: sig, bkg = 'classID=={}'.format(0), 'classID=={}'.format(1) # TMVA nbkg = float(tree.GetEntries(bkg)) nsig = float(tree.GetEntries(sig)) elif ismc: from tmvaconfig import ConfigFile conf = ConfigFile(options.conf) if conf.read() > 0: session = conf.get_session_config(options.session) else: sys.exit('No sesions found!') sig = session.cut_sig nsig = float(tree.GetEntries(sig)) else: # isdata ispion = 'lab1_PIDK<-5' # ~ s + b(w/ π) (FIXME: update range) region1 = '5300<lab0_MM && lab0_MM<5445 && {}'.format(ispion) # ~ b region2 = '5445<lab0_MM && lab0_MM<5800' # ~ b(w/ π) region3 = '5445<lab0_MM && lab0_MM<5800 && {}'.format(ispion) nregion1 = float(tree.GetEntries(region1)) nregion2 = float(tree.GetEntries(region2))
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)
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] # per-variable efficiency histograms, ranges, and titles
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)
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')