summaryrefslogtreecommitdiff
path: root/threadtest.py
diff options
context:
space:
mode:
Diffstat (limited to 'threadtest.py')
-rw-r--r--threadtest.py25
1 files changed, 6 insertions, 19 deletions
diff --git a/threadtest.py b/threadtest.py
index c9854a7..6cc9c07 100644
--- a/threadtest.py
+++ b/threadtest.py
@@ -11,44 +11,31 @@ import math
jobs = Queue()
output = Queue()
-def create_job(position=(0,0,0), nphotons=5000, max_steps=10):
- positions = np.tile(position, nphotons).reshape((nphotons, 3))
- directions = uniform_sphere(nphotons)
- polarizations = uniform_sphere(nphotons)
- wavelengths = np.random.uniform(200, 800, size=nphotons)
- times = np.zeros(nphotons)
- states = -np.ones(nphotons)
- last_hit_triangles = -np.ones(nphotons)
-
- return Job(positions, directions, wavelengths, polarizations, times,
- states, last_hit_triangles, max_steps)
-
def generate_event(detector, position=(0,0,0), nphotons=5000):
- jobs.put(create_job(position, nphotons))
+ jobs.put((gpuarray.vec.make_float3(*position), nphotons))
jobs.join()
- job = output.get()
+ earliest_times = output.get()
- pmt_times = job.earliest_times[detector.pmtids]
+ pmt_times = earliest_times[detector.pmtids]
event_times = [ (i, t) for i, t in zip(detector.pmtids, pmt_times) if t < 1e8 ]
print '%i hit pmts' % len(event_times)
return event_times
def likelihood(detector, event_times, position=(0,0,0), nphotons=5000, neval=100):
for i in range(neval):
- jobs.put(create_job(position, nphotons))
+ jobs.put((gpuarray.vec.make_float3(*position), nphotons))
jobs.join()
t = np.zeros(shape=(neval, max(detector.pmtids)+1), dtype=np.float32)
for i in range(neval):
- job = output.get()
- t[i] = job.earliest_times
+ t[i] = output.get()
log_likelihood = 0.0
log_likelihood_variance = 0.0
for i, time in event_times:
h = Histogram(500, (-0.5e-9, 99.5e-9))
- h.fill(t[:,i])
+ h.fill(t[:,i][t[:,i] < 1e8])
if h.nentries > 0:
h.normalize()