7 return np.divide(numer.astype(np.float), denom.astype(np.float), out=np.full(numer.size, np.nan), where=denom!=0)
11 trig_n1 = np.random.poisson(trig_n1, ntoys)
12 trig_n2 = np.random.poisson(trig_n2, ntoys)
14 eff = np.divide(1.0, np.divide(
nan_divide(trig_n1, trig_n2), 2.0) + np.full(ntoys, 1.0))
15 nonan_eff = eff[~np.isnan(eff)]
16 if nonan_eff.size > 0:
17 out_eff = np.median(nonan_eff)
18 out_err = nonan_eff.std()
23 return out_eff, out_err, eff, (trig_n1 + trig_n2)
27 matchos = np.random.poisson(matchos, ntoys)
28 matchss = np.random.poisson(matchss, ntoys)
29 nomatchos = np.random.poisson(nomatchos, ntoys)
30 nomatchss = np.random.poisson(nomatchss, ntoys)
32 numer = matchos - matchss
33 denom = (matchos - matchss) + (nomatchos - nomatchss)
36 nonan_eff = eff[~np.isnan(eff)]
37 if nonan_eff.size > 0:
38 out_eff = np.median(nonan_eff)
39 out_err = nonan_eff.std()
44 return out_eff, out_err, eff
46 def electron_toy_recoeff(matchos_peak, matchos_tail, matchss_tail, nomatchos_peak, nomatchos_tail, templateos_peak, templateos_tail, templatess_tail, ntoys=1000):
47 matchos_peak = np.random.poisson(matchos_peak, ntoys)
48 matchos_tail = np.random.poisson(matchos_tail, ntoys)
49 matchss_tail = np.random.poisson(matchss_tail, ntoys)
50 nomatchos_peak = np.random.poisson(nomatchos_peak, ntoys)
51 nomatchos_tail = np.random.poisson(nomatchos_tail, ntoys)
53 templateos_peak = np.random.poisson(templateos_peak, ntoys)
54 templateos_tail = np.random.poisson(templateos_tail, ntoys)
55 templatess_tail = np.random.poisson(templatess_tail, ntoys)
57 totalos_peak = matchos_peak + nomatchos_peak
58 totalos_tail = matchos_tail + nomatchos_tail
61 n2 = np.multiply(templateos_peak,
nan_divide(matchss_tail, templatess_tail))
63 d2 = np.multiply(templateos_peak,
nan_divide(nomatchos_tail, templateos_tail))
64 iterative_eff =
nan_divide((n1 - n2), (d1 - d2))
66 d2 = np.multiply(templateos_peak,
nan_divide((totalos_tail -
nan_divide(matchos_tail, iterative_eff)), templateos_tail))
68 nonan_eff = eff[~np.isnan(eff)]
69 if nonan_eff.size > 0:
70 out_eff = np.median(nonan_eff)
71 out_err = nonan_eff.std()
76 return out_eff, out_err, eff