Christian Grech bio photo

Christian Grech

Software Engineer at Quantum Diamonds GmbH.

Germany   G. Scholar LinkedIn Github e-Mail

Other Participants: Marc Guetg, Gianluca Aldo Geloni


Project description

Single-crystal monochromators are used in free electron lasers for hard x-ray self-seeding (HXRSS), selecting a very narrow spectral range and further amplifying the original SASE signal. When a crystal is rotated, one can exploit several symmetric and asymmetric reflections as established by Bragg's law. The following image shows the SASE 2 beamline at the European XFEL, set up for Hard X-Ray Self Seeding (HXRSS). In each undulator, an alternating magnetic field causes the emission of X-Ray radiation from electrons. Crystals are then used to filter certain wavelengths/energies.

European XFEL SASE2 undulator two-crystal self-seeding scheme

Fig. 1 - European XFEL's SASE2 undulator two-crystal self-seeding scheme. The first undulator section produces a self-amplified spontaneous emission (SASE) photon pulse. This photon pulse diffracts from a diamond crystal. The rotational convention for the crystal is shown in this diagram. The diffracted beam exits at some angle to the incident beam and is discarded. The electron pulse is delayed by a chicane to overlap spatially with the narrow-bandwidth tail of the x-ray pulse in the second undulator section. In the final section, an output undulator amplifies the monochromatic seed.



Currently, a Machine Learning (ML) classifier is used during experimental setup to identify the crystal indices corresponding to a given reflection, compare to a model, and eventually calculate the difference between the photon energy as measured by the single-shot spectrometer and the actual one. The model is shown below:


Bragg model showing photon energy vs pitch angle for diamond crystal reflections

Fig. 2 - Photon energy values at which diffraction occurs in a diamond crystal, as a function of the pitch angle for fixed values of the roll and yaw angles. Each curve corresponds to reflection from a different set of crystallographic planes. A partial list of reflections is shown in the legend.


Crystal reflections are first scanned at different pitch angles using the spectrometer, and the image obtained is binarized. With a 68% extraction rate and a very low false positive rate, lines with a high intensity and good contrast from the background can be detected using the Hough Transform method. A ML classifier then compares a preset measurement model and the extracted lines and identifies the reflections based on different line properties. Most errors were noted in cases where multiple parallel lines occur close to each other (for example classifying [1, -1, -1] as [1, -1, 1]).


Comparison of captured spectrometer image, processed version, and Hough Transform line detection

Fig. 3 - Example of a) a captured image, b) a processed version (binarization, dilation, erosion) and c) the detected lines (Hough Transform).



We are now proposing an alternative method for identifying the actual photon energy by implementing a technique known as Template Matching. Template matching is a common computer vision technique where an algorithm is trying to find similarities between two images. This technique slides a window across the image that will provide a percent match with the template. If the percent match is above a certain threshold then it is assumed to be a match. This will in some situations result in poor performance because it requires the template to overlap the image identically.


Template matching is a sufficient technique if one knows exactly what they are looking for and are confident that it will appear almost identically in every example. ML techniques such as Convolutional Neural Networks (CNN) can be used in cases where the template and the image are not identical. ML techniques are not rigid and are able to generalize a dataset very well. What is required in this case is a fairly large dataset so that the model is robust to many different scenarios.


This project involves the matching of a processed spectrometer image (template), with an image created from an available model. The following proof-of-concept gets the original spectrometer scan (first image) and clips out the unnecessary blank areas (second image). The second image is the template. The third image is the image created from the Bragg model, with the red box being the matched area using sklearn’s match_template package. By comparing the bottom left corner energy value of the spectrometer image and the matched image, one can calculate the energy difference. The final image plots the calibrated template on top of the model.


Template matching workflow applied to spectrometer scan for energy calibration

Fig. 4 - Example of template matching applied to a single-shot spectrometer scan.





Project resources