8 #include "CaloDetDescr/CaloDetDescrElement.h"
31 return StatusCode::SUCCESS;
41 return StatusCode::SUCCESS;
47 auto data = std::make_unique<JGTowerMappingData>();
51 std::map<std::tuple<int, int, int, int>, std::vector<std::size_t>> towerGrid;
53 std::map<int, std::tuple<int, int, int>> regionParams;
55 for (std::size_t towerIdx = 0; towerIdx < jgTowerID->
tower_hash_max(); ++towerIdx)
60 int detSide = jgTowerID->
pos_neg(towerID) < 0 ? -1 : +1;
65 int nTowers = (
int)std::ceil(TMath::Pi() / jDPhi);
66 jDPhi = TMath::Pi() / nTowers;
68 float jEta = detSide * ((jgTowerID->
eta(towerID) + 0.5) * jDEta + jgTowerID->
eta0(regionID));
71 data->emplace_back(jEta, jDEta, jPhi, jDPhi);
75 std::vector<std::size_t> &gridLoc = towerGrid[std::make_tuple(
77 jgTowerID->
region(towerID),
78 jgTowerID->
eta(towerID),
79 jgTowerID->
phi(towerID))];
80 regionParams[jgTowerID->
region(towerID)] = std::make_tuple(
86 gridLoc.insert(std::lower_bound(
87 gridLoc.begin(), gridLoc.end(), towerIdx,
88 [&
data](std::size_t lhs, std::size_t rhs) { return data->at(lhs).sampling() < data->at(rhs).sampling(); }),
98 return StatusCode::FAILURE;
105 helper.SetTileIndices(scIdx);
109 float superCellEta = dde->
eta_raw();
111 if (std::abs(superCellEta) > 3.2)
115 if (std::abs(std::abs(superCellEta) - 1.4) < 0.001 &&
118 superCellEta += (superCellEta > 0 ? 0.05 : -0.05);
123 helper.SetSCIndices(scIdx);
128 for (
auto &gridLocPair : towerGrid)
130 std::vector<std::size_t> &towerIndices = gridLocPair.second;
132 int pos_neg = std::get<0>(gridLocPair.first);
133 int region = std::get<1>(gridLocPair.first);
134 int iEta = std::get<2>(gridLocPair.first);
135 int iPhi = std::get<3>(gridLocPair.first);
136 int phiMax = std::get<0>(regionParams[region]);
137 int etaMin = std::get<1>(regionParams[region]);
138 int etaMax = std::get<2>(regionParams[region]);
139 auto nextPhiItr = towerGrid.find(std::make_tuple(pos_neg, region,
iEta,
iPhi == phiMax ? 0 :
iPhi + 1));
140 auto prevPhiItr = towerGrid.find(std::make_tuple(pos_neg, region,
iEta,
iPhi == 0 ? phiMax :
iPhi - 1));
141 auto nextEtaItr = towerGrid.end();
142 auto prevEtaItr = towerGrid.end();
149 auto itr = regionParams.find(region + 1);
150 if (itr != regionParams.end() && std::get<0>(itr->second) == phiMax)
152 (pos_neg > 0 ? nextEtaItr : prevEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region + 1, std::get<1>(itr->second),
iPhi));
155 (pos_neg > 0 ? nextEtaItr : prevEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region,
iEta + 1,
iPhi));
159 (pos_neg > 0 ? prevEtaItr : nextEtaItr) = towerGrid.find(std::make_tuple(pos_neg * -1, region,
iEta,
iPhi));
162 auto itr = regionParams.find(region - 1);
163 if (itr != regionParams.end() && std::get<0>(itr->second) == phiMax)
165 (pos_neg > 0 ? prevEtaItr : nextEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region - 1, std::get<2>(itr->second),
iPhi));
169 (pos_neg > 0 ? prevEtaItr : nextEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region,
iEta - 1,
iPhi));
171 std::vector<std::size_t> nextEtaTowers;
172 std::vector<std::size_t> prevEtaTowers;
173 std::vector<std::size_t> nextPhiTowers;
174 std::vector<std::size_t> prevPhiTowers;
175 if (nextEtaItr != towerGrid.end())
176 nextEtaTowers = nextEtaItr->second;
177 if (prevEtaItr != towerGrid.end())
178 prevEtaTowers = prevEtaItr->second;
179 if (nextPhiItr != towerGrid.end())
180 nextPhiTowers = nextPhiItr->second;
181 if (prevPhiItr != towerGrid.end())
182 prevPhiTowers = prevPhiItr->second;
183 nextEtaTowers.resize(towerIndices.size(), SIZE_MAX);
184 prevEtaTowers.resize(towerIndices.size(), SIZE_MAX);
185 nextPhiTowers.resize(towerIndices.size(), SIZE_MAX);
186 prevPhiTowers.resize(towerIndices.size(), SIZE_MAX);
188 std::size_t previousIdx = SIZE_MAX;
189 for (std::size_t iIdx = 0; iIdx < towerIndices.size(); ++iIdx)
193 std::size_t currentIdx = towerIndices.at(iIdx);
196 helper.setNextEtaIndex(nextEtaTowers.at(iIdx));
197 helper.setPreviousEtaIndex(prevEtaTowers.at(iIdx));
198 helper.setNextPhiIndex(nextPhiTowers.at(iIdx));
199 helper.setPreviousPhiIndex(prevPhiTowers.at(iIdx));
201 helper.setIndexInFront(previousIdx);
202 if (previousIdx != SIZE_MAX)
203 data->at(previousIdx).setIndexBehind(currentIdx);
204 previousIdx = currentIdx;
215 return StatusCode::SUCCESS;