Ejemplo n.º 1
0
    def __init__(self, files, lumifiles, outputdir, blinder=None):
        ''' Initialize the Plotter object

        Files should be a list of SAMPLE_NAME.root files.
        Lumifiles should contain floats giving the effective luminosity of
        each of the files.

        If [blinder] is not None, it will be applied to the data view.
        '''
        self.outputdir = outputdir
        self.views = data_views(files, lumifiles)
        self.canvas = plotting.Canvas(name='adsf', title='asdf')
        self.canvas.cd()
        if blinder:
            # Keep the unblinded data around if desired.
            self.views['data']['unblinded_view'] = self.views['data']['view']
            # Apply a blinding function
            self.views['data']['view'] = blinder(self.views['data']['view'])
        self.data = self.views['data']['view']
        self.keep = []
        # List of MC sample names to use.  Can be overridden.
        self.mc_samples = [
            'Zjets_M50',
            'WplusJets_madgraph',
            'TTplusJets_madgraph',
            'WZ*',
            'ZZ*',
            'WW*',
        ]
Ejemplo n.º 2
0
    def __init__(self, files, lumifiles, outputdir, blinder=None, forceLumi=-1):
        ''' Initialize the Plotter object

        Files should be a list of SAMPLE_NAME.root files.
        Lumifiles should contain floats giving the effective luminosity of
        each of the files.

        If [blinder] is not None, it will be applied to the data view.
        '''
        self.outputdir = outputdir
        self.base_out_dir = outputdir
        self.views = data_views(files, lumifiles, forceLumi)
        self.canvas = plotting.Canvas(name='adsf', title='asdf')
        self.canvas.cd()
        self.pad    = plotting.Pad('up', 'up', 0., 0., 1., 1.) #ful-size pad
        self.pad.Draw()
        self.pad.cd()
        self.lower_pad = None
        if blinder:
            # Keep the unblinded data around if desired.
            self.views['data']['unblinded_view'] = self.views['data']['view']
            # Apply a blinding function
            self.views['data']['view'] = blinder(self.views['data']['view'])
        self.data = self.views['data']['view']
        self.keep = []
        # List of MC sample names to use.  Can be overridden.
        self.mc_samples = []

        file_to_map = filter(lambda x: x.startswith('data_'), self.views.keys())[0]
        if not file_to_map: #no data here!
            file_to_map = self.views.keys()[0]
        #set_trace()
        self.file_dir_structure = Plotter.map_dir_structure( self.views[file_to_map]['file'] )
Ejemplo n.º 3
0
    def __init__(self, files, lumifiles, outputdir, blinder=None):
        ''' Initialize the Plotter object

        Files should be a list of SAMPLE_NAME.root files.
        Lumifiles should contain floats giving the effective luminosity of
        each of the files.

        If [blinder] is not None, it will be applied to the data view.
        '''
        self.outputdir = outputdir
        self.views = data_views(files, lumifiles)
        self.canvas = plotting.Canvas(name='adsf', title='asdf')
        self.canvas.cd()
        if blinder:
            # Keep the unblinded data around if desired.
            self.views['data']['unblinded_view'] = self.views['data']['view']
            # Apply a blinding function
            self.views['data']['view'] = blinder(self.views['data']['view'])
        self.data = self.views['data']['view']
        self.keep = []
        # List of MC sample names to use.  Can be overridden.
        self.mc_samples = [
            'Zjets_M50',
            'WplusJets_madgraph',
            'TTplusJets_madgraph',
            'WZJetsTo3LNu*',
            'ZZJetsTo4L*',
           # 'WW*',
        ]
Ejemplo n.º 4
0
    def __init__(self,
                 files,
                 lumifiles,
                 outputdir,
                 blinder=None,
                 forceLumi=-1):
        ''' Initialize the Plotter object

        Files should be a list of SAMPLE_NAME.root files.
        Lumifiles should contain floats giving the effective luminosity of
        each of the files.

        If [blinder] is not None, it will be applied to the data view.
        '''
        self.outputdir = outputdir
        self.views = data_views(files, lumifiles, forceLumi)
        self.canvas = plotting.Canvas(name='adsf', title='asdf')
        self.canvas.cd()
        self.pad = plotting.Pad('up', 'up', 0., 0., 1., 1.)  #ful-size pad
        self.pad.Draw()
        self.pad.cd()
        self.lower_pad = None
        if blinder:
            # Keep the unblinded data around if desired.
            self.views['data']['unblinded_view'] = self.views['data']['view']
            # Apply a blinding function
            self.views['data']['view'] = blinder(self.views['data']['view'])
        self.data = self.views['data']['view']
        self.keep = []
        # List of MC sample names to use.  Can be overridden.
        self.mc_samples = [
            'Zjets_M50',
            'WplusJets_madgraph',
            'TTplusJets_madgraph',
            'WZ*',
            'ZZ*',
            'WW*',
        ]
        file_to_map = filter(lambda x: x.startswith('data_'),
                             self.views.keys())[0]
        if not file_to_map:  #no data here!
            file_to_map = self.views.keys()[0]
        #from pdb import set_trace; set_trace()
        self.file_dir_structure = Plotter.map_dir_structure(
            self.views[file_to_map]['file'])
Ejemplo n.º 5
0
if __name__ == "__main__":
    log = logging.getLogger("render_zh_plots")
    view_builder = logging.getLogger("data_views")
    view_builder.setLevel(logging.WARNING)
    logging.basicConfig(level=logging.INFO, stream=sys.stderr)

    parser = argparse.ArgumentParser()
    parser.add_argument('pd', help='Primary dataset')
    parser.add_argument('l1name', help='Name of first lepton')
    parser.add_argument('l2name', help='Name of first lepton')
    parser.add_argument('files', metavar='file',
                        nargs='+', help = 'Histogram files')
    args = parser.parse_args(args[1:])

    log.info("Building views")
    data_views = data_views(args.files,args.pd)

    data_view = data_views[args.pd]['view']

    def write(to_stdout):
        sys.stdout.write(to_stdout)
        sys.stdout.write('\n')

    # Print out regions in the OS
    table = tabulartext.PrettyTable(
        ["Sign", "Final", "%s anti-iso" % args.l1name,
         "%s anti-iso" % args.l2name, "both anti-iso",
         "%s FR %%" % args.l1name, "%s FR %%" % args.l2name,
         'both x SS FR1 x SS FR2',
        ]
    )
Ejemplo n.º 6
0
    import rootpy.plotting as plotting
    from FinalStateAnalysis.MetaData.data_views import data_views

    logging.basicConfig(stream=sys.stderr, level=logging.INFO)

    files = []
    for pattern in args.files:
        files.extend(glob.glob(pattern))

    log.info("Loading data from %i files", len(files))

    lumifiles = []
    for pattern in args.lumifiles:
        lumifiles.extend(glob.glob(pattern))

    the_views = data_views(files, lumifiles)

    outputdir = os.path.dirname(args.outputfile)
    if outputdir and not os.path.exists(outputdir):
        os.makedirs(outputdir)

    log.info("Rebinning with factor %s", args.rebin)

    def rebin_view(x):
        """ Make a view which rebins histograms """
        binning = None
        if "," in args.rebin:
            binning = tuple(int(x) for x in args.rebin.split(","))
        else:
            binning = int(args.rebin)
        return RebinView(x, binning)
Ejemplo n.º 7
0
    log = logging.getLogger("render_zh_plots")
    view_builder = logging.getLogger("data_views")
    view_builder.setLevel(logging.DEBUG)
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('output', help='Output directory')
    parser.add_argument('pd', help='Primary dataset')
    parser.add_argument('files',
                        metavar='file',
                        nargs='+',
                        help='Histogram files')
    args = parser.parse_args(args[1:])

    log.info("Building views")
    data_views = data_views(args.files, args.pd)

    data_view = data_views[args.pd]['view']

    mc_samples_to_stack = [
        'Zjets', 'QCDMu', 'Wjets', 'ttjets', 'WZ_pythia', 'ZZ'
    ]

    # Build the MC stack
    mc_view = views.StackView(
        *[data_views[x]['view'] for x in mc_samples_to_stack], sort=True)

    # We just need to figure out the directory structure from any old file
    layout_filename = data_views.values()[0]['subsamples'].values(
    )[0]['filename']
    log.info("Getting file layout from %s", layout_filename)
Ejemplo n.º 8
0
    import ROOT
    import rootpy.plotting.views as views
    import rootpy.plotting as plotting
    from FinalStateAnalysis.MetaData.data_views import data_views

    files = []
    for pattern in args.files:
        files.extend(glob.glob(pattern))

    log.info("Loading data from %i files", len(files))

    lumifiles = []
    for pattern in args.lumifiles:
        lumifiles.extend(glob.glob(pattern))

    the_views = data_views(files, lumifiles)

    outputdir = os.path.dirname(args.outputfile)
    if outputdir and not os.path.exists(outputdir):
        os.makedirs(outputdir)

    log.info("Rebinning with factor %s", args.rebin)
    def rebin_view(x):
        ''' Make a view which rebins histograms '''
        binning = None
        binning = eval(args.rebin)
        return RebinView(x, binning)

    def round_to_ints(x):
        new = x.Clone()
        new.Reset()
Ejemplo n.º 9
0
    view_builder = logging.getLogger("data_views")
    view_builder.setLevel(logging.DEBUG)
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser()
    parser.add_argument('output', help='Output directory')
    parser.add_argument('pd', help='Primary dataset')
    parser.add_argument('l1name', help='Name of first lepton')
    parser.add_argument('l2name', help='Name of first lepton')
    parser.add_argument('bkgs', help='Background est. file')
    parser.add_argument('files', metavar='file',
                        nargs='+', help = 'Histogram files')
    args = parser.parse_args(args[1:])

    log.info("Building views")
    histogram_views = data_views(args.files,args.pd)

    def region_directory(base_view, is_os, passed1, passed2):
        ''' Get the directory given the configuration '''
        directory = "_".join([
            "os" if is_os else "ss",
            args.l1name,
            "pass" if passed1 else "fail",
            args.l2name,
            "pass" if passed2 else "fail",
        ])
        return views.SubdirectoryView(base_view, directory)

    plots_to_make = [
        'z1Mass'
    ]
Ejemplo n.º 10
0
)
lowpt_mu_qcd_fr = build_roofunctor(
    frfit_dir + '/m_qcd_pt10_h2taucuts_muonJetPt.root',
    'fit_efficiency', # workspace name
    'efficiency'
)
tau_qcd_fr = build_roofunctor(
    frfit_dir + '/t_ztt_pt20_mvaloose_tauPt.root',
    'fit_efficiency', # workspace name
    'efficiency'
)

# Get 2D fake rates

fr_data_views = data_views.data_views(
    glob.glob(os.path.join('results', os.environ['jobid'], 'FakeRatesMM', '*.root')),
    glob.glob(os.path.join('inputs', os.environ['jobid'], '*.sum')),
)

def get_view(sample_pattern):
    for sample, sample_info in fr_data_views.iteritems():
        if fnmatch.fnmatch(sample, sample_pattern):
            return sample_info['view']
    raise KeyError("I can't find a view that matches %s, I have: %s" % (
        sample_pattern, " ".join(fr_data_views.keys())))

# FR data, subtracting WZ and ZZ.
mu_fr_ewk_2d = TwoDimFakeRate(
    'wjets/pt10/h2taucuts/muonJetVsLeptonPt', 'wjets/pt10/muonJetVsLeptonPt',
    get_view('data'), get_view('WZ*'), get_view('ZZ*'))

mu_fr_qcd_2d = TwoDimFakeRate(
Ejemplo n.º 11
0
    parser = argparse.ArgumentParser()
    parser.add_argument('meta', help='File with meta information')
    parser.add_argument('output', help='Output directory')
    parser.add_argument('files', metavar='file', nargs='+',
                        help = 'Histogram files')
    args = parser.parse_args(args[1:])

    meta_info = None
    log.info("Opening meta file: %s", args.meta)
    with open(args.meta) as meta_file:
        meta_info = json.load(meta_file)

    log.info("Building views")
    data_views = data_views.data_views(
        args.files,
        'data_DoubleMu',
    )
    data_view = views.FunctorView(data_views['data_DoubleMu']['view'],
                                  lambda x: x.Rebin(1))

    mc_samples_to_stack = ['Zjets', 'QCDMu', 'Wjets', 'ttjets']
    # Build the MC stack
    mc_view = views.StackView(*[
        views.FunctorView(data_views[x]['view'], lambda x: x.Rebin(1))
        for x in mc_samples_to_stack], sort=True)

    log.debug("Zjets unweighted entries: %f",
              data_views['Zjets']['unweighted_view'].Get(
                  'plots/entry_count').Integral()
             )