def change_the_g(self, g): # funzione che in base alla posizione del cristallo su cui cade il # fotone gli cambia il g relativamente alla curvatura del cristallo raggio = math.sqrt (self.photon.r[0]**2 + self.photon.r[1]**2) delta_angle = (self.xtal.rho-raggio ) * self.xtal.curvature gtheta = self.xtal.gtheta + delta_angle return Physics.spherical2cartesian(norm(g),self.xtal.gphi, gtheta)
def g_needed(self, order=1): ############################################### local_xtal_g = self.change_the_g(self.xtal.g) #lgn=Physics.normalize(local_xtal_g) local_xtal_gphi = Physics.atan2(local_xtal_g[1], local_xtal_g[0]) ############################################### """Calculates the reciprocal lattice vector that a photon needs to be scattered by a known crystal with planes oriented in a particular direction that is already known""" #When the energy is too low the returned value is None. if self.photon.knorm < self.xtal.gnorm*order: return None # For the calculation see the notes of 09/07/2004 modified the 12/07/04 A = (self.photon.k[0]*math.cos(local_xtal_gphi)+self.photon.k[1]*math.sin(local_xtal_gphi)) B = self.photon.k[2] C = self.xtal.gnorm/2. #A = (self.photon.k[0]*math.cos(self.xtal.gphi)+self.photon.k[1]*math.sin(self.xtal.gphi)) #B = self.photon.k[2] #C = self.xtal.gnorm/2. if abs(A)<=EPSILON: # B can't be 0 together with A unless gnorm=0, so this function should be almost safe # The result can be otained with the calculation in the else block # but this is faster and common (is the case of paraxial photons). if abs(C/B)>1.: return None else: theta=math.acos(-C/B) else: A2B2=A**2+B**2 BC=B*C # Two solutions, but only one satisfies the Laue equation Mean=-BC/A2B2 try: Delta=A*math.sqrt(A2B2-C**2)/A2B2 except ValueError: return None cosp, cosm = Mean+Delta, Mean-Delta thp, thm = math.acos(cosp), math.acos(cosm) sinp, sinm = math.sin(thp), math.sin(thm) checkp = abs(A*sinp + B*cosp + C) checkm = abs(A*sinm + B*cosm + C) # Da ricontrollare if checkp<checkm: theta=thp else: theta=thm return Physics.spherical2cartesian(self.xtal.gnorm, local_xtal_gphi, theta)