Skip to content

Commit

Permalink
Fix rare crash in KF (cms-sw#151)
Browse files Browse the repository at this point in the history
* Fix rare crash in KF

* Fixed line break
  • Loading branch information
tomalin committed May 31, 2022
1 parent 05dca1b commit 4ca2bde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 40 deletions.
18 changes: 6 additions & 12 deletions L1Trigger/TrackFindingTMTT/interface/KFbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,18 @@ namespace tmtt {
// Do KF fit
L1fittedTrack fit(const L1track3D &l1track3D) override;

static const unsigned int nEta = 16;
static const unsigned int nGPlayID = 7;
static constexpr unsigned int invalidKFlayer = 7;
static const unsigned int nKFlayer_ = 7;
static const unsigned int nEta_ = 16;
static const unsigned int nGPlayer_ = 7;
static constexpr unsigned int invalidKFlayer_ = nKFlayer_;

// index across is GP encoded layer ID (where barrel layers=1,2,7,5,4,3 & endcap wheels=3,4,5,6,7 & 0 never occurs)
// index down is eta reg
// element.first is kalman layer when stub is from barrel, 7 is invalid
// element.second is kalman layer when stub is from endcap, 7 is invalid

static constexpr std::pair<unsigned, unsigned> layerMap[nEta / 2][nGPlayID + 1] = {
{{7, 7},
{0, 7},
{1, 7},
{5, 7},
{4, 7},
{3, 7},
{7, 7},
{2, 7}}, // B1 B2 B3 B4 B5 B6 -- Ultimate config with "maybe layer"
static constexpr std::pair<unsigned, unsigned> layerMap_[nEta_ / 2][nGPlayer_ + 1] = {
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}}, // B1 B2 B3 B4 B5 B6
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}}, // B1 B2 B3 B4 B5 B6
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}}, // B1 B2 B3 B4 B5 B6
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}}, // B1 B2 B3 B4 B5 B6
Expand Down
31 changes: 8 additions & 23 deletions L1Trigger/TrackFindingTMTT/src/KFbase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace tmtt {
// Get Kalman encoded layer ID for this stub.
int kalmanLay = this->kalmanLayer(etaReg, stub->layerIdReduced(), stub->barrel(), stub->r(), stub->z());

if (kalmanLay != invalidKFlayer) {
if (kalmanLay != invalidKFlayer_) {
if (layerStubs[kalmanLay].size() < settings_->kalmanMaxStubsPerLayer()) {
layerStubs[kalmanLay].push_back(stub);
} else {
Expand Down Expand Up @@ -266,7 +266,7 @@ namespace tmtt {
if (kfDeadLayers.find(layer + 1) != kfDeadLayers.end() && layerStubs[layer + 1].empty()) {
nextlay_stubs = layerStubs[layer + 2];
nSkippedDeadLayers_nextStubs++;
} else if (this->kalmanAmbiguousLayer(etaReg, layer) && layerStubs[layer + 1].empty()) {
} else if (this->kalmanAmbiguousLayer(etaReg, layer + 1) && layerStubs[layer + 1].empty()) {
nextlay_stubs = layerStubs[layer + 2];
nSkippedAmbiguousLayers_nextStubs++;
} else {
Expand Down Expand Up @@ -342,19 +342,6 @@ namespace tmtt {

new_states.insert(new_states.end(), next_states.begin(), next_states.end());
new_states.insert(new_states.end(), next_states_skipped.begin(), next_states_skipped.end());
/*
i = 0;
for (auto state : next_states) {
new_states.push_back(state);
i++;
}
i = 0;
for (auto state : next_states_skipped) {
new_states.push_back(state);
i++;
}
*/
} //end of state loop

// copy new_states into prev_states for next iteration or end if we are on
Expand All @@ -374,7 +361,7 @@ namespace tmtt {
// We're done.
prev_states.clear();
new_states.clear();

break;
} else {
// Continue iterating.
prev_states = new_states;
Expand Down Expand Up @@ -695,9 +682,9 @@ namespace tmtt {

unsigned int KFbase::kalmanLayer(
unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const {
if (nEta != numEtaRegions_)
if (nEta_ != numEtaRegions_)
throw cms::Exception("LogicError")
<< "ERROR KFbase::getKalmanLayer hardwired value of nEta differs from NumEtaRegions cfg param";
<< "ERROR KFbase::getKalmanLayer hardwired value of nEta_ differs from NumEtaRegions cfg param";

unsigned int kfEtaReg; // KF VHDL eta sector def: small in barrel & large in endcap.
if (iEtaReg < numEtaRegions_ / 2) {
Expand All @@ -707,7 +694,7 @@ namespace tmtt {
}

unsigned int kalmanLay =
barrel ? layerMap[kfEtaReg][layerIDreduced].first : layerMap[kfEtaReg][layerIDreduced].second;
barrel ? layerMap_[kfEtaReg][layerIDreduced].first : layerMap_[kfEtaReg][layerIDreduced].second;

// Switch back to the layermap that is consistent with current FW when "maybe layer" is not used
if (not settings_->kfUseMaybeLayers()) {
Expand Down Expand Up @@ -764,9 +751,7 @@ namespace tmtt {
// Only helps in extreme forward sector, and there not significantly.
// UNDERSTAND IF CAN BE USED ELSEWHERE.

const unsigned int nEta = 16;
const unsigned int nKFlayer = 7;
constexpr bool ambiguityMap[nEta / 2][nKFlayer] = {
constexpr bool ambiguityMap[nEta_ / 2][nKFlayer_] = {
{false, false, false, false, false, false, false},
{false, false, false, false, false, false, false},
{false, false, false, false, false, false, false},
Expand All @@ -785,7 +770,7 @@ namespace tmtt {
}

bool ambiguous = false;
if (settings_->kfUseMaybeLayers())
if (settings_->kfUseMaybeLayers() && kfLayer < nKFlayer_)
ambiguous = ambiguityMap[kfEtaReg][kfLayer];

return ambiguous;
Expand Down
10 changes: 5 additions & 5 deletions L1Trigger/TrackTrigger/src/HitPatternHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ namespace hph {
setupTT_(setupTT),
layerIds_(),
layermap_(),
nEtaRegions_(tmtt::KFbase::nEta / 2),
nKalmanLayers_(tmtt::KFbase::invalidKFlayer) {
nEtaRegions_(tmtt::KFbase::nEta_ / 2),
nKalmanLayers_(tmtt::KFbase::nKFlayer_) {
for (const tt::SensorModule& sm : setupTT_.sensorModules()) {
layerIds_.push_back(std::make_pair(sm.layerId(), sm.barrel()));
}
sort(layerIds_.begin(), layerIds_.end(), smallerID);
layerIds_.erase(unique(layerIds_.begin(), layerIds_.end(), equalID), layerIds_.end()); //Keep only unique layerIds
// Converting tmtt::KFbase::layerMap to a format that is acceptatble by HitPatternHelper
// Converting tmtt::KFbase::layerMap_ to a format that is acceptatble by HitPatternHelper
for (int i = 0; i < nEtaRegions_; i++) {
for (int j = 0; j < (int)layerIds_.size(); j++) {
int layer = nKalmanLayers_;
if (layerIds_[j].second) {
layer = tmtt::KFbase::layerMap[i][tmtt::TrackerModule::calcLayerIdReduced(layerIds_[j].first)].first;
layer = tmtt::KFbase::layerMap_[i][tmtt::TrackerModule::calcLayerIdReduced(layerIds_[j].first)].first;
} else {
layer = tmtt::KFbase::layerMap[i][tmtt::TrackerModule::calcLayerIdReduced(layerIds_[j].first)].second;
layer = tmtt::KFbase::layerMap_[i][tmtt::TrackerModule::calcLayerIdReduced(layerIds_[j].first)].second;
}
if (layer < nKalmanLayers_) {
layermap_[i][layer].push_back(layerIds_[j].first);
Expand Down

0 comments on commit 4ca2bde

Please sign in to comment.