File indexing completed on 2025-09-18 08:17:47
0001
0002
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 #include <vector>
0017
0018 #include "Beam.h"
0019 #include "Boost.h"
0020 #include "HadronicFinalState.h"
0021
0022 using ROOT::Math::PxPyPzEVector;
0023
0024 namespace eicrecon {
0025
0026 void HadronicFinalState::init() {}
0027
0028 void HadronicFinalState::process(const HadronicFinalState::Input& input,
0029 const HadronicFinalState::Output& output) const {
0030
0031 const auto [mcparts, rcparts, rcassoc] = input;
0032 auto [hadronicfinalstate] = output;
0033
0034
0035 const auto ei_coll = find_first_beam_electron(mcparts);
0036 if (ei_coll.empty()) {
0037 debug("No beam electron found");
0038 return;
0039 }
0040 const PxPyPzEVector ei(round_beam_four_momentum(ei_coll[0].getMomentum(),
0041 m_particleSvc.particle(ei_coll[0].getPDG()).mass,
0042 {-5.0, -10.0, -18.0}, 0.0));
0043
0044
0045 const auto pi_coll = find_first_beam_hadron(mcparts);
0046 if (pi_coll.empty()) {
0047 debug("No beam hadron found");
0048 return;
0049 }
0050 const PxPyPzEVector pi(round_beam_four_momentum(pi_coll[0].getMomentum(),
0051 m_particleSvc.particle(pi_coll[0].getPDG()).mass,
0052 {41.0, 100.0, 275.0}, m_crossingAngle));
0053
0054
0055 const auto ef_coll = find_first_scattered_electron(mcparts);
0056 if (ef_coll.empty()) {
0057 debug("No truth scattered electron found");
0058 return;
0059 }
0060
0061
0062
0063
0064
0065 auto ef_assoc = rcassoc->begin();
0066 for (; ef_assoc != rcassoc->end(); ++ef_assoc) {
0067 if (ef_assoc->getSim().getObjectID() == ef_coll[0].getObjectID()) {
0068 break;
0069 }
0070 }
0071 if (!(ef_assoc != rcassoc->end())) {
0072 debug("Truth scattered electron not in reconstructed particles");
0073 return;
0074 }
0075 const auto ef_rc{ef_assoc->getRec()};
0076 const auto ef_rc_id{ef_rc.getObjectID().index};
0077
0078
0079 double pxsum = 0;
0080 double pysum = 0;
0081 double pzsum = 0;
0082 double Esum = 0;
0083
0084
0085 auto boost = determine_boost(ei, pi);
0086
0087 auto hfs = hadronicfinalstate->create(0., 0., 0.);
0088
0089 for (const auto& p : *rcparts) {
0090
0091 if (p.getObjectID().index != ef_rc_id) {
0092
0093 PxPyPzEVector hf_lab(p.getMomentum().x, p.getMomentum().y, p.getMomentum().z, p.getEnergy());
0094
0095 PxPyPzEVector hf_boosted = apply_boost(boost, hf_lab);
0096
0097 pxsum += hf_boosted.Px();
0098 pysum += hf_boosted.Py();
0099 pzsum += hf_boosted.Pz();
0100 Esum += hf_boosted.E();
0101
0102 hfs.addToHadrons(p);
0103 }
0104 }
0105
0106
0107 auto sigma = Esum - pzsum;
0108 auto pT = sqrt(pxsum * pxsum + pysum * pysum);
0109 auto gamma = acos((pT * pT - sigma * sigma) / (pT * pT + sigma * sigma));
0110
0111 hfs.setSigma(sigma);
0112 hfs.setPT(pT);
0113 hfs.setGamma(gamma);
0114
0115
0116 if (sigma <= 0) {
0117 debug("Sigma zero or negative");
0118 return;
0119 }
0120
0121 debug("sigma_h, pT_h, gamma_h = {},{},{}", hfs.getSigma(), hfs.getPT(), hfs.getGamma());
0122 }
0123
0124 }