Skip to main content

A package for reweighting MC samples to match data

Project description

mcreweight

mcreweight is a python library to perform Monte Carlo event reweighting based on multiplicity and kinematic variables. The tool is using GBReweighter, a classifier-based method implemented in hep_ml package, and it supports automated hyperparameter tuning with Optuna. A folding approach over the reweighter is also applied, and performances are compared with the ones from the bins reweighting.

[!WARNING] Bins reweighting works fine for one or two dimensional histograms, but it is unstable and inaccurate for higher dimenstions

Requirements

  • Python 3.8+
  • Required packages listed in requirements.txt

Setup

If you run in a lb-conda environment, as

lb-conda default

consider exporting the PATH to run scripts/run_reweighting.py and scripts/apply_weights.py with commands run-reweight and apply-weights. In this case, use

export PATH=$PATH:/path/to/.local/bin

Installation

From PyPl

pip install mcreweight

From Gitlab

git clone https://github.com/tfulghes/mcreweight.git
cd mcreweight
pip install -e .

You may need the following dependencies:

pip install -r requirements.txt

Usage

To run the reweighting:

run-reweight --path_data <path_to_data.root> \
    	     --path_mc <path_to_mc.root> \
    	     --vars <variable_list> \
    	     --sample <sample> \
    	     --trials <optuna_tests> \
    	     --test_size <test_sample_size>

To apply the weights to the signal MC:

apply-weights --path_mc <path_to_mc.root> \
    	      --vars <variable_list> \
    	      --sample <sample> \
    	      --method <method_for_reweighter>

Options

For the reweighting:

  • --path_data: Path to the ROOT file containing real data events.
  • --path_mc: Path to the ROOT file containing Monte Carlo events.
  • --vars: List of variables to use for reweighting.
  • --sample: Name of the sample to process (used for output naming and selection).
  • --sweights_name: Name of sweights branch in the data
  • --trials: Number of Optuna optimization trials for hyperparameter tuning.
  • --test_size: Fraction of events to use as the test set (e.g., 0.3 for 30%).
  • --n_folds: Number of folds for the k-folding reweighting
  • --n_bins: Number of bins for binning reweighting
  • --n_neighs: Number of nearest neighbors for binning reweighting

Additional options can be found by running:

run-reweight --help

For the application of the weights:

  • --path_mc: Path to the MC ROOT file to which weights will be applied.
  • --vars: List of variables in MC to use for reweighting.
  • --training_vars: List of variables used for the training.
  • --sample: Name of the sample to process.
  • --method: Reweighting method to use (e.g., gbreweighter, kfolding or binning).

Additional options can be found by running:

apply-weights --help

Example

Reweighting:

run-reweight --path_data data/control_sample_tuple.root \
    	     --path_mc mc/control_sample_tuple.root \
    	     --vars B_DTF_Jpsi_P B_DTF_Jpsi_PT nLongTracks nPVs \
    	     --sample bd_jpsikst_ee \
    	     --trials 25 \
    	     --test_size 0.3 

Application of the weights:

apply_weights --path_mc mc/signal_tuple.root \
    	      --vars B_P B_PT nLongTracks nPVs  \
    	      --training_vars B_DTF_Jpsi_P B_DTF_Jpsi_PT nLongTracks nPVs  \
	      --sample bd_jpsikst_ee\
    	      --method gbreweighter

Contact

For questions, please contact the repository maintainer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcreweight-0.1.1.tar.gz (47.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcreweight-0.1.1-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

Details for the file mcreweight-0.1.1.tar.gz.

File metadata

  • Download URL: mcreweight-0.1.1.tar.gz
  • Upload date:
  • Size: 47.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mcreweight-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fe3060f614886b8371081ae8e009829e827a2c3dd7ace404197519dd0bba7930
MD5 c2ad73733f39f128adf3c7ae58fad279
BLAKE2b-256 c315647b3a11d180c62eb0b82f9bc6aa8e2234c6a51a9df3b8593a02240dd083

See more details on using hashes here.

File details

Details for the file mcreweight-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mcreweight-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 38.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mcreweight-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dde59a69ff97328c47f69d0a0df9d149467984a913e36099c0880dd3fbea45d1
MD5 f1e7daa641964143d83372aed3f4a870
BLAKE2b-256 d4241518201e35dfa455782b79876080f5627e97429ce525a3ec5a8b82810c82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page