def get_ff_stat(ntp, tree):
    ham_ok, wff = read_branches(ntp, tree, ['ham_ok', 'wff'])
    print(f'    Reweight success rate: {ham_ok.sum()/ham_ok.size:.2f}')
    wff_ok = wff[ham_ok]
    details = f'    FF avg wt: {wff_ok.mean():.3f}, max wt: {wff_ok.max():.3f}'
    details += f', wt > 1 ratio: {wff_ok[wff_ok > 1].size / wff_ok.size:.2f}'
    print(details)
Exemplo n.º 2
0
def cutflow_uniq_events_outer(ntp,
                              tree,
                              run_branch='runNumber',
                              event_branch='eventNumber'):
    run, event = read_branches(ntp, tree, (run_branch, event_branch))

    def inner(ntp_i, tree_i, arr):
        return extract_uid(ntp_i,
                           tree_i,
                           conditional=arr,
                           run_array=run,
                           event_array=event)[3]

    return inner
Exemplo n.º 3
0
# License: BSD 2-clause
# Last Change: Thu Feb 24, 2022 at 11:01 PM -0500

import numpy as np

from argparse import ArgumentParser
from pyTuplingUtils.io import read_branches


def parse_input():
    parser = ArgumentParser(
        description='Print RDX skim (e.g. ISO) sizes in step-2 ntuples.')

    parser.add_argument('ntp', help='specify input ntuple.')

    return parser.parse_args()


if __name__ == '__main__':
    args = parse_input()
    print('From ntuple: {}'.format(args.ntp))

    skims = ['ISO', '1OS', '2OS', 'DD']
    skim_branches = read_branches(args.ntp, 'tree',
                                  ['is_' + i.lower() for i in skims])
    # skim_branches = read_branches(args.ntp, 'tree', ['is_normal & d_mass_window_ok & ' + 'is_'+i.lower() for i in skims])

    for name, arr in zip(skims, skim_branches):
        cut = np.logical_and.reduce([arr])
        print('{:>6}: {:>12,}'.format(name, arr[cut].size))
Exemplo n.º 4
0
    parser.add_argument('tree', help='specify ntuple tree.')

    parser.add_argument('--l0', default='L0DUTCK',
                        help='specify L0 TCK branch.')

    parser.add_argument('--hlt1', default='HLT1TCK',
                        help='specify HLT1 TCK branch.')

    parser.add_argument('--hlt2', default='HLT2TCK',
                        help='specify HLT2 TCK branch.')

    return parser.parse_args()


########
# Main #
########

if __name__ == '__main__':
    args = parse_input()

    tck_raw = read_branches(args.ntp, args.tree, (args.l0, args.hlt1, args.hlt2),
                            transpose=True)
    tck = list(map(lambda x: '-'.join([hex(i) for i in x]), tck_raw))
    tck_uniq = np.unique(tck)

    print('Unique TCKs (L0-HLT1-HLT2):')
    for t in tck_uniq:
        print(t)
    # 220,
    230,
    # 240,
]

debugMode = len(sys.argv) == 1
print(f'Running in debug mode or not: {debugMode}')

for ntp in ntpsIn:
    hep.style.use('LHCb2')

    plotCommonName = plotBaseName(ntp)

    # particles = findDssInNtp(ntp)

    weight, tm, q2True, mass = read_branches(
        ntp, 'tree', ['wff', 'truthmatch', 'q2_true', 'ff_d_mass'])
    # massB = read_branch(ntp, 'tree', 'ff_b_mass')
    # rFac = mass / massB

    for p in particles:
        subplotCommonName = plotCommonName + f'_{p}'

        pNum = weight[tm == p].size
        pWeight = weight[tm == p].sum()
        pMass = mass[tm == p]
        xMin, xMax = pMass.min(), pMass.max()
        labels = [f'ISGW2 ({pNum})', f'BLR ({pWeight:.1f})']

        label = fr'\$B \\rightarrow {findDss(p)} {findLep(p)}$'
        plotNoComp(
            ntp,
        },
        'mu': {
            'title': r'$\mu$'
        },
    },
}

plotTitleAddOn = {
    'Dst': r'$D^{*}$ tree',
    'D0': r'$D^{0}$ tree',
}

for ntpName in ntpsIn:
    hep.style.use('LHCb2')
    ntp = uproot.open(ntpName)

    for treeId, scheme in plotScheme.items():
        if treeId in ntpName:
            for part in scheme:
                brP, brEta, brWt = read_branches(
                    ntp, 'tree', [f'{part}_p', f'{part}_eta', f'wtrk_{part}'])

                effRatio = f', {plotTitleAddOn[treeId]}, tracking eff: {brWt.sum() / brWt.size:.2f}'

                plotPEta(brP,
                         brEta,
                         f'{treeId}_{part}_p_eta.png',
                         binning=plotRange,
                         title=scheme[part]['title'] + effRatio)
            break