원시데이터 수집 시스템
선정목록으로

Messdatenerfassung für quantitative Elektronenbeugungsmessungen

관련 산업용 섬유 · (9) 타이어코드

기본 정보

저자
  1. Dörr, Florian — TU Wien
DOI
10.34726/hss.2024.116763
저널
reposiTUm (TU Wien)
발행년도
2024
발행기관
TU Wien
피인용수
0
라이선스
0
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.34726/hss.2024.116763
토픽
Electron and X-Ray Spectroscopy Techniques
OpenAlex ID
W6909007069

평가 내용

관련도
관련
사업분야
산업용 섬유 · (9) 타이어코드
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '산업용 섬유 > 타이어코드' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

LEED ist eine weit verbreitete Messmethode aus der Oberflächenphysik. Eine Sonderform sind sogenannte LEED-I(V) Messungen. Bei diesen werden mehrere LEED Aufnahmen der gleichen Probe bei unterschiedlichen Elektronenenergien getätigt. Mit derartigen Messungen kann die genaue Atomanordnung in der Einheitszelle einer Probe ermittelt werden. Trotz der hohen Genauigkeit der Technik werden LEED-I(V) Messungen selten durchgeführt. Dies ist der Fall, da solche Messungen meist mit viel Arbeitsaufwand verbunden sind. Kommerziell erwerbliche Systeme, die den Arbeitsaufwand reduzieren, sind oft mit hohen Anschaffungskosten verbunden und liefern oft unbefriedigende Qualität der Daten. Das Ziel des ViPErLEED Projektes ist es, LEED-I(V) Messungen mit minimalem Arbeitsaufwand und minimalen Kosten zu ermöglichen. Zu diesem Zweck automatisieren und erleichtern die Bestandteile des Projektes große Teile der Aufnahme und Auswertung von LEED-I(V) Messungen.Diese Arbeit befasst sich mit dem messungsorientierten Teil des ViPErLEED Projektes. Die Arbeit gibt einen Überblick über dessen Funktion und Struktur. Sie soll als Handbuch und als Grundlage für das Verständnis der entwickelten Software dienen. Sowohl die generelle Nutzung des bereits implementierten Arduino Micro Controllers mitsamt den bereits programmierten Funktionen, als auch die selbstständige Implementierung von völlig neuen Funktionen innerhalb des umgesetzten Frameworks, soll durch diese Arbeit zugänglich gemacht werden. Die wesentlichen Bestandteile des Codes werden beschrieben und die Kommunikation innerhalb der Programmbestandteile erläutert. Zuletzt wird auch noch auf die Umsetzung von Energiesprüngen während einer Messung eingegangen und deren Einfluss auf die Messung beschrieben.

본문 151,768자

