Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-10 07:55:28

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024 Tyler Kutz
0003 
0004 #include <Math/GenVector/LorentzVector.h>
0005 #include <Math/GenVector/PxPyPzE4D.h>
0006 #include <Math/Vector4Dfwd.h>
0007 #include <edm4eic/HadronicFinalStateCollection.h>
0008 #include <edm4eic/MCRecoParticleAssociationCollection.h>
0009 #include <edm4eic/ReconstructedParticleCollection.h>
0010 #include <edm4hep/MCParticleCollection.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <fmt/core.h>
0013 #include <podio/ObjectID.h>
0014 #include <cmath>
0015 #include <gsl/pointers>
0016 
0017 #include "Beam.h"
0018 #include "Boost.h"
0019 #include "HadronicFinalState.h"
0020 
0021 using ROOT::Math::PxPyPzEVector;
0022 
0023 namespace eicrecon {
0024 
0025 void HadronicFinalState::init() {}
0026 
0027 void HadronicFinalState::process(const HadronicFinalState::Input& input,
0028                                  const HadronicFinalState::Output& output) const {
0029 
0030   const auto [mcparts, rcparts, rcassoc] = input;
0031   auto [hadronicfinalstate]              = output;
0032 
0033   // Get incoming electron beam
0034   const auto ei_coll = find_first_beam_electron(mcparts);
0035   if (ei_coll.empty()) {
0036     debug("No beam electron found");
0037     return;
0038   }
0039   const PxPyPzEVector ei(round_beam_four_momentum(ei_coll[0].getMomentum(),
0040                                                   m_particleSvc.particle(ei_coll[0].getPDG()).mass,
0041                                                   {-5.0, -10.0, -18.0}, 0.0));
0042 
0043   // Get incoming hadron beam
0044   const auto pi_coll = find_first_beam_hadron(mcparts);
0045   if (pi_coll.empty()) {
0046     debug("No beam hadron found");
0047     return;
0048   }
0049   const PxPyPzEVector pi(round_beam_four_momentum(pi_coll[0].getMomentum(),
0050                                                   m_particleSvc.particle(pi_coll[0].getPDG()).mass,
0051                                                   {41.0, 100.0, 275.0}, m_crossingAngle));
0052 
0053   // Get first scattered electron
0054   const auto ef_coll = find_first_scattered_electron(mcparts);
0055   if (ef_coll.empty()) {
0056     debug("No truth scattered electron found");
0057     return;
0058   }
0059   // Associate first scattered electron with reconstructed electrons
0060   //const auto ef_assoc = std::find_if(
0061   //  rcassoc->begin(),
0062   //  rcassoc->end(),
0063   //  [&ef_coll](const auto& a){ return a.getSim().getObjectID() == ef_coll[0].getObjectID(); });
0064   auto ef_assoc = rcassoc->begin();
0065   for (; ef_assoc != rcassoc->end(); ++ef_assoc) {
0066     if (ef_assoc->getSim().getObjectID() == ef_coll[0].getObjectID()) {
0067       break;
0068     }
0069   }
0070   if (!(ef_assoc != rcassoc->end())) {
0071     debug("Truth scattered electron not in reconstructed particles");
0072     return;
0073   }
0074   const auto ef_rc{ef_assoc->getRec()};
0075   const auto ef_rc_id{ef_rc.getObjectID().index};
0076 
0077   // Sums in colinear frame
0078   double pxsum = 0;
0079   double pysum = 0;
0080   double pzsum = 0;
0081   double Esum  = 0;
0082 
0083   // Get boost to colinear frame
0084   auto boost = determine_boost(ei, pi);
0085 
0086   auto hfs = hadronicfinalstate->create(0., 0., 0.);
0087 
0088   for (const auto& p : *rcparts) {
0089     // Check if it's the scattered electron
0090     if (p.getObjectID().index != ef_rc_id) {
0091       // Lorentz vector in lab frame
0092       PxPyPzEVector hf_lab(p.getMomentum().x, p.getMomentum().y, p.getMomentum().z, p.getEnergy());
0093       // Boost to colinear frame
0094       PxPyPzEVector hf_boosted = apply_boost(boost, hf_lab);
0095 
0096       pxsum += hf_boosted.Px();
0097       pysum += hf_boosted.Py();
0098       pzsum += hf_boosted.Pz();
0099       Esum += hf_boosted.E();
0100 
0101       hfs.addToHadrons(p);
0102     }
0103   }
0104 
0105   // Hadronic final state calculations
0106   auto sigma = Esum - pzsum;
0107   auto pT    = sqrt(pxsum * pxsum + pysum * pysum);
0108   auto gamma = acos((pT * pT - sigma * sigma) / (pT * pT + sigma * sigma));
0109 
0110   hfs.setSigma(sigma);
0111   hfs.setPT(pT);
0112   hfs.setGamma(gamma);
0113 
0114   // Sigma zero or negative
0115   if (sigma <= 0) {
0116     debug("Sigma zero or negative");
0117     return;
0118   }
0119 
0120   debug("sigma_h, pT_h, gamma_h = {},{},{}", hfs.getSigma(), hfs.getPT(), hfs.getGamma());
0121 }
0122 
0123 } // namespace eicrecon