35 {
36 SG::WriteCondHandle<JGTowerMappingData> outputHandle(
m_outputKey, ctx);
37 if (outputHandle.isValid())
38 {
39
40
41 return StatusCode::SUCCESS;
42 }
45 const CaloSuperCellDetDescrManager *scDetMgr = *caloSuperCellMgrHandle;
46
47 auto data = std::make_unique<JGTowerMappingData>();
48
49
50
51 std::map<std::tuple<int, int, int, int>, std::vector<std::size_t>> towerGrid;
52
53 std::map<int, std::tuple<int, int, int>> regionParams;
54
55 for (std::size_t towerIdx = 0; towerIdx < jgTowerID->
tower_hash_max(); ++towerIdx)
56 {
57 Identifier towerID = jgTowerID->
tower_id(towerIdx);
58 Identifier regionID = jgTowerID->
region_id(towerID);
59
60 int detSide = jgTowerID->
pos_neg(towerID) < 0 ? -1 : +1;
61
62
65 int nTowers = (
int)std::ceil(TMath::Pi() / jDPhi);
66 jDPhi = TMath::Pi() / nTowers;
67
68 float jEta = detSide * ((jgTowerID->
eta(towerID) + 0.5) * jDEta + jgTowerID->
eta0(regionID));
69 float jPhi = TVector2::Phi_mpi_pi((jgTowerID->
phi(towerID) + 0.5) * jDPhi + jgTowerID->
phi0(regionID));
70
71 data->emplace_back(jEta, jDEta, jPhi, jDPhi);
74
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(
84
85
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(); }),
89 towerIdx);
90
91 for (std::size_t scIdx = 0; scIdx <
m_scid->calo_cell_hash_max(); ++scIdx)
92 {
93 Identifier scID =
m_scid->cell_id(scIdx);
94 const CaloDetDescrElement *dde = scDetMgr->
get_element(scID);
95 if (!dde)
96 {
98 return StatusCode::FAILURE;
99 }
100 if (
m_scid->is_tile(scID) &&
m_scid->sampling(scID) != 2)
101 {
103 continue;
105 helper.SetTileIndices(scIdx);
106 }
107 else
108 {
109 float superCellEta = dde->
eta_raw();
110
111 if (std::abs(superCellEta) > 3.2)
112 continue;
113
114
115 if (std::abs(std::abs(superCellEta) - 1.4) < 0.001 &&
116 m_scid->region(scID) == 0 &&
117 m_scid->sampling(scID) == 2)
118 superCellEta += (superCellEta > 0 ? 0.05 : -0.05);
123 helper.SetSCIndices(scIdx);
124 }
125 }
126 }
127
128 for (auto &gridLocPair : towerGrid)
129 {
130 std::vector<std::size_t> &towerIndices = gridLocPair.second;
131
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();
143
144
145
146 if (iEta == etaMax)
147 {
148
149 auto itr = regionParams.find(region + 1);
150 if (itr != regionParams.end() && std::get<0>(itr->second) == phiMax)
151
152 (pos_neg > 0 ? nextEtaItr : prevEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region + 1, std::get<1>(itr->second), iPhi));
153 }
154 else
155 (pos_neg > 0 ? nextEtaItr : prevEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region, iEta + 1, iPhi));
156 if (iEta == etaMin)
157 {
158 if (region == 0)
159 (pos_neg > 0 ? prevEtaItr : nextEtaItr) = towerGrid.find(std::make_tuple(pos_neg * -1, region, iEta, iPhi));
160 else
161 {
162 auto itr = regionParams.find(region - 1);
163 if (itr != regionParams.end() && std::get<0>(itr->second) == phiMax)
164
165 (pos_neg > 0 ? prevEtaItr : nextEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region - 1, std::get<2>(itr->second), iPhi));
166 }
167 }
168 else
169 (pos_neg > 0 ? prevEtaItr : nextEtaItr) = towerGrid.find(std::make_tuple(pos_neg, region, iEta - 1, iPhi));
170
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);
187
188 std::size_t previousIdx = SIZE_MAX;
189 for (std::size_t iIdx = 0; iIdx < towerIndices.size(); ++iIdx)
190 {
191
192
193 std::size_t currentIdx = towerIndices.at(iIdx);
195
196 helper.setNextEtaIndex(nextEtaTowers.at(iIdx));
197 helper.setPreviousEtaIndex(prevEtaTowers.at(iIdx));
198 helper.setNextPhiIndex(nextPhiTowers.at(iIdx));
199 helper.setPreviousPhiIndex(prevPhiTowers.at(iIdx));
200
201 helper.setIndexInFront(previousIdx);
202 if (previousIdx != SIZE_MAX)
203 data->at(previousIdx).setIndexBehind(currentIdx);
204 previousIdx = currentIdx;
205 }
206 }
207
210
211
214
215 return StatusCode::SUCCESS;
216 }
#define ATH_CHECK
Evaluate an expression and check for errors.
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
int sampling(const Identifier id) const
return sampling according to :
float eta0(const Identifier regId) const
Return the minimum eta of region, or NOT_VALID.
int eta_max(const Identifier regId) const
max value of eta index (-999 == failure)
int region(const Identifier id) const
return region according to :
size_type tower_hash_max() const
tower hash table max size
int eta_min(const Identifier regId) const
min value of eta index (-999 == failure)
int pos_neg(const Identifier id) const
Test wether given tower or layer is part of the Tile Calorimeter.
float phiGranularity(const Identifier regId) const
Return the phi granularity of a region, or NOT_VALID.
int phi_max(const Identifier regId) const
min value of phi index (-999 == failure)
int phi(const Identifier id) const
return phi according to :
Identifier tower_id(int pos_neg, int sampling, int region, int eta, int phi) const
build a tower identifier
Identifier region_id(int pos_neg, int sampling, int region) const
build a region (of towers) identifier
float etaGranularity(const Identifier regId) const
Return the eta granularity of a region, or NOT_VALID.
float phi0(const Identifier regId) const
Return the minimum phi of region, or NOT_VALID.
int eta(const Identifier id) const
return eta according to :
virtual StatusCode buildForwardMapping(JGTowerMappingData &data, const CaloSuperCellDetDescrManager *mgr) const =0
SG::ReadCondHandleKey< CaloSuperCellDetDescrManager > m_caloSuperCellMgrKey
virtual const JGTowerBase_ID * getJGTowerID() const =0
SG::WriteCondHandleKey< JGTowerMappingData > m_outputKey
Gaudi::Property< bool > m_mapTileCells
virtual StatusCode loadTowerAreas(JGTowerMappingData &data) const =0
setScale setgFexType iEta