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

User and Programmers Guide to the Neutron Ray-Tracing Package McStas, version 3.8.6

P. Willendrup, E. Farhi, K. Lefmann

September, 2026

The software package McStas is a tool for carrying out Monte Carlo ray-tracing simulations of neutron scattering instruments with high complexity and 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. McStas is based on a unique design where an automatic compilation process translates high-level textual instrument descriptions into efficient ISO-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 McStas, and, together with the manual for the McStas components, it contains documentation of most 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 McStas version 3.8.6, released September, 2026

The authors are:

Peter Kjær Willendrup <pkwi@fysik.dtu.dk>
Physics Department, Technical University of Denmark, Kongens Lyngby, Denmark

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

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

as well as authors who left the project:

Erik Knudsen <erkn@fysik.dtu.dk>
Physics Department, Technical University of Denmark, Kongens Lyngby, Denmark Jakob Garde <jaga@fysik.dtu.dk>
Physics Department, Technical University of Denmark, Kongens Lyngby, Denmark Jonas Stein <Jonas.Stein@uni-koeln.de>
Institute of Physics II, University of Cologne, Germany Peter Christiansen <pchristi@hep.lu.se>
Materials Research Department, Risø National Laboratory, Roskilde, Denmark
Present address: University of Lund, Lund, Sweden
Klaus Lieutenant <k.lieutenant@fz-juelich.de>
Institut Laue-Langevin, Grenoble, France
Present address: Forschungs-Zentrum Jülich, Germany
Kristian Nielsen <kristian-nielsen@mail.tele.dk>
Materials Research Department, Risø National Laboratory, Roskilde, Denmark
Presently associated with: MySQL AB, Sweden

ISBN 978–87–550–3679–6

ISSN 0106–2840

Physics Department \(\cdot \) DTU \(\cdot \) 2026

Contents
   Preface and acknowledgments
Preface and acknowledgments
1  Introduction to McStas
 1.1  Development of Monte Carlo neutron simulation
 1.2  Scientific background
 1.3  The design of McStas
 1.4  Overview
2  Monte Carlo Techniques and simulation strategy
 2.1  Neutron spectrometer simulations
 2.2  The neutron weight
 2.3  Weight factor transformations during a Monte Carlo choice
 2.4  Adaptive and Stratified sampling
 2.5  Accuracy of Monte Carlo simulations
3  Running McStas
 3.1  Installation and updates
 3.2  Brief introduction to the graphical user interface
 3.3  Running the instrument compiler
 3.4  Running the simulations
 3.5  Using simulation front-ends
 3.6  Data formats - Analyzing and visualizing the simulation results
 3.7  Using MPI for parallel computing
4  The McStas kernel and meta-language
 4.1  Notational conventions
 4.2  Syntactical conventions
 4.3  Writing instrument definitions
 4.4  Writing instrument definitions - complex arrangements and syntax
 4.5  Writing component definitions
 4.6  Extending component definitions
 4.7  McDoc, the McStas library documentation tool
5  Polarisation in McStas
 5.1  The Polarization Vector
 5.2  Polarized Neutron Scattering
 5.3  Magnetic fields: the precession algorithm and field framework
 5.4  Polarisation components in McStas
 5.5  Test and example instruments
6  Links to other computing codes
 6.1  McStas and MANTID
 6.2  McStas and MCNP(X)
7  The component library: Abstract
 7.1  Component categories
 7.2  Data files
 7.3  Component and instrument examples
8  Instrument examples
 8.1  A quick tour of instrument examples
 8.2  A test instrument for the component V_sample
 8.3  The triple axis spectrometer TAS1
 8.4  The time-of-flight spectrometer PRISMA
A  Random numbers in McStas
 A.1  Transformation of random numbers
 A.2  Random generator
B  Libraries and constants
 B.1  Run-time calls and functions (mcstas-r)
 B.2  Reading a data file into a vector/matrix (Table input, read_table-lib)
 B.3  Monitor_nD Library
 B.4  Adaptive importance sampling Library
 B.5  Vitess import/export Library
 B.6  Constants for unit conversion etc.
C  The McStas terminology
   Bibliography
Bibliography
   Index and keywords
Index