예제 #1
0
    def completeOperations(self, shadow_oe=None):
        self.setStatusMessage("Running SHADOW")

        if self.trace_shadow:
            grabber = TTYGrabber()
            grabber.start()

        self.progressBarSet(50)

        ###########################################
        # TODO: TO BE ADDED JUST IN CASE OF BROKEN
        #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
        #       TO TEST SHADOW
        self.fixWeirdShadowBug()
        ###########################################

        shadow_oe._oe.write("ziotreno.00")

        beam_out = ShadowBeam.traceFromOE(shadow_oe, self.input_beam)

        if self.trace_shadow:
            grabber.stop()

            for row in grabber.ttyData:
                self.writeStdOut(row)

        self.setStatusMessage("Plotting Results")

        self.plot_results(beam_out)

        self.setStatusMessage("")

        self.send("Beam", beam_out)
    def completeOperations(self, shadow_oe=None):
        self.setStatusMessage("Running SHADOW")

        if self.trace_shadow:
            grabber = TTYGrabber()
            grabber.start()

        self.progressBarSet(50)

        ###########################################
        # TODO: TO BE ADDED JUST IN CASE OF BROKEN
        #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
        #       TO TEST SHADOW
        self.fixWeirdShadowBug()
        ###########################################

        beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe)

        self.adjust_divergence_and_intensity(beam_out)

        if self.trace_shadow:
            grabber.stop()

            for row in grabber.ttyData:
                self.writeStdOut(row)

        self.setStatusMessage("Plotting Results")

        self.plot_results(beam_out)

        self.setStatusMessage("")

        self.send("Beam", beam_out)
        self.send("Trigger", ShadowTriggerIn(new_beam=True))
    def runShadowSource(self):
        self.error(self.error_id)
        self.setStatusMessage("")
        self.progressBarInit()

        try:
            self.checkFields()

            shadow_src = self.populateFields()

            self.progressBarSet(10)

            #self.information(0, "Running SHADOW")
            self.setStatusMessage("Running SHADOW")

            sys.stdout = EmittingStream(textWritten=self.writeStdOut)
            if self.trace_shadow:
                grabber = TTYGrabber()
                grabber.start()

            self.progressBarSet(50)

            beam_out = self.driver.processSource(shadow_src)

            if self.trace_shadow:
                grabber.stop()

                for row in grabber.ttyData:
                   self.writeStdOut(row)

            #self.information(0, "Plotting Results")
            self.setStatusMessage("Plotting Results")

            self.progressBarSet(80)
            self.plot_results(beam_out)

            #self.information()
            self.setStatusMessage("")

            self.send("Beam", beam_out)
        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

            #raise exception

        self.progressBarFinished()
    def completeOperations(self, shadow_oe=None):
        self.setStatusMessage("Running SHADOW")

        if self.trace_shadow:
            grabber = TTYGrabber()
            grabber.start()

        self.progressBarSet(50)

        ###########################################
        # TODO: TO BE ADDED JUST IN CASE OF BROKEN
        #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
        #       TO TEST SHADOW
        self.fixWeirdShadowBug()
        ###########################################

        write_start_files, write_end_files, write_star_files, write_mirr_files = self.get_write_file_options()

        beam_out = ShadowBeam.traceFromCompoundOE(self.input_beam,
                                                  shadow_oe,
                                                  write_start_files=write_start_files,
                                                  write_end_files=write_end_files,
                                                  write_star_files=write_star_files,
                                                  write_mirr_files=write_mirr_files,
                                                  widget_class_name=type(self).__name__
                                                  )

        if self.trace_shadow:
            grabber.stop()

            for row in grabber.ttyData:
                self.writeStdOut(row)

        self.setStatusMessage("Plotting Results")

        self.plot_results(beam_out)

        self.setStatusMessage("")

        self.send("Beam", beam_out)
        self.send("Trigger", ShadowTriggerIn(new_beam=True))
예제 #5
0
    def completeOperations(self, shadow_oe=None):
        self.setStatusMessage("Running SHADOW")

        if self.trace_shadow:
            grabber = TTYGrabber()
            grabber.start()

        self.progressBarSet(50)

        ###########################################
        # TODO: TO BE ADDED JUST IN CASE OF BROKEN
        #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
        #       TO TEST SHADOW
        self.fixWeirdShadowBug()
        ###########################################

        beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe)

        self.adjust_divergence_and_intensity(beam_out)

        if self.trace_shadow:
            grabber.stop()

            for row in grabber.ttyData:
                self.writeStdOut(row)

        self.setStatusMessage("Plotting Results")

        self.plot_results(beam_out)

        self.setStatusMessage("")

        self.send("Beam", beam_out)
        self.send("Trigger", ShadowTriggerIn(new_beam=True))
예제 #6
0
    def plot_results(self):
        #self.error(self.error_id)

        try:
            plotted = False

            sys.stdout = EmittingStream(textWritten=self.writeStdOut)
            if self.trace_shadow:
                grabber = TTYGrabber()
                grabber.start()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                ShadowPlot.set_conversion_active(self.getConversionActive())

                self.number_of_bins = congruence.checkStrictlyPositiveNumber(self.number_of_bins, "Number of Bins")

                x, y, auto_x_title, auto_y_title, xum, yum = self.get_titles()

                self.plot_xy(x, y, title=self.title, xtitle=auto_x_title, ytitle=auto_y_title, xum=xum, yum=yum)

                plotted = True
            if self.trace_shadow:
                grabber.stop()

                for row in grabber.ttyData:
                    self.writeStdOut(row)

            time.sleep(0.5)  # prevents a misterious dead lock in the Orange cycle when refreshing the histogram

            return plotted
        except Exception as exception:
            QtGui.QMessageBox.critical(self, "Error",
                                       str(exception),
                                       QtGui.QMessageBox.Ok)

            #self.error_id = self.error_id + 1
            #self.error(self.error_id, "Exception occurred: " + str(exception))
            return False
예제 #7
0
    def runShadowSource(self):
        #self.error(self.error_id)
        self.setStatusMessage("")
        self.progressBarInit()

        try:
            self.checkFields()

            ###########################################
            # TODO: TO BE ADDED JUST IN CASE OF BROKEN
            #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
            #       TO TEST SHADOW
            self.fixWeirdShadowBug()
            ###########################################

            shadow_src = ShadowSource.create_bm_src()

            self.populateFields(shadow_src)

            self.progressBarSet(10)

            #self.information(0, "Running SHADOW")
            self.setStatusMessage("Running SHADOW")

            sys.stdout = EmittingStream(textWritten=self.writeStdOut)
            if self.trace_shadow:
                grabber = TTYGrabber()
                grabber.start()

            self.progressBarSet(50)

            write_begin_file, write_start_file, write_end_file = self.get_write_file_options()

            beam_out = ShadowBeam.traceFromSource(shadow_src,
                                                  write_begin_file=write_begin_file,
                                                  write_start_file=write_start_file,
                                                  write_end_file=write_end_file)

            if self.trace_shadow:
                grabber.stop()

                for row in grabber.ttyData:
                   self.writeStdOut(row)

            #self.information(0, "Plotting Results")
            self.setStatusMessage("Plotting Results")

            self.progressBarSet(80)
            self.plot_results(beam_out)

            #self.information()
            self.setStatusMessage("")

            self.send("Beam", beam_out)
        except Exception as exception:
            QtGui.QMessageBox.critical(self, "Error",
                                       str(exception),
                QtGui.QMessageBox.Ok)

            #self.error_id = self.error_id + 1
            #self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
