summaryrefslogtreecommitdiff
path: root/solids/pmts.py
blob: 6b105227cc7d9a4d1671bb88adc5823623dabc9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import sys

dir = os.path.split(os.path.realpath(__file__))[0]
sys.path.append(dir + '/..')

import numpy as np
from geometry import Solid
from make import rotate_extrude
from optics import *
from tools import read_csv, offset

def get_lc_profile(radii, a, b, d, rmin, rmax):
    c = -b*np.sqrt(1 - (rmin-d)**2/a**2)
    return -c - b*np.sqrt(1-(radii-d)**2/a**2)

def build_light_collector(pmt, a, b, d, rmin, rmax, npoints=10):
    if not isinstance(pmt, Solid):
        raise Exception('`pmt` must be an instance of %s' % Solid)

    lc_radii = np.linspace(rmin, rmax, npoints)
    lc_profile = get_lc_profile(lc_radii, a, b, d, rmin, rmax)

    pmt_face_profile = pmt.profile[pmt.profile[:,1] > -1e-3]

    lc_offset = np.interp(lc_radii[0], list(reversed(pmt_face_profile[:,0])), list(reversed(pmt_face_profile[:,1])))

    lc_mesh = rotate_extrude(lc_radii, lc_profile + lc_offset, pmt.theta)

    return Solid(lc_mesh, pmt.outer_material, pmt.outer_material, color=0xff0000, surface=shiny_surface)

def build_pmt(filename, glass_thickness, outer_material=water, theta=np.pi/8):
    profile = read_csv(filename)

    # slice profile in half
    profile = profile[profile[:,0] < 0]
    profile[:,0] = -profile[:,0]
    # order profile from base to face
    profile = profile[np.argsort(profile[:,1])]
    # set x coordinate to 0.0 for first and last profile along the profile
    # so that the mesh is closed
    profile[0,0] = 0.0
    profile[-1,0] = 0.0
    # convert mm -> m
    profile /= 1000.0

    offset_profile = offset(profile, -glass_thickness)

    outer_envelope_mesh = rotate_extrude(profile[:,0], profile[:,1], theta)
    inner_envelope_mesh = rotate_extrude(offset_profile[:,0], offset_profile[:,1], theta)

    outer_envelope = Solid(outer_envelope_mesh, glass, outer_material)

    photocathode = np.mean(inner_envelope_mesh[:], axis=1)[:,1] > 0

    inner_envelope = Solid(inner_envelope_mesh, vacuum, glass, surface=np.where(photocathode, r7081hqe_photocathode, shiny_surface), color=np.where(photocathode, 0xff00, 0xff0000))

    pmt = outer_envelope + inner_envelope

    # profile points, outer_material, and theta are used to construct the
    # light collector
    pmt.profile = profile
    pmt.outer_material = outer_material
    pmt.theta = theta

    return pmt