summaryrefslogtreecommitdiff
path: root/generator/vertex.py
diff options
context:
space:
mode:
authorAnthony LaTorre <tlatorre9@gmail.com>2011-08-29 09:46:36 -0400
committerAnthony LaTorre <tlatorre9@gmail.com>2011-08-29 09:46:36 -0400
commit7e2a7e988031c22898249f3801aa0d3c690bb729 (patch)
tree2ef5d982f9dec9f90ea54e6481d3b3b88048fb3d /generator/vertex.py
parent1943931e95711f9676b5585f901c5fff25b7d759 (diff)
downloadchroma-7e2a7e988031c22898249f3801aa0d3c690bb729.tar.gz
chroma-7e2a7e988031c22898249f3801aa0d3c690bb729.tar.bz2
chroma-7e2a7e988031c22898249f3801aa0d3c690bb729.zip
add generator which yields drawn randomly from a histogram interpreted as a pdf.
Diffstat (limited to 'generator/vertex.py')
-rw-r--r--generator/vertex.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/generator/vertex.py b/generator/vertex.py
index 5626541..450c0e4 100644
--- a/generator/vertex.py
+++ b/generator/vertex.py
@@ -4,9 +4,18 @@ from itertools import izip, count
from chroma.pi0 import pi0_decay
from chroma.event import Event, Subtrack
from chroma.sample import uniform_sphere
+from chroma.itertoolset import repeat_func
# generator parts for use with gun()
+def from_histogram(h):
+ "Yield values drawn randomly from the histogram `h` interpreted as a pdf."
+ pdf = h.hist/h.hist.sum()
+ cdf = np.cumsum(pdf)
+
+ for x in repeat_func(np.random.random_sample):
+ yield h.bincenters[np.searchsorted(cdf, x)]
+
def constant(obj):
while True:
yield obj