src.optimize_target module#

Optimize target thickness for neutral meson reconstruction.

Scan different target lengths L: fit the meson peaks in the m(gg) histograms, and extract relevant metrics such as mass resolution, reconstruction efficiency, signal/background estimates, and significance. Use Poisson bootstrap to estimate uncertainties on these quantities. Also provide functions to plot the oversampled background histograms, normalized m(gg) spectra overlays, and the scan results.

src.optimize_target.compute_window_counts(h, m0, sigma, nsig=2.0)[source]#

Integrate histogram counts in a +/- nsig*sigma window around m0.

Parameters:
  • h (ROOT.TH1) – Histogram (possibly weighted).

  • m0 (float) – Window center in GeV.

  • sigma (float) – Window half-width is nsig*sigma (GeV).

  • nsig (float) – Number of sigmas for the half-window.

Returns:

out (dict) – Keys:

  • nfloat

    Integral in the window.

  • errfloat

    Statistical uncertainty from Sumw2.

  • low, highfloat

    Window bounds.

  • b1, b2int

    Bin indices used (inclusive).

src.optimize_target.fit_meson_peak(h, m_meson, L, k_range=2, n_iter=2, do_plot=False, suffix=None)[source]#

Fit the meson peak and plot the results.

Fit the m(gg) histogram h with a Gaussian in the range mu ± k_range*sigma, iterating n_iter times to refine mu and sigma. This is meant to be used on signal-only (forced) spectra to extract the intrinsic mass resolution vs target thickness L.

Parameters:
  • h (ROOT.TH1) – Histogram of m(gg), possibly weighted. Sumw2() should be enabled.

  • m_meson (float) – Meson mass to fit (M_PI0 or M_ETA).

  • L (float) – Target thickness (cm).

  • k_range (float) – Fit range is mu ± k_range*sigma.

  • n_iter (int) – Number of fit iterations to refine mu and sigma.

  • do_plot (bool) – If True, create and save a plot of the fit.

  • suffix (str or None) – Optional suffix for output files.

Returns:

out (dict) – Fit results. Keys: - ok : bool - mu, mu_err : float - sigma, sigma_err : float - chi2, ndf : float, int - fit_range : (float, float) - f : ROOT.TF1 (the fitted function) or None

src.optimize_target.make_poisson_bootstrap_hist(h, rng)[source]#

Create a Poisson bootstrap replica of an unweighted histogram.

For each bin i: n_i* ~ Poisson(n_i).

Parameters:
  • h (ROOT.TH1) – Input histogram (unweighted).

  • rng (numpy.random.Generator) – Random number generator.

src.optimize_target.compute_significance(S, B, kind='simple')[source]#

Compute significance from expected signal/background yields.

Parameters:
  • S (float) – Expected yields in the chosen mass window.

  • B (float) – Expected yields in the chosen mass window.

  • kind (str) – “simple”: S/sqrt(S+B) “asymptotic”: Asimov approximation (recommended)

Returns:

Z (float) – Significance.

src.optimize_target.load_histograms(suffix=None)[source]#

Load oversampled histograms and metadata from file.

Parameters:

suffix (str or None) – Optional suffix for input files.

Returns:

  • histogram_list (list of dict) – Each dict has keys: - h_bkg : ROOT.TH1 - h_pi0 : ROOT.TH1 - h_eta : ROOT.TH1

  • meta_bkg, meta_pi0, meta_eta (dict) – Metadata for background, pi0, and eta.

src.optimize_target.plot_oversampled_background(suffix=None)[source]#

Plot oversampled background histograms for each target thickness.

Parameters:

suffix (str or None) – Optional suffix for output files.

src.optimize_target.plot_normalized_histograms(suffix=None, logy=False)[source]#

Overlay normalized m(gg) histograms for pi0, eta, and background.

For each target thickness L, overlay the normalized m(gg) histograms for pi0, eta, and background on the same plot. Normalization is done to unit area (Integral over all bins).

Parameters:
  • suffix (str or None) – Optional suffix for input/output files.

  • logy (bool) – If True, use log scale on y axis (useful to compare tails).

src.optimize_target.scan_target_length(suffix=None, rng=None, n_boot=100)[source]#

Scan target thickness and compute efficiencies and significances.

To each target thickness L, compute:

  • Fitted mass resolution on signal-only spectra.

  • Counts in adaptive +/- nsig*sigma window.

  • Reconstruction efficiencies for pi0, eta, and background in the window.

  • Signal (S), background (B), and significance (Z) for pi0 and eta in the window.

Use Poisson bootstrap to estimate uncertainties on S, B, Z, and sigma.

Parameters:
  • suffix (str or None) – Optional suffix for input files.

  • rng (numpy.random.Generator) – Random number generator for Poisson bootstrap (if enabled).

  • n_boot (int) – Number of bootstrap replicas to perform.

Returns:

results (dict) – Keys:

  • L_values : array of float

  • eff_pi0, eff_eta, eff_bkgarray of float

    Reconstruction efficiencies.

  • S_pi0, B_pi0, Z_pi0array of float

    Metrics for pi0.

  • S_eta, B_eta, Z_etaarray of float

    Metrics for eta.

  • sigma_pi0, sigma_pi0_errarray of float

    Mass resolution and uncertainty for pi0 (MeV).

  • sigma_eta, sigma_eta_errarray of float

    Mass resolution and uncertainty for eta (MeV).

src.optimize_target.plot_significance(meson='pi0', suffix=None)[source]#

Plot significance, signal, and background after scan.

Plot those metrics vs target thickness L, with error bars from Poisson bootstrap and visualize relative uncertainties.

Parameters:
  • results (dict) – Output dictionary from scan_target_length().

  • meson (str) – “pi0” or “eta”.

  • suffix (str or None) – Optional suffix for output files.

src.optimize_target.plot_sigma(meson='pi0', suffix=None)[source]#

Plot mass resolution and efficiency vs target thickness after scan.

Mass resolution error bars are from Poisson bootstrap, efficiency error bars are binomial.

Parameters:
  • results (dict) – Output dictionary from scan_target_length().

  • meson (str) – “pi0” or “eta”.

  • suffix (str or None) – Optional suffix for output files.

src.optimize_target.main()[source]#

Execute the main function to parse arguments and run scan/plot.

CLI Parameters#

–scanbool

Perform the target length scan and save results in a file.

–plotbool

Plot the significance and mass resolution results after scanning, loading from file.

–plot_bkgbool

Plot only the background histograms for the each target length.

–plot_normalizedbool

Plot the normalized signal and background histograms for each target length.

–suffixstr or None

Optional suffix for input/output files.

–mesonstr

Meson to plot results for (pi0 and/or eta).