User and Programmers’ Guide to the X Ray-Tracing Package McXtrace, version 3.8.6
PIC
Physics Physics Department,
Technical University of Denmark
2800 Kongens Lyngby, Denmark

User and Programmers’ Guide to the X Ray-Tracing Package McXtrace, version 3.8.6

E. B. Knudsen, P. Willendrup, E. Farhi, K. Lefmann, S. Schmidt

September, 2026

The software package McXtrace is a tool for carrying out highly complex Monte Carlo ray-tracing simulations of X-ray beamlines to high precision. The simulations can compute all aspects of the performance of instruments and can thus be used to optimize the use of existing equipment, design new instrumentation, and carry out virtual experiments for e.g. training, experimental planning or data analysis. McXtrace is based is based on a unique design, inhereted from its sister McStas, where an automatic compilation process translates high-level textual instrument descriptions into efficient ANSI-C code. This design makes it simple to set up typical simulations and also gives essentially unlimited freedom to handle more unusual cases.

This report constitutes the reference manual for McXtrace, and, together with the manual for the McXtrace components, it contains full documentation of all aspects of the program. It covers the various ways to compile and run simulations, a description of the meta-language used to define simulations, and some example simulations performed with the program.

This report documents McXtrace version 3.8.6, released September, 2026

The authors are:

Erik B Knudsen <erkn@fysik.dtu.dk>
Physics Department, Technical University of Denmark, Kgs. Lyngby, Denmark.

Peter Kjær Willendrup <peter.willendrup@risoe.dk>
Physics Department, Technical University of Denmark, Kgs. Lyngby, Denmark.

Emmanuel Farhi <emmanuel.farhi@synchrotron-soleil.fr>
Synchrotron SOLEIL, Saint-Aubin, France

Kim Lefmann <lefmann@fys.ku.dk>
Niels Bohr Institute, University of Copenhagen, Denmark

other people connected to the project:

Jana Baltser  <jana.baltser@fys.ku.dk>
Niels Bohr Institute, University of Copenhagen, Denmark

Andrea Prodi  <aprodi@fys.ku.dk>
Niels Bohr Institute, University of Copenhagen, Denmark

Manuel Sanchez del Rio
Computer Science Department, ESRF, Grenbole, France

Claudio Ferrero
Computer Science Department, ESRF, Grenbole, France

Contents
   Preface and acknowledgements
Preface and acknowledgements
1  Introduction to McXtrace
 1.1  Development of Monte Carlo x-ray simulation
 1.2  Scientific background
 1.3  The design of McXtrace
 1.4  Overview
2  New features in McXtrace 3.8.6
 2.1  Kernel
 2.2  Run-time
 2.3  Components and Library
 2.4  Tools, installation
3  Installing McXtrace
4  Monte Carlo Techniques and simulation strategy
 4.1  X-ray simulations
 4.2  The x-ray weight
 4.3  Weight factor transformations during a Monte Carlo choice
 4.4  Stratified sampling
 4.5  Accuracy of Monte Carlo simulations
5  Running McXtrace
 5.1  Brief introduction to the graphical user interface
 5.2  Running the instrument compiler
 5.3  Running the simulations
 5.4  Using simulation front-ends
 5.5  Data formats - Analyzing and visualizing the simulation results
 5.6  Using MPI for parallel computing
6  The McXtrace kernel and meta-language
 6.1  Notational conventions
 6.2  Syntactical conventions
 6.3  Writing instrument definitions
 6.4  Writing instrument definitions - complex arrangements and syntax
 6.5  Writing component definitions
 6.6  Extending component definitions
 6.7  MxDoc, the McXtrace library documentation tool
7  The component library: Abstract
 7.1  Component categories
 7.2  Data files
 7.3  Component and instrument examples
A  Random numbers in McXtrace
 A.1  Transformation of random numbers
 A.2  Random generators
B  Libraries and conversion constants
 B.1  Run-time calls and functions (mcxtrace-r)
 B.2  Reading a data file into a vector/matrix (Table input, read_table-lib)
 B.3  Constants for unit conversion etc.
C  The McXtrace terminology
Bibliography
   Bibliography
   Index and keywords