Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:14:37

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 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/ReconstructedParticleCollection.h>
0009 #include <edm4hep/MCParticleCollection.h>
0010 #include <edm4hep/Vector3f.h>
0011 #include <fmt/core.h>
0012 #include <cmath>
0013 #include <gsl/pointers>
0014 
0015 #include "Beam.h"
0016 #include "Boost.h"
0017 #include "InclusiveKinematicsDA.h"
0018 
0019 using ROOT::Math::PxPyPzEVector;
0020 
0021 namespace eicrecon {
0022 
0023 void InclusiveKinematicsDA::init() {}
0024 
0025 void InclusiveKinematicsDA::process(const InclusiveKinematicsDA::Input& input,
0026                                     const InclusiveKinematicsDA::Output& output) const {
0027 
0028   const auto [mcparts, escat, hfs] = input;
0029   auto [kinematics]                = output;
0030 
0031   // Get incoming electron beam
0032   const auto ei_coll = find_first_beam_electron(mcparts);
0033   if (ei_coll.empty()) {
0034     debug("No beam electron found");
0035     return;
0036   }
0037   const PxPyPzEVector ei(round_beam_four_momentum(ei_coll[0].getMomentum(),
0038                                                   m_particleSvc.particle(ei_coll[0].getPDG()).mass,
0039                                                   {-5.0, -10.0, -18.0}, 0.0));
0040 
0041   // Get incoming hadron beam
0042   const auto pi_coll = find_first_beam_hadron(mcparts);
0043   if (pi_coll.empty()) {
0044     debug("No beam hadron found");
0045     return;
0046   }
0047   const PxPyPzEVector pi(round_beam_four_momentum(pi_coll[0].getMomentum(),
0048                                                   m_particleSvc.particle(pi_coll[0].getPDG()).mass,
0049                                                   {41.0, 100.0, 275.0}, m_crossingAngle));
0050 
0051   // Get boost to colinear frame
0052   auto boost = determine_boost(ei, pi);
0053 
0054   // Get electron angle
0055   if (escat->empty()) {
0056     debug("No scattered electron found");
0057     return;
0058   }
0059   auto kf = escat->at(0);
0060   PxPyPzEVector e_lab(kf.getMomentum().x, kf.getMomentum().y, kf.getMomentum().z, kf.getEnergy());
0061   PxPyPzEVector e_boosted = apply_boost(boost, e_lab);
0062   auto theta_e            = e_boosted.Theta();
0063 
0064   // Get hadronic final state variables
0065   if (hfs->empty()) {
0066     debug("No hadronic final state found");
0067     return;
0068   }
0069   auto sigma_h = hfs->at(0).getSigma();
0070   auto gamma_h = hfs->at(0).getGamma();
0071 
0072   // Sigma zero or negative
0073   if (sigma_h <= 0) {
0074     debug("Sigma zero or negative");
0075     return;
0076   }
0077 
0078   // Calculate kinematic variables
0079   static const auto m_proton = m_particleSvc.particle(2212).mass;
0080   const auto y_da            = tan(gamma_h / 2.) / (tan(theta_e / 2.) + tan(gamma_h / 2.));
0081   const auto Q2_da           = 4. * ei.energy() * ei.energy() * (1. / tan(theta_e / 2.)) *
0082                      (1. / (tan(theta_e / 2.) + tan(gamma_h / 2.)));
0083   const auto x_da  = Q2_da / (4. * ei.energy() * pi.energy() * y_da);
0084   const auto nu_da = Q2_da / (2. * m_proton * x_da);
0085   const auto W_da  = sqrt(m_proton * m_proton + 2 * m_proton * nu_da - Q2_da);
0086   auto kin         = kinematics->create(x_da, Q2_da, W_da, y_da, nu_da);
0087   kin.setScat(kf);
0088 
0089   debug("x,Q2,W,y,nu = {},{},{},{},{}", kin.getX(), kin.getQ2(), kin.getW(), kin.getY(),
0090         kin.getNu());
0091 }
0092 
0093 } // namespace eicrecon