diff options
author | Anthony LaTorre <tlatorre9@gmail.com> | 2011-08-18 11:11:55 -0400 |
---|---|---|
committer | Anthony LaTorre <tlatorre9@gmail.com> | 2011-08-18 11:11:55 -0400 |
commit | 9eae1bf247f3b275d7a6a876e6379a6d910f4786 (patch) | |
tree | fe5463674db8c993e3f4d1fdb1614800725808d6 | |
parent | f3589198dc7ffb765a2e76a8e608da1f169eb1ba (diff) | |
parent | 384f0b75d72cb034b8a148d4ae572f3f9cbe2454 (diff) | |
download | chroma-9eae1bf247f3b275d7a6a876e6379a6d910f4786.tar.gz chroma-9eae1bf247f3b275d7a6a876e6379a6d910f4786.tar.bz2 chroma-9eae1bf247f3b275d7a6a876e6379a6d910f4786.zip |
merge
-rw-r--r-- | detectors/__init__.py | 4 | ||||
-rw-r--r-- | detectors/miniclean.py | 80 | ||||
-rw-r--r-- | detectors/miniclean_cassettes.txt | 92 | ||||
-rw-r--r-- | detectors/miniclean_polygons.txt | 3 | ||||
-rw-r--r-- | itertoolset.py | 5 |
5 files changed, 184 insertions, 0 deletions
diff --git a/detectors/__init__.py b/detectors/__init__.py index f812058..726a985 100644 --- a/detectors/__init__.py +++ b/detectors/__init__.py @@ -1,5 +1,6 @@ from lbne import build_lbne from sno import build_sno as build_sno_detector +from miniclean import build_miniclean as build_miniclean_detector from chroma.camera import buildable import inspect @@ -34,6 +35,9 @@ def build_sno(): def build_real_sno(): return build_sno_detector(real_av=True) +@buildable('miniclean') +def build_miniclean(): + return build_miniclean_detector() def find(detector_name): members = globals() diff --git a/detectors/miniclean.py b/detectors/miniclean.py new file mode 100644 index 0000000..9223548 --- /dev/null +++ b/detectors/miniclean.py @@ -0,0 +1,80 @@ +import numpy as np +import numpy.linalg +import math +from chroma.make import linear_extrude, sphere +from chroma.geometry import * +from chroma.optics import * +from chroma.transform import rotate, make_rotation_matrix +from chroma.itertoolset import grouper +import os + + +dir = os.path.split(os.path.realpath(__file__))[0] + +def read_polygons(filename): + polygons = {} + with open(filename) as f: + for line in f: + parts = line.split() + idnum = int(parts[0]) + npoints = int(parts[1]) + points = np.zeros(shape=(npoints,2), dtype=np.float32) + for i, (x,y) in enumerate(grouper(2, parts[2:])): + points[i] = [float(x), float(y)] + polygons[idnum] = points + return polygons + +def read_cassettes(filename): + cassettes = [] + with open(filename) as f: + for line in f: + parts = line.split() + cassette_type = int(parts[0]) + rotation = np.transpose(np.array(map(float, parts[1:10]), dtype=np.float32).reshape((3,3))) + displacement = np.array(map(float, parts[10:13]), dtype=np.float32) + + cassettes.append({'type' : cassette_type, 'rotation' : rotation, + 'displacement' : displacement}) + + return cassettes + +def build_miniclean(real_av=False): + geo = Geometry() + + simple_iv = sphere(0.818) + geo.add_solid(Solid(simple_iv, water, vacuum, color=0x33FF0000)) + + polygons = read_polygons(os.path.join(dir, 'miniclean_polygons.txt')) + + height = 0.30 + polygon_types = {} + for polygon_id, polygon_points in polygons.items(): + mesh = linear_extrude(polygon_points[::-1,0]/1000.0, + polygon_points[::-1,1]/1000.0, + height=height, + center=[0,0,height/2]) + colors = np.zeros(len(mesh.triangles), dtype=np.uint32) + colors.fill(0x03CCCCFF) + # Color the faces on one end + triangles = mesh.assemble(group=True) + triangle_centroids = triangles.mean(axis=1) + face = triangle_centroids[:,2] < 0.1 + colors[face] = 0x1100FF00 + + polygon_types[polygon_id] = (mesh, colors) + + cassettes = read_cassettes(os.path.join(dir, 'miniclean_cassettes.txt')) + + geo.pmtids = [] + geo.pmt_id_map = {} + for i, cassette in enumerate(cassettes): + polygon_mesh, polygon_colors = polygon_types[cassette['type']] + solid = Solid(polygon_mesh, water, water, surface=shiny_surface, + color=polygon_colors) + + chroma_id = geo.add_solid(solid, cassette['rotation'], + cassette['displacement']/1000.0) + geo.pmt_id_map[chroma_id] = i + geo.pmtids.append(chroma_id) + + return geo diff --git a/detectors/miniclean_cassettes.txt b/detectors/miniclean_cassettes.txt new file mode 100644 index 0000000..a5e59f2 --- /dev/null +++ b/detectors/miniclean_cassettes.txt @@ -0,0 +1,92 @@ +1 1.000000 -0.000000 0.000000 0.000000 1.000000 0.000000 -0.000000 -0.000000 1.000000 0.000000 0.000000 435.000000 +1 0.361804 0.262866 -0.894427 -0.587785 0.809017 0.000000 0.723607 0.525731 0.447214 314.768956 228.692931 194.538037 +1 -0.138197 0.425326 -0.894427 -0.951057 -0.309017 0.000000 -0.276393 0.850651 0.447214 -120.230916 370.033081 194.538032 +1 -0.447214 0.000000 -0.894427 -0.000000 -1.000000 0.000000 -0.894427 0.000000 0.447214 -389.075740 0.000000 194.538090 +1 -0.138197 -0.425326 -0.894427 0.951057 -0.309017 -0.000000 -0.276393 -0.850651 0.447214 -120.230916 -370.033081 194.538032 +1 0.361804 -0.262866 -0.894427 0.587785 0.809017 -0.000000 0.723607 -0.525731 0.447214 314.768956 -228.692931 194.538037 +1 0.447214 0.000000 0.894427 0.000000 -1.000000 -0.000000 0.894427 0.000000 -0.447214 389.075740 0.000000 -194.538090 +1 0.138197 0.425326 0.894427 0.951057 -0.309017 0.000000 0.276393 0.850651 -0.447214 120.230916 370.033081 -194.538032 +1 -0.361804 0.262866 0.894427 0.587785 0.809017 -0.000000 -0.723607 0.525731 -0.447214 -314.768956 228.692931 -194.538037 +1 -0.361804 -0.262866 0.894427 -0.587785 0.809017 0.000000 -0.723607 -0.525731 -0.447214 -314.768956 -228.692931 -194.538037 +1 0.138197 -0.425326 0.894427 -0.951057 -0.309017 0.000000 0.276393 -0.850651 -0.447214 120.230916 -370.033081 -194.538032 +1 -1.000000 -0.000000 0.000000 -0.000000 1.000000 -0.000000 0.000000 -0.000000 -1.000000 0.000000 0.000000 -435.000000 +2 0.794654 -0.000000 -0.607062 0.000000 1.000000 0.000000 0.607062 -0.000000 0.794654 264.072061 0.000000 345.674625 +2 0.245561 0.755761 -0.607062 -0.951057 0.309016 0.000000 0.187592 0.577350 0.794654 81.602569 251.147409 345.674702 +2 -0.642889 0.467086 -0.607062 -0.587786 -0.809017 0.000000 -0.491123 0.356822 0.794655 -213.638636 155.217674 345.674713 +2 -0.642889 -0.467086 -0.607062 0.587786 -0.809017 0.000000 -0.491123 -0.356822 0.794655 -213.638636 -155.217674 345.674713 +2 0.245561 -0.755761 -0.607062 0.951057 0.309016 0.000000 0.187592 -0.577350 0.794654 81.602569 -251.147409 345.674702 +2 0.187592 -0.000000 -0.982247 0.000000 1.000000 -0.000000 0.982247 -0.000000 0.187592 427.277460 0.000000 81.602523 +2 0.057969 0.178411 -0.982247 -0.951056 0.309017 -0.000000 0.303531 0.934172 0.187592 132.036041 406.364992 81.602557 +2 -0.151765 0.110264 -0.982247 -0.587785 -0.809017 -0.000000 -0.794654 0.577350 0.187592 -345.674702 251.147409 81.602569 +2 -0.151765 -0.110264 -0.982247 0.587785 -0.809017 0.000000 -0.794654 -0.577350 0.187592 -345.674702 -251.147409 81.602569 +2 0.057969 -0.178411 -0.982247 0.951056 0.309017 0.000000 0.303531 -0.934172 0.187592 132.036041 -406.364992 81.602557 +2 -0.151765 -0.110264 -0.982247 -0.587785 0.809017 -0.000000 0.794654 0.577350 -0.187592 345.674702 251.147409 -81.602569 +2 0.057969 -0.178411 -0.982247 -0.951056 -0.309017 -0.000000 -0.303531 0.934172 -0.187592 -132.036041 406.364992 -81.602557 +2 0.187592 0.000000 -0.982247 -0.000000 -1.000000 -0.000000 -0.982247 0.000000 -0.187592 -427.277460 0.000000 -81.602523 +2 0.057969 0.178411 -0.982247 0.951056 -0.309017 0.000000 -0.303531 -0.934172 -0.187592 -132.036041 -406.364992 -81.602557 +2 -0.151765 0.110264 -0.982247 0.587785 0.809017 0.000000 0.794654 -0.577350 -0.187592 345.674702 -251.147409 -81.602569 +2 -0.642889 -0.467086 -0.607062 -0.587786 0.809017 0.000000 0.491123 0.356822 -0.794655 213.638636 155.217674 -345.674713 +2 0.245561 -0.755761 -0.607062 -0.951057 -0.309016 -0.000000 -0.187592 0.577350 -0.794654 -81.602569 251.147409 -345.674702 +2 0.794654 0.000000 -0.607062 -0.000000 -1.000000 -0.000000 -0.607062 0.000000 -0.794654 -264.072061 0.000000 -345.674625 +2 0.245561 0.755761 -0.607062 0.951057 -0.309016 -0.000000 -0.187592 -0.577350 -0.794654 -81.602569 -251.147409 -345.674702 +2 -0.642889 0.467086 -0.607062 0.587786 0.809017 -0.000000 0.491123 -0.356822 -0.794655 213.638636 -155.217674 -345.674713 +3 0.759856 0.552068 -0.343278 -0.587785 0.809017 0.000000 0.277718 0.201774 0.939234 120.807298 87.771665 408.566679 +3 -0.290240 0.893264 -0.343278 -0.951056 -0.309018 0.000000 -0.106079 0.326477 0.939234 -46.144352 142.017454 408.566692 +3 -0.939234 0.000000 -0.343279 -0.000000 -1.000000 0.000000 -0.343279 0.000000 0.939234 -149.326291 0.000000 408.566590 +3 -0.290240 -0.893264 -0.343278 0.951056 -0.309018 0.000000 -0.106079 -0.326477 0.939234 -46.144352 -142.017454 408.566692 +3 0.759856 -0.552068 -0.343278 0.587785 0.809017 0.000000 0.277718 -0.201774 0.939234 120.807298 -87.771665 408.566679 +3 -0.588217 -0.427365 0.686557 0.587785 -0.809017 -0.000000 0.555436 0.403548 0.727076 241.614708 175.543411 316.278111 +3 0.224679 -0.691490 0.686557 0.951056 0.309017 -0.000000 -0.212158 0.652955 0.727076 -92.288693 284.035318 316.277940 +3 0.727076 -0.000000 0.686557 0.000000 1.000000 0.000000 -0.686557 -0.000000 0.727076 -298.652292 0.000000 316.278056 +3 0.224679 0.691490 0.686557 -0.951056 0.309017 0.000000 -0.212158 -0.652955 0.727076 -92.288693 -284.035318 316.277940 +3 -0.588217 0.427365 0.686557 -0.587785 -0.809017 0.000000 0.555436 -0.403548 0.727076 241.614708 -175.543411 316.278111 +3 0.171639 -0.979432 0.106079 0.525731 -0.000000 -0.850651 0.833155 0.201774 0.514918 362.422317 87.771667 223.989282 +3 -0.878456 0.465900 0.106079 -0.162460 -0.500000 0.850651 0.449358 0.730026 0.514918 195.470612 317.561131 223.989214 +3 0.984535 -0.139422 0.106079 0.162460 0.500000 -0.850651 0.065560 0.854729 0.514918 28.518594 371.807049 223.989304 +3 -0.714555 -0.691490 0.106079 0.425325 -0.309017 0.850651 -0.555436 0.652955 0.514918 -241.614670 284.035427 223.989346 +3 0.436836 0.893264 0.106079 -0.425326 0.309017 -0.850651 -0.792636 0.326477 0.514918 -344.796720 142.017520 223.989388 +3 0.436836 -0.893264 0.106079 0.425326 0.309017 0.850651 -0.792636 -0.326477 0.514918 -344.796720 -142.017520 223.989388 +3 -0.714555 0.691490 0.106079 -0.425325 -0.309017 -0.850651 -0.555436 -0.652955 0.514918 -241.614670 -284.035427 223.989346 +3 0.984535 0.139422 0.106079 -0.162460 0.500000 0.850651 0.065560 -0.854729 0.514918 28.518594 -371.807049 223.989304 +3 -0.878456 -0.465900 0.106079 0.162460 -0.500000 -0.850651 0.449358 -0.730026 0.514918 195.470612 -317.561131 223.989214 +3 0.171639 0.979432 0.106079 -0.525731 -0.000000 0.850651 0.833155 -0.201774 0.514918 362.422317 -87.771667 223.989282 +3 0.351017 -0.427365 -0.833155 -0.262866 0.809017 -0.525731 0.898715 0.403548 0.171639 390.941108 175.543414 74.662977 +3 -0.297978 0.465899 -0.833155 -0.688191 0.500000 0.525731 0.661515 0.730026 0.171639 287.759023 317.561312 74.662963 +3 0.514918 0.201774 -0.833155 -0.850651 -0.000000 -0.525731 -0.106079 0.979432 0.171639 -46.144370 426.052975 74.662974 +3 -0.535177 -0.139423 -0.833155 -0.688191 -0.500000 0.525731 -0.489876 0.854729 0.171639 -213.096050 371.807095 74.662959 +3 -0.032780 0.552068 -0.833155 -0.262865 -0.809017 -0.525731 -0.964275 0.201774 0.171639 -419.459842 87.771736 74.663001 +3 -0.032780 -0.552068 -0.833155 0.262865 -0.809017 0.525731 -0.964275 -0.201774 0.171639 -419.459842 -87.771736 74.663001 +3 -0.535177 0.139423 -0.833155 0.688191 -0.500000 -0.525731 -0.489876 -0.854729 0.171639 -213.096050 -371.807095 74.662959 +3 0.514918 -0.201774 -0.833155 0.850651 -0.000000 0.525731 -0.106079 -0.979432 0.171639 -46.144370 -426.052975 74.662974 +3 -0.297978 -0.465899 -0.833155 0.688191 0.500000 -0.525731 0.661515 -0.730026 0.171639 287.759023 -317.561312 74.662963 +3 0.351017 0.427365 -0.833155 0.262866 0.809017 0.525731 0.898715 -0.403548 0.171639 390.941108 -175.543414 74.662977 +3 0.032780 0.552068 0.833155 0.262865 -0.809017 0.525731 0.964275 0.201774 -0.171639 419.459842 87.771736 -74.663001 +3 0.535177 -0.139423 0.833155 0.688191 -0.500000 -0.525731 0.489876 0.854729 -0.171639 213.096050 371.807095 -74.662959 +3 -0.514918 0.201774 0.833155 0.850651 -0.000000 0.525731 0.106079 0.979432 -0.171639 46.144370 426.052975 -74.662974 +3 0.297978 0.465899 0.833155 0.688191 0.500000 -0.525731 -0.661515 0.730026 -0.171639 -287.759023 317.561312 -74.662963 +3 -0.351017 -0.427365 0.833155 0.262866 0.809017 0.525731 -0.898715 0.403548 -0.171639 -390.941108 175.543414 -74.662977 +3 -0.351017 0.427365 0.833155 -0.262866 0.809017 -0.525731 -0.898715 -0.403548 -0.171639 -390.941108 -175.543414 -74.662977 +3 0.297978 -0.465899 0.833155 -0.688191 0.500000 0.525731 -0.661515 -0.730026 -0.171639 -287.759023 -317.561312 -74.662963 +3 -0.514918 -0.201774 0.833155 -0.850651 -0.000000 -0.525731 0.106079 -0.979432 -0.171639 46.144370 -426.052975 -74.662974 +3 0.535177 0.139423 0.833155 -0.688191 -0.500000 0.525731 0.489876 -0.854729 -0.171639 213.096050 -371.807095 -74.662959 +3 0.032780 -0.552068 0.833155 -0.262865 -0.809017 -0.525731 0.964275 -0.201774 -0.171639 419.459842 -87.771736 -74.663001 +3 -0.436836 0.893264 -0.106079 0.425326 0.309017 0.850651 0.792636 0.326477 -0.514918 344.796720 142.017520 -223.989388 +3 0.714555 -0.691490 -0.106079 -0.425325 -0.309017 -0.850651 0.555436 0.652955 -0.514918 241.614670 284.035427 -223.989346 +3 -0.984535 -0.139422 -0.106079 -0.162460 0.500000 0.850651 -0.065560 0.854729 -0.514918 -28.518594 371.807049 -223.989304 +3 0.878456 0.465900 -0.106079 0.162460 -0.500000 -0.850651 -0.449358 0.730026 -0.514918 -195.470612 317.561131 -223.989214 +3 -0.171639 -0.979432 -0.106079 -0.525731 -0.000000 0.850651 -0.833155 0.201774 -0.514918 -362.422317 87.771667 -223.989282 +3 -0.171639 0.979432 -0.106079 0.525731 -0.000000 -0.850651 -0.833155 -0.201774 -0.514918 -362.422317 -87.771667 -223.989282 +3 0.878456 -0.465900 -0.106079 -0.162460 -0.500000 0.850651 -0.449358 -0.730026 -0.514918 -195.470612 -317.561131 -223.989214 +3 -0.984535 0.139422 -0.106079 0.162460 0.500000 -0.850651 -0.065560 -0.854729 -0.514918 -28.518594 -371.807049 -223.989304 +3 0.714555 0.691490 -0.106079 0.425325 -0.309017 0.850651 0.555436 -0.652955 -0.514918 241.614670 -284.035427 -223.989346 +3 -0.436836 -0.893264 -0.106079 -0.425326 0.309017 -0.850651 0.792636 -0.326477 -0.514918 344.796720 -142.017520 -223.989388 +3 -0.727076 0.000000 -0.686557 0.000000 1.000000 -0.000000 0.686557 -0.000000 -0.727076 298.652292 0.000000 -316.278056 +3 -0.224679 -0.691490 -0.686557 -0.951056 0.309017 -0.000000 0.212158 0.652955 -0.727076 92.288693 284.035318 -316.277940 +3 0.588217 -0.427365 -0.686557 -0.587785 -0.809017 -0.000000 -0.555436 0.403548 -0.727076 -241.614708 175.543411 -316.278111 +3 0.588217 0.427365 -0.686557 0.587785 -0.809017 -0.000000 -0.555436 -0.403548 -0.727076 -241.614708 -175.543411 -316.278111 +3 -0.224679 0.691490 -0.686557 0.951056 0.309017 -0.000000 0.212158 -0.652955 -0.727076 92.288693 -284.035318 -316.277940 +3 0.939234 0.000000 0.343279 0.000000 -1.000000 -0.000000 0.343279 0.000000 -0.939234 149.326291 0.000000 -408.566590 +3 0.290240 0.893264 0.343278 0.951056 -0.309018 -0.000000 0.106079 0.326477 -0.939234 46.144352 142.017454 -408.566692 +3 -0.759856 0.552068 0.343278 0.587785 0.809017 -0.000000 -0.277718 0.201774 -0.939234 -120.807298 87.771665 -408.566679 +3 -0.759856 -0.552068 0.343278 -0.587785 0.809017 -0.000000 -0.277718 -0.201774 -0.939234 -120.807298 -87.771665 -408.566679 +3 0.290240 -0.893264 0.343278 -0.951056 -0.309018 -0.000000 0.106079 -0.326477 -0.939234 46.144352 -142.017454 -408.566692 diff --git a/detectors/miniclean_polygons.txt b/detectors/miniclean_polygons.txt new file mode 100644 index 0000000..594ed7d --- /dev/null +++ b/detectors/miniclean_polygons.txt @@ -0,0 +1,3 @@ +1 5 -66.925194 48.624001 25.563150 78.675285 82.724091 0.000000 25.563150 -78.675285 -66.925194 -48.624001 +3 6 -84.296997 48.624001 1.690830 107.301506 87.678658 61.878311 87.678658 -61.878311 1.690830 -107.301506 -84.296997 -48.624001 +2 6 -97.248001 0.000000 -48.624001 84.219238 48.624001 84.219238 97.248001 0.000000 48.624001 -84.219238 -48.624001 -84.219238 diff --git a/itertoolset.py b/itertoolset.py index a20d03b..314ba0b 100644 --- a/itertoolset.py +++ b/itertoolset.py @@ -1,6 +1,11 @@ from itertools import * import collections +def grouper(n, iterable, fillvalue=None): + "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" + args = [iter(iterable)] * n + return izip_longest(fillvalue=fillvalue, *args) + def roundrobin(*iterables): """roundrobin('ABC', 'D', 'EF') --> A D E B F C""" pending = len(iterables) |