MJOLNIR: A Software Package for Multiplexing Neutron Spectrometers

Novel multiplexing triple-axis neutron scattering spectrometers yield significant improvements of the common triple-axis instruments. While the planar scattering geometry keeps ensuring compatibility with complex sample environments, a simultaneous detection of scattered neutrons at various angles and energies leads to tremendous improvements in the data acquisition rate. Here we report on the software package MJOLNIR that we have developed to handle the resulting enhancement in data complexity. Using data from the new CAMEA spectrometer of the Swiss Spallation Neutron Source at the Paul Scherrer Institut, we show how the software reduces, visualises and treats observables measured on multiplexing spectrometers. The software package has been generalised to a uniformed framework, allowing for collaborations across multiplexing instruments at different facilities, further facilitating new developments in data treatment, such as fitting routines and modelling of multi-dimensional data.


Introduction
Inelastic neutron scattering instruments allow detailed studies of the dynamical structure factor, S(Q, ω), where Q is a scattering vector in reciprocal space andhω = ∆E an energy transfer. One of the work horses of modern neutron scattering are triple-axis instruments (see Fig. 1), because they typically have a high neutron flux and good energy resolution [1].
we describe the structure of MJOLNIR, followed by examples of some of its features. Figure 1a shows a sketch of a typical triple-axis spectrometer with the six relevant rotation axes, A 1 -A 6 . The monochromator is rotated with respect to the direct beam by A 1 . Through the Bragg scattering condition the sample is positioned at A 2 = 2A 1 , such that a single incoming neutron wavevector, k i (and thereby the energy E i ) is selected. The sample rotation is denoted A 3 , while A 4 is the angle between the incident beam on the sample and the analyser. Similarly to the monochromator, the analyser is rotated by A 5 and the detector is placed at A 6 = 2A 5 to select a single final neutron wavevector, k f (and thereby the energy E f ). The momentum and energy transfer between the neutron and the sample are given by Q = k i − k f and ∆E = E i − E f , which can be calculated from A 1 − A 6 and knowing the properties of the monochromator and analyser. We refer to Ref. [1] for a more extensive description of triple-axis spectrometers.

Triple axis spectrometers
A multiplexing triple-axis instrument uses multiple analysers and detectors which leads to simultaneous measurements of the neutron scattering intensity at multiple A 4 − A 6 positions (see Fig. 1b). In some instruments position sensitive detectors collect neutrons from multiple analysers. In addition, on most multiplexing instruments (including CAMEA) the scattering direction off the analyzers is rotated by 90 • when compared to standard triple-axis instruments, thus scattering neutrons onto detectors that are outof-plane. This impacts the resolution with which particular (Q, ∆E)-points are measured, but is mostly employed for practical reasons to allow for a maximal density of analyzer-detector pairs. The rotation out of plane changes the resolution calculation and renders current schemes inapplicable. Work is ongoing to account for this change.

Coordinate systems
In MJOLNIR, the data treatment of multiplexing instruments is facilitated by defining several related coordinate systems that describe the scattering vector, Q, illustrated in Fig. 2. The instrument coordinate system is an orthonormal coordinate system that is sample independent. It is defined by C instr = (Q x , Q y , Q z , ∆E), where Q y is parallel to k i and orthogonal to Q x within the scattering plane. The out-of-plane component Q z is zero in all cases. The sample coordinate system shares the axes of instrument coordinate system, but is rotated so that the first axis points along a reciprocal lattice vector of the sample: Figure 1: a: Sketch of a standard triple-axis instrument depicting the six angles, A 1 -A 6 . b: Zoom on multiplexing secondary spectrometer with two scattering angles and two final energies measured simultaneously.
The reciprocal lattice coordinate system is defined by two reciprocal lattice vectors in the scattering plane, C RLU = (P 1 , P 2 , ∆E), which is often chosen to be along high symmetry directions. For samples with cubic, tetragonal, or orthorhombic symmetry, the reciprocal lattice coordinate system overlaps with the sample coordinate system, such as illustrated in Fig. 2a. In contrast, the reciprocal lattice vectors are not orthorgonal in hexagonal, trigonal, monoclinic or triclinic systems, see Fig. 2b.
A typical measurement on CAMEA consists of rotating A 3 while keeping all other angles constant. This generates data points as shown in Fig. 2 by the red lines.

The Scope of MJOLNIR
MJOLNIR is designed to provide tools for three purposes: 1) conversion of data into the reciprocal lattice coordinate system or the sample coordinate system. 2) Normalisation and visualisation of the data in 1, 2 and 3 dimensions, and 3) analysis of the data. We now describe the scope of MJOLNIR in these three aspects.

