-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_utils.py
More file actions
26 lines (24 loc) · 1.02 KB
/
plot_utils.py
File metadata and controls
26 lines (24 loc) · 1.02 KB
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
import numpy as np
def NormOne(a):
return np.ones_like(a)/len(a)
def Eff(df,var,query,acceptance,bin_edges,absval=False):
bin_centers = 0.5*(bin_edges[1:]+bin_edges[:-1])
bins = []
bin_eff = []
bin_err = []
for i in range(len(bin_centers)):
binmin = bin_edges[i]
binmax = bin_edges[i+1]
bincut = '%s > %f and %s < %f'%(var,binmin,var,binmax)
if (absval == True):
bincut = '(%s > %f and %s < %f) or (%s > -%f and %s < -%f)'%(var,binmin,var,binmax,var,binmax,var,binmin)
if (acceptance != ''): bincut += ' and %s'%acceptance
df_tmp = df.query(bincut) # cut on bin range for desired var.
df_sub = df_tmp.query(query) # apply constrain
if (df_tmp.shape[0] == 0): continue
eff = df_sub.shape[0] / float( df_tmp.shape[0] )
err = np.sqrt( eff*(1-eff)/df_tmp.shape[0] )
bin_eff.append( eff )
bin_err.append( err )
bins.append(bin_centers[i])
return np.array(bins),np.array(bin_eff),np.array(bin_err)