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 pyproject.toml

Setup

Run in a lb-conda environment, as

lb-conda mcreweight

Installation

If you don't run in a lb-conda environment, consider installing the python package from PyPI or cloning it from GitLab

From PyPI

pip install mcreweight

From Gitlab

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

Usage

To run the reweighting:

run-reweight --path_data <path_to_data.root> \
    	     --path_mc <path_to_mc.root> \
    	     --vars <variable_list> \
    	     --monitoring_vars <monitoring_variable_list> \
    	     --sample <sample> \
    	     --n_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> \
    	      --training_sample <training_sample> \
    	      --application_sample <application_sample> \
    	      --method <method_for_reweighter> \
    	      --monitoring_vars <monitoring_variable_list> \
    	      --output_path <output_file.root>

Options

For the reweighting (run-reweight):

Input files:

  • --path_data: Path to the data control sample (required)
  • --tree_data: Name of the tree in the data control sample (default: "DecayTree")
  • --path_mc: Path to the MC control sample (required)
  • --tree_mc: Name of the tree in the MC control sample (default: "DecayTree")
  • --mcweights_name: Name of the branch for weights in the MC sample (default: None)
  • --sweights_name: Name of the sweights column in the data (default: "sweight_sig")
  • --mc_label: Label for the MC sample (default: "MC")
  • --data_label: Label for the data sample (default: "Data")

Variables:

  • --vars: List of variables to use for reweighting (default: ["B_DTF_Jpsi_P", "B_DTF_Jpsi_PT", "nLongTracks", "nPVs"])
  • --monitoring_vars: List of variables to plot (default: None)

Reweighter configuration:

  • --sample: Sample name for the dataset (default: "bd_jpsikst_ee")
  • --n_trials: Number of trials for the gradient boosting reweighting (default: 10)
  • --test_size: Proportion of the dataset to include in the test split (default: 0.3)
  • --n_folds: Number of folds for k-folding reweighting (default: 4)
  • --n_bins: Number of bins for binning reweighting (default: 20)
  • --n_neighs: Number of nearest neighbors for binning reweighting (default: 3)

Output:

  • --weightsdir: Directory to save weights (default: "weights")
  • --plotdir: Directory to save plots (default: "plots")

Additional options can be found by running:

run-reweight --help

For the application of the weights (apply-weights):

Input files:

  • --path_mc: Path to the MC signal sample (required)
  • --tree_mc: Name of the tree in the MC signal sample (default: "DecayTree")
  • --mcweights_name: Name of the branch for weights in the output ROOT file (default: None)
  • --path_data: Path to the data sample for comparison (default: None)
  • --tree_data: Name of the tree in the data sample (default: "DecayTree")
  • --sweights_name: Name of the sweights column in the data (default: "sweight_sig")

Variables:

  • --vars: List of variables to use for reweighting (default: ["B_DTF_Jpsi_P", "B_DTF_Jpsi_PT", "nLongTracks", "nPVs"])
  • --training_vars: List of variables used for training (default: ["B_DTF_Jpsi_P", "B_DTF_Jpsi_PT", "nLongTracks", "nPVs"])
  • --monitoring_vars: List of variables to plot (default: None)

Configuration:

  • --training_sample: Sample name for the dataset (default: "bd_jpsikst_ee")
  • --application_sample: Sample name for the application of weights (default: "bd_jpsikst_ee")
  • --method: Method to apply weights (choices: "gbreweighter", "kfolding", "binning", default: "gbreweighter")
  • --weightsdir: Directory to save weights (default: "weights")
  • --plotdir: Directory to save plots (default: "plots")

Output:

  • --output_path: Path to save the output ROOT file (required)
  • --output_tree: Name of the tree in the output ROOT file (default: "DecayTree")

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 \
    	     --monitoring_vars B_ETA nFTClusters nVPClusters nEcalClusters \
    	     --sample bd_jpsikst_ee \
    	     --n_trials 5 \
    	     --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  \
    	      --training_sample bd_jpsikst_ee \
    	      --application_sample bd_jpsikst_ee \
    	      --method gbreweighter \
    	      --monitoring_vars B_ETA nFTClusters nVPClusters nEcalClusters \
    	      --output_path mc/signal_tuple_reweighted.root

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.2.8.tar.gz (53.1 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.2.8-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcreweight-0.2.8.tar.gz
Algorithm Hash digest
SHA256 a8927da82a09a2e20a23e3ee258f4892e77d08a7815a5c920bfbcccbffec9cef
MD5 feb2db78777acea8b335a819de427272
BLAKE2b-256 2f7b1c7ff86053b5560524e140262bd5551d0b5ba141962a3131fa7c008622a0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for mcreweight-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1a5a6949ee62980a818f9394a9a333875c128d3d18ed8416e2712c34405c7cb1
MD5 634565f7d45c606fb60dd57b638d0fe8
BLAKE2b-256 97d8aaf0875dfd8f7ed37c20169bd8a23ab6718da35085fb6a25b040a00c6314

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