Package theia :: Package optics :: Module ghost
[hide private]
[frames] | no frames]

Source Code for Module theia.optics.ghost

  1  '''Defines the Ghost class for theia.''' 
  2   
  3  # Provides: 
  4  #   class Ghost 
  5  #       __init__ 
  6  #       lines 
  7  #       isHit 
  8  #       hit 
  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 #Check input 53 Diameter = float(Diameter) 54 55 # prepare for mother initializer 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 # initialize from base initializer 63 super(Ghost, self).__init__(Ref = Ref, 64 Diameter = Diameter, HRCenter = HRCenter, HRNorm = Norm, 65 Thickness = 0.)
66
67 - def lines(self):
68 '''Return the list of lines needed to print the object. 69 ''' 70 ans = [] 71 ans.append("Ghost: {" %self.Ref) 72 ans.append("Diameter: %sm" %str(self.Dia)) 73 ans.append("Center: %s" %str(self.HRCenter)) 74 sph = rectToSph(self.HRNorm) 75 ans.append("Norm: (%s, %s)deg" %(str(sph[0]/deg), str(sph[1]/deg))) 76 ans.append("}") 77 78 return ans
79
80 - def isHit(self, beam):
81 '''Determine if a beam hits the Ghost surface. 82 83 This uses the linePlaneInter function from the geometry module to find 84 characteristics of impact of beams on ghost surfaces. 85 86 beam: incoming beam. [GaussianBeam] 87 88 Returns a dictionary with keys: 89 'isHit': whether the beam hits the dump. [boolean] 90 'intersection point': point in space where it is first hit. 91 [3D vector] 92 'face': to indicate which face is first hit, can be 'HR', 'AR' or 93 'side'. [string] 94 'distance': geometrical distance from beam origin to impact. [float] 95 96 ''' 97 98 noInterDict = {'isHit': False, 99 'intersection point': np.array([0., 0., 0.], 100 dtype=np.float64), 101 'face': None, 102 'distance': 0.} 103 104 # Get impact parameters 105 HRDict = linePlaneInter(beam.Pos, beam.Dir, self.HRCenter, 106 self.HRNorm, self.Dia) 107 108 if HRDict['isHit']: 109 return {'isHit': True, 110 'intersection point': HRDict['intersection point'], 111 'face': 'HR', 112 'distance': HRDict['distance'] 113 } 114 else: 115 return noInterDict
116
117 - def hit(self, beam, order, threshold):
118 '''Return the beam simply transmitted by the ghost surface. 119 120 beam: incident beam. [GaussianBeam] 121 order: maximum strayness of daughter beams, which are not returned if 122 their strayness is over this order. [integer] 123 threshold: idem for the power of the daughter beams. [float] 124 125 Returns a dictionary of beams with keys: 126 't': Gaussian beam which is the continuity of the incident beam. 127 128 ''' 129 # get impact parameters and update beam 130 dic = self.isHit(beam) 131 beam.Length = dic['distance'] 132 beam.OptDist = beam.N * beam.Length 133 134 # get interaction point as origin of new beam 135 interactionPoint = dic['intersection point'] 136 137 # and Q tensor at interaction as new Q 138 newQ = beam.Q(beam.Length) 139 140 return {'t': GaussianBeam(Q = newQ, N = beam.N, Wl = beam.Wl, 141 P = beam.P, Pos = interactionPoint, Dir = beam.Dir, 142 Ux = beam.U[0], Uy = beam.U[1], Ref = beam.Ref, 143 OptDist = 0., Length = 0., StrayOrder = beam.StrayOrder, 144 Optic = self.Ref, Face = ''), 145 'r': None}
146