Beispiel #1
0
            '& abs(antiMuon_genEta) < 2.4 ' \
            '& muon_recoMatches == 1' \
            '& antiMuon_recoMatches == 1' \
            '& decayMode == 13'

# specify which branches to load
branches = [
    'nPU', 'muon_genEta', 'antiMuon_genEta', 'muon_genPhi', 'antiMuon_genPhi',
    'muon_dxy', 'antiMuon_dxy', 'muon_dz', 'antiMuon_dz', 'muon_tkIso',
    'antiMuon_tkIso', 'muon_pfIso', 'antiMuon_pfIso', 'muon_isFromPV',
    'antiMuon_isFromPV'
]

print(">>> Load Events in gen acceptance")
df = [
    tree_to_df(
        root2array(i, treeName[0], selection=selection, branches=branches), 5)
    for i in inputs
]
df = pd.concat(df)

# print(">>> add new columns")
# df['delRLL'] = np.sqrt(
#     (df['muon_genEta'] - df['antiMuon_genEta']) ** 2 + (df['muon_genPhi'] - df['antiMuon_genPhi']) ** 2)
#
#
# df = df.query('delRLL > 0.4')

# dfFromPV = df.query('muon_isFromPV == 1 & antiMuon_isFromPV == 1')
# dfNotFromPV = df.query('muon_isFromPV == 0 & antiMuon_isFromPV == 0')
#
# plot_scatter(dfFromPV['muon_dxy'], dfFromPV['antiMuon_dxy'], '$\mu^{-} d_{xy}$', '$\mu^{+} d_{xy}$',
Beispiel #2
0
branches_Reco = [
    'nPV', 'muon_Category', 'antiMuon_Category', 'muon_recoEta',
    'antiMuon_recoEta', 'muon_recoPhi', 'antiMuon_recoPhi', 'muon_recoPt',
    'antiMuon_recoPt'
]

branches_Gen = [
    'nPV', 'muon_genEta', 'antiMuon_genEta', 'muon_genPhi', 'antiMuon_genPhi',
    'muon_genPt', 'antiMuon_genPt'
]

print(">>> Load Events in reco acceptance")
dfReco = [
    tree_to_df(
        root2array(i,
                   treeName[0],
                   selection=selection_Reco,
                   branches=branches_Reco), 5) for i in inputs
]
dfReco = pd.concat(dfReco)
dfReco = dfReco.rename(
    columns={
        "muon_recoEta": "LepEta",
        "muon_recoPhi": "LepPhi",
        "muon_recoPt": "LepPt",
        "antiMuon_recoEta": "AntiLepEta",
        "antiMuon_recoPhi": "AntiLepPhi",
        "antiMuon_recoPt": "AntiLepPt"
    })

print(">>> Load Events in gen acceptance")
Beispiel #3
0
    os.mkdir(output)

if isinstance(inputs, (list, )):
    treeName = list_trees(inputs[0])
else:
    treeName = list_trees(inputs)
    inputs = [
        inputs,
    ]

if (len(treeName) > 1):
    print("more then one tree in file ... specify, which tree to use")
    exit()

dfPV = [
    tree_to_df(root2array(i, treeName[0], branches=['nPV']), 5) for i in inputs
]
dfPV = pd.concat(dfPV)

hPV = ROOT.TH1D("hPV", "th1d number of primary vertices shape", 75, -0.5, 74.5)

for nPV in dfPV['nPV']:
    hPV.Fill(nPV)

hPV.Scale(1. / hPV.Integral())

# acceptance selection
selection = 'muon_genRecoMatches == 1 ' \
            '& antiMuon_genRecoMatches == 1 ' \
            # '& (decayMode == 13 | decayMode == 151313)'
Beispiel #4
0
for era, input in inputs.iteritems():
    print("##### era {0}".format(era))

    treeName = rn.list_trees(input[0])[0]
    print(">>> Load Events from {0} files".format(len(input)))
    _df = []
    for i in input:
        print("> file " + i)
        tfile = ROOT.TFile.Open(i)
        if (tfile.Get(treeName).GetEntries(selection) == 0):
            print("> no events in this file found! continue with next file")
            continue
        _df.append(
            tree_to_df(
                rn.root2array(i,
                              treeName,
                              selection=selection,
                              branches=branches)))
    print(">>> Concatenate")
    df = pd.concat(_df)

    df['q'] = (df['q1'] + df['q2']) / 2.

    # ### additional requirement at Sel:
    # # case for is2HLT and only tag fails additional cut: tag and probe has to be chanched
    # selectedOr = df['is2HLT']
    #
    # if tkIsoCut is not None:
    #     selectedOr = selectedOr | (df['tkIso1'] >= tkIsoCut) & (df['tkIso2'] < tkIsoCut)
    # if pfIsoCut is not None:
    #     selectedOr = selectedOr | ((df['pfIso1'] >= pfIsoCut) & (df['pfIso2'] < pfIsoCut))
Beispiel #5
0
input = glob.glob(
    "/pnfs/desy.de/cms/tier2/store/user/dwalter/SingleMuon/MuonTrees_V06/200610_143117/0000/output_0_*"
)

treeName = rn.list_trees(input[0])[0]
print(">>> Load Events from {0} files".format(len(input)))
_df = []
for i, ifile in enumerate(input):
    print("> file {0}/{1}".format(i, len(input)))
    sys.stdout.flush()
    tfile = ROOT.TFile(ifile)
    ttree = tfile.Get(treeName)
    if ttree.GetEntries() == 0:
        print("tree has no entries, continue")
        continue
    _df.append(tree_to_df(rn.root2array(ifile, treeName)))

print(">>> Concatenate")
df = pd.concat(_df)

###############################################
# computation of difficiencies and acceptances #
###############################################


def diffacc(selection):
    """
    selection:
        lumbda function that returns a bool like lambda x: df['pt'] > x
    return:
        function for difficiency depending on selection as defined in lambda function
Beispiel #6
0
        os.mkdir(output)

    if isinstance(inputs, (list,)):
        treeName = list_trees(inputs[0])
    else:
        treeName = list_trees(inputs)
        inputs = [inputs, ]

    if (len(treeName) > 1):
        print("more then one tree in file ... specify, which tree to use")
        exit()



    print(">>> Load Events in gen acceptance")
    dfGen = [tree_to_df(root2array(i, treeName[0], selection=selection, branches=branches), 1) for i in inputs]
    dfGen = pd.concat(dfGen)

    dfGen = dfGen.rename(columns={
        'Muon_ID[muon_genRecoObj]_0': 'muon_ID',
        'Muon_ID[antiMuon_genRecoObj]_0': 'antiMuon_ID',
        'Muon_triggerBits[muon_genRecoObj]_0': 'muon_triggerBits',
        'Muon_triggerBits[antiMuon_genRecoObj]_0': 'antiMuon_triggerBits',
        'Muon_tkRelIso[muon_genRecoObj]_0': 'muon_tkIso',
        'Muon_tkRelIso[antiMuon_genRecoObj]_0': 'antiMuon_tkIso',
        'Muon_pfRelIso04_all[muon_genRecoObj]_0': 'muon_pfIso',
        'Muon_pfRelIso04_all[antiMuon_genRecoObj]_0': 'antiMuon_pfIso',
        'Muon_eta[muon_genRecoObj]_0': 'muon_eta',
        'Muon_eta[antiMuon_genRecoObj]_0': 'antiMuon_eta',
        'Muon_pt[muon_genRecoObj]_0': 'muon_pt',
        'Muon_pt[antiMuon_genRecoObj]_0': 'antiMuon_pt',