Skip to content
Snippets Groups Projects
Verified Commit 5455d842 authored by Stephen Nicholas Swatman's avatar Stephen Nicholas Swatman
Browse files

Deduplicate calorimeter eloss state updater

Previously, this bit of code was duplicated three times across the
code, which is a code smell. @cbittric suggested this change in a code
review for !35949. This commit deduplicates the code, converting all
three instances to a call to a single new method.
parent b1091906
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,8 @@ namespace Trk { ...@@ -51,6 +51,8 @@ namespace Trk {
void setChi2(double); void setChi2(double);
void setMass(double); void setMass(double);
void conditionalSetCalorimeterEnergyLossState(GXFTrackState *);
std::pair<GXFTrackState *, GXFTrackState *> findFirstLastMeasurement(void); std::pair<GXFTrackState *, GXFTrackState *> findFirstLastMeasurement(void);
bool hasKink(void); bool hasKink(void);
......
...@@ -82,16 +82,7 @@ namespace Trk { ...@@ -82,16 +82,7 @@ namespace Trk {
if (rhs.m_caloelossstate != nullptr) { if (rhs.m_caloelossstate != nullptr) {
for (auto & state : m_states) { for (auto & state : m_states) {
GXFMaterialEffects *meff = state->materialEffects(); conditionalSetCalorimeterEnergyLossState(state.get());
const TrackParameters *par = state->trackParameters();
if (
(meff != nullptr) && (par != nullptr) && meff->sigmaDeltaE() > 0 &&
meff->sigmaDeltaPhi() == 0 &&
(par->position().perp() > 1400 || std::abs(par->position().z()) > 3700)
) {
m_caloelossstate = state.get();
}
} }
} }
...@@ -141,14 +132,7 @@ namespace Trk { ...@@ -141,14 +132,7 @@ namespace Trk {
if (rhs.m_caloelossstate != nullptr) { if (rhs.m_caloelossstate != nullptr) {
for (auto & state : m_states) { for (auto & state : m_states) {
GXFMaterialEffects *meff = state->materialEffects(); conditionalSetCalorimeterEnergyLossState(state.get());
const TrackParameters *par = state->trackParameters();
if (
(meff != nullptr) && (par != nullptr) && meff->sigmaDeltaE() > 0 && meff->sigmaDeltaPhi() == 0 &&
(par->position().perp() > 1400 || std::abs(par->position().z()) > 3700)
) {
m_caloelossstate = state.get();
}
} }
} }
m_upstreammat = rhs.m_upstreammat; m_upstreammat = rhs.m_upstreammat;
...@@ -156,6 +140,24 @@ namespace Trk { ...@@ -156,6 +140,24 @@ namespace Trk {
return *this; return *this;
} }
void GXFTrajectory::conditionalSetCalorimeterEnergyLossState(GXFTrackState * state) {
constexpr double perpThreshold = 1400;
constexpr double zThreshold = 3700;
const GXFMaterialEffects *meff = state->materialEffects();
const TrackParameters *par = state->trackParameters();
if (
meff != nullptr &&
par != nullptr &&
meff->sigmaDeltaE() > 0 &&
meff->sigmaDeltaPhi() == 0 &&
(par->position().perp() > perpThreshold || std::abs(par->position().z()) > zThreshold)
) {
m_caloelossstate = state;
}
}
bool GXFTrajectory::addMeasurementState(std::unique_ptr<GXFTrackState> state, int index) { bool GXFTrajectory::addMeasurementState(std::unique_ptr<GXFTrackState> state, int index) {
if (!m_states.empty() && (m_states.back()->measurement() != nullptr)) { if (!m_states.empty() && (m_states.back()->measurement() != nullptr)) {
const MeasurementBase *meas = m_states.back()->measurement(); const MeasurementBase *meas = m_states.back()->measurement();
...@@ -213,7 +215,6 @@ namespace Trk { ...@@ -213,7 +215,6 @@ namespace Trk {
} }
void GXFTrajectory::addMaterialState(std::unique_ptr<GXFTrackState> state, int index) { void GXFTrajectory::addMaterialState(std::unique_ptr<GXFTrackState> state, int index) {
const TrackParameters *par = state->trackParameters();
GXFMaterialEffects *meff = state->materialEffects(); GXFMaterialEffects *meff = state->materialEffects();
if (state->trackStateType() == TrackState::Scatterer) { if (state->trackStateType() == TrackState::Scatterer) {
...@@ -226,13 +227,7 @@ namespace Trk { ...@@ -226,13 +227,7 @@ namespace Trk {
if (meff->sigmaDeltaE() > 0) { if (meff->sigmaDeltaE() > 0) {
m_nbrems++; m_nbrems++;
conditionalSetCalorimeterEnergyLossState(state.get());
if (
(par != nullptr) && meff->sigmaDeltaPhi() == 0 &&
(par->position().perp() > 1400 || std::abs(par->position().z()) > 3700)
) {
m_caloelossstate = state.get();
}
} }
m_toteloss += std::abs(meff->deltaE()); m_toteloss += std::abs(meff->deltaE());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment