Skip to content

Commit

Permalink
feat: Add kaon hypothesis to ParticleHypothesis (#2990)
Browse files Browse the repository at this point in the history
This adds the kaon hypothesis such that there's no need to define it by hand.

Currently:
```
kaon = acts.ParticleHypothesis(321, 0.493677, 1)
```

```
>>> import acts
>>> kaon = acts.ParticleHypothesis(321, 0.493677, 1)
>>> kaon.absolutePdg()
<PdgParticle.???: 321>
>>> 
```
  • Loading branch information
plariono authored Feb 29, 2024
1 parent 9854009 commit 6c910b0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Core/include/Acts/Definitions/PdgParticle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ enum PdgParticle : std::int32_t {
ePionZero = 111,
ePionPlus = 211,
ePionMinus = -ePionPlus,
eKaonPlus = 321,
eKaonMinus = -eKaonPlus,
eNeutron = 2112,
eAntiNeutron = -eNeutron,
eProton = 2212,
Expand Down
9 changes: 9 additions & 0 deletions Core/include/Acts/EventData/ParticleHypothesis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class SinglyChargedParticleHypothesis
static SinglyChargedParticleHypothesis electron() {
return SinglyChargedParticleHypothesis(PdgParticle::eElectron);
}
static SinglyChargedParticleHypothesis kaon() {
return SinglyChargedParticleHypothesis(PdgParticle::eKaonPlus);
}
static SinglyChargedParticleHypothesis proton() {
return SinglyChargedParticleHypothesis(PdgParticle::eProton);
}
Expand Down Expand Up @@ -106,6 +109,9 @@ class NonNeutralChargedParticleHypothesis
static NonNeutralChargedParticleHypothesis electron() {
return SinglyChargedParticleHypothesis::electron();
}
static NonNeutralChargedParticleHypothesis kaon() {
return SinglyChargedParticleHypothesis::kaon();
}
static NonNeutralChargedParticleHypothesis proton() {
return SinglyChargedParticleHypothesis::proton();
}
Expand Down Expand Up @@ -147,6 +153,9 @@ class ParticleHypothesis : public GenericParticleHypothesis<AnyCharge> {
static ParticleHypothesis electron() {
return SinglyChargedParticleHypothesis::electron();
}
static ParticleHypothesis kaon() {
return SinglyChargedParticleHypothesis::kaon();
}
static ParticleHypothesis proton() {
return SinglyChargedParticleHypothesis::proton();
}
Expand Down
3 changes: 3 additions & 0 deletions Core/src/Definitions/ParticleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ std::optional<std::string_view> Acts::pdgToShortAbsString(PdgParticle pdg) {
if (pdg == ePionPlus) {
return "pi";
}
if (pdg == eKaonPlus) {
return "K";
}
if (pdg == eNeutron) {
return "n";
}
Expand Down
2 changes: 2 additions & 0 deletions Examples/Python/src/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ void addPdgParticle(Acts::Python::Context& ctx) {
.value("ePionZero", Acts::PdgParticle::ePionZero)
.value("ePionPlus", Acts::PdgParticle::ePionPlus)
.value("ePionMinus", Acts::PdgParticle::ePionMinus)
.value("eKaonPlus", Acts::PdgParticle::eKaonPlus)
.value("eKaonMinus", Acts::PdgParticle::eKaonMinus)
.value("eNeutron", Acts::PdgParticle::eNeutron)
.value("eAntiNeutron", Acts::PdgParticle::eAntiNeutron)
.value("eProton", Acts::PdgParticle::eProton)
Expand Down
4 changes: 4 additions & 0 deletions Examples/Python/src/EventData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ void addEventData(Context& ctx) {
[](py::object /* self */) {
return Acts::ParticleHypothesis::electron();
})
.def_property_readonly_static("kaon",
[](py::object /* self */) {
return Acts::ParticleHypothesis::kaon();
})
.def_property_readonly_static("proton",
[](py::object /* self */) {
return Acts::ParticleHypothesis::proton();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_logging():


def test_pgd_particle():
assert len(acts.PdgParticle.__members__) == 17
assert len(acts.PdgParticle.__members__) == 19


def test_algebra():
Expand Down
5 changes: 3 additions & 2 deletions Examples/Python/tests/test_event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ def test_particle_hypothesis():
pion = acts.ParticleHypothesis.pion
electron = acts.ParticleHypothesis.electron
proton = acts.ParticleHypothesis.proton
kaon = acts.ParticleHypothesis.kaon
geantino = acts.ParticleHypothesis.geantino
chargedGeantino = acts.ParticleHypothesis.chargedGeantino

# create new particle hypothesis
kaon = acts.ParticleHypothesis(321, 0.493677, 1)

# check pdg
assert muon.absolutePdg() == acts.PdgParticle.eMuon
assert pion.absolutePdg() == acts.PdgParticle.ePionPlus
assert electron.absolutePdg() == acts.PdgParticle.eElectron
assert kaon.absolutePdg() == acts.PdgParticle.eKaonPlus
assert proton.absolutePdg() == acts.PdgParticle.eProton
assert geantino.absolutePdg() == acts.PdgParticle.eInvalid
assert chargedGeantino.absolutePdg() == acts.PdgParticle.eInvalid
assert kaon.absolutePdg() == 321

# check mass
assert electron.mass() != 0
Expand All @@ -45,6 +45,7 @@ def test_particle_hypothesis():
assert (
str(electron) == "ParticleHypothesis{absPdg=e, mass=0.000510999, absCharge=1}"
)
assert str(kaon) == "ParticleHypothesis{absPdg=K, mass=0.493677, absCharge=1}"
assert str(proton) == "ParticleHypothesis{absPdg=p, mass=0.938272, absCharge=1}"
assert str(geantino) == "ParticleHypothesis{absPdg=0, mass=0, absCharge=0}"
assert str(chargedGeantino) == "ParticleHypothesis{absPdg=0, mass=0, absCharge=1}"

0 comments on commit 6c910b0

Please sign in to comment.