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

Source Code for Module theia.optics.beamdump

  1  '''Defines the BeamDump class for theia.''' 
  2   
  3  # Provides: 
  4  #   class BeamDump 
  5  #       __init__ 
  6  #       lines 
  7  #       isHit 
  8  #       hit 
  9   
 10  import numpy as np 
 11  from ..helpers import settings 
 12  from ..helpers.geometry import rectToSph, linePlaneInter, lineCylInter 
 13  from ..helpers.units import deg, pi 
 14  from .component import SetupComponent 
 15   
16 -class BeamDump(SetupComponent):
17 ''' 18 19 BeamDump class. 20 21 This class represents components on which rays stop. They have cylindrical 22 symmetry and stop beams on all their faces. They can represent baffles 23 for example. 24 25 *=== Attributes ===* 26 SetupCount (inherited): class attribute, counts all setup components. 27 [integer] 28 Name: class attribute. [string] 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 Ref (inherited): reference string (for keeping track with the lab). [string] 37 38 ''' 39 Name = "BeamDump"
40 - def __init__(self, X = 0., Y = 0., Z = 0., Theta = pi/2., Phi = 0., 41 Ref = None, 42 Thickness = 2.e-2, Diameter = 5.e-2):
43 '''BeamDump initializer. 44 45 Parameters are the attributes. 46 47 Returns a BeamDump. 48 49 ''' 50 #Check input 51 Thickness = float(Thickness) 52 Diameter = float(Diameter) 53 54 # prepare for mother initializer 55 Norm = np.array([np.sin(Theta)*np.cos(Phi), 56 np.sin(Theta) * np.sin(Phi), 57 np.cos(Theta)], dtype = np.float64) 58 59 HRCenter = np.array([X, Y, Z], dtype = np.float64) 60 61 # initialize from base initializer 62 super(BeamDump, self).__init__(Ref = Ref, 63 Diameter = Diameter, HRCenter = HRCenter, HRNorm = Norm, 64 Thickness = Thickness)
65
66 - def lines(self):
67 '''Return the list of lines needed to print the object. 68 ''' 69 ans = [] 70 ans.append("BeamDump: %s {" %self.Ref) 71 ans.append("Thick: %sm" %str(self.Thick)) 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 BeamDump. 82 83 This uses the line***Inter functions from the geometry module to find 84 characteristics of impact of beams on beamdumps. 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 SideDict =lineCylInter(beam.Pos, beam.Dir, 109 self.HRCenter, self.HRNorm, 110 self.Thick, self.Dia) 111 112 ARCenter = self.HRCenter - self.Thick*self.HRNorm 113 114 ARDict = linePlaneInter(beam.Pos, beam.Dir, ARCenter, 115 - self.HRNorm, self.Dia) 116 117 # face tags 118 HRDict['face'] = 'HR' 119 ARDict['face'] = 'AR' 120 SideDict['face'] = 'Side' 121 122 # determine first hit 123 hitFaces = filter(lambda dic: dic['isHit'], [HRDict, ARDict, SideDict]) 124 125 if len(hitFaces) == 0: 126 return noInterDict 127 128 dist = hitFaces[0]['distance'] 129 j=0 130 131 for i in range(len(hitFaces)): 132 if hitFaces[i]['distance'] < dist: 133 dist = hitFaces[i]['distance'] 134 j=i 135 136 return {'isHit': True, 137 'intersection point': hitFaces[j]['intersection point'], 138 'face': hitFaces[j]['face'], 139 'distance': hitFaces[j]['distance'] 140 }
141
142 - def hit(self, beam, order, threshold):
143 '''Compute the refracted and reflected beams after interaction. 144 145 BeamDumps always stop beams. 146 147 beam: incident beam. [GaussianBeam] 148 order: maximum strayness of daughter beams, which are not returned if 149 their strayness is over this order. [integer] 150 threshold: idem for the power of the daughter beams. [float] 151 152 Returns a dictionary of beams with keys: 153 't': None 154 'r': None 155 156 ''' 157 # get impact parameters and update beam 158 dic = self.isHit(beam) 159 beam.Length = dic['distance'] 160 beam.OptDist = beam.N * beam.Length 161 if settings.info: 162 print "theia: Info: Reached beam stop (%s on %s)." \ 163 %(beam.Ref, self.Ref) 164 165 return {'r': None, 't': None}
166