src.scattering module#

Simulation of pi- p interactions in a polyethylene target.

Simulate the first interaction depth and channel choice of incoming pi- particles in a polyethylene target of varying thickness L. Produces plots comparing Monte Carlo results to analytical expectations for:

  • Accepted interaction counts vs target length L.

  • Rare channel counts meson n -> 2 gamma with Garwood confidence intervals.

  • Histogram of first interaction depths x for a fixed target length L, compared to the expected truncated exponential distribution.

class src.scattering.CrossSections[source]#

Bases: object

Static container for cross sections and derived quantities.

SIGMA_TOT_CM2 = 2.5e-26#
SIGMA_PI0_CM2 = 3.2e-30#
SIGMA_ETA_CM2 = 3.3e-31#
DENSITY_G_CM3 = 0.93#
MOLAR_MASS = 14.0#
NR_PROTONS = 2.0#
static lambda_cm()[source]#

Compute the mean free path lambda in the target material.

Returns:

float – Mean free path in cm.

static channel_probabilities()[source]#

Interaction channel probabilities from cross-section ratios.

Returns:

dict – Dictionary with keys: ‘pi0n’, ‘etan_2g’, ‘other’.

src.scattering.sample_depth(rng, size)[source]#

Sample first interaction depth using inverse CDF.

Parameters:
  • rng (numpy.random.Generator) – Random number generator (seeded once in main).

  • size (int) – Number of samples.

Returns:

x_cm (numpy.ndarray) – Sampled depths in cm.

src.scattering.expected_prob(L_cm)[source]#

Compute the expected probability to have the first interaction.

Parameters:

L_cm (float) – Target length in cm.

Returns:

p_acc (float) – Probability of acceptance.

src.scattering.sample_channels(rng, n)[source]#

Sample interaction channels for accepted events.

Parameters:
  • rng (numpy.random.Generator) – Random number generator (same instance used everywhere).

  • n (int) – Number of accepted events.

Returns:

channels (numpy.ndarray) – Array of channel labels of length n.

src.scattering.run_length_scan(rng, lengths_cm, n_events)[source]#

Run the simulation for a scan of target lengths.

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

  • lengths_cm (numpy.ndarray) – Array of target lengths (cm).

  • n_events (int) – Number of trials per target length.

Returns:

results (dict) – Dictionary containing arrays of results vs length.

src.scattering.plot_accepted_mc_vs_expected(results, n_events)[source]#

Plot accepted counts: MC vs expected with binomial errors.

Parameters:
  • results (dict) – Output of run_length_scan.

  • n_events (int) – Number of trials per target length.

src.scattering.plot_linearity(results, n_events)[source]#

Plot accepted counts: MC vs expected with binomial errors.

Parameters:
  • results (dict) – Output of run_length_scan.

  • n_events (int) – Number of trials per target length.

src.scattering.poisson_garwood_interval(n, cl=0.68)[source]#

Garwood confidence interval for Poisson mean mu, given observed n.

Parameters:
  • n (array-like or scalar) – Observed counts (>=0).

  • cl (float) – Confidence level, e.g. 0.68 or 0.90.

Returns:

low, up (np.ndarray) – Lower and upper limits for the Poisson mean mu.

src.scattering.plot_rare_channels(results, cl=0.68)[source]#

Plot rare channels (pi0, eta) with Garwood confidence intervals.

Parameters:
  • results (dict) – Output of run_length_scan.

  • cl (float) – Confidence level for Garwood interval (e.g. 0.68 or 0.90).

src.scattering.plot_depth_histogram(rng, L_cm, n_samples, n_bins)[source]#

Plot the histogram of accepted depths x, compare to truncated exponential.

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

  • L_cm (float) – Target length used for the depth histogram.

  • n_samples (int) – Number of sampled depths.

  • n_bins (int) – Number of histogram bins.

src.scattering.main(linear_approx=False)[source]#

Execute the main workflow.

  • Create a single RNG with a fixed seed.

  • Run the scan over target lengths.

  • Produce the requested plots.

Parameters:

linear_approx (bool) – If True, run only the linear approximation lengths.