Data conversion
Conversion of data to the reciprocal lattice coordinate system requires detailed knowledge of the specific instrument setup. MJOLNIR has initially been developed for CAMEA, and thus includes an accurate description of this instrument. We, however, aim for MJOLNIR to be used across many multiplexing spectrometers such as MultiFLEXX [20], FlatCone [3] and Bambus [7]. We have thus developed tools to model any multiplexing triple-axis type instrument in MJOLNIR. We note that MultiFLEXX is being moved to the Heinz Maier-Leibnitz Zentrum due to limited activities at the Helmholtz-Zentrum in Berlin. There are two methods by which the required instrument parameters can be extracted for the data conversion, which are explained in detail in Ref. [9]. The parameters can either be calculated from the instrument design directly, assuming a perfect setup, or measured through an experiment allowing for small deviations. A direct measurement yields more accurate results, but requires some extra modelling. At CAMEA, the scattering angles are calculated, while final energies are measured directly. At MultiFLEXX both parameters are calculated [20]. MJOLNIR supports both options.
Further differences among various multiplexing instruments arise from the fact that some of them employ a prismatic analyser concept of several energies scattered from one analyzer [21], while others do not. However, by implementing the prismatic concept, the standard setup will be a limiting case of just a single energy, and is thus also supported.
Along these lines, the requirements for the upcoming indirect time-offlight spectrometer BIFROST at the European Spallation Source are worth noting [22,23]. The instrument shares many similarities with CAMEA; both possess multiplexing secondary spectrometers, utilising the prismatic concept in combination with position sensitive detectors. However, their primary spectrometers differ. CAMEA is situated at a quasi-continuous source using a monochromator to determine the incoming energy. BIFROST, on the other hand, will be situated on a pulsed source, determining the incoming energy by time-of-flight. In effect, BIFROST performs a scan over incoming energies within a defined window, whereas CAMEA employs one fixed incoming energy only. In practice this extends BIFROST data by an additional dimension when compared to CAMEA. We expect that extensions of MJOLNIR will be suitable for handling data from BIFROST.

Visualisation
MJOLNIR is designed to work directly with raw data, where each data point consists of a neutron count, a monitor count, and normalization value, as well as a position in reciprocal space. Acquiring multiple scans at almost identical positions will increase the likelihood that multiple points are in close vicinity of each other. One may argue that if their difference is smaller than the expected instrumental uncertainty they should be binned. The approach, however, imposes a resolution estimate reducing the transparency of the data process, as two points within a given distance in a certain parameter space might be binned in some part of the measurement volume but not in other parts. This is due to the fact that the instrument resolution changes across the probed volume of reciprocal space. Instead, we prefer to treat all data points separate as long as no user-defined tolerance is provided.
MJOLNIR provides tools for visualising data from any multiplexing instrument in 1, 2 and 3 dimensions in the reciprocal lattice coordinate system and in the sample coordinate system. For these purposes, the user defines the size of the bins as well as the directions of the desired cuts. MJOLNIR then bins and normalises the raw data to the monitor count, and plots the binned data. The tools are described in detail in the documentation [12].
We note that MJOLNIR has been written for multiplexing triple-axis instruments specifically. The software is not suitable for data acquired on standard triple-axis instruments where only a one-dimensional sub-space of reciprocal space is measured. Conversely, direct geometry time-of-flight spectrometers produce 4-dimensional data sets, whose handeling is outside the scope of MJOLNIR.

Data analysis
Because all data is kept in the original un-tampered form throughout the data treatment process, different fitting algorithms and methods can be employed. This is important for non-standard Poisson and Multinomial fitting routines [24], where it is important to keep integer neutron counts as opposed to normalized counts. Currently, fitting is supported through a series of 1D cuts in reciprocal space for constant energy, or constant Q. At present, interface tools with the uFit [25] program is under development and will in the long run also interface with analysis software, such as SpinW [17].

Program Structure
The MJOLNIR package is composed of several modules, each dedicated to a specific task. A virtual model of the instrument is generated using the Geometry module. The actual data processing and visualization objects are located in the DataSet module. The data fitting process is kept separate from the data objects in the Statistics module in an effort to clearly separate data conversion and data analysis, and to be also able to switch fitting routines and software. At the time of writing this module is being merged with the capabilities of uFit [25], although these efforts are not reported in the following. General functions and repeatedly used subroutines are located in the _tools module. One of them is a collection of triple-axis conversion commands called TasUBLibDEG, which was translated from the C ++ library TasUBlib based on Lumsden et. al. [26]. In the following sections, we highlight some key features of the different modules.

