-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimalCut.py
127 lines (93 loc) · 3.99 KB
/
optimalCut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import numpy as np
import pandas as pd
import root_pandas
from matplotlib import gridspec
import matplotlib.pyplot as plt
%matplotlib inline
import ROOT as r
r.gROOT.LoadMacro('/belle2work/BelleII/belle2style/Belle2Style.C')
r.SetBelle2Style()
# Make nice looking plots
plt.rcParams.update({
'font.size': 20,
'figure.figsize': (12, 8),
})
signalfile ='/belle2work/sbasil/lambdacpi0/fromBelleII/xic_signal.root'
ccfile = '/belle2work/BelleII/XicToLcpi0/MC15rd/ccbar_temp.root'
mycols = ["Xic_DeltaM","Lambdac_M"]
mccols = ["Xic_isSignal","Lambdac_isSignal","Lambdac_genMotherPDG","pi0_genMotherPDG","pi0_mcPDG","Lambdac_mcPDG"]
input_vars = open("/belle2work/sbasil/lambdacpi0/fromBelleII/vars.txt").read().strip().split()
for i in input_vars:
mycols.append(i)
mycuts = 'Lambdac_M>2.25 & Lambdac_M<2.32 & Xic_DeltaM > 0.12 & Xic_DeltaM < 0.325'
df_sig = root_pandas.read_root(signalfile, key='xicp', columns=mycols+mccols, where=mycuts)
df_cc = root_pandas.read_root(ccfile, key='xicp', columns=mycols+mccols, where=mycuts)
charmbgs = '((abs(Lambdac_mcPDG)==411 and abs(Lambdac_genMotherPDG)==413) or (abs(Lambdac_mcPDG)==421 and abs(Lambdac_genMotherPDG)==423) or (abs(Lambdac_mcPDG)==431 and abs(Lambdac_genMotherPDG)==433))'
sigmast = '(pi0_mcPDG==111 and Lambdac_isSignal==1 and ((abs(Lambdac_genMotherPDG)==4212 and abs(pi0_genMotherPDG)==4212)))'
sigmastst = '(pi0_mcPDG==111 and Lambdac_isSignal==1 and ((abs(Lambdac_genMotherPDG)==4214 and abs(pi0_genMotherPDG)==4214)))'
cuts = mycuts
base_df = df_sig.query(cuts+' and Xic_isSignal==1')
#qq -> base_qq
base_qq = df_cc.query(cuts+' and not Xic_isSignal==1 and not Lambdac_isSignal==1 and not '+charmbgs+' and not '+sigmast+' and not '+sigmastst)
#other 5 bkgs
base_dst = df_cc.query(cuts+' and not Xic_isSignal==1 and '+charmbgs)
base_sigmastst = df_cc.query(cuts+' and not Xic_isSignal==1 and '+sigmastst)
base_sigmast = df_cc.query(cuts+' and not Xic_isSignal==1 and '+sigmast)
base_mis = df_sig.query(cuts+' and not Xic_isSignal==1')
base_Lc = df_cc.query(cuts+' and not Xic_isSignal==1 and Lambdac_isSignal==1 and not '+charmbgs+' and not '+sigmast+' and not '+sigmastst)
#form one base_bkg
frames = [base_qq, base_dst, base_sigmastst, base_Lc, base_mis, base_sigmast]
base_bkg = pd.concat(frames)
def optimalCutFinal(var):
nptrue = base_df[var].to_numpy()
npbkg = base_bkg[var].to_numpy()
maxtrue = max(nptrue)
mintrue = min(nptrue)
myrange=(mintrue,maxtrue)
signal_without_cuts = len(nptrue)
bkg_without_cuts = len(npbkg)
testvalue = mintrue
mytestvalue=0
mytotal=0
for i in range(100):
nptrue = nptrue[nptrue > testvalue]
npbkg = npbkg[npbkg > testvalue]
signal_efficiency = (len(nptrue))/signal_without_cuts
background_rejection = 1-(len(npbkg)/bkg_without_cuts)
total=signal_efficiency+background_rejection
if total > mytotal:
mytotal = total
mytestvalue = testvalue
testvalue+=((maxtrue-mintrue)/100)
print(mytotal,var + " > " + str(mytestvalue))
def optimalCutLessFinal(var):
nptrue = base_df[var].to_numpy()
npbkg = base_bkg[var].to_numpy()
maxtrue = max(nptrue)
mintrue = min(nptrue)
myrange=(mintrue,maxtrue)
signal_without_cuts = len(nptrue)
bkg_without_cuts = len(npbkg)
testvalue = maxtrue
mytestvalue=0
mytotal=0
for i in range(100):
nptrue = nptrue[nptrue < testvalue]
npbkg = npbkg[npbkg < testvalue]
signal_efficiency = (len(nptrue))/signal_without_cuts
background_rejection = 1-(len(npbkg)/bkg_without_cuts)
total=signal_efficiency+background_rejection
if total > mytotal:
mytotal = total
mytestvalue = testvalue
testvalue-=((maxtrue-mintrue)/100)
print(mytotal,var + " < " + str(mytestvalue))
for test in mycols[2:]:
try:
optimalCutFinal(test)
except:
print(test+": NaN")
try:
optimalCutLessFinal(test)
except:
print(test+": NaN")