def generator(self, Emin=1., Emax=1000., Exp=False, sphi=0., stheta=pi, deltasource=0): '''Generates randomly a photon going onto the xtal. Exp is the powerlaw spectral index -2.1 for Crab ''' # Defines the crystal angles using the angular coordinate of the # reciprocal lattice vector g. The same crystal angles (with -sign) # will be also appplied to the generated photon. l = math.sqrt(self.photon.r[0]**2 + self.photon.r[1]**2) #print "divergenza",self.photon.r[0], self.photon.r[1], l, self.divergence_stheta(l, deltasource) #print "stheta", stheta #stheta = stheta - self.divergence_stheta(l, deltasource) #sphi = self.divergence_sphi(self.photon.r) #print "stheta", stheta # Set the photon intensity equal to 1. This function generate a probability # for the photon, then it will be multplied by the requested intensity set # in the macro if self.photon.i !=1: self.photon.i=1. # wavevector definition from source angular parameters # stheta = pi and sphi = 0 means on-axis source while # off-axis source is simply obtained by changing stheta. # the k value is related to the energy from the relation k = 2 pi/lambda # is the erandom function that make the k from module 1 to the correct module # indeed erandom set the energy and follow that automatically k is set. # Now photon.k has module 1, erandom will give the right normalization. self.photon.k=Physics.makenormalvec(sphi, stheta) # Energy calculation (powerlaw if Exp is False) self.erandom((Emin, Emax), Exp=Exp)
def generator(self, Emin=1., Emax=1000., Exp=False, sphi=0., stheta=pi): '''Generates randomly a photon that will go on to xtal. Exp is the powerlaw spectral index (-2.1 for the Crab Nebula). ''' theta, phi = pi/2-self.xtal.gtheta, self.xtal.gphi # lambda functions # drag_out_xtal = lambda x: array(x) + array(self.xtal.r) rot_out_xtal = lambda x: Physics.rot(x, (('y', -theta), ('z', -phi))) # Puts a photon an EPSILON under the xtal surface in a random 2D point random_pos_on_surface=[uniform(-x/2., x/2.) for x in self.xtal.dim[:2]] random_pos_on_surface.append(-EPSILON) self.photon.r=random_pos_on_surface # The photon position in observer reference frame (rotation + translation) self.photon.r=rot_out_xtal(self.photon.r) self.photon.r=drag_out_xtal(self.photon.r) if self.photon.i !=1: self.photon.i=1. # wavevector definition from source angular parameters self.photon.k=Physics.makenormalvec(sphi, stheta) # Energy calculation (powerlaw if Exp is False) self.erandom((Emin, Emax), Exp=Exp)