Geometry
The objects and methods in the Geometry module have two principal purposes; the first is the virtual representation of the instruments, the second is to facilitate the generation of normalisation tables in which the calibrated pixel efficiency, final energy, and scattering angles of the detectors are stored. The normalisation has been separated from the implementation of the data structure in an effort of generalisation, and to signify its connection with the instrument as opposed to the data treatment. A virtual representation of the instrument will be particularly useful in foreseen future features of the data treatment such as calculations of the resolution function.
Virtual Instrument. The creation of a virtual instrument is done using the Instrument object and the subsequent Wedge, Analyser, and Detector objects. These encode their real world counterparts, containing information about instrument relevant positions, directions, and d-spacings. The simulation of an instrument is implemented either via a script that adds the objects to the instrument structure, or by means of an XML file.
Different instruments feature varying setups. In the simplest case, there is a one-to-one correspondence between detectors and analyser. This is the case for MultiFLEXX as each detector corresponds to a single analyser. The situation is more involved at CAMEA as the instrument consists of 13 position sensitive detectors inside a 8 • wide wedge. Each detector detects neutrons scattered from 8 different analysers, typically corresponding to 24 to 64 different energies, when the prismatic analyzer concept is employed. In such cases where a detector receives neutrons from different analysers, a position sensitive detector with a defined pixel numbering is simulated. This allows splitting of detectors into sub-parts, identifying neutrons from the different analysers.

Data
All code that is connected to the data conversion and data treatment is grouped in the Data module. This includes the DataFile and Sample objects, which refer to instrument and sample parameters of individual scan files. This, for instance, enables masking options for specified data regions in individual data files or across an entire data set.
Experiments on multiplexing instruments often produce a number of data files with similar parameters that can be combined into a single data set. For this reason we created the DataSet object that deals with multiple data files simultaneously. It represents an abstraction of a list containing DataFile objects, and hosts a number of methods and helper functions to perform cuts and plots.
Conversion. Once the experimental geometry and all instrument settings are known, the conversion from the detector positions to reciprocal lattice units happens in two steps. Fist, the A 4 angles and final energies of the instrument reference frame are transformed into the instrument coordinate system, and then to the reciprocal lattice unit system of the sample. Both conversions are based on the formalism of TasUBlib [26].
Most often, a data file arises by scanning one or more instruments settings, typically the incoming energy, the sample rotation, or the rotation angle of the analyzer-detector tank that impacts the scattering angle of all detectors. However, MJOLNIR allows for the most general case of multiple changing parameters, which happens when scanning both the sample rotation and scattering angle simultaneously.
Data from each file is converted to a structure of shape n p × n detectors × n pixels , where n p , n detectors and n pixels is the number of scan points, detectors and pixels per detector, respectively. One such object is created for A 3 , A 4 , ∆E, qx, qy, H, K, L, the normalisation, monitor and neutron count I. Here, normalization refers to the combined analyzer and detector efficiency, while the monitor count keeps track of the neutron count in the guide monitor.
The converted data are the basis for any further process. We note that the normalisation, monitor and I are not combined, but kept separately.
Performing cuts. Directly visualizing a complete scan file as a point cloud in 3D reciprocal space is often disadvantageous. Instead, cuts along specific lines or planes in reciprocal space are performed to highlight specific features. Due to the usual scarcity of regions of interest it may also be preferable to avoid cuts where only low scattering areas are present. Multiple cutting and corresponding plotting methods have been implemented in MJOLNIR. These include 1D cuts along a constant energy or momentum transfer line and 2D intensity maps connecting multiple scattering points. These cuts are useful to visualise the data, and are also the basis for further data processing such as fitting. Further information on the visualising routine is given below.
Masking. As CAMEA measures a large region in reciprocal space during a single scan, additional unintended signals are sometimes detected. These may be extrinsic features such as spurious peaks or additional phonons or magnetic contributions that do not concern the addressed scientific question. It may be preferential to mask these contributions, before cuts or fits are preformed. In MJOLNIR, this is supported by the Mask module where different options are available. They can be combined using standard Boolean algebraic operations, which are described in detail in the MJOLNIR documentation [12].

Statistics and Fitting
The main goal of any neutron scattering experiment is to gain deeper insight into microscopic parameters of the studied material. This happens either through direct determination of microscopic properties or indirectly through a comparison with theoretical models. In both cases some kind of fitting is needed. MJOLNIR provides a statistical tool, which allows for different statistical approaches. In particular when dealing with Poisson statistics, the normalisation and neutron intensity at each measured reciprocal lattice needs to be taken into account [24]. An accurate fitting routine of such data is currently developed by merging MJOLNIR with the existing software package of uFit. We refer to the documentation of that uFit for details [25].

