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 ARCenter (inherited): center of the secondary face of the Ghost in space.
35 [3D vector]
36 HRnorm (inherited): normal unitary vector the this principal face,
37 supposed to point outside the media. [3D vector]
38 Thick (inherited): thickness of the dump, counted in opposite direction to
39 HRNorm. [float]
40 Dia (inherited): diameter of the component. [float]
41 Ref (inherited): reference string (for keeping track with the lab). [string]
42
43 '''
44 Name = "Ghost"
45 - def __init__(self, X = 0., Y = 0., Z = 0., Theta = pi/2., Phi = 0.,
46 Ref = None, Diameter = 50.e-2):
47 '''Ghost initializer.
48
49 Parameters are the attributes.
50
51 Returns a Ghost.
52
53 '''
54
55 Diameter = float(Diameter)
56
57
58 Norm = np.array([np.sin(Theta) * np.cos(Phi),
59 np.sin(Theta) * np.sin(Phi),
60 np.cos(Theta)], dtype = np.float64)
61
62 HRCenter = np.array([X, Y, Z], dtype = np.float64)
63
64
65 super(Ghost, self).__init__(Ref = Ref,
66 Diameter = Diameter, HRCenter = HRCenter, HRNorm = Norm,
67 Thickness = 0., ARCenter = HRCenter)
68
70 '''Return the list of lines needed to print the object.
71 '''
72 sph = rectToSph(self.HRNorm)
73 return ["Ghost: {" % self.Ref,
74 "Diameter: %sm" % str(self.Dia),
75 "Center: %s" % str(self.HRCenter),
76 "Norm: (%s, %s)deg" % (str(sph[0]/deg), str(sph[1]/deg)),
77 "}"]
78
80 '''Determine if a beam hits the Ghost surface.
81
82 This uses the linePlaneInter function from the geometry module to find
83 characteristics of impact of beams on ghost surfaces.
84
85 beam: incoming beam. [GaussianBeam]
86
87 Returns a dictionary with keys:
88 'isHit': whether the beam hits the dump. [boolean]
89 'intersection point': point in space where it is first hit.
90 [3D vector]
91 'face': to indicate which face is first hit, can be 'HR', 'AR' or
92 'side'. [string]
93 'distance': geometrical distance from beam origin to impact. [float]
94
95 '''
96
97
98 HRDict = linePlaneInter(beam.Pos, beam.Dir, self.HRCenter,
99 self.HRNorm, self.Dia)
100
101 if HRDict['isHit']:
102 return {'isHit': True,
103 'intersection point': HRDict['intersection point'],
104 'face': 'HR',
105 'distance': HRDict['distance']
106 }
107 else:
108 return {'isHit': False,
109 'intersection point': np.array([0., 0., 0.],
110 dtype=np.float64),
111 'face': None,
112 'distance': 0.}
113
114 - def hit(self, beam, order, threshold):
115 '''Return the beam simply transmitted by the ghost surface.
116
117 beam: incident beam. [GaussianBeam]
118 order: maximum strayness of daughter beams, which are not returned if
119 their strayness is over this order. [integer]
120 threshold: idem for the power of the daughter beams. [float]
121
122 Returns a dictionary of beams with keys:
123 't': Gaussian beam which is the continuity of the incident beam.
124
125 '''
126
127 dic = self.isHit(beam)
128 beam.Length = dic['distance']
129 beam.OptDist = beam.N * beam.Length
130 beam.TargetOptic = self.Ref
131 beam.TargetFace = dic['face']
132 endSize = beam.width(beam.Length)
133 beam.TWx = endSize[0]
134 beam.TWy = endSize[1]
135
136
137 interactionPoint = dic['intersection point']
138
139
140 newQ = beam.Q(beam.Length)
141
142 return {'t': GaussianBeam(Q = newQ, N = beam.N, Wl = beam.Wl,
143 P = beam.P, Pos = interactionPoint, Dir = beam.Dir,
144 Ux = beam.U[0], Uy = beam.U[1], Ref = beam.Ref,
145 OptDist = 0., Length = 0., StrayOrder = beam.StrayOrder,
146 Optic = self.Ref, Face = ''),
147 'r': None}
148