Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-28 09:20:46

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2026 Wouter Deconinck
0003 
0004 #include <Math/GenVector/LorentzVector.h>
0005 #include <Math/GenVector/PxPyPzE4D.h>
0006 #include <Math/Vector4Dfwd.h>
0007 #include <edm4eic/InclusiveKinematicsCollection.h>
0008 #include <edm4eic/unit_system.h>
0009 #include <edm4hep/MCParticleCollection.h>
0010 #include <edm4hep/Vector3d.h>
0011 #include <cmath>
0012 #include <cstdlib>
0013 #include <optional>
0014 #include <tuple>
0015 #include <vector>
0016 
0017 #include "InclusiveKinematicsTruthBorn.h"
0018 #include "TruthLeptonLine.h"
0019 
0020 using ROOT::Math::PxPyPzEVector;
0021 
0022 namespace {
0023 // Maximum momentum difference between the momentum transfer and the exchanged boson
0024 constexpr double boson_momentum_tolerance = 10 * edm4eic::unit::MeV;
0025 } // namespace
0026 
0027 namespace eicrecon {
0028 
0029 void InclusiveKinematicsTruthBorn::init() {}
0030 
0031 void InclusiveKinematicsTruthBorn::process(
0032     const InclusiveKinematicsTruthBorn::Input& input,
0033     const InclusiveKinematicsTruthBorn::Output& output) const {
0034 
0035   const auto [mcparts] = input;
0036   auto [kinematics]    = output;
0037 
0038   // Get lepton line of the signal interaction
0039   const auto truth = find_lepton_line_truth(*mcparts);
0040   if (!truth.has_value()) {
0041     debug("No beam electron with a final-state scattered lepton found");
0042     return;
0043   }
0044 
0045   // Get incoming electron beam
0046   static const auto ei_mass = m_particleSvc.particle(11).mass;
0047   const PxPyPzEVector ei    = four_momentum(truth->beam_lepton(), ei_mass);
0048 
0049   // Get incoming hadron beam
0050   if (!truth->beam_hadron.has_value()) {
0051     debug("No beam hadron found");
0052     return;
0053   }
0054   const auto& pi_particle = *truth->beam_hadron;
0055   const auto pi_beam      = beam_per_nucleon(
0056       pi_particle,
0057       is_ion(pi_particle.getPDG()) ? 0. : m_particleSvc.particle(pi_particle.getPDG()).mass);
0058 
0059   // Get scattered lepton
0060   const auto lepton_mass = [this](const edm4hep::MCParticle& p) {
0061     return m_particleSvc.particle(std::abs(p.getPDG())).mass;
0062   };
0063   const auto& ef_particle = truth->scattered_lepton();
0064   const PxPyPzEVector ef  = four_momentum(ef_particle, lepton_mass(ef_particle));
0065 
0066   // Four-momentum transfer at the hadronic vertex: between the hard-scattering leptons when the
0067   // record marks them, otherwise from momentum conservation along the lepton line
0068   PxPyPzEVector q;
0069   if (truth->hard_in.has_value() && truth->hard_out.has_value() &&
0070       *truth->hard_in < *truth->hard_out) {
0071     const auto& l_in  = truth->line[*truth->hard_in];
0072     const auto& l_out = truth->line[*truth->hard_out];
0073     q = four_momentum(l_in, lepton_mass(l_in)) - four_momentum(l_out, lepton_mass(l_out));
0074     trace("q from hard-scattering leptons");
0075   } else {
0076     PxPyPzEVector photons;
0077     for (const auto& photon : truth->photons) {
0078       photons += four_momentum(photon.particle);
0079     }
0080     q = ei - ef - photons;
0081     trace("q from lepton line with {} radiated photons", truth->photons.size());
0082   }
0083 
0084   // Check against the exchanged boson, when stored. Only its momentum is compared: its energy
0085   // follows from its stored mass, which generators write with limited precision.
0086   if (truth->boson.has_value()) {
0087     const auto& p_boson = truth->boson->getMomentum();
0088     const double dp     = std::hypot(p_boson.x - q.Px(), p_boson.y - q.Py(), p_boson.z - q.Pz());
0089     if (dp > boson_momentum_tolerance) {
0090       warning("Momentum transfer differs from exchanged boson (PDG {}) by {} GeV",
0091               truth->boson->getPDG(), dp);
0092     }
0093   }
0094 
0095   // DIS kinematics calculations
0096   const auto dis = dis_variables(ei, pi_beam.momentum, pi_beam.mass, q);
0097   auto kin       = kinematics->create(dis.x, dis.Q2, dis.W, dis.y, dis.nu);
0098 
0099   debug("x,Q2,W,y,nu = {},{},{},{},{}", kin.getX(), kin.getQ2(), kin.getW(), kin.getY(),
0100         kin.getNu());
0101 }
0102 
0103 } // namespace eicrecon