Skip to content
Snippets Groups Projects
Commit d48a6b5f authored by Chao Peng's avatar Chao Peng
Browse files

Follow up: fix a typo for uncertainty

parent 93478735
No related branches found
No related tags found
1 merge request!282Add more info in E/p cut scan script, improve statistical uncertainty calculation
...@@ -170,6 +170,10 @@ if __name__ == '__main__': ...@@ -170,6 +170,10 @@ if __name__ == '__main__':
# print(dfr) # print(dfr)
# NOTE assumed e-pi only
nel = np.sum(el_hist, axis=1)[0]
npi = ntotal - nel
# prepare output container # prepare output container
best = OrderedDict( best = OrderedDict(
layer=int(nlayers + 1), layer=int(nlayers + 1),
...@@ -179,9 +183,13 @@ if __name__ == '__main__': ...@@ -179,9 +183,13 @@ if __name__ == '__main__':
) )
ep_dict = OrderedDict( ep_dict = OrderedDict(
info= OrderedDict( info= OrderedDict(
nsamples=int(ntotal), nsamples=OrderedDict(
total=int(ntotal),
electron=nel,
pion=npi,
),
targeted_efficiency=args.eff, targeted_efficiency=args.eff,
tracking_resolution=args.res tracking_resolution=args.res,
), ),
best=best, best=best,
) )
...@@ -200,7 +208,16 @@ if __name__ == '__main__': ...@@ -200,7 +208,16 @@ if __name__ == '__main__':
eff = np.sum(elvals[idx:])/np.sum(elvals) eff = np.sum(elvals[idx:])/np.sum(elvals)
# rejection power # rejection power
rej = np.sum(pivals[:idx])/np.sum(pivals) rej = np.sum(pivals[:idx])/np.sum(pivals)
ep_dict['layer_{:d}'.format(i + 1)] = {'ep_cut': ep_cut, 'el_eff': eff, 'pi_rej': rej} ep_dict['layer_{:d}'.format(i + 1)] = OrderedDict(
ep_cut=ep_cut,
el_eff=eff,
pi_rej=rej,
nsamples_after_cut=OrderedDict(
total=np.sum(elvals[idx:] + pivals[idx:]) ,
electron=np.sum(elvals[idx:]),
pion=np.sum(pivals[idx:]),
)
)
# greater or [equal] here because always favor the cut on more layers # greater or [equal] here because always favor the cut on more layers
if rej >= best['pi_rej']: if rej >= best['pi_rej']:
best.update({ best.update({
...@@ -230,15 +247,16 @@ if __name__ == '__main__': ...@@ -230,15 +247,16 @@ if __name__ == '__main__':
cuts_rej = np.array([c.get('pi_rej') for c in cuts]) cuts_rej = np.array([c.get('pi_rej') for c in cuts])
# estimated uncertainty (binomial) # estimated uncertainty (binomial)
nerr = np.sqrt(cuts_rej*(1. - cuts_rej)*ntotal) # npq nerr = np.sqrt(cuts_rej*(1. - cuts_rej)*npi) # npq
# leftover pions # leftover pions
nres = ntotal * (1. - cuts_rej) nres = npi * (1. - cuts_rej)
nres_lo = np.clip(nres - nerr, 1, ntotal) nres_lo = np.clip(nres - nerr, 1, npi)
nres_hi = np.clip(nres + nerr, 1, ntotal) nres_hi = np.clip(nres + nerr, 1, npi)
# rejection power # rejection power
rej_pow = ntotal/nres rej_pow = npi/nres
rej_err = (rej_pow - ntotal/nres_hi, ntotal/nres_lo - rej_pow) # NOTE: assumed half of them are pions, so need a factor of sqrt(2)
rej_err = ((rej_pow - npi/nres_hi)*np.sqrt(2), (npi/nres_lo - rej_pow)*np.sqrt(2))
fig, ax1 = plt.subplots(figsize=(8, 8)) fig, ax1 = plt.subplots(figsize=(8, 8))
ax2 = ax1.twinx() ax2 = ax1.twinx()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment