Skip to content

Commit

Permalink
perf: Cache particle hypothesis (acts-project#3151)
Browse files Browse the repository at this point in the history
It's not possible to make these compile time constants if we want to share the constants with `ParticleData` but we can make them runtime constants.

It looks like the `findMass` / `findCharge` calls got more expensive after acts-project#2908 but I don't see a reason to optimize them after keeping caching the hypothesis.
  • Loading branch information
andiwand authored and asalzburger committed May 21, 2024
1 parent 83da30d commit 3094312
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions Core/include/Acts/EventData/ParticleHypothesis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,30 @@ class SinglyChargedParticleHypothesis
: GenericParticleHypothesis(other) {}

static SinglyChargedParticleHypothesis muon() {
return SinglyChargedParticleHypothesis(PdgParticle::eMuon);
static const SinglyChargedParticleHypothesis cache(PdgParticle::eMuon);
return cache;
}
static SinglyChargedParticleHypothesis pion() {
return SinglyChargedParticleHypothesis(PdgParticle::ePionPlus);
static const SinglyChargedParticleHypothesis cache(PdgParticle::ePionPlus);
return cache;
}
static SinglyChargedParticleHypothesis electron() {
return SinglyChargedParticleHypothesis(PdgParticle::eElectron);
static const SinglyChargedParticleHypothesis cache(PdgParticle::eElectron);
return cache;
}
static SinglyChargedParticleHypothesis kaon() {
return SinglyChargedParticleHypothesis(PdgParticle::eKaonPlus);
static const SinglyChargedParticleHypothesis cache(PdgParticle::eKaonPlus);
return cache;
}
static SinglyChargedParticleHypothesis proton() {
return SinglyChargedParticleHypothesis(PdgParticle::eProton);
static const SinglyChargedParticleHypothesis cache(PdgParticle::eProton);
return cache;
}

static SinglyChargedParticleHypothesis chargedGeantino() {
return SinglyChargedParticleHypothesis(PdgParticle::eInvalid, 0);
static const SinglyChargedParticleHypothesis cache(PdgParticle::eInvalid,
0);
return cache;
}
};

Expand All @@ -72,14 +79,17 @@ class NeutralParticleHypothesis : public GenericParticleHypothesis<Neutral> {
: GenericParticleHypothesis(other) {}

static NeutralParticleHypothesis photon() {
return NeutralParticleHypothesis(PdgParticle::eGamma);
static const NeutralParticleHypothesis cache(PdgParticle::eGamma);
return cache;
}
static NeutralParticleHypothesis pion0() {
return NeutralParticleHypothesis(PdgParticle::ePionZero);
static const NeutralParticleHypothesis cache(PdgParticle::ePionZero);
return cache;
}

static NeutralParticleHypothesis geantino() {
return NeutralParticleHypothesis(PdgParticle::eInvalid, 0);
static const NeutralParticleHypothesis cache(PdgParticle::eInvalid, 0);
return cache;
}
};

Expand Down Expand Up @@ -122,7 +132,8 @@ class NonNeutralChargedParticleHypothesis
}

static NonNeutralChargedParticleHypothesis chargedGeantino() {
return chargedGeantino(Acts::UnitConstants::e);
static const auto cache = chargedGeantino(Acts::UnitConstants::e);
return cache;
}
static NonNeutralChargedParticleHypothesis chargedGeantino(float absQ) {
return NonNeutralChargedParticleHypothesis(PdgParticle::eInvalid, 0, absQ);
Expand Down Expand Up @@ -175,7 +186,8 @@ class ParticleHypothesis : public GenericParticleHypothesis<AnyCharge> {
return NeutralParticleHypothesis::geantino();
}
static ParticleHypothesis chargedGeantino() {
return chargedGeantino(Acts::UnitConstants::e);
static const auto cache = chargedGeantino(Acts::UnitConstants::e);
return cache;
}
static ParticleHypothesis chargedGeantino(float absQ) {
return ParticleHypothesis(PdgParticle::eInvalid, 0, absQ);
Expand Down

0 comments on commit 3094312

Please sign in to comment.