From 375046868564e4911ab3c6094e7e7fc92edd76c6 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Fri, 26 Aug 2011 18:28:56 -0400 Subject: vertex.isotropic() yields values from transform.uniform_sphere() --- generator/vertex.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'generator/vertex.py') diff --git a/generator/vertex.py b/generator/vertex.py index 139d675..7bf9ba0 100644 --- a/generator/vertex.py +++ b/generator/vertex.py @@ -1,10 +1,9 @@ -import itertools import numpy as np -from math import sin, cos, sqrt -import copy +from itertools import izip, count -import chroma.pi0 as pi0 +from chroma.pi0 import pi0_decay from chroma.event import Event, Subtrack +from chroma.transform import uniform_sphere # generator parts for use with gun() @@ -14,13 +13,7 @@ def constant(obj): def isotropic(): while True: - cos_theta = np.random.uniform(-1.0, 1.0) - sin_theta = sqrt(1.0 - cos_theta**2) - phi = np.random.uniform(0.0, 2*np.pi) - direction = np.array([sin_theta * cos(phi), - sin_theta * sin(phi), - cos_theta]) - yield direction + yield uniform_sphere() def line_segment(point1, point2): while True: @@ -40,7 +33,7 @@ def flat(e_lo, e_hi): def particle_gun(particle_name, position, direction, total_energy, start_id=0): for i, ev_particle, ev_position, ev_direction, ev_total_energy in \ - itertools.izip(itertools.count(start_id), + izip(count(start_id), particle_name, position, direction, total_energy): ev = Event(event_id=i, particle_name=ev_particle, gen_position=ev_position, gen_direction=ev_direction, gen_total_energy=ev_total_energy) @@ -48,7 +41,7 @@ def particle_gun(particle_name, position, direction, total_energy, start_id=0): def pi0_gun(pi0_position, pi0_direction, pi0_total_energy, start_id=0): for i, ev_position, ev_direction, ev_total_energy in \ - itertools.izip(itertools.count(start_id), pi0_position, pi0_direction, pi0_total_energy): + izip(count(start_id), pi0_position, pi0_direction, pi0_total_energy): ev = Event(event_id=i, particle_name='pi0', gen_position=ev_position, gen_direction=ev_direction, gen_total_energy=ev_total_energy) @@ -59,7 +52,7 @@ def pi0_gun(pi0_position, pi0_direction, pi0_total_energy, start_id=0): theta_rest = np.arccos(cos_theta_rest) phi_rest = np.random.random_sample() * 2 * np.pi - (gamma1_e, gamma1_dir), (gamma2_e, gamma2_dir) = pi0.pi0_decay(energy=ev_total_energy, + (gamma1_e, gamma1_dir), (gamma2_e, gamma2_dir) = pi0_decay(energy=ev_total_energy, direction=ev_direction, theta=theta_rest, phi=phi_rest) -- cgit From 28182873d1c8a8e1d3de38e3a4440490680683c5 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Fri, 26 Aug 2011 18:32:03 -0400 Subject: woops! import from wrong module in last commit --- generator/vertex.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'generator/vertex.py') diff --git a/generator/vertex.py b/generator/vertex.py index 7bf9ba0..5626541 100644 --- a/generator/vertex.py +++ b/generator/vertex.py @@ -3,7 +3,7 @@ from itertools import izip, count from chroma.pi0 import pi0_decay from chroma.event import Event, Subtrack -from chroma.transform import uniform_sphere +from chroma.sample import uniform_sphere # generator parts for use with gun() -- cgit From 7e2a7e988031c22898249f3801aa0d3c690bb729 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Mon, 29 Aug 2011 09:46:36 -0400 Subject: add generator which yields drawn randomly from a histogram interpreted as a pdf. --- generator/vertex.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'generator/vertex.py') 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 -- cgit From 707ca1b366f11032682cc864ca2848905e6b485c Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Fri, 2 Sep 2011 12:12:38 -0400 Subject: update event structure. break gpu.GPU class into separate smaller independent classes. --- generator/vertex.py | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) (limited to 'generator/vertex.py') diff --git a/generator/vertex.py b/generator/vertex.py index 450c0e4..5521d6b 100644 --- a/generator/vertex.py +++ b/generator/vertex.py @@ -2,7 +2,7 @@ import numpy as np from itertools import izip, count from chroma.pi0 import pi0_decay -from chroma.event import Event, Subtrack +from chroma import event from chroma.sample import uniform_sphere from chroma.itertoolset import repeat_func @@ -40,43 +40,34 @@ def flat(e_lo, e_hi): # vertex generators -def particle_gun(particle_name, position, direction, total_energy, start_id=0): - for i, ev_particle, ev_position, ev_direction, ev_total_energy in \ - izip(count(start_id), - particle_name, position, direction, total_energy): - ev = Event(event_id=i, particle_name=ev_particle, - gen_position=ev_position, gen_direction=ev_direction, gen_total_energy=ev_total_energy) - yield ev +def particle_gun(particle_name_iter, pos_iter, dir_iter, ke_iter, start_id=0): + for i, particle_name, pos, dir, ke in izip(count(start_id), particle_name_iter, pos_iter, dir_iter, ke_iter): + dir /= np.linalg.norm(dir) + vertex = event.Vertex(particle_name, pos, dir, None, ke) + ev_vertex = event.Event(i, vertex, [vertex]) + yield ev_vertex -def pi0_gun(pi0_position, pi0_direction, pi0_total_energy, start_id=0): - for i, ev_position, ev_direction, ev_total_energy in \ - izip(count(start_id), pi0_position, pi0_direction, pi0_total_energy): +def pi0_gun(pos_iter, dir_iter, ke_iter, start_id=0): + for i, pos, dir, ke in izip(count(start_id), pos_iter, dir_iter, ke_iter): + dir /= np.linalg.norm(dir) + primary_vertex = event.Vertex('pi0', pos, dir, None, ke) - ev = Event(event_id=i, particle_name='pi0', - gen_position=ev_position, gen_direction=ev_direction, gen_total_energy=ev_total_energy) - - ev_direction = ev_direction / np.linalg.norm(ev_direction) - cos_theta_rest = np.random.random_sample() * 2 - 1 theta_rest = np.arccos(cos_theta_rest) phi_rest = np.random.random_sample() * 2 * np.pi - (gamma1_e, gamma1_dir), (gamma2_e, gamma2_dir) = pi0_decay(energy=ev_total_energy, - direction=ev_direction, - theta=theta_rest, - phi=phi_rest) + (gamma1_e, gamma1_dir), (gamma2_e, gamma2_dir) = \ + pi0_decay(ke+134.9766, dir, theta_rest, phi_rest) + + gamma1_vertex = event.Vertex('gamma', pos, gamma1_dir, None, gamma1_e) + gamma2_vertex = event.Vertex('gamma', pos, gamma2_dir, None, gamma2_e) + + ev_vertex = event.Event(i, primary_vertex, [gamma1_vertex, gamma2_vertex]) - ev.subtracks = [Subtrack(particle_name='gamma', position=ev_position, direction=gamma1_dir, - start_time=0.0, total_energy=gamma1_e), - Subtrack(particle_name='gamma', position=ev_position, direction=gamma2_dir, - start_time=0.0, total_energy=gamma2_e)] - yield ev + yield ev_vertex -def constant_particle_gun(particle_name, position, direction, total_energy, - start_id=0): +def constant_particle_gun(particle_name, pos, dir, ke, start_id=0): '''Convenience wrapper around particle gun that assumes all arguments are constants, rather than generators.''' - return particle_gun(constant(particle_name), constant(position), - constant(direction), constant(total_energy), - start_id=start_id) + return particle_gun(constant(particle_name), constant(pos), constant(dir), constant(ke), start_id=start_id) -- cgit