Interfaces
Three different interfaces have been created which serve different purposes, also providing different levels of control. The main interface is the scripting interface of MJOLNIR which is imported in a python script. It supports all features of the software and allows creating new virtual instruments, normalization tables, and to convert and visualise the data. The scripting interface is the backbone of the software. A limited command line interface can be used to shortcut some of the key functions. These include reporting, conversion and visualization functions, serving as a quick way of checking data during experiments. Third, we have also developed a graphical user interface meant to both allow quick figure generation through a point-and-click interface and to also guide users towards the scripting interface.
Command Line Interface. Four commands have been created that act as a short list for MJOLNIR scripts. These are the MJOLNIR3DView-method plotting the interactive View3D window, the MJOLNIRConvert-method converting data sets from HDF to NXS using a specified binning, the MJOLNIRCalibrationInspectormethod that displays the current normalization options, A 4 values and final energies, and the MJOLNIRHistory-method that reports the data set content. In each case the respective data files are entered directly or through a file dialog. Further variables or input parameters can be attached to control properties such as the bin sizes used in conversion or the type of plot that is generated. An example of the MJOLNIRHistory-method is shown in Fig. 3. Graphical User Interface. A user-friendly interface has been created for users that prefer to avoid using Python in a scripting-based environment. The interface is built directly on top of the MJOLNIR package and provides access to a variety of its key features. The tool can generate different plots and inspect experimental data on the fly. We also implemented the possibility to directly generate Python scripts from the GUI interface. This is useful if the user prefers to add customary modifications to figures, for instance. Adhering to the desire of being usable across many operating systems, we wrote MJOLNIRGui using the python bindings of Qt [27]. In combination with FBS package [28] it allows for the creation of installers across different operating systems.

Using MJOLNIR
In this section we show examples of how MJOLNIR can be used during an experiment. The data and a tutorial replicating the figures produced here can be found in the documentation of MJOLNIR [12]. The presented spin waves were acquired on a large MnF 2 single crystal at T = 10 K acquired at the CAMEA instrument at PSI. Further details are found in the CAMEA commissioning article [9].

Loading and converting data
Using the MJOLNIRGui, we first create a new Data set, then add the data files, load them into MJOLNIR, and finally convert the data to the reciprocal lattice space. These steps are completed within the GUI, or using the scripting interface.

Overview of data: Viewer3D
For a quick overview of the data, the Viewer3D method is particularly useful. The method bins and plots the data in the instrument coordinate system (Q x , Q y , ∆E) or the reciprocal lattice coordinate system, (P 1 , P 2 , ∆E). The data is binned via the SciPy HistogramDD into equi-sized voxels, whose size can be specified by the user. The main reason for utilising a constant binning is rapid processing time. We chose to perform the binning in the orthonormal sample coordinate system to truthfully visualise the data, which would not be the case if it was performed in a geometry where the reciprocal lattice basis vectors had different lengths. Alternatively, one could plot constant energy planes where in a polar coordinate system. This is because an A 3 rotation represents a rotation around the origin, which yields almost equally distributed data points as a function of |Q|. We implemented this option into the plotQPlane method.
The View3D module comes with an interactive GUI that allows the user to step through the data, plane by plane, along three different directions, i.e., along the two projection vectors and the energy. It is possible to perform cuts along arbitrary directions, for which more computational power is required. Examples of the output of View3D are shown in Fig. 5, and the script needed to produce this figure is given in appendix Appendix A, as generated by the Gui interface.

Cuts through the data: plotCutQELine
The data may be understood deeper when plotting the intensity as function of energy and Q along a path in reciprocal space. The plotCutQELinemodule has been developed for this purpose. The code is composed of smaller building blocks, ensuring a successful visualisation of arbitrary twodimensional cuts with different binning sizes and relative distances in reciprocal space.
Each cut unifies a collection of one-dimensional cuts of a certain Q-width and constant energy window. An example is shown in Fig. 6a using 5 different Q points of MnF 2 . A mouse-over function displays the normalized intensity, the central relative lattice position, the normalization, monitor and the number of binning points to create the shown pixel intensity. The plotting method also allows to display 2D planes embedded in a three-dimensional figure as shown in Fig. 6b. The plots have been combined with constant energy plots generated by the plotQPlane method, and the colour map is chosen such that low intensity points are transparent.

Conclusion
We have developed the MJOLNIR software package to convert, visualize and analyse data from multiplexing triple-axis instruments. It has already been successfully used during the commissioning of CAMEA at PSI, and the analysis of the collected data thereof. The package will be further extended in the future to include direct support of other multiplexing instruments, prediction of spurions, experimental planning tools, advanced fitting tools, and resolution and absorption calculations. We anticipate MJOLNIR to greatly benefit users of multiplexing triple-axis instruments.

Conflict of Interest
We wish to confirm that there are no known conflicts of interest associated with this publication.