def plot_efficiency(self): if self.type_of_zp == PHASE_ZP: if self.energy_plot == 1: if self.plot_canvas[5] is None: self.plot_canvas[5] = oasysgui.plotWindow(roi=False, control=False, position=True, logScale=False) self.tab[5].layout().addWidget(self.plot_canvas[5] ) self.plot_canvas[5].clear() self.plot_canvas[5].setDefaultPlotLines(True) self.plot_canvas[5].setActiveCurveColor(color='blue') self.plot_canvas[5].setGraphTitle('Thickness: ' + str(self.zone_plate_thickness) + " nm") self.plot_canvas[5].getXAxis().setLabel('Energy [eV]') self.plot_canvas[5].getYAxis().setLabel('Efficiency [%]') x_values = numpy.linspace(self.energy_from, self.energy_to, 100) y_values = numpy.zeros(100) for index in range(len(x_values)): y_values[index], _, _ = ZonePlate.calculate_efficiency(ShadowPhysics.getWavelengthFromEnergy(x_values[index])/10, self.zone_plate_material, self.zone_plate_thickness) y_values = numpy.round(100.0*y_values, 3) self.plot_canvas[5].addCurve(x_values, y_values, "Efficiency vs Energy", symbol='', color='blue', replace=True) else: if not self.plot_canvas[5] is None: self.plot_canvas[5].clear() if self.thickness_plot == 1: if self.plot_canvas[6] is None: self.plot_canvas[6] = oasysgui.plotWindow(roi=False, control=False, position=True, logScale=False) self.tab[6].layout().addWidget(self.plot_canvas[6] ) self.plot_canvas[6].setDefaultPlotLines(True) self.plot_canvas[6].setActiveCurveColor(color='blue') self.plot_canvas[6].setGraphTitle('Energy: ' + str(round(ShadowPhysics.getEnergyFromWavelength(self.avg_wavelength*10), 3)) + " eV") self.plot_canvas[6].getXAxis().setLabel('Thickness [nm]') self.plot_canvas[6].getYAxis().setLabel('Efficiency [%]') x_values = numpy.linspace(self.thickness_from, self.thickness_to, 100) y_values = numpy.zeros(100) for index in range(len(x_values)): y_values[index], _, _ = ZonePlate.calculate_efficiency(self.avg_wavelength, self.zone_plate_material, x_values[index]) y_values = numpy.round(100*y_values, 3) self.plot_canvas[6].addCurve(x_values, y_values, "Efficiency vs Thickness", symbol='', color='blue', replace=True) else: if not self.plot_canvas[6] is None: self.plot_canvas[6].clear() else: if not self.plot_canvas[5] is None: self.plot_canvas[5].clear() if not self.plot_canvas[6] is None: self.plot_canvas[6].clear()
def compute(self): try: self.shadow_output.setText("") sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() m = -self.grating_diffraction_order if self.units_in_use == 0: wavelength = ShadowPhysics.getWavelengthFromEnergy( self.photon_energy) / self.workspace_units_to_m * 1e-10 elif self.units_in_use == 1: wavelength = self.photon_wavelength / self.workspace_units_to_m * 1e-10 sin_alpha = (-m*self.k*wavelength/(self.c**2 - 1)) + \ numpy.sqrt(1 + (m*m*self.c*self.c*self.k*self.k*wavelength*wavelength)/((self.c**2 - 1)**2)) alpha = numpy.arcsin(sin_alpha) beta = numpy.arcsin(sin_alpha - m * self.k * wavelength) self.design_alpha = round(numpy.degrees(alpha), 3) self.design_beta = round(numpy.degrees(beta), 3) #_beta = numpy.arccos(self.c*numpy.cos(alpha)) print("####################################################") print("# DESIGN PHASE") print("####################################################\n") print("Photon Wavelength:", wavelength, self.workspace_units_label) print("Design ALPHA :", self.design_alpha, "deg") print("Design BETA :", self.design_beta, "deg") self.b2 = (((numpy.cos(alpha)**2) / self.r_a) + ((numpy.cos(beta)**2) / self.r_b)) / (-2 * m * self.k * wavelength) self.b3 = ((numpy.sin(alpha)*numpy.cos(alpha)**2)/self.r_a**2 - \ (numpy.sin(beta)*numpy.cos(beta)**2)/self.r_b**2)/(-2*m*self.k*wavelength) self.b4 = (((4*numpy.sin(alpha)**2 - numpy.cos(alpha)**2)*numpy.cos(alpha)**2)/self.r_a**3 + \ ((4*numpy.sin(beta)**2 - numpy.cos(beta)**2)*numpy.cos(beta)**2)/self.r_b**3)/(-8*m*self.k*wavelength) print("\nb2:", self.b2) print("b3:", self.b3) print("b4:", self.b4) self.shadow_coeff_0 = round(self.k, 8) self.shadow_coeff_1 = round(-2 * self.k * self.b2, 8) self.shadow_coeff_2 = round(3 * self.k * self.b3, 8) self.shadow_coeff_3 = round(-4 * self.k * self.b4, 8) print("\nshadow_coeff_0:", self.shadow_coeff_0) print("shadow_coeff_1:", self.shadow_coeff_1) print("shadow_coeff_2:", self.shadow_coeff_2) print("shadow_coeff_3:", self.shadow_coeff_3) ############################################ # # 1 - in case of mirror recalculate real ray tracing distance (r_a') from initial r_a and vertical distance # between grating and mirror (h) # gamma = (alpha + beta) / 2 d_source_to_mirror = self.r_a - ( self.h / numpy.abs(numpy.tan(numpy.pi - 2 * gamma))) d_mirror_to_grating = self.h / numpy.abs( numpy.sin(numpy.pi - 2 * gamma)) r_a_first = d_source_to_mirror + d_mirror_to_grating print("\ngamma :", numpy.degrees(gamma), "deg") print("Source to Mirror distance :", d_source_to_mirror, self.workspace_units_label) print("Mirror to Grating distance:", d_mirror_to_grating, self.workspace_units_label) print("R_a' :", r_a_first, self.workspace_units_label) ############################################ if self.new_units_in_use == 0: newwavelength = ShadowPhysics.getWavelengthFromEnergy( self.new_photon_energy) / self.workspace_units_to_m * 1e-10 elif self.new_units_in_use == 1: newwavelength = self.new_photon_wavelength / self.workspace_units_to_m * 1e-10 r = self.r_b / r_a_first A0 = self.k * newwavelength A2 = self.k * newwavelength * self.r_b * self.b2 new_c_num = 2*A2 + 4*(A2/A0)**2 + \ (4 + 2*A2 - A0**2)*r - \ 4*(A2/A0)*numpy.sqrt((1 + r)**2 + 2*A2*(1 + r) - r*A0**2) new_c_den = -4 + A0**2 - 4 * A2 + 4 * (A2 / A0)**2 new_c = numpy.sqrt(new_c_num / new_c_den) new_sin_alpha = (-m*self.k*newwavelength/(new_c**2 - 1)) + \ numpy.sqrt(1 + (m*m*new_c*new_c*self.k*self.k*newwavelength*newwavelength)/((new_c**2 - 1)**2)) new_alpha = numpy.arcsin(new_sin_alpha) new_beta = numpy.arcsin(new_sin_alpha - m * self.k * newwavelength) self.raytracing_alpha = round(numpy.degrees(new_alpha), 6) self.raytracing_beta = round(numpy.degrees(new_beta), 6) #_new_beta = numpy.arccos(new_c*numpy.cos(new_alpha)) print("####################################################") print("# RAY-TRACING PHASE") print("####################################################\n") print("Ray-Tracing Wavelength:", newwavelength, self.workspace_units_label) print("Ray-Tracing C :", new_c) print("Ray-Tracing ALPHA :", self.raytracing_alpha, "deg") print("Ray-Tracing BETA :", self.raytracing_beta, "deg") gamma = (new_alpha + new_beta) / 2 self.d_source_to_mirror = self.r_a - ( self.h / numpy.abs(numpy.tan(numpy.pi - 2 * gamma))) self.d_mirror_to_grating = self.h / numpy.abs( numpy.sin(numpy.pi - 2 * gamma)) r_a_first = self.d_source_to_mirror + self.d_mirror_to_grating self.d_source_to_mirror = round(self.d_source_to_mirror, 3) self.d_source_plane_to_mirror = round( self.d_source_to_mirror - self.last_element_distance, 3) self.d_mirror_to_grating = round(self.d_mirror_to_grating, 3) print("\ngamma :", numpy.degrees(gamma), "deg") print("Source to Mirror distance :", self.d_source_to_mirror, self.workspace_units_label) print("Source Plane to Mirror distance :", self.d_source_plane_to_mirror, self.workspace_units_label) print("Mirror to Grating distance :", self.d_mirror_to_grating, self.workspace_units_label) print("R_a' :", r_a_first, self.workspace_units_label) self.send( "PreProcessor_Data", VlsPgmPreProcessorData( shadow_coeff_0=self.shadow_coeff_0, shadow_coeff_1=self.shadow_coeff_1, shadow_coeff_2=self.shadow_coeff_2, shadow_coeff_3=self.shadow_coeff_3, d_source_plane_to_mirror=self.d_source_plane_to_mirror, d_mirror_to_grating=self.d_mirror_to_grating, d_grating_to_exit_slits=self.r_b, alpha=self.raytracing_alpha, beta=self.raytracing_beta)) except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)
def compute(self): try: self.shadow_output.setText("") sys.stdout = EmittingStream(textWritten=self.writeStdOut) self.checkFields() m = -self.grating_diffraction_order if self.units_in_use == 0: _lambda = ShadowPhysics.getWavelengthFromEnergy(self.photon_energy) / self.workspace_units_to_m * 1e-10 elif self.units_in_use == 1: _lambda = self.photon_wavelength / self.workspace_units_to_m * 1e-10 sin_alpha = (-m * self.k * _lambda / (self.c ** 2 - 1)) + numpy.sqrt( 1 + (m * m * self.c * self.c * self.k * self.k * _lambda * _lambda) / ((self.c ** 2 - 1) ** 2) ) alpha = numpy.arcsin(sin_alpha) beta = numpy.arcsin(sin_alpha - m * self.k * _lambda) _beta = numpy.arccos(self.c * numpy.cos(alpha)) print("Lambda:", _lambda, self.workspace_units_label) print("ALPHA:", numpy.degrees(alpha), "deg") print("BETA:", numpy.degrees(beta), numpy.degrees(_beta), "deg") b2 = (((numpy.cos(alpha) ** 2) / self.r_a) + ((numpy.cos(beta) ** 2) / self.r_b)) / ( -2 * m * self.k * _lambda ) b3 = ( (numpy.sin(alpha) * numpy.cos(alpha) ** 2) / self.r_a ** 2 - (numpy.sin(beta) * numpy.cos(beta) ** 2) / self.r_b ** 2 ) / (-2 * m * self.k * _lambda) b4 = ( ((4 * numpy.sin(alpha) ** 2 - numpy.cos(alpha) ** 2) * numpy.cos(alpha) ** 2) / self.r_a ** 3 + ((4 * numpy.sin(beta) ** 2 - numpy.cos(beta) ** 2) * numpy.cos(beta) ** 2) / self.r_b ** 3 ) / (-8 * m * self.k * _lambda) print("\nb2", b2) print("b3", b3) print("b4", b4) shadow_coeff_0 = self.k shadow_coeff_1 = -2 * self.k * b2 shadow_coeff_2 = 3 * self.k * b3 shadow_coeff_3 = -4 * self.k * b4 print("\nshadow_coeff_0", shadow_coeff_0) print("shadow_coeff_1", shadow_coeff_1) print("shadow_coeff_2", shadow_coeff_2) print("shadow_coeff_3", shadow_coeff_3) ############################################ # # 1 - in case of mirror recalculate real ray tracing distance (r_a') from initial r_a and vertical distance # between grating and mirror (h) # gamma = (alpha + beta) / 2 d_source_to_mirror = self.r_a - (self.h / numpy.abs(numpy.tan(numpy.pi - 2 * gamma))) d_mirror_to_grating = self.h / numpy.abs(numpy.sin(numpy.pi - 2 * gamma)) r_a_first = d_source_to_mirror + d_mirror_to_grating print("\ngamma", numpy.degrees(gamma)) print("d_source_to_mirror", d_source_to_mirror, self.workspace_units_label) print("d_mirror_to_grating", d_mirror_to_grating, self.workspace_units_label) print("r_a_first", r_a_first, self.workspace_units_label) ############################################ if self.new_units_in_use == 0: new_lambda = ( ShadowPhysics.getWavelengthFromEnergy(self.new_photon_energy) / self.workspace_units_to_m * 1e-10 ) elif self.new_units_in_use == 1: new_lambda = self.new_photon_wavelength / self.workspace_units_to_m * 1e-10 r = self.r_b / r_a_first A0 = self.k * new_lambda A2 = self.k * new_lambda * self.r_b * b2 new_c_num = ( 2 * A2 + 4 * (A2 / A0) ** 2 + (4 + 2 * A2 - A0 ** 2) * r - 4 * (A2 / A0) * numpy.sqrt((1 + r) ** 2 + 2 * A2 * (1 + r) - r * A0 ** 2) ) new_c_den = -4 + A0 ** 2 - 4 * A2 + 4 * (A2 / A0) ** 2 new_c = numpy.sqrt(new_c_num / new_c_den) new_sin_alpha = (-m * self.k * new_lambda / (new_c ** 2 - 1)) + numpy.sqrt( 1 + (m * m * new_c * new_c * self.k * self.k * new_lambda * new_lambda) / ((new_c ** 2 - 1) ** 2) ) new_alpha = numpy.arcsin(new_sin_alpha) new_beta = numpy.arcsin(new_sin_alpha - m * self.k * new_lambda) _new_beta = numpy.arccos(new_c * numpy.cos(new_alpha)) print("New Lambda:", new_lambda, self.workspace_units_label) print("New C:", new_c) print("NEW ALPHA:", numpy.degrees(new_alpha), "deg") print("NEW BETA:", numpy.degrees(new_beta), numpy.degrees(_new_beta), "deg") gamma = (new_alpha + new_beta) / 2 d_source_to_mirror = self.r_a - (self.h / numpy.abs(numpy.tan(numpy.pi - 2 * gamma))) d_mirror_to_grating = self.h / numpy.abs(numpy.sin(numpy.pi - 2 * gamma)) r_a_first = d_source_to_mirror + d_mirror_to_grating print("\ngamma", numpy.degrees(gamma)) print("d_source_to_mirror", d_source_to_mirror, self.workspace_units_label) print("d_mirror_to_grating", d_mirror_to_grating, self.workspace_units_label) print("r_a_first", r_a_first, self.workspace_units_label) self.send("PreProcessor_Data", ShadowPreProcessorData()) except Exception as exception: QMessageBox.critical(self, "Error", str(exception), QMessageBox.Ok)