10 #include "UCTSummaryCard.hh"
11 #include "UCTObject.hh"
12 #include "UCTLayer1.hh"
13 #include "UCTCrate.hh"
15 #include "UCTRegion.hh"
16 #include "UCTGeometry.hh"
17 #include "UCTLogging.hh"
20 using namespace l1tcalo;
25 double tauIsolationFactorIn,
26 uint32_t eGammaSeedIn,
27 double eGammaIsolationFactorIn)
37 for (
int iPhi = 1; iPhi <= 72; iPhi++) {
43 UCTSummaryCard::~UCTSummaryCard() {
44 for (uint32_t
i = 0;
i <
regions.size();
i++) {
59 int etaMin = -NRegionsInCard;
60 int etaMax = NRegionsInCard;
66 for (uint32_t iPhi = 0; iPhi < MaxUCTRegionsPhi; iPhi++) {
67 const UCTRegion* uctRegion = getRegion(
iEta, iPhi);
68 uint32_t
et = uctRegion->et();
73 uint32_t totalRegionCount = 2 *
etaMax * MaxUCTRegionsPhi;
74 uint32_t pumBinSize = totalRegionCount / pumLUT->size();
75 pumBin = floor(pumLevel / pumBinSize);
76 if (pumBin >= pumLUT->size())
77 pumBin = pumLUT->size() - 1;
84 for (uint32_t side = 0; side < 2; side++) {
88 for (uint32_t crate = 0; crate <
g.getNCrates(); crate++) {
89 for (uint32_t card = 0; card <
g.getNCards(); card++) {
92 uint32_t iPhi =
g.getUCTRegionPhiIndex(crate, card);
93 UCTRegionIndex regionIndex(
iEta, iPhi);
94 processRegion(regionIndex);
95 const UCTRegion* uctRegion = getRegion(
iEta, iPhi);
96 if (uctRegion ==
nullptr) {
100 uint32_t pileupInRegion = (*pumLUT)[pumBin][side][
region];
102 if (pileupInRegion <
et)
103 et -= pileupInRegion;
106 UCTTowerIndex hitTower =
g.getUCTTowerIndexFromL1CaloRegion(regionIndex, uctRegion->rawData());
107 int hitCaloPhi = hitTower.second;
108 sumEx += ((
int)(((
double)
et) *
cosPhi[hitCaloPhi]));
109 sumEy += ((
int)(((
double)
et) *
sinPhi[hitCaloPhi]));
112 sumHx += ((
int)(((
double)
et) *
cosPhi[hitCaloPhi]));
113 sumHy += ((
int)(((
double)
et) *
sinPhi[hitCaloPhi]));
120 uint32_t metSquare = sumEx * sumEx + sumEy * sumEy;
121 uint32_t metValue =
sqrt((
double)metSquare);
122 double metPhi = (atan2(sumEy, sumEx) * 180. / 3.1415927) + 180.;
123 int metIPhi = (
int)(72. * (metPhi / 360.));
124 uint32_t mhtSquare = sumHx * sumHx + sumHy * sumHy;
125 uint32_t mhtValue =
sqrt((
double)mhtSquare);
126 double mhtPhi = (atan2(sumHy, sumHx) * 180. / 3.1415927) + 180.;
127 int mhtIPhi = (
int)(72. * (mhtPhi / 360.));
139 centralJetObjs.sort();
140 forwardJetObjs.sort();
141 boostedJetObjs.sort();
146 bool UCTSummaryCard::processRegion(UCTRegionIndex center) {
151 std::vector<uint32_t> boostedJetTowers;
152 boostedJetTowers.clear();
153 for (
size_t iPhi = 0; iPhi < 12; iPhi++) {
155 boostedJetTowers.push_back(0);
159 std::vector<uint32_t> boostedJetRegionET, boostedJetRegionTauVeto;
160 boostedJetRegionET.clear();
161 boostedJetRegionTauVeto.clear();
162 for (
size_t i = 0;
i < 9;
i++) {
163 boostedJetRegionET.push_back(0);
164 boostedJetRegionTauVeto.push_back(0);
167 UCTGeometryExtended
g;
169 const UCTRegion* cRegion = getRegion(center.first, center.second);
170 if (cRegion ==
nullptr) {
175 bool centralRegion =
false;
176 if (cRegion->getRegion() < (NRegionsInCard - 1))
177 centralRegion =
true;
179 uint32_t centralET = cRegion->et();
180 uint32_t centralPU =
std::min(centralET, (*pumLUT)[pumBin][0][cRegion->getRegion()]);
181 if (!cRegion->isNegativeEta())
182 centralPU =
std::min(centralET, (*pumLUT)[pumBin][1][cRegion->getRegion()]);
183 centralET -= centralPU;
184 UCTTowerIndex centralHitTower =
g.getUCTTowerIndexFromL1CaloRegion(center, cRegion->rawData());
186 bool centralIsTauLike = cRegion->isTauLike();
187 if (cRegion->isTauLike())
189 bool centralIsEGammaLike = cRegion->isEGammaLike();
190 int hitCaloEta = centralHitTower.first;
191 int hitCaloPhi = centralHitTower.second;
193 boostedJetRegionET[4] = centralET;
194 boostedJetRegionTauVeto[4] = cRegion->isTauLike();
196 UCTRegionIndex northIndex =
g.getUCTRegionNorth(center);
197 const UCTRegion* northRegion = getRegion(northIndex.first, northIndex.second);
198 uint32_t northET = 0;
199 uint32_t northPU = 0;
200 UCTTowerIndex northHitTower;
201 bool northIsTauLike =
false;
202 bool northIsEGammaLike =
false;
203 if (northRegion !=
nullptr) {
204 northET = northRegion->et();
205 northPU =
std::min(northET, (*pumLUT)[pumBin][0][northRegion->getRegion()]);
206 if (!northRegion->isNegativeEta())
207 northPU =
std::min(northET, (*pumLUT)[pumBin][1][northRegion->getRegion()]);
209 northHitTower =
g.getUCTTowerIndexFromL1CaloRegion(northIndex, northRegion->rawData());
210 northIsTauLike = northRegion->isTauLike();
211 if (northRegion->isTauLike())
213 northIsEGammaLike = northRegion->isEGammaLike();
214 boostedJetRegionET[3] = northET;
215 boostedJetRegionTauVeto[3] = northRegion->isTauLike();
218 UCTRegionIndex southIndex =
g.getUCTRegionSouth(center);
219 const UCTRegion* southRegion = getRegion(southIndex.first, southIndex.second);
220 uint32_t southET = 0;
221 uint32_t southPU = 0;
222 UCTTowerIndex southHitTower;
223 bool southIsTauLike =
false;
224 bool southIsEGammaLike =
false;
225 if (southRegion !=
nullptr) {
226 southET = southRegion->et();
227 southPU =
std::min(southET, (*pumLUT)[pumBin][0][southRegion->getRegion()]);
228 if (!southRegion->isNegativeEta())
229 southPU =
std::min(southET, (*pumLUT)[pumBin][1][southRegion->getRegion()]);
231 southHitTower =
g.getUCTTowerIndexFromL1CaloRegion(southIndex, southRegion->rawData());
232 southIsTauLike = southRegion->isTauLike();
233 if (southRegion->isTauLike())
235 southIsEGammaLike = southRegion->isEGammaLike();
236 boostedJetRegionET[5] = southET;
237 boostedJetRegionTauVeto[5] = southRegion->isTauLike();
240 UCTRegionIndex westIndex =
g.getUCTRegionWest(center);
241 const UCTRegion* westRegion = getRegion(westIndex.first, westIndex.second);
244 UCTTowerIndex westHitTower;
245 bool westIsTauLike =
false;
246 bool westIsEGammaLike =
false;
247 if (westRegion !=
nullptr) {
248 westET = westRegion->et();
249 westPU =
std::min(westET, (*pumLUT)[pumBin][0][westRegion->getRegion()]);
250 if (!westRegion->isNegativeEta())
251 westPU =
std::min(westET, (*pumLUT)[pumBin][1][westRegion->getRegion()]);
253 westHitTower =
g.getUCTTowerIndexFromL1CaloRegion(westIndex, westRegion->rawData());
254 westIsTauLike = westRegion->isTauLike();
255 if (westRegion->isTauLike())
257 westIsEGammaLike = westRegion->isEGammaLike();
258 boostedJetRegionET[7] = westET;
259 boostedJetRegionTauVeto[7] = westRegion->isTauLike();
262 UCTRegionIndex eastIndex =
g.getUCTRegionEast(center);
263 const UCTRegion* eastRegion = getRegion(eastIndex.first, eastIndex.second);
266 UCTTowerIndex eastHitTower;
267 bool eastIsTauLike =
false;
268 bool eastIsEGammaLike =
false;
269 if (eastRegion !=
nullptr) {
270 eastET = eastRegion->et();
271 eastPU =
std::min(eastET, (*pumLUT)[pumBin][0][eastRegion->getRegion()]);
272 if (!eastRegion->isNegativeEta())
273 eastPU =
std::min(eastET, (*pumLUT)[pumBin][1][eastRegion->getRegion()]);
275 eastHitTower =
g.getUCTTowerIndexFromL1CaloRegion(eastIndex, eastRegion->rawData());
276 eastIsTauLike = eastRegion->isTauLike();
277 if (eastRegion->isTauLike())
279 eastIsEGammaLike = eastRegion->isEGammaLike();
280 boostedJetRegionET[1] = eastET;
281 boostedJetRegionTauVeto[1] = eastRegion->isTauLike();
284 UCTRegionIndex nwIndex =
g.getUCTRegionNW(center);
285 const UCTRegion* nwRegion = getRegion(nwIndex.first, nwIndex.second);
288 UCTTowerIndex nwHitTower;
289 if (nwRegion !=
nullptr) {
290 if (nwRegion->isTauLike())
292 nwET = nwRegion->et();
293 nwPU =
std::min(nwET, (*pumLUT)[pumBin][0][nwRegion->getRegion()]);
294 if (!nwRegion->isNegativeEta())
295 nwPU =
std::min(nwET, (*pumLUT)[pumBin][1][nwRegion->getRegion()]);
297 nwHitTower =
g.getUCTTowerIndexFromL1CaloRegion(nwIndex, nwRegion->rawData());
298 boostedJetRegionET[6] = nwET;
299 boostedJetRegionTauVeto[6] = nwRegion->isTauLike();
302 UCTRegionIndex neIndex =
g.getUCTRegionNE(center);
303 const UCTRegion* neRegion = getRegion(neIndex.first, neIndex.second);
306 UCTTowerIndex neHitTower;
307 if (neRegion !=
nullptr) {
308 if (neRegion->isTauLike())
310 neET = neRegion->et();
311 nePU =
std::min(neET, (*pumLUT)[pumBin][0][neRegion->getRegion()]);
312 if (!neRegion->isNegativeEta())
313 nePU =
std::min(neET, (*pumLUT)[pumBin][1][neRegion->getRegion()]);
315 neHitTower =
g.getUCTTowerIndexFromL1CaloRegion(neIndex, neRegion->rawData());
316 boostedJetRegionET[0] = neET;
317 boostedJetRegionTauVeto[0] = neRegion->isTauLike();
320 UCTRegionIndex swIndex =
g.getUCTRegionSW(center);
321 const UCTRegion* swRegion = getRegion(swIndex.first, swIndex.second);
324 UCTTowerIndex swHitTower;
325 if (swRegion !=
nullptr) {
326 if (swRegion->isTauLike())
328 swET = swRegion->et();
329 swPU =
std::min(swET, (*pumLUT)[pumBin][0][swRegion->getRegion()]);
330 if (!swRegion->isNegativeEta())
331 swPU =
std::min(swET, (*pumLUT)[pumBin][1][swRegion->getRegion()]);
333 swHitTower =
g.getUCTTowerIndexFromL1CaloRegion(swIndex, swRegion->rawData());
334 boostedJetRegionET[8] = swET;
335 boostedJetRegionTauVeto[8] = swRegion->isTauLike();
338 UCTRegionIndex seIndex =
g.getUCTRegionSE(center);
339 const UCTRegion* seRegion = getRegion(seIndex.first, seIndex.second);
342 UCTTowerIndex seHitTower;
343 if (seRegion !=
nullptr) {
344 if (seRegion->isTauLike())
346 seET = seRegion->et();
347 sePU =
std::min(seET, (*pumLUT)[pumBin][0][seRegion->getRegion()]);
348 if (!seRegion->isNegativeEta())
349 sePU =
std::min(seET, (*pumLUT)[pumBin][1][seRegion->getRegion()]);
351 seHitTower =
g.getUCTTowerIndexFromL1CaloRegion(seIndex, seRegion->rawData());
352 boostedJetRegionET[2] = seET;
353 boostedJetRegionTauVeto[2] = seRegion->isTauLike();
356 uint32_t et3x3 = centralET + northET + nwET + westET + swET + southET + seET + eastET + neET;
360 uint32_t pu3x3 = centralPU + northPU + nwPU + westPU + swPU + southPU + sePU + eastPU + nePU;
364 if (centralET >= northET && centralET >= nwET && centralET >= westET && centralET >= swET && centralET > southET &&
365 centralET > seET && centralET > eastET && centralET > neET && centralET >
jetSeed) {
366 uint32_t jetET = et3x3;
368 centralJetObjs.push_back(
new UCTObject(
UCTObject::jet, jetET, hitCaloEta, hitCaloPhi, pu3x3, 0, et3x3));
370 forwardJetObjs.push_back(
new UCTObject(
UCTObject::jet, jetET, hitCaloEta, hitCaloPhi, pu3x3, 0, et3x3));
372 auto boostedJet =
new UCTObject(
UCTObject::jet, jetET, hitCaloEta, hitCaloPhi, pu3x3, 0, et3x3);
373 boostedJet->setNTaus(nTauLike);
374 boostedJet->setBoostedJetRegionET(boostedJetRegionET);
375 boostedJet->setBoostedJetRegionTauVeto(boostedJetRegionTauVeto);
376 boostedJetObjs.push_back(boostedJet);
381 if (centralRegion && centralIsTauLike && centralET >
tauSeed) {
382 uint32_t tauET = centralET;
383 uint32_t tauPU = centralPU;
384 int neighborMatchCount = 0;
386 if (!
g.isEdgeTower(centralHitTower)) {
389 if (
g.areNeighbors(centralHitTower, northHitTower) && northIsTauLike && centralET >= northET) {
392 neighborMatchCount++;
393 }
else if (
g.areNeighbors(centralHitTower, northHitTower) && northIsTauLike && centralET < northET) {
396 if (
g.areNeighbors(centralHitTower, southHitTower) && southIsTauLike && centralET > southET) {
399 neighborMatchCount++;
400 }
else if (
g.areNeighbors(centralHitTower, southHitTower) && southIsTauLike && centralET <= southET) {
403 if (
g.areNeighbors(centralHitTower, westHitTower) && westIsTauLike && centralET >= westET) {
406 neighborMatchCount++;
407 }
else if (
g.areNeighbors(centralHitTower, westHitTower) && westIsTauLike && centralET < westET) {
410 if (
g.areNeighbors(centralHitTower, eastHitTower) && eastIsTauLike && centralET > eastET) {
413 neighborMatchCount++;
414 }
else if (
g.areNeighbors(centralHitTower, eastHitTower) && eastIsTauLike && centralET <= eastET) {
417 if (neighborMatchCount > 2) {
422 tauObjs.push_back(
new UCTObject(
UCTObject::tau, tauET, hitCaloEta, hitCaloPhi, tauPU, 0xDEADBEEF, et3x3));
428 isoTauObjs.push_back(
new UCTObject(UCTObject::isoTau, tauET, hitCaloEta, hitCaloPhi, pu3x3,
isolation, et3x3));
439 if (centralRegion && centralIsEGammaLike && centralET >
eGammaSeed) {
440 uint32_t eGammaET = centralET;
441 uint32_t eGammaPU = centralPU;
442 int neighborMatchCount = 0;
443 if (!
g.isEdgeTower(centralHitTower)) {
444 if (
g.areNeighbors(centralHitTower, northHitTower) && northIsEGammaLike && centralET >= northET) {
447 neighborMatchCount++;
448 }
else if (
g.areNeighbors(centralHitTower, northHitTower) && northIsEGammaLike && centralET < northET) {
451 if (
g.areNeighbors(centralHitTower, southHitTower) && southIsEGammaLike && centralET > southET) {
454 neighborMatchCount++;
455 }
else if (
g.areNeighbors(centralHitTower, southHitTower) && southIsEGammaLike && centralET <= southET) {
458 if (
g.areNeighbors(centralHitTower, westHitTower) && westIsEGammaLike && centralET >= westET) {
461 neighborMatchCount++;
462 }
else if (
g.areNeighbors(centralHitTower, westHitTower) && westIsEGammaLike && centralET < westET) {
465 if (
g.areNeighbors(centralHitTower, eastHitTower) && eastIsEGammaLike && centralET > eastET) {
468 neighborMatchCount++;
469 }
else if (
g.areNeighbors(centralHitTower, eastHitTower) && eastIsEGammaLike && centralET <= eastET) {
472 if (neighborMatchCount > 2) {
477 emObjs.push_back(
new UCTObject(UCTObject::eGamma, eGammaET, hitCaloEta, hitCaloPhi, eGammaPU, 0xDEADBEEF, et3x3));
479 if (et3x3 > eGammaET)
483 new UCTObject(UCTObject::isoEGamma, eGammaET, hitCaloEta, hitCaloPhi, pu3x3,
isolation, et3x3));
491 bool UCTSummaryCard::clearEvent() {
496 centralJetObjs.clear();
497 forwardJetObjs.clear();
498 boostedJetObjs.clear();
502 bool UCTSummaryCard::clearRegions() {
507 const UCTRegion* UCTSummaryCard::getRegion(
int regionEtaIndex, uint32_t regionPhiIndex)
const {
508 if (regionEtaIndex == 0 || (uint32_t)
std::abs(regionEtaIndex) > NRegionsInCard ||
509 regionPhiIndex >= MaxUCTRegionsPhi) {
513 UCTRegionIndex
r = UCTRegionIndex(regionEtaIndex, regionPhiIndex);
514 UCTTowerIndex
t =
g.getUCTTowerIndex(
r);
516 uint32_t absCaloPhi =
std::abs(
t.second);
517 bool negativeEta =
false;
520 uint32_t nCrate =
g.getCrate(absCaloEta, absCaloPhi);
521 uint32_t nCard =
g.getCard(absCaloEta, absCaloPhi);
522 uint32_t nRegion =
g.getRegion(absCaloEta, absCaloPhi);
523 uint32_t
i = ((NCardsInCrate * NRegionsInCard * nCrate) + (NRegionsInCard * nCard) + nRegion) *
528 edm::LogError(
"L1TCaloSummary") <<
"UCTSummaryCard: Incorrect region requested -- bailing" << std::endl;
534 bool UCTSummaryCard::setRegionData(std::vector<UCTRegion*> inputRegions) {
535 for (
long unsigned int i = 0;
i < inputRegions.size();
i++) {
543 edm::LogInfo(
"L1TCaloSummary") <<
"UCTSummaryCard: result = " << cardSummary << std::endl;