diff --git a/docs/source/run_card.rst b/docs/source/run_card.rst index c2630c4280..ad1effbfd2 100644 --- a/docs/source/run_card.rst +++ b/docs/source/run_card.rst @@ -405,7 +405,8 @@ VEGAS grids adapt the phase-space sampling during the survey. ``t_channel`` (``"propagator"``) Parametrization of the t-channel part of the multichannel phase space. ``propagator`` follows the diagram as a chain of :math:`2 \to 2` steps. ``rambo`` applies RAMBO to the - t-channel particles and ``chili`` uses collider coordinates. + t-channel particles and ``chili`` uses collider coordinates. With lepton beams + (``leptonic``) ``chili`` generates the last two particles as a two-body decay. ``flat_mode`` (``"rambo"``) The same choice for the flat channel. diff --git a/madgraph/mg7/madgraph_process.py b/madgraph/mg7/madgraph_process.py index 6f1e3f83db..66adc90dff 100644 --- a/madgraph/mg7/madgraph_process.py +++ b/madgraph/mg7/madgraph_process.py @@ -1108,8 +1108,8 @@ def init_beam(self) -> None: # Monochromatic beams of massive particles (W/Z without EVA, muons of # a model with a muon mass): s and the rapidity of the beams are those # of the massive beam momenta, as madevent's stot (genps.f, lpp = 0), - # not 4 E1 E2, for each subprocess (beam_kinematics). The incoming - # momenta are then put on their mass shell by the Integrand. + # not 4 E1 E2, for each subprocess (beam_kinematics). The phase-space + # mapping then puts the incoming momenta on their mass shells. self.massive_beams = ( self.leptonic and not self.is_decay and not self.eva and not self.upc_flux diff --git a/madgraph/mg7/subprocess_madmatrix.py b/madgraph/mg7/subprocess_madmatrix.py index 6d09433496..5f1a857cd7 100644 --- a/madgraph/mg7/subprocess_madmatrix.py +++ b/madgraph/mg7/subprocess_madmatrix.py @@ -1696,6 +1696,10 @@ def build_integrands( ), eva=eva, eva_helicities=eva_helicities, + # the flux of massive incoming particles, which the + # phase-space mapping puts on their mass shells + incoming_masses=( + [] if self.process.is_decay else self.incoming_masses), ) ) partial_weights = self.process.systematics_enabled() diff --git a/madspace/include/madspace/phasespace/base.hpp b/madspace/include/madspace/phasespace/base.hpp index c2d64a12df..8fa7725bac 100644 --- a/madspace/include/madspace/phasespace/base.hpp +++ b/madspace/include/madspace/phasespace/base.hpp @@ -144,6 +144,19 @@ class Mapping { NamedVector _condition_types; }; +/** + * The absolute masses of the two incoming particles if one of them is massive, + * else an empty vector: the form in which the mappings that build massive + * incoming momenta (@ref TPropagatorMapping, @ref ColorOrderedMapping) keep + * them. + * + * @param masses The incoming masses. + * @param mapping Name of the mapping, for the error raised when a mass is + * nonzero but there are not two of them. + */ +std::vector +massive_incoming_masses(const std::vector& masses, const std::string& mapping); + /** * Base class for compute-graph functions that are not invertible mappings. * diff --git a/madspace/include/madspace/phasespace/chili.hpp b/madspace/include/madspace/phasespace/chili.hpp index 77f9429e54..30adf25d10 100644 --- a/madspace/include/madspace/phasespace/chili.hpp +++ b/madspace/include/madspace/phasespace/chili.hpp @@ -35,10 +35,28 @@ namespace madspace { * [2, 3]). Chili does not guarantee physical configurations, so unphysical * points are removed by a technical cut. * + * With fixed beams (lepton colliders, `fixed_beams`) the incoming momenta add + * up to @f$P = (\sqrt{s}, 0, 0, 0)@f$, and the final state cannot fix them. + * The first @f$n-2@f$ momenta are generated as above, and the last two as the + * two-body decay of what is left, @f$Q = P - \sum_{i& y_max, - const std::vector& pt_min + const std::vector& pt_min, + bool fixed_beams = false ); - /// Number of uniform random inputs consumed by the forward mapping, - /// equal to `3 * n_particles - 2`. - std::size_t random_dim() const { return 3 * _n_particles - 2; } + /// Number of uniform random inputs consumed by the forward mapping: + /// `3 * n_particles - 2`, or `3 * n_particles - 4` with fixed beams. + std::size_t random_dim() const { return 3 * _n_particles - (_fixed_beams ? 4 : 2); } + /// Whether the beams have fixed momenta. + bool fixed_beams() const { return _fixed_beams; } private: Result build_forward_impl( @@ -97,6 +122,7 @@ class ChiliMapping : public Mapping { std::size_t _n_particles; std::vector _y_max; std::vector _pt_min; + bool _fixed_beams; }; } // namespace madspace diff --git a/madspace/include/madspace/phasespace/color_ordered_mapping.hpp b/madspace/include/madspace/phasespace/color_ordered_mapping.hpp index d5519ef4e6..6480ae0c46 100644 --- a/madspace/include/madspace/phasespace/color_ordered_mapping.hpp +++ b/madspace/include/madspace/phasespace/color_ordered_mapping.hpp @@ -46,6 +46,12 @@ namespace madspace { * In addition every mapping returns a `det` (`float`, shape `(batch,)`), the * Jacobian of the transformation. * + * With massive incoming particles (see the constructor) the beams are built on + * their mass shells in the partonic centre-of-mass frame, and the blocks of + * the chain, which scatter off them, use their massive kernels + * (@ref TwoToTwoParticleScattering, @ref DoubleT and + * @ref TwoToThreeParticleScattering with `massive_beams`). + * * **References** * - [1] T. Heimel, O. Mattelaer, R. Winterhalder, "MadSpace", * https://arxiv.org/abs/2602.06895 (Sec. 2.2.5) @@ -104,13 +110,18 @@ class ColorOrderedMapping : public Mapping { * takes the beam momentum fractions `x1`, `x2` * (`float`, shape `(batch,)`) as two further * conditions. + * @param incoming_masses Masses of the two incoming particles, empty (or + * all zero) for massless ones. With a massive + * one, `momentum0` and `momentum1` are on their + * mass shells. */ ColorOrderedMapping( const Options& options, const std::vector& pt_min = {}, const std::vector>& m_inv_min = {}, const std::vector>& dr_min = {}, - const std::vector& y_max = {} + const std::vector& y_max = {}, + const std::vector& incoming_masses = {} ); /// Number of continuous unit-hypercube inputs consumed by the forward map. @@ -120,6 +131,9 @@ class ColorOrderedMapping : public Mapping { /// Whether rapidity bounds narrow a block (and the mapping therefore takes /// `x1`, `x2` as conditions). bool has_rapidity_window() const { return _rapidity_window; } + /// The absolute masses of the incoming particles, empty if both are + /// massless. + const std::vector& incoming_masses() const { return _incoming_masses; } private: // Rapidity bounds of the blocks that scatter the two beams (negative: @@ -138,13 +152,15 @@ class ColorOrderedMapping : public Mapping { static RapidityBounds rapidity_bounds( const std::vector& color_order, const std::vector& y_max ); - // The public constructor with the rapidity bounds worked out once. + // The public constructor with the rapidity bounds worked out once and the + // incoming masses as massive_incoming_masses gives them. ColorOrderedMapping( const RapidityBounds& bounds, const Options& options, const std::vector& pt_min, const std::vector>& m_inv_min, - const std::vector>& dr_min + const std::vector>& dr_min, + const std::vector& incoming_masses ); Result build_forward_impl( @@ -206,6 +222,7 @@ class ColorOrderedMapping : public Mapping { std::vector> _dr_min; bool _has_cut; bool _rapidity_window; + std::vector _incoming_masses; Invariant _mass_invariant; TwoToTwoParticleScattering _com_scattering; diff --git a/madspace/include/madspace/phasespace/cross_section.hpp b/madspace/include/madspace/phasespace/cross_section.hpp index 4337ac1a9a..ba34affdcb 100644 --- a/madspace/include/madspace/phasespace/cross_section.hpp +++ b/madspace/include/madspace/phasespace/cross_section.hpp @@ -32,6 +32,12 @@ namespace madspace { * @f$\sum_h f_{\lambda_1(h)} f_{\lambda_2(h)} |M_h|^2@f$. Leg @f$i@f$ * comes from beam @f$i@f$, or from the other one for `mirror_index` 1. * + * With massive @p incoming_masses (those of the @ref PhaseSpaceMapping, which + * puts the incoming particles on their mass shells) the flux is + * @f$1 / (2 \sqrt{\lambda(\hat s, m_1^2, m_2^2)})@f$ with + * @f$\hat s = x_1 x_2 s@f$ instead of @f$1 / (2 \hat s)@f$, as in madevent, + * and zero at and below the threshold @f$(m_1 + m_2)^2@f$. + * * `batch` is the leading batch dimension. * * **Arguments** @@ -91,6 +97,10 @@ class DifferentialCrossSection : public FunctionGenerator { * helicity table of the matrix element * (rows of the particles' helicities, * indexed by its helicity index). + * @param incoming_masses Masses of the two incoming particles of a + * collision, for the flux, empty or zero + * for massless ones. Needs + * @p input_momentum_fraction. */ DifferentialCrossSection( const MatrixElement& matrix_element, @@ -105,7 +115,8 @@ class DifferentialCrossSection : public FunctionGenerator { bool decay = false, bool return_matrix_element = false, const std::optional& eva = std::nullopt, - const nested_vector3& eva_helicities = {} + const nested_vector3& eva_helicities = {}, + const std::vector& incoming_masses = {} ); /// The allowed initial-parton flavour combinations. @@ -123,6 +134,9 @@ class DifferentialCrossSection : public FunctionGenerator { /// Whether the beams are effective vector bosons (then the arguments end /// with `fact_scale1`, `fact_scale2` and `mirror_index`). bool eva() const { return _eva_tables.has_value(); } + /// Masses of the incoming particles the flux is computed with (absolute + /// values): two for a collision with a massive one, empty otherwise. + const std::vector& incoming_masses() const { return _incoming_masses; } private: NamedVector build_function_impl( @@ -140,6 +154,7 @@ class DifferentialCrossSection : public FunctionGenerator { bool _decay; bool _return_matrix_element; std::optional _eva_tables; + std::vector _incoming_masses; }; } // namespace madspace diff --git a/madspace/include/madspace/phasespace/invariants.hpp b/madspace/include/madspace/phasespace/invariants.hpp index abaa454a82..666c6a5653 100644 --- a/madspace/include/madspace/phasespace/invariants.hpp +++ b/madspace/include/madspace/phasespace/invariants.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "madspace/phasespace/base.hpp" namespace madspace { @@ -76,6 +78,33 @@ class Invariant : public Mapping { double power = 0, double mass = 0, double width = 0, double flat_window = 0 ); + /** + * The forward map for a variable @f$x@f$ whose range can reach below 0, + * such as a momentum transfer off a massive beam. It samples + * @f$x - 2 \min(x_\text{min}, 0)@f$ on the range shifted alike, which is + * @f$x@f$ itself wherever the range stays at or above 0. Below 0 the + * sampled range starts at @f$|x_\text{min}|@f$, so that a power law keeps + * the density of about @f$|x_\text{min}|^{-\nu}@f$ that it has at a lower + * end above 0, rather than its pole, at the lower end. + * + * @param r The random number, `float`, shape `(batch,)`. + * @param x_min Lower end of the range of @f$x@f$. + * @param x_max Upper end of the range of @f$x@f$. + * @return @f$x@f$ and the Jacobian. + */ + std::array + build_forward_shifted(FunctionBuilder& fb, Value r, Value x_min, Value x_max) const; + /** + * The inverse of build_forward_shifted(). + * + * @param x The value, `float`, shape `(batch,)`. + * @param x_min Lower end of the range of @f$x@f$. + * @param x_max Upper end of the range of @f$x@f$. + * @return The random number and the Jacobian. + */ + std::array + build_inverse_shifted(FunctionBuilder& fb, Value x, Value x_min, Value x_max) const; + private: Result build_forward_impl( FunctionBuilder& fb, diff --git a/madspace/include/madspace/phasespace/phasespace.hpp b/madspace/include/madspace/phasespace/phasespace.hpp index a0983ddd88..08f4304e0f 100644 --- a/madspace/include/madspace/phasespace/phasespace.hpp +++ b/madspace/include/madspace/phasespace/phasespace.hpp @@ -37,6 +37,26 @@ namespace madspace { * @ref Topology and is used for the topology-free @ref TChannelMode::rambo and * @ref TChannelMode::chili modes. * + * Massive incoming particles of a collision (the incoming masses of the + * topology: W and Z beams, muons of a model with a muon mass, massive partons) + * are built on their mass shells in the partonic centre-of-mass frame + * (`com_p_in_massive`), as madevent's genps.f builds them (mom2cx). The + * t-channel chains of @ref TChannelMode::propagator and + * @ref TChannelMode::color_ordered scatter off them with the massive versions + * of their blocks, chosen when the graph is built. Chili, whose final state + * fixes the incoming momenta, is written for massless beams: it generates the + * final state against the massless pair with the same sum, which then goes on + * its mass shells (`incoming_on_shell`). With fixed beams (leptonic) and + * with dressed-lepton beams, whose split samples x1 and x2, chili builds the + * final state for fixed beams in the partonic frame (see @ref ChiliMapping), + * and massive ones are built directly. The n-body phase space depends on the + * incoming momenta only through their sum, so that leaves the Jacobian + * unchanged, and the inverse takes the massless pair back from the sum. + * Sampled s_hat starts at the threshold @f$(m_1 + m_2)^2@f$, and a weight + * below it (chili) is zero. The flux @f$1 / (2 \sqrt{\lambda(\hat s, m_1^2, + * m_2^2)})@f$ belongs to the cross section: see the `incoming_masses` of + * @ref DifferentialCrossSection. + * * `batch` is the leading batch dimension. `n_out` is the number of outgoing * particles. * @@ -55,7 +75,7 @@ namespace madspace { * * **Outputs** * - `momenta` – `float`, shape `(batch, n_out + 2, 4)` – all momenta (incoming - * beams first, then outgoing). + * beams first, on their mass shells, then outgoing). * - `x1` – `float`, shape `(batch,)` – first parton momentum fraction (1 for * every event if `leptonic` and for a decay). * - `x2` – `float`, shape `(batch,)` – second parton momentum fraction (1 for @@ -259,12 +279,14 @@ class PhaseSpaceMapping : public Mapping { double beam_rapidity() const { return _beam_rapidity; } /// Whether the mapping takes the `mirror_index` condition. bool mirror_beams() const { return _mirror_beams; } - /// Masses of the incoming particles. The mapping hands them out massless - /// (along the beams, at the sampled s_hat); @ref Integrand puts massive - /// ones on their mass shell, with the massive flux. + /// Masses of the incoming particles, on whose mass shells the mapping puts + /// them. A @ref DifferentialCrossSection of a collision with massive ones + /// needs the same `incoming_masses` for its flux. const std::vector& incoming_masses() const { return _topology.incoming_masses(); } + /// Whether this is a collision with a massive incoming particle. + bool massive_incoming() const { return _massive_incoming; } /// The cuts, applied to the lab-frame momenta. const Cuts& cuts() const { return _cuts; } /// True when the cuts exclude the whole region this mapping samples: a @@ -316,6 +338,11 @@ class PhaseSpaceMapping : public Mapping { bool _map_luminosity; double _lepton_power; bool _two_to_one; + // a collision with a massive incoming particle (see the class documentation) + bool _massive_incoming; + // massive incoming particles put on their mass shells after chili that + // reads x1 and x2 off its final state, which is written for massless beams + bool _project_incoming; // bound on the absolute rapidity of the partonic system, log(x1 / x2) / 2, // implied by the cuts; negative when they imply none double _y_max_lab = -1.; diff --git a/madspace/include/madspace/phasespace/t_propagator_mapping.hpp b/madspace/include/madspace/phasespace/t_propagator_mapping.hpp index c142fb7581..5a18eccfac 100644 --- a/madspace/include/madspace/phasespace/t_propagator_mapping.hpp +++ b/madspace/include/madspace/phasespace/t_propagator_mapping.hpp @@ -22,6 +22,12 @@ namespace madspace { * momentum on the chosen side by subtraction (Sec. 2.2.8 of [1], following * [2]). * + * The incoming momenta are those of the beams in their centre-of-mass frame, on + * the mass shells of the incoming particles (`com_p_in_massive`), so that each + * |t| is the momentum transfer from a massive beam, as in madevent's genps.f. + * The blocks of the chain then use the massive kernels of + * @ref TwoToTwoParticleScattering. + * * `batch` is the leading batch dimension. `kappa` is the number of `t`-channel * propagators, `len(integration_order)`. * @@ -69,12 +75,15 @@ class TPropagatorMapping : public Mapping { * the |t| range exactly. The mapping then takes * the beam momentum fractions `x1`, `x2` (`float`, * shape `(batch,)`) as two further conditions. + * @param incoming_masses Masses of the two incoming particles, empty or + * zero for massless ones. */ TPropagatorMapping( const std::vector& integration_order, double invariant_power = 0.8, const std::vector& pt_min = {}, - const std::vector& y_max = {} + const std::vector& y_max = {}, + const std::vector& incoming_masses = {} ); /// Number of uniform random inputs consumed by the forward mapping, /// equal to `3 * len(integration_order) - 1`. @@ -82,6 +91,9 @@ class TPropagatorMapping : public Mapping { /// Whether the first scattering is narrowed by rapidity bounds (and the /// mapping therefore takes `x1`, `x2` as conditions). bool has_rapidity_window() const { return _rapidity_window; } + /// Masses of the incoming particles (absolute values), two for massive ones, + /// empty for massless ones. + const std::vector& incoming_masses() const { return _incoming_masses; } private: // The public constructor with the first scattering's rapidity bounds @@ -90,7 +102,8 @@ class TPropagatorMapping : public Mapping { const std::array& first_step_bounds, const std::vector& integration_order, double invariant_power, - const std::vector& pt_min + const std::vector& pt_min, + const std::vector& incoming_masses ); Result build_forward_impl( @@ -115,6 +128,7 @@ class TPropagatorMapping : public Mapping { Invariant _uniform_invariant; TwoToTwoParticleScattering _com_scattering; TwoToTwoParticleScattering _lab_scattering; + std::vector _incoming_masses; }; } // namespace madspace diff --git a/madspace/include/madspace/phasespace/three_particle.hpp b/madspace/include/madspace/phasespace/three_particle.hpp index 69f35fc8c1..b06c392367 100644 --- a/madspace/include/madspace/phasespace/three_particle.hpp +++ b/madspace/include/madspace/phasespace/three_particle.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "madspace/phasespace/base.hpp" #include "madspace/phasespace/invariants.hpp" @@ -191,6 +193,21 @@ class TwoToThreeParticleScattering : public Mapping { * when both pass. The weight assumes * `discrete_choice` is sampled uniformly; with a * learned distribution of it, leave this off. + * @param massive_beams If true, `momentum_in1` (pa) is a massive beam, + * and with @p incoming_recoil so is k (see + * below). + * + * With @p massive_beams the range of @f$|t_1|@f$ comes from the massive + * kernels of @ref TwoToTwoParticleScattering (`t_inv_min_max_massive`, + * ...), and its @ref Invariant samples @f$|t_1|@f$ shifted where its + * range reaches below 0 (Invariant::build_forward_shifted), since + * @f$t_1@f$ can be positive off a massive beam. The ETmin bound of + * @f$\tilde s@f$ takes the mass of pa into account + * (`s23_min_max_cut_massive`). With @p incoming_recoil, + * @f$(p_2 - k)^2@f$ can be positive too: its bound from `etmin_2` is that + * of `recoil_v_min_massive`, and its negative is sampled shifted in the + * same way. The massless kernels are untouched by this choice, which is + * made when the graph is built. */ TwoToThreeParticleScattering( double t_invariant_power = 0, @@ -203,7 +220,8 @@ class TwoToThreeParticleScattering : public Mapping { bool arcsine_s23 = true, bool p12_condition = false, bool incoming_recoil = false, - bool cut_aware_branch = false + bool cut_aware_branch = false, + bool massive_beams = false ); /// Number of discrete inputs (1): which of the two two-body solutions. @@ -223,16 +241,41 @@ class TwoToThreeParticleScattering : public Mapping { std::array split_conditions(FunctionBuilder& fb, const NamedVector& conditions) const; - // Sampled and kinematic range of the second invariant: s23 itself, or - // |(p2 - k)^2| for an incoming recoil. Arguments: the kinematic range of - // s23, the squared mass of p2 and the conditions. - std::array sampling_ranges( + // The sampled and the kinematic range of the second invariant, and with + // massive beams the shift that takes its value into the sampled range + // (none: no shift). + struct Ranges { + Value min, max, phys_min, phys_max; + std::optional shift; + }; + // The ranges of -(p2 - k)^2 for an incoming recoil. Arguments: the + // kinematic range of s23 = (p2 - k)^2, the squared mass of p2 and the + // conditions. + Ranges recoil_ranges( FunctionBuilder& fb, Value s23_min, Value s23_max, Value m2_squared, const NamedVector& conditions ) const; + // the |t1| range, with the ETmin bound of the cuts if there are any + std::array t1_range( + FunctionBuilder& fb, + const NamedVector& conditions, + Value p_a, + Value p_c, + Value m1, + Value m2 + ) const; + // |t1| and its range from the outgoing momenta + std::array t1_value_and_range( + FunctionBuilder& fb, + const NamedVector& conditions, + Value p_a, + Value p_c, + Value p1, + Value p2 + ) const; Invariant _t_invariant; Invariant _s_invariant; double _s_power, _s_mass; @@ -241,6 +284,7 @@ class TwoToThreeParticleScattering : public Mapping { bool _p12_condition; bool _incoming_recoil; bool _cut_aware_branch; + bool _massive_beams; }; } // namespace madspace diff --git a/madspace/include/madspace/phasespace/two_particle.hpp b/madspace/include/madspace/phasespace/two_particle.hpp index 00818a9b83..950f2b5b92 100644 --- a/madspace/include/madspace/phasespace/two_particle.hpp +++ b/madspace/include/madspace/phasespace/two_particle.hpp @@ -156,6 +156,8 @@ class TwoToTwoParticleScattering : public Mapping { * @param y_max2 The same for `momentum2`. * @param beam_sign +1 if `momentum_in1` is beam 1 (along +z), -1 * if it is beam 2. + * @param massive_beams If true, the block is part of a chain off massive + * beams (see below). * * The rapidity bounds are only valid when the two incoming momenta are * the beams in the partonic centre-of-mass frame (the first step of a @@ -163,6 +165,14 @@ class TwoToTwoParticleScattering : public Mapping { * each bound becomes an interval of @f$|t|@f$. With a bound set, the * mapping takes the beam momentum fractions `x1`, `x2` (`float`, shape * `(batch,)`) as two further conditions. + * + * With @p massive_beams an incoming momentum can be a massive beam, and + * @f$t = (p_a - p_1)^2@f$ can then be positive near the forward + * direction. The range of @f$|t|@f$, its ETmin bound and the rapidity + * bounds come from the massive kernels (`t_inv_min_max_massive`, ...), + * and the @ref Invariant samples @f$|t|@f$ shifted where the range reaches + * below 0 (Invariant::build_forward_shifted). The massless kernels are + * untouched by this choice, which is made when the graph is built. */ TwoToTwoParticleScattering( bool com, @@ -172,7 +182,8 @@ class TwoToTwoParticleScattering : public Mapping { bool has_cut = false, double y_max1 = -1., double y_max2 = -1., - double beam_sign = 1. + double beam_sign = 1., + bool massive_beams = false ); /** @@ -227,6 +238,15 @@ class TwoToTwoParticleScattering : public Mapping { Value m1, Value m2 ) const; + // |t| from its random number and back, and the Jacobian + std::array + sample_t(FunctionBuilder& fb, Value r, Value t_min, Value t_max) const; + std::array + unsample_t(FunctionBuilder& fb, Value t_abs, Value t_min, Value t_max) const; + // the |t| range, with the ETmin bound of the cuts if there are any + std::array t_range( + FunctionBuilder& fb, const NamedVector& conditions, Value m1, Value m2 + ) const; bool _com; Invariant _invariant; @@ -235,6 +255,7 @@ class TwoToTwoParticleScattering : public Mapping { double _y_max1; double _y_max2; double _beam_sign; + bool _massive_beams; }; /** @@ -301,6 +322,8 @@ class DoubleT : public Mapping { * @param y_max2 The same for `momentum2` (the recoil). * @param beam_sign +1 if `momentum_in1` is beam 1 (along +z), -1 * if it is beam 2. + * @param massive_beams If true, the incoming momenta are massive + * beams (see below). * * The incoming momenta are the beams, so pa.p1 and pb.p1 are fixed by * @f$|t_1|@f$ and @f$|t_2|@f$: the rapidity bounds narrow @f$|t_1|@f$ to @@ -308,6 +331,14 @@ class DoubleT : public Mapping { * @f$|t_1|@f$, both exactly. With a bound set, the * mapping takes the beam momentum fractions `x1`, `x2` (`float`, shape * `(batch,)`) as two further conditions. + * + * With @p massive_beams the scattering, the ranges of @f$|t_1|@f$ and + * @f$|t_2|@f$ and the rapidity bounds come from the massive kernels + * (`double_t_scattering_massive`, `t1_inv_min_max_doublet_massive`, ...). + * Off a massive beam a momentum transfer can be positive, and each + * @ref Invariant samples it shifted where its range reaches below 0 + * (Invariant::build_forward_shifted). The massless kernels are untouched + * by this choice, which is made when the graph is built. */ DoubleT( double t1_invariant_power = 0, @@ -319,7 +350,8 @@ class DoubleT : public Mapping { bool has_cut = false, double y_max1 = -1., double y_max2 = -1., - double beam_sign = 1. + double beam_sign = 1., + bool massive_beams = false ); private: @@ -347,6 +379,21 @@ class DoubleT : public Mapping { Value t2_max, Value t1_abs ) const; + // a momentum transfer from its random number and back, and the Jacobian + std::array sample_t( + FunctionBuilder& fb, + const Invariant& invariant, + Value r, + Value t_min, + Value t_max + ) const; + std::array unsample_t( + FunctionBuilder& fb, + const Invariant& invariant, + Value t_abs, + Value t_min, + Value t_max + ) const; Invariant _t1_invariant; Invariant _t2_invariant; @@ -355,6 +402,7 @@ class DoubleT : public Mapping { double _y_max1; double _y_max2; double _beam_sign; + bool _massive_beams; }; } // namespace madspace diff --git a/madspace/instruction_set.yaml b/madspace/instruction_set.yaml index 3a39c5cbc7..6219dc72ec 100644 --- a/madspace/instruction_set.yaml +++ b/madspace/instruction_set.yaml @@ -725,6 +725,23 @@ com_p_in: desc: "incoming momentum along -z" desc: "Builds the two incoming momenta for a given center-of-mass energy." +com_p_in_massive: + inputs: + - name: e_cm + type: [float] + desc: "center-of-mass energy" + - name: masses + type: [float, single, 2] + desc: "masses of the two incoming particles" + outputs: + - name: p1 + type: [float, 4] + desc: "incoming momentum along +z" + - name: p2 + type: [float, 4] + desc: "incoming momentum along -z" + desc: "`com_p_in` for massive incoming particles: the two incoming momenta in their center-of-mass frame on their mass shells, as madevent's mom2cx (genps.f). Below the threshold (m1 + m2)^2 they are at rest. See @ref PhaseSpaceMapping." + incoming_on_shell: inputs: - name: p_ext @@ -732,16 +749,15 @@ incoming_on_shell: desc: "external momenta, the two incoming ones first, along the beam axis" - name: masses type: [float, single, 2] - desc: "masses of the two incoming particles" + desc: "masses to put the two incoming particles on" outputs: - name: p_out type: [float, n, 4] - desc: "the same momenta with the incoming ones on their mass shell" - - name: flux_ratio + desc: "the same momenta with the incoming ones on these mass shells" + - name: above_threshold type: [float] - desc: "s_hat / sqrt(lambda(s_hat, m1^2, m2^2)), zero below threshold" - vectorized: False - desc: "Puts the two incoming momenta on their mass shell, with the same sum (so the same s_hat and rapidity) and the same directions, and returns the ratio of the massive flux 1/(2 sqrt(lambda)) to the massless 1/(2 s_hat), as madevent's genps.f has them for massive partons. Below the threshold (m1 + m2)^2 the momenta are unchanged and the ratio is zero." + desc: "1 for s > (m1 + m2)^2, 0 otherwise" + desc: "Puts the two incoming momenta on the mass shells `masses`, along the beam axis, with the same sum (so the same s and rapidity) and each in the direction it had in the rest frame of the pair, as madevent's mom2cx builds massive incoming particles (genps.f). Built in light-cone components, so that the momenta keep their relative precision at any rapidity. With masses 0 it turns a massive pair back into the massless one with the same sum. See @ref PhaseSpaceMapping." r_to_x1x2: inputs: @@ -913,6 +929,35 @@ diff_cross_section: desc: "differential cross section" desc: "Differential cross section in pb: matrix_element * pdf1 * pdf2 / (2 e_cm2 x1^2 x2^2), with the unit conversion from GeV^-2. See @ref DifferentialCrossSection." +diff_cross_section_massive: + inputs: + - name: x1 + type: [float] + desc: "momentum fraction of beam 1" + - name: x2 + type: [float] + desc: "momentum fraction of beam 2" + - name: pdf1 + type: [float] + desc: "PDF value for beam 1" + - name: pdf2 + type: [float] + desc: "PDF value for beam 2" + - name: matrix_element + type: [float] + desc: "matrix element value" + - name: e_cm2 + type: [float, single] + desc: "squared center-of-mass energy" + - name: masses + type: [float, single, 2] + desc: "masses of the two incoming particles" + outputs: + - name: result + type: [float] + desc: "differential cross section" + desc: "`diff_cross_section` with massive incoming particles: the flux 1/(2 sqrt(lambda(s_hat, m1^2, m2^2))), s_hat = x1 x2 e_cm2, in place of 1/(2 s_hat), zero at and below the threshold (m1 + m2)^2. See @ref DifferentialCrossSection." + two_body_decay_com: inputs: - name: r_phi @@ -1394,6 +1439,38 @@ double_t_scattering: desc: "Jacobian of the mapping" desc: "Scattering step with two t-channel momentum transfers. Building block of @ref DoubleT." +double_t_scattering_massive: + inputs: + - name: r_phi + type: [float] + desc: "random number for the azimuthal angle" + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: t1_abs + type: [float] + desc: "absolute value of the first momentum transfer" + - name: t2_abs + type: [float] + desc: "absolute value of the second momentum transfer" + - name: m1 + type: [float] + desc: "mass of the outgoing particle" + outputs: + - name: p1 + type: [float, 4] + desc: "first outgoing momentum" + - name: p2 + type: [float, 4] + desc: "second outgoing momentum" + - name: det + type: [float] + desc: "Jacobian of the mapping" + desc: "`double_t_scattering` off massive beams, with the Jacobian pi / (2 sqrt(lambda(s, ma^2, mb^2))). Building block of @ref DoubleT." + double_t_scattering_inverse: inputs: - name: p1 @@ -1417,6 +1494,29 @@ double_t_scattering_inverse: desc: "Jacobian of the mapping" desc: "Inverse of `double_t_scattering`. Building block of @ref DoubleT." +double_t_scattering_inverse_massive: + inputs: + - name: p1 + type: [float, 4] + desc: "first outgoing momentum" + - name: p2 + type: [float, 4] + desc: "second outgoing momentum" + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + outputs: + - name: r_phi + type: [float] + desc: "random number for the azimuthal angle" + - name: det + type: [float] + desc: "Jacobian of the mapping" + desc: "Inverse of `double_t_scattering_massive`. Building block of @ref DoubleT." + three_body_decay_com: inputs: - name: r_e1 @@ -1791,57 +1891,430 @@ t1_rapidity_clamp_doublet: outputs: - name: t1_min_out type: [float] - desc: "narrowed lower bound of |t1|" - - name: t1_max_out + desc: "narrowed lower bound of |t1|" + - name: t1_max_out + type: [float] + desc: "narrowed upper bound of |t1|" + desc: "Narrows |t1| of the double-t central block to the values that leave some |t2| for the rapidity bounds of both outgoing momenta. Building block of @ref DoubleT." + +t1_rapidity_clamp_doublet_massive: + inputs: + - name: t1_min + type: [float] + desc: "lower bound of |t1|" + - name: t1_max + type: [float] + desc: "upper bound of |t1|" + - name: pa + type: [float, 4] + desc: "first incoming momentum (a beam, in the partonic centre-of-mass frame)" + - name: pb + type: [float, 4] + desc: "second incoming momentum (the other beam)" + - name: m1 + type: [float] + desc: "mass of the single outgoing particle p1" + - name: mir_min + type: [float] + desc: "minimum invariant mass of the recoil system" + - name: etmin_1 + type: [float] + desc: "lower bound on the transverse energy of p1 (0 for none)" + - name: etmin_2 + type: [float] + desc: "lower bound on the transverse energy of the recoil p2 (0 for none)" + - name: x1 + type: [float] + desc: "momentum fraction of beam 1" + - name: x2 + type: [float] + desc: "momentum fraction of beam 2" + - name: beam_sign + type: [float, single] + desc: "+1 if pa is beam 1, -1 if it is beam 2" + - name: y_max1 + type: [float, single] + desc: "bound on the absolute lab rapidity of p1, negative or 100 and above for none" + - name: y_max2 + type: [float, single] + desc: "bound on the absolute lab rapidity of the recoil p2, negative or 100 and above for none" + outputs: + - name: t1_min_out + type: [float] + desc: "narrowed lower bound of |t1|" + - name: t1_max_out + type: [float] + desc: "narrowed upper bound of |t1|" + desc: "`t1_rapidity_clamp_doublet` with the kinematics of massive beams. Building block of @ref DoubleT." + +t2_rapidity_clamp_doublet: + inputs: + - name: t2_min + type: [float] + desc: "lower bound of |t2|" + - name: t2_max + type: [float] + desc: "upper bound of |t2|" + - name: pa + type: [float, 4] + desc: "first incoming momentum (a beam, in the partonic centre-of-mass frame)" + - name: pb + type: [float, 4] + desc: "second incoming momentum (the other beam)" + - name: m1 + type: [float] + desc: "mass of the single outgoing particle p1" + - name: t1_abs + type: [float] + desc: "the sampled |t1| = -(pa - p1)^2" + - name: x1 + type: [float] + desc: "momentum fraction of beam 1" + - name: x2 + type: [float] + desc: "momentum fraction of beam 2" + - name: beam_sign + type: [float, single] + desc: "+1 if pa is beam 1, -1 if it is beam 2" + - name: y_max1 + type: [float, single] + desc: "bound on the absolute lab rapidity of p1, negative or 100 and above for none" + - name: y_max2 + type: [float, single] + desc: "bound on the absolute lab rapidity of the recoil p2, negative or 100 and above for none" + outputs: + - name: t2_min_out + type: [float] + desc: "narrowed lower bound of |t2|" + - name: t2_max_out + type: [float] + desc: "narrowed upper bound of |t2|" + desc: "Narrows |t2| of the double-t central block, at fixed |t1|, to the values for which both outgoing momenta can satisfy their rapidity bounds. Building block of @ref DoubleT." + +t2_rapidity_clamp_doublet_massive: + inputs: + - name: t2_min + type: [float] + desc: "lower bound of |t2|" + - name: t2_max + type: [float] + desc: "upper bound of |t2|" + - name: pa + type: [float, 4] + desc: "first incoming momentum (a beam, in the partonic centre-of-mass frame)" + - name: pb + type: [float, 4] + desc: "second incoming momentum (the other beam)" + - name: m1 + type: [float] + desc: "mass of the single outgoing particle p1" + - name: t1_abs + type: [float] + desc: "the sampled |t1| = -(pa - p1)^2" + - name: x1 + type: [float] + desc: "momentum fraction of beam 1" + - name: x2 + type: [float] + desc: "momentum fraction of beam 2" + - name: beam_sign + type: [float, single] + desc: "+1 if pa is beam 1, -1 if it is beam 2" + - name: y_max1 + type: [float, single] + desc: "bound on the absolute lab rapidity of p1, negative or 100 and above for none" + - name: y_max2 + type: [float, single] + desc: "bound on the absolute lab rapidity of the recoil p2, negative or 100 and above for none" + outputs: + - name: t2_min_out + type: [float] + desc: "narrowed lower bound of |t2|" + - name: t2_max_out + type: [float] + desc: "narrowed upper bound of |t2|" + desc: "`t2_rapidity_clamp_doublet` with the kinematics of massive beams. Building block of @ref DoubleT." + +t_inv_value_and_min_max_cut: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: p1 + type: [float, 4] + desc: "first outgoing momentum" + - name: p2 + type: [float, 4] + desc: "second outgoing momentum" + - name: etmin_1 + type: [float] + desc: "minimum transverse energy of the first outgoing particle" + - name: etmin_2 + type: [float] + desc: "minimum transverse energy of the second outgoing particle" + outputs: + - name: t_abs + type: [float] + desc: "absolute value of the momentum transfer" + - name: t_min + type: [float] + desc: "lower limit of the momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the momentum transfer" + desc: "Momentum transfer and its cut-restricted limits for a given final state. Building block of @ref TwoToTwoParticleScattering; see @ref Cuts." + +t_inv_min_max_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: m1 + type: [float] + desc: "mass of the first outgoing particle" + - name: m2 + type: [float] + desc: "mass of the second outgoing particle" + outputs: + - name: t_min + type: [float] + desc: "lower limit of the momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the momentum transfer" + desc: "Range of the momentum transfer |t| of a 2 -> 2 scattering with a massive beam among the incoming momenta: as `t_inv_min_max`, without its clamp at |t| = 0, since t > 0 is reached near the forward direction. Building block of @ref TwoToTwoParticleScattering." + +t_inv_value_and_min_max_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: p1 + type: [float, 4] + desc: "first outgoing momentum" + - name: p2 + type: [float, 4] + desc: "second outgoing momentum" + outputs: + - name: t_abs + type: [float] + desc: "absolute value of the momentum transfer" + - name: t_min + type: [float] + desc: "lower limit of the momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the momentum transfer" + desc: "`t_inv_value_and_min_max` with a massive beam among the incoming momenta (the range of `t_inv_min_max_massive`). Building block of @ref TwoToTwoParticleScattering." + +t_inv_min_max_cut_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: m1 + type: [float] + desc: "mass of the first outgoing particle" + - name: m2 + type: [float] + desc: "mass of the second outgoing particle" + - name: etmin_1 + type: [float] + desc: "minimum transverse energy of the first outgoing particle" + - name: etmin_2 + type: [float] + desc: "minimum transverse energy of the second outgoing particle" + outputs: + - name: t_min + type: [float] + desc: "lower limit of the momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the momentum transfer" + desc: "`t_inv_min_max_cut` with a massive beam among the incoming momenta: the range of `t_inv_min_max_massive`, narrowed by the ETmin bounds for a massive pa where it lies along the beam axis. Building block of @ref TwoToTwoParticleScattering; see @ref Cuts." + +t_inv_value_and_min_max_cut_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: p1 + type: [float, 4] + desc: "first outgoing momentum" + - name: p2 + type: [float, 4] + desc: "second outgoing momentum" + - name: etmin_1 + type: [float] + desc: "minimum transverse energy of the first outgoing particle" + - name: etmin_2 + type: [float] + desc: "minimum transverse energy of the second outgoing particle" + outputs: + - name: t_abs + type: [float] + desc: "absolute value of the momentum transfer" + - name: t_min + type: [float] + desc: "lower limit of the momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the momentum transfer" + desc: "`t_inv_value_and_min_max_cut` with a massive beam among the incoming momenta (the range of `t_inv_min_max_cut_massive`). Building block of @ref TwoToTwoParticleScattering; see @ref Cuts." + +t_rapidity_clamp_massive: + inputs: + - name: t_min + type: [float] + desc: "lower bound of |t|" + - name: t_max + type: [float] + desc: "upper bound of |t|" + - name: pa + type: [float, 4] + desc: "first incoming momentum (a beam, in the partonic centre-of-mass frame)" + - name: pb + type: [float, 4] + desc: "second incoming momentum (the other beam)" + - name: m1 + type: [float] + desc: "mass of the first outgoing momentum (the recoil)" + - name: m2 + type: [float] + desc: "mass of the second outgoing momentum (the peeled particle)" + - name: x1 + type: [float] + desc: "momentum fraction of beam 1" + - name: x2 + type: [float] + desc: "momentum fraction of beam 2" + - name: beam_sign + type: [float, single] + desc: "+1 if pa is beam 1, -1 if it is beam 2" + - name: y_max1 + type: [float, single] + desc: "bound on the absolute lab rapidity of the recoil, negative or 100 and above for none" + - name: y_max2 + type: [float, single] + desc: "bound on the absolute lab rapidity of the peeled particle, negative or 100 and above for none" + outputs: + - name: t_min_out + type: [float] + desc: "narrowed lower bound of |t|" + - name: t_max_out + type: [float] + desc: "narrowed upper bound of |t|" + desc: "`t_rapidity_clamp` for massive beams: narrows the |t| range of a beam-beam 2 -> 2 scattering to the values for which both outgoing momenta can satisfy their rapidity bounds, with the kinematics of massive beams in their rest frame. Building block of @ref TwoToTwoParticleScattering." + +t1_inv_min_max_doublet: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: m1 + type: [float] + desc: "mass of the outgoing particle" + - name: mir_min + type: [float] + desc: "minimum invariant mass of the i-r system" + - name: etmin_i + type: [float] + desc: "minimum transverse energy of particle i" + - name: etmin_ir + type: [float] + desc: "minimum transverse energy of the i-r system" + outputs: + - name: t_min + type: [float] + desc: "lower limit of the first momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the first momentum transfer" + desc: "Limits of the first momentum transfer in a double-t configuration. Building block of @ref DoubleT." + +t1_inv_min_max_doublet_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: pb + type: [float, 4] + desc: "second incoming momentum" + - name: m1 + type: [float] + desc: "mass of the outgoing particle" + - name: mir_min + type: [float] + desc: "minimum invariant mass of the i-r system" + - name: etmin_i + type: [float] + desc: "minimum transverse energy of particle i" + - name: etmin_ir + type: [float] + desc: "minimum transverse energy of the i-r system" + outputs: + - name: t_min + type: [float] + desc: "lower limit of the first momentum transfer" + - name: t_max type: [float] - desc: "narrowed upper bound of |t1|" - desc: "Narrows |t1| of the double-t central block to the values that leave some |t2| for the rapidity bounds of both outgoing momenta. Building block of @ref DoubleT." + desc: "upper limit of the first momentum transfer" + desc: "`t1_inv_min_max_doublet` with massive beams: the range over every recoil mass from mir_min on, which reaches |t1| = -(ma - m1)^2 where p1 can move with the velocity of pa, narrowed by the ETmin bounds for massive beams. Building block of @ref DoubleT." -t2_rapidity_clamp_doublet: +t1_inv_value_and_min_max_doublet: inputs: - - name: t2_min - type: [float] - desc: "lower bound of |t2|" - - name: t2_max - type: [float] - desc: "upper bound of |t2|" - name: pa type: [float, 4] - desc: "first incoming momentum (a beam, in the partonic centre-of-mass frame)" + desc: "first incoming momentum" - name: pb type: [float, 4] - desc: "second incoming momentum (the other beam)" + desc: "second incoming momentum" + - name: p1 + type: [float, 4] + desc: "outgoing momentum" - name: m1 type: [float] - desc: "mass of the single outgoing particle p1" - - name: t1_abs + desc: "mass of the outgoing particle" + - name: mir_min type: [float] - desc: "the sampled |t1| = -(pa - p1)^2" - - name: x1 + desc: "minimum invariant mass of the i-r system" + - name: etmin_i type: [float] - desc: "momentum fraction of beam 1" - - name: x2 + desc: "minimum transverse energy of particle i" + - name: etmin_ir type: [float] - desc: "momentum fraction of beam 2" - - name: beam_sign - type: [float, single] - desc: "+1 if pa is beam 1, -1 if it is beam 2" - - name: y_max1 - type: [float, single] - desc: "bound on the absolute lab rapidity of p1, negative or 100 and above for none" - - name: y_max2 - type: [float, single] - desc: "bound on the absolute lab rapidity of the recoil p2, negative or 100 and above for none" + desc: "minimum transverse energy of the i-r system" outputs: - - name: t2_min_out + - name: t_abs type: [float] - desc: "narrowed lower bound of |t2|" - - name: t2_max_out + desc: "absolute value of the first momentum transfer" + - name: t_min type: [float] - desc: "narrowed upper bound of |t2|" - desc: "Narrows |t2| of the double-t central block, at fixed |t1|, to the values for which both outgoing momenta can satisfy their rapidity bounds. Building block of @ref DoubleT." + desc: "lower limit of the first momentum transfer" + - name: t_max + type: [float] + desc: "upper limit of the first momentum transfer" + desc: "First momentum transfer and its limits in a double-t configuration. Building block of @ref DoubleT." -t_inv_value_and_min_max_cut: +t1_inv_value_and_min_max_doublet_massive: inputs: - name: pa type: [float, 4] @@ -1851,29 +2324,32 @@ t_inv_value_and_min_max_cut: desc: "second incoming momentum" - name: p1 type: [float, 4] - desc: "first outgoing momentum" - - name: p2 - type: [float, 4] - desc: "second outgoing momentum" - - name: etmin_1 + desc: "outgoing momentum" + - name: m1 type: [float] - desc: "minimum transverse energy of the first outgoing particle" - - name: etmin_2 + desc: "mass of the outgoing particle" + - name: mir_min type: [float] - desc: "minimum transverse energy of the second outgoing particle" + desc: "minimum invariant mass of the i-r system" + - name: etmin_i + type: [float] + desc: "minimum transverse energy of particle i" + - name: etmin_ir + type: [float] + desc: "minimum transverse energy of the i-r system" outputs: - name: t_abs type: [float] - desc: "absolute value of the momentum transfer" + desc: "absolute value of the first momentum transfer" - name: t_min type: [float] - desc: "lower limit of the momentum transfer" + desc: "lower limit of the first momentum transfer" - name: t_max type: [float] - desc: "upper limit of the momentum transfer" - desc: "Momentum transfer and its cut-restricted limits for a given final state. Building block of @ref TwoToTwoParticleScattering; see @ref Cuts." + desc: "upper limit of the first momentum transfer" + desc: "`t1_inv_value_and_min_max_doublet` with massive beams (the range of `t1_inv_min_max_doublet_massive`). Building block of @ref DoubleT." -t1_inv_min_max_doublet: +t2_inv_min_max_doublet: inputs: - name: pa type: [float, 4] @@ -1887,6 +2363,9 @@ t1_inv_min_max_doublet: - name: mir_min type: [float] desc: "minimum invariant mass of the i-r system" + - name: t1_abs + type: [float] + desc: "absolute value of the first momentum transfer" - name: etmin_i type: [float] desc: "minimum transverse energy of particle i" @@ -1896,13 +2375,13 @@ t1_inv_min_max_doublet: outputs: - name: t_min type: [float] - desc: "lower limit of the first momentum transfer" + desc: "lower limit of the second momentum transfer" - name: t_max type: [float] - desc: "upper limit of the first momentum transfer" - desc: "Limits of the first momentum transfer in a double-t configuration. Building block of @ref DoubleT." + desc: "upper limit of the second momentum transfer" + desc: "Limits of the second momentum transfer in a double-t configuration. Building block of @ref DoubleT." -t1_inv_value_and_min_max_doublet: +t2_inv_min_max_doublet_massive: inputs: - name: pa type: [float, 4] @@ -1910,15 +2389,15 @@ t1_inv_value_and_min_max_doublet: - name: pb type: [float, 4] desc: "second incoming momentum" - - name: p1 - type: [float, 4] - desc: "outgoing momentum" - name: m1 type: [float] desc: "mass of the outgoing particle" - name: mir_min type: [float] desc: "minimum invariant mass of the i-r system" + - name: t1_abs + type: [float] + desc: "absolute value of the first momentum transfer" - name: etmin_i type: [float] desc: "minimum transverse energy of particle i" @@ -1926,18 +2405,15 @@ t1_inv_value_and_min_max_doublet: type: [float] desc: "minimum transverse energy of the i-r system" outputs: - - name: t_abs - type: [float] - desc: "absolute value of the first momentum transfer" - name: t_min type: [float] - desc: "lower limit of the first momentum transfer" + desc: "lower limit of the second momentum transfer" - name: t_max type: [float] - desc: "upper limit of the first momentum transfer" - desc: "First momentum transfer and its limits in a double-t configuration. Building block of @ref DoubleT." + desc: "upper limit of the second momentum transfer" + desc: "`t2_inv_min_max_doublet` with massive beams: |t2| at fixed |t1| between the two values where p1 lies along the beam axis and at most the one where the recoil has the mass mir_min, narrowed by the ETmin bounds for massive beams. Building block of @ref DoubleT." -t2_inv_min_max_doublet: +t2_inv_value_and_min_max_doublet: inputs: - name: pa type: [float, 4] @@ -1945,6 +2421,9 @@ t2_inv_min_max_doublet: - name: pb type: [float, 4] desc: "second incoming momentum" + - name: p1 + type: [float, 4] + desc: "outgoing momentum" - name: m1 type: [float] desc: "mass of the outgoing particle" @@ -1961,15 +2440,18 @@ t2_inv_min_max_doublet: type: [float] desc: "minimum transverse energy of the i-r system" outputs: + - name: t_abs + type: [float] + desc: "absolute value of the second momentum transfer" - name: t_min type: [float] desc: "lower limit of the second momentum transfer" - name: t_max type: [float] desc: "upper limit of the second momentum transfer" - desc: "Limits of the second momentum transfer in a double-t configuration. Building block of @ref DoubleT." + desc: "Second momentum transfer and its limits in a double-t configuration. Building block of @ref DoubleT." -t2_inv_value_and_min_max_doublet: +t2_inv_value_and_min_max_doublet_massive: inputs: - name: pa type: [float, 4] @@ -2005,7 +2487,7 @@ t2_inv_value_and_min_max_doublet: - name: t_max type: [float] desc: "upper limit of the second momentum transfer" - desc: "Second momentum transfer and its limits in a double-t configuration. Building block of @ref DoubleT." + desc: "`t2_inv_value_and_min_max_doublet` with massive beams (the range of `t2_inv_min_max_doublet_massive`). Building block of @ref DoubleT." s23_min_max: inputs: @@ -2106,6 +2588,47 @@ s23_min_max_cut: desc: "upper limit of the 2-3 invariant mass squared" desc: "Cut-restricted limits of the 2-3 invariant mass squared. Building block of @ref TwoToThreeParticleScattering; see @ref Cuts." +s23_min_max_cut_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: p12 + type: [float, 4] + desc: "momentum of the system of the first and second outgoing particles" + - name: p3 + type: [float, 4] + desc: "momentum of the third particle" + - name: t1_abs + type: [float] + desc: "absolute value of the first momentum transfer" + - name: m1 + type: [float] + desc: "mass of the first outgoing particle" + - name: m2 + type: [float] + desc: "mass of the second outgoing particle" + - name: etmin_1 + type: [float] + desc: "minimum transverse energy of the first outgoing particle" + - name: etmin_2 + type: [float] + desc: "minimum transverse energy of the second outgoing particle" + - name: drcut + type: [float] + desc: "minimum angular separation between the outgoing particles" + - name: s23_min_cut + type: [float] + desc: "explicit lower cut on the 2-3 invariant mass squared" + outputs: + - name: s23_min + type: [float] + desc: "lower limit of the 2-3 invariant mass squared" + - name: s23_max + type: [float] + desc: "upper limit of the 2-3 invariant mass squared" + desc: "`s23_min_max_cut` with a massive pa: the transverse-energy floor of the recoil that bounds s23 from above takes the mass of pa into account. Building block of @ref TwoToThreeParticleScattering; see @ref Cuts." + s23_value_and_min_max_cut: inputs: - name: pa @@ -2147,6 +2670,67 @@ s23_value_and_min_max_cut: desc: "upper limit of the 2-3 invariant mass squared" desc: "The 2-3 invariant mass squared and its cut-restricted limits. Building block of @ref TwoToThreeParticleScattering; see @ref Cuts." +s23_value_and_min_max_cut_massive: + inputs: + - name: pa + type: [float, 4] + desc: "first incoming momentum" + - name: p3 + type: [float, 4] + desc: "momentum of the third particle" + - name: t1_abs + type: [float] + desc: "absolute value of the first momentum transfer" + - name: p1 + type: [float, 4] + desc: "first outgoing momentum" + - name: p2 + type: [float, 4] + desc: "second outgoing momentum" + - name: etmin_1 + type: [float] + desc: "minimum transverse energy of the first outgoing particle" + - name: etmin_2 + type: [float] + desc: "minimum transverse energy of the second outgoing particle" + - name: drcut + type: [float] + desc: "minimum angular separation between the outgoing particles" + - name: s23_min_cut + type: [float] + desc: "explicit lower cut on the 2-3 invariant mass squared" + outputs: + - name: s_23 + type: [float] + desc: "the 2-3 invariant mass squared" + - name: s23_min + type: [float] + desc: "lower limit of the 2-3 invariant mass squared" + - name: s23_max + type: [float] + desc: "upper limit of the 2-3 invariant mass squared" + desc: "`s23_value_and_min_max_cut` with a massive pa (the range of `s23_min_max_cut_massive`). Building block of @ref TwoToThreeParticleScattering; see @ref Cuts." + +recoil_v_min_massive: + inputs: + - name: pa + type: [float, 4] + desc: "incoming beam on the side of the two outgoing particles" + - name: k + type: [float, 4] + desc: "the other incoming beam, the recoil of the step" + - name: m2_2 + type: [float] + desc: "squared mass of the second outgoing particle p2" + - name: etmin_2 + type: [float] + desc: "minimum transverse energy of p2" + outputs: + - name: v_min + type: [float] + desc: "lower bound on v = -(p2 - k)^2" + desc: "Lower bound on v = -(p2 - k)^2 of the 2 -> 3 step with an incoming recoil off a massive beam k, from the transverse-energy floor of p2. Building block of @ref TwoToThreeParticleScattering; see @ref Cuts." + s23_position: inputs: - name: s23 @@ -3096,6 +3680,32 @@ chili_forward: desc: "Jacobian of the mapping" desc: "Chili hadron-collider mapping from the unit hypercube to external momenta. Building block of @ref ChiliMapping." +chili_forward_fixed: + inputs: + - name: r + type: [float, 3n-4] + desc: "random numbers, one per phase-space degree of freedom" + - name: e_cm + type: [float] + desc: "center-of-mass energy of the beams" + - name: m_out + type: [float, n] + desc: "mass of each final-state particle" + - name: pt_min + type: [float, single, n] + desc: "minimum transverse momentum per final-state particle (the last two entries are not used)" + - name: y_max + type: [float, single, n] + desc: "maximum rapidity per final-state particle" + outputs: + - name: p_ext + type: [float, n+2, 4] + desc: "external momenta, incoming particles first" + - name: det + type: [float] + desc: "Jacobian of the mapping" + desc: "Chili with fixed beams (lepton colliders): the first n - 2 outgoing momenta as in `chili_forward`, the last two as the two-body decay of what is left of the beams' momentum, in its rest frame. Building block of @ref ChiliMapping." + chili_inverse: inputs: - name: p_ext @@ -3122,6 +3732,32 @@ chili_inverse: desc: "Jacobian of the mapping" desc: "Inverse of `chili_forward`. Building block of @ref ChiliMapping." +chili_inverse_fixed: + inputs: + - name: p_ext + type: [float, n+2, 4] + desc: "external momenta, incoming particles first" + - name: e_cm + type: [float] + desc: "center-of-mass energy of the beams" + - name: m_out + type: [float, n] + desc: "mass of each final-state particle" + - name: pt_min + type: [float, single, n] + desc: "minimum transverse momentum per final-state particle (the last two entries are not used)" + - name: y_max + type: [float, single, n] + desc: "maximum rapidity per final-state particle" + outputs: + - name: r + type: [float, 3n-4] + desc: "random numbers, one per phase-space degree of freedom" + - name: det + type: [float] + desc: "Jacobian of the mapping" + desc: "Inverse of `chili_forward_fixed`. Building block of @ref ChiliMapping." + --- title: Interface to ME and PDF diff --git a/madspace/src/kernels/chili.hpp b/madspace/src/kernels/chili.hpp index acec1eba84..e1ea20388c 100644 --- a/madspace/src/kernels/chili.hpp +++ b/madspace/src/kernels/chili.hpp @@ -2,32 +2,60 @@ #include "definitions.hpp" #include "kinematics.hpp" +#include "twoparticle.hpp" namespace madspace { namespace kernels { +// The largest rapidity of an outgoing particle of mass m and transverse mass^2 +// mt2 with fixed beams of total energy e_cm, acosh(E_max / m_T), from its +// largest energy E_max = (s + m^2 - (mass_sum - m)^2) / (2 sqrt(s)) when all +// the others together have the least mass, mass_sum - m. 0 where m_T > E_max. template -KERNELSPEC void kernel_chili_forward( +KERNELSPEC FVal +chili_fixed_y_max(FVal e_cm, FVal m, FVal mass_sum, FVal mt2) { + auto rest = mass_sum - m; + auto e_max = 0.5 * (e_cm + (m - rest) * (m + rest) / e_cm); + auto ratio2 = e_max * e_max / max(mt2, FVal(EPS2)); + return log(sqrt(max(ratio2, 1.)) + sqrt(max(ratio2 - 1., 0.))); +} + +// The sums of the momenta chili has built so far, and the Jacobian. +template +struct ChiliSums { + FVal e, px, py, pz, det; +}; + +// The first `count` outgoing momenta of chili, in p_ext[i + 2], generated in +// transverse momentum, rapidity and azimuth, the azimuth relative to the +// running recoil. The random numbers of particle i are r[pt_at + i], +// r[y_at + i] and r[phi_at + i]. The rapidity of a particle runs up to where +// its energy reaches sqrt(s) / 2, and with fixed beams up to its largest one, +// (s + m_i^2 - (mass_sum - m_i)^2) / (2 sqrt(s)), which is larger for a +// particle heavier than all the others together. +template +KERNELSPEC ChiliSums chili_head_forward( FIn r, - FIn e_cm, + std::size_t count, + std::size_t pt_at, + std::size_t y_at, + std::size_t phi_at, + FVal _e_cm, FIn m_out, FSIn pt_min, FSIn y_max, FOut p_ext, - FOut det + FVal mass_sum = 0. ) { - // Handle the first n-1 outgoing t-channel particles FVal e_sum(0.), px_sum(0.), py_sum(0.), pz_sum(0.); FVal det_tmp(1.); - FVal _e_cm(e_cm); auto e_cm2 = _e_cm * _e_cm; auto pt_max = _e_cm / 2; // loose bound; points with x1 or x2 >= 1 get zero weight auto pt2_max = pt_max * pt_max; - auto n_out = m_out.size(); - for (std::size_t i = 0; i < n_out - 1; ++i) { + for (std::size_t i = 0; i < count; ++i) { FVal pt_min_i(pt_min[i]), y_max_i(y_max[i]), m_out_i(m_out[i]); auto p_i = p_ext[i + 2]; - FVal r_pt(r[i]), r_y(r[n_out - 1 + i]), r_phi(r[2 * n_out - 1 + i]); + FVal r_pt(r[pt_at + i]), r_y(r[y_at + i]), r_phi(r[phi_at + i]); // ---- get the pts auto pt2_min_i = pt_min_i * pt_min_i; @@ -55,7 +83,12 @@ KERNELSPEC void kernel_chili_forward( // ------ get first n-1 rapidities and phi auto mt2 = pt2 + m_out_i * m_out_i; auto mt = sqrt(mt2); - auto y_max_calc = log(sqrt(e_cm2 / 4. / mt2) + sqrt(e_cm2 / 4. / mt2 - 1.0)); + FVal y_max_calc; + if constexpr (fixed) { + y_max_calc = chili_fixed_y_max(_e_cm, m_out_i, mass_sum, mt2); + } else { + y_max_calc = log(sqrt(e_cm2 / 4. / mt2) + sqrt(e_cm2 / 4. / mt2 - 1.0)); + } y_max_calc = min(y_max_i, y_max_calc); auto y = y_max_calc * (2. * r_y - 1.0); auto phi = 2. * PI * r_phi + atan2(py_sum, px_sum); @@ -78,78 +111,34 @@ KERNELSPEC void kernel_chili_forward( py_sum = py_sum + py_i; pz_sum = pz_sum + pz_i; } - - // Build last t-channel momentum - FVal r_y(r[2 * n_out - 2]), y_max_n(y_max[n_out - 1]), m_out_n(m_out[n_out - 1]); - auto p_n = p_ext[n_out + 1]; - auto mj2 = e_sum * e_sum - px_sum * px_sum - py_sum * py_sum - pz_sum * pz_sum; - auto yj = 0.5 * log((e_sum + pz_sum) / (e_sum - pz_sum)); - yj = where(e_sum < EPS, 99.0, yj); - auto ptj2 = px_sum * px_sum + py_sum * py_sum; - auto m2 = m_out_n * m_out_n; - auto qt = sqrt(ptj2 + m2); - auto mt = sqrt(ptj2 + max(mj2, 0.)); - auto y_min_calc = -log(_e_cm / qt * (1.0 - mt / _e_cm * exp(-yj))); - y_min_calc = max(y_min_calc, -y_max_n); // apply potential cuts - auto y_max_calc = log(_e_cm / qt * (1.0 - mt / _e_cm * exp(yj))); - y_max_calc = min(y_max_calc, y_max_n); // apply potential cuts - auto dely = y_max_calc - y_min_calc; - auto yn = y_min_calc + r_y * dely; - det_tmp = det_tmp * dely / e_cm2; - auto sinhyn = sinh(yn); - auto coshyn = sqrt(1. + sinhyn * sinhyn); - auto e_n = qt * coshyn; - auto pz_n = qt * sinhyn; - p_n[0] = e_n; - p_n[1] = -px_sum; - p_n[2] = -py_sum; - p_n[3] = pz_n; - e_sum = e_sum + e_n; - pz_sum = pz_sum + pz_n; - - // Build incoming momenta - auto pp = e_sum + pz_sum; - auto pm = e_sum - pz_sum; - auto p_a = p_ext[0], p_b = p_ext[1]; - p_a[0] = pp / 2.; - p_a[1] = 0.; - p_a[2] = 0.; - p_a[3] = pp / 2.; - p_b[0] = pm / 2.; - p_b[1] = 0.; - p_b[2] = 0.; - p_b[3] = -pm / 2.; - - // Get the bjorken variables - auto x1 = pp / e_cm; - auto x2 = pm / e_cm; - - // keep invalid point but set det/weight to zero (important to obtain correct - // integral) - det = where((x1 < 1.) & (x2 < 1.), det_tmp, 0.); + return {e_sum, px_sum, py_sum, pz_sum, det_tmp}; } -template -KERNELSPEC void kernel_chili_inverse( +// The inverse of chili_head_forward: the random numbers of the first `count` +// outgoing momenta, the sums of these momenta and the inverse Jacobian. With +// fixed beams the rapidity is read off as sign(p_z) log((E + |p_z|) / m_T), +// which keeps its precision far forward, where E - |p_z| cancels. +template +KERNELSPEC ChiliSums chili_head_inverse( FIn p_ext, - FIn e_cm, + std::size_t count, + std::size_t pt_at, + std::size_t y_at, + std::size_t phi_at, + FVal _e_cm, FIn m_out, FSIn pt_min, FSIn y_max, FOut r, - FOut det + FVal mass_sum = 0. ) { - - // Handle the first n-1 outgoing particles // need same sums as in forward mapping FVal e_sum(0.), px_sum(0.), py_sum(0.), pz_sum(0.); FVal det_tmp(1.); - FVal _e_cm(e_cm); auto e_cm2 = _e_cm * _e_cm; auto pt_max = _e_cm / 2; auto pt2_max = pt_max * pt_max; - auto n_out = m_out.size(); - for (std::size_t i = 0; i < n_out - 1; ++i) { + for (std::size_t i = 0; i < count; ++i) { FVal pt_min_i(pt_min[i]), y_max_i(y_max[i]), m_out_i(m_out[i]); auto p_i = load_mom(p_ext[i + 2]); auto E = p_i[0], px = p_i[1], py = p_i[2], pz = p_i[3]; @@ -170,7 +159,7 @@ KERNELSPEC void kernel_chili_inverse( auto has_pt_cut = pt2_min_i > 1e-9; auto r_pt = where(has_pt_cut, r_pt_cut, r_pt_nocut); - r[i] = r_pt; + r[pt_at + i] = r_pt; // get determinant auto pt2_withcut = 1. / (r_pt / pt2_max + (1. - r_pt) / pt2_min_i); @@ -190,7 +179,7 @@ KERNELSPEC void kernel_chili_inverse( auto phi = atan2(py, px); phi = where(phi < 0, phi + 2. * PI, phi); auto r_phi = phi / (2. * PI); - r[2 * n_out - 1 + i] = r_phi; + r[phi_at + i] = r_phi; } else { // for i>0, need to subtract previous sums auto base = atan2(py_sum, px_sum); @@ -198,19 +187,27 @@ KERNELSPEC void kernel_chili_inverse( auto r_phi = (phi - base) / (2. * PI); r_phi = where(r_phi < 0.0, r_phi + 1.0, r_phi); r_phi = where(r_phi >= 1.0, r_phi - 1.0, r_phi); - r[2 * n_out - 1 + i] = r_phi; + r[phi_at + i] = r_phi; } // ---- compute y from momentum (same rapidity used forward) - auto y = 0.5 * log((E + pz) / (E - pz)); auto mt2 = pt2 + m_out_i * m_out_i; auto mt = sqrt(mt2); - auto y_max_calc = log(sqrt(e_cm2 / 4. / mt2) + sqrt(e_cm2 / 4. / mt2 - 1.0)); + FVal y, y_max_calc; + if constexpr (fixed) { + auto pz_abs = fabs(pz); + auto y_abs = log((E + pz_abs) / max(mt, FVal(EPS))); + y = where(pz < 0., -y_abs, y_abs); + y_max_calc = chili_fixed_y_max(_e_cm, m_out_i, mass_sum, mt2); + } else { + y = 0.5 * log((E + pz) / (E - pz)); + y_max_calc = log(sqrt(e_cm2 / 4. / mt2) + sqrt(e_cm2 / 4. / mt2 - 1.0)); + } y_max_calc = min(y_max_i, y_max_calc); // invert y = y_max_calc * (2 r_y - 1) auto r_y = (y / y_max_calc + 1.0) * 0.5; - r[n_out - 1 + i] = r_y; + r[y_at + i] = r_y; det_tmp = det_tmp * 4.0 / (det_pt * (2.0 * y_max_calc) * (2.0 * PI)); @@ -220,6 +217,99 @@ KERNELSPEC void kernel_chili_inverse( py_sum = py_sum + py; pz_sum = pz_sum + pz; } + return {e_sum, px_sum, py_sum, pz_sum, det_tmp}; +} + +template +KERNELSPEC void kernel_chili_forward( + FIn r, + FIn e_cm, + FIn m_out, + FSIn pt_min, + FSIn y_max, + FOut p_ext, + FOut det +) { + // Handle the first n-1 outgoing t-channel particles + FVal _e_cm(e_cm); + auto e_cm2 = _e_cm * _e_cm; + auto n_out = m_out.size(); + auto head = chili_head_forward( + r, n_out - 1, 0, n_out - 1, 2 * n_out - 1, _e_cm, m_out, pt_min, y_max, p_ext + ); + auto e_sum = head.e, px_sum = head.px, py_sum = head.py, pz_sum = head.pz; + auto det_tmp = head.det; + + // Build last t-channel momentum + FVal r_y(r[2 * n_out - 2]), y_max_n(y_max[n_out - 1]), m_out_n(m_out[n_out - 1]); + auto p_n = p_ext[n_out + 1]; + auto mj2 = e_sum * e_sum - px_sum * px_sum - py_sum * py_sum - pz_sum * pz_sum; + auto yj = 0.5 * log((e_sum + pz_sum) / (e_sum - pz_sum)); + yj = where(e_sum < EPS, 99.0, yj); + auto ptj2 = px_sum * px_sum + py_sum * py_sum; + auto m2 = m_out_n * m_out_n; + auto qt = sqrt(ptj2 + m2); + auto mt = sqrt(ptj2 + max(mj2, 0.)); + auto y_min_calc = -log(_e_cm / qt * (1.0 - mt / _e_cm * exp(-yj))); + y_min_calc = max(y_min_calc, -y_max_n); // apply potential cuts + auto y_max_calc = log(_e_cm / qt * (1.0 - mt / _e_cm * exp(yj))); + y_max_calc = min(y_max_calc, y_max_n); // apply potential cuts + auto dely = y_max_calc - y_min_calc; + auto yn = y_min_calc + r_y * dely; + det_tmp = det_tmp * dely / e_cm2; + auto sinhyn = sinh(yn); + auto coshyn = sqrt(1. + sinhyn * sinhyn); + auto e_n = qt * coshyn; + auto pz_n = qt * sinhyn; + p_n[0] = e_n; + p_n[1] = -px_sum; + p_n[2] = -py_sum; + p_n[3] = pz_n; + e_sum = e_sum + e_n; + pz_sum = pz_sum + pz_n; + + // Build incoming momenta + auto pp = e_sum + pz_sum; + auto pm = e_sum - pz_sum; + auto p_a = p_ext[0], p_b = p_ext[1]; + p_a[0] = pp / 2.; + p_a[1] = 0.; + p_a[2] = 0.; + p_a[3] = pp / 2.; + p_b[0] = pm / 2.; + p_b[1] = 0.; + p_b[2] = 0.; + p_b[3] = -pm / 2.; + + // Get the bjorken variables + auto x1 = pp / e_cm; + auto x2 = pm / e_cm; + + // keep invalid point but set det/weight to zero (important to obtain correct + // integral) + det = where((x1 < 1.) & (x2 < 1.), det_tmp, 0.); +} + +template +KERNELSPEC void kernel_chili_inverse( + FIn p_ext, + FIn e_cm, + FIn m_out, + FSIn pt_min, + FSIn y_max, + FOut r, + FOut det +) { + + // Handle the first n-1 outgoing particles + FVal _e_cm(e_cm); + auto e_cm2 = _e_cm * _e_cm; + auto n_out = m_out.size(); + auto head = chili_head_inverse( + p_ext, n_out - 1, 0, n_out - 1, 2 * n_out - 1, _e_cm, m_out, pt_min, y_max, r + ); + auto e_sum = head.e, px_sum = head.px, py_sum = head.py, pz_sum = head.pz; + auto det_tmp = head.det; // ------------------------------------------------------------------------- // Invert last outgoing momentum p_ext[n_out+1] @@ -250,5 +340,107 @@ KERNELSPEC void kernel_chili_inverse( det = det_tmp; } +// Chili with fixed beams (lepton colliders): the incoming momenta add up to +// P = (e_cm, 0, 0, 0), so the final state cannot fix them as in +// kernel_chili_forward, and its two longitudinal degrees of freedom are not +// free. The first n - 2 outgoing momenta are generated as there, and the last +// two as the two-body decay of what is left, Q = P - sum of the others, in the +// rest frame of Q (r[3 (n - 2)] for cos(theta), r[3 (n - 2) + 1] for phi): +// dPhi_n = prod_{i < n-2} (dpt_i^2 dy_i dphi_i / 4) dPhi_2(Q), +// dPhi_2(Q) = pi p* / M_Q per unit of the two random numbers, +// with p* the momentum of the decay in the rest frame of Q. A point with Q not +// time-like or below the threshold of the last two masses gets zero weight. +// p_ext[0], p_ext[1] are the massless beams. +template +KERNELSPEC void kernel_chili_forward_fixed( + FIn r, + FIn e_cm, + FIn m_out, + FSIn pt_min, + FSIn y_max, + FOut p_ext, + FOut det +) { + FVal _e_cm(e_cm); + auto n_out = m_out.size(); + auto k = n_out - 2; + FVal mass_sum(0.); + for (std::size_t i = 0; i < n_out; ++i) { + mass_sum = mass_sum + FVal(m_out[i]); + } + auto head = chili_head_forward( + r, k, 0, k, 2 * k, _e_cm, m_out, pt_min, y_max, p_ext, mass_sum + ); + + // the decay of Q into the last two + FourMom q{_e_cm - head.e, -head.px, -head.py, -head.pz}; + auto q_mass2 = lsquare(q); + FVal m1(m_out[n_out - 2]), m2(m_out[n_out - 1]); + auto physical = (q[0] > 0.) & (q_mass2 > 0.); + // an unphysical Q is replaced by one at rest above the threshold, which + // keeps the momenta finite + FourMom q_safe{ + where(physical, q[0], m1 + m2 + 1.), + where(physical, q[1], FVal(0.)), + where(physical, q[2], FVal(0.)), + where(physical, q[3], FVal(0.)) + }; + auto q_safe_mass2 = lsquare(q_safe); + auto m0 = sqrt(q_safe_mass2); + auto decay = two_body_decay(r[3 * k + 1], r[3 * k], m0, m1, m2); + auto p1_rest = decay.first; + auto e2_rest = 0.5 * (m0 - (m1 - m2) * (m1 + m2) / max(m0, FVal(EPS))); + FourMom p2_rest{max(e2_rest, 0.), -p1_rest[1], -p1_rest[2], -p1_rest[3]}; + auto p_out = + boost_two_body(p1_rest, m1 * m1, p2_rest, m2 * m2, q_safe, q_safe_mass2); + store_mom(p_ext[n_out], p_out.first); + store_mom(p_ext[n_out + 1], p_out.second); + + auto p_a = p_ext[0], p_b = p_ext[1]; + p_a[0] = 0.5 * _e_cm; + p_a[1] = 0.; + p_a[2] = 0.; + p_a[3] = 0.5 * _e_cm; + p_b[0] = 0.5 * _e_cm; + p_b[1] = 0.; + p_b[2] = 0.; + p_b[3] = -0.5 * _e_cm; + + det = where(physical, head.det * decay.second, FVal(0.)); +} + +template +KERNELSPEC void kernel_chili_inverse_fixed( + FIn p_ext, + FIn e_cm, + FIn m_out, + FSIn pt_min, + FSIn y_max, + FOut r, + FOut det +) { + FVal _e_cm(e_cm); + auto n_out = m_out.size(); + auto k = n_out - 2; + FVal mass_sum(0.); + for (std::size_t i = 0; i < n_out; ++i) { + mass_sum = mass_sum + FVal(m_out[i]); + } + auto head = chili_head_inverse( + p_ext, k, 0, k, 2 * k, _e_cm, m_out, pt_min, y_max, r, mass_sum + ); + + // the decay of Q = p1 + p2 into the last two, in its rest frame + auto p1 = load_mom(p_ext[n_out]), p2 = load_mom(p_ext[n_out + 1]); + FourMom q; + for (int i = 0; i < 4; ++i) { + q[i] = p1[i] + p2[i]; + } + auto decay = two_body_decay_inverse(q, boost(p1, q, -1.), p2); + r[3 * k] = decay.second; + r[3 * k + 1] = decay.first; + det = head.det * decay.sixth; +} + } // namespace kernels } // namespace madspace diff --git a/madspace/src/kernels/kinematics.hpp b/madspace/src/kernels/kinematics.hpp index 5a15b26e3d..7050ef28d9 100644 --- a/madspace/src/kernels/kinematics.hpp +++ b/madspace/src/kernels/kinematics.hpp @@ -89,9 +89,11 @@ KERNELSPEC FVal kaellen(FVal x, FVal y, FVal z) { return xyz * xyz - 4 * y * z; } +// The range of |t| = -(pa - p1)^2 of pa pb -> p1 p2 at fixed masses, unclamped +// (see t_inv_min_max and t_inv_min_max_massive). template KERNELSPEC Pair, FVal> -t_inv_min_max(FVal s, FVal ma_2, FVal mb_2, FVal m1_2, FVal m2_2) { +t_inv_range(FVal s, FVal ma_2, FVal mb_2, FVal m1_2, FVal m2_2) { // |t| at cos(theta) = 1 and -1 in the rest frame of pa + pb is // (prod -+ yr) / (2 s) - ma^2 - m1^2, with prod = A B, A = s + ma^2 - mb^2, // B = s + m1^2 - m2^2 and yr = sqrt(lambda_a lambda_1). At the lower end @@ -112,15 +114,35 @@ t_inv_min_max(FVal s, FVal ma_2, FVal mb_2, FVal m1_2, FVal m2_2) 0.5 * (prod - yr) / s_pos - m_sum ); auto t_hi = 0.5 * (prod + yr) / s_pos - m_sum; - auto t_min_tmp = min(t_lo, t_hi); - auto t_max_tmp = max(t_lo, t_hi); - auto t_min = max(t_min_tmp, 0.); - // an empty range gets a width of at least 1e-14 |t_min|, since EPS can be below one - // ulp of t - auto t_max = where( - t_max_tmp > t_min, t_max_tmp, t_min + max(FVal(EPS), 1e-14 * fabs(t_min)) - ); - return {t_min, t_max}; + return {min(t_lo, t_hi), max(t_lo, t_hi)}; +} + +// an empty range gets a width of at least 1e-14 |t_min|, since EPS can be below one +// ulp of t +template +KERNELSPEC FVal t_max_nonempty(FVal t_min, FVal t_max) { + return where(t_max > t_min, t_max, t_min + max(FVal(EPS), 1e-14 * fabs(t_min))); +} + +// The |t| range for massless beams, where |t| >= 0, so that rounding cannot +// take its lower end below 0. +template +KERNELSPEC Pair, FVal> +t_inv_min_max(FVal s, FVal ma_2, FVal mb_2, FVal m1_2, FVal m2_2) { + auto range = t_inv_range(s, ma_2, mb_2, m1_2, m2_2); + auto t_min = max(range.first, 0.); + return {t_min, t_max_nonempty(t_min, range.second)}; +} + +// The |t| range with a massive beam among pa, pb: then |t| < 0 is reached +// near the forward direction, e.g. |t| = -(ma - m1)^2 for p1 at rest relative +// to pa, and the range is not clamped at 0. +template +KERNELSPEC Pair, FVal> t_inv_min_max_massive( + FVal s, FVal ma_2, FVal mb_2, FVal m1_2, FVal m2_2 +) { + auto range = t_inv_range(s, ma_2, mb_2, m1_2, m2_2); + return {range.first, t_max_nonempty(range.first, range.second)}; } template @@ -146,6 +168,23 @@ t2_inv_min_max_doublet(FVal s, FVal m1_2, FVal mir_min_2, FVal t1_ab return {t2_min, t2_max}; } +// The range of the light-cone component p1_- = E1 -+ pz1 of the double-t single +// particle against either beam that the transverse-energy floors of it and its +// recoil leave, [Eimax - pzmax, Eimax + pzmax], in the rest frame of the two +// beams (AmpliCol double_t). Returns sqrt(s), Eimax and pzmax. +template +KERNELSPEC Triplet, FVal, FVal> +doublet_etmin_light_cone(FVal s, FVal etmin_i, FVal etmin_ir) { + auto sqrt_s = sqrt(max(s, EPS)); + auto ei2 = etmin_i * etmin_i; + auto eir2 = etmin_ir * etmin_ir; + auto lam = s * s + ei2 * ei2 + eir2 * eir2 - 2.0 * s * ei2 - 2.0 * ei2 * eir2 - + 2.0 * eir2 * s; + auto pzmax = sqrt(max(lam, 0.)) / (2.0 * sqrt_s); + auto Eimax = sqrt_s - sqrt(max(eir2 + pzmax * pzmax, 0.)); + return {sqrt_s, Eimax, pzmax}; +} + // ETmin floor on the double-t central single particle (mass^2 m1_2) and its recoil // system, ported from AmpliCol double_t. AmpliCol writes signed-t (lines 605-608); // we work in |t| = -t, so its tmin=max/tmax=min map to our |t|_min/|t|_max with both @@ -159,13 +198,8 @@ KERNELSPEC Pair, FVal> doublet_t1_etmin_clamp( FVal etmin_i, FVal etmin_ir ) { - auto sqrt_s = sqrt(max(s, EPS)); - auto ei2 = etmin_i * etmin_i; - auto eir2 = etmin_ir * etmin_ir; - auto lam = s * s + ei2 * ei2 + eir2 * eir2 - 2.0 * s * ei2 - 2.0 * ei2 * eir2 - - 2.0 * eir2 * s; - auto pzmax = sqrt(max(lam, 0.)) / (2.0 * sqrt_s); - auto Eimax = sqrt_s - sqrt(max(eir2 + pzmax * pzmax, 0.)); + auto light_cone = doublet_etmin_light_cone(s, etmin_i, etmin_ir); + auto sqrt_s = light_cone.first, Eimax = light_cone.second, pzmax = light_cone.third; auto cut_min = sqrt_s * (Eimax - pzmax) - m1_2; auto cut_max = sqrt_s * (Eimax + pzmax) - m1_2; auto active = (etmin_i > EPS) | (etmin_ir > EPS); @@ -635,51 +669,92 @@ KERNELSPEC void kernel_com_p_in(FIn e_cm, FOut p1, FOut p2) { p2[3] = -p_com; } -// The incoming momenta of an event on their mass shell, keeping their sum and -// directions; the ratio s_hat / sqrt(lambda(s_hat, m1^2, m2^2)) of the massive -// flux to the massless one, zero below threshold. madevent's genps.f has -// massive incoming particles so (mom2cx and its flux), the phase-space -// mappings build them massless. +// The two incoming momenta in their centre-of-mass frame on the mass shells m1, +// m2, the first along +z, as madevent's mom2cx builds massive incoming +// particles (genps.f): E1,2 = (s + m1,2^2 - m2,1^2) / (2 sqrt(s)) and +// p = sqrt(lambda(s, m1^2, m2^2)) / (2 sqrt(s)), with p = 0 below the +// threshold (m1 + m2)^2, where there is no such pair. +template +KERNELSPEC void kernel_com_p_in_massive( + FIn e_cm, FSIn masses, FOut p1, FOut p2 +) { + auto m1 = fabs(FVal(masses[0])), m2 = fabs(FVal(masses[1])); + FVal e = e_cm; + auto s = e * e; + auto s_safe = where(s > 0., s, FVal(1.)); + auto half = 0.5 * e; + auto delta = (m1 * m1 - m2 * m2) / s_safe; + auto p_com = half * + sqrt(max( + (1. - (m1 + m2) * (m1 + m2) / s_safe) * + (1. - (m1 - m2) * (m1 - m2) / s_safe), + 0. + )); + p1[0] = half * (1. + delta); + p1[1] = 0.; + p1[2] = 0.; + p1[3] = p_com; + p2[0] = half * (1. - delta); + p2[1] = 0.; + p2[2] = 0.; + p2[3] = -p_com; +} + +// The two incoming momenta of an event, along the beam axis, put on the mass +// shells m1, m2 with their sum kept, and with it s and the rapidity of the +// pair. In the rest frame of the pair each keeps the direction it had, as +// madevent's mom2cx builds massive incoming particles (genps.f). Built in the +// light-cone components P_+- = sum of E +- p_z of the pair: the boost from its +// rest frame has exp(y) = sqrt(P_+ / P_-), and each momentum gets its large +// component from the two-body kinematics, E* + p* = u sqrt(s), and its small +// one from the mass shell, m^2 / (E* + p*), so that it keeps its relative +// precision at any rapidity. With the masses 0 this turns a massive pair back +// into the massless one with the same sum. The outgoing momenta are copied. +// above_threshold is 1 for s = P_+ P_- > (m1 + m2)^2, else 0 (and the pair is +// then built with p* = 0, which does not keep its sum). template KERNELSPEC void kernel_incoming_on_shell( - FIn p_ext, FIn masses, FOut p_out, FOut flux_ratio + FIn p_ext, FSIn masses, FOut p_out, FOut above_threshold ) { - using F = FVal; - for (std::size_t i = 0; i < p_ext.size(); ++i) { + for (std::size_t i = 2; i < p_ext.size(); ++i) { for (std::size_t j = 0; j < 4; ++j) { - p_out[i][j] = static_cast(p_ext[i][j]); + p_out[i][j] = FVal(p_ext[i][j]); } } - F m1 = masses[0], m2 = masses[1]; - F e_a = p_ext[0][0], z_a = p_ext[0][3]; - F e_b = p_ext[1][0], z_b = p_ext[1][3]; - F e_tot = e_a + e_b, z_tot = z_a + z_b; - F s = e_tot * e_tot - z_tot * z_tot; - F threshold = (m1 + m2) * (m1 + m2); - if (!(s > threshold) || !(e_tot > 0.)) { - flux_ratio = 0.; - return; - } - F sqrt_s = sqrt(s); - F lambda = (s - threshold) * (s - (m1 - m2) * (m1 - m2)); - F p_cm = sqrt(lambda) / (2. * sqrt_s); - F e1 = (s + m1 * m1 - m2 * m2) / (2. * sqrt_s); - F e2 = (s + m2 * m2 - m1 * m1) / (2. * sqrt_s); - // the boost from the rest frame of the pair to the frame of p_ext - F cosh_y = e_tot / sqrt_s, sinh_y = z_tot / sqrt_s; - // direction of the first incoming particle in the rest frame - F z_a_cm = cosh_y * z_a - sinh_y * e_a; - F sign = z_a_cm >= 0. ? 1. : -1.; - F z1 = sign * p_cm, z2 = -sign * p_cm; - p_out[0][0] = cosh_y * e1 + sinh_y * z1; + auto m1 = fabs(FVal(masses[0])), m2 = fabs(FVal(masses[1])); + FVal e_a(p_ext[0][0]), z_a(p_ext[0][3]); + FVal e_b(p_ext[1][0]), z_b(p_ext[1][3]); + auto plus_a = e_a + z_a, minus_a = e_a - z_a; + auto plus = plus_a + (e_b + z_b); + auto minus = minus_a + (e_b - z_b); + auto s = plus * minus; + auto threshold = (m1 + m2) * (m1 + m2); + auto above = s > threshold; + auto s_safe = where(s > 0., s, FVal(1.)); + auto root = sqrt(max((s - threshold) * (s - (m1 - m2) * (m1 - m2)), 0.)); + // (E* + p*) / sqrt(s) of each in the rest frame of the pair + auto delta = (m1 * m1 - m2 * m2) / s_safe; + auto u1 = 0.5 * (1. + delta + root / s_safe); + auto u2 = 0.5 * (1. - delta + root / s_safe); + // the first one moves along +z in the rest frame where its rapidity is + // above that of the pair, (E + p_z) / (E - p_z) > P_+ / P_- + auto forward = plus_a * minus >= minus_a * plus; + // large light-cone components: P_+ u along +z, P_- u along -z + auto big1 = where(forward, plus, minus) * u1; + auto big2 = where(forward, minus, plus) * u2; + auto small1 = m1 * m1 / big1; + auto small2 = m2 * m2 / big2; + auto plus1 = where(forward, big1, small1), minus1 = where(forward, small1, big1); + auto plus2 = where(forward, small2, big2), minus2 = where(forward, big2, small2); + p_out[0][0] = 0.5 * (plus1 + minus1); p_out[0][1] = 0.; p_out[0][2] = 0.; - p_out[0][3] = cosh_y * z1 + sinh_y * e1; - p_out[1][0] = cosh_y * e2 + sinh_y * z2; + p_out[0][3] = 0.5 * (plus1 - minus1); + p_out[1][0] = 0.5 * (plus2 + minus2); p_out[1][1] = 0.; p_out[1][2] = 0.; - p_out[1][3] = cosh_y * z2 + sinh_y * e2; - flux_ratio = s / sqrt(lambda); + p_out[1][3] = 0.5 * (plus2 - minus2); + above_threshold = where(above, FVal(1.), FVal(0.)); } template @@ -821,6 +896,35 @@ KERNELSPEC void kernel_diff_cross_section( (2. * e_cm2 * x1 * x1 * x2 * x2); } +// kernel_diff_cross_section with massive incoming particles: the flux +// 1 / (2 sqrt(lambda(s_hat, m1^2, m2^2))) with s_hat = x1 x2 e_cm2 in place of +// 1 / (2 s_hat), as madevent's genps.f, zero at and below the threshold +// (m1 + m2)^2. pdf1, pdf2 are x f(x) as there. +template +KERNELSPEC void kernel_diff_cross_section_massive( + FIn x1, + FIn x2, + FIn pdf1, + FIn pdf2, + FIn matrix_element, + FSIn e_cm2, + FSIn masses, + FOut result +) { + auto m1 = fabs(FVal(masses[0])), m2 = fabs(FVal(masses[1])); + FVal x_1 = x1, x_2 = x2; + auto s_hat = x_1 * x_2 * e_cm2; + auto threshold = (m1 + m2) * (m1 + m2); + auto above = s_hat > threshold; + auto lambda = (s_hat - threshold) * (s_hat - (m1 - m2) * (m1 - m2)); + auto root = sqrt(where(above, lambda, FVal(1.))); + result = where( + above, + INV_GEV2_TO_PB * matrix_element * pdf1 * pdf2 / (2. * x_1 * x_2 * root), + FVal(0.) + ); +} + template KERNELSPEC void kernel_t_inv_min_max( FIn pa, @@ -927,14 +1031,14 @@ KERNELSPEC void kernel_t_inv_value( // particle 2 == single peeled jet "i" (mass^2 m2_2, ETmin floor etmin_2) // t is measured w.r.t. beam a: t = (pa - p1)^2 = (pb - p2)^2, so the angle->|t| // offset carries the recoil mass^2 (m1). +// The two-body range behind it, in the frame where p_tot has p_z = 0 (its +// transverse mass piir0 as energy): the light-cone component of the recoil +// against the beam axis lies in [base - rootsq, base + rootsq] / (2 piir0), for +// a recoil of transverse mass at least eff_1. Returns piir0, base, rootsq and +// eff_1. template -KERNELSPEC Pair, FVal> t_cut_bounds_etmin( - FourMom p_tot, - FourMom pa, - FVal m1_2, - FVal m2_2, - FVal etmin_1, - FVal etmin_2 +KERNELSPEC Quartuplet, FVal, FVal, FVal> t_cut_etmin_range( + FourMom p_tot, FVal m1_2, FVal m2_2, FVal etmin_1, FVal etmin_2 ) { // squared masses recomputed from momenta (inverse direction) can be slightly // negative; clamp them so that the square roots below cannot give NaN @@ -943,7 +1047,6 @@ KERNELSPEC Pair, FVal> t_cut_bounds_etmin( auto pt_tot2 = p_tot[1] * p_tot[1] + p_tot[2] * p_tot[2]; auto s = lsquare(p_tot); auto piir0 = sqrt(max(s, 0.) + pt_tot2); - auto ppa0 = (p_tot[0] * pa[0] - p_tot[3] * pa[3]) / piir0; // peeled jet (2): pt floor^2 = etmin_2^2 - m2^2; recoil (1) floor corrected // for the system's own pt. auto pt2_floor = etmin_2 * etmin_2 - m2_2; @@ -954,13 +1057,76 @@ KERNELSPEC Pair, FVal> t_cut_bounds_etmin( auto base = piir0 * piir0 - eff_2 * eff_2 + eff_1 * eff_1; auto root = (piir0 - eff_2 - eff_1) * (piir0 + eff_2 - eff_1) * (piir0 - eff_2 + eff_1) * (piir0 + eff_2 + eff_1); - auto rootsq = sqrt(max(root, 0.)); + return {piir0, base, sqrt(max(root, 0.)), eff_1}; +} + +template +KERNELSPEC Pair, FVal> t_cut_bounds_etmin( + FourMom p_tot, + FourMom pa, + FVal m1_2, + FVal m2_2, + FVal etmin_1, + FVal etmin_2 +) { + auto range = t_cut_etmin_range(p_tot, m1_2, m2_2, etmin_1, etmin_2); + auto piir0 = range.first, base = range.second, rootsq = range.third; + auto ppa0 = (p_tot[0] * pa[0] - p_tot[3] * pa[3]) / piir0; auto ratio = ppa0 / piir0; // signed-t -> |t|: min uses (base - root), max uses (base + root); the // angle->|t| offset carries the recoil mass^2 (m1). + m1_2 = max(m1_2, 0.); return {ratio * (base - rootsq) - m1_2, ratio * (base + rootsq) - m1_2}; } +// The least value of pa_big c + pa_small e^2 / c over c >= c_lo, the light-cone +// part of 2 pa.p1 for a p1 of transverse mass at least e whose component +// against pa is c: 2 e ma at c = e ma / pa_big if that lies above c_lo, else +// its value at c_lo. For a massless pa it is pa_big c_lo. +template +KERNELSPEC FVal +least_light_cone_product(FVal pa_big, FVal ma_2, FVal c_lo, FVal e) { + auto pa_small = ma_2 / max(pa_big, FVal(EPS)); + auto ma = sqrt(ma_2); + auto at_c_lo = pa_big * c_lo + pa_small * e * e / max(c_lo, FVal(EPS)); + return where(e * ma > pa_big * c_lo, 2. * e * ma, at_c_lo); +} + +// The ETmin bounds of t_cut_bounds_etmin for a massive pa along the beam +// axis. With light-cone components along pa, in the frame where p_tot has +// p_z = 0, +// |t| = 2 pa.p1 - ma^2 - m1^2, 2 pa.p1 = pa_big c + pa_small q, +// with c = p1_small in [c_lo, c_hi] = [base -+ rootsq] / (2 piir0) of +// t_cut_etmin_range and q = p1_big = m_T(p1)^2 / c, where m_T(p1) >= eff_1 and +// q <= P_big = piir0. The lower end is least_light_cone_product at c_lo, the +// upper one pa_big c_hi + pa_small piir0. For ma = 0 these are the bounds of +// t_cut_bounds_etmin. Floors that no recoil meets (rootsq = 0) give an empty +// range, as for massless beams, also for a massless pa whose ma^2 is rounding. +template +KERNELSPEC Pair, FVal> t_cut_bounds_etmin_massive( + FourMom p_tot, + FourMom pa, + FVal ma_2, + FVal m1_2, + FVal m2_2, + FVal etmin_1, + FVal etmin_2 +) { + auto range = t_cut_etmin_range(p_tot, m1_2, m2_2, etmin_1, etmin_2); + auto piir0 = range.first, base = range.second, rootsq = range.third; + // pa in the frame where p_tot has p_z = 0 + auto e_a = (p_tot[0] * pa[0] - p_tot[3] * pa[3]) / piir0; + auto z_a = (p_tot[0] * pa[3] - p_tot[3] * pa[0]) / piir0; + auto pa_big = e_a + fabs(z_a); + ma_2 = max(ma_2, 0.); + auto offset = ma_2 + max(m1_2, 0.); + auto c_lo = (base - rootsq) / (2. * piir0), c_hi = (base + rootsq) / (2. * piir0); + auto lower = least_light_cone_product(pa_big, ma_2, c_lo, range.fourth); + auto upper = pa_big * c_hi + ma_2 / max(pa_big, FVal(EPS)) * piir0; + upper = where(rootsq > 0., upper, lower); + return {lower - offset, upper - offset}; +} + // Clamp the kinematic |t| range against the ETmin cut interval. Returns the // bounds on the absolute (positive) t invariant. The ETmin bound only improves // sampling; the real cut is applied on the final momenta. @@ -1282,6 +1448,207 @@ KERNELSPEC void kernel_t_inv_value_and_min_max_cut( t_abs = -t_temp; } +// Massive beams: the 2 -> 2 blocks of a t-channel chain whose incoming momenta +// include a massive beam use these instead of the kernels above, chosen when +// the graph is built (see TwoToTwoParticleScattering), which leaves the +// massless ones as they are. + +template +KERNELSPEC void kernel_t_inv_min_max_massive( + FIn pa, + FIn pb, + FIn m1, + FIn m2, + FOut t_min, + FOut t_max +) { + FourMom p_tot; + for (int i = 0; i < 4; ++i) { + p_tot[i] = pa[i] + pb[i]; + } + auto s = lsquare(p_tot); + auto ma_2 = lsquare(load_mom(pa)); + auto mb_2 = lsquare(load_mom(pb)); + auto t_min_max = t_inv_min_max_massive(s, ma_2, mb_2, m1 * m1, m2 * m2); + t_min = t_min_max.first; + t_max = t_min_max.second; +} + +template +KERNELSPEC void kernel_t_inv_value_and_min_max_massive( + FIn pa, + FIn pb, + FIn p1, + FIn p2, + FOut t_abs, + FOut t_min, + FOut t_max +) { + FourMom pa1, p_tot; + for (int i = 0; i < 4; ++i) { + pa1[i] = pa[i] - p1[i]; + p_tot[i] = pa[i] + pb[i]; + } + auto t_min_max = t_inv_min_max_massive( + lsquare(p_tot), + lsquare(load_mom(pa)), + lsquare(load_mom(pb)), + lsquare(load_mom(p1)), + lsquare(load_mom(p2)) + ); + t_min = t_min_max.first; + t_max = t_min_max.second; + t_abs = -lsquare(pa1); +} + +// The massive |t| range narrowed by the ETmin floors, where pa lies along the +// beam axis and is not space-like (t_cut_bounds_etmin_massive). If that leaves +// nothing, the kinematic range is returned. +template +KERNELSPEC Pair, FVal> t_min_max_cut_massive( + FourMom pa, + FourMom pb, + FVal m1_2, + FVal m2_2, + FVal etmin_1, + FVal etmin_2 +) { + FourMom p_tot; + for (int i = 0; i < 4; ++i) { + p_tot[i] = pa[i] + pb[i]; + } + auto ma_2 = lsquare(pa); + auto range = + t_inv_min_max_massive(lsquare(p_tot), ma_2, lsquare(pb), m1_2, m2_2); + auto cut = + t_cut_bounds_etmin_massive(p_tot, pa, ma_2, m1_2, m2_2, etmin_1, etmin_2); + auto pa0_2 = pa[0] * pa[0]; + auto on_axis = + (pa[1] * pa[1] + pa[2] * pa[2] <= 1e-9 * pa0_2) & (ma_2 >= -1e-12 * pa0_2); + auto lo = where(on_axis, max(range.first, cut.first), range.first); + auto hi = where(on_axis, min(range.second, cut.second), range.second); + auto ok = hi > lo; + return {where(ok, lo, range.first), where(ok, hi, range.second)}; +} + +template +KERNELSPEC void kernel_t_inv_min_max_cut_massive( + FIn pa, + FIn pb, + FIn m1, + FIn m2, + FIn etmin_1, + FIn etmin_2, + FOut t_min, + FOut t_max +) { + auto t_min_max = t_min_max_cut_massive( + load_mom(pa), load_mom(pb), m1 * m1, m2 * m2, etmin_1, etmin_2 + ); + t_min = t_min_max.first; + t_max = t_min_max.second; +} + +template +KERNELSPEC void kernel_t_inv_value_and_min_max_cut_massive( + FIn pa, + FIn pb, + FIn p1, + FIn p2, + FIn etmin_1, + FIn etmin_2, + FOut t_abs, + FOut t_min, + FOut t_max +) { + FourMom pa1; + for (int i = 0; i < 4; ++i) { + pa1[i] = pa[i] - p1[i]; + } + auto t_min_max = t_min_max_cut_massive( + load_mom(pa), + load_mom(pb), + lsquare(load_mom(p1)), + lsquare(load_mom(p2)), + etmin_1, + etmin_2 + ); + t_min = t_min_max.first; + t_max = t_min_max.second; + t_abs = -lsquare(pa1); +} + +// kernel_t_rapidity_clamp for massive beams pa, pb. In the rest frame of +// pa + pb, with pa along +z, +// E_b = A / (2 sqrt(s)), p = R / (2 sqrt(s)), E_1,2 = B', B / (2 sqrt(s)), +// A = s + mb^2 - ma^2, R = sqrt(lambda(s, ma^2, mb^2)), +// B = s + m2^2 - m1^2, B' = s + m1^2 - m2^2, +// and |t| = 2 w - mb^2 - m2^2 with w = pb.p2 = E_b E_2 + p z_2. The rapidity +// along pa of a momentum q is atanh(q_z / E_q), so a bound y on that of p2 +// (the peeled particle) gives +// w = E_2 (E_b + p tanh(y)) = E_2 (mb^2 / (E_b + p) + 2 p logistic(2 y)), +// increasing in y, and one on that of p1 (the recoil, z_1 = -z_2) +// w = E_b E_2 - p E_1 tanh(y) = c + 2 p E_1 logistic(-2 y), +// c = E_b E_2 - p E_1 = (A^2 (m2^2 - m1^2) + mb^2 B'^2) / (A B + R B'), +// decreasing in y, both written so that no terms of order s cancel. For +// ma = mb = 0 they are the w of kernel_t_rapidity_clamp, and the lab rapidity, +// unused bounds and an empty result are handled as there. +template +KERNELSPEC void kernel_t_rapidity_clamp_massive( + FIn t_min, + FIn t_max, + FIn pa, + FIn pb, + FIn m1, + FIn m2, + FIn x1, + FIn x2, + FSIn beam_sign, + FSIn y_max1, + FSIn y_max2, + FOut t_min_out, + FOut t_max_out +) { + FourMom p_tot; + for (int i = 0; i < 4; ++i) { + p_tot[i] = pa[i] + pb[i]; + } + auto s = lsquare(p_tot); + auto ma_2 = lsquare(load_mom(pa)), mb_2 = lsquare(load_mom(pb)); + auto m1_2 = m1 * m1, m2_2 = m2 * m2; + auto sqrt_s = sqrt(max(s, EPS)); + auto a = s + mb_2 - ma_2; + auto r = sqrt(max(kaellen(s, ma_2, mb_2), 0.)); + auto b = s + m2_2 - m1_2, b_prime = s + m1_2 - m2_2; + auto e_b = a / (2. * sqrt_s), p = r / (2. * sqrt_s); + auto e_1 = b_prime / (2. * sqrt_s), e_2 = b / (2. * sqrt_s); + auto e_b_minus_p = mb_2 / max(e_b + p, FVal(EPS)); + auto c = (a * a * (m2_2 - m1_2) + mb_2 * b_prime * b_prime) / + max(a * b + r * b_prime, FVal(EPS)); + auto y_boost = beam_sign * 0.5 * log(x1 / x2); + + auto on1 = rapidity_bound_on(y_max1), on2 = rapidity_bound_on(y_max2); + + // bounds on w, turned into |t| = 2 w - mb^2 - m2^2 before they meet the + // input range (see kernel_t_rapidity_clamp) + FVal lo = t_min, hi = t_max; + auto offset = mb_2 + m2_2; + // peeled particle, increasing in its rapidity + auto w_lo2 = e_2 * (e_b_minus_p + 2. * p * logistic(2. * (-y_max2 - y_boost))); + auto w_hi2 = e_2 * (e_b_minus_p + 2. * p * logistic(2. * (y_max2 - y_boost))); + lo = where(on2, max(lo, 2. * w_lo2 - offset), lo); + hi = where(on2, min(hi, 2. * w_hi2 - offset), hi); + // recoil, decreasing in its rapidity + auto w_lo1 = c + 2. * p * e_1 * logistic(-2. * (y_max1 - y_boost)); + auto w_hi1 = c + 2. * p * e_1 * logistic(-2. * (-y_max1 - y_boost)); + lo = where(on1, max(lo, 2. * w_lo1 - offset), lo); + hi = where(on1, min(hi, 2. * w_hi1 - offset), hi); + + auto ok = hi > lo; + t_min_out = where(ok, lo, FVal(t_min)); + t_max_out = where(ok, hi, FVal(t_max)); +} + template KERNELSPEC void kernel_invariants_from_momenta( FIn p_ext, FSIn factors, FOut invariants @@ -1411,6 +1778,424 @@ KERNELSPEC void kernel_t2_inv_value_and_min_max_doublet( t_abs = -lsquare(pb1); } +// Massive beams in the double-t block pa pb -> p1 X. The kernels below replace +// the ones above when the beams are massive, chosen when the graph is built +// (see DoubleT), which leaves the massless ones as they are. +// +// In the rest frame of pa + pb with pa along +z, the light-cone components +// (x_+, x_-) = (E + p_z, E - p_z) of the beams are pa = (a_big, a_small) and +// pb = (b_small, b_big), with big = E + |p| and small = m^2 / big, and +// a_big b_big - a_small b_small = sqrt(lambda(s, ma^2, mb^2)) = root. For p1, +// ta = 2 pa.p1 = |t1| + ma^2 + m1^2 = a_big x_- + a_small x_+, +// tb = 2 pb.p1 = |t2| + mb^2 + m1^2 = b_big x_+ + b_small x_-, +// which give x_+ = (a_big tb - b_small ta) / root and +// x_- = (b_big ta - a_small tb) / root. +template +struct BeamLightCone { + FVal s, sqrt_s, ma_2, mb_2, root, a_big, a_small, b_big, b_small; +}; + +template +KERNELSPEC BeamLightCone beam_light_cone(FourMom pa, FourMom pb) { + FourMom p_tot; + for (int i = 0; i < 4; ++i) { + p_tot[i] = pa[i] + pb[i]; + } + auto s = lsquare(p_tot); + auto sqrt_s = sqrt(max(s, EPS)); + auto ma_2 = max(lsquare(pa), 0.), mb_2 = max(lsquare(pb), 0.); + auto root = sqrt(max(kaellen(s, ma_2, mb_2), 0.)); + auto a_big = (s + ma_2 - mb_2 + root) / (2. * sqrt_s); + auto b_big = (s + mb_2 - ma_2 + root) / (2. * sqrt_s); + return { + s, + sqrt_s, + ma_2, + mb_2, + root, + a_big, + ma_2 / max(a_big, FVal(EPS)), + b_big, + mb_2 / max(b_big, FVal(EPS)) + }; +} + +// The |t1| range of the double-t block off massive beams, over every recoil +// mass m_X >= mir_min. Its upper end is that of pa pb -> p1 X at m_X = mir_min. +// So is its lower end, unless p1 can move with the velocity of pa, where +// pa.p1 = ma m1 is least and |t1| = -(ma - m1)^2: that needs the energy +// m1 E_a / ma at most the largest one, (s + m1^2 - mir_min^2) / (2 sqrt(s)). +template +KERNELSPEC Pair, FVal> +t1_inv_min_max_doublet_massive(BeamLightCone lc, FVal m1_2, FVal mir_min_2) { + auto range = t_inv_range(lc.s, lc.ma_2, lc.mb_2, m1_2, mir_min_2); + auto ma = sqrt(lc.ma_2), m1 = sqrt(max(m1_2, 0.)); + auto co_moving = m1 * (lc.s + lc.ma_2 - lc.mb_2) <= ma * (lc.s + m1_2 - mir_min_2); + auto t_min = where(co_moving, -(ma - m1) * (ma - m1), range.first); + return {t_min, t_max_nonempty(t_min, range.second)}; +} + +// The ETmin bound of doublet_t1_etmin_clamp for massive beams. In ta = +// a_big x_- + a_small x_+, x_- lies in [Eimax - pzmax, Eimax + pzmax] of +// doublet_etmin_light_cone and x_+ = m_T(p1)^2 / x_- <= sqrt(s), with +// m_T(p1) >= etmin_i: least_light_cone_product below, a_big (Eimax + pzmax) + +// a_small sqrt(s) above. For massless beams these are the bounds of +// doublet_t1_etmin_clamp. Floors that no p1 meets (pzmax = 0) give an empty +// range, as for massless beams, also for a massless pa whose ma^2 is rounding. +template +KERNELSPEC Pair, FVal> doublet_t1_etmin_clamp_massive( + FVal t_min, + FVal t_max, + BeamLightCone lc, + FVal m1_2, + FVal etmin_i, + FVal etmin_ir +) { + auto light_cone = doublet_etmin_light_cone(lc.s, etmin_i, etmin_ir); + auto x_lo = light_cone.second - light_cone.third; + auto x_hi = light_cone.second + light_cone.third; + auto mt = max(etmin_i, sqrt(max(m1_2, 0.))); + auto offset = lc.ma_2 + m1_2; + auto cut_min = least_light_cone_product(lc.a_big, lc.ma_2, x_lo, mt) - offset; + auto cut_max = lc.a_big * x_hi + lc.a_small * lc.sqrt_s - offset; + cut_max = where(light_cone.third > 0., cut_max, cut_min); + auto active = (etmin_i > EPS) | (etmin_ir > EPS); + auto lo = where(active, max(t_min, cut_min), t_min); + auto hi = where(active, min(t_max, cut_max), t_max); + auto ok = hi > lo; + return {where(ok, lo, t_min), where(ok, hi, t_max)}; +} + +// The least and largest tb at fixed ta for a p1 of transverse mass^2 at least +// mt_2. With x_+ x_- >= mt_2 (see above), tb lies between the roots of +// ma^2 tb^2 - sigma ta tb + mb^2 ta^2 + lambda mt_2 = 0, sigma = s - ma^2 - mb^2, +// the lower one written without cancellations, the upper one infinite for a +// massless pa. For massless beams the lower one is s mt_2 / ta. +template +KERNELSPEC Pair, FVal> +doublet_tb_roots(BeamLightCone lc, FVal ta, FVal mt_2) { + auto sigma = lc.s - lc.ma_2 - lc.mb_2; + auto disc = lc.root * sqrt(max(ta * ta - 4. * lc.ma_2 * mt_2, 0.)); + auto sum = ta * sigma + disc; + auto lower = + 2. * (ta * ta * lc.mb_2 + lc.root * lc.root * mt_2) / max(sum, FVal(EPS)); + auto upper = + where(lc.ma_2 > 0., sum / (2. * max(lc.ma_2, FVal(EPS))), FVal(1e300)); + return {lower, upper}; +} + +// The |t2| range of the double-t block off massive beams at fixed |t1|: tb from +// p1 on its mass shell (doublet_tb_roots) and at most the value at which the +// recoil has the mass mir_min, tb = s + m1^2 - mir_min^2 - ta. +template +KERNELSPEC Pair, FVal> t2_inv_min_max_doublet_massive( + BeamLightCone lc, FVal m1_2, FVal mir_min_2, FVal t1_abs +) { + auto ta = t1_abs + lc.ma_2 + m1_2; + auto roots = doublet_tb_roots(lc, ta, m1_2); + auto offset = lc.mb_2 + m1_2; + auto t2_min = roots.first - offset; + auto t2_max = min(roots.second, lc.s + m1_2 - mir_min_2 - ta) - offset; + return {t2_min, t_max_nonempty(t2_min, t2_max)}; +} + +// The ETmin bound of doublet_t2_etmin_clamp for massive beams at fixed ta. From +// below, p1 has a transverse mass of at least etmin_i, which raises the lower +// root of doublet_tb_roots. From above, the recoil P - p1 has one of at least +// etmin_ir: with x_+-(tb) of beam_light_cone, +// (sqrt(s) - x_+) (sqrt(s) - x_-) root^2 = (P1 - a_big tb) (Q1 + a_small tb), +// P1 = sqrt(s) root + b_small ta, Q1 = sqrt(s) root - b_big ta, +// at least etmin_ir^2 root^2, a quadratic in tb that opens downwards: tb is +// at most its upper root, written without cancellations. For massless beams +// both ends are those of doublet_t2_etmin_clamp. +template +KERNELSPEC Pair, FVal> doublet_t2_etmin_clamp_massive( + FVal t_min, + FVal t_max, + BeamLightCone lc, + FVal m1_2, + FVal t1_abs, + FVal etmin_i, + FVal etmin_ir +) { + auto ta = t1_abs + lc.ma_2 + m1_2; + auto offset = lc.mb_2 + m1_2; + auto mt_2 = max(etmin_i * etmin_i, m1_2); + auto cut_min = doublet_tb_roots(lc, ta, mt_2).first - offset; + // ma^2 tb^2 - b tb - c <= 0 + auto sqrt_s_root = lc.sqrt_s * lc.root; + auto p1 = sqrt_s_root + lc.b_small * ta, q1 = sqrt_s_root - lc.b_big * ta; + auto b = p1 * lc.a_small - lc.a_big * q1; + auto c = p1 * q1 - etmin_ir * etmin_ir * lc.root * lc.root; + auto disc = sqrt(max(b * b + 4. * lc.ma_2 * c, 0.)); + auto upper = where( + b < 0., + 2. * c / max(disc - b, FVal(EPS)), + (b + disc) / (2. * max(lc.ma_2, FVal(EPS))) + ); + auto cut_max = upper - offset; + auto lo = where(etmin_i > EPS, max(t_min, cut_min), t_min); + auto hi = where(etmin_ir > EPS, min(t_max, cut_max), t_max); + auto ok = hi > lo; + return {where(ok, lo, t_min), where(ok, hi, t_max)}; +} + +template +KERNELSPEC void kernel_t1_inv_min_max_doublet_massive( + FIn pa, + FIn pb, + FIn m1, + FIn mir_min, + FIn etmin_i, + FIn etmin_ir, + FOut t_min, + FOut t_max +) { + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto bounds = t1_inv_min_max_doublet_massive(lc, m1_2, mir_min * mir_min); + auto c = doublet_t1_etmin_clamp_massive( + bounds.first, bounds.second, lc, m1_2, etmin_i, etmin_ir + ); + t_min = c.first; + t_max = c.second; +} + +template +KERNELSPEC void kernel_t1_inv_value_and_min_max_doublet_massive( + FIn pa, + FIn pb, + FIn p1, + FIn m1, + FIn mir_min, + FIn etmin_i, + FIn etmin_ir, + FOut t_abs, + FOut t_min, + FOut t_max +) { + FourMom pa1; + for (int i = 0; i < 4; ++i) { + pa1[i] = pa[i] - p1[i]; + } + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto bounds = t1_inv_min_max_doublet_massive(lc, m1_2, mir_min * mir_min); + auto c = doublet_t1_etmin_clamp_massive( + bounds.first, bounds.second, lc, m1_2, etmin_i, etmin_ir + ); + t_min = c.first; + t_max = c.second; + t_abs = -lsquare(pa1); +} + +template +KERNELSPEC void kernel_t2_inv_min_max_doublet_massive( + FIn pa, + FIn pb, + FIn m1, + FIn mir_min, + FIn t1_abs, + FIn etmin_i, + FIn etmin_ir, + FOut t_min, + FOut t_max +) { + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto bounds = + t2_inv_min_max_doublet_massive(lc, m1_2, mir_min * mir_min, t1_abs); + auto c = doublet_t2_etmin_clamp_massive( + bounds.first, bounds.second, lc, m1_2, t1_abs, etmin_i, etmin_ir + ); + t_min = c.first; + t_max = c.second; +} + +template +KERNELSPEC void kernel_t2_inv_value_and_min_max_doublet_massive( + FIn pa, + FIn pb, + FIn p1, + FIn m1, + FIn mir_min, + FIn t1_abs, + FIn etmin_i, + FIn etmin_ir, + FOut t_abs, + FOut t_min, + FOut t_max +) { + FourMom pb1; + for (int i = 0; i < 4; ++i) { + pb1[i] = pb[i] - p1[i]; + } + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto bounds = + t2_inv_min_max_doublet_massive(lc, m1_2, mir_min * mir_min, t1_abs); + auto c = doublet_t2_etmin_clamp_massive( + bounds.first, bounds.second, lc, m1_2, t1_abs, etmin_i, etmin_ir + ); + t_min = c.first; + t_max = c.second; + t_abs = -lsquare(pb1); +} + +// tb on the lines of fixed rapidity in the double-t block off massive beams. +// A rapidity y along pa in the rest frame of pa + pb gives r = e^{2y} = +// x_+ / x_- for p1, and r = (sqrt(s) - x_+) / (sqrt(s) - x_-) for the recoil +// P - p1, which with x_+, x_- from ta, tb (see beam_light_cone) is +// p1: tb = beta ta, +// recoil: tb = alpha + beta ta, +// beta = (b_small + r b_big) / (a_big + r a_small), +// alpha = sqrt(s) root (1 - r) / (a_big + r a_small). +// tb rises with the rapidity of p1 and falls with that of the recoil. For +// massless beams, beta = r and alpha = s (1 - r). +template +KERNELSPEC Pair, FVal> doublet_tb_line(BeamLightCone lc, FVal r) { + auto den = lc.a_big + r * lc.a_small; + return {lc.sqrt_s * lc.root * (1. - r) / den, (lc.b_small + r * lc.b_big) / den}; +} + +// kernel_t1_rapidity_clamp_doublet for massive beams. The bounds on tb at fixed +// ta are lines (doublet_tb_line) and the kinematic ones, tb <= s + m1^2 - +// mir_min^2 - ta and the least tb of a p1 with x_- <= sqrt(s), +// tb >= min over x_- of (b_big m1^2 / x_- + b_small x_-), +// which is 2 m1 mb where p1 can move with the velocity of pb and m1^2 for +// massless beams. The transverse-energy floors bound ta itself: ta >= +// a_big x_- >= a_big etmin_1 e^{-y} for p1, and for the recoil, +// s + ma^2 - mb^2 - ta = 2 pa.(P - p1) >= a_big etmin_2 e^{-y}. The rest is as +// in kernel_t1_rapidity_clamp_doublet, in ta and then in |t1|. +template +KERNELSPEC void kernel_t1_rapidity_clamp_doublet_massive( + FIn t1_min, + FIn t1_max, + FIn pa, + FIn pb, + FIn m1, + FIn mir_min, + FIn etmin_1, + FIn etmin_2, + FIn x1, + FIn x2, + FSIn beam_sign, + FSIn y_max1, + FSIn y_max2, + FOut t1_min_out, + FOut t1_max_out +) { + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto y_boost = beam_sign * 0.5 * log(x1 / x2); + auto on1 = rapidity_bound_on(y_max1), on2 = rapidity_bound_on(y_max2); + auto line_lo1 = doublet_tb_line(lc, bounded_exp(2. * (-y_max1 - y_boost))); + auto line_hi1 = doublet_tb_line(lc, bounded_exp(2. * (y_max1 - y_boost))); + auto line_lo2 = doublet_tb_line(lc, bounded_exp(2. * (-y_max2 - y_boost))); + auto line_hi2 = doublet_tb_line(lc, bounded_exp(2. * (y_max2 - y_boost))); + + // the bounds on tb as alpha + beta ta; an inactive one is replaced by the + // kinematic bound of the same side + auto m1_abs = sqrt(max(m1_2, 0.)), mb = sqrt(lc.mb_2); + auto kin_lo = where( + m1_abs * lc.b_big <= mb * lc.sqrt_s, + 2. * m1_abs * mb, + lc.b_big * m1_2 / lc.sqrt_s + lc.b_small * lc.sqrt_s + ); + FVal lo_alpha[3] = { + kin_lo, where(on1, FVal(0.), kin_lo), where(on2, line_hi2.first, kin_lo) + }; + FVal lo_beta[3] = { + FVal(0.), + where(on1, line_lo1.second, FVal(0.)), + where(on2, line_hi2.second, FVal(0.)) + }; + auto kin_alpha = lc.s + m1_2 - mir_min * mir_min; + FVal hi_alpha[3] = { + kin_alpha, + where(on1, FVal(0.), kin_alpha), + where(on2, line_lo2.first, kin_alpha) + }; + FVal hi_beta[3] = { + FVal(-1.), + where(on1, line_hi1.second, FVal(-1.)), + where(on2, line_lo2.second, FVal(-1.)) + }; + + auto offset = lc.ma_2 + m1_2; + FVal lo = t1_min + offset, hi = t1_max + offset; + lo = where( + on1, max(lo, lc.a_big * etmin_1 * bounded_exp(-(y_max1 - y_boost))), lo + ); + hi = where( + on2, + min(hi, + lc.s + lc.ma_2 - lc.mb_2 - + lc.a_big * etmin_2 * bounded_exp(-(y_max2 - y_boost))), + hi + ); + auto feasible = lo <= hi; + for (int i = 0; i < 3; ++i) { + for (int j = 0; j < 3; ++j) { + // lo_alpha_i + lo_beta_i ta <= hi_alpha_j + hi_beta_j ta + auto slope = lo_beta[i] - hi_beta[j]; + auto rhs = hi_alpha[j] - lo_alpha[i]; + auto bound = rhs / where(slope == 0., FVal(1.), slope); + hi = where(slope > 0., min(hi, bound), hi); + lo = where(slope < 0., max(lo, bound), lo); + feasible = feasible & ((slope != 0.) | (rhs >= 0.)); + } + } + // back to |t1|, inside the input range + auto lo_t = max(lo - offset, FVal(t1_min)); + auto hi_t = min(hi - offset, FVal(t1_max)); + auto ok = (on1 | on2) & feasible & (hi_t > lo_t); + t1_min_out = where(ok, lo_t, FVal(t1_min)); + t1_max_out = where(ok, hi_t, FVal(t1_max)); +} + +// kernel_t2_rapidity_clamp_doublet for massive beams, with the lines of +// doublet_tb_line at the sampled ta. +template +KERNELSPEC void kernel_t2_rapidity_clamp_doublet_massive( + FIn t2_min, + FIn t2_max, + FIn pa, + FIn pb, + FIn m1, + FIn t1_abs, + FIn x1, + FIn x2, + FSIn beam_sign, + FSIn y_max1, + FSIn y_max2, + FOut t2_min_out, + FOut t2_max_out +) { + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto ta = t1_abs + lc.ma_2 + m1_2; + auto offset = lc.mb_2 + m1_2; + auto y_boost = beam_sign * 0.5 * log(x1 / x2); + auto on1 = rapidity_bound_on(y_max1), on2 = rapidity_bound_on(y_max2); + auto line_lo1 = doublet_tb_line(lc, bounded_exp(2. * (-y_max1 - y_boost))); + auto line_hi1 = doublet_tb_line(lc, bounded_exp(2. * (y_max1 - y_boost))); + auto line_lo2 = doublet_tb_line(lc, bounded_exp(2. * (-y_max2 - y_boost))); + auto line_hi2 = doublet_tb_line(lc, bounded_exp(2. * (y_max2 - y_boost))); + + FVal lo = t2_min, hi = t2_max; + // p1, tb rising with its rapidity + lo = where(on1, max(lo, line_lo1.second * ta - offset), lo); + hi = where(on1, min(hi, line_hi1.second * ta - offset), hi); + // the recoil, tb falling with its rapidity + lo = where(on2, max(lo, line_hi2.first + line_hi2.second * ta - offset), lo); + hi = where(on2, min(hi, line_lo2.first + line_lo2.second * ta - offset), hi); + + auto ok = hi > lo; + t2_min_out = where(ok, lo, FVal(t2_min)); + t2_max_out = where(ok, hi, FVal(t2_max)); +} + template KERNELSPEC void kernel_pt_eta_phi_x(FIn p_ext, FIn x1, FIn x2, FOut output) { diff --git a/madspace/src/kernels/threeparticle.hpp b/madspace/src/kernels/threeparticle.hpp index 9a1b4c3252..a6fa8cce77 100644 --- a/madspace/src/kernels/threeparticle.hpp +++ b/madspace/src/kernels/threeparticle.hpp @@ -428,7 +428,17 @@ KERNELSPEC void kernel_s23_value_and_min_max( // the sampled s-channel mass s23 = (peeled + im1)^2 using the recoil's ETmin // floor (upper bound, smax) and the peeled particle's ETmin + dR cut (lower // bound, smin -- only for a massless peeled particle). -template +// +// The recoil floor is the least energy of the recoil p1 in the frame below at +// fixed d = 2 pa.p1 = m1^2 + |t1| + ma^2 and transverse mass at least etmin_1. +// With the light-cone components of p1 along the beam axis, q against pa and +// q' along it, E1 = (q + q') / 2, q q' >= etmin_1^2 and d = pa_big q + +// pa_small q'. E1 falls with q along that line, so its least value is at the +// larger root of pa_big q^2 - d q + pa_small etmin_1^2 = 0, +// q = (d + sqrt(d^2 - 4 ma^2 etmin_1^2)) / (2 pa_big), +// which for a massless pa (pa_big = 2 E_a, massive = false) is d / (2 E_a), +// AmpliCol's floor. +template KERNELSPEC Pair, FVal> s23_etmin_clamp( FVal smn, FVal smx, @@ -456,9 +466,21 @@ KERNELSPEC Pair, FVal> s23_etmin_clamp( auto pim1_1 = sqrt(pim1[1] * pim1[1] + pim1[2] * pim1[2]); auto pib_0 = max((pib[0] * Eim1 - pib[3] * pzim1) / mT_im1, EPS); // Block-B recoil ET floor (t-dependent): invm(ir)-invm(ir+ib) = m1_2 + t1_abs. - auto denom = max(m1_2 + t1_abs, EPS); - auto etminir_b = - max(etmin_1, pib_0 * etmin_1 * etmin_1 / denom + denom / (4. * pib_0)); + FVal etminir_b = etmin_1; + if constexpr (massive) { + auto pib_z = (pib[3] * Eim1 - pib[0] * pzim1) / mT_im1; + auto pa_big = max(pib_0 + fabs(pib_z), EPS); + auto ma_2 = max(lsquare(pib), 0.); + auto e1_2 = etmin_1 * etmin_1; + auto d = m1_2 + t1_abs + ma_2; + auto q = + max((d + sqrt(max(d * d - 4. * ma_2 * e1_2, 0.))) / (2. * pa_big), EPS); + etminir_b = max(etmin_1, 0.5 * (q + e1_2 / q)); + } else { + auto denom = max(m1_2 + t1_abs, EPS); + etminir_b = + max(etmin_1, pib_0 * etmin_1 * etmin_1 / denom + denom / (4. * pib_0)); + } // smax: the recoil's ETmin caps the s-channel mass from above. auto e_eff = piir_0 - etminir_b; auto disc = e_eff * e_eff - m2_2; @@ -479,8 +501,8 @@ KERNELSPEC Pair, FVal> s23_etmin_clamp( // Clamp the s23 range against the lower bound s23_min_cut (minimum mass^2 of the // (2,3) system implied by the pt / m_inv_min / dR cuts, gen23's invm_min) and // the ETmin refinement of s23_etmin_clamp. -template -KERNELSPEC void kernel_s23_min_max_cut( +template +KERNELSPEC void s23_min_max_cut_impl( FIn pa, FIn p12, FIn p3, @@ -510,7 +532,7 @@ KERNELSPEC void kernel_s23_min_max_cut( smx = where(smx > smn, smx, smn + s23_min_width(smn)); // Block-B ETmin refinement: piir = p_12 (recoil system), pim1 = p3, pib = pa. - auto sb = s23_etmin_clamp( + auto sb = s23_etmin_clamp( smn, smx, p_12, @@ -530,7 +552,69 @@ KERNELSPEC void kernel_s23_min_max_cut( } template -KERNELSPEC void kernel_s23_value_and_min_max_cut( +KERNELSPEC void kernel_s23_min_max_cut( + FIn pa, + FIn p12, + FIn p3, + FIn t1_abs, + FIn m1, + FIn m2, + FIn etmin_1, + FIn etmin_2, + FIn drcut, + FIn s23_min_cut, + FOut s23_min, + FOut s23_max +) { + s23_min_max_cut_impl( + pa, + p12, + p3, + t1_abs, + m1, + m2, + etmin_1, + etmin_2, + drcut, + s23_min_cut, + s23_min, + s23_max + ); +} + +template +KERNELSPEC void kernel_s23_min_max_cut_massive( + FIn pa, + FIn p12, + FIn p3, + FIn t1_abs, + FIn m1, + FIn m2, + FIn etmin_1, + FIn etmin_2, + FIn drcut, + FIn s23_min_cut, + FOut s23_min, + FOut s23_max +) { + s23_min_max_cut_impl( + pa, + p12, + p3, + t1_abs, + m1, + m2, + etmin_1, + etmin_2, + drcut, + s23_min_cut, + s23_min, + s23_max + ); +} + +template +KERNELSPEC void s23_value_and_min_max_cut_impl( FIn pa, FIn p3, FIn t1_abs, @@ -571,7 +655,7 @@ KERNELSPEC void kernel_s23_value_and_min_max_cut( // Block-B ETmin refinement (must mirror the forward kernel exactly so the // sampled s23 range is identical and the round-trip stays invertible). - auto sb = s23_etmin_clamp( + auto sb = s23_etmin_clamp( smn, smx, p_12, @@ -591,6 +675,101 @@ KERNELSPEC void kernel_s23_value_and_min_max_cut( s_23 = lsquare(p_23); } +template +KERNELSPEC void kernel_s23_value_and_min_max_cut( + FIn pa, + FIn p3, + FIn t1_abs, + FIn p1, + FIn p2, + FIn etmin_1, + FIn etmin_2, + FIn drcut, + FIn s23_min_cut, + FOut s_23, + FOut s23_min, + FOut s23_max +) { + s23_value_and_min_max_cut_impl( + pa, + p3, + t1_abs, + p1, + p2, + etmin_1, + etmin_2, + drcut, + s23_min_cut, + s_23, + s23_min, + s23_max + ); +} + +template +KERNELSPEC void kernel_s23_value_and_min_max_cut_massive( + FIn pa, + FIn p3, + FIn t1_abs, + FIn p1, + FIn p2, + FIn etmin_1, + FIn etmin_2, + FIn drcut, + FIn s23_min_cut, + FOut s_23, + FOut s23_min, + FOut s23_max +) { + s23_value_and_min_max_cut_impl( + pa, + p3, + t1_abs, + p1, + p2, + etmin_1, + etmin_2, + drcut, + s23_min_cut, + s_23, + s23_min, + s23_max + ); +} + +// Lower bound on v = -(p2 - k)^2 in the 2->3 step with an incoming recoil (see +// TwoToThreeParticleScattering) off a massive beam k, against the other beam pa, +// for a p2 of mass^2 m2_2 and transverse energy at least etmin_2. With the +// light-cone components along k, +// v = k_big p2_small + k_small p2_big - m2^2 - mk^2, p2_small = m_T^2 / p2_big, +// and p2_big is at most what comes in along k, Q = k_big + pa_small. As a +// function of p2_big, k_big e^2 / p2_big + k_small p2_big with e = etmin_2 is +// least at p2_big = e k_big / mk, where it is 2 e mk, or else at Q. For +// massless beams the bound is etmin_2^2 - m2^2, that of the massless step. +template +KERNELSPEC void kernel_recoil_v_min_massive( + FIn pa, FIn k, FIn m2_2, FIn etmin_2, FOut v_min +) { + auto p_a = load_mom(pa), p_k = load_mom(k); + auto sign = where(p_k[3] < 0., FVal(-1.), FVal(1.)); + auto k_big = p_k[0] + fabs(p_k[3]); + auto mk_2 = max(lsquare(p_k), 0.); + auto k_small = mk_2 / max(k_big, FVal(EPS)); + // pa against k: E - |p_z| as m^2 / (E + |p_z|) + auto pa_z = sign * p_a[3]; + auto pa_small = where( + pa_z < 0., + max(lsquare(p_a), 0.) / max(p_a[0] - pa_z, FVal(EPS)), + p_a[0] + pa_z + ); + auto q = max(k_big + pa_small, FVal(EPS)); + FVal e = etmin_2; + auto mk = sqrt(mk_2); + auto least = + where(e * k_big < q * mk, 2. * e * mk, k_big * e * e / q + k_small * q); + v_min = least - m2_2 - mk_2; +} + // Arcsine map of the s23 sampling variable. // // At fixed s12, t1 and t2, s23 is linear in cos(phi) on its physical range diff --git a/madspace/src/kernels/twoparticle.hpp b/madspace/src/kernels/twoparticle.hpp index ceb392cda8..c0825a7819 100644 --- a/madspace/src/kernels/twoparticle.hpp +++ b/madspace/src/kernels/twoparticle.hpp @@ -445,5 +445,76 @@ KERNELSPEC void kernel_double_t_scattering_inverse( det = 2. * max(s, EPS) / PI; } +// kernel_double_t_scattering for massive beams pa, pb. With the light-cone +// components of beam_light_cone, ta = |t1| + ma^2 + m1^2, tb = |t2| + mb^2 + m1^2, +// p1 in the rest frame of pa + pb with pa along +z has +// E1 +- pz1 = x_+-, x_+ = (a_big tb - b_small ta) / root, +// x_- = (b_big ta - a_small tb) / root, pt^2 = x_+ x_- - m1^2, +// and d^3p1 / (2 E1) = dx_+ dx_- dphi / 4 = dt1 dt2 dphi / (4 root), so the +// Jacobian is pi / (2 root) per unit of r_phi, with root = sqrt(lambda(s, ma^2, +// mb^2)). For massless beams these are the formulas above. +template +KERNELSPEC void kernel_double_t_scattering_massive( + FIn r_phi, + FIn pa, + FIn pb, + FIn t1_abs, + FIn t2_abs, + FIn m1, + FOut p1, + FOut p2, + FOut det +) { + FourMom p_tot; + for (int i = 0; i < 4; ++i) { + p_tot[i] = pa[i] + pb[i]; + } + auto pa_com = boost(load_mom(pa), p_tot, -1.); + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + auto m1_2 = m1 * m1; + auto ta = t1_abs + lc.ma_2 + m1_2; + auto tb = t2_abs + lc.mb_2 + m1_2; + auto root = max(lc.root, FVal(EPS)); + auto x_plus = (lc.a_big * tb - lc.b_small * ta) / root; + auto x_minus = (lc.b_big * ta - lc.a_small * tb) / root; + auto pt = sqrt(max(x_plus * x_minus - m1_2, 0.)); + auto phi = PI * (2. * r_phi - 1.); + + FourMom p1_canon{ + 0.5 * (x_plus + x_minus), pt * cos(phi), pt * sin(phi), 0.5 * (x_plus - x_minus) + }; + + auto p1_rot = rotate(p1_canon, pa_com); + auto p1_lab = boost(p1_rot, p_tot, 1.); + store_mom(p1, p1_lab); + for (int i = 0; i < 4; ++i) { + p2[i] = p_tot[i] - p1_lab[i]; + } + + det = PI / (2. * root); +} + +template +KERNELSPEC void kernel_double_t_scattering_inverse_massive( + FIn p1, + FIn p2, + FIn pa, + FIn pb, + FOut r_phi, + FOut det +) { + FourMom p_tot; + for (int i = 0; i < 4; ++i) { + p_tot[i] = pa[i] + pb[i]; + } + auto pa_com = boost(load_mom(pa), p_tot, -1.); + auto p1_com = boost(load_mom(p1), p_tot, -1.); + auto p1_canon = rotate_inverse(p1_com, pa_com); + auto phi = atan2(p1_canon[2], p1_canon[1]); + r_phi = phi / PI / 2. + 0.5; + auto lc = beam_light_cone(load_mom(pa), load_mom(pb)); + det = 2. * max(lc.root, FVal(EPS)) / PI; +} + } // namespace kernels } // namespace madspace diff --git a/madspace/src/phasespace/base.cpp b/madspace/src/phasespace/base.cpp index 1b784cdaf7..3a341096a0 100644 --- a/madspace/src/phasespace/base.cpp +++ b/madspace/src/phasespace/base.cpp @@ -1,5 +1,9 @@ #include "madspace/phasespace/base.hpp" +#include +#include +#include + #include "madspace/util.hpp" using namespace madspace; @@ -198,3 +202,17 @@ Function FunctionGenerator::function() const { fb.output_range(0, sorted_outputs.values()); return fb.function(); } + +std::vector madspace::massive_incoming_masses( + const std::vector& masses, const std::string& mapping +) { + if (std::none_of(masses.begin(), masses.end(), [](double m) { return m != 0.; })) { + return {}; + } + if (masses.size() != 2) { + throw std::invalid_argument( + std::format("{}: incoming_masses are the masses of the two beams", mapping) + ); + } + return {std::abs(masses.at(0)), std::abs(masses.at(1))}; +} diff --git a/madspace/src/phasespace/chili.cpp b/madspace/src/phasespace/chili.cpp index 92977fbd07..8ce8821c04 100644 --- a/madspace/src/phasespace/chili.cpp +++ b/madspace/src/phasespace/chili.cpp @@ -1,17 +1,25 @@ #include "madspace/phasespace/chili.hpp" +#include + using namespace madspace; ChiliMapping::ChiliMapping( std::size_t n_particles, const std::vector& y_max, - const std::vector& pt_min + const std::vector& pt_min, + bool fixed_beams ) : Mapping( "ChiliMapping", [&] { + if (fixed_beams && n_particles < 2) { + throw std::invalid_argument( + "ChiliMapping: fixed beams need at least two outgoing particles" + ); + } NamedVector input_types; - for (std::size_t i = 0; i < 3 * n_particles - 2; ++i) { + for (std::size_t i = 0; i < 3 * n_particles - (fixed_beams ? 4 : 2); ++i) { input_types.push_back(std::format("random{}", i), batch_float); } return input_types; @@ -33,7 +41,8 @@ ChiliMapping::ChiliMapping( ), _n_particles(n_particles), _y_max(y_max), - _pt_min(pt_min) {} + _pt_min(pt_min), + _fixed_beams(fixed_beams) {} Mapping::Result ChiliMapping::build_forward_impl( FunctionBuilder& fb, @@ -42,7 +51,10 @@ Mapping::Result ChiliMapping::build_forward_impl( ) const { Value e_cm = conditions.at(0); ValueVec m_out(conditions.begin() + 1, conditions.end()); - auto [p_ext, det] = fb.chili_forward( + auto forward = _fixed_beams + ? &FunctionBuilder::chili_forward_fixed + : &FunctionBuilder::chili_forward; + auto [p_ext, det] = (fb.*forward)( fb.stack(inputs.values()), e_cm, fb.stack(m_out), _pt_min, _y_max ); auto outputs = fb.unstack(p_ext); @@ -56,7 +68,10 @@ Mapping::Result ChiliMapping::build_inverse_impl( ) const { Value e_cm = conditions.at(0); ValueVec m_out(conditions.begin() + 1, conditions.end()); - auto [r, det] = fb.chili_inverse( + auto inverse = _fixed_beams + ? &FunctionBuilder::chili_inverse_fixed + : &FunctionBuilder::chili_inverse; + auto [r, det] = (fb.*inverse)( fb.stack(inputs.values()), e_cm, fb.stack(m_out), _pt_min, _y_max ); ValueVec r_vec = fb.unstack(r); diff --git a/madspace/src/phasespace/color_ordered_mapping.cpp b/madspace/src/phasespace/color_ordered_mapping.cpp index b32378e3bf..e502f92670 100644 --- a/madspace/src/phasespace/color_ordered_mapping.cpp +++ b/madspace/src/phasespace/color_ordered_mapping.cpp @@ -335,10 +335,16 @@ ColorOrderedMapping::ColorOrderedMapping( const std::vector& pt_min, const std::vector>& m_inv_min, const std::vector>& dr_min, - const std::vector& y_max + const std::vector& y_max, + const std::vector& incoming_masses ) : ColorOrderedMapping( - rapidity_bounds(options.color_order, y_max), options, pt_min, m_inv_min, dr_min + rapidity_bounds(options.color_order, y_max), + options, + pt_min, + m_inv_min, + dr_min, + massive_incoming_masses(incoming_masses, "ColorOrderedMapping") ) {} ColorOrderedMapping::ColorOrderedMapping( @@ -346,7 +352,8 @@ ColorOrderedMapping::ColorOrderedMapping( const Options& options, const std::vector& pt_min, const std::vector>& m_inv_min, - const std::vector>& dr_min + const std::vector>& dr_min, + const std::vector& incoming_masses ) : Mapping( "ColorOrderedMapping", @@ -408,7 +415,11 @@ ColorOrderedMapping::ColorOrderedMapping( _dr_min(dr_min), _has_cut(has_any_cut(pt_min, m_inv_min, dr_min)), _rapidity_window(bounds.active()), + _incoming_masses(incoming_masses), _mass_invariant(0.5), + // every block below scatters off a beam (the central ones and the first + // peels off both, the 2->3 steps off the opposite one), with the massive + // kernels if the beams are massive _com_scattering( true, chain_power(options, pt_min, m_inv_min, dr_min), @@ -417,14 +428,19 @@ ColorOrderedMapping::ColorOrderedMapping( has_any_cut(pt_min, m_inv_min, dr_min), bounds.double_t ? -1. : bounds.central1, bounds.double_t ? -1. : bounds.central2, - 1. + 1., + !incoming_masses.empty() ), _lab_scattering( false, chain_power(options, pt_min, m_inv_min, dr_min), 0., 0., - has_any_cut(pt_min, m_inv_min, dr_min) + has_any_cut(pt_min, m_inv_min, dr_min), + -1., + -1., + 1., + !incoming_masses.empty() ), _chain_scattering( false, @@ -434,7 +450,8 @@ ColorOrderedMapping::ColorOrderedMapping( has_any_cut(pt_min, m_inv_min, dr_min), bounds.chain_rest, bounds.chain_peeled, - bounds.chain_beam_sign + bounds.chain_beam_sign, + !incoming_masses.empty() ), _two_to_three( chain_power(options, pt_min, m_inv_min, dr_min), @@ -447,7 +464,8 @@ ColorOrderedMapping::ColorOrderedMapping( true, true, false, - options.cut_aware_branch + options.cut_aware_branch, + !incoming_masses.empty() ), _two_to_three_beam( chain_power(options, pt_min, m_inv_min, dr_min), @@ -460,7 +478,8 @@ ColorOrderedMapping::ColorOrderedMapping( true, true, true, - options.cut_aware_branch + options.cut_aware_branch, + !incoming_masses.empty() ), _double_t( chain_power(options, pt_min, m_inv_min, dr_min), @@ -472,7 +491,8 @@ ColorOrderedMapping::ColorOrderedMapping( has_any_cut(pt_min, m_inv_min, dr_min), bounds.double_t ? bounds.central1 : -1., bounds.double_t ? bounds.central2 : -1., - 1. + 1., + !incoming_masses.empty() ) { auto [s1, s2] = split_sets_from_color_order(options.color_order); _set1 = s1; @@ -514,7 +534,11 @@ Mapping::Result ColorOrderedMapping::build_forward_impl( // * DoubleT: exactly one set has size 1; defers the multi-particle // side's mass until after the central block. // * standard: both sets non-empty -> central 2->2 scattering. - auto [pa, pb] = fb.com_p_in(e_cm); + // the beams in the partonic centre-of-mass frame, on their mass shells if + // they are massive + auto [pa, pb] = _incoming_masses.empty() + ? fb.com_p_in(e_cm) + : fb.com_p_in_massive(e_cm, _incoming_masses); Value m_set1, m_set2; Value P_set1, P_set2; auto masses_of = [&](const std::vector& idxs) { diff --git a/madspace/src/phasespace/cross_section.cpp b/madspace/src/phasespace/cross_section.cpp index b8d3c607d2..44140075e6 100644 --- a/madspace/src/phasespace/cross_section.cpp +++ b/madspace/src/phasespace/cross_section.cpp @@ -14,7 +14,8 @@ DifferentialCrossSection::DifferentialCrossSection( bool decay, bool return_matrix_element, const std::optional& eva, - const nested_vector3& eva_helicities + const nested_vector3& eva_helicities, + const std::vector& incoming_masses ) : FunctionGenerator( "DifferentialCrossSection", @@ -126,6 +127,26 @@ DifferentialCrossSection::DifferentialCrossSection( } _eva_tables = EvaLegTables(eva.value(), pid_options, eva_helicities); } + if (std::any_of(incoming_masses.begin(), incoming_masses.end(), [](double m) { + return m != 0.; + })) { + if (decay || incoming_masses.size() != 2) { + throw std::invalid_argument( + "incoming_masses are the masses of the two incoming particles of a " + "collision" + ); + } + if (!input_momentum_fraction) { + // momenta_to_x1x2 reads x off the energies of massless beams + throw std::invalid_argument( + "massive incoming particles need input momentum fractions" + ); + } + // a mass of the param card can be negative + _incoming_masses = { + std::abs(incoming_masses.at(0)), std::abs(incoming_masses.at(1)) + }; + } } NamedVector DifferentialCrossSection::build_function_impl( @@ -232,6 +253,16 @@ NamedVector DifferentialCrossSection::build_function_impl( // dGamma = |M|^2 dPhi_n / (2 M), in GeV; no GeV^-2 -> pb conversion // since a width is not a cross section. me_result.at(me_index) = fb.mul(me_result.at(me_index), 1. / (2. * _e_cm)); + } else if (!_incoming_masses.empty()) { + me_result.at(me_index) = fb.diff_cross_section_massive( + x1x2.at(0), + x1x2.at(1), + pdf_outputs.at(0), + pdf_outputs.at(1), + me_result.at(me_index), + _e_cm * _e_cm, + _incoming_masses + ); } else { me_result.at(me_index) = fb.diff_cross_section( x1x2.at(0), diff --git a/madspace/src/phasespace/integrand.cpp b/madspace/src/phasespace/integrand.cpp index de99b20f6d..93ef37301b 100644 --- a/madspace/src/phasespace/integrand.cpp +++ b/madspace/src/phasespace/integrand.cpp @@ -391,6 +391,20 @@ Integrand::Integrand( "EVA beams need EVA differential cross sections, and vice versa" ); } + // the mapping puts massive incoming particles on their mass shells, and + // the flux of the cross sections has to be that of the same masses + std::vector mapping_masses; + if (_mapping.massive_incoming()) { + for (double mass : _mapping.incoming_masses()) { + mapping_masses.push_back(std::abs(mass)); + } + } + if (xs.incoming_masses() != mapping_masses) { + throw std::invalid_argument( + "the differential cross sections need the incoming_masses of the " + "phase-space mapping" + ); + } } if (_eva && energy_scale && energy_scale->is_mlm()) { throw std::invalid_argument("EVA beams cannot be combined with MLM merging"); @@ -881,16 +895,6 @@ NamedVector Integrand::build_channel_part( ); weights_before_cuts.push_back(mapping_result["det"]); Value momenta = mapping_result["momenta"]; - // The mapping hands out massless incoming momenta. Massive ones (EVA's W - // and Z, monochromatic W or muon beams, massive partons) go on their mass - // shell, with the same sum, and the flux 1/(2 sqrt(lambda)) replaces the - // massless 1/(2 s_hat) of diff_cross_section, as in madevent. - if (auto& masses = _mapping.incoming_masses(); - masses.size() == 2 && (masses.at(0) > 0. || masses.at(1) > 0.)) { - auto on_shell = fb.incoming_on_shell(momenta, masses); - momenta = on_shell.at(0); - weights_before_cuts.push_back(on_shell.at(1)); - } Value x0 = mapping_result["x1"]; Value x1 = mapping_result["x2"]; // A dressed-lepton mapping also hands back 1-x. It has to: it samples x diff --git a/madspace/src/phasespace/invariants.cpp b/madspace/src/phasespace/invariants.cpp index 28847aa3e7..557700e84f 100644 --- a/madspace/src/phasespace/invariants.cpp +++ b/madspace/src/phasespace/invariants.cpp @@ -50,3 +50,21 @@ Mapping::Result Invariant::build_inverse_impl( : fb.stable_invariant_nu_inverse(s, _mass, _power, s_min, s_max); return {{{"random", r}}, det}; } + +std::array Invariant::build_forward_shifted( + FunctionBuilder& fb, Value r, Value x_min, Value x_max +) const { + auto shift = fb.mul(fb.min(x_min, 0.), 2.); + auto result = build_forward(fb, {r}, {fb.sub(x_min, shift), fb.sub(x_max, shift)}); + return {fb.add(result["invariant"], shift), result["det"]}; +} + +std::array Invariant::build_inverse_shifted( + FunctionBuilder& fb, Value x, Value x_min, Value x_max +) const { + auto shift = fb.mul(fb.min(x_min, 0.), 2.); + auto result = build_inverse( + fb, {fb.sub(x, shift)}, {fb.sub(x_min, shift), fb.sub(x_max, shift)} + ); + return {result["random"], result["det"]}; +} diff --git a/madspace/src/phasespace/phasespace.cpp b/madspace/src/phasespace/phasespace.cpp index 00504d9805..f33f4c43bd 100644 --- a/madspace/src/phasespace/phasespace.cpp +++ b/madspace/src/phasespace/phasespace.cpp @@ -312,13 +312,25 @@ PhaseSpaceMapping::PhaseSpaceMapping( // A decay has no beams to sample momentum fractions for: the root // virtuality is fixed at the decaying particle's mass (passed as // cm_energy) and there is no boost into a lab frame. + // chili reads x1 and x2 off its final state, except with dressed-lepton + // beams, whose split samples them _map_luminosity( !leptonic && !topology.is_decay() && (_topology.t_propagator_count() == 0 || - t_channel_mode != PhaseSpaceMapping::chili) + t_channel_mode != PhaseSpaceMapping::chili || lepton_sampling_power != 0.) ), _lepton_power(lepton_sampling_power), _two_to_one(topology.outgoing_masses().size() == 1), + _massive_incoming( + topology.incoming_masses().size() == 2 && + (topology.incoming_masses().at(0) != 0. || + topology.incoming_masses().at(1) != 0.) + ), + _project_incoming( + _massive_incoming && topology.t_propagator_count() > 0 && + t_channel_mode == PhaseSpaceMapping::chili && !leptonic && + lepton_sampling_power == 0. + ), _t_mapping(std::monostate{}) { // the chain order and settings belong to the color-ordered mode only if ((t_channel_mode == PhaseSpaceMapping::color_ordered) != @@ -604,6 +616,22 @@ PhaseSpaceMapping::PhaseSpaceMapping( _topology.raise_decay_e_min(0, transverse_mass_sum); } } + // Massive incoming particles need sqrt(s_hat) above m1 + m2: a floor on the + // root of the luminosity mapping. Fixed beams (leptonic) and a 2 -> 1 + // process fix s_hat, which is either above the threshold or leaves nothing. + if (_massive_incoming) { + double threshold = std::abs(_topology.incoming_masses().at(0)) + + std::abs(_topology.incoming_masses().at(1)); + double sqrt_s_hat_max = + _two_to_one ? _topology.outgoing_masses().at(0) : _sqrt_s_lab; + auto& root = _topology.decays().at(0); + if (sqrt_s_hat_max <= threshold || + (root.e_max > 0. && root.e_max <= threshold)) { + _empty = true; + } else if (_map_luminosity && !_two_to_one) { + _topology.raise_decay_e_min(0, threshold); + } + } for (auto [decay, info] : zip(std::views::reverse(_topology.decays()), std::views::reverse(decay_info))) { @@ -681,9 +709,24 @@ PhaseSpaceMapping::PhaseSpaceMapping( y_max.push_back(node_y_max.at(index)); } if (t_channel_mode == PhaseSpaceMapping::chili) { - // |y| <= |eta|, so we can pass y_max = eta_max - _t_mapping = - ChiliMapping(_topology.t_propagator_count() + 1, eta_max, pt_min); + // |y| <= |eta|, so we can pass y_max = eta_max. Fixed beams leave + // the final state no longitudinal freedom (lepton chili). With + // dressed-lepton beams the split samples x1 and x2, and chili + // builds the final state for fixed beams in their partonic frame, + // where the cuts of the lab bound no rapidity. + if (_lepton_power != 0.) { + std::fill( + eta_max.begin(), + eta_max.end(), + std::numeric_limits::infinity() + ); + } + _t_mapping = ChiliMapping( + _topology.t_propagator_count() + 1, + eta_max, + pt_min, + _leptonic || _lepton_power != 0. + ); } else if (t_channel_mode == PhaseSpaceMapping::color_ordered) { // Reorder the per-pair cut matrices into the child order handed to // the chain. Composite children carry no pairwise cut. @@ -739,14 +782,25 @@ PhaseSpaceMapping::PhaseSpaceMapping( if (!options.chain_invariant_power) { options.chain_invariant_power = chain_cuts ? 1. : invariant_power; } - _t_mapping = ColorOrderedMapping(options, pt_min, m_inv_co, dr_co, y_max); + _t_mapping = ColorOrderedMapping( + options, + pt_min, + m_inv_co, + dr_co, + y_max, + _massive_incoming ? _topology.incoming_masses() : std::vector{} + ); } else if (t_channel_mode == PhaseSpaceMapping::propagator || topology.t_propagator_count() < 2) { // The first scattering of the chain is between the two beams in // the partonic centre-of-mass frame, so the rapidity bounds of the // particle it peels and of the recoil narrow its |t| range. _t_mapping = TPropagatorMapping( - _topology.t_integration_order(), invariant_power, pt_min, y_max + _topology.t_integration_order(), + invariant_power, + pt_min, + y_max, + _massive_incoming ? _topology.incoming_masses() : std::vector{} ); } else if (t_channel_mode == PhaseSpaceMapping::rambo) { // TODO: add massless special case @@ -852,8 +906,24 @@ Mapping::Result PhaseSpaceMapping::build_forward_impl( Value x1 = 1.0, x2 = 1.0; Value omx1, omx2; + // the incoming momenta in the partonic centre-of-mass frame, on the mass + // shells of massive incoming particles + auto incoming = [&](Value e_cm) { + return _massive_incoming && !_project_incoming + ? fb.com_p_in_massive(e_cm, _topology.incoming_masses()) + : fb.com_p_in(e_cm); + }; + // permute, boost into the lab frame and apply the cuts auto finish = [&](Value p_ext_stack) -> Result { + if (_project_incoming) { + // chili builds the final state against the massless pair, which + // goes on its mass shells with the same sum (in the beams' frame) + auto on_shell = + fb.incoming_on_shell(p_ext_stack, _topology.incoming_masses()); + p_ext_stack = on_shell.at(0); + dets.push_back(on_shell.at(1)); + } if (_permutations.size() > 1) { p_ext_stack = fb.permute_momenta( p_ext_stack, _permutations, conditions.at("permutation_index") @@ -896,7 +966,7 @@ Mapping::Result PhaseSpaceMapping::build_forward_impl( x1 = x1_new; x2 = x2_new; dets.push_back(det_x); - auto [p1, p2] = fb.com_p_in(mass); + auto [p1, p2] = incoming(mass); return finish(fb.stack({p1, p2, fb.add(p1, p2)})); } @@ -1028,13 +1098,22 @@ Mapping::Result PhaseSpaceMapping::build_forward_impl( auto t_result = t_mapping.build_forward(fb, args, conds); std::size_t result_index; if constexpr (std::is_same_v) { - auto [p1, p2] = fb.com_p_in(sqrt_s_hat); + auto [p1, p2] = incoming(sqrt_s_hat); p_ext = {p1, p2}; result_index = 0; } else { p_ext = {t_result.at(0), t_result.at(1)}; result_index = 2; } + // chili with fixed beams builds the final state in the beams' + // frame, and the beams are those of the collision, on their + // mass shells if they are massive + if constexpr (std::is_same_v) { + if (t_mapping.fixed_beams()) { + auto [p1, p2] = incoming(sqrt_s_hat); + p_ext = {p1, p2}; + } + } for (std::size_t index : decay_data.at(0).decay.child_indices) { decay_data.at(index).momentum = t_result.at(result_index); ++result_index; @@ -1042,15 +1121,17 @@ Mapping::Result PhaseSpaceMapping::build_forward_impl( dets.push_back(t_result["det"]); if constexpr (std::is_same_v) { - auto [x1_new, x2_new] = fb.momenta_to_x1x2( - fb.stack({t_result.at(0), t_result.at(1)}), _sqrt_s_lab - ); - x1 = x1_new; - x2 = x2_new; + if (!t_mapping.fixed_beams()) { + auto [x1_new, x2_new] = fb.momenta_to_x1x2( + fb.stack({t_result.at(0), t_result.at(1)}), _sqrt_s_lab + ); + x1 = x1_new; + x2 = x2_new; + } } }, [&](std::monostate) { - auto [p1, p2] = fb.com_p_in(sqrt_s_hat); + auto [p1, p2] = incoming(sqrt_s_hat); if (_topology.is_decay()) { // Single incoming particle at rest: p_in = (M, 0, 0, 0) is // the sum of the beam momenta com_p_in builds for M. @@ -1219,6 +1300,13 @@ Mapping::Result PhaseSpaceMapping::build_inverse_impl( ); } + // chili: the massless incoming pair with the same sum, which the forward map + // built the final state against + if (_project_incoming) { + p_ext_stack = + fb.incoming_on_shell(p_ext_stack, std::vector{0., 0.}).at(0); + } + // initialize momenta, masses and square masses ValueVec p_ext = fb.unstack(p_ext_stack); std::vector decay_data( diff --git a/madspace/src/phasespace/t_propagator_mapping.cpp b/madspace/src/phasespace/t_propagator_mapping.cpp index 35d6245d30..6b4874de84 100644 --- a/madspace/src/phasespace/t_propagator_mapping.cpp +++ b/madspace/src/phasespace/t_propagator_mapping.cpp @@ -4,6 +4,7 @@ #include #include +#include using namespace madspace; @@ -57,20 +58,23 @@ TPropagatorMapping::TPropagatorMapping( const std::vector& integration_order, double invariant_power, const std::vector& pt_min, - const std::vector& y_max + const std::vector& y_max, + const std::vector& incoming_masses ) : TPropagatorMapping( first_step_rapidity_bounds(integration_order, y_max), integration_order, invariant_power, - pt_min + pt_min, + massive_incoming_masses(incoming_masses, "TPropagatorMapping") ) {} TPropagatorMapping::TPropagatorMapping( const std::array& first_step_bounds, const std::vector& integration_order, double invariant_power, - const std::vector& pt_min + const std::vector& pt_min, + const std::vector& incoming_masses ) : Mapping( "TPropagatorMapping", @@ -112,9 +116,23 @@ TPropagatorMapping::TPropagatorMapping( has_pt_cut(pt_min), first_step_bounds.at(0), first_step_bounds.at(1), - first_step_bounds.at(2) + first_step_bounds.at(2), + !incoming_masses.empty() + ), + // a later step can still have an untouched massive beam as an incoming + // momentum, so all steps take the massive kernels + _lab_scattering( + false, + invariant_power, + 0., + 0., + has_pt_cut(pt_min), + -1., + -1., + 1., + !incoming_masses.empty() ), - _lab_scattering(false, invariant_power, 0., 0., has_pt_cut(pt_min)) { + _incoming_masses(incoming_masses) { std::size_t next_index_low = 0; std::size_t next_index_high = integration_order.size() - 1; for (std::size_t index : integration_order) { @@ -175,8 +193,10 @@ Mapping::Result TPropagatorMapping::build_forward_impl( } mass_sum_invariants.push_back(m_out.at(_integration_order.back())); - // construct initial state momenta - auto [p1, p2] = fb.com_p_in(e_cm); + // construct initial state momenta, on the mass shells of massive beams + auto [p1, p2] = _incoming_masses.empty() + ? fb.com_p_in(e_cm) + : fb.com_p_in_massive(e_cm, _incoming_masses); ValueVec p_ext(_integration_order.size() + 3); p_ext.at(0) = p1; p_ext.at(1) = p2; diff --git a/madspace/src/phasespace/three_particle.cpp b/madspace/src/phasespace/three_particle.cpp index 9fa505a7a4..75a73de2a5 100644 --- a/madspace/src/phasespace/three_particle.cpp +++ b/madspace/src/phasespace/three_particle.cpp @@ -103,7 +103,8 @@ TwoToThreeParticleScattering::TwoToThreeParticleScattering( bool arcsine_s23, bool p12_condition, bool incoming_recoil, - bool cut_aware_branch + bool cut_aware_branch, + bool massive_beams ) : Mapping( "TwoToThreeParticleScattering", @@ -136,7 +137,8 @@ TwoToThreeParticleScattering::TwoToThreeParticleScattering( _arcsine_s23(arcsine_s23), _p12_condition(p12_condition), _incoming_recoil(incoming_recoil), - _cut_aware_branch(cut_aware_branch && has_cut) { + _cut_aware_branch(cut_aware_branch && has_cut), + _massive_beams(massive_beams) { // The arcsine sampling covers power laws only. if (arcsine_s23 && s_width != 0.) { throw std::invalid_argument( @@ -171,32 +173,99 @@ std::array TwoToThreeParticleScattering::split_conditions( return {p_a, fb.sub(fb.add(p_a, p_b), p_3), fb.sub(p_b, p_3)}; } -std::array TwoToThreeParticleScattering::sampling_ranges( +TwoToThreeParticleScattering::Ranges TwoToThreeParticleScattering::recoil_ranges( FunctionBuilder& fb, Value s23_min, Value s23_max, Value m2_squared, const NamedVector& conditions ) const { - // returns the sampled and the kinematic range of the sampled variable - if (!_incoming_recoil) { - return {s23_min, s23_max, s23_min, s23_max}; - } - // v = -(p2 - k)^2 >= 0 runs over [-s23_max, -s23_min] + // v = -(p2 - k)^2 runs over [-s23_max, -s23_min], at or above 0 for a + // massless k auto v_phys_min = negated(fb, s23_max), v_phys_max = negated(fb, s23_min); auto v_min = v_phys_min, v_max = v_phys_max; if (_has_cut) { - // |(p2 - k)^2| >= m_T(p2)^2 - m2^2 = p_T(p2)^2 for a massless k along - // the beam axis: the ETmin floor of a massive particle bounds m_T - v_min = fb.max( - v_min, fb.max(fb.sub(fb.square(conditions.at(4)), m2_squared), Value(0.)) - ); + if (_massive_beams) { + v_min = fb.max( + v_min, + fb.recoil_v_min_massive( + conditions.at(0), conditions.at(2), m2_squared, conditions.at(4) + ) + ); + } else { + // |(p2 - k)^2| >= m_T(p2)^2 - m2^2 = p_T(p2)^2 for a massless k + // along the beam axis: the ETmin floor of a massive particle bounds + // m_T + v_min = fb.max( + v_min, + fb.max(fb.sub(fb.square(conditions.at(4)), m2_squared), Value(0.)) + ); + } // an empty range keeps a small width; the weight is zero there, as // the point then lies outside the kinematic range auto width = fb.max(fb.mul(v_min, Value(1e-10)), Value(1e-300)); v_max = fb.max(v_max, fb.add(v_min, width)); } - return {v_min, v_max, v_phys_min, v_phys_max}; + if (!_massive_beams) { + return {v_min, v_max, v_phys_min, v_phys_max, std::nullopt}; + } + // off a massive k, v can be negative: the sampled variable is + // v - 2 min(v_min, 0), as in Invariant::build_forward_shifted, and the + // positions in the range stay as they are + auto shift = fb.mul(fb.min(v_min, 0.), 2.); + return { + fb.sub(v_min, shift), + fb.sub(v_max, shift), + fb.sub(v_phys_min, shift), + fb.sub(v_phys_max, shift), + shift + }; +} + +std::array TwoToThreeParticleScattering::t1_range( + FunctionBuilder& fb, + const NamedVector& conditions, + Value p_a, + Value p_c, + Value m1, + Value m2 +) const { + if (_has_cut) { + auto range = _massive_beams + ? &FunctionBuilder::t_inv_min_max_cut_massive + : &FunctionBuilder::t_inv_min_max_cut; + auto [t_min, t_max] = + (fb.*range)(p_a, p_c, m1, m2, conditions.at(3), conditions.at(4)); + return {t_min, t_max}; + } + auto range = _massive_beams + ? &FunctionBuilder::t_inv_min_max_massive + : &FunctionBuilder::t_inv_min_max; + auto [t_min, t_max] = (fb.*range)(p_a, p_c, m1, m2); + return {t_min, t_max}; +} + +std::array TwoToThreeParticleScattering::t1_value_and_range( + FunctionBuilder& fb, + const NamedVector& conditions, + Value p_a, + Value p_c, + Value p1, + Value p2 +) const { + if (_has_cut) { + auto value_and_range = _massive_beams + ? &FunctionBuilder::t_inv_value_and_min_max_cut_massive + : &FunctionBuilder::t_inv_value_and_min_max_cut; + auto [t_abs, t_min, t_max] = + (fb.*value_and_range)(p_a, p_c, p1, p2, conditions.at(3), conditions.at(4)); + return {t_abs, t_min, t_max}; + } + auto value_and_range = _massive_beams + ? &FunctionBuilder::t_inv_value_and_min_max_massive + : &FunctionBuilder::t_inv_value_and_min_max; + auto [t_abs, t_min, t_max] = (fb.*value_and_range)(p_a, p_c, p1, p2); + return {t_abs, t_min, t_max}; } Mapping::Result TwoToThreeParticleScattering::build_forward_impl( @@ -208,19 +277,30 @@ Mapping::Result TwoToThreeParticleScattering::build_forward_impl( m1 = inputs.at(3), m2 = inputs.at(4); auto p_3 = _incoming_recoil ? negated(fb, conditions.at(2)) : conditions.at(2); auto [p_a, p_12, p_c] = split_conditions(fb, conditions); - auto [t1_min, t1_max] = _has_cut - ? fb.t_inv_min_max_cut(p_a, p_c, m1, m2, conditions.at(3), conditions.at(4)) - : fb.t_inv_min_max(p_a, p_c, m1, m2); - auto t_inv_result = _t_invariant.build_forward(fb, {r_t1}, {t1_min, t1_max}); - auto t1 = t_inv_result["invariant"]; + auto [t1_min, t1_max] = t1_range(fb, conditions, p_a, p_c, m1, m2); + Value t1, det_t1; + if (_massive_beams) { + // t1 can be positive off a massive beam + auto [t1_out, det_out] = + _t_invariant.build_forward_shifted(fb, r_t1, t1_min, t1_max); + t1 = t1_out; + det_t1 = det_out; + } else { + auto t_inv_result = _t_invariant.build_forward(fb, {r_t1}, {t1_min, t1_max}); + t1 = t_inv_result["invariant"]; + det_t1 = t_inv_result["det"]; + } // The scattering kernel takes the position of s23 in its kinematic range, // u and 1 - u. Without cuts the sampled and the kinematic range coincide. - std::array ranges; + Ranges ranges; + auto s23_cut_range = _massive_beams + ? &FunctionBuilder::s23_min_max_cut_massive + : &FunctionBuilder::s23_min_max_cut; if (_incoming_recoil) { auto [lo, hi] = fb.s23_min_max(p_a, p_12, p_3, t1, m1, m2); - ranges = sampling_ranges(fb, lo, hi, fb.square(m2), conditions); + ranges = recoil_ranges(fb, lo, hi, fb.square(m2), conditions); } else if (_has_cut) { - auto [s_min, s_max] = fb.s23_min_max_cut( + auto [s_min, s_max] = (fb.*s23_cut_range)( p_a, p_12, p_3, @@ -233,12 +313,12 @@ Mapping::Result TwoToThreeParticleScattering::build_forward_impl( conditions.at(6) ); auto [lo, hi] = fb.s23_min_max(p_a, p_12, p_3, t1, m1, m2); - ranges = {s_min, s_max, lo, hi}; + ranges = {s_min, s_max, lo, hi, std::nullopt}; } else { auto [lo, hi] = fb.s23_min_max(p_a, p_12, p_3, t1, m1, m2); - ranges = {lo, hi, lo, hi}; + ranges = {lo, hi, lo, hi, std::nullopt}; } - auto [v_min, v_max, v_phys_min, v_phys_max] = ranges; + auto [v_min, v_max, v_phys_min, v_phys_max, v_shift] = ranges; Value u, u_c, det_s23; if (_arcsine_s23) { // arcsine map and importance sampling in one step, carrying u and @@ -261,7 +341,7 @@ Mapping::Result TwoToThreeParticleScattering::build_forward_impl( // v = -s23 runs the other way through the range of s23 std::swap(u, u_c); } - auto det_inv = fb.mul(t_inv_result["det"], det_s23); + auto det_inv = fb.mul(det_t1, det_s23); if (_cut_aware_branch) { auto [index_pass, factor, inv_factor] = fb.two_to_three_branch_choice( index_choice, @@ -293,23 +373,33 @@ Mapping::Result TwoToThreeParticleScattering::build_inverse_impl( auto p1 = inputs.at(0), p2 = inputs.at(1); auto p_3 = _incoming_recoil ? negated(fb, conditions.at(2)) : conditions.at(2); auto [p_a, p_12, p_c] = split_conditions(fb, conditions); - auto [t1_abs, t1_min, t1_max] = _has_cut - ? fb.t_inv_value_and_min_max_cut( - p_a, p_c, p1, p2, conditions.at(3), conditions.at(4) - ) - : fb.t_inv_value_and_min_max(p_a, p_c, p1, p2); - auto t_inv_result = _t_invariant.build_inverse(fb, {t1_abs}, {t1_min, t1_max}); + auto [t1_abs, t1_min, t1_max] = + t1_value_and_range(fb, conditions, p_a, p_c, p1, p2); + Value r_t1, det_t1; + if (_massive_beams) { + auto [r_out, det_out] = + _t_invariant.build_inverse_shifted(fb, t1_abs, t1_min, t1_max); + r_t1 = r_out; + det_t1 = det_out; + } else { + auto t_inv_result = _t_invariant.build_inverse(fb, {t1_abs}, {t1_min, t1_max}); + r_t1 = t_inv_result["random"]; + det_t1 = t_inv_result["det"]; + } Value v; - std::array ranges; + Ranges ranges; + auto s23_cut_value_and_range = _massive_beams + ? &FunctionBuilder::s23_value_and_min_max_cut_massive + : &FunctionBuilder::s23_value_and_min_max_cut; if (_incoming_recoil) { auto [s23, lo, hi] = fb.s23_value_and_min_max(p_a, p_3, t1_abs, p1, p2); v = negated(fb, s23); nested_vector2 factors_p2{{1.0}}; auto m2_squared = fb.unstack(fb.invariants_from_momenta(fb.stack({p2}), factors_p2)).at(0); - ranges = sampling_ranges(fb, lo, hi, m2_squared, conditions); + ranges = recoil_ranges(fb, lo, hi, m2_squared, conditions); } else if (_has_cut) { - auto [s23, s_min, s_max] = fb.s23_value_and_min_max_cut( + auto [s23, s_min, s_max] = (fb.*s23_cut_value_and_range)( p_a, p_3, t1_abs, @@ -321,18 +411,18 @@ Mapping::Result TwoToThreeParticleScattering::build_inverse_impl( conditions.at(6) ); v = s23; - ranges = {s_min, s_max, s_min, s_max}; + ranges = {s_min, s_max, s_min, s_max, std::nullopt}; if (_arcsine_s23) { auto [s23_phys, lo, hi] = fb.s23_value_and_min_max(p_a, p_3, t1_abs, p1, p2); - ranges = {s_min, s_max, lo, hi}; + ranges = {s_min, s_max, lo, hi, std::nullopt}; } } else { auto [s23, lo, hi] = fb.s23_value_and_min_max(p_a, p_3, t1_abs, p1, p2); v = s23; - ranges = {lo, hi, lo, hi}; + ranges = {lo, hi, lo, hi, std::nullopt}; } - auto [v_min, v_max, v_phys_min, v_phys_max] = ranges; + auto [v_min, v_max, v_phys_min, v_phys_max, v_shift] = ranges; auto [m1, m2, index_choice, u, u_c, det_scatter] = fb.two_to_three_particle_scattering_inverse(p1, p2, p_3, p_a, p_12, t1_abs); Value det_branch = Value(1.); @@ -370,18 +460,20 @@ Mapping::Result TwoToThreeParticleScattering::build_inverse_impl( r_s23 = r; det_s23 = det_r; } else { - auto s23_inv_result = _s_invariant.build_inverse(fb, {v}, {v_min, v_max}); + auto s23_inv_result = _s_invariant.build_inverse( + fb, {v_shift ? fb.sub(v, *v_shift) : v}, {v_min, v_max} + ); r_s23 = s23_inv_result["random"]; det_s23 = s23_inv_result["det"]; } - auto det_inv = fb.mul(t_inv_result["det"], det_s23); + auto det_inv = fb.mul(det_t1, det_s23); if (_cut_aware_branch) { det_inv = fb.mul(det_inv, det_branch); } return { {{"discrete_choice", index_choice}, {"random_s23", r_s23}, - {"random_t1", t_inv_result["random"]}, + {"random_t1", r_t1}, {"mass1", m1}, {"mass2", m2}}, fb.mul(det_inv, det_scatter) diff --git a/madspace/src/phasespace/two_particle.cpp b/madspace/src/phasespace/two_particle.cpp index 6784496377..78d0ae3384 100644 --- a/madspace/src/phasespace/two_particle.cpp +++ b/madspace/src/phasespace/two_particle.cpp @@ -121,7 +121,8 @@ TwoToTwoParticleScattering::TwoToTwoParticleScattering( bool has_cut, double y_max1, double y_max2, - double beam_sign + double beam_sign, + bool massive_beams ) : Mapping( "TwoToTwoParticleScattering", @@ -151,7 +152,27 @@ TwoToTwoParticleScattering::TwoToTwoParticleScattering( _rapidity_window(y_max1 >= 0. || y_max2 >= 0.), _y_max1(y_max1), _y_max2(y_max2), - _beam_sign(beam_sign) {} + _beam_sign(beam_sign), + _massive_beams(massive_beams) {} + +std::array TwoToTwoParticleScattering::t_range( + FunctionBuilder& fb, const NamedVector& conditions, Value m1, Value m2 +) const { + auto p_in1 = conditions.at(0), p_in2 = conditions.at(1); + if (_has_cut) { + auto range = _massive_beams + ? &FunctionBuilder::t_inv_min_max_cut_massive + : &FunctionBuilder::t_inv_min_max_cut; + auto [t_min, t_max] = + (fb.*range)(p_in1, p_in2, m1, m2, conditions.at(2), conditions.at(3)); + return {t_min, t_max}; + } + auto range = _massive_beams + ? &FunctionBuilder::t_inv_min_max_massive + : &FunctionBuilder::t_inv_min_max; + auto [t_min, t_max] = (fb.*range)(p_in1, p_in2, m1, m2); + return {t_min, t_max}; +} std::array TwoToTwoParticleScattering::rapidity_clamp( FunctionBuilder& fb, @@ -165,7 +186,10 @@ std::array TwoToTwoParticleScattering::rapidity_clamp( return {t_min, t_max}; } std::size_t x_index = _has_cut ? 4 : 2; - auto [lo, hi] = fb.t_rapidity_clamp( + auto clamp = _massive_beams + ? &FunctionBuilder::t_rapidity_clamp_massive + : &FunctionBuilder::t_rapidity_clamp; + auto [lo, hi] = (fb.*clamp)( t_min, t_max, conditions.at(0), @@ -181,6 +205,28 @@ std::array TwoToTwoParticleScattering::rapidity_clamp( return {lo, hi}; } +// With massive beams the range can reach below |t| = 0, and the Invariant +// samples |t| shifted; see Invariant::build_forward_shifted. +std::array TwoToTwoParticleScattering::sample_t( + FunctionBuilder& fb, Value r, Value t_min, Value t_max +) const { + if (!_massive_beams) { + auto result = _invariant.build_forward(fb, {r}, {t_min, t_max}); + return {result["invariant"], result["det"]}; + } + return _invariant.build_forward_shifted(fb, r, t_min, t_max); +} + +std::array TwoToTwoParticleScattering::unsample_t( + FunctionBuilder& fb, Value t_abs, Value t_min, Value t_max +) const { + if (!_massive_beams) { + auto result = _invariant.build_inverse(fb, {t_abs}, {t_min, t_max}); + return {result["random"], result["det"]}; + } + return _invariant.build_inverse_shifted(fb, t_abs, t_min, t_max); +} + Mapping::Result TwoToTwoParticleScattering::build_forward_impl( FunctionBuilder& fb, const NamedVector& inputs, @@ -189,21 +235,13 @@ Mapping::Result TwoToTwoParticleScattering::build_forward_impl( auto r_phi = inputs.at(0), r_inv = inputs.at(1), m1 = inputs.at(2), m2 = inputs.at(3); auto p_in1 = conditions.at(0), p_in2 = conditions.at(1); - auto [t_min_kin, t_max_kin] = _has_cut - ? fb.t_inv_min_max_cut(p_in1, p_in2, m1, m2, conditions.at(2), conditions.at(3)) - : fb.t_inv_min_max(p_in1, p_in2, m1, m2); + auto [t_min_kin, t_max_kin] = t_range(fb, conditions, m1, m2); auto [t_min, t_max] = rapidity_clamp(fb, conditions, t_min_kin, t_max_kin, m1, m2); - auto t_result = _invariant.build_forward(fb, {r_inv}, {t_min, t_max}); + auto [t_abs, det_t] = sample_t(fb, r_inv, t_min, t_max); auto [p1, p2, det_scatter] = _com - ? fb.two_to_two_particle_scattering_com( - r_phi, p_in1, p_in2, t_result["invariant"], m1, m2 - ) - : fb.two_to_two_particle_scattering( - r_phi, p_in1, p_in2, t_result["invariant"], m1, m2 - ); - return { - {{"momentum1", p1}, {"momentum2", p2}}, fb.mul(t_result["det"], det_scatter) - }; + ? fb.two_to_two_particle_scattering_com(r_phi, p_in1, p_in2, t_abs, m1, m2) + : fb.two_to_two_particle_scattering(r_phi, p_in1, p_in2, t_abs, m1, m2); + return {{{"momentum1", p1}, {"momentum2", p2}}, fb.mul(det_t, det_scatter)}; } Mapping::Result TwoToTwoParticleScattering::build_inverse_impl( @@ -239,11 +277,20 @@ Mapping::Result TwoToTwoParticleScattering::inverse( ) const { auto p1 = inputs.at(0), p2 = inputs.at(1); auto p_in1 = conditions.at(0), p_in2 = conditions.at(1); - auto t_values = _has_cut - ? fb.t_inv_value_and_min_max_cut( - p_in1, p_in2, p1, p2, conditions.at(2), conditions.at(3) - ) - : fb.t_inv_value_and_min_max(p_in1, p_in2, p1, p2); + std::array t_values; + if (_has_cut) { + auto value_and_range = _massive_beams + ? &FunctionBuilder::t_inv_value_and_min_max_cut_massive + : &FunctionBuilder::t_inv_value_and_min_max_cut; + t_values = (fb.*value_and_range)( + p_in1, p_in2, p1, p2, conditions.at(2), conditions.at(3) + ); + } else { + auto value_and_range = _massive_beams + ? &FunctionBuilder::t_inv_value_and_min_max_massive + : &FunctionBuilder::t_inv_value_and_min_max; + t_values = (fb.*value_and_range)(p_in1, p_in2, p1, p2); + } Value t_abs = t_values.at(0); std::array t_kin{t_values.at(1), t_values.at(2)}; auto [mass1, mass2] = @@ -252,25 +299,18 @@ Mapping::Result TwoToTwoParticleScattering::inverse( // |t| without cancellations of order E^2, and the range of the forward // map, from the masses t_abs = fb.t_inv_value(p_in1, p_in2, p1, p2, mass1, mass2); - t_kin = _has_cut - ? fb.t_inv_min_max_cut( - p_in1, p_in2, mass1, mass2, conditions.at(2), conditions.at(3) - ) - : fb.t_inv_min_max(p_in1, p_in2, mass1, mass2); + t_kin = t_range(fb, conditions, mass1, mass2); } auto [t_min, t_max] = _rapidity_window ? rapidity_clamp(fb, conditions, t_kin.at(0), t_kin.at(1), mass1, mass2) : t_kin; - auto t_result = _invariant.build_inverse(fb, {t_abs}, {t_min, t_max}); + auto [r_inv, det_t] = unsample_t(fb, t_abs, t_min, t_max); auto [r_phi, m1, m2, det_scatter] = _com ? fb.two_to_two_particle_scattering_com_inverse(p1, p2, p_in1, p_in2) : fb.two_to_two_particle_scattering_inverse(p1, p2, p_in1, p_in2); return { - {{"random_phi", r_phi}, - {"random_inv", t_result["random"]}, - {"mass1", m1}, - {"mass2", m2}}, - fb.mul(t_result["det"], det_scatter) + {{"random_phi", r_phi}, {"random_inv", r_inv}, {"mass1", m1}, {"mass2", m2}}, + fb.mul(det_t, det_scatter) }; } @@ -284,7 +324,8 @@ DoubleT::DoubleT( bool has_cut, double y_max1, double y_max2, - double beam_sign + double beam_sign, + bool massive_beams ) : Mapping( "DoubleT", @@ -316,7 +357,8 @@ DoubleT::DoubleT( _rapidity_window(y_max1 >= 0. || y_max2 >= 0.), _y_max1(y_max1), _y_max2(y_max2), - _beam_sign(beam_sign) {} + _beam_sign(beam_sign), + _massive_beams(massive_beams) {} std::array DoubleT::rapidity_clamp_t1( FunctionBuilder& fb, @@ -328,7 +370,10 @@ std::array DoubleT::rapidity_clamp_t1( return {t1_min, t1_max}; } std::size_t x_index = _has_cut ? 6 : 4; - auto [lo, hi] = fb.t1_rapidity_clamp_doublet( + auto clamp = _massive_beams + ? &FunctionBuilder::t1_rapidity_clamp_doublet_massive + : &FunctionBuilder::t1_rapidity_clamp_doublet; + auto [lo, hi] = (fb.*clamp)( t1_min, t1_max, conditions.at(0), @@ -357,7 +402,10 @@ std::array DoubleT::rapidity_clamp( return {t2_min, t2_max}; } std::size_t x_index = _has_cut ? 6 : 4; - auto [lo, hi] = fb.t2_rapidity_clamp_doublet( + auto clamp = _massive_beams + ? &FunctionBuilder::t2_rapidity_clamp_doublet_massive + : &FunctionBuilder::t2_rapidity_clamp_doublet; + auto [lo, hi] = (fb.*clamp)( t2_min, t2_max, conditions.at(0), @@ -373,6 +421,32 @@ std::array DoubleT::rapidity_clamp( return {lo, hi}; } +// With massive beams a range can reach below |t| = 0; see +// Invariant::build_forward_shifted. +std::array DoubleT::sample_t( + FunctionBuilder& fb, const Invariant& invariant, Value r, Value t_min, Value t_max +) const { + if (!_massive_beams) { + auto result = invariant.build_forward(fb, {r}, {t_min, t_max}); + return {result["invariant"], result["det"]}; + } + return invariant.build_forward_shifted(fb, r, t_min, t_max); +} + +std::array DoubleT::unsample_t( + FunctionBuilder& fb, + const Invariant& invariant, + Value t_abs, + Value t_min, + Value t_max +) const { + if (!_massive_beams) { + auto result = invariant.build_inverse(fb, {t_abs}, {t_min, t_max}); + return {result["random"], result["det"]}; + } + return invariant.build_inverse_shifted(fb, t_abs, t_min, t_max); +} + Mapping::Result DoubleT::build_forward_impl( FunctionBuilder& fb, const NamedVector& inputs, @@ -385,23 +459,30 @@ Mapping::Result DoubleT::build_forward_impl( auto etmin_i = _has_cut ? conditions.at(4) : Value(0.); auto etmin_ir = _has_cut ? conditions.at(5) : Value(0.); + auto t1_range = _massive_beams + ? &FunctionBuilder::t1_inv_min_max_doublet_massive + : &FunctionBuilder::t1_inv_min_max_doublet; auto [t1_min_kin, t1_max_kin] = - fb.t1_inv_min_max_doublet(p_in1, p_in2, m1, mir_min, etmin_i, etmin_ir); + (fb.*t1_range)(p_in1, p_in2, m1, mir_min, etmin_i, etmin_ir); auto [t1_min, t1_max] = rapidity_clamp_t1(fb, conditions, t1_min_kin, t1_max_kin); - auto t1_result = _t1_invariant.build_forward(fb, {r_t1}, {t1_min, t1_max}); + auto [t1_abs, det_t1] = sample_t(fb, _t1_invariant, r_t1, t1_min, t1_max); - auto [t2_min_kin, t2_max_kin] = fb.t2_inv_min_max_doublet( - p_in1, p_in2, m1, mir_min, t1_result["invariant"], etmin_i, etmin_ir - ); + auto t2_range = _massive_beams + ? &FunctionBuilder::t2_inv_min_max_doublet_massive + : &FunctionBuilder::t2_inv_min_max_doublet; + auto [t2_min_kin, t2_max_kin] = + (fb.*t2_range)(p_in1, p_in2, m1, mir_min, t1_abs, etmin_i, etmin_ir); auto [t2_min, t2_max] = - rapidity_clamp(fb, conditions, t2_min_kin, t2_max_kin, t1_result["invariant"]); - auto t2_result = _t2_invariant.build_forward(fb, {r_t2}, {t2_min, t2_max}); + rapidity_clamp(fb, conditions, t2_min_kin, t2_max_kin, t1_abs); + auto [t2_abs, det_t2] = sample_t(fb, _t2_invariant, r_t2, t2_min, t2_max); - auto [p1, p2, det_scatter] = fb.double_t_scattering( - r_phi, p_in1, p_in2, t1_result["invariant"], t2_result["invariant"], m1 - ); + auto scattering = _massive_beams + ? &FunctionBuilder::double_t_scattering_massive + : &FunctionBuilder::double_t_scattering; + auto [p1, p2, det_scatter] = + (fb.*scattering)(r_phi, p_in1, p_in2, t1_abs, t2_abs, m1); - auto det_inv = fb.mul(t1_result["det"], t2_result["det"]); + auto det_inv = fb.mul(det_t1, det_t2); return {{{"momentum1", p1}, {"momentum2", p2}}, fb.mul(det_inv, det_scatter)}; } @@ -417,26 +498,32 @@ Mapping::Result DoubleT::build_inverse_impl( auto etmin_i = _has_cut ? conditions.at(4) : Value(0.); auto etmin_ir = _has_cut ? conditions.at(5) : Value(0.); - auto [r_phi, det_scatter] = fb.double_t_scattering_inverse(p1, p2, p_in1, p_in2); + auto scattering_inverse = _massive_beams + ? &FunctionBuilder::double_t_scattering_inverse_massive + : &FunctionBuilder::double_t_scattering_inverse; + auto [r_phi, det_scatter] = (fb.*scattering_inverse)(p1, p2, p_in1, p_in2); - auto [t1_abs, t1_min_kin, t1_max_kin] = fb.t1_inv_value_and_min_max_doublet( - p_in1, p_in2, p1, m1, mir_min, etmin_i, etmin_ir - ); + auto t1_value_and_range = _massive_beams + ? &FunctionBuilder::t1_inv_value_and_min_max_doublet_massive + : &FunctionBuilder::t1_inv_value_and_min_max_doublet; + auto [t1_abs, t1_min_kin, t1_max_kin] = + (fb.*t1_value_and_range)(p_in1, p_in2, p1, m1, mir_min, etmin_i, etmin_ir); auto [t1_min, t1_max] = rapidity_clamp_t1(fb, conditions, t1_min_kin, t1_max_kin); - auto t1_result = _t1_invariant.build_inverse(fb, {t1_abs}, {t1_min, t1_max}); + auto [r_t1, det_t1] = unsample_t(fb, _t1_invariant, t1_abs, t1_min, t1_max); - auto [t2_abs, t2_min_kin, t2_max_kin] = fb.t2_inv_value_and_min_max_doublet( + auto t2_value_and_range = _massive_beams + ? &FunctionBuilder::t2_inv_value_and_min_max_doublet_massive + : &FunctionBuilder::t2_inv_value_and_min_max_doublet; + auto [t2_abs, t2_min_kin, t2_max_kin] = (fb.*t2_value_and_range)( p_in1, p_in2, p1, m1, mir_min, t1_abs, etmin_i, etmin_ir ); auto [t2_min, t2_max] = rapidity_clamp(fb, conditions, t2_min_kin, t2_max_kin, t1_abs); - auto t2_result = _t2_invariant.build_inverse(fb, {t2_abs}, {t2_min, t2_max}); + auto [r_t2, det_t2] = unsample_t(fb, _t2_invariant, t2_abs, t2_min, t2_max); - auto det_inv = fb.mul(t1_result["det"], t2_result["det"]); + auto det_inv = fb.mul(det_t1, det_t2); return { - {{"random_phi", r_phi}, - {"random_t1", t1_result["random"]}, - {"random_t2", t2_result["random"]}}, + {{"random_phi", r_phi}, {"random_t1", r_t1}, {"random_t2", r_t2}}, fb.mul(det_inv, det_scatter) }; } diff --git a/madspace/src/python/madspace.cpp b/madspace/src/python/madspace.cpp index b47933a474..f027a21426 100644 --- a/madspace/src/python/madspace.cpp +++ b/madspace/src/python/madspace.cpp @@ -1087,13 +1087,20 @@ PYBIND11_MODULE(_madspace_py, m) { std::vector, double, std::vector, + std::vector, std::vector>(), py::arg("integration_order"), py::arg("invariant_power") = 0.8, py::arg("pt_min") = std::vector{}, py::arg("y_max") = std::vector{}, + py::arg("incoming_masses") = std::vector{}, pydoc::doc("TPropagatorMapping::TPropagatorMapping") ) + .def( + "incoming_masses", + &TPropagatorMapping::incoming_masses, + pydoc::doc("TPropagatorMapping::incoming_masses") + ) .def( "random_dim", &TPropagatorMapping::random_dim, @@ -1140,14 +1147,21 @@ PYBIND11_MODULE(_madspace_py, m) { std::vector, std::vector>, std::vector>, + std::vector, std::vector>(), py::arg("options"), py::arg("pt_min") = std::vector{}, py::arg("m_inv_min") = std::vector>{}, py::arg("dr_min") = std::vector>{}, py::arg("y_max") = std::vector{}, + py::arg("incoming_masses") = std::vector{}, pydoc::doc("ColorOrderedMapping::ColorOrderedMapping") ) + .def( + "incoming_masses", + &ColorOrderedMapping::incoming_masses, + pydoc::doc("ColorOrderedMapping::incoming_masses") + ) .def( "random_dim", &ColorOrderedMapping::random_dim, @@ -1164,16 +1178,23 @@ PYBIND11_MODULE(_madspace_py, m) { py::init< std::size_t, const std::vector&, - const std::vector&>(), + const std::vector&, + bool>(), py::arg("n_particles"), py::arg("y_max"), py::arg("pt_min"), + py::arg("fixed_beams") = false, pydoc::doc("ChiliMapping::ChiliMapping") ) .def( "random_dim", &ChiliMapping::random_dim, pydoc::doc("ChiliMapping::random_dim") + ) + .def( + "fixed_beams", + &ChiliMapping::fixed_beams, + pydoc::doc("ChiliMapping::fixed_beams") ); py::classh( @@ -1800,6 +1821,16 @@ PYBIND11_MODULE(_madspace_py, m) { &PhaseSpaceMapping::mirror_beams, pydoc::doc("PhaseSpaceMapping::mirror_beams") ) + .def( + "incoming_masses", + &PhaseSpaceMapping::incoming_masses, + pydoc::doc("PhaseSpaceMapping::incoming_masses") + ) + .def( + "massive_incoming", + &PhaseSpaceMapping::massive_incoming, + pydoc::doc("PhaseSpaceMapping::massive_incoming") + ) .def("cuts", &PhaseSpaceMapping::cuts, pydoc::doc("PhaseSpaceMapping::cuts")) .def( "empty", &PhaseSpaceMapping::empty, pydoc::doc("PhaseSpaceMapping::empty") @@ -2946,7 +2977,8 @@ PYBIND11_MODULE(_madspace_py, m) { bool, bool, const std::optional&, - const nested_vector3&>(), + const nested_vector3&, + const std::vector&>(), py::arg("matrix_element"), py::arg("cm_energy"), py::arg("running_coupling"), @@ -2959,9 +2991,15 @@ PYBIND11_MODULE(_madspace_py, m) { py::arg("return_matrix_element") = false, py::arg("eva") = std::nullopt, py::arg("eva_helicities") = nested_vector3{}, + py::arg("incoming_masses") = std::vector{}, pydoc::doc("DifferentialCrossSection::DifferentialCrossSection") ) .def("eva", &DifferentialCrossSection::eva, pydoc::doc("DifferentialCrossSection::eva")) + .def( + "incoming_masses", + &DifferentialCrossSection::incoming_masses, + pydoc::doc("DifferentialCrossSection::incoming_masses") + ) .def( "pid_options", &DifferentialCrossSection::pid_options, diff --git a/madspace/tests/test_chili_fixed_beams.py b/madspace/tests/test_chili_fixed_beams.py new file mode 100644 index 0000000000..a1ed69f863 --- /dev/null +++ b/madspace/tests/test_chili_fixed_beams.py @@ -0,0 +1,260 @@ +"""Chili with fixed beams (lepton colliders). + +With fixed beams the incoming momenta add up to P = (sqrt(s), 0, 0, 0), and the +final state has no longitudinal freedom left. ChiliMapping(fixed_beams=True) +generates the first n - 2 momenta as chili does (pT, y, phi, with the exact +energy bound on y), and the last two as the two-body decay of +Q = P - sum p_i in the rest frame of Q, from 3n - 4 random numbers. +PhaseSpaceMapping takes it for chili with leptonic beams, whose momenta, on +their mass shells if they are massive, it builds itself. With dressed-lepton +beams the split of the luminosity samples x1 and x2, and chili builds the +final state for fixed beams in their partonic frame. + +The forward map is a bijection onto the phase space with its density if it +gives the volume of rambo, if its inverse takes every rambo event into the unit +cube, and if the inverse gives back the random numbers and the inverse +Jacobian. With a density g = 1 / det of the inverse, +E_rambo[w g] over a region R is the fraction of chili events in R, a test of +the density everywhere. +""" + +import math + +import numpy as np +import pytest +from madspace_testing import to_numpy +from pytest import approx + +import madspace as ms + +# numpy inputs, which madspace runs on the CPU +pytestmark = pytest.mark.cpu_only + +PSM = ms.PhaseSpaceMapping +SQRT_S = 1000.0 + +# outgoing masses, the heavy particle among the first n - 2 (generated by +# chili) and among the last two (the decay) +OUTGOING = { + "2 massless": [0.0, 0.0], + "2 t tbar": [173.0, 173.0], + "3 massless": [0.0, 0.0, 0.0], + "3 heavy first": [173.0, 0.0, 10.0], + "3 heavy last": [0.0, 173.0, 10.0], + "4 massless": [0.0, 0.0, 0.0, 0.0], + "5 with W": [80.0, 0.0, 0.0, 0.0, 0.0], +} +BEAMS = {"massless beams": [0.0, 0.0], "W Z beams": [80.4, 91.2]} + + +def make(m_in, m_out, mode="chili", cuts=None): + kwargs = {} if cuts is None else {"cuts": cuts} + return PSM( + list(m_in) + list(m_out), + SQRT_S, + leptonic=True, + mode=getattr(PSM, mode), + **kwargs, + ) + + +def jet_cuts(n_out, pt_min=30.0, eta_max=2.0): + """pt and |eta| cuts on the outgoing particles, all jets""" + O = ms.Observable + pids = [11, -11] + [21] * n_out + return ms.Cuts( + [ + ms.CutItem(O(pids, O.obs_pt, [O.jet_pids]), min=pt_min), + ms.CutItem(O(pids, O.obs_eta_abs, [O.jet_pids]), max=eta_max), + ] + ) + + +def in_cuts(p, pt_min=30.0, eta_max=2.0): + q = p[:, 2:] + pt = np.hypot(q[..., 1], q[..., 2]) + with np.errstate(divide="ignore", invalid="ignore"): + eta = np.arctanh(q[..., 3] / np.sqrt(pt**2 + q[..., 3] ** 2)) + return np.all((pt > pt_min) & (np.abs(eta) < eta_max), axis=1) + + +def forward(mapping, seed, n): + r = np.random.default_rng(seed).random((n, mapping.random_dim())) + p, x1, x2, det = map(to_numpy, mapping.map_forward([r], [])) + return r, p, np.broadcast_to(x1, (n,)), np.broadcast_to(x2, (n,)), det + + +def inverse(mapping, p, x1, x2): + result = mapping.map_inverse( + [p, np.ascontiguousarray(x1), np.ascontiguousarray(x2)], [] + ) + return to_numpy(result[0]), to_numpy(result[-1]) + + +def mass2(p): + return p[..., 0] ** 2 - p[..., 1] ** 2 - p[..., 2] ** 2 - p[..., 3] ** 2 + + +def mean_and_error(w): + return w.mean(), w.std() / math.sqrt(len(w)) + + +def test_random_dim(): + for n in range(2, 6): + args = (n, [math.inf] * n, [0.0] * n) + fixed = ms.ChiliMapping(*args, fixed_beams=True) + assert fixed.fixed_beams() and fixed.random_dim() == 3 * n - 4 + assert ms.ChiliMapping(*args).random_dim() == 3 * n - 2 + m_out = [0.0] * n + assert make([0.0, 0.0], m_out).random_dim() == 3 * n - 4 + assert ( + make([0.0, 0.0], m_out).random_dim() + == make([0.0, 0.0], m_out, "rambo").random_dim() + ) + with pytest.raises(ValueError): + ms.ChiliMapping(1, [math.inf], [0.0], fixed_beams=True) + + +@pytest.mark.parametrize("m_in", BEAMS.values(), ids=BEAMS.keys()) +@pytest.mark.parametrize("m_out", OUTGOING.values(), ids=OUTGOING.keys()) +def test_momenta(m_in, m_out): + """The beams with their sum at rest, x1 = x2 = 1, every particle on its + mass shell and momentum conservation.""" + _, p, x1, x2, det = forward(make(m_in, m_out), 1, 4000) + ok = det > 0 + assert np.all(det >= 0) and ok.mean() > 0.3 + assert np.all(x1 == 1.0) and np.all(x2 == 1.0) + p = p[ok] + for leg, mass in enumerate(list(m_in) + list(m_out)): + assert mass2(p[:, leg]) == approx(mass**2, abs=1e-10 * SQRT_S**2) + assert np.all(p[:, :2, 1:3] == 0.0) and np.all(p[:, 0, 3] > 0.0) + total = np.array([SQRT_S, 0.0, 0.0, 0.0]) + assert p[:, :2].sum(axis=1) == approx( + np.broadcast_to(total, (len(p), 4)), abs=1e-12 * SQRT_S + ) + assert p[:, 2:].sum(axis=1) == approx( + np.broadcast_to(total, (len(p), 4)), abs=1e-10 * SQRT_S + ) + + +# without cuts chili samples four and more massless particles with weights of +# a variance too large for a test of the volume, so those have cuts below +VOLUME = {name: m_out for name, m_out in OUTGOING.items() if len(m_out) <= 3} + + +@pytest.mark.parametrize("m_out", VOLUME.values(), ids=VOLUME.keys()) +def test_volume(m_out): + """The phase-space volume of rambo, with a heavy particle among the first + n - 2 too (with the bound acosh(sqrt(s) / (2 mT)) of hadronic chili on y + it lost 7% of [173, 0, 10]). Two particles are the decay of P alone, with + the two-body volume as a constant Jacobian.""" + n = 1000000 + w_chili = forward(make([0.0, 0.0], m_out), 2, n)[-1] + if len(m_out) == 2: + s, (m1, m2) = SQRT_S**2, m_out + root = math.sqrt((s - (m1 + m2) ** 2) * (s - (m1 - m2) ** 2)) + assert w_chili == approx(root / s / (8.0 * math.pi), rel=1e-12) + return + w_rambo = forward(make([0.0, 0.0], m_out, "rambo"), 3, n)[-1] + (a, error_a), (b, error_b) = mean_and_error(w_chili), mean_and_error(w_rambo) + assert abs(a - b) < 5.0 * math.hypot(error_a, error_b) + + +@pytest.mark.parametrize("cuts", [False, True], ids=["no-cuts", "cuts"]) +@pytest.mark.parametrize("m_in", BEAMS.values(), ids=BEAMS.keys()) +@pytest.mark.parametrize("m_out", OUTGOING.values(), ids=OUTGOING.keys()) +def test_round_trip(m_out, m_in, cuts): + """The inverse gives back the random numbers and the inverse Jacobian, + also at large rapidities.""" + mapping = make(m_in, m_out, cuts=jet_cuts(len(m_out)) if cuts else None) + r, p, x1, x2, det = forward(mapping, 5, 4000) + ok = det > 0 + r_inv, det_inv = inverse(mapping, p[ok], x1[ok], x2[ok]) + assert r_inv == approx(r[ok], abs=1e-10) + assert det_inv * det[ok] == approx(1.0, rel=1e-10) + + +@pytest.mark.parametrize("cuts", [False, True], ids=["no-cuts", "cuts"]) +@pytest.mark.parametrize("m_out", OUTGOING.values(), ids=OUTGOING.keys()) +def test_covers_the_phase_space(m_out, cuts): + """The inverse takes every rambo event into the unit cube, and with cuts, + which keep the density g = 1 / det away from the soft and collinear + regions, E_rambo[w g] over the region of the cuts is the fraction of chili + events in it.""" + n = 100000 + kwargs = dict(cuts=jet_cuts(len(m_out))) if cuts else {} + chili = make([0.0, 0.0], m_out, **kwargs) + rambo = make([0.0, 0.0], m_out, "rambo", **kwargs) + _, p, x1, x2, w = forward(rambo, 6, n) + region = (w > 0) & (in_cuts(p) if cuts else True) + r, g = inverse(chili, p[region], x1[region], x2[region]) + assert np.all((r >= 0.0) & (r <= 1.0)) + assert np.all(np.isfinite(g) & (g > 0.0)) + if not cuts: + return + lhs = np.zeros(n) + lhs[region] = w[region] * g + _, p_c, _, _, w_c = forward(chili, 7, n) + rhs = ((w_c > 0) & in_cuts(p_c)).astype(float) + (a, error_a), (b, error_b) = mean_and_error(lhs), mean_and_error(rhs) + assert b > 0.05 + assert abs(a - b) < 5.0 * math.hypot(error_a, error_b) + + +def dressed(m_in, m_out, mode="chili", cuts=None): + """beams with a dressed-lepton density: x1 and x2 from the split""" + kwargs = {} if cuts is None else {"cuts": cuts} + return PSM( + list(m_in) + list(m_out), + SQRT_S, + leptonic=False, + mode=getattr(PSM, mode), + lepton_sampling_power=0.96, + **kwargs, + ) + + +def forward_dressed(mapping, seed, n): + r = np.random.default_rng(seed).random((n, mapping.random_dim())) + return [to_numpy(out) for out in mapping.map_forward([r], [])] + + +@pytest.mark.parametrize("m_in", BEAMS.values(), ids=BEAMS.keys()) +def test_dressed_lepton_beams(m_in): + """The split draws x1, x2 and 1 - x first, the same as for rambo, and chili + the final state of the partonic frame, boosted to the lab: momentum + conservation, every particle on its mass shell, and the volume of + rambo.""" + m_out = [80.4, 80.4, 0.0] + chili, rambo = dressed(m_in, m_out), dressed(m_in, m_out, "rambo") + assert chili.random_dim() == rambo.random_dim() == 3 * len(m_out) - 1 + n = 200000 + p, *fractions, det = forward_dressed(chili, 8, n) + _, *fractions_rambo, det_rambo = forward_dressed(rambo, 8, n) + for a, b in zip(fractions, fractions_rambo): + assert np.array_equal(a, b) + x1, x2 = fractions[:2] + ok = det > 0 + assert ok.mean() > 0.5 + p, x1, x2 = p[ok], x1[ok], x2[ok] + half = 0.5 * SQRT_S + total = np.stack([half * (x1 + x2), 0.0 * x1, 0.0 * x1, half * (x1 - x2)], axis=1) + assert p[:, :2].sum(axis=1) == approx(total, abs=1e-12 * SQRT_S) + assert p[:, 2:].sum(axis=1) == approx(total, abs=1e-10 * SQRT_S) + for leg, mass in enumerate(list(m_in) + m_out): + assert mass2(p[:, leg]) == approx(mass**2, abs=1e-10 * SQRT_S**2) + (a, error_a), (b, error_b) = mean_and_error(det), mean_and_error(det_rambo) + assert abs(a - b) < 5.0 * math.hypot(error_a, error_b) + + +def test_dressed_lepton_beams_with_cuts(): + """The cuts hold in the lab, which the partonic frame of chili is boosted + from: the volume they leave is that of rambo.""" + m_out = [80.4, 80.4, 0.0] + volumes = [] + for mode, seed in [("chili", 9), ("rambo", 10)]: + mapping = dressed([0.0, 0.0], m_out, mode, cuts=jet_cuts(len(m_out))) + p, *_, det = forward_dressed(mapping, seed, 200000) + volumes.append(mean_and_error(det * in_cuts(p))) + (a, error_a), (b, error_b) = volumes + assert abs(a - b) < 5.0 * math.hypot(error_a, error_b) diff --git a/madspace/tests/test_massive_incoming.py b/madspace/tests/test_massive_incoming.py new file mode 100644 index 0000000000..4c1a497539 --- /dev/null +++ b/madspace/tests/test_massive_incoming.py @@ -0,0 +1,985 @@ +"""Massive incoming particles in PhaseSpaceMapping and DifferentialCrossSection. + +The mapping builds massive incoming particles (W and Z beams, muons with a +mass, massive partons) on their mass shells in the partonic frame +(com_p_in_massive). The propagator and color-ordered chains scatter off them +with the massive versions of their blocks (unclamped |t| ranges, shifted |t| +sampling, massive rapidity and ETmin bounds, the double-t and 2 -> 3 blocks). +Without a t-channel chain (rambo, s-channel, 2 -> 1) the final state and the +Jacobian are those of massless incoming particles. Chili with beams from PDFs +builds the final state against the massless pair with the same sum and puts it +on its mass shells afterwards (incoming_on_shell), and chili with fixed beams +builds it for the sum of the beams alone, with the same final state and +Jacobian too. +Every mode has the phase-space volume of massless beams, an inverse that takes +the massive momenta, and s_hat from the threshold (m1 + m2)^2 on. The flux +1/(2 sqrt(lambda(s_hat, m1^2, m2^2))) is that of DifferentialCrossSection with +the same incoming_masses. +""" + +import itertools +import math +from decimal import Decimal, getcontext + +import numpy as np +import pytest +from madspace_testing import default_context, to_numpy +from pytest import approx + +import madspace as ms + +# numpy inputs, which madspace runs on the CPU +pytestmark = pytest.mark.cpu_only + +PSM = ms.PhaseSpaceMapping +SQRT_S = 1000.0 +M_IN = [80.4, 91.2] +M_OUT = [173.0, 173.0, 10.0] +N = 4000 + +MODES = [ + ("rambo", False), + ("propagator", False), + ("color_ordered", False), + ("chili", False), + ("rambo", True), + ("propagator", True), + ("color_ordered", True), + ("chili", True), +] +MODE_IDS = [ + f"{mode}-{'leptonic' if leptonic else 'hadronic'}" for mode, leptonic in MODES +] +# the modes whose final state does not depend on the incoming masses +CHAINS = ("propagator", "color_ordered") +SAME = [case for case in MODES if case[0] not in CHAINS] +SAME_IDS = [name for name, case in zip(MODE_IDS, MODES) if case[0] not in CHAINS] + +# color orders that take every block of the color-ordered chain off the beams: +# a single chain (2 -> 2 peel, 2 -> 3), the double-t block with a walk +# (2 -> 2 peel, 2 -> 3) or a side of two (2 -> 3 with an incoming recoil), and +# the central 2 -> 2 with both +COLOR_ORDERS = { + "single": [0, 2, 3, 4, 1], + "double_t": [0, 2, 1, 3, 4, 5], + "double_t_pair": [0, 2, 1, 3, 4], + "central": [0, 2, 3, 4, 1, 5, 6], +} + + +def make(m_in, mode, leptonic, m_out=M_OUT, sqrt_s=SQRT_S, order=None, **kwargs): + if mode == "color_ordered": + order = order or [0] + [i + 2 for i in range(len(m_out))] + [1] + kwargs["color_ordered"] = ms.ColorOrderedMapping.Options(order) + return PSM( + list(m_in) + list(m_out), + sqrt_s, + leptonic=leptonic, + mode=getattr(PSM, mode), + **kwargs, + ) + + +def draw(mapping, seed, n=N): + rng = np.random.default_rng(seed) + inputs = [rng.random((n, mapping.random_dim()))] + if mapping.discrete_dim(): + inputs.append(rng.integers(0, 2, (n, mapping.discrete_dim()), dtype=np.int32)) + return inputs + + +def forward(mapping, inputs): + p, x1, x2, det = map(to_numpy, mapping.map_forward(inputs, [])) + n = p.shape[0] + return p, np.broadcast_to(x1, (n,)), np.broadcast_to(x2, (n,)), det + + +def mass2(p): + return p[..., 0] ** 2 - p[..., 1] ** 2 - p[..., 2] ** 2 - p[..., 3] ** 2 + + +def rapidity(p): + return 0.5 * np.log((p[..., 0] + p[..., 3]) / (p[..., 0] - p[..., 3])) + + +@pytest.mark.parametrize("mode,leptonic", SAME, ids=SAME_IDS) +def test_same_final_state_and_jacobian(mode, leptonic): + """Without a chain that scatters off the beams only the incoming momenta + differ from the massless mapping: on their mass shells along the beams, + with the same sum and in the same order of rapidity, the first one + ahead.""" + massless = make([0.0, 0.0], mode, leptonic) + massive = make(M_IN, mode, leptonic) + assert massive.massive_incoming() and not massless.massive_incoming() + assert massive.incoming_masses() == M_IN + inputs = draw(massive, 11) + p0, x1_0, x2_0, det0 = forward(massless, inputs) + p, x1, x2, det = forward(massive, inputs) + ok = det0 > 0 + assert ok.mean() > 0.3 + + # (chili leaves x and the momenta of unphysical points, of no weight, NaN) + assert det == approx(det0, rel=1e-12) + assert x1[ok] == approx(x1_0[ok], rel=1e-14) and x2[ok] == approx( + x2_0[ok], rel=1e-14 + ) + assert p[ok, 2:] == approx(p0[ok, 2:], rel=1e-12, abs=1e-10 * SQRT_S) + + p_in = p[ok, :2] + for leg, mass in enumerate(M_IN): + assert mass2(p_in[:, leg]) == approx(mass**2, rel=1e-8) + assert np.all(p_in[..., 1:3] == 0.0) + assert p_in.sum(axis=1) == approx( + p0[ok, :2].sum(axis=1), rel=1e-13, abs=1e-10 * SQRT_S + ) + assert p_in.sum(axis=1) == approx( + p[ok, 2:].sum(axis=1), rel=1e-12, abs=1e-10 * SQRT_S + ) + assert np.all(rapidity(p_in[:, 0]) > rapidity(p_in[:, 1])) + + +@pytest.mark.parametrize("leptonic", [False, True], ids=["hadronic", "leptonic"]) +def test_asymmetric_and_mirrored_beams(leptonic): + """With a beam rapidity and mirrored events the incoming momenta are on + their mass shells in the lab too, and the final state and the Jacobian are + still those of the massless mapping (rambo).""" + kwargs = dict( + leptonic=leptonic, mode=PSM.rambo, beam_rapidity=0.2, mirror_beams=True + ) + massless = PSM([0.0, 0.0] + M_OUT, SQRT_S, **kwargs) + massive = PSM(M_IN + M_OUT, SQRT_S, **kwargs) + rng = np.random.default_rng(19) + r = rng.random((N, massive.random_dim())) + mirror = rng.integers(0, 2, N, dtype=np.int32) + p0, _, _, det0 = map(to_numpy, massless.map_forward([r], [mirror])) + p, x1, x2, det = map(to_numpy, massive.map_forward([r], [mirror])) + ok = det0 > 0 + assert det == approx(det0, rel=1e-12) + assert p[ok, 2:] == approx(p0[ok, 2:], rel=1e-12, abs=1e-10 * SQRT_S) + for leg, mass in enumerate(M_IN): + assert mass2(p[ok, leg]) == approx(mass**2, rel=1e-8) + assert p[ok, :2].sum(axis=1) == approx( + p0[ok, :2].sum(axis=1), rel=1e-13, abs=1e-10 * SQRT_S + ) + # a mirrored event has its first leg from beam 2 + ahead = rapidity(p[ok, 0]) > rapidity(p[ok, 1]) + assert np.all(ahead == (mirror[ok] == 0)) + result = massive.map_inverse( + [ + p, + np.ascontiguousarray(np.broadcast_to(x1, (N,))), + np.ascontiguousarray(np.broadcast_to(x2, (N,))), + ], + [mirror], + ) + assert to_numpy(result[0])[ok] == approx(r[ok], abs=1e-7) + + +def jet_cuts(n_out, pt_min=30.0, eta_max=2.0): + """pt and |eta| cuts on the outgoing particles, all jets""" + O = ms.Observable + pids = [24, -24] + [21] * n_out + return ms.Cuts( + [ + ms.CutItem(O(pids, O.obs_pt, [O.jet_pids]), min=pt_min), + ms.CutItem(O(pids, O.obs_eta_abs, [O.jet_pids]), max=eta_max), + ] + ) + + +CHAIN_CASES = [("propagator", None)] + [("color_ordered", o) for o in COLOR_ORDERS] + + +@pytest.mark.parametrize("cuts", [False, True], ids=["no-cuts", "cuts"]) +@pytest.mark.parametrize("leptonic", [False, True], ids=["hadronic", "leptonic"]) +@pytest.mark.parametrize( + "mode,order", CHAIN_CASES, ids=[order or mode for mode, order in CHAIN_CASES] +) +def test_chain_off_massive_beams(mode, order, leptonic, cuts): + """The propagator and color-ordered chains scatter off the massive beams: + the incoming momenta are on their mass shells before the chain, and every + block takes its massive kernels. The phase-space volume, with cuts too, + whose |t| windows are then the massive ones, is that of massless beams + above the threshold, about as many points pass the cuts, and the inverse + takes the massive momenta back to the random numbers.""" + n_out = len(COLOR_ORDERS[order]) - 2 if order else 3 + m_out = [0.0] * n_out + kwargs = dict(invariant_power=0.0, order=order and COLOR_ORDERS[order]) + if cuts: + kwargs["cuts"] = jet_cuts(n_out) + massive = make(M_IN, mode, leptonic, m_out, **kwargs) + massless = make([0.0, 0.0], mode, leptonic, m_out, **kwargs) + n = 100000 + inputs = draw(massive, 20, n) + p, x1, x2, det = forward(massive, inputs) + _, x1_0, x2_0, det0 = forward(massless, draw(massless, 21, n)) + ok = det > 0 + assert ok.mean() > 0.5 * np.mean(det0 > 0) + # massless beams also reach below the threshold, which massive ones cannot + det0 = det0 * (x1_0 * x2_0 * SQRT_S**2 > sum(M_IN) ** 2) + for leg, mass in enumerate(M_IN): + assert mass2(p[ok, leg]) == approx(mass**2, rel=1e-8) + assert p[ok, :2].sum(axis=1) == approx( + p[ok, 2:].sum(axis=1), rel=1e-12, abs=1e-10 * SQRT_S + ) + error = math.hypot(det.std(), det0.std()) / math.sqrt(n) + assert abs(det.mean() - det0.mean()) < 5.0 * error + + # the inverse, through the same (massive) ranges and clamps (the central + # color-ordered topology loses about 1e-6 at rare points, with massless + # beams too) + inv_inputs = [p, np.ascontiguousarray(x1), np.ascontiguousarray(x2)] + result = massive.map_inverse(inv_inputs, []) + r_inv, det_inv = to_numpy(result[0]), to_numpy(result[-1]) + assert r_inv[ok] == approx(inputs[0][ok], abs=1e-6) + assert det_inv[ok] * det[ok] == approx(1.0, rel=1e-5) + if massive.discrete_dim() and not cuts: + # and the two-solution choices (with cuts, the cut-aware choice maps + # both onto the one that passes where only one does) + assert np.all(to_numpy(result[1])[ok] == inputs[1][ok]) + + # the transfer from the first beam to the particle the propagator chain + # peels first (the last outgoing one) reaches down to its kinematic minimum + # with the beam masses, below which a massless beam would put it + if mode == "propagator" and not cuts and leptonic: + q = p[ok, 0] - p[ok, 4] + t_abs = -mass2(q) + s = SQRT_S**2 + m1, m2 = M_IN + lam = (s - (m1 + m2) ** 2) * (s - (m1 - m2) ** 2) + e1, p1 = (s + m1**2 - m2**2) / (2 * SQRT_S), math.sqrt(lam) / (2 * SQRT_S) + # |t| = 2 (E1 E - p1 p_z) - m1^2 >= 2 E (E1 - p1) - m1^2 for a massless + # particle of energy E, so |t| > -m1^2 always and t_min < 0 is reached + assert t_abs.min() < 0.0 + assert np.all(t_abs >= -(m1**2) * (1 + 1e-9)) + energy = p[ok, 4, 0] + assert np.all(t_abs >= 2 * energy * (e1 - p1) - m1**2 - 1e-9 * s) + + +@pytest.mark.parametrize("order", list(COLOR_ORDERS)) +def test_color_ordered_distributions_match_rambo(order): + """Off massive beams the color-ordered chain gives the distributions of + rambo, which builds them without its blocks: the weighted means of the + transverse momentum and the absolute rapidity of every outgoing particle, + with cuts. Its weight leaves out the factor 2 of each uniformly sampled + two-solution choice.""" + n_out = len(COLOR_ORDERS[order]) - 2 + m_out = [0.0] * n_out + kwargs = dict(cuts=jet_cuts(n_out)) + chain = make( + M_IN, "color_ordered", True, m_out, order=COLOR_ORDERS[order], **kwargs + ) + rambo = make(M_IN, "rambo", True, m_out, **kwargs) + means = [] + for mapping, seed in [(chain, 35), (rambo, 36)]: + p, _, _, det = forward(mapping, draw(mapping, seed, 200000)) + det = det * 2.0 ** mapping.discrete_dim() + p_out = p[:, 2:] + pt = np.hypot(p_out[..., 1], p_out[..., 2]) + with np.errstate(divide="ignore", invalid="ignore"): + y_abs = np.where(det[:, None] > 0, np.abs(rapidity(p_out)), 0.0) + observables = np.concatenate([pt, y_abs], axis=1) * det[:, None] + means.append( + (observables.mean(axis=0), observables.std(axis=0) / math.sqrt(len(det))) + ) + (a, error_a), (b, error_b) = means + assert np.all(np.abs(a - b) < 5.0 * np.hypot(error_a, error_b)) + + +@pytest.mark.parametrize("mode,leptonic", MODES, ids=MODE_IDS) +def test_inverse_takes_the_massive_momenta(mode, leptonic): + mapping = make(M_IN, mode, leptonic) + inputs = draw(mapping, 12) + p, x1, x2, det = forward(mapping, inputs) + ok = det > 0 + result = mapping.map_inverse( + [p, np.ascontiguousarray(x1), np.ascontiguousarray(x2)], [] + ) + r_inv, det_inv = to_numpy(result[0]), to_numpy(result[-1]) + assert r_inv[ok] == approx(inputs[0][ok], abs=1e-7) + assert det_inv[ok] * det[ok] == approx(1.0, rel=1e-7) + + +@pytest.mark.parametrize("mode", ["rambo", "propagator"]) +def test_s_hat_from_the_threshold_on(mode): + """With a massless final state the luminosity mapping starts s_hat at + (m1 + m2)^2, and its weight is that of the massless incoming mapping above + the threshold.""" + m_out = [0.0, 0.0] + massive = make(M_IN, mode, False, m_out) + massless = make([0.0, 0.0], mode, False, m_out) + threshold = sum(M_IN) ** 2 + p, x1, x2, det = forward(massive, draw(massive, 13, 40000)) + s_hat = x1 * x2 * SQRT_S**2 + assert np.all(det > 0.0) + assert s_hat.min() >= threshold * (1.0 - 1e-12) + assert mass2(p[:, 0]) == approx(M_IN[0] ** 2, rel=1e-8) + + _, x1_0, x2_0, det0 = forward(massless, draw(massless, 14, 40000)) + above = det0 * (x1_0 * x2_0 * SQRT_S**2 > threshold) + mean, mean0 = det.mean(), above.mean() + error = math.hypot(det.std(), above.std()) / math.sqrt(len(det)) + assert abs(mean - mean0) < 5.0 * error + + +def test_chili_below_threshold_has_no_weight(): + """chili samples x1, x2 itself, below the threshold too: no weight there.""" + mapping = make(M_IN, "chili", False, [0.0, 0.0, 0.0]) + p, x1, x2, det = forward(mapping, draw(mapping, 15)) + below = x1 * x2 * SQRT_S**2 <= sum(M_IN) ** 2 + assert below.any() and (~below).any() + assert np.all(det[below] == 0.0) + above = ~below & (det > 0) + assert above.any() + assert mass2(p[above, 1]) == approx(M_IN[1] ** 2, rel=1e-8) + + +def two_to_one(m_in, mass): + return ms.Topology(ms.Diagram(list(m_in), [mass], [], [["i0", "i1", "o0"]])) + + +def test_fixed_s_hat(): + """A 2 -> 1 process and fixed beams give s_hat, below the threshold an + empty mapping.""" + assert PSM(two_to_one([80.4, 80.4], 125.0), SQRT_S).empty() + assert make(M_IN, "rambo", True, sqrt_s=170.0, m_out=[10.0, 10.0]).empty() + assert not make(M_IN, "rambo", True, sqrt_s=500.0, m_out=[10.0, 10.0]).empty() + + mapping = PSM(two_to_one([80.4, 80.4], 500.0), SQRT_S) + massless = PSM(two_to_one([0.0, 0.0], 500.0), SQRT_S) + assert not mapping.empty() + r = np.random.default_rng(16).random((N, 1)) + p, x1, x2, det = forward(mapping, [r]) + _, _, _, det0 = forward(massless, [r]) + assert det == approx(det0, rel=1e-14) + assert x1 * x2 * SQRT_S**2 == approx(500.0**2) + assert mass2(p[:, 0]) == approx(80.4**2, rel=1e-8) + assert p[:, 0] + p[:, 1] == approx(p[:, 2], rel=1e-12, abs=1e-10) + + +def run(fb, args): + runtime = ms.FunctionRuntime(fb.function(), default_context()) + return [np.from_dlpack(out) for out in runtime.call(args)] + + +def on_shell(p, masses): + vec = ms.batch_four_vec_array(p.shape[1]) + fb = ms.FunctionBuilder( + ms.NamedTypes([("p", vec)]), + ms.NamedTypes([("p_out", vec), ("above_threshold", ms.batch_float)]), + ) + out = fb.incoming_on_shell(fb.input(0), ms.Value(list(masses))) + fb.output(0, out[0]) + fb.output(1, out[1]) + return run(fb, [p]) + + +def exact_pair(plus, minus, m1, m2): + """E and p_z of the on-shell pair with the light-cone sums plus, minus, to + 40 digits""" + getcontext().prec = 40 + plus, minus, m1, m2 = map(Decimal, (plus, minus, m1, m2)) + s = plus * minus + root = ((s - (m1 + m2) ** 2) * (s - (m1 - m2) ** 2)).sqrt() + u1 = (1 + (m1 * m1 - m2 * m2) / s + root / s) / 2 + u2 = (1 - (m1 * m1 - m2 * m2) / s + root / s) / 2 + p1 = (plus * u1, m1 * m1 / (plus * u1)) + p2 = (m2 * m2 / (minus * u2), minus * u2) + return [[float((a + b) / 2), float((a - b) / 2)] for a, b in (p1, p2)] + + +@pytest.mark.parametrize( + "masses", [(80.4, 91.2), (0.10566, 0.10566)], ids=["wz", "mumu"] +) +def test_on_shell_keeps_its_precision(masses): + """Up to |y| = 10: each energy and p_z to rounding (light-cone components), + and the masses 0 take the massless pair back. The way back takes the sums + E -+ p_z of the pair from the massive momenta, whose small light-cone + component a momentum at rapidity y holds to eps exp(2 |y|) only, which is + why the mapping goes back in the partonic frame.""" + rng = np.random.default_rng(17) + n = 200 + sqrt_s = 10 ** rng.uniform(np.log10(sum(masses)) + 0.01, 4.0, n) + y = rng.uniform(-10.0, 10.0, n) + plus, minus = sqrt_s * np.exp(y), sqrt_s * np.exp(-y) + p = np.zeros((n, 3, 4)) + p[:, 0, 0] = p[:, 0, 3] = plus / 2 + p[:, 1, 0], p[:, 1, 3] = minus / 2, -minus / 2 + p[:, 2, 0], p[:, 2, 3] = (plus + minus) / 2, (plus - minus) / 2 + p_out, above = on_shell(p, masses) + assert np.all(above == 1.0) + assert np.all(p_out[:, 2] == p[:, 2]) + assert np.all(p_out[:, :2, 1:3] == 0.0) + exact = np.array([exact_pair(a, b, *masses) for a, b in zip(plus, minus)]) + assert p_out[:, :2, 0] == approx(exact[..., 0], rel=1e-14) + assert p_out[:, :2, 3] == approx(exact[..., 1], rel=1e-14) + + back, _ = on_shell(p_out, (0.0, 0.0)) + tolerance = 1e-14 + 1e-15 * np.exp(2.0 * np.abs(y)) + assert np.all( + np.abs(back[:, :2] - p[:, :2]) <= tolerance[:, None, None] * p[:, 2:, :1] + ) + p_rest = p.copy() + p_rest[:, 0, 0] = p_rest[:, 0, 3] = sqrt_s / 2 + p_rest[:, 1, 0], p_rest[:, 1, 3] = sqrt_s / 2, -sqrt_s / 2 + back, _ = on_shell(on_shell(p_rest, masses)[0], (0.0, 0.0)) + assert back[:, :2] == approx(p_rest[:, :2], rel=1e-14, abs=0.0) + + # below the threshold + p[:, 0, 0] = p[:, 0, 3] = p[:, 1, 0] = 0.4 * sum(masses) + p[:, 1, 3] = -p[:, 1, 0] + assert np.all(on_shell(p, masses)[1] == 0.0) + + +def test_massive_flux(): + names = ["x1", "x2", "pdf1", "pdf2", "me"] + e_cm2 = SQRT_S**2 + + def flux(masses): + fb = ms.FunctionBuilder( + ms.NamedTypes([(name, ms.batch_float) for name in names]), + ms.NamedTypes([("result", ms.batch_float)]), + ) + args = [fb.input(i) for i in range(len(names))] + if masses is None: + fb.output(0, fb.diff_cross_section(*args, e_cm2)) + else: + fb.output( + 0, fb.diff_cross_section_massive(*args, e_cm2, ms.Value(list(masses))) + ) + return run(fb, [x1, x2, pdf1, pdf2, me])[0] + + rng = np.random.default_rng(18) + x1, x2 = rng.random((2, N)) ** 2 + pdf1, pdf2, me = rng.random((3, N)) + s_hat = x1 * x2 * e_cm2 + m1, m2 = M_IN + lam = (s_hat - (m1 + m2) ** 2) * (s_hat - (m1 - m2) ** 2) + above = s_hat > (m1 + m2) ** 2 + assert above.any() and (~above).any() + gev2_to_pb = flux(None) * 2.0 * s_hat * x1 * x2 / (me * pdf1 * pdf2) + expected = np.where( + above, + gev2_to_pb * me * pdf1 * pdf2 / (2.0 * x1 * x2 * np.sqrt(np.abs(lam))), + 0.0, + ) + assert flux(M_IN) == approx(expected, rel=1e-13) + assert flux([-m1, m2]) == approx(expected, rel=1e-13) + assert flux([0.0, 0.0]) == approx(flux(None), rel=1e-14) + + +def flat_matrix_element(n_particles): + return ms.MatrixElement( + 0xBADCAFE, + n_particles, + ms.Integrand.matrix_element_inputs, + ms.Integrand.matrix_element_outputs, + 1, + True, + ) + + +def cross_section(**kwargs): + return ms.DifferentialCrossSection( + matrix_element=flat_matrix_element(2 + len(M_OUT)), + cm_energy=SQRT_S, + running_coupling=None, + energy_scale=ms.CachedScale(), + **kwargs, + ) + + +def test_cross_section_incoming_masses(): + assert cross_section().incoming_masses() == [] + assert cross_section(incoming_masses=[0.0, 0.0]).incoming_masses() == [] + assert cross_section(incoming_masses=[-80.4, 91.2]).incoming_masses() == M_IN + with pytest.raises(ValueError): + cross_section(incoming_masses=[80.4]) + with pytest.raises(ValueError): + cross_section(incoming_masses=M_IN, input_momentum_fraction=False) + + +def test_integrand_needs_the_masses_of_the_mapping(): + mapping = make(M_IN, "propagator", True) + with pytest.raises(ValueError, match="incoming_masses"): + ms.Integrand(mapping, [cross_section()]) + with pytest.raises(ValueError, match="incoming_masses"): + ms.Integrand( + make([0.0, 0.0], "propagator", True), [cross_section(incoming_masses=M_IN)] + ) + ms.Integrand(mapping, [cross_section(incoming_masses=M_IN)]) + + +def kernel(name, inputs, outputs, *args): + """Runs one kernel on numpy arrays: inputs [(name, type, array)], then the + constant arguments args after them""" + fb = ms.FunctionBuilder( + ms.NamedTypes([(n, t) for n, t, _ in inputs]), + ms.NamedTypes([(n, ms.batch_float) for n in outputs]), + ) + out = getattr(fb, name)(*[fb.input(i) for i in range(len(inputs))], *args) + out = out if isinstance(out, (list, tuple)) else [out] + for i in range(len(outputs)): + fb.output(i, out[i]) + return run(fb, [np.ascontiguousarray(a) for _, _, a in inputs]) + + +def boost_z(p, y): + """p boosted along z by the rapidity -y (into the frame moving with y)""" + q = p.copy() + ch, sh = np.cosh(y), np.sinh(y) + q[..., 0] = ch * p[..., 0] - sh * p[..., 3] + q[..., 3] = ch * p[..., 3] - sh * p[..., 0] + return q + + +def partonic_2to2(m_out, n=50000, seed=22): + """2 -> 2 events off the massive beams, without cuts, in the partonic frame: + pa, pb, p1, p2, x1, x2""" + mapping = PSM(M_IN + m_out, SQRT_S, leptonic=False, mode=PSM.propagator) + p, x1, x2, det = forward(mapping, draw(mapping, seed, n)) + ok = det > 0 + p, x1, x2 = p[ok], x1[ok], x2[ok] + p = np.stack([boost_z(p[:, i], 0.5 * np.log(x1 / x2)) for i in range(4)], axis=1) + return p[:, 0], p[:, 1], p[:, 2], p[:, 3], x1, x2 + + +def t_abs(pa, p1): + return -mass2(pa - p1) + + +FOUR = ms.batch_four_vec +FLOAT = ms.batch_float + + +def test_massive_rapidity_clamp_keeps_what_passes(): + """Every event whose outgoing lab rapidities pass the bounds has its |t| + inside the range of t_rapidity_clamp_massive, which is narrower than the + kinematic one for many events.""" + m_out = [173.0, 10.0] + pa, pb, p1, p2, x1, x2 = partonic_2to2(m_out) + n = len(x1) + m1, m2 = np.full(n, m_out[0]), np.full(n, m_out[1]) + t_min, t_max = kernel( + "t_inv_min_max_massive", + [("pa", FOUR, pa), ("pb", FOUR, pb), ("m1", FLOAT, m1), ("m2", FLOAT, m2)], + ["t_min", "t_max"], + ) + y_boost = 0.5 * np.log(x1 / x2) + for y_max1, y_max2 in [(1.0, 2.0), (2.5, 0.5), (-1.0, 1.5), (0.8, -1.0)]: + lo, hi = kernel( + "t_rapidity_clamp_massive", + [ + ("t_min", FLOAT, t_min), + ("t_max", FLOAT, t_max), + ("pa", FOUR, pa), + ("pb", FOUR, pb), + ("m1", FLOAT, m1), + ("m2", FLOAT, m2), + ("x1", FLOAT, x1), + ("x2", FLOAT, x2), + ], + ["lo", "hi"], + 1.0, + y_max1, + y_max2, + ) + y1 = rapidity(p1) + y_boost + y2 = rapidity(p2) + y_boost + passes = (y_max1 < 0) | (np.abs(y1) <= y_max1) + passes &= (y_max2 < 0) | (np.abs(y2) <= y_max2) + t = t_abs(pa, p1) + tolerance = 1e-9 * SQRT_S**2 + assert passes.sum() > 100 + assert np.all(t[passes] >= lo[passes] - tolerance) + assert np.all(t[passes] <= hi[passes] + tolerance) + assert np.mean(hi - lo < 0.9 * (t_max - t_min)) > 0.2 + + +def test_massive_etmin_bound_keeps_what_passes(): + """The same for the ETmin bounds of t_inv_min_max_cut_massive.""" + m_out = [173.0, 10.0] + pa, pb, p1, p2, x1, x2 = partonic_2to2(m_out, seed=23) + n = len(x1) + m1, m2 = np.full(n, m_out[0]), np.full(n, m_out[1]) + et = lambda p: np.sqrt(mass2(p) + p[:, 1] ** 2 + p[:, 2] ** 2) + for et1, et2 in [(200.0, 50.0), (180.0, 150.0), (0.0, 120.0)]: + e1, e2 = np.full(n, et1), np.full(n, et2) + lo, hi = kernel( + "t_inv_min_max_cut_massive", + [ + ("pa", FOUR, pa), + ("pb", FOUR, pb), + ("m1", FLOAT, m1), + ("m2", FLOAT, m2), + ("etmin_1", FLOAT, e1), + ("etmin_2", FLOAT, e2), + ], + ["lo", "hi"], + ) + t_min, t_max = kernel( + "t_inv_min_max_massive", + [("pa", FOUR, pa), ("pb", FOUR, pb), ("m1", FLOAT, m1), ("m2", FLOAT, m2)], + ["t_min", "t_max"], + ) + passes = (et(p1) >= et1) & (et(p2) >= et2) + t = t_abs(pa, p1) + assert passes.sum() > 100 + assert np.all(t[passes] >= lo[passes] - 1e-9 * SQRT_S**2) + assert np.all(t[passes] <= hi[passes] + 1e-9 * SQRT_S**2) + assert np.mean((lo > t_min) | (hi < t_max)) > 0.2 + + +def rounded(p, seed): + """p with a relative error of 4e-16 in each component, which leaves the + mass^2 of a massless beam rounding of either sign, as fused multiply-adds + do (the scalar build on arm64)""" + rng = np.random.default_rng(seed) + return p * (1.0 + 4e-16 * rng.standard_normal(p.shape)) + + +ROUNDING = pytest.mark.parametrize("rounding", [False, True], ids=["exact", "rounded"]) + + +@ROUNDING +def test_massive_kernels_have_the_massless_limit(rounding): + """With massless beams the massive kernels give the massless ranges, also + where the floors of the ETmin bound leave nothing.""" + m_out = [173.0, 10.0] + mapping = PSM([0.0, 0.0] + m_out, SQRT_S, leptonic=False, mode=PSM.propagator) + p, x1, x2, det = forward(mapping, draw(mapping, 24, 20000)) + ok = det > 0 + p, x1, x2 = p[ok], x1[ok], x2[ok] + p = np.stack([boost_z(p[:, i], 0.5 * np.log(x1 / x2)) for i in range(4)], axis=1) + if rounding: + p = rounded(p, 32) + n = len(x1) + momenta = [("pa", FOUR, p[:, 0]), ("pb", FOUR, p[:, 1])] + masses = [("m1", FLOAT, np.full(n, m_out[0])), ("m2", FLOAT, np.full(n, m_out[1]))] + for name in ["t_inv_min_max"]: + massless = kernel(name, momenta + masses, ["lo", "hi"]) + massive = kernel(name + "_massive", momenta + masses, ["lo", "hi"]) + assert massive[0] == approx(massless[0], rel=1e-9, abs=1e-9) + assert massive[1] == approx(massless[1], rel=1e-12) + ranges = kernel("t_inv_min_max", momenta + masses, ["lo", "hi"]) + clamp_inputs = [("t_min", FLOAT, ranges[0]), ("t_max", FLOAT, ranges[1])] + clamp_inputs += momenta + masses + [("x1", FLOAT, x1), ("x2", FLOAT, x2)] + massless = kernel("t_rapidity_clamp", clamp_inputs, ["lo", "hi"], 1.0, 1.2, 0.7) + massive = kernel( + "t_rapidity_clamp_massive", clamp_inputs, ["lo", "hi"], 1.0, 1.2, 0.7 + ) + assert massive[0] == approx(massless[0], rel=1e-9, abs=1e-6) + assert massive[1] == approx(massless[1], rel=1e-9, abs=1e-6) + # the ETmin bound + etmin = [ + ("etmin_1", FLOAT, np.full(n, 200.0)), + ("etmin_2", FLOAT, np.full(n, 50.0)), + ] + massless = kernel("t_inv_min_max_cut", momenta + masses + etmin, ["lo", "hi"]) + massive = kernel( + "t_inv_min_max_cut_massive", momenta + masses + etmin, ["lo", "hi"] + ) + assert np.mean(massless[0] > ranges[0]) > 0.2 + assert massive[0] == approx(massless[0], rel=1e-9, abs=1e-6) + assert massive[1] == approx(massless[1], rel=1e-9, abs=1e-6) + + +def rambo_events(m_in, m_out, leptonic, n=50000, seed=25): + """Events in the partonic frame, from rambo, which builds the massive beams + without any of the kernels below: p (n, 2 + n_out, 4), x1, x2""" + mapping = PSM(list(m_in) + list(m_out), SQRT_S, leptonic=leptonic, mode=PSM.rambo) + p, x1, x2, det = forward(mapping, draw(mapping, seed, n)) + ok = det > 0 + p, x1, x2 = p[ok], x1[ok], x2[ok] + y = 0.5 * np.log(x1 / x2) + p = np.stack([boost_z(p[:, i], y) for i in range(p.shape[1])], axis=1) + return p, x1, x2 + + +def transverse_mass(p): + return np.sqrt(np.maximum(mass2(p) + p[..., 1] ** 2 + p[..., 2] ** 2, 0.0)) + + +COLUMNS = itertools.count() + + +def column(value, n): + """a kernel input of n copies of value, under a name of its own""" + return (f"c{next(COLUMNS)}", FLOAT, np.full(n, float(value))) + + +# the double-t block pa pb -> p1 X, with p1 a massive and a massless particle +DOUBLE_T = {"heavy": ([173.0, 10.0, 0.0], 0), "light": ([173.0, 10.0, 0.0], 2)} + + +def double_t_events(m_in, case, leptonic=False, seed=26): + m_out, single = DOUBLE_T[case] + p, x1, x2 = rambo_events(m_in, m_out, leptonic, seed=seed) + pa, pb = p[:, 0], p[:, 1] + p1 = p[:, 2 + single] + recoil = p[:, 2:].sum(axis=1) - p1 + m1 = m_out[single] + mir_min = sum(m_out) - m1 + return pa, pb, p1, recoil, m1, mir_min, x1, x2 + + +def double_t_ranges(name, pa, pb, m1, mir_min, et_i, et_ir, t1=None): + n = len(pa) + inputs = [("pa", FOUR, pa), ("pb", FOUR, pb), column(m1, n), column(mir_min, n)] + if t1 is not None: + inputs.append(("t1", FLOAT, t1)) + inputs += [column(et_i, n), column(et_ir, n)] + return kernel(name, inputs, ["lo", "hi"]) + + +@pytest.mark.parametrize("case", list(DOUBLE_T)) +def test_double_t_ranges_keep_what_passes(case): + """Every event of pa pb -> p1 X off massive beams has |t1| = -(pa - p1)^2 + and |t2| = -(pb - p1)^2 inside the ranges of the massive double-t kernels, + with the ETmin bounds where p1 and X pass them. |t1| reaches below 0, down + to -(ma - m1)^2 for a massless p1.""" + pa, pb, p1, recoil, m1, mir_min, x1, x2 = double_t_events(M_IN, case) + t1, t2 = t_abs(pa, p1), t_abs(pb, p1) + tolerance = 1e-9 * SQRT_S**2 + assert t1.min() < 0.0 + for et_i, et_ir in [(0.0, 0.0), (60.0, 200.0), (200.0, 60.0)]: + lo1, hi1 = double_t_ranges( + "t1_inv_min_max_doublet_massive", pa, pb, m1, mir_min, et_i, et_ir + ) + lo2, hi2 = double_t_ranges( + "t2_inv_min_max_doublet_massive", pa, pb, m1, mir_min, et_i, et_ir, t1 + ) + passes = (transverse_mass(p1) >= et_i) & (transverse_mass(recoil) >= et_ir) + assert passes.sum() > 100 + assert np.all(t1[passes] >= lo1[passes] - tolerance) + assert np.all(t1[passes] <= hi1[passes] + tolerance) + assert np.all(t2[passes] >= lo2[passes] - tolerance) + assert np.all(t2[passes] <= hi2[passes] + tolerance) + if et_i == 0.0: + if m1 == 0.0: + assert lo1 == approx(-M_IN[0] ** 2, rel=1e-9) + # the ranges are those of the events + assert t1.min() == approx(lo1.min(), rel=0.05, abs=0.02 * M_IN[0] ** 2) + assert np.mean(t2 > 0.98 * hi2 - 1e-3 * SQRT_S**2) > 0.0 + + +@pytest.mark.parametrize("case", list(DOUBLE_T)) +def test_double_t_rapidity_clamps_keep_what_passes(case): + """The same for the rapidity clamps of the double-t block off massive + beams, with the transverse-energy floors of the |t1| clamp, in the lab + frame of hadronic events; they narrow the ranges of many events.""" + pa, pb, p1, recoil, m1, mir_min, x1, x2 = double_t_events(M_IN, case, seed=27) + n = len(x1) + t1, t2 = t_abs(pa, p1), t_abs(pb, p1) + tolerance = 1e-9 * SQRT_S**2 + y_boost = 0.5 * np.log(x1 / x2) + y1, y2 = rapidity(p1) + y_boost, rapidity(recoil) + y_boost + lo1, hi1 = double_t_ranges( + "t1_inv_min_max_doublet_massive", pa, pb, m1, mir_min, 0.0, 0.0 + ) + beams = [("pa", FOUR, pa), ("pb", FOUR, pb), column(m1, n)] + fractions = [("x1", FLOAT, x1), ("x2", FLOAT, x2)] + narrowed1, narrowed2 = [], [] + for y_max1, y_max2, et1, et2 in [ + (1.0, 2.0, 0.0, 0.0), + (2.5, 0.5, 50.0, 0.0), + (-1.0, 1.5, 0.0, 150.0), + (0.8, -1.0, 100.0, 100.0), + ]: + clamp1 = kernel( + "t1_rapidity_clamp_doublet_massive", + [("t1_min", FLOAT, lo1), ("t1_max", FLOAT, hi1)] + + beams + + [column(mir_min, n), column(et1, n), column(et2, n)] + + fractions, + ["lo", "hi"], + 1.0, + y_max1, + y_max2, + ) + lo2, hi2 = double_t_ranges( + "t2_inv_min_max_doublet_massive", pa, pb, m1, mir_min, 0.0, 0.0, t1 + ) + clamp2 = kernel( + "t2_rapidity_clamp_doublet_massive", + [("t2_min", FLOAT, lo2), ("t2_max", FLOAT, hi2)] + + beams + + [("t1", FLOAT, t1)] + + fractions, + ["lo", "hi"], + 1.0, + y_max1, + y_max2, + ) + passes = (y_max1 < 0) | (np.abs(y1) <= y_max1) + passes &= (y_max2 < 0) | (np.abs(y2) <= y_max2) + passes &= (transverse_mass(p1) >= et1) & (transverse_mass(recoil) >= et2) + assert passes.sum() > 100 + assert np.all(t1[passes] >= clamp1[0][passes] - tolerance) + assert np.all(t1[passes] <= clamp1[1][passes] + tolerance) + assert np.all(t2[passes] >= clamp2[0][passes] - tolerance) + assert np.all(t2[passes] <= clamp2[1][passes] + tolerance) + narrowed1.append(np.mean(clamp1[1] - clamp1[0] < 0.9 * (hi1 - lo1))) + narrowed2.append(np.mean(clamp2[1] - clamp2[0] < 0.9 * (hi2 - lo2))) + assert max(narrowed1) > 0.2 and max(narrowed2) > 0.2 + + +def test_double_t_scattering_round_trip(): + """The massive double-t scattering puts p1 back from its |t1|, |t2| and + azimuth, with Jacobians that are each other's inverses.""" + pa, pb, p1, recoil, m1, mir_min, x1, x2 = double_t_events(M_IN, "heavy", seed=28) + n = len(x1) + beams = [("pa", FOUR, pa), ("pb", FOUR, pb)] + r_phi, det_inv = kernel( + "double_t_scattering_inverse_massive", + [("p1", FOUR, p1), ("p2", FOUR, recoil)] + beams, + ["r_phi", "det"], + ) + fb = ms.FunctionBuilder( + ms.NamedTypes( + [("r", FLOAT), ("pa", FOUR), ("pb", FOUR), ("t1", FLOAT), ("t2", FLOAT)] + + [("m1", FLOAT)] + ), + ms.NamedTypes([("p1", FOUR), ("p2", FOUR), ("det", FLOAT)]), + ) + out = fb.double_t_scattering_massive(*[fb.input(i) for i in range(6)]) + for i in range(3): + fb.output(i, out[i]) + q1, q2, det = run(fb, [r_phi, pa, pb, t_abs(pa, p1), t_abs(pb, p1), np.full(n, m1)]) + assert q1 == approx(p1, rel=1e-9, abs=1e-9 * SQRT_S) + assert q2 == approx(recoil, rel=1e-9, abs=1e-9 * SQRT_S) + assert det * det_inv == approx(1.0, rel=1e-12) + s = mass2(pa + pb) + lam = (s - sum(M_IN) ** 2) * (s - (M_IN[0] - M_IN[1]) ** 2) + assert det == approx(math.pi / (2.0 * np.sqrt(lam)), rel=1e-9) + + +@ROUNDING +def test_double_t_kernels_have_the_massless_limit(rounding): + """With massless beams the massive double-t kernels give the massless + ranges, clamps and momenta.""" + pa, pb, p1, recoil, m1, mir_min, x1, x2 = double_t_events( + [0.0, 0.0], "heavy", seed=29 + ) + if rounding: + pa, pb = rounded(pa, 33), rounded(pb, 34) + n = len(x1) + t1 = t_abs(pa, p1) + for et_i, et_ir in [(0.0, 0.0), (200.0, 60.0)]: + for name, extra in [ + ("t1_inv_min_max_doublet", None), + ("t2_inv_min_max_doublet", t1), + ]: + massless = double_t_ranges(name, pa, pb, m1, mir_min, et_i, et_ir, extra) + massive = double_t_ranges( + name + "_massive", pa, pb, m1, mir_min, et_i, et_ir, extra + ) + for a, b in zip(massive, massless): + assert a == approx(b, rel=1e-9, abs=1e-6) + lo1, hi1 = double_t_ranges("t1_inv_min_max_doublet", pa, pb, m1, mir_min, 0, 0) + lo2, hi2 = double_t_ranges("t2_inv_min_max_doublet", pa, pb, m1, mir_min, 0, 0, t1) + beams = [("pa", FOUR, pa), ("pb", FOUR, pb), column(m1, n)] + fractions = [("x1", FLOAT, x1), ("x2", FLOAT, x2)] + inputs1 = [("t1_min", FLOAT, lo1), ("t1_max", FLOAT, hi1)] + beams + inputs1 += [column(mir_min, n), column(50.0, n), column(100.0, n)] + fractions + inputs2 = [("t2_min", FLOAT, lo2), ("t2_max", FLOAT, hi2)] + beams + inputs2 += [("t1", FLOAT, t1)] + fractions + for name, inputs in [ + ("t1_rapidity_clamp_doublet", inputs1), + ("t2_rapidity_clamp_doublet", inputs2), + ]: + massless = kernel(name, inputs, ["lo", "hi"], 1.0, 1.2, 0.7) + massive = kernel(name + "_massive", inputs, ["lo", "hi"], 1.0, 1.2, 0.7) + assert np.mean(massless[1] - massless[0] < hi1.mean() - lo1.mean()) > 0.2 + for a, b in zip(massive, massless): + assert a == approx(b, rel=1e-9, abs=1e-6) + inputs = [("r", FLOAT, np.random.default_rng(30).random(n)), ("pa", FOUR, pa)] + inputs += [("pb", FOUR, pb), ("t1", FLOAT, t1), ("t2", FLOAT, t_abs(pb, p1))] + inputs += [column(m1, n)] + names = ["p1", "p2", "det"] + fb_out = [] + for name in ["double_t_scattering", "double_t_scattering_massive"]: + fb = ms.FunctionBuilder( + ms.NamedTypes([(k, t) for k, t, _ in inputs]), + ms.NamedTypes([("p1", FOUR), ("p2", FOUR), ("det", FLOAT)]), + ) + out = getattr(fb, name)(*[fb.input(i) for i in range(len(inputs))]) + for i in range(3): + fb.output(i, out[i]) + fb_out.append(run(fb, [a for _, _, a in inputs])) + for a, b in zip(*fb_out): + assert a == approx(b, rel=1e-9, abs=1e-9 * SQRT_S) + + +def two_to_three_events(m_in, seed=31): + """pa, p12, p3 and p1, p2 of a 2 -> 3 step: p1 the system the chain hands + on (here a top), p2 the peeled jet and p3 the previously peeled jet""" + p, x1, x2 = rambo_events(m_in, [173.0, 0.0, 0.0], True, seed=seed) + return p[:, 1], p[:, 2] + p[:, 3], p[:, 4], p[:, 2], p[:, 3] + + +def s23_cut_range(name, pa, p12, p3, p1, p2, et1, et2): + n = len(pa) + inputs = [("pa", FOUR, pa), ("p12", FOUR, p12), ("p3", FOUR, p3)] + inputs += [("t1", FLOAT, t_abs(pa, p1))] + inputs += [column(173.0, n), column(0.0, n), column(et1, n), column(et2, n)] + inputs += [column(0.0, n), column(0.0, n)] + return kernel(name, inputs, ["lo", "hi"]) + + +def test_s23_cut_range_keeps_what_passes(): + """Every 2 -> 3 step off a massive beam whose outgoing particles pass the + transverse-energy floors has its s23 inside the range of + s23_min_max_cut_massive, and for massless beams that range is the + massless one.""" + pa, p12, p3, p1, p2 = two_to_three_events(M_IN) + s23 = mass2(p2 + p3) + for et1, et2 in [(200.0, 30.0), (300.0, 80.0)]: + lo, hi = s23_cut_range("s23_min_max_cut_massive", pa, p12, p3, p1, p2, et1, et2) + passes = (transverse_mass(p1) >= et1) & (transverse_mass(p2) >= et2) + assert passes.sum() > 100 + assert np.all(s23[passes] >= lo[passes] * (1 - 1e-9) - 1e-9 * SQRT_S**2) + assert np.all(s23[passes] <= hi[passes] * (1 + 1e-9) + 1e-9 * SQRT_S**2) + pa, p12, p3, p1, p2 = two_to_three_events([0.0, 0.0], seed=32) + massless = s23_cut_range("s23_min_max_cut", pa, p12, p3, p1, p2, 200.0, 30.0) + massive = s23_cut_range("s23_min_max_cut_massive", pa, p12, p3, p1, p2, 200.0, 30.0) + for a, b in zip(massive, massless): + assert a == approx(b, rel=1e-9, abs=1e-6) + + +def test_recoil_v_floor_keeps_what_passes(): + """v = -(p2 - k)^2 of every outgoing particle p2 that passes its + transverse-energy floor is above recoil_v_min_massive, which reaches below + 0 for a floor below the beam mass and is etmin_2^2 - m2^2 for massless + beams.""" + p, x1, x2 = rambo_events(M_IN, [173.0, 0.0, 0.0], True, seed=33) + n = len(x1) + for k_leg, pa_leg in [(0, 1), (1, 0)]: + pa, k = p[:, pa_leg], p[:, k_leg] + for leg, m2 in [(2, 173.0), (3, 0.0), (4, 0.0)]: + p2 = p[:, leg] + v = -mass2(p2 - k) + for et in [20.0, 60.0, 200.0]: + (v_min,) = kernel( + "recoil_v_min_massive", + [("pa", FOUR, pa), ("k", FOUR, k), column(m2**2, n), column(et, n)], + ["v_min"], + ) + passes = transverse_mass(p2) >= et + if passes.sum() > 100: + assert np.all(v[passes] >= v_min[passes] - 1e-9 * SQRT_S**2) + pa, k = p[:, 1], p[:, 0] + (v_min,) = kernel( + "recoil_v_min_massive", + [("pa", FOUR, pa), ("k", FOUR, k), column(0.0, n), column(20.0, n)], + ["v_min"], + ) + assert np.all(v_min < 0.0) + q, _, _ = rambo_events([0.0, 0.0], [0.0, 0.0, 0.0], True, seed=34) + (v_min,) = kernel( + "recoil_v_min_massive", + [("pa", FOUR, q[:, 1]), ("k", FOUR, q[:, 0])] + + [column(0.0, len(q)), column(30.0, len(q))], + ["v_min"], + ) + assert v_min == approx(900.0, rel=1e-12) diff --git a/tests/unit_tests/various/test_mg7_massive_incoming.py b/tests/unit_tests/various/test_mg7_massive_incoming.py index 901b3de20d..e8cf14cbbc 100644 --- a/tests/unit_tests/various/test_mg7_massive_incoming.py +++ b/tests/unit_tests/various/test_mg7_massive_incoming.py @@ -14,12 +14,13 @@ ################################################################################ """Massive incoming particles in mg7, as madevent has them (genps.f). -The phase-space mappings of madspace build the incoming momenta massless. The -Integrand puts massive ones on their mass shell, with the same sum, and the -flux 1/(2 sqrt(lambda(s, m1^2, m2^2))) instead of 1/(2 s) (the -incoming_on_shell kernel); for monochromatic beams the run's s and beam -rapidity are those of the massive beam momenta (MadgraphProcess._massive_beams). -Without this, w+ w- > t t~ with 2 x 500 GeV W beams was 10% low. +The phase-space mapping of madspace builds massive incoming particles on their +mass shells (madspace/tests/test_massive_incoming.py), and +DifferentialCrossSection takes the flux 1/(2 sqrt(lambda(s, m1^2, m2^2))) +instead of 1/(2 s) from the same incoming_masses. For monochromatic beams the +run's s and beam rapidity are those of the massive beam momenta +(MadgraphProcess._massive_beams). Without this, w+ w- > t t~ with 2 x 500 GeV +W beams was 10% low. """ import math import os @@ -48,7 +49,7 @@ def on_shell(self, p, masses): vec = ms.batch_four_vec_array(p.shape[1]) fb = ms.FunctionBuilder( ms.NamedTypes([('p', vec)]), - ms.NamedTypes([('p_out', vec), ('flux_ratio', ms.batch_float)])) + ms.NamedTypes([('p_out', vec), ('above_threshold', ms.batch_float)])) out = fb.incoming_on_shell(fb.input(0), ms.Value(list(masses))) fb.output(0, out[0]) fb.output(1, out[1]) @@ -69,7 +70,7 @@ def test_on_shell_with_the_same_sum(self): p[:, 1, 0], p[:, 1, 3] = e2, np.where(mirror, e2, -e2) p[:, 2] = [500., 30., -40., 100.] p[:, 3] = [400., -30., 40., -50.] - p_out, flux = self.on_shell(p, masses) + p_out, above_threshold = self.on_shell(p, masses) p_in = p_out[:, :2] s = (p[:, 0, 0] + p[:, 1, 0]) ** 2 - (p[:, 0, 3] + p[:, 1, 3]) ** 2 above = s > sum(masses) ** 2 @@ -91,13 +92,8 @@ def test_on_shell_with_the_same_sum(self): np.testing.assert_allclose(p_in[a].sum(axis=1), p[a, :2].sum(axis=1), rtol=1e-12, atol=1e-9) np.testing.assert_array_equal(p_out[:, 2:], p[:, 2:]) - # the flux ratio s / sqrt(lambda) - m1, m2 = masses - lam = (s - (m1 + m2) ** 2) * (s - (m1 - m2) ** 2) - np.testing.assert_allclose(flux[a], s[a] / np.sqrt(lam[a]), rtol=1e-12) - # below threshold: no weight, momenta as they were - self.assertTrue(np.all(flux[~a] == 0.)) - np.testing.assert_array_equal(p_out[~a], p[~a]) + # below threshold: flagged, as no weight in the mapping + np.testing.assert_array_equal(above_threshold, np.where(a, 1., 0.)) def test_monochromatic_beams_come_out_as_madevent_has_them(self): """With the run's s and rapidity from _massive_beams, the mapping's @@ -117,7 +113,7 @@ def test_monochromatic_beams_come_out_as_madevent_has_them(self): p[0, leg] = [half * math.cosh(y) + sign * half * math.sinh(y), 0., 0., sign * half * math.cosh(y) + half * math.sinh(y)] p[0, 2] = p[0, 0] + p[0, 1] - p_out, flux = self.on_shell(p, (mw, mw)) + p_out, _ = self.on_shell(p, (mw, mw)) np.testing.assert_allclose(p_out[0, 0], [400., 0., 0., p1], rtol=1e-12) np.testing.assert_allclose(p_out[0, 1], [600., 0., 0., -p2], rtol=1e-12) # massless beams keep s = 4 E1 E2