1 '''Defines the Ghost class for theia.'''
2
3
4
5
6
7
8
9
10 import numpy as np
11 from ..helpers.geometry import rectToSph, linePlaneInter
12 from ..helpers.units import deg, pi
13 from .component import SetupComponent
14 from .beam import GaussianBeam
15
16 -class Ghost(SetupComponent):
17 '''
18
19 Ghost class.
20
21 This class represents surfaces which don't interact with the beams. They
22 just transmit the same beam, and may be useful to monitor the beams on their
23 way, without having to calculate the Q yourself if you're looking for the
24 Q at another place than the origin of the beam.
25
26 Ghost surfaces basically have a null thickness and transmit the beams.
27
28 *=== Attributes ===*
29 SetupCount (inherited): class attribute, counts all setup components.
30 [integer]
31 Name: class attribute. [string]
32 HRCenter (inherited): center of the principal face of the Ghost in space.
33 [3D vector]
34 HRnorm (inherited): normal unitary vector the this principal face,
35 supposed to point outside the media. [3D vector]
36 Thick (inherited): thickness of the dump, counted in opposite direction to
37 HRNorm. [float]
38 Dia (inherited): diameter of the component. [float]
39 Ref (inherited): reference string (for keeping track with the lab). [string]
40
41 '''
42 Name = "Ghost"
43 - def __init__(self, X = 0., Y = 0., Z = 0., Theta = pi/2., Phi = 0.,
44 Ref = None, Diameter = 5.e-2):
45 '''Ghost initializer.
46
47 Parameters are the attributes.
48
49 Returns a Ghost.
50
51 '''
52
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(Ghost, self).__init__(Ref = Ref,
64 Diameter = Diameter, HRCenter = HRCenter, HRNorm = Norm,
65 Thickness = 0.)
66
68 '''Return the list of lines needed to print the object.
69 '''
70 ans = []
71 ans.append("Ghost: " + self.Name + " (" + self.Ref + ") {")
72 ans.append("Diameter: " + str(self.Dia) + "m")
73 ans.append("Center: " + str(self.HRCenter))
74 sph = rectToSph(self.HRNorm)
75 ans.append("Norm: (" + str(sph[0]/deg) + ', ' \
76 + str(sph[1]/deg) + ')deg')
77 ans.append("}")
78
79 return ans
80
82 '''Determine if a beam hits the Ghost surface.
83
84 This uses the linePlaneInter function from the geometry module to find
85 characteristics of impact of beams on ghost surfaces.
86
87 beam: incoming beam. [GaussianBeam]
88
89 Returns a dictionary with keys:
90 'isHit': whether the beam hits the dump. [boolean]
91 'intersection point': point in space where it is first hit.
92 [3D vector]
93 'face': to indicate which face is first hit, can be 'HR', 'AR' or
94 'side'. [string]
95 'distance': geometrical distance from beam origin to impact. [float]
96
97 '''
98
99 noInterDict = {'isHit': False,
100 'intersection point': np.array([0., 0., 0.],
101 dtype=np.float64),
102 'face': None,
103 'distance': 0.}
104
105
106 HRDict = linePlaneInter(beam.Pos, beam.Dir, self.HRCenter,
107 self.HRNorm, self.Dia)
108
109 if HRDict['isHit']:
110 return {'isHit': True,
111 'intersection point': HRDict['intersection point'],
112 'face': 'HR',
113 'distance': HRDict['distance']
114 }
115 else:
116 return noInterDict
117
118 - def hit(self, beam, order, threshold):
119 '''Return the beam simply transmitted by the ghost surface.
120
121 beam: incident beam. [GaussianBeam]
122 order: maximum strayness of daughter beams, which are not returned if
123 their strayness is over this order. [integer]
124 threshold: idem for the power of the daughter beams. [float]
125
126 Returns a dictionary of beams with keys:
127 't': Gaussian beam which is the continuity of the incident beam.
128
129 '''
130
131 dic = self.isHit(beam)
132 beam.Length = dic['distance']
133 beam.OptDist = beam.N * beam.Length
134
135
136 interactionPoint = dic['intersection point']
137
138
139 newQ = beam.Q(beam.Length)
140
141 return {'t': GaussianBeam(Q = newQ, N = beam.N, Wl = beam.Wl,
142 P = beam.P, Pos = interactionPoint, Dir = beam.Dir,
143 Ux = beam.U[0], Uy = beam.U[1], Ref = beam.Ref,
144 OptDist = 0., Length = 0., StrayOrder = beam.StrayOrder,
145 Optic = self.Ref, Face = ''),
146 'r': None}
147