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/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/phasespace.hpp b/madspace/include/madspace/phasespace/phasespace.hpp index 3229ccd7a7..08f4304e0f 100644 --- a/madspace/include/madspace/phasespace/phasespace.hpp +++ b/madspace/include/madspace/phasespace/phasespace.hpp @@ -46,7 +46,10 @@ namespace madspace { * 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`). The n-body phase space depends on the + * 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 @@ -337,8 +340,8 @@ class PhaseSpaceMapping : public Mapping { 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, which is - // written for massless beams + // 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 diff --git a/madspace/instruction_set.yaml b/madspace/instruction_set.yaml index 3bef3b00af..6219dc72ec 100644 --- a/madspace/instruction_set.yaml +++ b/madspace/instruction_set.yaml @@ -3680,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 @@ -3706,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/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/phasespace.cpp b/madspace/src/phasespace/phasespace.cpp index b8d16bce5c..f33f4c43bd 100644 --- a/madspace/src/phasespace/phasespace.cpp +++ b/madspace/src/phasespace/phasespace.cpp @@ -312,10 +312,12 @@ 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), @@ -326,7 +328,8 @@ PhaseSpaceMapping::PhaseSpaceMapping( ), _project_incoming( _massive_incoming && topology.t_propagator_count() > 0 && - t_channel_mode == PhaseSpaceMapping::chili + 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 @@ -706,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. @@ -1087,6 +1105,15 @@ Mapping::Result PhaseSpaceMapping::build_forward_impl( 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; @@ -1094,11 +1121,13 @@ 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) { diff --git a/madspace/src/python/madspace.cpp b/madspace/src/python/madspace.cpp index 6f3f5f4ce3..f027a21426 100644 --- a/madspace/src/python/madspace.cpp +++ b/madspace/src/python/madspace.cpp @@ -1178,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( 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 index ae076cace2..4c1a497539 100644 --- a/madspace/tests/test_massive_incoming.py +++ b/madspace/tests/test_massive_incoming.py @@ -6,9 +6,11 @@ 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 builds the final state -against the massless pair with the same sum and puts it on its mass shells -afterwards (incoming_on_shell), with the same final state and Jacobian too. +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 @@ -43,6 +45,7 @@ ("rambo", True), ("propagator", True), ("color_ordered", True), + ("chili", True), ] MODE_IDS = [ f"{mode}-{'leptonic' if leptonic else 'hadronic'}" for mode, leptonic in MODES