Exemplo n.º 1
0
    def __init__(self, options, **kwargs):

        super(c3po, self).__init__(**kwargs)
        parser = ArgumentParser()
        parser.add_argument('--syst-terms', default=None)
        parser.add_argument('--no-trigger', action='store_true', default=False)
        parser.add_argument('--no-grl', action='store_true', default=False)
        self.args = parser.parse_args(options)
        if self.args.syst_terms is not None:
            self.args.syst_terms = set([
                eval('Systematics.%s' % term) for term in
                self.args.syst_terms.split(',')])
Exemplo n.º 2
0
    def __init__(self, options, **kwargs):

        super(C3POProcessor, self).__init__(**kwargs)
        parser = ArgumentParser()
        parser.add_argument('--student-verbose',
            dest='verbose',
            action='store_true', default=False)
        parser.add_argument('--syst-terms', default=None)
        self.args = parser.parse_args(options)
        if self.args.syst_terms is not None:
            self.args.syst_terms = set([
                eval('Systematics.%s' % term) for term in
                self.args.syst_terms.split(',')])
Exemplo n.º 3
0
def main():

    import rootpy
    from rootpy.extern.argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, RawTextHelpFormatter

    class formatter_class(ArgumentDefaultsHelpFormatter, RawTextHelpFormatter):
        pass

    parser = ArgumentParser(
        formatter_class=formatter_class,
        description="Convert ROOT files containing TTrees into HDF5 files " "containing HDF5 tables",
    )
    parser.add_argument(
        "--version", action="version", version=rootpy.__version__, help="show the version number and exit"
    )
    parser.add_argument("-n", "--entries", type=int, default=100000, help="number of entries to read at once")
    parser.add_argument("-f", "--force", action="store_true", default=False, help="overwrite existing output files")
    parser.add_argument("-u", "--update", action="store_true", default=False, help="update existing output files")
    parser.add_argument("--ext", default="h5", help="output file extension")
    parser.add_argument("-c", "--complevel", type=int, default=5, choices=range(0, 10), help="compression level")
    parser.add_argument(
        "-l", "--complib", default="zlib", choices=("zlib", "lzo", "bzip2", "blosc"), help="compression algorithm"
    )
    parser.add_argument(
        "-s", "--selection", default=None, help="apply a selection on each " "tree with a cut expression"
    )
    parser.add_argument(
        "--script",
        default=None,
        help="Python script containing a function with the same name \n"
        "that will be called on each tree and must return a tree or \n"
        "list of trees that will be converted instead of the \n"
        "original tree",
    )
    parser.add_argument("-q", "--quiet", action="store_true", default=False, help="suppress all warnings")
    parser.add_argument("--no-progress-bar", action="store_true", default=False, help="do not show the progress bar")
    parser.add_argument("files", nargs="+")
    args = parser.parse_args()

    rootpy.log.basic_config_colorized()
    import logging

    if hasattr(logging, "captureWarnings"):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip(".")

    if args.quiet:
        warnings.simplefilter("ignore", RootNumpyUnconvertibleWarning)
        warnings.simplefilter("ignore", tables.NaturalNameWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, "exec"), globals(), locals())
        except IOError:
            sys.exit("Could not open script {0}".format(args.script))
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit("Could not find the function '{0}' in the script {1}".format(funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + "." + args.ext
        if os.path.exists(outputname) and not (args.force or args.update):
            sys.exit("Output {0} already exists. " "Use the --force option to overwrite it".format(outputname))
        try:
            rootfile = root_open(inputname)
        except IOError:
            sys.exit("Could not open {0}".format(inputname))
        try:
            if args.complevel > 0:
                filters = tables.Filters(complib=args.complib, complevel=args.complevel)
            else:
                filters = None
            hd5file = tables_open(filename=outputname, mode="a" if args.update else "w", title="Data", filters=filters)
        except IOError:
            sys.exit("Could not create {0}".format(outputname))
        try:
            log.info("Converting {0} ...".format(inputname))
            root2hdf5(
                rootfile,
                hd5file,
                entries=args.entries,
                userfunc=userfunc,
                selection=args.selection,
                show_progress=not args.no_progress_bar,
            )
            log.info("Created {0}".format(outputname))
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            os.unlink(outputname)
            break
        finally:
            hd5file.close()
            rootfile.Close()
Exemplo n.º 4
0
def main():

    import rootpy
    from rootpy.extern.argparse import (ArgumentParser,
                                        ArgumentDefaultsHelpFormatter,
                                        RawTextHelpFormatter)

    class formatter_class(ArgumentDefaultsHelpFormatter, RawTextHelpFormatter):
        pass

    parser = ArgumentParser(
        formatter_class=formatter_class,
        description="Convert ROOT files containing TTrees into HDF5 files "
        "containing HDF5 tables")
    parser.add_argument('--version',
                        action='version',
                        version=rootpy.__version__,
                        help="show the version number and exit")
    parser.add_argument('-n',
                        '--entries',
                        type=int,
                        default=100000,
                        help="number of entries to read at once")
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        default=False,
                        help="overwrite existing output files")
    parser.add_argument('-u',
                        '--update',
                        action='store_true',
                        default=False,
                        help="update existing output files")
    parser.add_argument('--ext', default='h5', help="output file extension")
    parser.add_argument('-c',
                        '--complevel',
                        type=int,
                        default=5,
                        choices=range(0, 10),
                        help="compression level")
    parser.add_argument('-l',
                        '--complib',
                        default='zlib',
                        choices=('zlib', 'lzo', 'bzip2', 'blosc'),
                        help="compression algorithm")
    parser.add_argument('-s',
                        '--selection',
                        default=None,
                        help="apply a selection on each "
                        "tree with a cut expression")
    parser.add_argument(
        '--script',
        default=None,
        help="Python script containing a function with the same name \n"
        "that will be called on each tree and must return a tree or \n"
        "list of trees that will be converted instead of the \n"
        "original tree")
    parser.add_argument('-q',
                        '--quiet',
                        action='store_true',
                        default=False,
                        help="suppress all warnings")
    parser.add_argument('-d',
                        '--debug',
                        action='store_true',
                        default=False,
                        help="show stack trace in the event of "
                        "an uncaught exception")
    parser.add_argument('--no-progress-bar',
                        action='store_true',
                        default=False,
                        help="do not show the progress bar")
    parser.add_argument('--ignore-exception',
                        action='store_true',
                        default=False,
                        help="ignore exceptions raised in converting trees "
                        "and instead skip such trees")
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    rootpy.log.basic_config_colorized()
    import logging
    if hasattr(logging, 'captureWarnings'):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip('.')

    if args.quiet:
        warnings.simplefilter("ignore", RootNumpyUnconvertibleWarning)
        warnings.simplefilter("ignore", tables.NaturalNameWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, 'exec'),
                 globals(), locals())
        except IOError:
            sys.exit('Could not open script {0}'.format(args.script))
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit(
                "Could not find the function '{0}' in the script {1}".format(
                    funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + '.' + args.ext
        output_exists = os.path.exists(outputname)
        if output_exists and not (args.force or args.update):
            sys.exit(
                "Output {0} already exists. "
                "Use the --force option to overwrite it".format(outputname))
        try:
            rootfile = root_open(inputname)
        except IOError:
            sys.exit("Could not open {0}".format(inputname))
        try:
            if args.complevel > 0:
                filters = tables.Filters(complib=args.complib,
                                         complevel=args.complevel)
            else:
                filters = None
            hd5file = tables_open(filename=outputname,
                                  mode='a' if args.update else 'w',
                                  title='Data',
                                  filters=filters)
        except IOError:
            sys.exit("Could not create {0}".format(outputname))
        try:
            log.info("Converting {0} ...".format(inputname))
            root2hdf5(rootfile,
                      hd5file,
                      entries=args.entries,
                      userfunc=userfunc,
                      selection=args.selection,
                      show_progress=not args.no_progress_bar,
                      ignore_exception=args.ignore_exception)
            log.info("{0} {1}".format(
                "Updated" if output_exists and args.update else "Created",
                outputname))
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            hd5file.close()
            rootfile.Close()
            if not output_exists:
                log.info("Removing {0}".format(outputname))
                os.unlink(outputname)
            sys.exit(1)
        except Exception as e:
            if args.debug:
                # If in debug mode show full stack trace
                import traceback
                traceback.print_exception(*sys.exc_info())
            log.error(str(e))
            sys.exit(1)
        finally:
            hd5file.close()
            rootfile.Close()
Exemplo n.º 5
0
def main():

    import rootpy
    from rootpy.extern.argparse import (
        ArgumentParser,
        ArgumentDefaultsHelpFormatter, RawTextHelpFormatter)

    class formatter_class(ArgumentDefaultsHelpFormatter,
                          RawTextHelpFormatter):
        pass

    parser = ArgumentParser(formatter_class=formatter_class,
        description="Convert ROOT files containing TTrees into HDF5 files "
                    "containing HDF5 tables")
    parser.add_argument('--version', action='version',
                        version=rootpy.__version__,
                        help="show the version number and exit")
    parser.add_argument('-n', '--entries', type=int, default=100000,
                        help="number of entries to read at once")
    parser.add_argument('-f', '--force', action='store_true', default=False,
                        help="overwrite existing output files")
    parser.add_argument('-u', '--update', action='store_true', default=False,
                        help="update existing output files")
    parser.add_argument('--ext', default='h5',
                        help="output file extension")
    parser.add_argument('-c', '--complevel', type=int, default=5,
                        choices=range(0, 10),
                        help="compression level")
    parser.add_argument('-l', '--complib', default='zlib',
                        choices=('zlib', 'lzo', 'bzip2', 'blosc'),
                        help="compression algorithm")
    parser.add_argument('-s', '--selection', default=None,
                        help="apply a selection on each "
                             "tree with a cut expression")
    parser.add_argument(
        '--script', default=None,
        help="Python script containing a function with the same name \n"
             "that will be called on each tree and must return a tree or \n"
             "list of trees that will be converted instead of the \n"
             "original tree")
    parser.add_argument('-q', '--quiet', action='store_true', default=False,
                        help="suppress all warnings")
    parser.add_argument('-d', '--debug', action='store_true', default=False,
                        help="show stack trace in the event of "
                             "an uncaught exception")
    parser.add_argument('--no-progress-bar', action='store_true', default=False,
                        help="do not show the progress bar")
    parser.add_argument('--ignore-exception', action='store_true',
                        default=False,
                        help="ignore exceptions raised in converting trees "
                             "and instead skip such trees")
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    rootpy.log.basic_config_colorized()
    import logging
    if hasattr(logging, 'captureWarnings'):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip('.')

    if args.quiet:
        warnings.simplefilter(
            "ignore",
            RootNumpyUnconvertibleWarning)
        warnings.simplefilter(
            "ignore",
            tables.NaturalNameWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, 'exec'),
                 globals(), locals())
        except IOError:
            sys.exit('Could not open script {0}'.format(args.script))
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit(
                "Could not find the function '{0}' in the script {1}".format(
                    funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + '.' + args.ext
        output_exists = os.path.exists(outputname)
        if output_exists and not (args.force or args.update):
            sys.exit(
                "Output {0} already exists. "
                "Use the --force option to overwrite it".format(outputname))
        try:
            rootfile = root_open(inputname)
        except IOError:
            sys.exit("Could not open {0}".format(inputname))
        try:
            if args.complevel > 0:
                filters = tables.Filters(complib=args.complib,
                                         complevel=args.complevel)
            else:
                filters = None
            hd5file = tables_open(filename=outputname,
                                  mode='a' if args.update else 'w',
                                  title='Data', filters=filters)
        except IOError:
            sys.exit("Could not create {0}".format(outputname))
        try:
            log.info("Converting {0} ...".format(inputname))
            root2hdf5(rootfile, hd5file,
                      entries=args.entries,
                      userfunc=userfunc,
                      selection=args.selection,
                      show_progress=not args.no_progress_bar,
                      ignore_exception=args.ignore_exception)
            log.info("{0} {1}".format(
                "Updated" if output_exists and args.update else "Created",
                outputname))
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            hd5file.close()
            rootfile.Close()
            if not output_exists:
                log.info("Removing {0}".format(outputname))
                os.unlink(outputname)
            sys.exit(1)
        except Exception as e:
            if args.debug:
                # If in debug mode show full stack trace
                import traceback
                traceback.print_exception(*sys.exc_info())
            log.error(str(e))
            sys.exit(1)
        finally:
            hd5file.close()
            rootfile.Close()
Exemplo n.º 6
0
def main():

    from rootpy.extern.argparse import (ArgumentParser,
            ArgumentDefaultsHelpFormatter, RawTextHelpFormatter)

    class formatter_class(ArgumentDefaultsHelpFormatter,
                          RawTextHelpFormatter):
        pass

    parser = ArgumentParser(formatter_class=formatter_class)
    parser.add_argument('-n', '--entries', type=int, default=1E5,
            help="number of entries to read at once")
    parser.add_argument('-f', '--force', action='store_true', default=False,
            help="overwrite existing output files")
    parser.add_argument('--ext', default='h5',
            help="output file extension")
    parser.add_argument('-c', '--complevel', type=int, default=5,
            choices=range(0, 10),
            help="compression level")
    parser.add_argument('-l', '--complib', default='zlib',
            choices=('zlib', 'lzo', 'bzip2', 'blosc'),
            help="compression algorithm")
    parser.add_argument('-s', '--selection', default=None,
            help="apply a selection on each tree with a cut expression")
    parser.add_argument('--script', default=None,
            help="Python script containing a function with the same name \n"
                 "that will be called on each tree and must return a tree or \n"
                 "list of trees that will be converted instead of the \n"
                 "original tree")
    parser.add_argument('-q', '--quiet', action='store_true', default=False,
            help="suppress all warnings")
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    import rootpy
    rootpy.log.basic_config_colorized()
    import logging
    if hasattr(logging, 'captureWarnings'):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip('.')

    if args.quiet:
        warnings.simplefilter("ignore",
            RootNumpyUnconvertibleWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, 'exec'),
                 globals(), locals())
        except IOError:
            sys.exit('Could not open script %s' % args.script)
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit("Could not find the function '%s' in the script %s" %
                (funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + '.' + args.ext
        if os.path.exists(outputname) and not args.force:
            sys.exit(('Output %s already exists. '
                'Use the --force option to overwrite it') % outputname)
        try:
            rootfile = ropen(inputname)
        except IOError:
            sys.exit("Could not open %s" % inputname)
        try:
            filters = tables.Filters(
                    complib=args.complib, complevel=args.complevel)
            hd5file = tables.openFile(filename=outputname, mode='w',
                    title='Data', filters=filters)
        except IOError:
            sys.exit("Could not create %s" % outputname)
        try:
            log.info("Converting %s ..." % inputname)
            convert(rootfile, hd5file,
                    entries=args.entries,
                    userfunc=userfunc,
                    selection=args.selection)
            log.info("Created %s" % outputname)
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            os.unlink(outputname)
            break
        finally:
            hd5file.close()
            rootfile.Close()
Exemplo n.º 7
0
#!/usr/bin/env python
"""
==========================
Setting the plotting style
==========================

This example demonstrates how to set the plotting style.
"""
print __doc__

from rootpy.extern.argparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument('style', default='ATLAS', nargs='?')
args, extra = parser.parse_known_args()

import sys
import ROOT
import rootpy
rootpy.log.basic_config_colorized()
from rootpy.plotting import Canvas, Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait

try:
    kwargs = {}
    for arg in extra:
        name, value = arg.lstrip('--').split('=')
        kwargs[name] = value
except ValueError:
    sys.exit("specify style parameters with --name=value")
Exemplo n.º 8
0
#!/usr/bin/env python
"""
==========================
Setting the plotting style
==========================

This example demonstrates how to set the plotting style.
"""
print(__doc__)

from rootpy.extern.argparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument('style', default='ATLAS', nargs='?')
args, extra = parser.parse_known_args()

import ROOT
from rootpy.plotting import Canvas, Hist
from rootpy.plotting.style import get_style
from rootpy.interactive import wait
from rootpy.extern.six.moves import range

try:
    kwargs = {}
    for arg in extra:
        name, value = arg.lstrip('--').split('=')
        kwargs[name] = value
except ValueError:
    print("specify style parameters with --name=value")

try:
Exemplo n.º 9
0
def main():

    from rootpy.extern.argparse import (ArgumentParser,
                                        ArgumentDefaultsHelpFormatter,
                                        RawTextHelpFormatter)

    class formatter_class(ArgumentDefaultsHelpFormatter, RawTextHelpFormatter):
        pass

    parser = ArgumentParser(formatter_class=formatter_class)
    parser.add_argument('-n',
                        '--entries',
                        type=int,
                        default=1E5,
                        help="number of entries to read at once")
    parser.add_argument('-f',
                        '--force',
                        action='store_true',
                        default=False,
                        help="overwrite existing output files")
    parser.add_argument('--ext', default='h5', help="output file extension")
    parser.add_argument('-c',
                        '--complevel',
                        type=int,
                        default=5,
                        choices=range(0, 10),
                        help="compression level")
    parser.add_argument('-l',
                        '--complib',
                        default='zlib',
                        choices=('zlib', 'lzo', 'bzip2', 'blosc'),
                        help="compression algorithm")
    parser.add_argument(
        '-s',
        '--selection',
        default=None,
        help="apply a selection on each tree with a cut expression")
    parser.add_argument(
        '--script',
        default=None,
        help="Python script containing a function with the same name \n"
        "that will be called on each tree and must return a tree or \n"
        "list of trees that will be converted instead of the \n"
        "original tree")
    parser.add_argument('-q',
                        '--quiet',
                        action='store_true',
                        default=False,
                        help="suppress all warnings")
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    import rootpy
    rootpy.log.basic_config_colorized()
    import logging
    if hasattr(logging, 'captureWarnings'):
        logging.captureWarnings(True)

    def formatwarning(message, category, filename, lineno, line=None):
        return "{0}: {1}".format(category.__name__, message)

    warnings.formatwarning = formatwarning
    args.ext = args.ext.strip('.')

    if args.quiet:
        warnings.simplefilter("ignore", RootNumpyUnconvertibleWarning)

    userfunc = None
    if args.script is not None:
        # get user-defined function
        try:
            exec(compile(open(args.script).read(), args.script, 'exec'),
                 globals(), locals())
        except IOError:
            sys.exit('Could not open script %s' % args.script)
        funcname = os.path.splitext(os.path.basename(args.script))[0]
        try:
            userfunc = locals()[funcname]
        except KeyError:
            sys.exit("Could not find the function '%s' in the script %s" %
                     (funcname, args.script))

    for inputname in args.files:
        outputname = os.path.splitext(inputname)[0] + '.' + args.ext
        if os.path.exists(outputname) and not args.force:
            sys.exit(('Output %s already exists. '
                      'Use the --force option to overwrite it') % outputname)
        try:
            rootfile = root_open(inputname)
        except IOError:
            sys.exit("Could not open %s" % inputname)
        try:
            if args.complevel > 0:
                filters = tables.Filters(complib=args.complib,
                                         complevel=args.complevel)
            else:
                filters = None
            hd5file = tables.openFile(filename=outputname,
                                      mode='w',
                                      title='Data',
                                      filters=filters)
        except IOError:
            sys.exit("Could not create %s" % outputname)
        try:
            log.info("Converting %s ..." % inputname)
            convert(rootfile,
                    hd5file,
                    entries=args.entries,
                    userfunc=userfunc,
                    selection=args.selection)
            log.info("Created %s" % outputname)
        except KeyboardInterrupt:
            log.info("Caught Ctrl-c ... cleaning up")
            os.unlink(outputname)
            break
        finally:
            hd5file.close()
            rootfile.Close()
Exemplo n.º 10
0
# https://github.com/rootpy/rootpy
from rootpy.plotting import Hist, Legend, Canvas
from rootpy.plotting.style import set_style
from rootpy.interactive import wait
from rootpy.extern.argparse import ArgumentParser
from rootpy import log
log.basic_config_colorized()
import numpy as np

parser = ArgumentParser()
parser.add_argument('--smooth-iterations', type=int, default=1)
parser.add_argument('--transform-scale', type=float, default=5.)
parser.add_argument('--events', type=int, default=1000)
parser.add_argument('--bins', type=int, default=20)
args = parser.parse_args()

set_style('ATLAS')

nominal_scores = np.random.normal(-.3, .2, size=args.events)
up_scores = np.random.normal(-.25, .2, size=args.events)
dn_scores = np.random.normal(-.35, .2, size=args.events)


def transform(x):
    return 2.0 / (1.0 + np.exp(-args.transform_scale * x)) - 1.0


nominal = Hist(args.bins, -1, 1, title='Nominal')
nominal.fill_array(transform(nominal_scores))

up = nominal.Clone(title='Up',
Exemplo n.º 11
0
    def __init__(self, options, **kwargs):
        super(hhskim, self).__init__(**kwargs)
        parser = ArgumentParser()
        parser.add_argument('--local', action='store_true', default=False)
        parser.add_argument('--syst-terms', default=None)
        parser.add_argument('--student-verbose', action='store_true', default=False)
        parser.add_argument('--student-very-verbose', action='store_true', default=False)
        parser.add_argument('--redo-selection', action='store_true', default=False)
        parser.add_argument('--nominal-values', action='store_true', default=False)
        args = parser.parse_args(options)
        self.args = args
        if args.syst_terms is not None:
            args.syst_terms = set([
                eval('Systematics.%s' % term) for term in
                args.syst_terms.split(',')])
        if args.local:
            def merge(inputs, output, metadata):
                # merge output trees
                root_output = output + '.root'
                log.info("merging output trees")
                subprocess.call(['hadd', root_output] + inputs)
                if metadata.datatype == datasets.DATA:
                    # merge GRLs
                    log.info("merging GRL fragments")
                    grl = goodruns.GRL()
                    for input in inputs:
                        grl |= goodruns.GRL('%s:/lumi' % input)
                    grl.save('%s:/lumi' % root_output)

            hhskim.merge = staticmethod(merge)
Exemplo n.º 12
0
            for component in components:
                if 'nominal' not in component.GetName():
                    continue
                comp_hists.append(
                    component.createHistogram(
                        '{0}_{1}'.format(
                            category.name, component.GetName()), obs))


def draw_file(filename, output_path=None):
    if output_path is None:
        output_path = os.path.splitext(filename)[0]
    if os.path.isfile(output_path):
        raise ValueError("a file already exists at {0}".format(output_path))
    with root_open(filename) as file:
        for dirpath, dirnames, objectnames in file.walk(class_pattern='RooWorkspace'):
            for name in objectnames:
                workspace = file['{0}/{1}'.format(dirpath, name)]
                draw_workspace(workspace, os.path.join(output_path, dirpath, name))

if __name__ == '__main__':
    from rootpy.extern.argparse import ArgumentParser

    parser = ArgumentParser()
    parser.add_argument('--output', '-o', default=None)
    parser.add_argument('files', nargs='+')
    args = parser.parse_args()

    for filename in args.files:
        draw_file(filename, args.output)
Exemplo n.º 13
0
def get_parser():
    parser = ArgumentParser()
    parser.add_argument('--format', choices=('latex', 'text'), default='text')
    parser.add_argument('--errors', action='store_true', default=False)
    parser.add_argument('--precision', default=2)
    parser.add_argument('--proc', default='HHProcessor')
    parser.add_argument('--db', default='datasets_hh')
    parser.add_argument('--year', type=int, default=2012)
    parser.add_argument('--no-weight', action='store_true', default=False)
    parser.add_argument('--verbose', action='store_true', default=False)
    parser.add_argument('--rst', action='store_true', default=False)
    parser.add_argument('--rst-class', default='cutflow')
    parser.add_argument('--total', action='store_true', default=False)
    parser.add_argument('--landscape', action='store_true', default=False)
    parser.add_argument('--warn-missing', action='store_true', default=False)
    return parser
Exemplo n.º 14
0
import logging
import os

# rootpy/ROOT imports
import rootpy
from rootpy.extern.argparse import ArgumentParser
# setup the argument parser
parser = ArgumentParser()
parser.add_argument('--test_mode',
                    type=str,
                    default='VBF',
                    choices=['VBF', 'gg', 'mix', 'Z'])
parser.add_argument('--test_level',
                    type=str,
                    default='reco',
                    choices=['truth', 'reco'])
parser.add_argument('--train_level',
                    type=str,
                    default='truth',
                    choices=['truth', 'reco'])
parser.add_argument(
    '--train_id',
    type=str,
    default='0000',
)

parser.add_argument('--channel',
                    type=str,
                    default='hh',
                    choices=['hh', 'lh', 'll'])
parser.add_argument('--train_mode',
Exemplo n.º 15
0
import ROOT

from rootpy.tree.filtering import EventFilter, EventFilterList
from rootpy.tree import Tree, TreeChain, TreeModel, TreeBuffer
from rootpy.extern.argparse import ArgumentParser
from rootpy.io import root_open
from rootpy import stl

from flat.models import *
from flat.filters import *
from flat.objects import define_objects
import flat.branches as branches
from flat import log
log = log[__name__]

parser = ArgumentParser()
parser.add_argument('input', type=str, help='input file name')
parser.add_argument('output', type=str, help='output file name')
parser.add_argument('--tree-name',
                    type=str,
                    default='tau',
                    help='Input tree name')
args = parser.parse_args()

output = root_open(args.output, 'recreate')
output.cd()
model = get_model()
outtree = Tree(name='Tree', model=model)
outtree.define_object(name='tau1', prefix='tau1_')
outtree.define_object(name='tau2', prefix='tau2_')
outtree.define_object(name='jet1', prefix='jet1_')
Exemplo n.º 16
0
    def __init__(self, options, **kwargs):
        super(hhskim_truth, self).__init__(**kwargs)
        parser = ArgumentParser()
        parser.add_argument('--local', action='store_true', default=False)
        parser.add_argument('--syst-terms', default=None)
        parser.add_argument('--student-verbose',
                            action='store_true',
                            default=False)
        parser.add_argument('--student-very-verbose',
                            action='store_true',
                            default=False)
        parser.add_argument('--redo-selection',
                            action='store_true',
                            default=False)
        parser.add_argument('--nominal-values',
                            action='store_true',
                            default=False)
        args = parser.parse_args(options)
        self.args = args
        if args.syst_terms is not None:
            args.syst_terms = set([
                eval('Systematics.%s' % term)
                for term in args.syst_terms.split(',')
            ])
        if args.local:

            def merge(inputs, output, metadata):
                # merge output trees
                root_output = output + '.root'
                log.info("merging output trees")
                subprocess.call(['hadd', root_output] + inputs)
                if metadata.datatype == datasets.DATA:
                    # merge GRLs
                    log.info("merging GRL fragments")
                    grl = goodruns.GRL()
                    for input in inputs:
                        grl |= goodruns.GRL('%s:/lumi' % input)
                    grl.save('%s:/lumi' % root_output)

            hhskim_truth.merge = staticmethod(merge)
Exemplo n.º 17
0
# https://github.com/rootpy/rootpy
from rootpy.plotting import Hist, Legend, Canvas
from rootpy.plotting.style import set_style
from rootpy.interactive import wait
from rootpy.extern.argparse import ArgumentParser
from rootpy import log; log.basic_config_colorized()
import numpy as np

parser = ArgumentParser()
parser.add_argument('--smooth-iterations', type=int, default=1)
parser.add_argument('--transform-scale', type=float, default=5.)
parser.add_argument('--events', type=int, default=1000)
parser.add_argument('--bins', type=int, default=20)
args = parser.parse_args()

set_style('ATLAS')

nominal_scores = np.random.normal(-.3, .2, size=args.events)
up_scores = np.random.normal(-.25, .2, size=args.events)
dn_scores = np.random.normal(-.35, .2, size=args.events)

def transform(x):
    return 2.0 / (1.0 + np.exp(- args.transform_scale * x)) - 1.0

nominal = Hist(args.bins, -1, 1, title='Nominal')
nominal.fill_array(transform(nominal_scores))

up = nominal.Clone(title='Up', linecolor='red', linestyle='dashed', linewidth=2)
up.Reset()
up.fill_array(transform(up_scores))