376 std::vector<SimpleCaloHit> ecalhits;
378 for (
const auto&
hit : *pcalohits.
product()) {
379 if (
hit.encodedEt() > 0)
382 float et =
hit.encodedEt() / 8.;
389 ehit.setId(
hit.
id());
390 ehit.setPosition(
GlobalVector(cell->getPosition().x(), cell->getPosition().y(), cell->getPosition().z()));
393 ecalhits.push_back(ehit);
398 std::vector<SimpleCaloHit> hcalhits;
402 float et = decoder.hcaletValue(
hit.
id(),
hit.t0());
406 LogError(
"L1EGCrystalClusterEmulatorProducer")
407 <<
" -- Hcal hit DetID not present in HCAL Geom: " <<
hit.
id() << std::endl;
411 const std::vector<HcalDetId>& hcId = theTrigTowerGeometry.detIds(
hit.
id());
413 LogError(
"L1EGCrystalClusterEmulatorProducer")
414 <<
"Cannot find any HCalDetId corresponding to " <<
hit.
id() << std::endl;
418 if (hcId[0].subdetId() > 1)
421 for (
const auto& hcId_i : hcId) {
422 if (hcId_i.subdetId() > 1)
428 hcal_tp_position = tmpVector;
432 hhit.setId(
hit.
id());
433 hhit.setIdHcal(
hit.
id());
434 hhit.setPosition(hcal_tp_position);
437 hcalhits.push_back(hhit);
463 ECAL_tower_L1Card[
ii][
jj][ll] = 0;
464 HCAL_tower_L1Card[
ii][
jj][ll] = 0;
465 iPhi_tower_L1Card[
ii][
jj][ll] = -999;
466 iEta_tower_L1Card[
ii][
jj][ll] = -999;
473 energy_cluster_L1Card[
ii][
jj][ll] = 0;
474 brem_cluster_L1Card[
ii][
jj][ll] = 0;
475 towerID_cluster_L1Card[
ii][
jj][ll] = 0;
476 crystalID_cluster_L1Card[
ii][
jj][ll] = 0;
490 bool build_cluster =
true;
494 build_cluster =
false;
495 SimpleCaloHit centerhit;
497 for (
const auto&
hit : ecalhits) {
505 !
hit.used() &&
hit.pt() >= 1.0 &&
hit.pt() > centerhit.pt())
509 build_cluster =
true;
516 if (build_cluster && nclusters > 0 && nclusters <=
n_clusters_max) {
519 mc1.cWeightedEta_ = 0.0;
520 mc1.cWeightedPhi_ = 0.0;
537 for (
auto&
hit : ecalhits) {
544 if (
abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) > 2 &&
hit.diphi(centerhit) <= 7) {
545 rightlobe +=
hit.pt();
547 if (
abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) < -2 &&
hit.diphi(centerhit) >= -7) {
548 leftlobe +=
hit.pt();
550 if (
abs(
hit.dieta(centerhit)) <= 2 &&
abs(
hit.diphi(centerhit)) <= 2) {
551 e5x5 +=
hit.energy();
554 if ((
hit.dieta(centerhit) == 1
or hit.dieta(centerhit) == 0) &&
555 (
hit.diphi(centerhit) == 1
or hit.diphi(centerhit) == 0)) {
556 e2x2_1 +=
hit.energy();
559 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == -1) &&
560 (
hit.diphi(centerhit) == 0
or hit.diphi(centerhit) == 1)) {
561 e2x2_2 +=
hit.energy();
564 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == 1) &&
565 (
hit.diphi(centerhit) == 0
or hit.diphi(centerhit) == -1)) {
566 e2x2_3 +=
hit.energy();
569 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == -1) &&
570 (
hit.diphi(centerhit) == 0
or hit.diphi(centerhit) == -1)) {
571 e2x2_4 +=
hit.energy();
574 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == 1) &&
abs(
hit.diphi(centerhit)) <= 2) {
575 e2x5_1 +=
hit.energy();
578 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == -1) &&
abs(
hit.diphi(centerhit)) <= 2) {
579 e2x5_2 +=
hit.energy();
587 abs(
hit.dieta(centerhit)) <= 1 &&
abs(
hit.diphi(centerhit)) <= 2 &&
593 mc1.cWeightedEta_ +=
float(
hit.pt()) *
float(
hit.position().eta());
594 mc1.cWeightedPhi_ = mc1.cWeightedPhi_ + (
float(
hit.pt()) *
float(
hit.position().phi()));
597 if (
do_brem && (rightlobe > 0.10 * mc1.cpt
or leftlobe > 0.10 * mc1.cpt)) {
598 for (
auto&
hit : ecalhits) {
606 if (rightlobe > 0.10 * mc1.cpt && (leftlobe < 0.10 * mc1.cpt or rightlobe > leftlobe) &&
607 abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) > 2 &&
hit.diphi(centerhit) <= 7) {
612 if (leftlobe > 0.10 * mc1.cpt && (rightlobe < 0.10 * mc1.cpt or leftlobe >= rightlobe) &&
613 abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) < -2 &&
hit.diphi(centerhit) >= -7) {
622 mc1.c2x5_ =
max(e2x5_1, e2x5_2);
624 if (e2x2_2 > mc1.c2x2_)
626 if (e2x2_3 > mc1.c2x2_)
628 if (e2x2_4 > mc1.c2x2_)
630 mc1.cWeightedEta_ = mc1.cWeightedEta_ / mc1.cpt;
631 mc1.cWeightedPhi_ = mc1.cWeightedPhi_ / mc1.cpt;
634 mc1.crawphi_ = centerhit.position().phi();
635 mc1.craweta_ = centerhit.position().eta();
636 cluster_list[
cc].push_back(mc1);
640 std::sort(begin(cluster_list[
cc]),
end(cluster_list[
cc]), [](mycluster
a, mycluster
b) {
return a.cpt >
b.cpt; });
643 for (
unsigned int jj = 0;
jj < unsigned(cluster_list[
cc].
size()); ++
jj) {
644 for (
unsigned int kk =
jj + 1;
kk < unsigned(cluster_list[
cc].
size()); ++
kk) {
645 if (
std::abs(cluster_list[
cc][
jj].ceta_ - cluster_list[
cc][
kk].ceta_) < 2 &&
647 if (cluster_list[
cc][
kk].cpt > cluster_list[
cc][
jj].cpt) {
648 cluster_list[
cc][
kk].cpt += cluster_list[
cc][
jj].cpt;
649 cluster_list[
cc][
kk].c5x5_ += cluster_list[
cc][
jj].c5x5_;
650 cluster_list[
cc][
kk].c2x5_ += cluster_list[
cc][
jj].c2x5_;
651 cluster_list[
cc][
jj].cpt = 0;
652 cluster_list[
cc][
jj].c5x5_ = 0;
653 cluster_list[
cc][
jj].c2x5_ = 0;
654 cluster_list[
cc][
jj].c2x2_ = 0;
656 cluster_list[
cc][
jj].cpt += cluster_list[
cc][
kk].cpt;
657 cluster_list[
cc][
jj].c5x5_ += cluster_list[
cc][
kk].c5x5_;
658 cluster_list[
cc][
jj].c2x5_ += cluster_list[
cc][
kk].c2x5_;
659 cluster_list[
cc][
kk].cpt = 0;
660 cluster_list[
cc][
kk].c2x2_ = 0;
661 cluster_list[
cc][
kk].c2x5_ = 0;
662 cluster_list[
cc][
kk].c5x5_ = 0;
666 if (cluster_list[
cc][
jj].cpt > 0) {
667 cluster_list[
cc][
jj].cpt =
668 cluster_list[
cc][
jj].cpt *
671 cluster_list_merged[
cc].push_back(cluster_list[
cc][
jj]);
674 std::sort(begin(cluster_list_merged[
cc]),
end(cluster_list_merged[
cc]), [](mycluster
a, mycluster
b) {
675 return a.cpt >
b.cpt;
687 cluster_list_merged[
cc][
jj].c2x5_ / cluster_list_merged[
cc][
jj].c5x5_))
692 cluster_list_merged[
cc][
jj].c2x5_ / cluster_list_merged[
cc][
jj].c5x5_))
697 cluster_list_merged[
cc][
jj].c2x2_ / cluster_list_merged[
cc][
jj].c2x5_))
704 for (
const auto&
hit : ecalhits) {
723 static constexpr
float tower_width = 0.0873;
728 (
ii + 0.5) * tower_width;
738 for (
const auto&
hit : hcalhits) {
747 HCAL_tower_L1Card[
jj][
ii][
cc] +=
hit.pt();
759 if (cluster_list_merged[
cc][
kk].cpt > 0) {
790 HCAL_tower_L2Card[
ii][
jj][ll] = 0;
791 ECAL_tower_L2Card[
ii][
jj][ll] = 0;
792 iEta_tower_L2Card[
ii][
jj][ll] = 0;
793 iPhi_tower_L2Card[
ii][
jj][ll] = 0;
800 energy_cluster_L2Card[
ii][
jj][ll] = 0;
801 brem_cluster_L2Card[
ii][
jj][ll] = 0;
802 towerID_cluster_L2Card[
ii][
jj][ll] = 0;
803 crystalID_cluster_L2Card[
ii][
jj][ll] = 0;
804 isolation_cluster_L2Card[
ii][
jj][ll] = 0;
805 HE_cluster_L2Card[
ii][
jj][ll] = 0;
806 photonShowerShape_cluster_L2Card[
ii][
jj][ll] = 0;
807 showerShape_cluster_L2Card[
ii][
jj][ll] = 0;
808 showerShapeLooseTk_cluster_L2Card[
ii][
jj][ll] = 0;
819 int card_left = 2 *
ii +
jj;
820 int card_right = 2 *
ii +
jj + 2;
857 int card_left = 2 *
ii +
jj;
858 int card_right = 2 *
ii +
jj + 2;
909 int card_bottom = 2 *
ii;
910 int card_top = 2 *
ii + 1;
950 cluster_list_L2[
ii].push_back(mc1);
954 begin(cluster_list_L2[
ii]),
end(cluster_list_L2[
ii]), [](mycluster
a, mycluster
b) {
return a.cpt >
b.cpt; });
960 if (cluster_list_L2[
ii][
jj].cpt > 0) {
963 cluster_list_L2[
ii][
jj].cpt = 0;
964 cluster_list_L2[
ii][
jj].ctowerid_ = 0;
965 cluster_list_L2[
ii][
jj].ccrystalid_ = 0;
972 for (
unsigned int jj = 0;
jj < 8 &&
jj < cluster_list_L2[
ii].size(); ++
jj) {
975 float hcal_nrj = 0.0;
979 for (
unsigned int jjj = 0; jjj < 8 && jjj < cluster_list_L2[iii].size(); ++jjj) {
980 if (!(iii ==
ii && jjj ==
jj)) {
983 if (
abs(cluster2_eta - cluster_etaOfTower_fullDetector) <= 2 &&
984 (
abs(cluster2_phi - cluster_phiOfTower_fullDetector) <= 2
or
985 abs(cluster2_phi -
n_towers_Phi - cluster_phiOfTower_fullDetector) <= 2)) {
986 isolation += cluster_list_L2[iii][jjj].cpt;
998 if (
abs(etaOftower_fullDetector - cluster_etaOfTower_fullDetector) <= 2 &&
999 (
abs(phiOftower_fullDetector - cluster_phiOfTower_fullDetector) <= 2
or
1000 abs(phiOftower_fullDetector -
n_towers_Phi - cluster_phiOfTower_fullDetector) <= 2)) {
1002 if (!((cluster_phiOfTower_fullDetector == 0 && phiOftower_fullDetector == 71)
or
1003 (cluster_phiOfTower_fullDetector == 23 && phiOftower_fullDetector == 26)
or
1004 (cluster_phiOfTower_fullDetector == 24 && phiOftower_fullDetector == 21)
or
1005 (cluster_phiOfTower_fullDetector == 47 && phiOftower_fullDetector == 50)
or
1006 (cluster_phiOfTower_fullDetector == 48 && phiOftower_fullDetector == 45)
or
1007 (cluster_phiOfTower_fullDetector == 71 && phiOftower_fullDetector == 2))) {
1014 if (
abs(etaOftower_fullDetector - cluster_etaOfTower_fullDetector) <= 2 &&
1015 (
abs(phiOftower_fullDetector - cluster_phiOfTower_fullDetector) <= 2
or
1016 abs(phiOftower_fullDetector -
n_towers_Phi - cluster_phiOfTower_fullDetector) <= 2)) {
1017 hcal_nrj += HCAL_tower_L1Card[ll][mm][
kk];
1022 cluster_list_L2[
ii][
jj].ciso_ = ((
isolation) * (25.0 / ntowers)) / cluster_list_L2[
ii][
jj].cpt;
1023 cluster_list_L2[
ii][
jj].chovere_ = hcal_nrj / cluster_list_L2[
ii][
jj].cpt;
1031 for (
int ll = 0; ll < 3; ++ll) {
1032 ECAL_tower_L2Card[
ii][
jj][ll] =
1034 HCAL_tower_L2Card[
ii][
jj][ll] =
1036 iEta_tower_L2Card[
ii][
jj][ll] =
1038 iPhi_tower_L2Card[
ii][
jj][ll] =
1068 auto L1EGXtalClusters = std::make_unique<l1tp2::CaloCrystalClusterCollection>();
1069 auto L1EGammas = std::make_unique<l1t::EGammaBxCollection>();
1070 auto L1CaloTowers = std::make_unique<l1tp2::CaloTowerCollection>();
1076 for (
int jj = 0;
jj < 2; ++
jj) {
1077 if (energy_cluster_L2Card[
ii][
jj][ll] > 0.45) {
1079 energy_cluster_L2Card[
ii][
jj][ll],
1081 ii, ll, towerID_cluster_L2Card[
ii][
jj][ll], crystalID_cluster_L2Card[
ii][
jj][ll]),
1083 ii, ll, towerID_cluster_L2Card[
ii][
jj][ll], crystalID_cluster_L2Card[
ii][
jj][ll]),
1085 SimpleCaloHit centerhit;
1086 bool is_iso =
passes_iso(energy_cluster_L2Card[
ii][
jj][ll], isolation_cluster_L2Card[
ii][
jj][ll]);
1087 bool is_looseTkiso =
1089 bool is_ss = (showerShape_cluster_L2Card[
ii][
jj][ll] == 1);
1090 bool is_photon = (photonShowerShape_cluster_L2Card[
ii][
jj][ll] == 1) && is_ss && is_iso;
1091 bool is_looseTkss = (showerShapeLooseTk_cluster_L2Card[
ii][
jj][ll] == 1);
1094 energy_cluster_L2Card[
ii][
jj][ll],
1095 HE_cluster_L2Card[
ii][
jj][ll],
1096 isolation_cluster_L2Card[
ii][
jj][ll],
1102 energy_cluster_L2Card[
ii][
jj][ll],
1108 is_looseTkiso&& is_looseTkss,
1111 std::map<std::string, float>
params;
1112 params[
"standaloneWP_showerShape"] = is_ss;
1113 params[
"standaloneWP_isolation"] = is_iso;
1114 params[
"trkMatchWP_showerShape"] = is_looseTkss;
1115 params[
"trkMatchWP_isolation"] = is_looseTkiso;
1118 cluster.setExperimentalParams(
params);
1119 L1EGXtalClusters->push_back(cluster);
1121 int standaloneWP = (
int)(is_iso && is_ss);
1122 int looseL1TkMatchWP = (
int)(is_looseTkiso && is_looseTkss);
1123 int photonWP = (
int)(is_photon);
1126 L1EGammas->push_back(
1127 0,
l1t::EGamma(p4calibrated, p4calibrated.pt(), p4calibrated.eta(), p4calibrated.phi(),
quality, 1));
1145 static float constexpr towerEtaUpperUnitialized = -80;
1146 static float constexpr towerPhiUpperUnitialized = -90;
1147 if (l1CaloTower.
towerEta() < towerEtaUpperUnitialized && l1CaloTower.
towerPhi() < towerPhiUpperUnitialized) {
1155 for (
const auto& l1eg : *L1EGXtalClusters) {
1156 if (l1eg.experimentalParam(
"TTiEta") != l1CaloTower.
towerIEta())
1158 if (l1eg.experimentalParam(
"TTiPhi") != l1CaloTower.
towerIPhi())
1161 int n_L1eg = l1CaloTower.
nL1eg();
1165 if (l1CaloTower.
nL1eg() > 1)
1167 l1CaloTower.
setL1egTrkSS(l1eg.experimentalParam(
"trkMatchWP_showerShape"));
1168 l1CaloTower.
setL1egTrkIso(l1eg.experimentalParam(
"trkMatchWP_isolation"));
1173 L1CaloTowers->push_back(l1CaloTower);