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: " + self.Name + " (" + self.Ref + ") {") 71 ans.append("Thick: " + str(self.Thick) + "m") 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
81 - def isHit(self, beam):
82 '''Determine if a beam hits the BeamDump. 83 84 This uses the line***Inter functions from the geometry module to find 85 characteristics of impact of beams on beamdumps. 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 # Get impact parameters 106 HRDict = linePlaneInter(beam.Pos, beam.Dir, self.HRCenter, 107 self.HRNorm, self.Dia) 108 109 SideDict =lineCylInter(beam.Pos, beam.Dir, 110 self.HRCenter, self.HRNorm, 111 self.Thick, self.Dia) 112 113 ARCenter = self.HRCenter - self.Thick*self.HRNorm 114 115 ARDict = linePlaneInter(beam.Pos, beam.Dir, ARCenter, 116 - self.HRNorm, self.Dia) 117 118 # face tags 119 HRDict['face'] = 'HR' 120 ARDict['face'] = 'AR' 121 SideDict['face'] = 'Side' 122 123 # determine first hit 124 hitFaces = filter(lambda dic: dic['isHit'], [HRDict, ARDict, SideDict]) 125 126 if len(hitFaces) == 0: 127 return noInterDict 128 129 dist = hitFaces[0]['distance'] 130 j=0 131 132 for i in range(len(hitFaces)): 133 if hitFaces[i]['distance'] < dist: 134 dist = hitFaces[i]['distance'] 135 j=i 136 137 return {'isHit': True, 138 'intersection point': hitFaces[j]['intersection point'], 139 'face': hitFaces[j]['face'], 140 'distance': hitFaces[j]['distance'] 141 }
142
143 - def hit(self, beam, order, threshold):
144 '''Compute the refracted and reflected beams after interaction. 145 146 BeamDumps always stop beams. 147 148 beam: incident beam. [GaussianBeam] 149 order: maximum strayness of daughter beams, which are not returned if 150 their strayness is over this order. [integer] 151 threshold: idem for the power of the daughter beams. [float] 152 153 Returns a dictionary of beams with keys: 154 't': None 155 'r': None 156 157 ''' 158 # get impact parameters and update beam 159 dic = self.isHit(beam) 160 beam.Length = dic['distance'] 161 beam.OptDist = beam.N * beam.Length 162 if settings.info: 163 print "theia: Info: Reached beam stop (" + beam.Ref + ' on '\ 164 + self.Ref + ').' 165 166 return {'r': None, 't': None}
167