30 std::size_t getRemappedIndex(
const std::map<std::size_t, std::size_t> &
remap, std::size_t originalIdx)
32 auto itr =
remap.find(originalIdx);
33 return itr ==
remap.end() ? SIZE_MAX : itr->second;
55 return StatusCode::SUCCESS;
61 if (!inputTowers.isValid())
64 return StatusCode::FAILURE;
67 auto outputTowers = std::make_unique<xAOD::JGTowerContainer>();
68 auto outputTowersAux = std::make_unique<xAOD::JGTowerAuxContainer>();
69 outputTowers->setStore(outputTowersAux.get());
76 return StatusCode::FAILURE;
78 const std::vector<JGTowerHelper> &helpers = **
mapping;
80 std::map<std::size_t, std::size_t> indexRemap;
85 if (!
helper.isFrontTower())
98 indexRemap[tower->index()] = outputTowers->size();
99 std::vector<int> SCIndex = tower->SCIndex();
100 std::vector<int> tileIndex = tower->TileIndex();
101 float totalEt = tower->et();
102 std::size_t nextTowerIdx = accIndexBehind(*tower);
103 float area = accArea(*tower);
104 float eta = tower->eta();
105 std::size_t nextEtaIndex = accNextEtaIndex(*tower);
106 std::size_t previousEtaIndex = accPreviousEtaIndex(*tower);
107 std::vector<std::size_t> mergedIndices{tower->index()};
108 while (nextTowerIdx != SIZE_MAX)
110 const xAOD::JGTower *nextTower = inputTowers->at(nextTowerIdx);
111 totalEt += nextTower->
et();
112 SCIndex.insert(SCIndex.end(), nextTower->
SCIndex().begin(), nextTower->
SCIndex().end());
113 tileIndex.insert(tileIndex.end(), nextTower->
TileIndex().begin(), nextTower->
TileIndex().end());
114 mergedIndices.push_back(nextTowerIdx);
115 nextTowerIdx = helpers.at(nextTower->
Id()).indexBehind();
122 if (tower->eta() > 0)
124 nextTowerIdx = nextEtaIndex;
125 const xAOD::JGTower *nextTower = inputTowers->at(nextTowerIdx);
127 nextEtaIndex = accNextEtaIndex(*nextTower);
131 nextTowerIdx = previousEtaIndex;
132 const xAOD::JGTower *nextTower = inputTowers->at(nextTowerIdx);
134 previousEtaIndex = accPreviousEtaIndex(*nextTower);
136 indexRemap[nextTowerIdx] = outputTowers->size();
137 while (nextTowerIdx != SIZE_MAX)
139 const xAOD::JGTower *nextTower = inputTowers->at(nextTowerIdx);
140 if (helpers.at(nextTowerIdx).isFrontTower())
142 area += accArea(*nextTower);
143 eta += std::copysign(nextTower->
deta() / 2, eta);
145 totalEt += nextTower->
et();
146 SCIndex.insert(SCIndex.end(), nextTower->
SCIndex().begin(), nextTower->
SCIndex().end());
147 tileIndex.insert(tileIndex.end(), nextTower->
TileIndex().begin(), nextTower->
TileIndex().end());
148 mergedIndices.push_back(nextTowerIdx);
149 nextTowerIdx = helpers.at(nextTower->
Id()).indexBehind();
155 outputTowers->push_back(newTower);
158 decArea(*newTower) =
area;
160 newTower->
setEt(totalEt);
167 decIndexInFront(*newTower) = SIZE_MAX;
168 decIndexBehind(*newTower) = SIZE_MAX;
169 decNextEtaIndex(*newTower) = nextEtaIndex;
170 decPreviousEtaIndex(*newTower) = previousEtaIndex;
171 decMergedIndices(*newTower) = mergedIndices;
177 decNextEtaIndex(*tower) = getRemappedIndex(indexRemap, accNextEtaIndex(*tower));
178 decPreviousEtaIndex(*tower) = getRemappedIndex(indexRemap, accPreviousEtaIndex(*tower));
179 decNextPhiIndex(*tower) = getRemappedIndex(indexRemap, accNextPhiIndex(*tower));
180 decPreviousPhiIndex(*tower) = getRemappedIndex(indexRemap, accPreviousPhiIndex(*tower));
184 ATH_CHECK(outputHandle.record(std::move(outputTowers), std::move(outputTowersAux)));
185 return StatusCode::SUCCESS;