bin+lib cres

Cell resampling for collider events

8 releases

Uses new Rust 2021

new 0.3.2 Nov 24, 2021
0.3.1 Nov 12, 2021
0.2.3 Nov 11, 2021
0.2.2 Sep 28, 2021
0.1.1 Aug 18, 2021

#90 in Science

Download history 38/week @ 2021-08-16 10/week @ 2021-08-23 3/week @ 2021-09-13 16/week @ 2021-09-27 7/week @ 2021-10-04 8/week @ 2021-10-11 52/week @ 2021-11-08 18/week @ 2021-11-15 21/week @ 2021-11-22

91 downloads per month


2.5K SLoC


This crate implements the cell resampling algorithm for the elimination of negative weights in Monte Carlo collider event samples. The algorithm is described in

Unbiased Elimination of Negative Weights in Monte Carlo Samples
J. Andersen, A. Maier


If Rust and Cargo are installed on your system, run

cargo install cres

Precompiled executables are available on hepforge.


The basic usage is


This takes a file IN.HEPMC2 in hepmc2 format with mixed-weight events and produces a file OUT.HEPMC2 where all event weights are positive. The input file can be compressed with bzip2, gzip, zstd, or lz4.

We recommend to set the jet algorithm JETALGO, jet radius JETR, and minimum jet transverse momentum JETPT to the same values that were used to generate the input events. The supported jet algorithms are anti-kt, kt, and Cambridge-Aachen.

cres assumes that the total cross section is given by the sum of all event weights. If this is not the case one should pass a normalisation factor via the --weight-norm option.


To see a full list of options with short descriptions run

cres --help

The most important options are

  • --max-cell-size can be used to limit the size of the generated cells. This ensures that weights are only transferred between events which are sufficiently similar. The downside is that not all negative event weights will be removed. If you use this option, we recommend values that are not too much smaller than the median radius that cres shows during a standard run.

  • --ptweight specifies how much transverse momenta affect distances between particles with momenta p and q according to the formula

    d(p, q) = \sqrt{ ptweight^2 (p_\perp - q_\perp)^2 + \sum (p_i - q_i)^2 }
  • --strategy sets the order in which cell seeds are selected. The chosen strategy can affect generation times and cell sizes significantly. It is not clear which strategy is best in general.

  • With --minweight events are also unweighted in addition to the resampling. Events with weight w < minweight are discarded with probability 1-|w|/minweight and reweighted to sign(w) * minweight otherwise. Finally, all event weights are rescaled to exactly preserve the original sum of weights. The seed for unweighting can be chosen with the --seed option.

Environment variables

The CRES_LOG environment variable allows fine-grained control over the command line output. For example, to see the debugging output of the jet clustering, set


See the env_logger crate for a comprehensive documentation.

By default, cres uses all available cores. For small event samples, limiting the number of threads can be faster. You can set the number of threads with the RAYON_NUM_THREADS environment variable.

Use as a library

For full flexibility like custom distance functions cres can be used as a library from Rust and C. For examples, see the examples subdirectory. The Rust API is documented on docs.rs. The C API is still limited and only available on unixoid platforms.


~258K SLoC