Skip to content

Commit

Permalink
feat: particleSvc to distribute mass by PDG
Browse files Browse the repository at this point in the history
  • Loading branch information
wdconinc committed Jun 4, 2024
1 parent 2e074ae commit d8af15f
Show file tree
Hide file tree
Showing 23 changed files with 368 additions and 26 deletions.
251 changes: 251 additions & 0 deletions src/algorithms/interfaces/ParticleSvc.cc

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions src/algorithms/interfaces/ParticleSvc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2024 Wouter Deconinck

#pragma once

#include <memory>
#include <algorithms/service.h>

namespace algorithms {

class ParticleSvc : public Service<ParticleSvc> {
public:
struct ParticleData {
int pdgCode;
int charge;
double mass;
std::string name;
};
using Particle = ParticleData;
using ParticleMap = std::map<int, Particle>;

public:
ParticleSvc();

virtual void init(std::shared_ptr<ParticleMap> map = nullptr) {
if (map != nullptr) {
m_particleMap = map;
}
}

virtual std::shared_ptr<ParticleMap> particleMap() const {
return m_particleMap;
};

virtual Particle& particle(int pdg) const {
if (m_particleMap->count(pdg) == 0) {
return m_particleMap->at(0);
}
return m_particleMap->at(pdg);
};

protected:
std::shared_ptr<ParticleMap> m_particleMap =
std::make_shared<ParticleMap>(
std::make_pair(0, ParticleData{0, 0, 0.0}));
};

} // namespace algorithms
4 changes: 2 additions & 2 deletions src/algorithms/reco/HadronicFinalState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace eicrecon {
const PxPyPzEVector ei(
round_beam_four_momentum(
ei_coll[0].getMomentum(),
m_electron,
m_particleSvc.particle(ei_coll[0].getPDG()).mass,
{-5.0, -10.0, -18.0},
0.0)
);
Expand All @@ -63,7 +63,7 @@ namespace eicrecon {
const PxPyPzEVector pi(
round_beam_four_momentum(
pi_coll[0].getMomentum(),
pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron,
m_particleSvc.particle(pi_coll[0].getPDG()).mass,
{41.0, 100.0, 275.0},
m_crossingAngle)
);
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/HadronicFinalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using HadronicFinalStateAlgorithm = algorithms::Algorithm<
Expand All @@ -31,7 +33,8 @@ class HadronicFinalState : public HadronicFinalStateAlgorithm {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
5 changes: 3 additions & 2 deletions src/algorithms/reco/InclusiveKinematicsDA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace eicrecon {
const PxPyPzEVector ei(
round_beam_four_momentum(
ei_coll[0].getMomentum(),
m_electron,
m_particleSvc.particle(ei_coll[0].getPDG()).mass,
{-5.0, -10.0, -18.0},
0.0)
);
Expand All @@ -61,7 +61,7 @@ namespace eicrecon {
const PxPyPzEVector pi(
round_beam_four_momentum(
pi_coll[0].getMomentum(),
pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron,
m_particleSvc.particle(pi_coll[0].getPDG()).mass,
{41.0, 100.0, 275.0},
m_crossingAngle)
);
Expand All @@ -87,6 +87,7 @@ namespace eicrecon {
}

// Calculate kinematic variables
const auto m_proton = m_particleSvc.particle(2212).mass;
const auto y_da = tan(gamma_h/2.) / ( tan(theta_e/2.) + tan(gamma_h/2.) );
const auto Q2_da = 4.*ei.energy()*ei.energy() * ( 1. / tan(theta_e/2.) ) * ( 1. / (tan(theta_e/2.) + tan(gamma_h/2.)) );
const auto x_da = Q2_da / (4.*ei.energy()*pi.energy()*y_da);
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/InclusiveKinematicsDA.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using InclusiveKinematicsDAAlgorithm = algorithms::Algorithm<
Expand All @@ -32,7 +34,8 @@ class InclusiveKinematicsDA : public InclusiveKinematicsDAAlgorithm {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
5 changes: 3 additions & 2 deletions src/algorithms/reco/InclusiveKinematicsElectron.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace eicrecon {
const PxPyPzEVector ei(
round_beam_four_momentum(
ei_coll[0].getMomentum(),
m_electron,
m_particleSvc.particle(ei_coll[0].getPDG()).mass,
{-5.0, -10.0, -18.0},
0.0)
);
Expand All @@ -109,7 +109,7 @@ namespace eicrecon {
const PxPyPzEVector pi(
round_beam_four_momentum(
pi_coll[0].getMomentum(),
pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron,
m_particleSvc.particle(pi_coll[0].getPDG()).mass,
{41.0, 100.0, 275.0},
m_crossingAngle)
);
Expand All @@ -128,6 +128,7 @@ namespace eicrecon {
}

// DIS kinematics calculations
const auto m_proton = m_particleSvc.particle(2212).mass;
const auto ef = electrons.front();
const auto q = ei - ef;
const auto q_dot_pi = q.Dot(pi);
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/InclusiveKinematicsElectron.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using InclusiveKinematicsElectronAlgorithm = algorithms::Algorithm<
Expand All @@ -32,7 +34,8 @@ class InclusiveKinematicsElectron : public InclusiveKinematicsElectronAlgorithm
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
5 changes: 3 additions & 2 deletions src/algorithms/reco/InclusiveKinematicsJB.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace eicrecon {
const PxPyPzEVector ei(
round_beam_four_momentum(
ei_coll[0].getMomentum(),
m_electron,
m_particleSvc.particle(ei_coll[0].getPDG()).mass,
{-5.0, -10.0, -18.0},
0.0)
);
Expand All @@ -58,7 +58,7 @@ namespace eicrecon {
const PxPyPzEVector pi(
round_beam_four_momentum(
pi_coll[0].getMomentum(),
pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron,
m_particleSvc.particle(pi_coll[0].getPDG()).mass,
{41.0, 100.0, 275.0},
m_crossingAngle)
);
Expand All @@ -75,6 +75,7 @@ namespace eicrecon {
}

// Calculate kinematic variables
const auto m_proton = m_particleSvc.particle(2212).mass;
const auto y_jb = sigma_h / (2.*ei.energy());
const auto Q2_jb = ptsum*ptsum / (1. - y_jb);
const auto x_jb = Q2_jb / (4.*ei.energy()*pi.energy()*y_jb);
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/InclusiveKinematicsJB.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using InclusiveKinematicsJBAlgorithm = algorithms::Algorithm<
Expand All @@ -32,7 +34,8 @@ class InclusiveKinematicsJB : public InclusiveKinematicsJBAlgorithm {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
5 changes: 3 additions & 2 deletions src/algorithms/reco/InclusiveKinematicsSigma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace eicrecon {
const PxPyPzEVector ei(
round_beam_four_momentum(
ei_coll[0].getMomentum(),
m_electron,
m_particleSvc.particle(ei_coll[0].getPDG()).mass,
{-5.0, -10.0, -18.0},
0.0)
);
Expand All @@ -60,7 +60,7 @@ namespace eicrecon {
const PxPyPzEVector pi(
round_beam_four_momentum(
pi_coll[0].getMomentum(),
pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron,
m_particleSvc.particle(pi_coll[0].getPDG()).mass,
{41.0, 100.0, 275.0},
m_crossingAngle)
);
Expand Down Expand Up @@ -88,6 +88,7 @@ namespace eicrecon {
auto sigma_tot = sigma_e + sigma_h;

// Calculate kinematic variables
const auto m_proton = m_particleSvc.particle(2122).mass;
const auto y_sig = sigma_h / sigma_tot;
const auto Q2_sig = (pt_e*pt_e) / (1. - y_sig);
const auto x_sig = Q2_sig / (4.*ei.energy()*pi.energy()*y_sig);
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/InclusiveKinematicsSigma.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using InclusiveKinematicsSigmaAlgorithm = algorithms::Algorithm<
Expand All @@ -32,7 +34,8 @@ class InclusiveKinematicsSigma : public InclusiveKinematicsSigmaAlgorithm {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
6 changes: 3 additions & 3 deletions src/algorithms/reco/InclusiveKinematicsTruth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace eicrecon {
}
const auto ei_p = ei_coll[0].getMomentum();
const auto ei_p_mag = edm4hep::utils::magnitude(ei_p);
const auto ei_mass = m_electron;
const auto ei_mass = m_particleSvc.particle(11).mass;
const PxPyPzEVector ei(ei_p.x, ei_p.y, ei_p.z, std::hypot(ei_p_mag, ei_mass));

// Get incoming hadron beam
Expand All @@ -61,7 +61,7 @@ namespace eicrecon {
}
const auto pi_p = pi_coll[0].getMomentum();
const auto pi_p_mag = edm4hep::utils::magnitude(pi_p);
const auto pi_mass = pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron;
const auto pi_mass = m_particleSvc.particle(pi_coll[0].getPDG()).mass;
const PxPyPzEVector pi(pi_p.x, pi_p.y, pi_p.z, std::hypot(pi_p_mag, pi_mass));

// Get first scattered electron
Expand All @@ -76,7 +76,7 @@ namespace eicrecon {
}
const auto ef_p = ef_coll[0].getMomentum();
const auto ef_p_mag = edm4hep::utils::magnitude(ef_p);
const auto ef_mass = m_electron;
const auto ef_mass = m_particleSvc.particle(11).mass;
const PxPyPzEVector ef(ef_p.x, ef_p.y, ef_p.z, std::hypot(ef_p_mag, ef_mass));

// DIS kinematics calculations
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/InclusiveKinematicsTruth.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using InclusiveKinematicsTruthAlgorithm =
Expand All @@ -29,7 +31,8 @@ class InclusiveKinematicsTruth : public InclusiveKinematicsTruthAlgorithm {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
5 changes: 3 additions & 2 deletions src/algorithms/reco/InclusiveKinematicseSigma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace eicrecon {
const PxPyPzEVector ei(
round_beam_four_momentum(
ei_coll[0].getMomentum(),
m_electron,
m_particleSvc.particle(ei_coll[0].getPDG()).mass,
{-5.0, -10.0, -18.0},
0.0)
);
Expand All @@ -61,7 +61,7 @@ namespace eicrecon {
const PxPyPzEVector pi(
round_beam_four_momentum(
pi_coll[0].getMomentum(),
pi_coll[0].getPDG() == 2212 ? m_proton : m_neutron,
m_particleSvc.particle(pi_coll[0].getPDG()).mass,
{41.0, 100.0, 275.0},
m_crossingAngle)
);
Expand Down Expand Up @@ -96,6 +96,7 @@ namespace eicrecon {
const auto Q2_sig = (pt_e*pt_e) / (1. - y_sig);
const auto x_sig = Q2_sig / (4.*ei.energy()*pi.energy()*y_sig);

const auto m_proton = m_particleSvc.particle(2212).mass;
const auto Q2_esig = Q2_e;
const auto x_esig = x_sig;
const auto y_esig = Q2_esig / (4.*ei.energy()*pi.energy()*x_esig); //equivalent to (2*ei.energy() / sigma_tot)*y_sig
Expand Down
5 changes: 4 additions & 1 deletion src/algorithms/reco/InclusiveKinematicseSigma.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

using InclusiveKinematicseSigmaAlgorithm = algorithms::Algorithm<
Expand All @@ -32,7 +34,8 @@ class InclusiveKinematicseSigma : public InclusiveKinematicseSigmaAlgorithm {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_crossingAngle{-0.025};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();
double m_crossingAngle{-0.025};
};

} // namespace eicrecon
2 changes: 2 additions & 0 deletions src/algorithms/reco/ScatteredElectronsTruth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ namespace eicrecon {
if (p.getObjectID() == ef_rc_id) {

output_electrons->push_back( p );
static const auto m_electron = m_particleSvc.particle(11).mass;
vScatteredElectron.SetCoordinates( p.getMomentum().x, p.getMomentum().y, p.getMomentum().z, m_electron );
electrons.emplace_back(p.getMomentum().x, p.getMomentum().y, p.getMomentum().z, p.getEnergy());
// break; NOTE: if we are not computing E-Pz
// we can safely break here and save precious CPUs
} else {
// Compute the sum hadronic final state
static const auto m_pion = m_particleSvc.particle(211).mass;
vHadron.SetCoordinates( p.getMomentum().x, p.getMomentum().y, p.getMomentum().z, m_pion );
vHadronicFinalState += vHadron;
}
Expand Down
4 changes: 3 additions & 1 deletion src/algorithms/reco/ScatteredElectronsTruth.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>
#include <string_view>

#include "algorithms/interfaces/ParticleSvc.h"

namespace eicrecon {

Expand Down Expand Up @@ -38,7 +39,8 @@ namespace eicrecon {
void process(const Input&, const Output&) const final;

private:
double m_proton{0.93827}, m_neutron{0.93957}, m_electron{0.000510998928}, m_pion{0.13957};
const algorithms::ParticleSvc& m_particleSvc = algorithms::ParticleSvc::instance();

};

} // namespace eicrecon
Loading

0 comments on commit d8af15f

Please sign in to comment.