コード例 #1
0
    def test_list_type_filter(self):
        tfile = r.TFile.Open(
            os.path.join(self.test_data_dir,
                         'multiple_trees_plus_others.root'))

        elements = list(list_obj(tfile, 'TTree', '1'))
        self.assertEqual(['tree1'], elements)
コード例 #2
0
def costh_ratios(gfile):
    """Make the costh ratio plots"""
    graphs = [
        gfile.Get(n) for n in list_obj(gfile, 'TGraph', 'chic_CMS_pol_ptM')
    ]

    cans = []
    for graph in graphs:
        ptm_s = graph.GetName().split('_')[-1]
        ptm = float(ptm_s.replace('p', '.'))

        leg = setup_legend(0.55, 0.7, 0.88, 0.78)
        can = mkplot(graph,
                     drawOpt='PE',
                     attr=DATA_ATTR,
                     leg=leg,
                     legEntries=['CMS @ p_{{T}} / M = {:.2f}'.format(ptm)],
                     xRange=[0, 1],
                     xLabel=CTH_LABEL,
                     yRange=[0.2, 0.6],
                     yLabel='#chi_{c2} / #chi_{c1}')

        model = gfile.Get('chic_pol_ptM_{}'.format(ptm_s))
        mkplot(model,
               can=can,
               drawOpt='Lsame',
               leg=leg,
               legEntries=['model'],
               legOpt='L')

        cans.append((ptm_s, can))

    return cans
コード例 #3
0
    def test_list_type(self):
        # NOTE: Only checking one file here
        tfile = r.TFile.Open(
            os.path.join(self.test_data_dir, 'one_tree_plus_others.root'))

        elements = list(list_obj(tfile, 'TTree'))
        self.assertEqual(elements, ['tree1'])
コード例 #4
0
def make_state_prob_plot(rfile, state, var):
    """
    Make a plot comparing (the normalized) state probability distributions in
    all the bins
    """
    hist_base = r'^{}_JpsiPt_0_{}_([0-9]+)_state_prob$'.format(state, var)
    hists = [rfile.Get(n) for n in list_obj(rfile, 'TH1D', hist_base)]
    [h.Scale(1.0 / h.Integral()) for h in hists]

    can = mkplot(hists,
                 drawOpt='hist',
                 xRange=[0, 1.25],
                 xLabel=get_xlab(state),
                 legPos=[0.83, 0.2, 0.94, 0.2 + 0.04 * len(hists)],
                 legOpt='l',
                 legEntries=['bin {}'.format(i) for i in xrange(len(hists))],
                 yLabel='normalized distributions',
                 logy=True,
                 yRange=[0.0003, None])
    mkplot(r.TLine(1, 0, 1,
                   get_y_max(hists) * 1.1),
           can=can,
           drawOpt='same',
           attr=[{
               'color': 12,
               'line': 7,
               'width': 2
           }])

    return can
コード例 #5
0
def make_rej_evs_w_state_prob_plot(rfile, state, var):
    """
    Make a plot showing the state probability of the rejected events in all the
    bins
    """
    hist_base = r'{}_JpsiPt_0_{}_([0-9]+)_state_prob_rej_ev'.format(state, var)
    hists = [rfile.Get(n) for n in list_obj(rfile, 'TH1D', hist_base)]

    can = mkplot(hists,
                 drawOpt='PEX0',
                 xRange=[0, 1.25],
                 xLabel=get_xlab(state),
                 legPos=[0.83, 0.2, 0.94, 0.2 + 0.04 * len(hists)],
                 legEntries=['bin {}'.format(i) for i in xrange(len(hists))],
                 yLabel='rejected events',
                 logy=True,
                 yRange=[0.1, None])
    mkplot(r.TLine(1, 0, 1,
                   get_y_max(hists) * 1.1),
           can=can,
           drawOpt='same',
           attr=[{
               'color': 12,
               'line': 7,
               'width': 2
           }])

    return can
コード例 #6
0
    def test_list_filter(self):
        tfile = r.TFile.Open(
            os.path.join(self.test_data_dir,
                         'multiple_trees_plus_others.root'))

        elements = list(list_obj(tfile, filter_str='1'))
        for elem in ['tree1', 'hist1']:
            self.assertTrue(elem in elements)
        self.assertEqual(len(elements), 2)
コード例 #7
0
    def test_list_all(self):
        # NOTE: Only checking one file here
        tfile = r.TFile.Open(
            os.path.join(self.test_data_dir,
                         'multiple_trees_plus_others.root'))

        elements = list(list_obj(tfile))
        for elem in ['tree1', 'tree2', 'hist1', 'hist2']:
            self.assertTrue(elem in elements)
コード例 #8
0
def main(args):
    """Main"""
    numfile = r.TFile.Open(args.numfile)
    denomfile = r.TFile.Open(args.denomfile)

    # use sets so that it is easier to find the histograms with the same names
    num_hists = set(list_obj(numfile, 'TH1', args.filter))
    denom_hists = set(list_obj(denomfile, 'TH1', args.filter))
    ratio_hists = num_hists.intersection(denom_hists)

    outfile = r.TFile(args.outfile, 'update' if args.update else 'recreate')
    for ratio_n in ratio_hists:
        logging.debug('Creating: {}'.format(ratio_n))
        ratio = divide(numfile.Get(ratio_n), denomfile.Get(ratio_n))
        outfile.cd()
        ratio.Write()

    outfile.Write('', r.TObject.kWriteDelete)
    outfile.Close()
コード例 #9
0
def get_graphs(gfile):
    """Get the graphs and the variable for which the graphs are plotted"""
    graphnames = list_obj(gfile, 'TGraphAsymmErrors', r'v_pt_(n_sig|cl)_')
    graphs = OrderedDict()
    for name in graphnames:
        n_sig = name.split('_')[-1]
        graphs[n_sig] = gfile.Get(name)

    var = graphs.values()[0].GetName().split('_')[0]

    return var, graphs
コード例 #10
0
def determine_bin_variable(rfile):
    """
    Determine whether the ratio has been obtained as a function of costh or phi
    from the names of the histograms in the file

    NOTE: very brittle, but works for now
    """
    all_hists = list_obj(rfile, 'TH1D')
    if all('costh_HX_fold' in h for h in all_hists):
        return 'costh_HX_fold'

    if all('phi_HX_fold' in h for h in all_hists):
        return 'phi_HX_fold'
コード例 #11
0
def main(args):
    """Main"""
    if args.verbose:
        logging.getLogger().setLevel(logging.INFO)
    else:
        r.gROOT.ProcessLine('gErrorIgnoreLevel = 1001')

    histfile = r.TFile.Open(args.inputfile)
    cond_mkdir(args.outdir)

    formats = args.extensions.split(',')
    for hist in list_obj(histfile, 'TH1', args.filter):
        store_hist(histfile.Get(hist),
                   args.outdir,
                   formats,
                   args.draw_opt,
                   xrange=args.xrange,
                   yrange=args.yrange,
                   zrange=args.zrange,
                   hist_cmd=args.hist_cmd)