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
arXiv:2109.07851
Efficient negative-weight elimination in large high-multiplicity Monte Carlo event samples
Jeppe R. Andersen, Andreas Maier, Daniel Maître
arXiv:2303.15246
The current version requires Rust 1.82.0 or later. You can install Rust and Cargo with
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
To install the latest release, run
cargo install cres
Precompiled executables are available on hepforge and github.
To install the development version, run
cargo install --git https://github.com/a-maier/cres
Check the Features section for more options.
To generate shell command completion, run
cres-generate-shell-completions SHELL
For bash and fish, command completion should work upon the next login. For other shells, the completion code is written to standard output. Consult your shell's documentation if you are unsure what to do with it. To list the supported shells, run
cres-generate-shell-completions --help
The basic usage is
cres -a JETALGO -R JETR --jetpt JETPT --max-cell-size R -o OUTDIR EVENTFILES...
This takes a number of input events files in HepMC2 or Les Houches
Event format with mixed-weight events and for each file produces an
output file of the same name inside OUTDIR with a smaller
contribution from negative weights. The input file can be compressed
with bzip2, gzip, zstd, or lz4. The input format is detected
automatically.
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. When including QED corrections,
for instance through a shower, one should also set
--leptonalgorithm, --leptonradius, and --leptonpt.
Setting a maximum cell radius R is optional, but highly
recommended. Lower values lead to much faster resampling and smaller
smearing effects. Larger values eliminate a larger fraction of
negative weights. It is recommended to start with a value between 1
and 10 and adjust as needed.
To see a full list of options with short descriptions run
cres --help
The most important options are
-
--max-cell-sizecan 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.Cell resampling is much faster with a small cell size limit. It is therefore recommended to start with a small value, for example 10, and gradually increase the value if too many negative weights are left.
-
--leptonalgorithm,--leptonradius,--leptonptenable clustering for leptons and photons. These options should be set whenever QED corrections are included, for example through showering. -
--ptweightspecifies how much transverse momenta affect distances between particles with momenta p and q according to the formulad(p, q) = \sqrt{ ptweight^2 (p_\perp - q_\perp)^2 + \sum (p_i - q_i)^2 } -
With
--minweightevents are also unweighted in addition to the resampling. For events with weightw < minweightthe weight is set to zero with probability1-|w|/minweightand tosign(w) * minweightotherwise. Finally, all event weights are rescaled to exactly preserve the original sum of weights. The seed for unweighting can be chosen with the--seedoption.
To avoid cluttering the command line, options can be saved in an argfile. Each line should contain exactly one option, and option name and value have to be separated by '='. For example:
--jetalgorithm=anti-kt
--jetradius=0.4
--jetpt=30
The argfile can be used like this:
cres @argfile -o OUTDIR IN.HEPMC2
Ideally, cres should be run on as many events as possible. Naive
parallelisation over several nodes is discouraged, as the cell
resampling quality will not benefit from higher event statistics.
For very large samples consisting of many smaller subsamples the following work flow is recommended. The following commands assume uncompressed HepMC event files, but other event formats as well as compressed event files are supported as usual.
-
Run
cres-partition @partitionargs -o partition --regions N SUBSAMPLE.HEPMC2on one single subsample, e.g. 10^6 events.
Nis the number of nodes on whichcresshould be later run in parallel.cres-partitionshould be fast and memory-efficient enough to be run on a single node.@partitionargsstands for further command-line arguments, or alternatively for an argument file containing the standardcresoptions needed to define the metric, e.g.--jetalgorithm,--jetradius,--jetpt, and--max-cell-size. -
Using the
partitionfile created in step 1., runcres-classify-events --outdir cres-split -p partition SUBSAMPLE.HEPMC2on each subsample. Each subsample can be treated in parallel. This will split
SUBSAMPLE.HEPMC2intoNpartsSUBSAMPLE.X.HEPMC2. -
For each part
X, runcreson all subsamplescres @argfile SUBSAMPLE0.X.HEPMC2 SUBSAMPLE1.X.HEPMC2 ...Each instance can be run on a separate node.
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
CRES_LOG=jetty=debug,cres=info
See the env_logger crate for a
comprehensive documentation.
By default, cres uses as many cores as possible. For small event
samples, limiting the number of threads can be faster. You can set the
number of threads with the --threads command line option or with the
RAYON_NUM_THREADS environment variable.
To install cres with additional features, add --features name1,name2
to your installation command. Default features don't have to be added
manually. To disable them, add the --no-default-features flag.
-
multiweight: Enables the--weightsoption for treating multiple weights in one run. If you only want to consider a single weight you can disable this feature to save some memory and computing time. -
lhef: Support for reading and writing files in the Les Houches Event format.
-
ntuple: Support for reading and writing ROOT ntuple files. This requires a recent version oflibclangand a ROOT installation withroot-configin the executable path. -
stripper-xml: Experimental support for the XML format used by STRIPPER. -
capi: Enables the C API for usingcresas a C library. For examples, see the examples subdirectory. The API is limited and only available on unixoid platforms. It will be extended on request.
For full flexibility like custom distance functions cres can be used
as a library. For examples, see the
examples
subdirectory. The API is documented on
docs.rs.