본문 펼치기
##### DIPLOMARBEIT # Data acquisition system for quantitative low-energy electron diffraction zur Erlangung des akademischen Grades ##### Diplom-Ingenieur/in im Rahmen des Studiums Masterstudium Technische Physik eingereicht von Florian Dörr Matrikelnummer 01604819 ausgeführt am Institut für Angewandte Physik der Fakultät für Physik der Technischen Universität Wien Betreuung Betreuer/in: Ao.Univ.Prof. Dipl.-Ing. Dr.techn. Michael Schmid Mitwirkung: Michele Riva, PhD Wien, 12.12.2023 (Unterschrift Verfasser/in) (Unterschrift Betreuer/in) #### Abstract Low-energy electron diffraction (LEED) is a surface-sensitive technique with widespread use. Almost every surface-science group has access to LEED optics. By performing multiple LEED measurements at different energies [LEED I(V)] it is possible to resolve the unit cell of a sample with very high precision. However, LEED-I(V) measurements are rarely done. This is because a lot of effort is required when acquiring and evaluating LEED-I(V) measurements manually. While there are commercially available systems to perform LEED-I(V) measurements, these are usually expensive, highly specialized, and do not always yield satisfactory data quality. The Vienna Package for Erlangen LEED (ViPErLEED) provides a system that automates large parts of acquisition and evaluation of LEED-I(V) data, to make LEED I(V) more accessible for a wider audience. This thesis describes the functions and components of an automated measurement system integrated into ViPErLEED, the ViPErLEED measurement package. The ViPErLEED measurement package is a system for data acquisition and measurement control that is meant to enable LEED-I(V) measurements with minimal effort at little cost. The system presented is capable to calibrate itself, acquire measurements, and present collected data visually. It is a python-based package built to communicate with a wide variety of controllers and cameras and can therefore be configured to fit a large range of user requirements. It is highly modifiable and devised to be expandable. The system can communicate with multiple controllers at once and can collect data from multiple devices at the same time. The C++-based Arduino Micro firmware has been fully implemented in this thesis to be used by the package. It is an all-in-one solution, and once the hardware has been assembled by the user, the provided code can be used out of the box to acquire data. The functionality implemented for cameras will be mentioned as well, but the main focus of this thesis is on the controller and measurement part of the package. The presented system significantly reduces the effort and time required to take LEED-I(V) measurements while improving measurement reproducibility and quality as well. This thesis will also explain how energy steps are implemented in the system and how these impact measurements. 1 #### Deutsche Kurzfassung LEED ist eine weit verbreitete Messmethode aus der Oberflächenphysik. Eine Sonderform sind sogenannte LEED-I(V) Messungen. Bei diesen werden mehrere LEED Aufnahmen der gleichen Probe bei unterschiedlichen Elektronenenergien getätigt. Mit derartigen Messungen kann die genaue Atomanordnung in der Einheitszelle einer Probe ermittelt werden. Trotz der hohen Genauigkeit der Technik werden LEED-I(V) Messungen selten durchgeführt. Dies ist der Fall, da solche Messungen meist mit viel Arbeitsaufwand verbunden sind. Kommerziell erwerbliche Systeme, die den Arbeitsaufwand reduzieren, sind oft mit hohen Anschaffungskosten verbunden und liefern oft unbefriedigende Qualität der Daten. Das Ziel des ViPErLEED Projektes ist es, LEED-I(V) Messungen mit minimalem Arbeitsaufwand und minimalen Kosten zu ermöglichen. Zu diesem Zweck automatisieren und erleichtern die Bestandteile des Projektes große Teile der Aufnahme und Auswertung von LEED-I(V) Messungen. Diese Arbeit befasst sich mit dem messungsorientierten Teil des ViPErLEED Projektes. Die Arbeit gibt einen Überblick über dessen Funktion und Struktur. Sie soll als Handbuch und als Grundlage für das Verständnis der entwickelten Software dienen. Sowohl die generelle Nutzung des bereits implementierten Arduino Micro Controllers mitsamt den bereits programmierten Funktionen, als auch die selbstständige Implementierung von völlig neuen Funktionen innerhalb des umgesetzten Frameworks, soll durch diese Arbeit zugänglich gemacht werden. Die wesentlichen Bestandteile des Codes werden beschrieben und die Kommunikation innerhalb der Programmbestandteile erläutert. Zuletzt wird auch noch auf die Umsetzung von Energiesprüngen während einer Messung eingegangen und deren Einfluss auf die Messung beschrieben. 2 #### Acknowledgement I wish to thank Ao.Univ.Prof. Dipl.-Ing. Dr.techn. Michael Schmid and Michele Riva PhD for supervising this work and the extensive help and support they have provided. Furthermore, I give my thanks to Univ. Prof.in Dipl.-Ing.in Dr.in techn. Dr.in h.c. Ulrike Diebold and the entirety of the Surface Science group at TU Wien for their help and the opportunity to do my Master thesis in this group. 3 #### Contents 1 Introduction 7 2 ViPErLEED measurement package 14 2.1 General overview . . . . . . . . . . . . . . . . . . . . . . . . . 14 2.2 Package anatomy . . . . . . . . . . . . . . . . . . . . . . . . . 15 3 Measurement GUI 18 3.1 Measurement front-end . . . . . . . . . . . . . . . . . . . . . . 18 3.1.1 File menu . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.1.2 Devices menu . . . . . . . . . . . . . . . . . . . . . . . 19 3.1.3 Tools menu . . . . . . . . . . . . . . . . . . . . . . . . 20 3.1.4 Settings menu . . . . . . . . . . . . . . . . . . . . . . . 20 3.1.5 About menu . . . . . . . . . . . . . . . . . . . . . . . . 21 3.1.6 Starting a measurement . . . . . . . . . . . . . . . . . 21 3.1.7 Aborting a measurement . . . . . . . . . . . . . . . . . 21 3.1.8 Set energy . . . . . . . . . . . . . . . . . . . . . . . . . 21 4 Measurement 22 4.1 Measurement progression . . . . . . . . . . . . . . . . . . . . . 22 4.2 `MeasurementABC` . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.2.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . 26 4.2.2 Preparation . . . . . . . . . . . . . . . . . . . . . . . . 26 4.2.3 Executing a measurement . . . . . . . . . . . . . . . . 27 4.2.4 Finishing a measurement . . . . . . . . . . . . . . . . . 28 4.2.5 Aborting a measurement . . . . . . . . . . . . . . . . . 28 4.2.6 Controller management . . . . . . . . . . . . . . . . . . 28 4.3 Acquisition of LEED-I(V) data . . . . . . . . . . . . . . . . . 29 4.4 Electron energy scale calibration . . . . . . . . . . . . . . . . . 30 4.5 Time-resolved data acquisition . . . . . . . . . . . . . . . . . . 32 5 Controller 36 5.1 Base controllers . . . . . . . . . . . . . . . . . . . . . . . . . . 37 5.1.1 Controller settings . . . . . . . . . . . . . . . . . . . . 37 5.1.2 Preparatory measures . . . . . . . . . . . . . . . . . . . 38 5.1.3 Setting energies . . . . . . . . . . . . . . . . . . . . . . 39 5.1.4 Taking measurements . . . . . . . . . . . . . . . . . . . 40 5.1.5 Data acquisition . . . . . . . . . . . . . . . . . . . . . . 41 5.1.6 Receiving measurements . . . . . . . . . . . . . . . . . 42 5.1.7 Accessing controller settings . . . . . . . . . . . . . . . 42 4 5.1.8 Controller operation supervision . . . . . . . . . . . . . 42 5.2 `ViPErinoController` . . . . . . . . . . . . . . . . . . . . . . . 42 5.2.1 Controller settings . . . . . . . . . . . . . . . . . . . . 44 5.2.2 Preparation . . . . . . . . . . . . . . . . . . . . . . . . 45 5.2.3 Setting energies . . . . . . . . . . . . . . . . . . . . . . 46 5.2.4 Taking measurements . . . . . . . . . . . . . . . . . . . 46 5.2.5 Receiving measurements . . . . . . . . . . . . . . . . . 46 5.2.6 Important properties . . . . . . . . . . . . . . . . . . . 47 5.3 Controller interaction visualization . . . . . . . . . . . . . . . 47 6 Serial 49 6.1 `SerialABC` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 6.1.1 Serial settings . . . . . . . . . . . . . . . . . . . . . . . 49 6.1.2 Port management . . . . . . . . . . . . . . . . . . . . . 50 6.1.3 Sending messages . . . . . . . . . . . . . . . . . . . . . 50 6.1.4 Receiving messages . . . . . . . . . . . . . . . . . . . . 50 6.2 `ViPErLEEDSerial` . . . . . . . . . . . . . . . . . . . . . . . . . 51 6.2.1 Sending messages . . . . . . . . . . . . . . . . . . . . . 51 6.2.2 Receiving messages . . . . . . . . . . . . . . . . . . . . 52 6.3 Serial interaction visualization . . . . . . . . . . . . . . . . . . 54 7 Camera 55 7.1 `CameraABC` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 8 Data Points 58 9 Plot 59 10 Settings 60 11 ViPErLEED Errors 61 11.1 Error table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 11.2 `QSerialPort` errors . . . . . . . . . . . . . . . . . . . . . . . . 66 11.3 `ViPErLEEDSettings` exceptions . . . . . . . . . . . . . . . . . 66 12 Step profile 67 13 Conclusions and outlook 70 A PyQt 71 A.1 `QObject` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 A.2 `QThread` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 5 A.3 Signals and Slots . . . . . . . . . . . . . . . . . . . . . . . . . 73 A.4 `QTimer` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 A.5 `QWidget` . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 A.6 `QSerialPort` . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 B Signals 75 B.1 Signal table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 6 #### 1 Introduction Surface studies of materials are essential to understand many of their physical and chemical properties. While there are many techniques to investigate surfaces, one low-cost option that is available to the vast majority of surfacescience groups is LEED. It is generally used to obtain data about the basic structure of samples and is commonly considered as a supporting technique rather than the main focus of a study. In order to motivate the development of ViPErLEED, the basics of LEED and its widely untapped potential will be elaborated on in this chapter. grids electron source scattered electrons sample screen Figure 1: A simplified LEED schematic displaying the basic components of a LEED setup. An electron beam is emitted by the electron source and scattered at the sample. LEED has been used for almost a century to conduct surface studies. A simplified schematic of a LEED setup can be seen in Figure 1. In essence, only an electron beam and a detector are required. As an electron source, a tungsten filament is already sufficient, but other emitters (e.g., LaB6) might be more desirable. A phosphor screen is often used as a detector. Electrons will light up the screen according to the intensity of the scattered electron wave. Normally, two to four hemispherical grids are placed between the sample and the screen. The first grid, the one closest to the sample, is grounded with the sample. This is done in order to prevent electrical fields from deviating the paths of scattered electrons. The second (and third, if present) grid is set to a negative potential as to repel electrons that have been inelastically scattered. Two grids are being used in an attempt to make the field between them more homogeneous. The fourth grid, if present, is 7 grounded again and only necessary if the current on the screen is measured. The phosphor screen behind the grids has a large positive voltage ( _≈_ 5 kV) applied to it [1]. In order to achieve a basic understanding of how LEED and any other diffraction method works, it is sufficient to look at diffraction under the kinematic approximation. The kinematic approximation assumes that scattering only happens once. In the case of LEED, this means that an electron enters the sample surface, gets scattered, and leaves the sample again. The electron is diffracted by the periodic structure of the sample because of its wave properties [2]. Incoming electron wave Outgoing electron wave θ d d Figure 2: Bragg diffraction at a surface Figure 2 shows a side view of a hypothetical surface. The black dots represent the atoms in the surface. The black and red arrows represent the incoming and outgoing electron waves, respectively. Both the incoming and outgoing waves are assumed to be plane waves. This is a valid simplification due to the distance between the electron gun and the sample. In this case the incoming wave is assumed to be impacting the sample perpendicularly. It is then Bragg diffracted at the periodic structure of the surface. When diffracted waves overlap constructively the typical Bragg intensity maxima appear. These peaks appear as bright spots on the phosphor screen. The angles of the intensity maxima in relation to the incoming beam can be calculated from the relation 8 _d_ sin Θ = _nλ._ (1) In Eq. (1), _d_ is the distance between rows of atoms and Θ is the scattering angle, i.e., the angle of the electron trajectory between entering and leaving the surface. _n_ is a positive integer, and _λ_ is the de Broglie wavelength of the electron. At angles Θ at which Eq. (1) is fulfilled for a certain beam energy and row distance, intensity peaks of the diffracted electron beam can be observed. Eq. (1) reveals that the wavelength of the scattered electrons needs to be smaller than the distances in the observed material to resolve them. The de Broglie wavelength of electrons can be calculated as _λ_ = <sup>_<u>h</u>_</sup> _p_ _._ (2) 2 _mE_ _<u>h</u>_ <sup>_<u>h</u>_</sup> _~~√~~_ _p_ <sup>=</sup> 2 In Eq. (2), _h_ is the Planck constant, _p_ = 2 _mE_ is the electron momen tum, _m_ its mass and _E_ its kinetic energy. LEED measurements are generally performed at energies between 50 and 500 eV [3]. At such energies the electron wavelength ranges from 1.8 to 0.5 Å and is therefore small enough to resolve the unit cell of crystalline structures. Furthermore, at these energies the inelastic mean free path of electrons is in the order of magnitude of 10 Å. Electrons that penetrate deeper are very likely to scatter inelastically on phonons and plasmons and therefore most likely lack the energy to overcome the retarding voltage applied to the grids in front of the screen. This means that LEED is highly surface sensitive, and the investigated sample only needs to be a few layers thick [2]. The diffraction process at the lattice of the investigated sample is mathematically equivalent to a Fourier transform. Approximating the surface as a two-dimensional grid and performing a Fourier transformation on it creates rods in the reciprocal space. This is because only two dimensions are defined, and values in the third dimension can therefore be chosen at will. The screen cuts through these rods and makes them visible to the eye as the bright intensity peaks, which can be seen in Figure 3. This can also be interpreted as the screen showing intensity peaks where the wave vectors of the diffracted electrons land on the Ewald sphere. The kinematic theory is enough to determine the overall crystal lattice of a sample. This means, in particular, that the position of the spots and the symmetry of the LEED pattern allow one to qualitatively determine the shape, size, and symmetry of the unit cell of the surface. However, there is more information hidden in the intensity of peaks. The brightness of the peaks varies with the energy of the electron beam. This complexity of the intensity variation cannot be explained by the kinematic approximation. 9 In Eq. (2), _h_ is the Planck constant, _p_ = _√_ sample electron source grids phosphor screen <u>3,0</u> <u>2,0</u> <u>1,0</u> <u>0,0</u> <u>-1,0</u> <u>-2,0</u> <u>-3,0</u> <u>k</u> Figure 3: Ewald sphere construction for LEED, identifying the directions of the diffracted beams that interfere constructively giving bright Bragg reflexes on the phosphor screen. Reprinted from [4] According to it, only the contributions from diffraction processes beneath the first atomic layer of the surface should be visible in the intensity variation, but in fact the I(V) spectrum is much richer in information. To describe the intensity variation of peaks with the energy, multiple scattering processes have to be taken into account. This leads to the dynamic theory. To describe multiple scattering processes at a surface, the so called “muffin-tin” potential is used. As implied by Figure 4, the muffin-tin potential describes a potential in which every atom is approximated as a spherically symmetrical dip in an otherwise constant energy below the vacuum potential. The _E_ -axis denotes the potential and the _x_ -axis denotes a real space axis in the sample. This constant potential between atoms is called interstitial potential or muffin-tin constant. The benefit of this potential is that between the scattering centers, in the region where the potential is constant, the electrons can still be described as plane waves. The scattering process leads to a phase shift of the electron wave. The scattering process is fully described through this phase shift and the plane wave propagation, and the atoms can be assumed to be point scatterers [4]. With multiple scattering processes, the energy dependence of the relative intensity of the spots is now described, but the effort to calculate the I(V) curve has vastly increased. With this approach it is possible to simulate a unit cell and predict the intensity variations with changes of the beam energy. Generally there has to be a reasonable guess for the structure in the 10 _E_ _E_ vacuum Position of atoms _E_ interstitial _x_ Figure 4: The Muffin-tin potential. It receives its name from the periodic potential drops between the interstitial potential which are reminiscent of a muffin tin. beginning which can for instance be relaxed with density functional theory. Afterwards, the dynamic theory is used to calculate the intensity curves for it. Since calculating the curves is a very expensive operation, the curves are usually only calculated for one initial structure and variations are calculated with perturbation theory. This approach is called tensor-LEED [5]. To compare the theoretical predictions to reality, experimental data must be collected with the LEED setup. It is necessary to acquire images at various energies over a wide energy range and extract the intensity curves for the observed spots in this data. This is called LEED I(V), as intensities are measured in relation to the voltage used to accelerate the electron beam. Additionally, the beam current _I_ 0 is measured to normalize the acquired intensity curves. If the beam current is known, the effects of beam current changes due to shape changes of the filament and the slow energy dependence of _I_ 0 can be removed. Information about the sample can be gained by changing the energy of the electron beam and by changing the angle at which the LEED I(V) measurement is performed. The latter way to gain additional data is particularly interesting: measuring the same energy range at a different angle adds to the measurement range as increasing the energy range of the measurement would. To compare experimental I(V) curves to the calculated ones, a so-called reliability factor ( _R_ -factor) is used. There are many definitions for it, but one of the most prominent ones is the Pendry _R_ -factor by J. B. Pendry [6], which will be derived here. To start off, we take a closer look at the intensity 11 _I_ . It can be approximated as a series of Lorentzian peaks, that is _I_ ( _E_ ) _≈_ _j_ _<u>aj</u>_ _._ (3) ( _E −_ _Ej_ ) <sup>2</sup> + _V_ 0i <sup>2</sup> In Eq. (3) the _Ej_ are the energies of the peak maxima, the _aj_ are constants describing the height of the maxima, and _V_ 0i is the imaginary part of the electron self energy. _V_ 0i determines the width Δ _E_ = _|_ 2 _V_ 0i _|_ of the peaks. The Pendry _R_ -factor now takes the logarithmic derivative of the intensity as the observable gathered from the data. It is taken because of its insensitivity to the amplitude, since _L_ ( _E_ ) = <sup><u>d ln(</u></sup> <sup>_<u>I</u>_</sup> <sup><u>)</u></sup> = <u>1</u> d _E_ _I_ ( _E_ ) <u>d</u> _<u>I</u>_ d _E_ <sup>_._</sup> (4) To avoid divergence when the intensity is zero, the _Y_ function _<u>L</u>_ <u>(</u> _<u>E</u>_ <u>)</u> _Y_ ( _E_ ) = (5) 1 + V <sup>2</sup> 0i <sup>_L_</sup> <sup>2(</sup> <sup>_E_</sup> <sup>)</sup> is introduced. It takes the previously defined observable _L_ and divides it by a term that will not allow it to diverge as _L_ did. With the _Y_ function, the Pendry _R_ -factor can be constructed. _R_ P = <u>(</u> _<u>Y</u>_ <u>exp</u> _<u>−</u>_ _<u>Y</u>_ <u>theo)</u> <sup>2</sup> <u>d</u> _<u>E</u>_ ~~�~~ ( _Y_ exp <sup>2</sup> <sup>+</sup> <sup>_Y_</sup> theo <sup>2</sup> <sup>)d</sup> <sup>_E_</sup> exp <sup>2</sup> <sup>+</sup> <sup>_Y_</sup> <sup>2</sup> (6) theo <sup>2</sup> <sup>)d</sup> <sup>_E_</sup> An _R_ P-factor of 0 means perfect correlation of the experiment with the guessed structure. If it is 2, then this implies perfect anti-correlation. A value of 1 means no correlation at all [6]. This comparison between prediction and experiment is the crucial part of LEED I(V). It is a well-defined and quantitative comparison between theory and experiment. If done correctly, the accuracy of structural determination can be in the order of picometers. In the past, taking LEED I(V) measurements and evaluating them would take hours without automation. There are commercial solutions for this, but they are generally expensive and not as adaptable as the system we developed as part of this thesis work. Our goal is to provide an all-in-one solution that is cheap and easy to use. The data collected by the measurement can immediately be viewed and evaluated. Our setup allows the user to complete measurements within minutes with full automation. The reduction in effective measurement time will allow investigation of samples that degrade under long-term electron bombardment. Tracking spots over multiple images does no longer need to be done manually as ViPErLEED comes with a spot 12 tracker that can even correctly identify other spots after one spot has been given initially. ViPErLEED also includes full integration of the Erlangen Tensor LEED package (TensErLEED). TensErLEED allows fast and efficient quantitative analysis of intensity spectra of virtually any periodic surface. But this and the spot tracker are not a matter of the measurement package and only mentioned here to give a taste of the scale of the project. Our system requires very few modifications on most LEED systems to be installed and take high accuracy measurements. The ViPErLEED measurement package needs to be able to set the beam energy on the LEED optics, which is also the only strict necessity. We provide schematics for the hardware which can be assembled by the user with low-cost components. The suggested controller is however not a necessity and other controllers can take its place. This means, non-ViPErLEED controllers can be made to work with the measurement package. To use all of the pre-made calibration features, the system also needs to be able to measure the beam energy and the beam or sample current at the very least. If modifications are required, we provide instructions on our website on how to do these for the most common LEED systems. This thesis will not describe any of the conducted modifications, which are available in the ViPErLEED documentation (found under `[https://github.com/viperleed](https://github.com/viperleed)` and `[http://viperleed.org/](http://viperleed.org/)` ). The focus of this thesis is instead on the software part of the ViPErLEED measurement package. It will describe how it works and how it can be used to conduct LEED I(V) measurements. Currently our software requires Python 3.7 or newer, therefore supporting Windows, Linux and Mac OS. However, effectively only support for Windows has been fully implemented and tested and the available camera drivers only work under Windows. In the following chapters the measurement package is separated into smaller functional parts and explained. Each chapter goes deeper into one specific topic that is isolated from the remaining parts of the package. Wherever knowledge about another chapter is crucial, cross-references are placed. 13 #### 2 ViPErLEED measurement package 2.1 General overview The measurement control system presented in this thesis is responsible for managing measurements, controlling devices, communicating tasks and receiving data. It performs many tasks and multiple components are required for it to function. First, there is the actual hardware that is required to perform a LEED-I(V) measurement. This hardware consists at least of one camera and one controller. The camera is necessary to collect images of the LEED pattern emerging on the LEED screen. The mentioned controller, the one that is necessarily required, will be called the primary controller. The primary controller is at the very least required to set the beam energy (HV) on the LEED optics. Note that the controller does not necessarily need to be integrated into the LEED electronics. A controller can be a completely separate device from the optics unit, as long as this unit is externally programmable. However, a controller may perform more and/or different tasks. The developed system is capable of handling more devices than just one controller and one camera. This design choice was made for multiple reasons. First, a user might have a primary controller that can only set the beam energy, but might need another controller to measure a specific quantity at the same time. For instance, when setting the beam energy, the energy and the beam current ( _I_ 0) need a certain time to settle. With an additional controller capable of measuring these quantities, the settle times can also be determined for a primary controller that cannot measure on its own. Any additional controllers aside from the primary controller are called secondary controllers. Note that secondary controllers never set the beam energy. There also can be multiple cameras at the same time, if required. The system is able to control them all at the same time and will receive and process frames from all of them simultaneously. The software described in this thesis comprises two core parts. One part is related to user interaction and the other part manages the hardware. New developers should only require to extend or edit the portion of the code that manages the hardware. The current version of the hardware management part does feature a fully implemented controller. The software for hardware management can be upgraded to fit new controllers and cameras. It is assumed that there is a suitable interface for all involved devices to communicate with the PC. To summarize, the measurement package can manage multiple devices at the same time to achieve full automation of a measurement. Each of those devices has a software counterpart that is specifically tailored to work with 14 this device. New devices that have not been implemented yet can be added retroactively and will work in a fully integrated manner with the remaining parts of the package. 2.2 Package anatomy class Measure class CameraViewer class CameraViewer class MeasurementPlot class Measurement class Camera 1 class Camera N class Primary Controller class Secondary Controller 1 class Secondary Controller M class DataPoints class Driver 1 class Driver N class Primary Serial class Secondary Serial 1 class Secondary Serial M data data data Set E data data PC Hard drive hardware Camera 1 hardware Camera N hardware Primary Controller hardware Secondary Controller 1 hardware Secondary Controller M Figure 5: Visualization of the ViPErLEED measurement package as functional blocks. On the right the hardware parts can be seen. Progressing from the right to the left, first the drivers and serials handling the communication between the hardware and the software can be seen. These communicate with the camera and controller classes managing the hardware. All parts not directly related to the user interface are bound together by the measurement, handling all of the data-acquisition-related tasks. Acquired data is further sent to GUI-related parts to be displayed, as seen on the left. The ViPErLEED measurement package is structured in multiple objects which all serve a specific purpose. They interact with each other while the measurement is ongoing. Interaction is achieved through signals if the task must be executed in a different thread and by direct calls if the demand 15 is time critical (see Appendix A.2). Measurements and devices are implemented as abstract classes. These abstract classes contain all of the basic functionalities required to work with the system. They work as base classes and can be subclassed to support new devices. The subclasses then only have to focus on the specifics of the device, therefore simplifying implementation of new hardware. The overall structure is schematically represented in Figure 5. Notice that Figure 5 is a simplification, and further classes are used in the background, but they are not necessary to achieve a basic understanding of the measurement process. The objects on the left all relate to the GUI, in the middle the objects responsible for I/O handling are located, and on the right there is the physical hardware. All of the classes are tied together in the measurement GUI (see Section 3). It is denoted in Figure 5 as the `Measure` class. It is the graphical user interface the user interacts with to start, stop, and observe measurements. The class interacts with all other parts of the measurement package either directly or indirectly. It is the first object of the measurement package that is visible to the user. It is responsible for setting up the measurement and presenting the user with a way to interact with devices and collected data. The camera and controller settings can be edited via GUI widgets and the location where measurements should be saved can be selected here. The measurement (see Section 4) started by the GUI is its own entity and handles all of the devices selected in the settings to take part in the measurement. Its primary role is to handle the flow of the measurement and instructing devices on which tasks to perform. It collects data from the devices and stores it in a dedicated data structure ( `DataPoints` ). The measurement class requires at least one primary controller, and it can take any number of cameras and secondary controllers. `DataPoints` objects (see Section 8) act as a storage for measurement data in a sorted manner which can also return specific measured quantities on demand. It is responsible for saving numerical data to comma-separated files and reading data from previously stored measurements to plot them. Controllers (see Section 5) are handled by the measurement object. The primary controller is differentiated from the secondary controllers by the fact that it sets the beam energy on the LEED optics. The primary controller does not necessarily need to collect data, but it is required to be able to set the beam energy. The secondary controllers, instead, only need to acquire measurements. The distinction between the primary controller and secondary controllers has been made to allow the implementation of a non-ViPErLEED controller exclusively responsible to set beam energies as is required by some commercially available LEED systems (e.g., the one produced by OCI). Each controller communicates with the physical hardware via a serial port, man 16 aged by `SerialABC` objects (see Section 6). Each controller lives in a different thread from the other ones. This is done because all controllers are managed in parallel and do return data asynchronously. The controller forwards collected data along with the times at which measurements were taken to the measurement object. Cameras (see Section 7) are also handled by the measurement object. All cameras are treated the same way by the measurement class, but they are treated differently than controllers. Cameras are triggered separately from controllers. They are triggered when the beam energy is settled. At this point in time, the beam current may not be stabilized yet, but the impact of slight variations of the beam current _I_ 0 on LEED images is minimal. The measured quantity in the images is the energy dependence of the intensity curves of the observed spots. Therefore, cameras are triggered when the energy has stabilized and not when the current has stabilized. This is done to conserve time because acquiring quality images normally takes longer than acquiring any data the controllers may measure. Each camera has its own driver that is responsible for the communication with the associated hardware. The driver takes a role in relation to the camera like the serial class does to the controller. Raw images acquired by the camera are processed by `ImageProcessor` objects. Numerical data can be plotted in the `MeasurementPlot` (see Section 9) in real time. There, multiple quantities measured by different controllers can be displayed simultaneously as long as they are of the same unit. Taken images are displayed by `CameraViewer` s. Each camera has its own camera viewer, displaying the most recent image acquired by the camera. The measurement, controller, and camera classes all use `ViPErLEEDSettings` (see Section 10) to handle their settings. These settings can be edited through the GUI tools, but can also be looked up and edited with a simple text editor. Certain settings are even automatically edited by the measurement package to use them later on, which is for instance the case when calibrating the nominal beam energy set by the primary controller. It is necessary to correctly report errors to the user that may occur during regular operation. The system therefore features a universal reporting structure, that will always display an error code and, more importantly, an error description to the user. The most common errors are detected, reported graphically, and the description often includes instructions on how to fix the error. Internally, the errors and their descriptions are contained in `ViPErLEEDErrorEnum` objects (see Section 11). 17 #### 3 Measurement GUI The measurement GUI is the interface for the user to interact with the measurement package. The measurement GUI can be opened by selecting the “Measure LEED-IV” button as seen in Figure 6. Figure 7 shows the measurement GUI while no measurement is running. Here settings can be edited, measurements can be started and aborted, and saved data can be loaded. The menus in the top contain the settings-related tools, specifically by selecting “Devices” the device settings can be accessed. The widgets below are directly related to the measurement. Additionally to the GUI window, the measurement GUI also always opens a window in which loaded or measured data can be plotted (see Section 9). If cameras are connected, their last image will also be displayed in separate windows during a measurement. Measurement GUI Figure 6: Screenshot of ViPErLEED GUI. The button on the bottom opens the measurement GUI. 3.1 Measurement front-end The measurement front-end is a window the user can interact with to control measurements. It can be accessed by pressing the lower button on the ViPErLEED GUI as seen in Figure 6. A screenshot of the measurement GUI is displayed in Figure 7. It allows the user to select devices and see their configuration. It can as well open up a live stream of detected cameras. A `MeasurementPlot` (see Section 9) is automatically opened with the measurement GUI, and live measurements will be plotted in real time. Old 18 BadPixelsFinder Controllers and cameras Folder locations Measurement type Figure 7: Screenshot of the measurement GUI. The menus on the top contain tools and allow the changing of settings, while the buttons below allow the starting and aborting of measurements and the selection of the measurement type. measurements can be opened and plotted in the measurement plot. System settings for measurements have to be set before taking a measurement. The measurement type can be selected in the window. The class overseeing the creation and handling of the measurement GUI is `Measure` . The errors of the GUI are found in `UIErrors` . The signals of this class can be found under `Measure` in the signal table. The `Measure` object can be found in the `uimeasurement` module. `Measure` is a subclass of `ViPErLEEDPluginBase` . 3.1.1 File menu Via this tab users can open up saved measurements. They will be automatically plotted and displayed in the plotting window. 3.1.2 Devices menu This menu tab allows the user to access detected cameras and controllers that are supported in their respective sub-menus seen in Figure 8. If a camera has the necessary requirements and settings, the user can start up a `CameraViewer` by clicking on the device in the camera section. This viewer will give a live view of the selected camera. By right clicking it, it is possible to view and change the settings and set the region of interest (ROI). More on cameras and their settings can be read in Section 7. Upon starting a measurement the `CameraViewer` will automatically be reset, and the camera will no longer return a live view. The controller settings can be accessed by selecting them. In the window containing the controller settings the user can edit their respective settings 19 Figure 8: Screenshot of the “Devices” menu. The settings of a device can be accessed by selecting a device under one of the two sections. for a measurement if the controller has that option. In the case of the viperino controller, as described in Section 5, it is also possible to see the hardware configuration and set the serial number of the controller. The viperino controller does show which quantities can be measured by the present hardware configuration. 3.1.3 Tools menu This tab contains various utilities that are usable independently from a measurement. Currently, the only utility available is the one for detecting bad pixels. Upon selecting “Find bad pixels...” users are presented with a dialog that will guide them through bad-pixel acquisition. Bad pixels are pixels that are either too hot, too dark, or too noisy and have to be found before doing LEED-I(V) measurements to ensure high quality data. Bad pixels are replaced by the best neighboring pixels. In the future there will be the option to upgrade the firmware of the viperino controller and other ViPErLEED hardware under the tools tab. 3.1.4 Settings menu Upon pressing on “Settings”, a window will open up which lets the user select in which folder configuration files should be stored and in which folder measurements should be automatically saved. Note that the configuration files contain all settings of the devices involved in a measurement. More details on settings in general are given in Section 10. Specific details for special settings files are given in the respective measurement (Section 4), controller (Section 5), serial (Section 6), and camera (Section 7) sections. 20 3.1.5 About menu The about section contains useful information about the version of the installed ViPErLEED package and instructions on where to report bugs. 3.1.6 Starting a measurement By pressing the “Start Measurement” button in Figure 7, the measurement type selected below is enacted. The GUI will start the selected measurement type with the measurement settings found in the path given in the settings menu. The measurement itself runs in a different thread as the GUI in order to keep the GUI responsive. The preparation for the measurement is initiated and when it is completed, the actual measurement is starting. Measured data can be visualized in real time in the measurement plot. In the future it will be possible to edit the measurement settings when starting a new measurement. 3.1.7 Aborting a measurement This button is only enabled during an active measurement. Pushing it will interrupt and stop the measurement as soon as possible. This is the only way to interrupt a time-resolved, endless measurement (see Section 4). 3.1.8 Set energy In future versions this button will enable the user to set the energy of the electron beam to the value selected in the text box to the right of it. In combination with the `CameraViewer`, this can be used, for example, to properly align a sample before acquiring a measurement. At the time of writing this thesis, this has not been implemented yet. 21 #### 4 Measurement A “measurement”, as described by this section, is the entity managing the actual measurement process enacted by the ViPErLEED measurement package. The “measurement” knows all of the devices involved in a measurement, gives commands to them and receives data from them. Before a “measurement” can start, it has to be able to communicate with the necessary hardware. Communication during a measurement is entirely performed through specific handlers for each device. Communicating in this manner allows the “measurement” to issue generic commands to the software equivalents of the cameras and controllers. This generic command is then translated into commands specific to each device, completely abstracting communication and therefore allowing the use of any camera and controller as long as they have been implemented on the software side. The `MeasurementABC` (Section 4.2) is the abstract base class for all measurement classes and contains all of the basic functionalities all of them require. The fully implemented measurement types currently available all serve specific tasks. To ensure that beam energies set on the LEED optics are accurate during a measurement, the primary controller has to be calibrated for the LEED optics. This can be done by performing a `MeasureEnergyCalibration` (Section 4.4) before doing any other measurement. Time-resolved data can be acquired by a `TimeResolved` measurement (Section 4.5). This data can be used to determine how long the beam energy and beam current need to settle after a new energy has been set on the LEED optics. The final measurement type is the `IVVideo` (Section 4.3) which performs all the tasks needed to collect LEED-I(V) data. Measurements can either be energy-resolved or timeresolved. An energy-resolved measurement will collect one measurement per controller for each requested quantity at a certain energy. A time-resolved measurement in contrast will remain at each energy for the desired amount of time and continue collecting data during this time span. This section will first explain the flow of a measurement and then go into deeper details of each of the measurement types. 4.1 Measurement progression The functionality of the different measurement types can be broken down into functional blocks as shown in Figure 9. While certain tasks are performed by different objects other than the measurement (e.g., the actual preparation of hardware performed by a controller or a camera), it is sufficient to attribute them to the measurement class to understand the overall flow. The first functional block is the initialization phase of the measurement 22 class Measurement Initialize Prepare Set Energy Measure Process data Finalize Error report Error Display data Save Data Figure 9: Measurement functional flow chart. The figure displays the functional blocks a measurement consists of, progressing from top to bottom. The measurement is supposed to go through each block from initializing to finalizing the measurement. A single measurement step involves setting an energy, acquiring data, and processing it. Processed numerical data is displayed as a plot. The latest processed image for each camera is shown. After processing, the measurement decides if it has to collected more data by returning to setting the energy, or if it can wrap things up and save the collected data. At any point an error may occur, which will force the measurement to stop and attempt to save the data it has collected so far. Detected errors are reported to the GUI. 23 object. In this phase the measurement creates the other objects required for its own operation. Settings are read from the settings files, and communication with the hardware is established. The preparation phase is entered if the initialization was completed uninterrupted. (This phase is in fact the starting point of the measurement from the viewpoint of the GUI.) In this phase the connected devices are instructed to perform their preparations to execute a measurement. The preparation of the controllers is split into two steps, one before the starting energy of the measurement has been set and the other after the energy has been set. This is done to ensure that certain preparation tasks can be performed while the starting energy is guaranteed to be set. These, for example, include calibration steps of the measurement devices that require a non-zero electron energy. When all controllers are done with the first preparation step, the starting beam energy is set and the second preparation step is started. The preparation of the cameras is only triggered at the beginning of the first preparation step as their preparation is independent of the beam energy. The preparation phase is complete when all of the devices have completed their own preparation and are no longer busy. The content of the preparation is unknown to the measurement class and is only known by each controller/camera class for themselves. Once preparation has been completed, the measurement loop is engaged. At the beginning of each iteration of this loop, the next beam energy of the measurement is set. This can be a no-op if the required energy has already been set as is the case right after the end of the preparation. Along with the required energy to set, a settling time is also sent to the primary controller. This settling time is the time controllers are supposed to wait before taking measurements. Similarly, the cameras can have a different time they are supposed to wait before acquiring frames. Setting the energy can be as simple as doing a single abrupt energy step, or as complicated as setting multiple intermediate energies with different times to wait afterwards. Energy steps and the reasons for waiting times are elaborated on in Section 12. After the desired energy has been set and the settling time has passed, the controllers and cameras will start to acquire data. Depending on the measurement type this can be in triggered mode or continuous mode. In triggered mode the devices will acquire a set number of measurements and return data once per request. In continuous mode they will keep returning data until stopped. The exact behaviours of each measurement type are discussed in Sections 4.3 ( `IVVideo` ), 4.4 ( `MeasureEnergyCalibration` ), and 4.5 ( `TimeResolved` ). When the desired amount of data has been collected, it is stored as a data point in a `DataPoints` object. Newly collected numerical measurements 24 are plotted at the end of the measurement step. Each camera displays its newest image in its `CameraViewer` as soon as it has been processed. If the measurement settings require further measurements, then the measurement proceeds to setting the next beam energy. If the desired end point has been reached, then the measurement class will enter the finalization phase. During finalization all collected data is saved for future use. The used devices are disconnected, and the ViPErLEED package is returned to a state ready to start a new measurement. The beam energy is always set to zero at the end of a measurement. The configuration files are stored with the collected data to enable an exact reproduction of the measurement in the future. Errors may happen at any point during the measurement. A descriptive error report to aid during troubleshooting has been added for many errors. Whenever able to, the measurement class will attempt to salvage as much data as possible despite an error and save it. The system is returned to a safe state by setting the electron beam energy to zero. Many possible errors have been accounted for and will lead to an abortion of the measurement. The measurement may also be aborted by the user if required, which will also save all collected data and set the beam energy to zero. 25 4.2 `MeasurementABC` The `MeasurementABC` contains many of the basic functions required to perform a measurement, such as creating the software objects that handle hardware devices (controllers and cameras) and collecting data from these devices. It can do all the necessary preparations and can give all of the necessary commands to perform a measurement. What it does not contain is in which manner to perform these measurements as this is a matter of its subclasses. The module containing this class is the `abc` module located in the `measurement` package. The errors of the `MeasurementABC` class are found in `MeasurementErrors` . Its mandatory settings include a primary controller in the devices section and a starting energy in the measurement settings of the `ViPErLEEDSettings` handed to it. The signals of this class can be found under `MeasurementABC` in the signal table. This section elaborates more on the common features all measurement types share and is partially a repeat of the flow chart in Section 4.1, but focuses much closer on the actual implementation of the code. 4.2.1 Initialization During initialization, `MeasurementABC` takes care of creating a `DataPoints` instance, the `data_points` property, to store all of the received measurements (both numerical data from controllers and information about images acquired by cameras). All measurement types take their settings from their configuration files. These files are read, checked if they contain all necessary settings and applied to the measurement [in `set_settings()` ]. Invalid or missing settings are reported to the GUI and displayed to the user. The necessary hardware to perform the measurement is determined from the settings. The measurement will attempt to create the software counterparts of these devices to manage them. The objects related to controllers are moved to separate threads, except for the primary controller (see Section 4.2.6). After being initialized, devices are technically in a state ready to perform measurements, however, they have not done their preparation tasks yet. 4.2.2 Preparation The beginning of the measurement is handled by the `begin_preparation()` method. This is the intended entry point to start a measurement and is the way the GUI triggers a measurement. When the measurement is started in this manner, it will initiate the first preparation step in the devices it is handling. The devices then work through all tasks they can complete before an energy is set. These tasks should include items such as determining 26 the state of the hardware or internally calibrating the electronics against a reference voltage. Unlike the other controllers, the primary controller has the unique task of setting the first beam energy at the end of its own first preparation step. Each controller lets the measurement know it is not busy anymore when it has completed all of its preparation tasks in the first step. Once all controllers have completed the first preparation step, the second preparation step will begin. Since the starting energy was set in the first preparation step, now all of the tasks that require a beam energy can be performed. Such a task could for instance be determining a reasonable gain for the measuring hardware. Again the devices enact their respective tasks on their own and report when they are not busy anymore. `MeasurementABC` will wait until all devices have completed their tasks. At the end of the preparation, the `prepared` signal is emitted, and the first measurement step is started by calling the `start_next_measurement()` method. 4.2.3 Executing a measurement The execution of a measurement is performed in a loop. First an energy is set, then data is acquired, and then the measured data is processed. After which the measurement is either completed, or it returns back to setting a new energy. One iteration through this loop is one measurement step, or energy step, as each iteration is done at a single beam energy. Each measurement step is started automatically by calling the `start_next_measurement()` method. The specifics on how each step looks are determined by the subclass of `MeasurementABC` . The base implementation of this method will automatically take care of creating a new entry in the data points where information about the numeric values and images acquired at this energy will be stored. A core detail that is shared between all subclasses is that the controller that sets the beam energy is the only controller directly triggered to measure by the measurement class. All other controllers are only triggered after the `about_to_trigger` signal of this controller has been emitted. Further details about the triggering of controllers after setting an energy can be found in Section 5.1.3. At the beginning of each measurement step, the energy should be set [with `set_leed_energy()` ]. The profile of the energy step can be more complex than just a jump from one energy to another. For instance, a single step can be split into two or more intermediate steps. Section 12 elaborates more on how step profiles can be optimized to reduce waiting times. Whenever data is returned from a device it is stored in `data_points` . If all devices are idle and all expected data was received, then the measurement checks whether it is finished. This check returns if the measurement is completed or goes on. The ending parameters can vary between different 27 measurement types and depend on their settings. Normally, a measurement ends when a specific energy value has been reached. If the measurement goes on, then `start_next_measurement()` is called again. If it is completed, then the finalization of the measurement begins. 4.2.4 Finishing a measurement The end of a measurement is initiated in the finalization. All measurement data that arrives after this process has been initiated will be discarded. When ready, the measurement will order all connected devices to stop their ongoing processes. Devices will abort all ongoing data acquisition and return to an idle state. The measurement will wait for all devices to report back that they have successfully aborted their tasks. Once all devices are idle, the measurement will attempt to save the collected data and disconnect all secondary devices. The connection to the primary controller is maintained. This way the electron energy can be set back to zero before the measurements concludes its execution. When the primary controller is done, it is finally disconnected and all active threads are stopped. At the end, the `finished` signal is emitted. 4.2.5 Aborting a measurement For various reasons it may be necessary to abort a measurement. This may be actively initiated by the user or it may happen automatically because an error was detected. When a measurement is aborted, it attempts clean up after itself to prevent conflicts. There also is a failsafe to force the measurement to stop should an error occur while trying to abort. At the end of an abort a measurement will finalize like the normal end of a measurement would. This ensures that any data that may be available is safely stored to disk, and that the electron energy is reset to zero. Aborting is done via the `abort()` method. 4.2.6 Controller management As outlined in Section 2.2, controllers can be differentiated into primary controllers and secondary controllers. Each measurement has one dedicated primary controller and any number of secondary controllers. The primary controller is in charge of setting the beam energy, while the secondary controllers only perform measurements. The measurement may potentially have to manage a large amount of controllers, all of which can theoretically return data at any point during a measurement. To allow the measurement to handle this complicated issue, the design choice to implement multi-threading for 28 controllers was made. Secondary controllers are moved to separate threads because their tasks are less time critical than those of the primary controller. Secondary controllers perform their activities and receive data asynchronously in their own thread, while the primary controller must react immediately to requests by the measurement. In other words, secondary controllers all live in their own threads, while the primary controller lives in the thread of the measurement. 4.3 Acquisition of LEED-I(V) data The `IVVideo` is the main measurement type of the ViPErLEED measurement package. All LEED-I(V) data required to determine the structure of a sample is collected through this measurement type. It is the only measurement type that necessarily requires a camera to function. When doing a `IVVideo`, the hardware will ramp up from a start energy to an end energy in multiple energy steps. The step height is the delta energy between data acquisition processes. At each step the measurement will acquire the requested numerical data and, more importantly, images of the LEED screen. This automatizes the entire data acquisition process and can be done significantly faster than if it were performed manually. `IVVideo` works with two different settling times. The _I_ 0 settle time ( `i0_-` `settle_time` ) is the time taken until any transients (e.g., oscillations) of _I_ 0 stemming from setting the beam energy can no longer be observed. The HV settle time ( `hv_settle_time` ) is the time until the beam energy has stabilized. During hardware testing in this thesis, the _I_ 0 settle time used to be longer than the HV settle time on all tested electronics. This is to be expected on all LEED optics. The electronic components of the hardware tend to act as capacitive load. While the beam energy will quickly respond to a change of voltage, the beam current will at the very least show the transient of a charging capacitor. The settle time can be significantly worsened if the optics are implemented with a bad feedback loop. Depending on the hardware, modifications may be beneficial to speed up the data acquisition. Suggestions for modifications of certain LEED electronics will be available at `[http://viperleed.org/](http://viperleed.org/)` . The `i0_settle_time` is used as the waiting time interval that has to run out before controllers take measurements after the energy has been set. Cameras are delayed by `hv_settle_time` milliseconds after the energy has been set. This can be done because the image data is primarily sensitive to the beam energy and relative intensity of the peaks and not to the overall intensity of the pattern. The relative timing of controllers and cameras can be seen in Figure 10. An `IVVideo` measurement is finished when the next 29 energy step would exceed the end energy. _Ebeam_ trigger cameras trigger controllers _t_ _t0_ _tHV_ _tI0_ HV settle time I0 settle time Figure 10: Visualization of an energy step in an IV video. The controllers and cameras are triggered separately from each other. The cameras wait for the beam energy to settle, while the controllers wait for the beam current to stabilize. Each measurement requires an end energy and a delta energy in the configuration files. The end energy should be chosen with care. A wider energy range adds more data to the available data pool. However, higher beam energies can sometimes degrade a sample very quickly. Due to the faster data acquisition with ViPErLEED compared to manual data acquisition, it is possible to go to slightly higher energy ranges on unstable samples. This is especially true if the settle times are short an the energy steps are short. It is recommended to perform an energy calibration and determine the settle times of the electronics to ensure quality data before taking LEED-I(V) measurements. The energy calibration taken from the most recent `MeasureEnergyCalibration` is automatically applied if available. More on settle times is elaborated on in Section 12. The `IVVideo` can be found in module `iv_video` . 4.4 Electron energy scale calibration To perform a high quality measurement, the beam energy that is actually set on the output of the LEED optics has to exactly match the nominal energy the primary controller is setting. However, in reality almost all LEED optics experience some kind of offset and energy shift as the beam energy rises to higher and higher values. This effect can be corrected for by performing a 30 measurement in which only the nominal and the output energies are compared. By describing this relation, a correction function can be determined that can be applied to the nominal energies to reduce the difference between desired and output energy. Performing an energy calibration only makes sense for a sensible energy range. If the starting energy is too low (typically < 5–10 eV), the starting offset will disproportionately affect the energy calibration. LEED optics tend to have non-linearities in these energy ranges. In regards to the LEED-I(V) measurement, there is very little information in these ranges. Therefore it does not make sense to calibrate for the lowest energies and, in doing so, reduce the quality of the calibration for the remaining energy range. On the other hand, it is extremely important to calibrate for energies high enough so that the calibration range includes all subsequent measurements. Note that during the energy calibration the electron beam does not need to be directed at the sample if the sample degrades quickly under it. The ViPErLEED measurement package is able to self-correct for inaccuracies of the beam energy. It can do this with the `MeasureEnergyCalibration` object, which is used to calibrate the primary controller for the LEED electronics. Its function is to set various energies and measure the actual electron beam energy. By comparing the nominal values set with those measured, a linear approximation of the relation of these two quantities is calculated. This approximation can then be used to set more accurate electron energies in subsequent measurements. This measurement does not need any cameras as it is not designed to acquire images while performing an energy calibration. If the settings contain cameras that are supposed to be used, they are simply discarded. The only thing needed for this measurement is a primary controller and any controller with the ability to measure the actual output energy. The energy calibration is performed as a single ramp with steps in between. If no end energy has been given in the settings, then the calibration will be performed for energies up to 1000 eV. To avoid damaging any samples, it is suggested to do this measurement without a sample in front of the electron gun. An alternative is to set a very negative Wehnelt voltage to repel emitted electrons. `MeasureEnergyCalibration` can be found in module `energy_calibration` . Aside from the default behaviour of all measurements (see Section 4.2.2) this measurement type also ensures that the collected data is sufficient to produce a meaningful energy calibration. To be exact, the measurement will enforce that at least one controller measures at least 10 different energies over an energy range no smaller than 10 eV. The old calibration is also temporarily saved in case the measurement gets aborted before it collects all necessary data to calculate the new calibration. 31 `start_next_measurement()` sets the beam energy after which a measurement is triggered. The energy calibration measurement is finished if the next energy step would result in a beam energy larger than the end energy. If it is, then the new energy calibration curve is calculated and the measurement proceeds to the finalization step. If it is not, then the delta energy is added to the current energy and the next step is initiated. Apart from the regular finalization of any measurement, a `MeasureEnergyCalibration` will determine a new energy calibration at the end of the measurement. It calculates a polynomial of first degree from a least-squares fit to the collected data. The _x_ -coordinates are the measured energies, and the _y_ -coordinates are the nominal energies, resulting in the equation _E_ nominal = _c_ 1 + _c_ 2 _E_ measured. This way the energy _E_ nominal that has to be set by the primary controller can be determined by putting the requested energy _E_ measured into the polynomial. The coefficients _c_ 1 and _c_ 2 are stored. Higher orders of polynomials can in principle be generated by changing the degree in the fit function, but past experience has shown that this is not required. The newly calculated energy calibration automatically replaces the previous calibration and is stored in the configuration files of the primary controllers. 4.5 Time-resolved data acquisition To observe the evolution of a measurement over time it is necessary to be able to collect time-resolved data. The core difference between an energy-resolved measurement and a time-resolved measurement is that the time-resolved measurement acquires multiple data points at the same energy. While the energy-resolved measurement collects one data point and moves on, the timeresolved measurement remains at that energy and keeps collecting data at a predetermined interval for a certain time. Time-resolved measurements are helpful when trying to determine how long the LEED optics need to relax after setting a new energy or when performing a long term measurement to observe the energy drift of the optics when they heat up during extended use. Another typical use case is the measurement of I(t) curves, for example during a phase transition induced by the electron beam or by temperature. The measurement package can perform these kinds of measurements with the `TimeResolved` measurement type. A time-resolved measurement can be performed in two manners. Either it is a continuous measurement, or it is non-continuous and therefore triggered. Continuous mode means the controllers constantly return data without interruption. The continuous, time-resolved measurement does not acquire any images and is commonly used to determine the settle times of the LEED electronics. The triggered, time-resolved measurement mode is intended to 32 take isolated measurements regularly over a very long time period. In this case the measurement triggers the controllers to perform measurements at regular intervals. In contrast to the continuous mode the triggered mode can acquire images. The time intervals of the triggered mode are slightly less equidistant than those of the continuous mode as the timing is not managed by the controllers but by the PC. (The irregularities can be up to a few milliseconds.) The triggered mode is therefore more suitable to measure a long-term drift rather than short-term oscillations. A `TimeResolved` measurement takes its measurement mode (continuous or triggered) from its settings. Furthermore, the settings must also contain the energy step duration. The energy step duration (given in milliseconds) decides how long a time-resolved measurement remains at a certain energy to acquire data. The signals of this class can be found under `TimeResolved` in the signal table. The measurement class `TimeResolved` can be found in module `time_resolved` . In continuous mode the measurement adjusts the preparation of the controllers such that they are able to acquire data continuously. After controllers are triggered in continuous mode, they will continue returning data on their own. At the beginning of each energy step, when the primary controller starts measuring, a timer for the step duration is started. This timer waits until the step duration has ended and initiates the next energy step. This timer is solely responsible for progressing from one energy step to the next. Figure 11 shows how a continuously measuring controller takes measurements while the energy is ramping up. To be exact, the figure visualizes how a secondary controller would acquire data. In continuous mode the controllers start measuring as quickly as possible after setting the beam energy, thereby ignoring any settle time that may have been set. Secondary controllers are triggered just once in the first energy step and keep measuring until the measurement is concluded. The time between measurements is dictated by the clock and settings of the hardware. This means the controller settings decide how much data is collected, not the measurement. Note that secondary controllers keep returning data while an energy step is happening. The primary controller needs to be interrupted at each energy step to set a new energy. The primary controller will continue measuring only after it has set the next LEED energy. The energy step duration timer is the same for triggered, time-resolved measurements as it is for continuous measurements. However, a second timer is necessary to trigger measurements. It takes the interval between measurements from the settings. This timer repeats itself until the energy step is over. It is important to note that, while Qt timers have millisecond precision, the defined interval is just the minimum time that will pass between 33 _E_ beam Measurement Energy step duration Step Beam energy _t_ Time between measurements Figure 11: Step timing for continuously measuring controllers measurements. The operating system of the PC may delay the actual execution of the measurement by a few milliseconds. This is accounted for when creating the time stamp of the measurement. The measurement just saves the time when the measurement has actually been acquired and not when it was supposed to happen. Figure 12 shows how data is acquired in a triggered time-resolved measurement. The first measurement of each step happens after the initial delay, or in other words the settle time and any additional time the step profile may take. Every subsequent measurement is triggered by the second timer and the time between these measurements is dictated by the measurement interval setting of the measurement. It is important to note that, unlike the continuous case, data acquisition is still delayed by the settle time after each energy step. The triggered measurement is interrupted at each energy step. _E_ beam Measurement Energy step duration Step Beam energy _t_ Time between measurements Initial delay Figure 12: Step timing for triggered controllers 34 Another option that is introduced for this measurement type is to make the measurement endless. This means that the measurement does not end unless aborted, restarting at the first energy whenever it is done with the last one. The measurement can also be forced to remain at a constant energy. If the measurement is set to constant energy, then the measurement will never continue on from the starting energy and will always remain there. In this case the measurement must be stopped by aborting it. If the measurement is finished or aborted, the controllers are stopped and continuous mode is turned off. The measurement will wait until both of those tasks are completed on all controllers. After all controllers have returned to an idle state, the measurement is finalized. For continuous, timeresolved measurements the times for each controller at which measurements were taken are calculated from the amount of data that has been returned and the settings file of the controller, assuming that controllers are precise enough to do this. Triggered time-resolved measurements do not face this issue since, as previously mentioned, a time stamp is created whenever a measurement is taken. Aborting a time-resolved measurement will cancel the measurement immediately. This may result in energy steps that are cut off. 35 #### 5 Controller A controller is the hardware necessary to operate the LEED optics and collect numerical measurements. Controllers may be microcontrollers that manage electronics which collect data about the beam energy, beam current, or any other physical quantity impacting a LEED-I(V) measurement. However, controllers can also be integrated into the LEED control units themselves. For instance, a LEED unit that can directly communicate with the PC and receive orders to set the beam energy and perhaps even return data is as well a controller. Controllers can be split into two categories. The primary controller is the main controller of a measurement. It is responsible to set the beam energy and without it a measurement cannot be performed. The primary controller is however not required to be able to collect measurement data. Secondary controllers do not set the beam energy. They are only operated to collect additional data and not strictly required to be able to measure LEED-I(V) data. They may however be necessary, for instance, if one wants to measure the beam current when the primary controller is not able to perform this measurement. Then secondary controllers can be added to the hardware managed by the measurement to fill this gap. The controller object is responsible for knowing and communicating tasks to the hardware given to it by, e.g., the measurement. Controllers have a serial port object that is unique to them in order to be able to communicate with the associated hardware. Note that there are two layers of abstraction here. The controller object represents the hardware on the code side and knows what the hardware has to do in order to achieve a certain goal. In other words, it manages the tasks the hardware has to go through. The serial object more or less acts as a translator. It receives the orders from the controller object, translates them to something the hardware will understand and then communicates these tasks to the hardware. This also works in the other direction, when the hardware returns data back to the PC. The incoming data is first received and translated by the serial object and only after that it is actually forwarded to the controller object. Controllers know which preparations they have to go through to collect quality data. Preparations may include tasks such as calibrating the electronics, or finding the optimal gain for a measurement. There are two base classes of controllers. The `ControllerABC` which is a controller that cannot measure but knows how to prepare itself and how to set energies. The other class is the `MeasureControllerABC` which inherits its capabilities from `ControllerABC` . In contrast to its parent class it is also able to take measurements. Secondary controllers, whose task it is to take 36 measurements, must be subclasses of `MeasureControllerABC` . The primary controller is responsible for setting the beam energy and can therefore be a subclass of either of the base classes. 5.1 Base controllers `ControllerABC` is the base class of all controllers. Its single use is to be the primary controller which sets the beam energy on the LEED electronics. This controller already contains all of the necessary signals for interaction with a measurement and all of the structure necessary to communicate with its serial port. The serial port lives in the same thread as the controller. The `ControllerABC` is however incapable of processing measurement data. The errors of the `ControllerABC` class are found in `ControllerErrors` . The serial port is elaborated on in Section 6. The signals of this controller can be found under `ControllerABC` in the signal table. The `ControllerABC` is located in the `abc` module in the `controller` package. Unlike the `ControllerABC`, the `MeasureControllerABC` is able to acquire measurements. `MeasureControllerABC` is a subclass of `ControllerABC` and the base class of measuring controllers. It is located in the `abc` module in the `controller` package. 5.1.1 Controller settings The `ControllerABC` creates its `ViPErLEEDSettings` and learns if it is a primary controller during its initialization. The settings are stored in humanreadable text files. Each controller has its own configuration file. If the controller does not have a settings file yet, a default settings file for this controller class is used if available. The settings of a primary controller must contain additional settings relevant for the measurement. These are the measurement settings `first_settle_time`, `hv_settle_time`, `i0_settle_time` and the energy calibration. They are present in the settings of the primary controller because they are a product of the interaction between the LEED optics and the primary controller. The `first_settle_time` is used only once when the beam energy is set for the first time during the preparation of a measurement. This first settle time exists because the first energy step of a measurement may be significantly larger than any other steps and thus a longer time may be required for the electronics to relax. `hv_settle_time` is the time it takes until the beam energy has relaxed and `i0_settle_time` is the time until the beam current has relaxed, respectively. These times can be determined with a `TimeResolved` measurement as described in Section 4.5. Settle times can 37 further be reduced with optimized step profiles when going from one beam energy to another. Step profiles are explained in Section 12. The energy calibration is stored as a polynomial and is used to convert the desired beam energy to a nominal energy that has to be set. This corrects for offset and gain errors that are typical for LEED electronics. A suitable energy calibration can be obtained automatically by performing a `MeasureEnergyCalibration` measurement. The energy calibration is elaborated on in Section 4.4. For primary controllers that have never been calibrated before, these times and the energy calibration will be unusable, but they must be present in the settings regardless. This does not present an issue as long as the first thing that is measured is an energy calibration. The second measurement after that should be a continuous, time-resolved measurement to determine the settle times. Once the settings of the primary controller have been updated to fit the connected hardware, then LEED-I(V) measurements can be performed. The `name` of a controller needs to be a unique string that identifies each controller. For instance, a serial number is a good candidate for a controller name if the hardware can respond with its serial number. The settings of a `MeasureControllerABC` must include `nr_samples`, the number of measurements to average over per triggered measurement. The exact implementation of the measurement acquisition process is a matter of subclasses. If possible, the averaging should be done at the firmware level. 5.1.2 Preparatory measures The preparation to perform tasks is unique to each controller. The preparation is however always split into two separate steps. The first step happens before or while the first beam energy is set. The tasks contained in it must be independent of the beam energy set on the optics. The primary controller features one extra task at the end of its first preparation step, which is setting the beam energy to the desired initial value. During the second preparation step all tasks that require a defined beam energy can be performed. When the first preparation step of a controller is initiated, the controller is sent into a loop in which it completes the first preparation tasks step by step on its own. The completion of the tasks is overseen by the controller itself and does not require an external handler to tell the controller to perform the next task. One task at a time is sent to the hardware. When the task has been completed by the hardware, the next task is sent. When the first batch of tasks has been completed, the controller returns to an idle state. The start of the second preparation step will as well lead to the same 38 loop, just with different tasks being executed. If the measurement type is a continuous measurement, then the measurement will order all measuring controllers to set themselves to continuous mode as the last task of their second preparation step. Continuous mode means that the controller will, once it is ordered to measure, continuously measure and return data to the PC without interruption. Once both preparation steps have been completed, the controller is ready to be used in a measurement. The preparation of controllers is critical to collect quality data and must not be interrupted. If a controller is not properly prepared for a measurement, measured data can experience a significant offset, or the controller may not even be able to measure at all. If the preparation fails, the measurement is aborted before any data has been collected. 5.1.3 Setting energies Setting the energy is always performed by the primary controller. The primary controller has to use the method `true_energy_to_setpoint()` to apply the energy calibration onto the desired output energy. This method calculates the nominal energy necessary to achieve the desired beam energy using the `energy_calibration_curve` measured with `MeasureEnergyCalibration` . There are two options for how an energy can be set. Either it is just an operation that sets the energy or it is an operation that also starts data acquisition on all devices after a predefined time interval. Usually this time interval is one of the settle times, but the time can also be zero which will trigger devices immediately to measure. All currently implemented measurement types utilize the latter option. This is because the measurement package aims to minimize the time it takes to perform a full measurement, so down time between acquisition of data points is kept to the required minimum. The primary controller is expected to start measuring on its own if it is supposed to measure after setting the energy. For the primary controller, an optimization of measurement quality can be achieved if it is also able to acquire measurements. If a measurement is supposed to happen after the energy has been set and if the firmware can initiate a measurement on its own, this capability should be used. Having the firmware trigger the measurement is recommended because if the timing is done on the hardware side, then the inaccuracies of the operating system timing of the PC do not influence the quality of the measurement data. A high timing accuracy is especially useful if the LEED optics experiences strong transients after setting a new energy. This is because exact timing significantly improves reproducibility of measurements in this case. If the firmware of the controller is able to set the energy, and able to take measure 39 ments, but not able to trigger itself, then the primary controller must wait for the settling time to elapse and then trigger a measurement separately. For secondary controllers, which only acquire data but never set the energy, none of this is relevant because they are triggered by the measurement after the primary controller has set the beam energy. The timing of secondary controllers is always dependent on the operating system of the PC and therefore less accurate than that of a primary controller that can trigger itself via its firmware. `set_energy()`, the method used to set the beam energy, is specific to the controller. This method is required to emit the `about_to_trigger` signal, if a measurement should be taken, after setting the energy. This is also true for non-measuring primary controllers. Essentially the primary controllers are responsible for synchronizing all other controllers. If no measurement is required, then `about_to_trigger` is not emitted. 5.1.4 Taking measurements The `ControllerABC` is unable to take measurements. Attempting to force a set of `measured_quantities` onto the `ControllerABC` will lead to an error. All controllers that can take measurements must be subclasses of `MeasureControllerABC` . The `MeasureControllerABC` can take measurements. The `measured_-` `quantities` which can be selected are `QuantityInfo` objects which contain additional data about the measured quantity. They are necessary to let the controller class decide which hardware channels must be measured. Taking measurements can be achieved through two methods. If the controller is a primary controller and an energy has been set with `set_energy()`, a measurement can be automatically triggered. When the measurement is automatically triggered, the primary controller will emit the `about_to_-` `trigger` signal. This signal should be used to trigger all other connected devices to collect data. The second method that can trigger a measurement is `measure_now()` . `measure_now()` is a straight call for an immediate measurement and will ignore any delays and settle times. Note that if the measurement on the primary controller is initiated with the `measure_now()` method, the `about_to_trigger` signal is not emitted by the primary controller and therefore other devices are not automatically triggered. In the current implementation of the measurement types, the primary controller is triggered to emit this signal by the measurement object. 40 5.1.5 Data acquisition The times `initial_delay`, `measurement_interval`, and `time_to_first_-` `measurement` and the number of measurements to average over, `nr_samples`, characterize the data acquisition process of controllers. `initial_delay` is the time between when a measurement was triggered and when the controller actually starts measuring. `measurement_interval` is the time between two data acquisitions by the hardware. `time_to_first_measurement` is the sum of `initial_delay` and however many `measurement_interval` have passed between single measurements that were averaged over. These times are needed to correctly calculate time-resolved data. The time axis of data acquisition for a measuring controller can be seen in Figure 13. single measurement by controller initial_delay measurement_interval _t_ = 0 _t_ time_to_first_measurement controller triggered _E_ beam last data acquisition Measurement _t_ Figure 13: Data acquisition as performed by a controller. For each measurement that is triggered on the controller, the controller will perform as many data acquisitions as set by `nr_samples` and then average over them. 41 5.1.6 Receiving measurements The controller receives data from its serial object. If the received data is measurement data, it is stored temporarily with the other `measurements` and converted to physical units if not done yet. Other data such as the hardware configuration may also be handled depending on the type of controller. The processed measurement data is emitted with a time stamp via the `data_-` `ready` signal. 5.1.7 Accessing controller settings The settings of controllers can be viewed in the measurement GUI. Controller settings can only be edited when no measurement is running. Each controller is selected in the GUI, it will display a `SettingsDialog`, with its controller-specific `SettingsHandler` . This handler contains the settings that this type of controller has. If the controller returning the handler is the primary controller, it will additionally return its settling times. If the settings of a controller are edited in its `SettingsDialog` and applied, they are also saved in the configuration files. For measuring controllers the returned settings include `nr_samples`, which can be edited in the `SettingsDialog` as well. 5.1.8 Controller operation supervision A very important property of the controller object is `busy` . It is true if the controller or the serial of the controller is busy. Whenever the busy state of a controller changes a `controller_busy` signal is emitted carrying the current busy state of the controller. This is important because much of how a measurement functions is dependent on this signal. The measurement relies on the `controller_busy` signal to trigger the next step in many situations. The `busy` property is often used to check if all connected devices have completed their tasks. If the controller is sent a task to perform while it is busy, it will store this task and wait for the serial to signal that the firmware is done processing the last command. Whenever the serial is no longer busy, the controller will attempt to send the next unsent task in chronological order. Note that this may lead to a build-up of tasks which the controller has to send before any of the newly arriving tasks can be processed. 5.2 `ViPErinoController` The `ViPErinoController` is the controller object built to handle the hardware setup described in the project work “Vienna Package for TensErLEED: 42 Hardware setup”. This hardware setup is a controller based on the Arduino Micro microcontroller, capable of acquiring measurement data and setting the beam energy on externally programmable LEED optics. Two analog-todigital converters (ADCs) allow it to measure two channels each. Each of those channels is configured for one specific physical quantity that is measured with it. Both ADCs can only measure one channel at a time. A digital-to-analog converter (DAC) provides the controller with the ability to set beam energies. Furthermore, the controller also features a temperature sensor that takes the room temperature. Schematics for the hardware and the source code of the firmware can be obtained at `[http://viperleed.org/](http://viperleed.org/)` . An assembled setup can be seen in Figure 14. Figure 14: A controller assembled according to the specifics of the ViPErLEED hardware setup. The two BNC plugs on the top right are for the beam (LEED) current and sample current respectively. The BNC plug below is the output of the DAC. In the bottom left the input for the beam energy can be seen. The controller can be used both as primary and as secondary controller and can measure the beam current, beam energy, sample current and the temperature of a thermocouple. Additionally, there is one temperature sensor used to provide a reference temperature for a thermocouple. If used as a primary controller, it can trigger a measurement after setting a new beam energy on the firmware level which allows it to perform measurements with very accurate timing. It can also perform averaging of measurements on the 43 firmware. The `ViPErinoController` is capable to use all of the features programmed for the hardware setup, and it is recommended to be used in tandem with it. The errors of the `ViPErinoController` class are found in `ViPErinoErrors` . `ViPErinoController` is a subclass of `MeasureControllerABC` and can be found in the `viperinocontroller` module. 5.2.1 Controller settings Figure 15: Settings dialog of a `ViPErinoController` . The settings of the controller can be edited in this window and then saved to the configuration files of the controller. The number of measurements to average over and the serial number of the controller can be set via the `SettingsDialog` . The energy calibration curve in the controller settings is automatically overwritten as soon as an energy calibration has been performed with this `ViPErinoController` . However, currently the controller settings require the user to edit a few settings manually in the configuration text files. These settings are the settling times `first_settle_time`, `hv_settle_time`, and `i0_settle_time` and the ADC update rate. The three settling times have to be determined with timeresolved data-acquisition methods. They are only used in a measurement if 44 the controller is the primary controller. The ADC update is the frequency at which the controller performs single data acquisition events (i.e., it is the inverse of "Time between measurements" in Figure 11). There is a large amount of mandatory commands and settings present in the settings file that should never be edited. These commands and settings are necessary to communicate with and operate the hardware. All settings that can be edited by the user are found under the `[measurement_settings]` section in the configuration file. This controller type will be displayed under the controller section in the devices tab of the GUI. For each found `ViPErinoController` an attempt will be initiated to get its hardware configuration. If the controller responds with a serial number, it is added to the device list. The `SettingsHandler` of this controller object displays its hardware configuration, firmware version, and serial number as seen in Figure 15. The serial number can be set from the dialog window. It can either be entered manually or generated randomly. The serial number can only consist of capital letters and numbers. 5.2.2 Preparation During the first preparation step the `ViPErinoController` performs either 3 tasks if it is a secondary controller, or 4 tasks if it is a primary controller. The first task is determining the hardware configuration. During this task the hardware will test which parts of the setup are installed and ready to be operated. The quantities that can be measured with the detected hardware are then compared to the quantities the controller object wants to measure. If they do not match, this is reported as an error to the user. Furthermore, the hardware will also return its firmware version. This firmware version must be earlier or equal to the `ViPErinoController` version installed on the PC. The second task is calibrating the ADCs. This is done internally on the hardware with a reference voltage that is created by the setup. The ADCs need to be calibrated to fix any offset of measured values. Calibration data is collected for the selected ADC channels and automatically applied without further intervention by the user. For secondary controllers the last task is setting up the ADCs. This means, in particular, selecting the ADC channels that should be measured and setting the number of measurements the controller is supposed to average over. If the `ViPErinoController` is the primary controller, it will set the first beam energy as its last task. At this point the controller will not start a measurement or trigger any other devices to start measuring yet. 45 In the following preparation step the hardware will determine the optimal gain to set on the ADCs for the selected starting energy. The gain of an ADC is the amplification it applies to the input channels. A high gain means high amplification. The gain is adjusted for each measurement because the highest possible gain allows the ADC to acquire data with the highest possible accuracy with the limited resolution it has. Whenever an ADC would saturate during a measurement, its gain is decreased, which decreases resolution, but increases the range the ADC can measure. If the measurement class is non-continuous, then the preparation ends here. In a time-resolved, continuous measurement the controller will set itself to continuous mode at the end of the second preparation step. In continuous mode the controller will send an uninterrupted stream of measurement data back to the PC as soon as it is triggered to measure. Section 4.5 elaborates more on the continuous mode of measurements. 5.2.3 Setting energies The `ViPErinoController` is capable of setting beam energies on externally programmable LEED electronics with its integrated DAC. Furthermore, the controller is capable of setting energies via complex step profiles by processing lists of energies and times which act as intermediate steps. Step profiles are explained in Section 12. The controller will set each energy in the list it receives and wait for the associated time period. All timing is done on the firmware side and therefore highly accurate. The nominal energy to set on the DAC is calculated automatically from the desired beam energy. This is done for each energy if the received step profile consists of multiple steps. The `about_to_trigger` signal is emitted after the beam energy has been set. 5.2.4 Taking measurements As previously mentioned, this controller can trigger itself to measure after setting a beam energy. It does however also have a command to measure without setting an energy. 5.2.5 Receiving measurements Data is received from the serial by the controller. The controller object sorts the received data by quantity. Whenever a full set of data is acquired, it is emitted with a time stamp with the `data_ready` signal. If this controller type is handled by a ViPErLEED measurement, then its acquired data will be stored in the `.csv` file of the measurement. There, the measurement data will be sorted by energy or time. Each measured quantity has its own column 46 and the serial number of the controller that acquired this data is written next to the quantity. 5.2.6 Important properties This controller type is able to handle a `thermocouple` and calculate a temperature from the measured voltage. The implemented types are B, E, J, K, N, R, S and T thermocouples. The integrated temperature sensor of the controller is used to get the room temperature as a reference for the thermocouple. 5.3 Controller interaction visualization Figure 16 presents a simplified visualization of how the controller object interacts with other ViPErLEED objects and how tasks are triggered within it by other objects. The figure shows the multilayered structure of the ViPErLEED measurement package. Tasks, that are given to the controller by a measurement or the GUI, are processed by the controller and reach the hardware through the serial object. The figure also shows which signals are used by the controller to communicate information back to other objects. A more detailed visualization of what the serial object does can be seen in the serial interchange. 47 __preparation_started __preparation_continued primary.set_energy() primary.about_to_trigger class Measurement primary.measure_now() GUI prepare_to_show_settings() primary.set_energy() about_to_trigger controller_busy data_ready controller_busy data_ready ready_to_show_settings class Controller Preparation Take Measurement Set Energy Get Settings request class Serial request hardware response response Figure 16: Visualization of the most common interactions the controller object has with other objects. The red arrows pointing downwards are commands and request and the black arrows pointing upwards are responses and acknowledgements. The boxes in the controller symbolize core tasks of the controller that get triggered by outside actors. #### 6 Serial The serial takes the role of translator between controller object and hardware and manages the serial port on which the hardware is connected. It is responsible for sending and receiving messages to/from the hardware. A serial can encode and decode messages and should be able to preprocess messages to a point at which they can be understood by the ViPErLEED software. The serial handles communication with the hardware via, e.g., the USB port of the PC. Different hardware needs different serials that are configured for the specifics of that controller type. Therefore serials are highly specialized and each controller type needs its own specific serial type. Like with controllers, serials in the ViPErLEED measurement package feature a premade base class that handles all of the conceptual tasks and contains the required structure to function with the package. This object, that all other serials should be based on, is the `SerialABC` . Each controller features its own serial object that lives in the same thread as the controller object. The serial takes care of putting outgoing messages into a form compatible with the associated hardware. It decides which of the incoming messages are worthwhile to be forwarded to the controller object. It takes care of encoding outgoing messages, decoding incoming messages, and setting up the port to communicate with the hardware. 6.1 `SerialABC` `SerialABC` is the base class of serials. It features all of the necessary signals for communication. The structure to send and receive messages has already been implemented, but subclasses must add the specifics necessary for their hardware. The errors of the `SerialABC` class are found in `ExtraSerialErrors` . Additional errors for the `QSerialPort` class are found in the `QSerialPort` errors. The signals of this class can be found under `SerialABC` in the signal table. The `SerialABC` is located in the `abc` module in the `serial` package. 6.1.1 Serial settings To be able to encode and decode message, a serial needs to know how a message is encoded. This information is usually hardcoded into the serial object itself. In other words, this is part of the specific serial type. However, the settings files of a serial does contain additional information. For instance, each serial needs to have information on its endianness. Endianness describes the byte order of messages and it can only be big or little. Big-endian means 49 the most significant byte of a message is comes first, while little-endian means the least significant byte comes first. The configuration files must also contain an end marker. The end marker is one or more bytes that are placed at the end of every message between hardware and the PC. There can also be a start marker, which is placed at the start of messages. This start marker is however not mandatory. The serial uses a `QSerialPort` for communication with the hardware. The settings read from the serial settings are applied to the `QSerialPort` . 6.1.2 Port management The base serial object can connect to a port, load port settings from a settings file, receive and send messages, detect port errors, and disconnect. The errors of `QSerialPort` are caught and reported in the same manner as errors of ViPErLEED classes. For instance, if the port is disconnected during operation, an error message will pop up notifying the user that the device has been disconnected. 6.1.3 Sending messages Outgoing messages are first checked if they are supported, then prepared for encoding and then actually encoded. The start marker (if available) and end marker are added to the encoded message. Afterwards, the message is written on the port. The serial will remain busy until receiving an answer if one is expected. This will halt sending of any further messages. Unsent messages are queued and sent one at a time in chronological order as soon as the serial is idle again. If there is a timeout time given in the settings, the serial class will time out and emit an error if no response is received from the hardware within this time. Sending a message to the hardware is done with the `send_message()` method. 6.1.4 Receiving messages The serial class can handle partial messages and will remember unfinished messages to assemble them when the remaining part arrives. Messages are then preprocessed and decoded. The implementation of decoding is a matter of subclasses. The decoded message is processed according to the specifics of the serial type. Processing is therefore something that is special to each serial and not something that can be generalized. Worthwhile data is emitted with the `data_received` signal. If the incoming message is an error message, then the error will be identified. Identified errors are emitted and reported to the user. 50 6.2 `ViPErLEEDSerial` The `ViPErLEEDSerial` is an example of a serial that works with the hardware developed for the `ViPErinoController` . This serial can communicate with the associated hardware and detect errors that may happen on the hardware side. This means this serial is not only able to decode and encode messages, but it also understands error types that are reported to the user. The errors of the `ViPErLEEDSerial` class are found in `ViPErLEEDHardwareErrors` . These errors include many of the errors the hardware itself will return if it detects any faults. The signals of this class can be found under `ViPErLEEDSerial` in the signal table. The `ViPErLEEDSerial` can be found in module `viperleedserial` . 6.2.1 Sending messages message MSG_START message content MSG_END length 1 byte 1 byte _x_ bytes 1 byte Figure 17: Message structure between the hardware and the `ViPErLEEDSerial` . The message content is wrapped by the start, message length and end bytes. When this serial sends a message to the hardware, it always first sends a message containing a command. This command message lets the hardware know which task it has to perform. Then, if the task requires additional information to be performed, a data message can follow. Every message between the hardware and the `ViPErLEEDSerial` is encoded and wrapped by additional overhead bytes. These additional message bytes are a start and end marker at the beginning and end of the message, respectively. After the start marker and before the encoded message is a byte that contains the length of the unencoded message (i.e., the number of payload bytes). This message structure can be seen in Figure 17. The byte values for the start and end marker are loaded from the controller settings. Exactly one command is sent per message, if the message is a command message. Only one data message per command that needs extra data is sent. This means the serial first sends a message to the hardware that contains a single command. Then, if the command requires additional data, a second 51 message containing the necessary data is sent. It is important to note here that command messages are always only 1 byte long, while data messages are at least 2 bytes long before encoding and without non-data markers. The message length before encoding is always sent with the data message. This is done because the amount of data bytes the hardware is expecting for a certain command is fixed and the message length can therefore be used as a safety measure to determine if a suitable data message has arrived. Encoding is performed in the following manner. Message bytes whose numerical value is larger than a special byte value are split into two bytes. The first of these bytes is equal in value to the special byte. The second byte is the difference between the original byte value and the special byte. In other words, bytes larger than the special byte are split into two bytes. The value of the special byte is defined in the controller settings. Encoding is performed to ensure that bytes like the start marker, that are larger than the special byte, are never confused with regular message bytes. This is important because otherwise a regular message byte could be mistaken with a start marker which would make the message look like it has been corrupted. After sending any command to the hardware the serial will always be busy. When the hardware is done processing the received command it responds with an acknowledgement. This does not necessarily mean the task has been finished, only that a new task can be received. Tasks such as taking measurements may take longer and the acknowledgement is only there to let the PC know the hardware has started acquiring measurements and is ready to process new requests. 6.2.2 Receiving messages All incoming messages are decoded by the serial. Decoding is done by adding each byte with the value of the special byte to the following byte in the message, restoring the original length of the message. The length of the decoded message must be equal to the message length sent with the message, otherwise the message has been corrupted. This message length must also be among the message lengths the hardware can respond with in general. If non-error data has arrived, then it is processed according to the last command that was sent. Since the serial remains busy after sending any command, every command requires an acknowledgement by the hardware. This acknowledgement lets serial know it can send new commands to the hardware. This does not necessarily mean the hardware is finished with its entire task, such as when it is measuring continuously, just that it is ready to process a new command. Incoming measurement data is converted to float. The measurements are 52 emitted with the `data_received` signal once measurements from all active devices installed on the hardware have arrived. Incoming hardware information is decoded and also emitted with the `data_received` signal. Note that the installed `ViPErLEEDSerial` version on the PC must at least be equal or newer than the firmware version installed on the hardware. (The installed software on the PC must be equal or newer because backwards compatibility is maintained for older software that may be running on the hardware.) If either the firmware versions do not match or the hardware configuration seems faulty, this is reported as an error to the user. Any other message that is not a debug message and that does not fit the expected lengths will lead to an error. If the last command was a `PC_SET_VOLTAGE`, the command to set the beam energy and measure, then the `about_to_trigger` signal is emitted as soon as the PC receives the acknowledgement from the hardware that the energy has been set. This is done because if the controller is setting the energy, it must be the primary controller and other devices in the measurement must be notified that measurement data can be acquired. (Section 5.1.3 elaborates more on the `about_to_trigger` signal and its use when setting the beam energy and acquiring measurements afterwards.) Error messages from the hardware always arrive in two packages, first an error message, that tells the serial the next message will contain error data, then the actual error message containing information about the error. From the error message, `ViPErLEEDSerial` will determine the error and the state the finite-state machine was in when the error occurred. It will then assign the error to one of the errors stored in `ViPErLEEDHardwareError` and report it to the user. 53 6.3 Serial interaction visualization Figure 18 presents a simplified visualization of what the serial object does and how communication is achieved between the controller object and the hardware. It also shows which signals the serial uses to communicate information back to the controller object. A more detailed visualization of what the controller does can be seen in the controller interchange. class Controller send_message() data_received error_occurred class Serial Encode and Send Decode and Process Identify Error encoded request encoded data encoded error hardware Figure 18: Visualization of the most common interactions the serial object has with the controller object. The red arrows pointing downwards are outgoing messages and the black arrows pointing upwards are received data or error messages. The boxes in the serial symbolize the main tasks of the serial when it is managing the communication between the controller object and the hardware. #### 7 Camera Cameras are, like controllers, necessary to perform a LEED-I(V) measurement. The structural information about the measured sample is hidden in the diffraction pattern observed on the fluorescent screen of the LEED optics. The camera records this information for different beam energies during a LEED-I(V) measurement and returns it to the PC. Every LEED-I(V) measurement requires at least one camera to be in operation to be able to collect images of the diffraction pattern. Similar to how controllers are implemented, the camera hardware has a code equivalent existing on the PC side that manages the tasks of the camera. This camera object is managing the hardware and issuing tasks to it. The camera object can be given tasks by other objects such as a measurement. The camera object knows what the hardware has to do to achieve a certain outcome. The camera object is specific to the hardware, which means that each hardware type needs its own camera object type. Between the camera object and the hardware is another layer of abstraction. This layer is the driver. The driver acts as the translator between the camera object and the hardware, making sure that issued commands are received and understood. Drivers are specific to the camera object and hardware: each camera type needs its own driver implementation. The camera object needs to be able to prepare its associated camera to take quality images. Certain image processing tasks (e.g., binning) that are usually done by cameras at the hardware level can be performed in software by the camera object. 7.1 `CameraABC` `CameraABC` is the abstract base class of all camera classes. It contains all signals, properties, and abstract methods for functions a camera needs to perform. Each camera object has its own driver which it uses for all communication with the hardware. The errors of the `CameraABC` class are found in `CameraErrors` . The signals of this class can be found under `CameraABC` in the signal table. The `CameraABC` is located in the `abc` module in the `camera` package. The driver of a camera functions much like the serial of the controller, however there is no ABC class handling the overall structure for it. Like controllers, cameras use `ViPErLEEDSettings` objects to handle their settings. The settings read from the configuration files of the camera are directly uploaded to the hardware. The camera is `busy` while uploading the settings. The settings of cameras can be viewed in the measurement GUI. Selecting 55 Figure 19: `SettingsDialog` of a camera. It can be accessed by right-clicking in the `CameraViewer` and pressing “Properties”. Editing settings in here and applying them will automatically upload them to the hardware. a camera will open it with a live `CameraViewer` . Right-clicking the image will bring up a menu under which the option “Properties” will bring up the `SettingsDialog` of the camera class. Such a dialog can be seen in Figure 19. The camera settings can be edited in the displayed settings handler and are uploaded to the firmware once applied. The exposure time, gain, frames to average over in triggered mode, ROI, and binning can be set from this handler. The path where bad pixel maps are stored can be viewed too. The ROI is the region of interest. It is the sensor area of the camera the user is interested to collect data with. If the hardware does not support this setting, the collected frames can be cut afterwards. (Because camera sensors tend to be rectangular and LEED screens are usually round, so only a square section of the image is needed.) The act of binning is reducing multiple pixels of an image into one. It is a form of averaging that decreases image size and reduces noise. Bad pixels are pixels that either give too much, too little, or too noisy signal and that cannot be used in a measurement. The camera object can take a map of these bad pixels and filter them out automatically by replacing them with average values of the surrounding pixels. The bad pixel finder in the GUI of the measurement package can generate maps for bad pixels (see Section 3.1.3). The path where bad pixel maps are stored can be set via this tool as well. 56 A core difference between cameras and controllers is that cameras perform their preparation in a single step. Once their preparation has been initiated, they are busy until the full preparation has been completed. During a measurement, frames are collected in triggered mode. This will start an event loop that will take the required number of frames with the set exposure time, binning, and ROI and average over them. Certain parts of this process may be executed by the camera firmware and other parts may be done at the software level on the PC side. Either way, one frame will be the end product. In order to execute this method the connected camera must be in triggered mode, otherwise an error will be raised. While the camera is acquiring frames the camera remains `busy` . Only when all frames have been recorded, the camera returns to idle. Received frames are sent to a specialized image processor. This image processor takes multiple frames and processes them according to the settings. The processor is moved to its own thread and handed all the incoming frames for a single measurement step. Processing of frames is done in different threads as to not slow down the camera object during a measurement. After handing the first frame to the processor the camera will repeat acquisition of new data until the desired amount of frames has been recorded. If the camera cannot perform the tasks of applying the ROI, averaging over frames, and binning, then they are performed by the processor. Bad pixels are removed according to the bad pixels file. Since processing is done in a different thread, the camera may start acquiring a new batch of frames even before the previous batch of frames has been completely processed. After processing is done, the `CameraViewer` will display the new image to the user. Images are saved in a folder named after the camera, are numbered in chronological acquisition order, and contain the beam energy they were taken at in the name. Frames can also be collected outside of a measurement in the `CamerViewer` . This is done by “snapping” an image. This takes the latest image displayed by the viewer and saves it. 57 #### 8 Data Points Collected measurements are stored in “data points” in the `DataPoints` class. It sorts data into a structure ready to be plotted or saved and can pull up saved measurements to replot them. The `DataPoints` object sorts and stores all data collected during measurements. Besides storing time stamps and measurements, it also saves the names of images for each energy step. It can also calculate times for measurements so that all measurements can be plotted in a time-resolved manner. The errors of the `DataPoints` class are found in `DataErrors` . The signals of this class can be found under `DataPoints` in the signal table. The `DataPoints` class can be found in the `datapoints` module. Processed data is saved in a `measurement.csv` file after a measurement is finished or aborted. This file contains all measured numerical data, sorted in chronological order, starting with the first measurement that has been acquired. With the numerical data the image file names are stored. The numerical measurements are sorted by quantities and devices, which means that each column contains measurements of exactly one quantity from a single device. The head row displays which quantity measured by which devices is stored in each column. Image names also get their own column for each camera. Another column shows at which nominal energy the measurements or images were acquired. The time at which a device has acquired a measurement is stored in an additional column. To summarize, a row will contain numerical data collected by controllers, image names of images taken by cameras, the nominal energy set on the LEED optics and the times when the measurement was performed. Data can be extracted from a `DataPoints` object during a live measurement to analyze it, as is implemented with the `MeasurementPlot` . 58 #### 9 Plot The plot displays measurements in real time while the measurement is happening. It can however also be used to plot data loaded from a saved measurement. Figure 20 shows the plot in action, plotting a current measurement. The `MeasurementPlot` widget is responsible for plotting the collected measurement data. The quantities that need to be potted can be selected in a drop down menu. This menu will allow the user to select multiple quantities to be plotted under the condition that they are of the same unit. A legend is placed in the top-left corner. This legend displays different controllers in different colors and different quantities with different symbols. The plot can display both time-resolved and energy-resolved data. It is capable to switch the plotted quantities during a running measurement. The `MeasurementPlot` can be found in the `measurement_plot` module. Figure 20: Screenshot of a measurement plot. In the top is the menu that lets the user select the quantities that are plotted. In the top-left corner of the graph the legend of the currently displayed quantities can be seen. 59 #### 10 Settings Settings for objects of the ViPErLEED measurement package have to be given as `.ini` files. This kind of settings file is a plain text file that is human-readable. In such a file there are so called key–value pairs organized into sections. The keys act as identifiers such that the correct value can be loaded from the file. The ViPErLEED measurement package loads these settings files into `ViPErLEEDSettings`, which can perform operations on the settings that have been loaded. All devices used during a measurement require a settings file. In this specific settings file the properties of that device are stored. Reading from a settings file will result in an attempt to read settings from the provided path. If this fails, the object searching for the settings will attempt to get settings from the default settings files if any have been provided. Usually all devices should have a default settings file provided for them, from which a unique settings file for a single device can be generated. For instance, in the current implementation a default settings file exists for the `ViPErinoController` . This file is used to generate settings files for any number of controllers of this type. If searching for a default settings file fails as well, the operation will raise an error. `ViPErLEEDSettings` can detect if required settings are present in a file. This is used in the measurement package to check the validity of settings before a measurement is started. After settings have been edited in the GUI they can be saved in the `.ini` file they have been loaded from. They can however also be directly edited in the `.ini` files as they are human-readable. Going through the tools provided in the GUI is however preferable. The errors of the `ViPErLEEDSettings` class are found in the `ViPErLEEDSettings` errors. The `ViPErLEEDSettings` class can be found in module `settings` . 60 #### 11 ViPErLEED Errors Errors may occur during the operation of the measurement package. Many of the errors that can happen have been accounted for and a structure has been put in place that reports these errors visually. Errors are reported when they occur and forwarded to the user via a window with descriptive text on it. Upon receiving such an error, the user may act upon it to restore functionality if possible. Each error has an error code and a descriptive text that elaborates on the fault. The descriptive text can often take strings from the code to enable more precise reporting on the error that occurred. Figure 21 shows how an error report may look like. The error report displays the error code and the description. Errors are emitted with the sender’s `error_occurred` signal. The objects responsible for holding error types and codes are all subclasses of `ViPErLEEDErrorEnum` . The error base class `ViPErLEEDErrorEnum` can be found in the `hardwarebase` module. Figure 21: Screenshot of an error report. The report includes the device or object that experienced the error and the issue at hand. 61 11.1 Error table Error code Value Reason ``` UIErrors ``` `FILE_NOT_FOUND_ERROR` 1000 Could not find a given file at its expected location. `FILE_UNSUPPORTED` 1001 The requested file was found, but cannot be opened. `RUNTIME_ERROR` 1002 Unused. ``` MeasurementErrors ``` `MISSING_SETTINGS` 300 No settings have been given. `INVALID_SETTINGS` 301 The given settings do not contain all of the required information or they contain wrong information. `INVALID_SETTING_WITH_FALLBACK` 302 Something was wrong with the settings, but a fallback has been used. `RUNTIME_ERROR` 303 Runtime error. `WRONG_CONTROLLER_CLASS` 304 A secondary controller is not a `MeasureControllerABC` controller. `MISSING_CAMERA` 305 This measurement requires a camera, but no camera was selected. ``` ControllerErrors ``` `INVALID_SETTINGS` 100 The given settings do not contain all of the required information or wrong information. `MISSING_SETTINGS` 101 No settings have been given. `DEFAULT_SETTINGS_CORRUPTED` 102 No or multiple default settings have been found. `CANNOT_MEASURE` 103 A `ControllerABC` subclass that is not supposed to measure has been ordered to acquire data. `INVALID_SETTING_WITH_FALLBACK` 104 Something was wrong with the settings, but a fallback has been used. `NOT_CONNECTED` 105 There is no serial connected to the chosen controller. Error code Value Reason ``` ViPErinoErrors ``` `TOO_MANY_MEASUREMENT_TYPES` 150 More quantities are requested to be measured than there are ADCs. `OVERLAPPING_MEASUREMENTS` 151 More than one quantity is requested to be measured by a single ADC. `INVALID_REQUEST` 152 Hardware cannot measure requested quantity. `REQUESTED_ADC_OFFLINE` 153 ADC assigned to the requested quantity was not detected. `CANNOT_CONVERT_THERMOCOUPLE` 154 Type of thermocouple cannot be derived from settings. Either missing or data is faulty. `HARDWARE_INFO_MISSING` 155 Hardware configuration needs to be detected. ``` ExtraSerialErrors ``` `NO_MESSAGE_ERROR` 50 Received an empty message from hardware. `NO_START_MARKER_ERROR` 51 Received message had no start marker. (If there is a start marker defined.) `TIMEOUT_ERROR` 52 No response received within timeout duration. `UNSUPPORTED_COMMAND_ERROR` 53 Command requested to be sent to the hardware is not supported by it. `INVALID_PORT_SETTINGS` 54 Required port settings either missing or inappropriate. `MISSING_SETTINGS` 55 No settings have been given. `PORT_NOT_OPEN` 56 Serial port could not be opened. ``` ViPErLEEDHardwareError ``` `ERROR_NO_ERROR` 0 No error. `ERROR_SERIAL_OVERFLOW` 1 Overflow on hardware serial. `ERROR_MSG_TOO_LONG` 2 Sent message was too long. `ERROR_MSG_SENT_INCONSISTENT` 3 Message length and length byte of the sent message do not match. `ERROR_MSG_UNKNOWN` 4 Unknown request from PC. `ERROR_MSG_DATA_INVALID` 5 Request from PC contains invalid information. Error code Value Reason ``` ViPErLEEDHardwareError ``` `ERROR_NEVER_CALIBRATED` 6 Need to calibrate the ADCs before performing sent task. `ERROR_TIMEOUT` 7 Microcontroller timeout while waiting for something. `ERROR_ADC_SATURATED` 8 ADC saturated and gain cannot be decreased further. `ERROR_TOO_HOT` 9 Temperature read by LM35 is too high. Not used yet. `ERROR_HARDWARE_UNKNOWN` 10 Need to get configuration before performing sent task. `ERROR_ERROR_SLIPPED_THROUGH` 11 Somehow an error identifier ended up in the unprocessed messages. `ERROR_MSG_RCVD_INVALID` 12 Received message length does not fit any expected response. `ERROR_MSG_RCVD_INCONSISTENT` 13 Message length and length byte of the received message do not match. `ERROR_TOO_MANY_COMMANDS` 14 Attempted to send more than one command at once. `ERROR_NO_HARDWARE_DETECTED` 15 No ADC was detected by the microcontroller. `ERROR_VERSIONS_DO_NOT_MATCH` 16 Firmware version of hardware and ViPErLEED hardware package version do not match. `ADC_POWER_FAULT` 17 ADC_1 has power while ADC_0 was not detected. Likely a hardware fault. `ERROR_RUNTIME` 255 Some function has been called from an inappropriate state. `ERROR_UNKNOWN_ERROR` 256 The error code received is not a known error. ``` CameraErrors ``` `INVALID_SETTINGS` 200 The given settings do not contain all of the required information or wrong information. `MISSING_SETTINGS` 201 No settings have been given. `CAMERA_NOT_FOUND` 202 Could not find the requested camera. `SETTINGS_MISMATCH` 203 Loaded settings of the camera and settings file do not match. `INVALID_SETTINGS_WITH_FALLBACK` 204 Something was wrong with the settings, but a fallback has been used. Error code Value Reason ``` CameraErrors ``` `UNSUPPORTED_OPERATION` 205 Cannot perform requested task in set mode. `BINNING_ROI_MISMATCH` 206 Region of interest size is incompatible with binning factor. Not used yet. `UNSUPPORTED_WHILE_BUSY` 207 Cannot perform requested task while camera is busy. `TIMEOUT` 208 No frames returned within timeout duration. `DEFAULT_SETTINGS_CORRUPTED` 209 No or multiple default settings have been found. ``` DataErrors ``` `INVALID_MEASUREMENT` 400 An unknown quantity has been returned. `UNKNOWN_QUANTITIES` 401 An unknown quantity has been read from a file and will be ignored. `NO_DATA_FOR_CONTROLLER` 402 Controller has not returned any data. 11.2 `QSerialPort` errors A special category of errors are the errors of the `QSerialPort` . They are stored in the `SERIAL_ERROR_MESSAGES` found in the `abc` module in the `serial` package. They are reported like the regular errors. Error code Reason `NoError` No error `DeviceNotFoundError` No device found on the requested port. `PermissionError` No permission to open the port. `OpenError` Cannot open the same port twice. `NotOpenError` Given task cannot be performed on a closed port. `WriteError` Cannot write on port. `ReadError` Cannot read from port. `ResourceError` Port became unavailable. `UnsupportedOperationError` Requested task either unsupported or prohibited. `TimeoutError` Serial timed out. `UnknownError` An unknown error occurred. 11.3 `ViPErLEEDSettings` exceptions The errors encountered when reading from settings files are raised directly. Error code Reason `MissingSettingsFileError` Cannot read file. `NoSettingsError` Cannot read file and there is nothing to default to. `NoDefaultSettingsError` Cannot read default file. `NotASequenceError` Failed to convert data from settings file into a sequence. 66 #### 12 Step profile One of the core issues slowing down measurements is how long it takes the LEED optics to settle after a beam energy has been set. There are two relevant settle times to consider, the HV settle time and the _I_ 0 settle time. The HV settle time is how long it takes the beam energy to stabilize. It is the time cameras have to wait until they can start acquiring frames due to the energy dependence of the beam intensity. The _I_ 0 settle time is how long it takes until the beam current is stabilized. Since both the beam current and the sample current are quantities the controllers are supposed to measure, controllers must wait until the beam current is stable. _Ebeam_ trigger cameras step profile trigger controllers _t0_ _tprofile_ _tHV_ _tI0_ HV settle time I0 settle time _t_ Figure 22: Visualization of an energy step in an I(V) video. Before the measurement can be started, the beam energy has to be set. The step profile may be more complex than just an abrupt step and can take some extra time. The cameras and controllers are triggered after different times once the step profile has been completed. An energy step by the measurement can in fact incorporate multiple energies that are set on the LEED optics before the next beam energy is set. This means instead of jumping directly to the desired beam energy, the measurement will first set different energies, wait for a certain amount of time 67 and then continue on to finally end up with the desired energy. This is done in order to allow the setting of a more nuanced step profile which reduces the overall settling time of the electronics. Figure 22 shows how an energy step during a regular `IVVideo` might look like. Note that the cameras get triggered separately from the controllers. Both have their respective settle times after each energy step, as explained in Section 4.3. In order to set energies with intermediate steps in an attempt to reduce settling times, the step profile can currently be adjusted in the settings. The step can be abrupt, linear or a custom setting. The abrupt setting will just do a single abrupt step with no intermediate transitions. The linear step will split the step into the number of steps given in the settings. For more specialized profiles the custom mode can be used, which performs intermediate steps as fractions of the total energy difference between two steps. Future plans include the implementation of a more sophisticated `EnergyRamp` that will be responsible for providing an optimized step profile for the task at hand. The idea is to automatize the analysis of the response function of the LEED hardware to quickly determine suitable intermediate steps to reduce settle times. The `EnergyRamp` would then use the collected data to calculate the most desireable step profile for each energy step. During tests conducted on the setups used for this thesis the HV settle time has consistently been longer than the _I_ 0 settle time. One system in particular, the Omicron SpectaLEED (with MCP), has shown strong oscillations after an energy step. A plot of _I_ 0 can be seen in Figure 23. It shows the instability of the beam current when the electron energy is decreased from 51 to 50 eV. (A similar pattern can be observed when increasing the energy from 50 to 51 eV.) Figure 23 shows a regular, abrupt energy step in black and a linear step in red. Especially right after the energy has been set, a severe spike can be observed in the abrupt step. After the step follows a 5 Hz oscillation that persists visibly for 1000 ms. The magnitude of the oscillation can be reduced by instead setting the energy via a linear step profile. The step is done in 4 separate steps over 200 ms. As seen in red in Figure 23, this reduces the amplitude of the oscillation. Additionally, the overall settle time has been reduced: it is now located at the 750 ms mark, while it was 1000 ms without the intermediate steps. The core result is that with the correct step profile the settle time can be significantly reduced. Furthermore, with oscillations for 1000 ms on a SpectaLEED with multi-channel plate compared to 60 ms observed on an ErLEED it is safe to say that some LEED optics are better suited for LEEDI(V) measurements than others. On our website we present modifications we have performed to improve the settle times. 68 15 10 5 0 _E_ abrupt 200ms linear _t_ 0 1000 2000 ###### Times (ms) Figure 23: _I_ 0 response doing a 51 to 50 eV step. In black: abrupt step; in red: linear step with intermediate transition. The intermediate steps reduce the initial spike and the duration of the transient. 69 #### 13 Conclusions and outlook This thesis has provided an in-depth description of the most essential parts of the ViPErLEED measurement package. The ViPErLEED measurement package is a highly adaptable tool that can already be used to perform LEEDI(V) measurements. The system can calibrate the energy scale by itself and the tools required to determine the settle times of LEED electronics are available. Performing LEED-I(V) measurements with the presented tools enables users to quickly acquire high-quality data. Furthermore, the data acquisition can even be monitored in real time. The structure that has been put in place provides a framework that is able to work with a wide variety of devices and that is future-proof. If the user chooses to assemble the ViPErLEED hardware controller (viperino), the system can be deployed out of the box with a wide range of capabilities. In the future, the ViPErLEED measurement package will enjoy further improvements and more development is needed to bring together the complete system we have imagined. Further testing needs to be done to find bugs that may remain in the code. The separate setting of a beam energy without starting a measurement must be implemented. The `TimeResolved` class will be modified to automatically calculate the necessary settle times on request. Furthermore, we have planned to implement a feature which attempts to find a step profile that reduces the required settle time. With future iterations of the package, more controller classes may be added. A currently planned feature is a ViPErLEED controller that measures external magnetic fields to compensate for them in real time. Additionally, we plan to further abstract the setting of energies to allow for a generator class that determines the next energy. Some features in the camera class require optimization to guarantee real-time functionality. 70 ### Appendix #### A PyQt In order to implement the handling of hardware and provide the user with a graphical interface, other premade systems have been integrated in ViPErLEED. Since much of the administrative tasks performed by ViPErLEED are written in Python, it makes sense to integrate Python-based packages to expand on the capabilities of ViPErLEED. One such package is PyQt and it is heavily relied on. PyQt is a free python plugin developed by Riverbank Computing. It is a Python binding of the cross-platform C++ graphical user interface (GUI) toolkit Qt. It supports Windows, Linux, and MacOS and provides many GUI widgets and functionalities used in the Python package for ViPErLEED. One of its uses in this thesis was to gain the ability to multithread. PyQt features its own implementation of multithreading including signals and slots that allow the communication between objects living in different threads. This allows the ViPErLEED measurement package to handle multiple controllers at once, sending them commands and receiving data from all measuring controllers simultaneously [7]. Through this implementation choice it is possible to have multiple controllers measure different quantities during a measurement. Having multiple controllers also makes it possible to split the tasks of controllers into one whose sole task it is to set the beam energy and other controllers that can acquire measurement data. This is useful if there is a hardware controller that is integrated into the LEED system. In this case the integrated controller can be used to set the beam energy and another controller can be used to acquire numerical data. The full documentation of PyQt can be accessed at `[https://doc.qt.io/qtforpython-5/](https://doc.qt.io/qtforpython-5/)`, and the documentation of the C++ code can be accessed here `[https://doc.qt.io/qt.html](https://doc.qt.io/qt.html)` . It is important to note that PyQt version 5 has been used to ensure compatibility with Windows 7 and later. The following paragraphs describe which crucial objects from PyQt have been used in the thesis and what they are meant to do. A.1 `QObject` `QObject` is the base class of all Qt objects. This class is at the core of all object communication in Qt. It allows for signals and slots to be used and gives objects the ability to be moved to different threads (see Appendix A.2). `QObjects` have a so-called thread affinity which means they can live in a specific thread. A signal received by an object living in a cer 71 tain thread will be processed in the event loop of this thread. All Qt widgets inherit from `QObject` [8]. The `MeasurementABC`, `CameraABC`, `SerialABC`, and `ControllerABC` classes described in this thesis are all subclasses of the QObject class. In return, all classes derived from these base classes also inherit the methods of the `QObject` class. The abstract base classes (ABC) provided handle much of the `QObject` -related tasks. Implementations of new devices or measurement types should therefore always subclass the provided ABCs and follow the instructions of abstract methods closely. Each of the abstract methods provides ample documentation that programmers can consult for more information. A.2 `QThread` This class provides the ability to manage threads. Once a `QThread` has been created, `QObjects` can be moved to this thread. To allow objects to perform their tasks in their respective threads, methods of the objects must be “called” via signals (see Appendix A.3) from other threads. It is important to note that the `QThread` of the created thread lives in the thread the new thread was created in. Its own methods therefore must be called in the old thread, while anything handled in the event loop of the new thread must be “called” via signals or in the new thread. To be able to execute an object’s method from another thread the method has to be decorated with the `@qtc.pyqtSlot()` slot decorator [9]. The use of the slot operator is extremely important as the invoked method will otherwise be executed in the thread in which the invoking signal was emitted. Threads have been used extensively in the ViPErLEED measurement package. With the exception of the primary controller, all controllers are moved to their own threads after creation. The primary controller however lives in the same thread as the measurement class. The measurement class itself is moved into its own thread by the measurement GUI upon creation. The reason for the extensive implementation of multi-threading in the ViPErLEED measurement package is to allow asynchronous collection and processing of data while not stalling the GUI. Moving resource-intensive processes to other threads keeps the GUI responsive and allows the user to interact with it while a measurement is ongoing. All tasks that are completed in another thread are not guaranteed to be performed immediately. They are instead performed when the operating system happens to start processing that specific thread. This may take a considerable amount of time if there is a significant backlog of tasks. All tasks that are time critical, tasks that must be performed immediately, should be called directly, therefore immediately performing them in the currently executing thread. 72 A.3 Signals and Slots Signals are used in PyQt to communicate between objects. A signal can be connected to another signal or a slot via the `connect()` method. The slot is a python callable. Signals can be connected to slots in other threads. The signal can therefore cause the execution of a method of an object living in another thread. To do this, a signal first has to be connected to this method. When the thread the object is living in is running, the signal has to be emitted. To emit a signal, the `emit()` method has to be used which can be passed with arguments if necessary. A signal can be disconnected from other slots and signals using the `disconnect()` method [10]. Signals and slots are type safe and can take any number and type of arguments. Signals and slots are inherited by subclasses [11]. In accordance with the heavy implementation of multithreading, most of the communication between objects of the ViPErLEED measurement package happens via signals. One of the few exceptions are tasks specific to the primary controller which are time critical and are enacted by the measurement class directly. This is why the primary controller and the measurement class live in the same thread. A.4 `QTimer` `QTimers` can be used to start timers in different threads. `QTimers` emit a `timeout` signal at the end of their duration. They can be set to repeat themselves or to fire only once. `QTimers` have to be started and stopped in the thread they live in, or by using an appropriate signal connected to their `start()` and `stop()` slots. Their accuracy depends on the operating system but is supposed to be within milliseconds [12]. All timers used in this thesis are `QTimers` . A.5 `QWidget` This is the base class of all user-interface objects in PyQt. `QWidgets` can be displayed on the screen and be interacted with using mouse and keyboard. A widget that is not embedded in a parent widget is referred to as a window. Most widgets with parents however are limited by their parents’ geometry. They can be placed within their parent widgets using layouts. Widgets holding multiple children widgets are called composite widgets [13]. `Measure`, the measurement GUI, and `MeasurementPlot`, the measurement plotter, are both highly modified, composite widgets. 73 A.6 `QSerialPort` `QSerialPort` provides the ability to access serial ports. Ports can be set and opened in read-only, write-only, or read–write mode. An open port will prevent any other process from accessing the used serial port. Therefore, ports must be closed to allow other entities to take over. When a `QSerialPort` is opened, it will try to determine its current configuration and initialize itself. `QSerialPort` can be configured by setting the baud rate, the data bits, the parity, the stop bits and the flow control [14]. The serial classes of controllers in the measurement package rely on `QSerialPort` for their functionality. 74 #### B Signals B.1 Signal table Name Reason Arguments Triggers ``` Measure ``` `error_occurred` Error occurred. `tuple` containing error information. ``` MeasurementABC ``` `error_occurred` Error occurred. `tuple` containing error information. Error window. Error window. `finished` Measurement completed. None. Wrapping up of measurement in `Measure` `new_data_available` New data to process. `dict` containing newest mea- Plot of new data. surements. `prepared` Preparation completed. None. Time stamp recording in `Measure` for display purposes. `_request_stop_devices` Stop all devices. None. Interrupt any ongoing task in all controllers and cameras. `_request_stop_primary` Stop primary controller. None. Interrupt any ongoing task in primary controller. `__preparation_started` Starting preparation. `tuple` representing energies First preparation step of conand settle times. nected devices. `__preparation_continued` Continuing preparation. None. Second preparation step of connected controllers. Name Reason Arguments Triggers ``` TimeResolved ``` `__request_continuous_mode` Changing measurement mode from/to singlemeasurement to/from continuous. ``` ControllerABC ``` `bool` representing value of continuous mode set. Setting of continuous mode in controllers. Error window. `error_occurred` Error occurred. `tuple` containing error information. `about_to_trigger` Primary is about to trigger a measurement after setting an energy. None. Measurement in secondary controllers and cameras. `data_ready` Data has been collected. `dict` containing measurement. Storing of numerical data. `controller_busy` Controller busy changed. `bool` representing busy Methods in measurement state of controller. class. `ready_to_show_settings` Controller has collected None. Opening of settings dialog. all the information needed to display settings to the user. `controller_busy` Controller busy changed. `bool` representing busy state of controller. None. Opening of settings dialog. Name Reason Arguments Triggers ``` SerialABC ``` `error_occurred` Error occurred. `tuple` containing error information. Error window. `data_received` Received data that needs to be processed further. `object` containing data. Processing by controller class. `serial_busy` Serial busy changed. `bool` representing busy state Sending of next unsent mesof serial. sage of the controller class if not busy. `about_to_trigger` Hardware has set an en- None. Controller `about_to_trigger` ergy and is ready to trig- signal. ger a measurement. `serial_busy` Serial busy changed. `bool` representing busy state of serial. None. Controller `about_to_trigger` signal. `__move_to_thread_requested` Serial moved to thread. `bool` representing if the port was open. ``` ViPErLEEDSerial ``` Connect to port. `debug_info_arrived` Debug info arrived. `str` ``` CameraABC ``` `error_occurred` Error occurred. `tuple` containing error information. `camera_busy` Camera busy changed. `bool` representing busy state of camera. Error window. `camera_busy` Camera busy changed. `bool` representing busy state Methods in measurement of camera. class. `frame_ready` New frame ready. `ndarray` containing an im- Processing of frame. age. Processing of frame. Name Reason Arguments Triggers ``` CameraABC ``` `image_processed` Image was processed. `ndarray` containing a processed image. `image_saved` Image was saved. `str` containing the path to the saved file. Displaying of new image. Archiving of saved image. `started` Camera started. None. Displaying of images. `stopped` Camera stopped. None. Finalization of measurement. `camera_connected` Camera was either con- `bool` representing connection Enabling of camera in viewer. nected or disconnected. status. Enabling of camera in viewer. Processing of frame in another thread. Error window. `preparing` Camera started _\_ finished pre-acquisition tasks. `bool` representing connection status. `bool` representing if preacquisition tasks are ongoing. `__process_frame` Start processing frame. `ndarray` containing an image. ``` DataPoints ``` `error_occurred` Error occurred. `tuple` containing error information. Signals that are headed by a `__` are for internal use only, while signals headed by a `_` are meant to be used in subclasses as well. #### References [1] M. De Graef, T. Lucatorto, _Advances in Surface Science_, Elsevier Science, 2001. [2] E. Bauer, Ch. Eisenmenger-Sittner, J. Fidler, _Materialwissenschaften_ _für_ _Technische_ _Physiker_, Skriptum TU Wien, 2017. [3] W. Demtröder, _Experimentalphysik_ _3:_ _Atome,_ _Moleküle_ _und_ _Festkörper_, Springer-Verlag, 2009. [4] M. Schmid, _Experimentelle_ _Methoden_ _der_ _Oberflächenphysik_, Skriptum TU Wien, 2021. [5] P.J. Rous, J.B. Pendry, _Tensor_ _LEED_ _I:_ _A_ _technique_ _for_ _high_ _speed_ _sur-_ _face_ _structure_ _determination_ _by_ _low_ _energy_ _electron_ _diffraction._ _TLEED1_, Comput. Phys. Commun. 54 (1989)137–156. [6] J.B. Pendry, _Reliability_ _factors_ _for_ _LEED_ _calculations_, J. Phys. C: Solid State Phys. 13 (1980) 937-944. [7] Riverbank Computing Limited, _What_ _is_ _PyQt?_, `[https:](https://riverbankcomputing.com/software/pyqt/)` ``` //riverbankcomputing.com/software/pyqt/ ``` [8] The Qt Company Ltd., _QObject_ _documentation_, `[https://doc.qt.io/](https://doc.qt.io/qtforpython-6/PySide6/QtCore/QObject.html)` ``` qtforpython-6/PySide6/QtCore/QObject.html ``` [9] The Qt Company Ltd., _QThread_ _documentation_, `[https://doc.qt.io/](https://doc.qt.io/qtforpython-6/PySide6/QtCore/QThread.html)` ``` qtforpython-6/PySide6/QtCore/QThread.html ``` [10] The Qt Company Ltd., _Signal_ _documentation_, `[https://doc.qt.io/](https://doc.qt.io/qtforpython-5/PySide2/QtCore/Signal.html)` ``` qtforpython-5/PySide2/QtCore/Signal.html ``` [11] The Qt Company Ltd., _Signal_ _and_ _slot_ _documentation_, `[https://doc.](https://doc.qt.io/qtforpython-6/overviews/signalsandslots.html)` ``` qt.io/qtforpython-6/overviews/signalsandslots.html ``` [12] The Qt Company Ltd., _QTimer_ _documentation_, `[https://doc.qt.io/](https://doc.qt.io/qtforpython-5/PySide2/QtCore/QTimer.html)` ``` qtforpython-5/PySide2/QtCore/QTimer.html ``` [13] The Qt Company Ltd., _QWidget_ _documentation_, `[https://doc.qt.io/](https://doc.qt.io/qtforpython-5/PySide2/QtWidgets/QWidget.html)` ``` qtforpython-5/PySide2/QtWidgets/QWidget.html ``` [14] The Qt Company Ltd., _QSerialPort_ _documentation_, `[https://doc.qt.](https://doc.qt.io/qtforpython-6.2/PySide6/QtSerialPort/QSerialPort.html)` ``` io/qtforpython-6.2/PySide6/QtSerialPort/QSerialPort.html ``` 79

섹션 본문

섹션 본문이 없습니다.

참고문헌

참고문헌 정보가 없습니다.