15 #include "GaudiKernel/SystemOfUnits.h"
23 std::vector<std::size_t> createVectorFromRanges(
const std::vector<std::pair<std::size_t, std::size_t>> &
ranges)
26 std::size_t total = 0;
27 for (
const std::pair<std::size_t, std::size_t> &
range :
ranges)
29 std::vector<std::size_t>
result(total);
30 auto startItr =
result.begin();
31 auto endItr =
result.begin();
32 for (
const std::pair<std::size_t, std::size_t> &
range :
ranges)
35 endItr = startItr + (
range.second -
range.first);
36 std::iota(startItr, endItr,
range.first);
41 std::vector<std::size_t> findBinNumbers(
43 const std::vector<std::pair<float, float>> &
etaBins,
44 const std::vector<std::pair<float, float>> &phiBins,
47 std::vector<std::size_t> binNumbers;
49 phi = TVector2::Phi_0_2pi(
phi - phiOffset);
52 for (
const std::pair<float, float> &
phiBin : phiBins)
57 binNumbers.push_back(iBin);
86 return StatusCode::SUCCESS;
96 std::vector<std::pair<float, float>>
etaBins{
103 std::vector<std::pair<float, float>> etaBinsCore{
111 std::vector<std::pair<float, float>> phiBins{
112 {0.0, TMath::Pi()}, {TMath::Pi(), 2 * TMath::Pi()}};
113 float phiOffset = 0.25 * TMath::Pi();
117 std::vector<std::size_t> EMTowers = createVectorFromRanges(
118 {{1, 1696}, {3392, 5088}, {6784, 6816}, {6848, 6880}, {6912, 6976}});
119 std::vector<std::size_t> hadTowers = createVectorFromRanges(
120 {{1696, 3392}, {5088, 6784}, {6816, 6848}, {6880, 6912}});
121 std::vector<std::size_t> FCALTowers = createVectorFromRanges({{6976, 7744}});
124 std::vector<std::size_t> had1Towers;
125 std::vector<std::size_t> had2Towers;
126 std::vector<std::size_t> had3Towers;
127 for (std::size_t
idx : hadTowers)
129 float eta = std::abs(
towers->at(
idx)->eta());
131 had1Towers.push_back(
idx);
133 had2Towers.push_back(
idx);
135 had3Towers.push_back(
idx);
139 std::vector<std::vector<std::size_t>> regions;
141 regions.push_back(std::move(had1Towers));
142 regions.push_back(std::move(had2Towers));
143 regions.push_back(std::move(had3Towers));
144 regions.push_back(std::move(EMTowers));
145 regions.push_back(std::move(FCALTowers));
147 bins.m_bins.resize(regions.size() *
nBins);
148 bins.m_binsCore.resize(regions.size() *
nBins);
150 for (std::size_t regionIdx = 0; regionIdx < regions.size(); ++regionIdx)
152 for (std::size_t towerIdx : regions.at(regionIdx))
155 for (std::size_t binIdx : findBinNumbers(tower.
eta(), tower.
phi(),
etaBins, phiBins, phiOffset))
156 bins.m_bins.at(binIdx + regionIdx *
nBins).push_back(towerIdx);
157 for (std::size_t binIdx : findBinNumbers(tower.
eta(), tower.
phi(), etaBinsCore, phiBins, phiOffset))
158 bins.m_binsCore.at(binIdx + regionIdx *
nBins).push_back(towerIdx);
163 for (std::size_t binIdx = 0; binIdx <
bins.m_bins.size(); ++binIdx)
164 if (
bins.m_binsCore.at(binIdx).size() == 0)
165 bins.m_bins.at(binIdx).clear();
173 if (!inputTowers.isValid())
176 return StatusCode::FAILURE;
179 std::unique_ptr<xAOD::JGTowerContainer> outputTowers(shallowCopy.first);
180 std::unique_ptr<xAOD::ShallowAuxContainer> outputTowersAux(shallowCopy.second);
186 std::vector<float> rhos;
187 rhos.reserve(jFEXBins.
m_bins.size());
188 for (
const std::vector<std::size_t> &binTowerIndices : jFEXBins.
m_bins)
190 std::size_t
count = 0;
192 for (std::size_t towerIdx : binTowerIndices)
195 float area = accArea(*tower);
196 float towerRho = tower->
et() /
area;
206 rhos.push_back(rhoSum /
count);
209 std::vector<float> subtractedTowerEnergies(inputTowers->size(), 0.0);
210 for (std::size_t binIdx = 0; binIdx < jFEXBins.
m_binsCore.size(); ++binIdx)
212 for (std::size_t towerIdx : jFEXBins.
m_binsCore.at(binIdx))
215 float area = accArea(*tower);
216 float etSub = tower->
et() - rhos.at(binIdx) *
area;
219 subtractedTowerEnergies.at(towerIdx) = etSub;
222 for (std::size_t
idx = 0;
idx < subtractedTowerEnergies.size(); ++
idx)
223 outputTowers->
at(
idx)->setEt(subtractedTowerEnergies.at(
idx));
227 ATH_CHECK(outputHandle.record(std::move(outputTowers), std::move(outputTowersAux)));
230 auto rhoCont = std::make_unique<xAOD::EnergySumRoI>();
231 auto rhoContAux = std::make_unique<xAOD::EnergySumRoIAuxInfo>();
232 rhoCont->setStore(rhoContAux.get());
233 decRhos(*rhoCont) = rhos;
235 ATH_CHECK(outputRhoHandle.record(std::move(rhoCont), std::move(rhoContAux)));
236 return StatusCode::SUCCESS;