summaryrefslogtreecommitdiff
path: root/detectors/lbne.py
blob: 54e11a998d0eb863bded730ed0742288db980d1f (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy as np
from copy import deepcopy
from chroma import layout
from chroma.stl import read_stl
from chroma.transform import rotate
from chroma.geometry import Geometry, Solid
from chroma.materials import glass, h2o
from chroma.photon import uniform_sphere
from chroma.gpu import GPU
from itertools import product
from histogram import *

endcap_spacing = .485

radius = 25.0/10.0
height = 50.0/10.0

nstrings = 324//10
pmts_per_string = 102//10

class LBNE(Geometry):
    """Miniature version of the LBNE water Cerenkov detector geometry."""
    def __init__(self):
        super(LBNE, self).__init__()

        pmt_mesh = read_stl(layout.models + '/hamamatsu_12inch.stl')/1000.0
        pmt_solid = Solid(pmt_mesh, glass, h2o)

        # construct the barrel
        for i in range(pmts_per_string):
            for j in range(nstrings):
                pmt = deepcopy(pmt_solid)
                pmt.mesh += (-radius,0,-height/2+i*height/(pmts_per_string-1))
                pmt.mesh = rotate(pmt.mesh, j*2*np.pi/nstrings, (0,0,1))
                self.add_solid(pmt)

        # construct the top endcap
        for x, y in np.array(tuple(product(\
                    np.arange(-radius+0.075, radius, endcap_spacing),
                    np.arange(-radius+0.075, radius, endcap_spacing)))):
            if np.sqrt(x**2 + y**2) <= radius:
                pmt = deepcopy(pmt_solid)
                pmt.mesh = rotate(pmt.mesh, -np.pi/2, (0,1,0))
                pmt.mesh += (x,y,+height/2+height/(pmts_per_string-1)/2)
                self.add_solid(pmt)

        # construct the bottom endcap
        for x, y in np.array(tuple(product(\
                    np.arange(-radius+0.075, radius, endcap_spacing),
                    np.arange(-radius+0.075, radius, endcap_spacing)))):
            if np.sqrt(x**2 + y**2) <= radius:
                pmt = deepcopy(pmt_solid)
                pmt.mesh = rotate(pmt.mesh, +np.pi/2, (0,1,0))
                pmt.mesh += (x,y,-height/2-height/(pmts_per_string-1)/2)
                self.add_solid(pmt)

    def load_geometry(self):
        self.gpu = GPU()
        self.texrefs = self.gpu.load_geometry(self)
        self.propagate = self.gpu.get_function('propagate')

if __name__ == '__main__':
    import sys
    import optparse
    import pickle

    parser = optparse.OptionParser('prog filename')
    parser.add_option('-b', '--bits', type='int', dest='bits',
                      help='bits for z-ordering space axes', default=6)
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit(parser.format_help())

    lbne = LBNE()
    lbne.build(bits=options.bits)

    f = open(args[0], 'wb')
    pickle.dump(lbne, f)
    f.close()