1 '''Defines the BeamDump class for theia.'''
2
3
4
5
6
7
8
9
10 import numpy as np
11 from ..helpers import settings
12 from ..helpers.geometry import rectToSph, linePlaneInter, lineCylInter
13 from ..helpers.tools import formatter
14 from ..helpers.units import deg, pi
15 from .component import SetupComponent
16
18 '''
19
20 BeamDump class.
21
22 This class represents components on which rays stop. They have cylindrical
23 symmetry and stop beams on all their faces. They can represent baffles
24 for example.
25
26 *=== Attributes ===*
27 SetupCount (inherited): class attribute, counts all setup components.
28 [integer]
29 HRCenter (inherited): center of the principal face of the BeamDump in space.
30 [3D vector]
31 HRnorm (inherited): normal unitary vector the this principal face,
32 supposed to point outside the media. [3D vector]
33 Thick (inherited): thickness of the dump, counted in opposite direction to
34 HRNorm. [float]
35 Dia (inherited): diameter of the component. [float]
36 Name (inherited): name of the component. [string]
37 Ref (inherited): reference string (for keeping track with the lab). [string]
38
39 '''
40
41 - def __init__(self, X = 0., Y = 0., Z = 0., Theta = pi/2., Phi = 0.,
42 Name = 'BeamDump', Ref = None,
43 Thickness = 2.e-2, Diameter = 5.e-2):
44 '''BeamDump initializer.
45
46 Parameters are the attributes.
47
48 Returns a BeamDump.
49
50 '''
51
52 Thickness = float(Thickness)
53 Diameter = float(Diameter)
54
55
56 Norm = np.array([np.sin(Theta)*np.cos(Phi),
57 np.sin(Theta) * np.sin(Phi),
58 np.cos(Theta)], dtype = np.float64)
59
60 HRCenter = np.array([X, Y, Z], dtype = np.float64)
61
62
63 super(BeamDump, self).__init__(Name = Name, Ref = Ref,
64 Diameter = Diameter, HRCenter = HRCenter, HRNorm = Norm,
65 Thickness = Thickness)
66
68 '''Return the list of lines needed to print the object.
69 '''
70 ans = []
71 ans.append("BeamDump: " + self.Name + " (" + self.Ref + ") {")
72 ans.append("Thick: " + str(self.Thick) + "m")
73 ans.append("Diameter: " + str(self.Dia) + "m")
74 ans.append("Center: " + str(self.HRCenter))
75 sph = rectToSph(self.HRNorm)
76 ans.append("Norm: (" + str(sph[0]/deg) + ', ' \
77 + str(sph[1]/deg) + ')deg')
78 ans.append("}")
79
80 return ans
81
83 '''Determine if a beam hits the BeamDump.
84
85 This uses the line***Inter functions from the geometry module to find
86 characteristics of impact of beams on beamdumps.
87
88 beam: incoming beam. [GaussianBeam]
89
90 Returns a dictionary with keys:
91 'isHit': whether the beam hits the dump. [boolean]
92 'intersection point': point in space where it is first hit.
93 [3D vector]
94 'face': to indicate which face is first hit, can be 'HR', 'AR' or
95 'side'. [string]
96 'distance': geometrical distance from beam origin to impact. [float]
97
98 '''
99
100 noInterDict = {'isHit': False,
101 'intersection point': np.array([0., 0., 0.],
102 dtype=np.float64),
103 'face': None,
104 'distance': 0.}
105
106
107 HRDict = linePlaneInter(beam.Pos, beam.Dir, self.HRCenter,
108 self.HRNorm, self.Dia)
109
110 SideDict =lineCylInter(beam.Pos, beam.Dir,
111 self.HRCenter, self.HRNorm,
112 self.Thick, self.Dia)
113
114 ARCenter = self.HRCenter - self.Thick*self.HRNorm
115
116 ARDict = linePlaneInter(beam.Pos, beam.Dir, ARCenter,
117 - self.HRNorm, self.Dia)
118
119
120 HRDict['face'] = 'HR'
121 ARDict['face'] = 'AR'
122 SideDict['face'] = 'Side'
123
124
125 hitFaces = filter(lambda dic: dic['isHit'], [HRDict, ARDict, SideDict])
126
127 if len(hitFaces) == 0:
128 return noInterDict
129
130 dist = hitFaces[0]['distance']
131 j=0
132
133 for i in range(len(hitFaces)):
134 if hitFaces[i]['distance'] < dist:
135 dist = hitFaces[i]['distance']
136 j=i
137
138 return {'isHit': True,
139 'intersection point': hitFaces[j]['intersection point'],
140 'face': hitFaces[j]['face'],
141 'distance': hitFaces[j]['distance']
142 }
143
144 - def hit(self, beam, order, threshold):
145 '''Compute the refracted and reflected beams after interaction.
146
147 BeamDumps always stop beams.
148
149 beam: incident beam. [GaussianBeam]
150 order: maximum strayness of daughter beams, which are not returned if
151 their strayness is over this order. [integer]
152 threshold: idem for the power of the daughter beams. [float]
153
154 Returns a dictionary of beams with keys:
155 't': None
156 'r': None
157
158 '''
159
160 dic = self.isHit(beam)
161 beam.Length = dic['distance']
162 beam.OptDist = beam.N * beam.Length
163 if settings.info:
164 print "theia: Info: Reached beam stop (" + beam.Ref + ' on '\
165 + self.Ref + ').'
166
167 return {'r': None, 't': None}
168