|
SND@LHC Software
|
Classes | |
| class | FluxReweighter |
Functions | |
| tqdm (x, **kwargs) | |
| load_analysis_config (path) | |
| resolve_normalization (norm, number_files, target_luminosity=68.6, luminosity_per_file=100.0) | |
| build_fastsim_curves (fastsim_configs, reference, degree) | |
| dpm_file_list (data_dir, n_files, pattern, indexed=True) | |
| build_chain (files, tree_name="cbmsim") | |
| _incoming_neutrino_energy (tree, pids) | |
| get_energies_pyroot (files, flavour="mu", tree_name="cbmsim", n_events=None) | |
| _find_mctrack_branches (tree) | |
| get_energies_uproot (files, flavour="mu", tree_name="cbmsim", n_events=None) | |
| read_dpm_energies (ri, reader="auto") | |
| make_comparison_plot (dpm, curves, normalized_factor, outfile, bins=100, hist_range=(0, 2000), title=None) | |
| fastsim_entries_from_args (paths) | |
| main () | |
Variables | |
| ROOT = None | |
| uproot = None | |
| ak = None | |
| dict | NU_PID = {"e": 12, "mu": 14, "tau": 16} |
| list | DEFAULT_COLORS = ["tab:blue", "tab:red", "tab:green", "tab:orange", "tab:purple"] |
| list | DEFAULT_STYLES = ["--", "-.", ":"] |
Neutrino-flux reweighting and energy-distribution comparison for SND@LHC.
Overview
--------
Hadron-production models disagree about the neutrino flux reaching SND@LHC.
This module derives an energy-dependent weight w(E) that maps one model onto
another, and applies it to a simulated sample.
w(E) = flux_fastsim(E) / flux_DPMJET(E)
where each flux is the sum of a light-hadron (pi/K) and a heavy-flavour
(charm) contribution:
flux_DPMJET = light_DPMJET + charm_DPMJET (the reference / denominator)
flux_fastsim = light_EPOS + charm_POWHEG (the target / numerator)
Multiplying every DPMJET event by w(E) therefore reproduces the fast-sim
prediction, without re-running the simulation:
DPMJET x w(E) == fast-sim (light + charm)
Two capabilities
----------------
1. ``FluxReweighter`` -- builds the ratio from the flux text files, fits a
polynomial w(E), and writes a diagnostic plot per polynomial degree.
2. ``main()`` in "compare" mode -- reads neutrino energies straight from
SND@LHC ROOT files (``cbmsim`` tree), applies w(E), and overlays the
DPMJET reference with each reweighted fast-sim prediction.
Inputs
------
Flux text files: whitespace-separated, one neutrino per row, no header, with
the columns listed in ``FluxReweighter.COLS``. POWHEG files carry one extra
trailing column (``iEvent``).
ROOT files: standard SND@LHC digitised output holding the ``cbmsim`` tree with
the ``MCTrack`` branch, from which the incoming (primary) neutrino energy is
taken.
Configuration
-------------
Every input is read from YAML; nothing analysis-specific is hard-coded.
Analysis.yaml run settings: ROOT input, which fast-sim variants to
overlay, normalisation, plot styling
Config_epos.yaml one per fast-sim variant: flux file paths, flavour,
binning, fit range, cuts, weights, output label
Usage
-----
# diagnostic ratio-fit plots for one or more reweighter configs
python3 reweighting_function.py -m reweight -rc Config_epos.yaml
# full comparison: fit w(E), read ROOT energies, overlay and save
python3 reweighting_function.py -c Analysis.yaml -rc Config_epos.yaml
# everything taken from the run YAML, no extra arguments
python3 reweighting_function.py -c Analysis.yaml
As a library:
from reweighting_function import FluxReweighter
poly, chi2red = FluxReweighter("Config_epos.yaml").fit(degree=2)
weights = poly(energies) # w(E) evaluated per event
|
protected |
Locate the MCTrack member branches whatever the exact prefix is. Different productions store them as ``MCTrack.fPdgCode``, ``MCTrack/fPdgCode`` and so on, so the names are matched by suffix. Returns a dict mapping the member name to the branch key found.
Definition at line 732 of file reweighting_function.py.
|
protected |
Energy of the primary neutrino in the current entry, or None. The incoming neutrino is the MCTrack whose |pdg| matches the requested flavour and which has no mother (MotherId == -1).
Definition at line 699 of file reweighting_function.py.
| reweighting_function.build_chain | ( | files, | |
tree_name = "cbmsim" |
|||
| ) |
Chain the given ROOT files into one TChain (pyROOT only).
Definition at line 689 of file reweighting_function.py.
| reweighting_function.build_fastsim_curves | ( | fastsim_configs, | |
| reference, | |||
| degree | |||
| ) |
Fit w(E) for each fast-sim variant and assemble the curves to draw. One ``FluxReweighter`` is run per config, so the weights come from the fit and are never hard-coded. The fitted coefficients and chi2/ndf are printed for the record, and each curve is labelled from its own config. Returns a list of ``(label, weight_poly | None, color, linestyle)`` with the unweighted DPMJET reference (``weight_poly`` None) first.
Definition at line 647 of file reweighting_function.py.
| reweighting_function.dpm_file_list | ( | data_dir, | |
| n_files, | |||
| pattern, | |||
indexed = True |
|||
| ) |
Build the list of ROOT files to read. ``indexed=True`` expects the per-job layout ``<data_dir>/<i>/<pattern>`` for i in range(n_files); ``indexed=False`` a single merged file at ``<data_dir>/<pattern>``.
Definition at line 677 of file reweighting_function.py.
| reweighting_function.fastsim_entries_from_args | ( | paths | ) |
Turn bare config paths from ``-rc`` into styled fast-sim entries.
Definition at line 885 of file reweighting_function.py.
| reweighting_function.get_energies_pyroot | ( | files, | |
flavour = "mu", |
|||
tree_name = "cbmsim", |
|||
n_events = None |
|||
| ) |
Read per-event neutrino energies [GeV] with pyROOT. Loops the chained ``cbmsim`` tree entry by entry. Returns a 1-D array with one energy per event that contains a matching primary neutrino.
Definition at line 711 of file reweighting_function.py.
| reweighting_function.get_energies_uproot | ( | files, | |
flavour = "mu", |
|||
tree_name = "cbmsim", |
|||
n_events = None |
|||
| ) |
Read per-event neutrino energies [GeV] with uproot, without ROOT. Selects the incoming neutrino (|pdg| matching the flavour, fMotherId == -1) and, neutrinos being effectively massless, takes E = |p|. Unreadable files are skipped with a message.
Definition at line 750 of file reweighting_function.py.
| reweighting_function.load_analysis_config | ( | path | ) |
Load the top-level run YAML (Analysis.yaml) into a dict.
Definition at line 622 of file reweighting_function.py.
| reweighting_function.main | ( | ) |
Parse the command line and run the requested mode.
Modes
-----
reweight : fit each reweighter config and save its diagnostic plots. Needs
no run YAML when both ``-m reweight`` and ``-rc`` are given.
compare : fit w(E), read the DPMJET energies from ROOT, and save the
overlay. Needs the run YAML for the ROOT input and plot settings.
Command-line options override the corresponding run-YAML fields; anything
not given falls back to the YAML.
Definition at line 893 of file reweighting_function.py.
| reweighting_function.make_comparison_plot | ( | dpm, | |
| curves, | |||
| normalized_factor, | |||
| outfile, | |||
bins = 100, |
|||
hist_range = (0, 2000), |
|||
title = None |
|||
| ) |
Overlay the DPMJET energy spectrum with each reweighted fast-sim curve.
The same array of DPMJET energies is histogrammed once per curve. The
reference is unweighted; every other curve applies its w(E) per event, so
``DPMJET x w(E)`` is the fast-sim prediction. The binning here is
independent of the binning used to derive w(E): the weight is evaluated
from the polynomial at each event's energy, not looked up by bin.
The integral quoted in each legend entry is the normalised area under the
histogram, i.e. the expected yield at the target luminosity.
Returns a dict of ``{label: integral}``.
Definition at line 820 of file reweighting_function.py.
| reweighting_function.read_dpm_energies | ( | ri, | |
reader = "auto" |
|||
| ) |
Read the DPMJET neutrino energies using the requested ROOT backend. ``ri`` is the ``root_input`` block of the run YAML. ``reader`` is "auto" (pyROOT when importable, else uproot), "pyroot" or "uproot".
Definition at line 792 of file reweighting_function.py.
| reweighting_function.resolve_normalization | ( | norm, | |
| number_files, | |||
target_luminosity = 68.6, |
|||
luminosity_per_file = 100.0 |
|||
| ) |
Return the factor scaling the simulated sample to the target luminosity.
The automatic value is the luminosity ratio L_data / L_MC,
target_luminosity / (number_files * luminosity_per_file)
with each input file representing ``luminosity_per_file`` [fb^-1] and
``number_files`` of them merged. Passing a number instead of ``"auto"``
uses it verbatim; ``"auto"`` or a non-positive value uses the formula.
Definition at line 628 of file reweighting_function.py.
| reweighting_function.tqdm | ( | x, | |
| ** | kwargs | ||
| ) |
Definition at line 100 of file reweighting_function.py.
| reweighting_function.ak = None |
Definition at line 95 of file reweighting_function.py.
| list reweighting_function.DEFAULT_COLORS = ["tab:blue", "tab:red", "tab:green", "tab:orange", "tab:purple"] |
Definition at line 881 of file reweighting_function.py.
| list reweighting_function.DEFAULT_STYLES = ["--", "-.", ":"] |
Definition at line 882 of file reweighting_function.py.
| dict reweighting_function.NU_PID = {"e": 12, "mu": 14, "tau": 16} |
Definition at line 619 of file reweighting_function.py.
| reweighting_function.ROOT = None |
Definition at line 84 of file reweighting_function.py.
| reweighting_function.uproot = None |
Definition at line 91 of file reweighting_function.py.