ATLAS Offline Software
Loading...
Searching...
No Matches
toys.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
4import numpy as np
5
6def nan_divide(numer, denom):
7 return np.divide(numer.astype(np.float), denom.astype(np.float), out=np.full(numer.size, np.nan), where=denom!=0)
8
9
10def toy_trigeff(trig_n1, trig_n2, ntoys=10000):
11 trig_n1 = np.random.poisson(trig_n1, ntoys)
12 trig_n2 = np.random.poisson(trig_n2, ntoys)
13
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()
19 else:
20 out_eff = 0.0
21 out_err = 0.0
22
23 return out_eff, out_err, eff, (trig_n1 + trig_n2)
24
25
26def muon_toy_recoeff(matchos, matchss, nomatchos, nomatchss, ntoys=10000):
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)
31
32 numer = matchos - matchss
33 denom = (matchos - matchss) + (nomatchos - nomatchss)
34
35 eff = nan_divide(numer, denom)
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()
40 else:
41 out_eff = 0.0
42 out_err = 0.0
43
44 return out_eff, out_err, eff
45
46def 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)
52
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)
56
57 totalos_peak = matchos_peak + nomatchos_peak
58 totalos_tail = matchos_tail + nomatchos_tail
59
60 n1 = matchos_peak
61 n2 = np.multiply(templateos_peak, nan_divide(matchss_tail, templatess_tail))
62 d1 = totalos_peak
63 d2 = np.multiply(templateos_peak, nan_divide(nomatchos_tail, templateos_tail))
64 iterative_eff = nan_divide((n1 - n2), (d1 - d2))
65
66 d2 = np.multiply(templateos_peak, nan_divide((totalos_tail - nan_divide(matchos_tail, iterative_eff)), templateos_tail))
67 eff = nan_divide((n1 - n2), (d1 - d2))
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()
72 else:
73 out_eff = 0.0
74 out_err = 0.0
75
76 return out_eff, out_err, eff
nan_divide(numer, denom)
Definition toys.py:6
toy_trigeff(trig_n1, trig_n2, ntoys=10000)
Definition toys.py:10
muon_toy_recoeff(matchos, matchss, nomatchos, nomatchss, ntoys=10000)
Definition toys.py:26
electron_toy_recoeff(matchos_peak, matchos_tail, matchss_tail, nomatchos_peak, nomatchos_tail, templateos_peak, templateos_tail, templatess_tail, ntoys=1000)
Definition toys.py:46