예제 #8
0
    def plot_results(self):
        self.error(self.error_id)

        try:
            sys.stdout = EmittingStream(textWritten=self.writeStdOut)
            if self.trace_shadow:
                grabber = TTYGrabber()
                grabber.start()

            if ShadowGui.checkEmptyBeam(self.input_beam):
                self.number_of_bins = ShadowGui.checkPositiveNumber(self.number_of_bins, "Number of Bins")

                auto_x_title = self.x_column.currentText().split(":", 2)[1]
                auto_y_title = self.y_column.currentText().split(":", 2)[1]

                xum = auto_x_title + " "
                yum = auto_y_title + " "

                self.title = auto_x_title + "," + auto_y_title

                x = self.x_column_index + 1

                if x == 1 or x == 2 or x == 3:
                    xum = xum + "[" + u"\u03BC" + "m]"
                    auto_x_title = auto_x_title + " [$\mu$m]"
                elif x == 4 or x == 5 or x == 6:
                    xum = xum + "[" + u"\u03BC" + "rad]"
                    auto_x_title = auto_x_title + " [$\mu$rad]"
                elif x == 11:
                    xum = xum + "[eV]"
                    auto_x_title = auto_x_title + " [eV]"
                elif x == 13:
                    xum = xum + "[cm]"
                    auto_x_title = auto_x_title + " [cm]"
                elif x == 14:
                    xum = xum + "[rad]"
                    auto_x_title = auto_x_title + " [rad]"
                elif x == 15:
                    xum = xum + "[rad]"
                    auto_x_title = auto_x_title + " [rad]"
                elif x == 19:
                    xum = xum + "[Å]"
                    auto_x_title = auto_x_title + " [Å]"
                elif x == 20:
                    xum = xum + "[cm]"
                    auto_x_title = auto_x_title + " [cm]"
                elif x == 21:
                    xum = xum + "[rad]"
                    auto_x_title = auto_x_title + " [rad]"
                elif x >= 25 and x <= 28:
                    xum = xum + "[Å-1]"
                    auto_x_title = auto_x_title + " [Å-1]"

                y = self.y_column_index + 1

                if y == 1 or y == 2 or y == 3:
                    yum = yum + "[" + u"\u03BC" + "m]"
                    auto_y_title = auto_y_title + " [$\mu$m]"
                elif y == 4 or y == 5 or y == 6:
                    yum = yum + "[" + u"\u03BC" + "rad]"
                    auto_y_title = auto_y_title + " [$\mu$rad]"
                elif y == 11:
                    yum = yum + "[eV]"
                    auto_y_title = auto_y_title + " [eV]"
                elif y == 13:
                    yum = yum + "[cm]"
                    auto_y_title = auto_y_title + " [cm]"
                elif y == 14:
                    yum = yum + "[rad]"
                    auto_y_title = auto_y_title + " [rad]"
                elif y == 15:
                    yum = yum + "[rad]"
                    auto_y_title = auto_y_title + " [rad]"
                elif y == 19:
                    yum = yum + "[Å]"
                    auto_y_title = auto_y_title + " [Å]"
                elif y == 20:
                    yum = yum + "[cm]"
                    auto_y_title = auto_y_title + " [cm]"
                elif y == 21:
                    yum = yum + "[rad]"
                    auto_y_title = auto_y_title + " [rad]"
                elif y >= 25 and y <= 28:
                    yum = yum + "[Å-1]"
                    auto_y_title = auto_y_title + " [Å-1]"

                self.plot_xy(x, y, title=self.title, xtitle=auto_x_title, ytitle=auto_y_title, xum=xum, yum=yum)

            if self.trace_shadow:
                grabber.stop()

                for row in grabber.ttyData:
                    self.writeStdOut(row)

            time.sleep(0.5)  # prevents a misterious dead lock in the Orange cycle when refreshing the histogram
        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                                       QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))
    def reconstructWavefront(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.progressBarSet(10)

                    self.checkFields()

                    self.setStatusMessage(
                        "Modifing coordinates to equal optical paths")

                    if self.trace_shadow:
                        grabber = TTYGrabber()
                        grabber.start()

                    self.progressBarSet(50)

                    beam_out = self.input_beam.duplicate()

                    reference_distance = 0.0

                    for history_element in beam_out.getOEHistory():
                        if not history_element._shadow_oe_end is None:
                            reference_distance += history_element._shadow_oe_end._oe.SSOUR + history_element._shadow_oe_end._oe.SIMAG

                    for index in range(0, len(beam_out._beam.rays)):
                        optical_path_difference = beam_out._beam.rays[
                            index, 12] - reference_distance

                        beam_out._beam.rays[index, 0] = beam_out._beam.rays[
                            index,
                            0] + optical_path_difference * beam_out._beam.rays[
                                index, 3]
                        beam_out._beam.rays[index, 1] = beam_out._beam.rays[
                            index,
                            1] + optical_path_difference * beam_out._beam.rays[
                                index, 4]
                        beam_out._beam.rays[index, 2] = beam_out._beam.rays[
                            index,
                            2] + optical_path_difference * beam_out._beam.rays[
                                index, 5]
                        beam_out._beam.rays[index, 12] = reference_distance

                    last_element = beam_out.getOEHistory(
                    )[-self.element_before]

                    alpha = last_element._shadow_oe_end._oe.T_INCIDENCE
                    beta = last_element._shadow_oe_end._oe.T_REFLECTION

                    delta_calculated = numpy.round(
                        numpy.degrees(
                            numpy.arctan(
                                numpy.tan(beta) -
                                (numpy.sin(alpha) / numpy.cos(beta)))), 4)

                    # y max
                    cursor_1 = numpy.where(beam_out._beam.rays[:, 1] ==
                                           numpy.max(beam_out._beam.rays[:,
                                                                         1]))
                    cursor_2 = numpy.where(beam_out._beam.rays[:, 1] ==
                                           numpy.min(beam_out._beam.rays[:,
                                                                         1]))

                    point_1 = [
                        beam_out._beam.rays[cursor_1, 2][0][0],
                        beam_out._beam.rays[cursor_1, 1][0][0]
                    ]
                    point_2 = [
                        beam_out._beam.rays[cursor_2, 2][0][0],
                        beam_out._beam.rays[cursor_2, 1][0][0]
                    ]

                    delta_shadow = numpy.round(
                        numpy.degrees(
                            numpy.arctan((point_1[1] - point_2[1]) /
                                         (point_1[0] - point_2[0]))), 4)

                    self.delta_angle_calculated = delta_calculated
                    self.delta_angle_shadow = delta_shadow

                    if self.trace_shadow:
                        grabber.stop()

                        for row in grabber.ttyData:
                            self.writeStdOut(row)

                    self.setStatusMessage("Plotting Results")

                    self.plot_results(beam_out)

                    self.setStatusMessage("")

                    self.send("Beam", beam_out)
                    self.send("Trigger", ShadowTriggerIn(new_beam=True))
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception), QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
예제 #10
0
    def runShadowSource(self):
        #self.error(self.error_id)
        self.setStatusMessage("")
        self.progressBarInit()

        try:
            self.checkFields()

            ###########################################
            # TODO: TO BE ADDED JUST IN CASE OF BROKEN
            #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
            #       TO TEST SHADOW
            self.fixWeirdShadowBug()
            ###########################################

            wigFile = bytes(congruence.checkFileName("xshwig.sha"), 'utf-8')

            if self.type_combo == 0:
                inData = ""
            elif self.type_combo == 1:
                inData = congruence.checkFileName(self.file_with_b_vs_y)
            elif self.type_combo == 2:
                inData = congruence.checkFileName(self.file_with_harmonics)

            self.progressBarSet(10)
            #self.information(0, "Calculate electron trajectory")
            self.setStatusMessage("Calculate electron trajectory")

            (traj, pars) = srfunc.wiggler_trajectory(b_from=self.type_combo,
                                                     inData=inData,
                                                     nPer=self.number_of_periods,
                                                     nTrajPoints=501,
                                                     ener_gev=self.energy,
                                                     per=self.id_period,
                                                     kValue=self.k_value,
                                                     trajFile=congruence.checkFileName("tmp.traj"),
                                                     shift_x_flag=self.shift_x_flag,
                                                     shift_x_value=self.shift_x_value,
                                                     shift_betax_flag=self.shift_betax_flag,
                                                     shift_betax_value=self.shift_betax_value)

            #
            # calculate cdf and write file for Shadow/Source
            #

            self.progressBarSet(20)
            #self.information(0, "Calculate cdf and write file for Shadow/Source")
            self.setStatusMessage("Calculate cdf and write file for Shadow/Source")

            srfunc.wiggler_cdf(traj,
                               enerMin=self.e_min,
                               enerMax=self.e_max,
                               enerPoints=1001,
                               outFile=wigFile,
                               elliptical=False)

            #self.information(0, "CDF written to file %s \n"%(wigFile))
            self.setStatusMessage("CDF written to file %s \n"%(str(wigFile)))

            self.progressBarSet(40)

            #self.information(0, "Set the wiggler parameters in the wiggler container")
            self.setStatusMessage("Set the wiggler parameters in the wiggler container")

            shadow_src = ShadowSource.create_wiggler_src()

            self.populateFields(shadow_src)

            shadow_src.src.FILE_TRAJ = wigFile

            sys.stdout = EmittingStream(textWritten=self.writeStdOut)
            if self.trace_shadow:
                grabber = TTYGrabber()
                grabber.start()

            self.progressBarSet(50)

            self.setStatusMessage("Running Shadow/Source")

            write_begin_file, write_start_file, write_end_file = self.get_write_file_options()

            beam_out = ShadowBeam.traceFromSource(shadow_src,
                                                  write_begin_file=write_begin_file,
                                                  write_start_file=write_start_file,
                                                  write_end_file=write_end_file)

            if self.trace_shadow:
                grabber.stop()

                for row in grabber.ttyData:
                   self.writeStdOut(row)

            #self.information(0, "Plotting Results")
            self.setStatusMessage("Plotting Results")

            self.progressBarSet(80)

            self.plot_results(beam_out, 80)

            self.setStatusMessage("Plotting Wiggler Data")

            self.plot_wiggler_results()

            #self.information()
            self.setStatusMessage("")

            self.send("Beam", beam_out)
        except Exception as exception:
            QtGui.QMessageBox.critical(self, "Error",
                                       str(exception),
                QtGui.QMessageBox.Ok)

            #self.error_id = self.error_id + 1
            #self.error(self.error_id, "Exception occurred: " + str(exception))


        self.progressBarFinished()
    def reconstructWavefront(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.progressBarSet(10)

                    self.checkFields()

                    self.setStatusMessage("Modifing coordinates to equal optical paths")

                    if self.trace_shadow:
                        grabber = TTYGrabber()
                        grabber.start()

                    self.progressBarSet(50)

                    beam_out = self.input_beam.duplicate()

                    reference_distance = 0.0

                    for history_element in beam_out.getOEHistory():
                        if not history_element._shadow_oe_end is None:
                            reference_distance += (
                                history_element._shadow_oe_end._oe.SSOUR + history_element._shadow_oe_end._oe.SIMAG
                            )

                    for index in range(0, len(beam_out._beam.rays)):
                        optical_path_difference = beam_out._beam.rays[index, 12] - reference_distance

                        beam_out._beam.rays[index, 0] = (
                            beam_out._beam.rays[index, 0] + optical_path_difference * beam_out._beam.rays[index, 3]
                        )
                        beam_out._beam.rays[index, 1] = (
                            beam_out._beam.rays[index, 1] + optical_path_difference * beam_out._beam.rays[index, 4]
                        )
                        beam_out._beam.rays[index, 2] = (
                            beam_out._beam.rays[index, 2] + optical_path_difference * beam_out._beam.rays[index, 5]
                        )
                        beam_out._beam.rays[index, 12] = reference_distance

                    last_element = beam_out.getOEHistory()[-self.element_before]

                    alpha = last_element._shadow_oe_end._oe.T_INCIDENCE
                    beta = last_element._shadow_oe_end._oe.T_REFLECTION

                    delta_calculated = numpy.round(
                        numpy.degrees(numpy.arctan(numpy.tan(beta) - (numpy.sin(alpha) / numpy.cos(beta)))), 4
                    )

                    # y max
                    cursor_1 = numpy.where(beam_out._beam.rays[:, 1] == numpy.max(beam_out._beam.rays[:, 1]))
                    cursor_2 = numpy.where(beam_out._beam.rays[:, 1] == numpy.min(beam_out._beam.rays[:, 1]))

                    point_1 = [beam_out._beam.rays[cursor_1, 2][0][0], beam_out._beam.rays[cursor_1, 1][0][0]]
                    point_2 = [beam_out._beam.rays[cursor_2, 2][0][0], beam_out._beam.rays[cursor_2, 1][0][0]]

                    delta_shadow = numpy.round(
                        numpy.degrees(numpy.arctan((point_1[1] - point_2[1]) / (point_1[0] - point_2[0]))), 4
                    )

                    self.delta_angle_calculated = delta_calculated
                    self.delta_angle_shadow = delta_shadow

                    if self.trace_shadow:
                        grabber.stop()

                        for row in grabber.ttyData:
                            self.writeStdOut(row)

                    self.setStatusMessage("Plotting Results")

                    self.plot_results(beam_out)

                    self.setStatusMessage("")

                    self.send("Beam", beam_out)
                    self.send("Trigger", ShadowTriggerIn(new_beam=True))
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()", str(exception), QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
예제 #12
0
    def traceOpticalElement(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.progressBarSet(10)

                    self.checkFields()

                    self.setStatusMessage("Running SHADOW")

                    if self.trace_shadow:
                        grabber = TTYGrabber()
                        grabber.start()

                    self.progressBarSet(50)

                    ###########################################
                    # TODO: TO BE ADDED JUST IN CASE OF BROKEN
                    #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
                    #       TO TEST SHADOW
                    self.fixWeirdShadowBug()
                    ###########################################

                    shadow_oe_1 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_1(shadow_oe_1)

                    beam_out = ShadowBeam.traceFromOE(self.input_beam,
                                                      shadow_oe_1)

                    self.adjust_first_divergence(beam_out)

                    self.progressBarSet(60)

                    shadow_oe_2 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_2(shadow_oe_2)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_2)

                    self.adjust_second_divergence_and_intensity(beam_out)

                    self.progressBarSet(70)

                    shadow_oe_3 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_3(shadow_oe_3)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_3)

                    if self.trace_shadow:
                        grabber.stop()

                        for row in grabber.ttyData:
                            self.writeStdOut(row)

                    self.setStatusMessage("Plotting Results")

                    self.plot_results(beam_out)

                    self.setStatusMessage("")

                    self.send("Beam", beam_out)
                    self.send("Trigger", ShadowTriggerIn(new_beam=True))
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception), QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()
    def traceOpticalElement(self):
        try:
            self.error(self.error_id)
            self.setStatusMessage("")
            self.progressBarInit()

            if ShadowCongruence.checkEmptyBeam(self.input_beam):
                if ShadowCongruence.checkGoodBeam(self.input_beam):
                    sys.stdout = EmittingStream(textWritten=self.writeStdOut)

                    self.progressBarSet(10)

                    self.checkFields()

                    self.setStatusMessage("Running SHADOW")

                    if self.trace_shadow:
                        grabber = TTYGrabber()
                        grabber.start()

                    self.progressBarSet(50)

                    ###########################################
                    # TODO: TO BE ADDED JUST IN CASE OF BROKEN
                    #       ENVIRONMENT: MUST BE FOUND A PROPER WAY
                    #       TO TEST SHADOW
                    self.fixWeirdShadowBug()
                    ###########################################

                    shadow_oe_1 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_1(shadow_oe_1)

                    beam_out = ShadowBeam.traceFromOE(self.input_beam, shadow_oe_1)

                    self.adjust_first_divergence(beam_out)

                    self.progressBarSet(60)

                    shadow_oe_2 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_2(shadow_oe_2)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_2)

                    self.adjust_second_divergence_and_intensity(beam_out)

                    self.progressBarSet(70)

                    shadow_oe_3 = ShadowOpticalElement.create_screen_slit()
                    self.populateFields_3(shadow_oe_3)

                    beam_out = ShadowBeam.traceFromOE(beam_out, shadow_oe_3)

                    if self.trace_shadow:
                        grabber.stop()

                        for row in grabber.ttyData:
                            self.writeStdOut(row)

                    self.setStatusMessage("Plotting Results")

                    self.plot_results(beam_out)

                    self.setStatusMessage("")

                    self.send("Beam", beam_out)
                    self.send("Trigger", ShadowTriggerIn(new_beam=True))
                else:
                    raise Exception("Input Beam with no good rays")
            else:
                raise Exception("Empty Input Beam")

        except Exception as exception:
            QtGui.QMessageBox.critical(self, "QMessageBox.critical()",
                                       str(exception),
                                       QtGui.QMessageBox.Ok)

            self.error_id = self.error_id + 1
            self.error(self.error_id, "Exception occurred: " + str(exception))

        self.progressBarFinished()