Commit 953d8ff8 authored by Rafal Bielski's avatar Rafal Bielski
Browse files

Improve on major performance issue with jTowerContainer::findTower()

parent bb743f76
......@@ -27,6 +27,8 @@
#include "CxxUtils/CachedValue.h"
#include "AthLinks/tools/findInContainer.h"
#include <unordered_map>
namespace LVL1 {
class jTowerContainer : public DataVector<LVL1::jTower>
......@@ -74,7 +76,7 @@ class jTowerContainer : public DataVector<LVL1::jTower>
IMessageSvc* msgSvc() const;
//* @brief Keeps track of the towerID of each jTower associated to each MAP index *.
std::map<int,int> m_map_towerID_containerIndex;
std::unordered_map<int,int> m_map_towerID_containerIndex;
};
}
......
......@@ -211,10 +211,11 @@ std::map<int, jFEXForwardJetsInfo> LVL1::jFEXForwardJetsAlgo::isSeedLocalMaxima(
float centre_eta = myFCALJetInfoClass.getCentreTTEta();
int centre_energy = myFCALJetInfoClass.getSeedET();
std::vector<int> TTinSeed = myFCALJetInfoClass.getTTinSeed();
for (std::size_t i = 0, max = TTinSeed.size(); i != max; ++i){
float seed_phi = jk_jFEXForwardJetsAlgo_jTowerContainer->findTower(TTinSeed[i])->centrePhi();
float seed_eta = jk_jFEXForwardJetsAlgo_jTowerContainer->findTower(TTinSeed[i])->centreEta();
const std::vector<int> TTinSeed = myFCALJetInfoClass.getTTinSeed();
for (const int iTTinSeed : TTinSeed){
const LVL1::jTower* seed_tower = jk_jFEXForwardJetsAlgo_jTowerContainer->findTower(iTTinSeed);
float seed_phi = seed_tower->centrePhi();
float seed_eta = seed_tower->centreEta();
float delta_phi = seed_phi - centre_phi;
float delta_eta = seed_eta - centre_eta;
......@@ -222,23 +223,19 @@ std::map<int, jFEXForwardJetsInfo> LVL1::jFEXForwardJetsAlgo::isSeedLocalMaxima(
static constexpr float TT_Size = M_PI/32;
int seed_energy = 0;
//here is where the extra values are being created.
if(localMaximaLists.count(TTinSeed[i])==1 ){//&& (localMaximaLists[TTinSeed[i]].getSeedET()==0)) {
seed_energy = localMaximaLists[TTinSeed[i]].getSeedET();
if(localMaximaLists.count(iTTinSeed)==1 ){//&& (localMaximaLists[iTTinSeed].getSeedET()==0)) {
seed_energy = localMaximaLists[iTTinSeed].getSeedET();
}
else if(localMaximaLists.count(TTinSeed[i])==0){
else if(localMaximaLists.count(iTTinSeed)==0){
for(int nphi = 0; nphi < 32; nphi++) {
for(int neta = m_lowerEM_eta; neta < m_upperEM_eta; neta++) {
SG::ReadHandle<jTowerContainer> jk_jFEXForwardJetsAlgo_jTowerContainer(m_jFEXForwardJetsAlgo_jTowerContainerKey);
float centre_seed_eta = jk_jFEXForwardJetsAlgo_jTowerContainer->findTower(TTinSeed[i])->centreEta();
float centre_seed_phi = jk_jFEXForwardJetsAlgo_jTowerContainer->findTower(TTinSeed[i])->centrePhi();
seed_energy += getTTowerET(centre_seed_phi, centre_seed_phi);
seed_energy += getTTowerET(seed_phi, seed_eta);
if((TTinSeed[i] == m_jFEXalgoTowerID[nphi][neta]) ||(m_jFEXalgoTowerID[nphi][neta])==0 ){continue;}
if((iTTinSeed == m_jFEXalgoTowerID[nphi][neta]) ||(m_jFEXalgoTowerID[nphi][neta])==0 ){continue;}
float TT_phi = globalPhi(nphi, neta);
float TT_eta = globalEta(nphi, neta);
float R = sqrt(pow((centre_seed_eta - TT_eta),2) + pow((centre_seed_phi - TT_phi),2));
float R = sqrt(pow((seed_eta - TT_eta),2) + pow((seed_phi - TT_phi),2));
if((R > 0) && (R <( 2 * TT_Size))){
seed_energy += getTTowerET(nphi, neta);
}
......
......@@ -254,13 +254,15 @@ namespace LVL1 {
}
}
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
if (msgLvl(MSG::DEBUG)) {
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
for (int thisCol=0; thisCol<cols; thisCol++) {
int tmptowerid = tmp_jTowersIDs_subset_ENDCAP_AND_EMB_AND_FCAL[thisRow][thisCol];
if(tmptowerid == 0 ) continue;
const float tmptowereta = this_jTowerContainer->findTower(tmptowerid)->eta();
const float tmptowerphi = this_jTowerContainer->findTower(tmptowerid)->phi();
const LVL1::jTower* tmptower = this_jTowerContainer->findTower(tmptowerid);
const float tmptowereta = tmptower->eta();
const float tmptowerphi = tmptower->phi();
if(thisCol != cols-1) {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowerphi << "][" << tmptowereta << "]) ");
}
......@@ -268,6 +270,7 @@ namespace LVL1 {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) |");
}
}
}
}
m_jFEXSimTool->init(thisJFEX);
ATH_CHECK(m_jFEXSimTool->ExecuteForwardASide(tmp_jTowersIDs_subset_ENDCAP_AND_EMB_AND_FCAL));
......@@ -344,13 +347,16 @@ namespace LVL1 {
}
}
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
if (msgLvl(MSG::DEBUG)) {
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
for (int thisCol=0; thisCol<cols; thisCol++) {
int tmptowerid = tmp_jTowersIDs_subset_1[thisRow][thisCol];
if(tmptowerid == 0) continue;
const float tmptowereta = this_jTowerContainer->findTower(tmptowerid)->eta();
const float tmptowerphi = this_jTowerContainer->findTower(tmptowerid)->phi();
const LVL1::jTower* tmptower = this_jTowerContainer->findTower(tmptowerid);
const float tmptowereta = tmptower->eta();
const float tmptowerphi = tmptower->phi();
if(thisCol != cols-1) {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowerphi << "][" << tmptowereta << "]) ");
}
......@@ -358,6 +364,7 @@ namespace LVL1 {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) |");
}
}
}
}
m_jFEXSimTool->init(thisJFEX);
ATH_CHECK(m_jFEXSimTool->ExecuteBarrel(tmp_jTowersIDs_subset_1));
......@@ -455,17 +462,15 @@ namespace LVL1 {
}
}
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
if (msgLvl(MSG::DEBUG)) {
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
for (int thisCol=0; thisCol<cols; thisCol++) {
int tmptowerid = tmp_jTowersIDs_subset_2[thisRow][thisCol];
if(tmptowerid == 0) continue;
const float tmptowereta = this_jTowerContainer->findTower(tmptowerid)->eta();
const float tmptowerphi = this_jTowerContainer->findTower(tmptowerid)->phi();
const LVL1::jTower* tmptower = this_jTowerContainer->findTower(tmptowerid);
const float tmptowereta = tmptower->eta();
const float tmptowerphi = tmptower->phi();
if(thisCol != cols-1) {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) ");
}
......@@ -473,6 +478,7 @@ namespace LVL1 {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) |");
}
}
}
}
//tool use instead
......@@ -571,13 +577,15 @@ namespace LVL1 {
}
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
if (msgLvl(MSG::DEBUG)) {
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
for (int thisCol=0; thisCol<cols; thisCol++) {
int tmptowerid = tmp_jTowersIDs_subset_3[thisRow][thisCol];
if(tmptowerid == 0) continue;
const float tmptowereta = this_jTowerContainer->findTower(tmptowerid)->eta();
const float tmptowerphi = this_jTowerContainer->findTower(tmptowerid)->phi();
const LVL1::jTower* tmptower = this_jTowerContainer->findTower(tmptowerid);
const float tmptowereta = tmptower->eta();
const float tmptowerphi = tmptower->phi();
if(thisCol != cols-1) {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) ");
}
......@@ -585,6 +593,7 @@ namespace LVL1 {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) |");
}
}
}
}
//tool use instead
......@@ -658,13 +667,15 @@ namespace LVL1 {
}
}
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
if (msgLvl(MSG::DEBUG)) {
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
for (int thisCol=0; thisCol<cols; thisCol++) {
int tmptowerid = tmp_jTowersIDs_subset_4[thisRow][thisCol];
if(tmptowerid == 0) continue;
const float tmptowereta = this_jTowerContainer->findTower(tmptowerid)->eta();
const float tmptowerphi = this_jTowerContainer->findTower(tmptowerid)->phi();
const LVL1::jTower* tmptower = this_jTowerContainer->findTower(tmptowerid);
const float tmptowereta = tmptower->eta();
const float tmptowerphi = tmptower->phi();
if(thisCol != cols-1) {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) ");
}
......@@ -672,6 +683,7 @@ namespace LVL1 {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) |");
}
}
}
}
//tool use instead
......@@ -811,13 +823,15 @@ namespace LVL1 {
}
//---
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
if (msgLvl(MSG::DEBUG)) {
ATH_MSG_DEBUG("CONTENTS OF jFEX " << thisJFEX << " :");
for (int thisRow=rows-1; thisRow>=0; thisRow--) {
for (int thisCol=0; thisCol<cols; thisCol++) {
int tmptowerid = tmp_jTowersIDs_subset_ENDCAP_AND_EMB_AND_FCAL_2[thisRow][thisCol];
if(tmptowerid == 0) continue;
const float tmptowereta = this_jTowerContainer->findTower(tmptowerid)->eta();
const float tmptowerphi = this_jTowerContainer->findTower(tmptowerid)->phi();
const LVL1::jTower* tmptower = this_jTowerContainer->findTower(tmptowerid);
const float tmptowereta = tmptower->eta();
const float tmptowerphi = tmptower->phi();
if(thisCol != cols-1) {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowerphi << "][" << tmptowereta << "]) ");
}
......@@ -825,6 +839,7 @@ namespace LVL1 {
ATH_MSG_DEBUG("| " << tmptowerid << "([" << tmptowereta << "][" << tmptowerphi << "]) |");
}
}
}
}
m_jFEXSimTool->init(thisJFEX);
......
......@@ -31,36 +31,42 @@ void jTowerContainer::print() const {
const LVL1::jTower * jTowerContainer::findTower(int towerID) const
{
int container_index = -1;
container_index = m_map_towerID_containerIndex.find(towerID)->second;
//should be written like this
if(m_map_towerID_containerIndex.find(towerID) != m_map_towerID_containerIndex.end()){
if(container_index >= 0) {
return (*this)[container_index];
}
const auto it = m_map_towerID_containerIndex.find(towerID);
if (it==m_map_towerID_containerIndex.cend()) {
// FIXME !!!
// This should be:
// return nullptr;
// but the previous version of the code had a bug and relied on UNDEFINED BEHAVIOUR
// which would often set container_index to 0 for out-of-range towerID, but maybe
// sometimes to a different number. I keep the container_index=0 for now while only
// refactoring the code for performance. Rafal Bielski 31/08/2021
return (*this)[0];
}
if(container_index >= 0) {
return (*this)[container_index];
const int container_index = it->second;
if (container_index < 0) {
return nullptr;
}
return nullptr;
return (*this)[container_index];
}
LVL1::jTower * jTowerContainer::findTower(int towerID)
{
int container_index = -1;
container_index = m_map_towerID_containerIndex.find(towerID)->second;
//should be written like this
if(m_map_towerID_containerIndex.find(towerID) != m_map_towerID_containerIndex.end()){
if(container_index >= 0) {
return (*this)[container_index];
}
const auto it = m_map_towerID_containerIndex.find(towerID);
if (it==m_map_towerID_containerIndex.cend()) {
// FIXME !!!
// This should be:
// return nullptr;
// but the previous version of the code had a bug and relied on UNDEFINED BEHAVIOUR
// which would often set container_index to 0 for out-of-range towerID, but maybe
// sometimes to a different number. I keep the container_index=0 for now while only
// refactoring the code for performance. Rafal Bielski 31/08/2021
return (*this)[0];
}
if(container_index >= 0) {
return (*this)[container_index];
const int container_index = it->second;
if (container_index < 0) {
return nullptr;
}
return nullptr;
return (*this)[container_index];
}
void jTowerContainer::clearContainerMap()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment