Adaptive phase space max weight#
Introduction#
TFPhaseSpaceGenerator produces phase space samples with phasespace. That package generates weighted events, so the generator turns them into unweighted events with a hit-and-miss step: an event is kept if a uniform random number is below its weight. By default, the random numbers are drawn up to \(1\), the upper bound of the normalized weights that phasespace guarantees. tensorwaves#604 adds an adaptive_max_weight option that draws them up to an estimate of the maximum weight instead: the largest weight seen so far plus a margin of 5%. If a later bunch contains a larger weight, the estimate is raised and the sample is generated anew, so that the result remains unbiased.
This report quantifies how much faster the option is and checks that it produces the same distributions as the default setting.
Weight distributions#
The following plots illustrate this for a \(5\,\mathrm{GeV}\) particle that decays into an increasing number of pions. The left panel shows the weight distributions relative to the largest weight in each sample. The right panel shows the fraction of events that survive the hit-and-miss step: with the default setting, this is the mean weight, while with adaptive_max_weight=True it is the mean weight divided by the estimated maximum.
The shape of the weight distribution relative to its maximum changes only moderately with more particles, but the mean weight relative to the bound of \(1\) drops by several orders of magnitude. With the estimated maximum, the fraction of accepted events stays above 10%.
Speed#
The gain grows with the number of final state particles, because the spread of the weights grows with it. The following table times both settings for 10,000 events of a \(5\,\mathrm{GeV}\) particle that decays into an increasing number of pions. The timings depend on the machine that executed this report.
| Ā | Default | adaptive_max_weight=True | Speed-up |
|---|---|---|---|
| Pions | Ā | Ā | Ā |
| 3 | 0.47 s | 0.84 s | 0.6x |
| 4 | 0.76 s | 0.73 s | 1.0x |
| 5 | 1.97 s | 1.06 s | 1.8x |
| 6 | 16.40 s | 1.14 s | 14.3x |
For three particles, a single bunch of 50,000 events already contains enough accepted events, so both settings take about equally long. For more particles, the default setting needs many more bunches.
Generated distributions#
We now generate a large sample of the three-body decay with both settings. The events differ, because the hit-and-miss step consumes the random numbers differently, but both samples should be distributed uniformly over phase space. The Dalitz plots show this: the events fill the kinematically allowed region evenly with both settings.
initial_state_mass = 3.0969
final_state_masses = {0: 0.1350, 1: 0.1396, 2: 0.4937}
default_generator = TFPhaseSpaceGenerator(initial_state_mass, final_state_masses)
adaptive_generator = TFPhaseSpaceGenerator(
initial_state_mass, final_state_masses, adaptive_max_weight=True
)
size = 500_000
default_generator.show_progress = False
adaptive_generator.show_progress = False
samples = {
"Default": default_generator.generate(size, TFUniformRealNumberGenerator(seed=0)),
"adaptive_max_weight=True": adaptive_generator.generate(
size, TFUniformRealNumberGenerator(seed=0)
),
}
Projections#
Overlaying the projections of both samples shows that they agree within statistical fluctuations. The lower panels show the difference per bin, divided by its statistical uncertainty. These pulls should scatter around zero with a spread of about one.
A two-sample KolmogorovāSmirnov test quantifies this. A \(p\)-value well above a typical threshold such as \(0.05\) means that the test finds no evidence that the two samples come from different distributions. The table also lists the means and standard deviations, which agree to the precision expected for this sample size.
pd.DataFrame({
key: {
"Mean (default)": default[key].mean(),
"Mean (adaptive)": adaptive[key].mean(),
"Std (default)": default[key].std(),
"Std (adaptive)": adaptive[key].std(),
"KS p-value": ks_2samp(default[key], adaptive[key]).pvalue,
}
for key in labels
}).T.style.format("{:.4f}")
| Ā | Mean (default) | Mean (adaptive) | Std (default) | Std (adaptive) | KS p-value |
|---|---|---|---|---|---|
| m12 | 2.6645 | 2.6621 | 1.7040 | 1.7020 | 0.8405 |
| m23 | 3.6098 | 3.6095 | 2.0327 | 2.0324 | 0.9992 |
| m13 | 3.5979 | 3.6006 | 2.0284 | 2.0273 | 0.8717 |
| cos_theta | -0.0010 | -0.0021 | 0.5773 | 0.5771 | 0.9184 |
Five-pion decay#
The same holds for decays into more particles, where the option makes the biggest difference. The comparison below repeats the test for a five-pion decay, using the invariant mass of each pair of neighboring pions.
Conclusion#
With adaptive_max_weight=True, the hit-and-miss step accepts more than 10% of the events for any number of pions, while the default setting accepts orders of magnitude fewer events for five or more pions. The samples that the two settings generate agree within statistical fluctuations. A small bunch_size makes the estimate of the maximum weight less accurate and leads to more restarts, so the option works best with the default bunch size.