root_mcp.extended.analysis.fitting module
Histogram fitting engine for ROOT-MCP extended mode.
Provides least-squares curve fitting via scipy.optimize.curve_fit
for a registry of physics-motivated models:
Gaussian — symmetric peaks (resonances, detector resolutions)
Exponential — falling backgrounds
Polynomial (linear, quadratic, cubic) — smooth backgrounds
Crystal Ball — asymmetric peaks with a power-law tail (common in HEP)
Double Gaussian — overlapping resonances
Voigt — convolution of Gaussian detector resolution and Lorentzian natural width
Breit-Wigner — resonance line shape
The public entry point is HistogramFitter.
- class root_mcp.extended.analysis.fitting.CompositeModel(components)[source]
Bases:
objectRepresents a sum of multiple models.
- class root_mcp.extended.analysis.fitting.CustomModel(expr, params)[source]
Bases:
objectModel defined by a string expression.
- class root_mcp.extended.analysis.fitting.ModelInfo[source]
Bases:
TypedDictType definition for model registry entries.
- root_mcp.extended.analysis.fitting.crystal_ball(x, amp, mu, sigma, alpha, n)[source]
Crystal Ball function.
- root_mcp.extended.analysis.fitting.fit_histogram(data, model, initial_guess=None, bounds=None, fixed_parameters=None)[source]
Fit a model to histogram data.
- Parameters:
model (str | list[str | dict[str, Any]] | dict[str, Any]) – Model definition. Can be: - str: Name of built-in model (e.g., “gaussian”) - list[str]: List of built-in models (e.g., [“gaussian”, “exponential”]) - list[dict]: List of models with config (e.g.,
[{"name": "gaussian", "prefix": "s_"}]) - dict: Custom model definition (e.g. {“expr”: “A*x + B”, “params”: [“A”, “B”]})initial_guess (list[float] | None) – Initial parameter values
bounds (list[list[float]] | None) – List of [min, max] pairs for each parameter. Use [-np.inf, np.inf] for no bound.
fixed_parameters (dict[str | int, float] | None) – Dictionary of parameters to fix. Keys can be index (int) or name (str).
- Returns:
Dictionary with fitted parameters, errors, and stats
- Return type:
- root_mcp.extended.analysis.fitting.fit_histogram_2d(x, y, z, z_errors=None, model='gaussian_2d', initial_params=None, fixed_params=None, bounds=None)[source]
Fit a 2D histogram with a model function.
- Parameters:
x (ndarray) – X-coordinate array (flattened)
y (ndarray) – Y-coordinate array (flattened)
z (ndarray) – Z-values (bin contents, flattened)
z_errors (ndarray | None) – Errors on z-values
model (str) – Model name from MODEL_REGISTRY_2D
initial_params (list[float] | None) – Initial parameter guesses
fixed_params (dict[str, float] | None) – Dictionary of {param_name: value} for fixed parameters
bounds (tuple[list[float], list[float]] | None) – Tuple of (lower_bounds, upper_bounds)
- Returns:
Dictionary with fit results
- Return type:
- root_mcp.extended.analysis.fitting.gaussian_2d(xy, amp, mu_x, mu_y, sigma_x, sigma_y, rho=0.0)[source]
2D Gaussian function with correlation.
- Parameters:
- Returns:
Function values at (x, y) points
- Return type: