372 std::vector<SimpleCaloHit> ecalhits;
374 for (
const auto&
hit : *pcalohits.
product()) {
375 if (
hit.encodedEt() > 0)
378 float et =
hit.encodedEt() / 8.;
385 ehit.setId(
hit.
id());
386 ehit.setPosition(
GlobalVector(cell->getPosition().x(), cell->getPosition().y(), cell->getPosition().z()));
389 ecalhits.push_back(ehit);
394 std::vector<SimpleCaloHit> hcalhits;
402 LogError(
"L1EGCrystalClusterEmulatorProducer")
403 <<
" -- Hcal hit DetID not present in HCAL Geom: " <<
hit.
id() << std::endl;
407 const std::vector<HcalDetId>& hcId = theTrigTowerGeometry.detIds(
hit.
id());
409 LogError(
"L1EGCrystalClusterEmulatorProducer")
410 <<
"Cannot find any HCalDetId corresponding to " <<
hit.
id() << std::endl;
414 if (hcId[0].subdetId() > 1)
417 for (
const auto& hcId_i : hcId) {
418 if (hcId_i.subdetId() > 1)
424 hcal_tp_position = tmpVector;
428 hhit.setId(
hit.
id());
429 hhit.setIdHcal(
hit.
id());
430 hhit.setPosition(hcal_tp_position);
433 hcalhits.push_back(hhit);
459 ECAL_tower_L1Card[
ii][
jj][ll] = 0;
460 HCAL_tower_L1Card[
ii][
jj][ll] = 0;
461 iPhi_tower_L1Card[
ii][
jj][ll] = -999;
462 iEta_tower_L1Card[
ii][
jj][ll] = -999;
469 energy_cluster_L1Card[
ii][
jj][ll] = 0;
470 brem_cluster_L1Card[
ii][
jj][ll] = 0;
471 towerID_cluster_L1Card[
ii][
jj][ll] = 0;
472 crystalID_cluster_L1Card[
ii][
jj][ll] = 0;
486 bool build_cluster =
true;
490 build_cluster =
false;
491 SimpleCaloHit centerhit;
493 for (
const auto&
hit : ecalhits) {
501 !
hit.used() &&
hit.pt() >= 1.0 &&
hit.pt() > centerhit.pt())
505 build_cluster =
true;
512 if (build_cluster && nclusters > 0 && nclusters <=
n_clusters_max) {
515 mc1.cWeightedEta_ = 0.0;
516 mc1.cWeightedPhi_ = 0.0;
533 for (
auto&
hit : ecalhits) {
540 if (
abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) > 2 &&
hit.diphi(centerhit) <= 7) {
541 rightlobe +=
hit.pt();
543 if (
abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) < -2 &&
hit.diphi(centerhit) >= -7) {
544 leftlobe +=
hit.pt();
546 if (
abs(
hit.dieta(centerhit)) <= 2 &&
abs(
hit.diphi(centerhit)) <= 2) {
547 e5x5 +=
hit.energy();
550 if ((
hit.dieta(centerhit) == 1
or hit.dieta(centerhit) == 0) &&
551 (
hit.diphi(centerhit) == 1
or hit.diphi(centerhit) == 0)) {
552 e2x2_1 +=
hit.energy();
555 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == -1) &&
556 (
hit.diphi(centerhit) == 0
or hit.diphi(centerhit) == 1)) {
557 e2x2_2 +=
hit.energy();
560 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == 1) &&
561 (
hit.diphi(centerhit) == 0
or hit.diphi(centerhit) == -1)) {
562 e2x2_3 +=
hit.energy();
565 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == -1) &&
566 (
hit.diphi(centerhit) == 0
or hit.diphi(centerhit) == -1)) {
567 e2x2_4 +=
hit.energy();
570 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == 1) &&
abs(
hit.diphi(centerhit)) <= 2) {
571 e2x5_1 +=
hit.energy();
574 if ((
hit.dieta(centerhit) == 0
or hit.dieta(centerhit) == -1) &&
abs(
hit.diphi(centerhit)) <= 2) {
575 e2x5_2 +=
hit.energy();
583 abs(
hit.dieta(centerhit)) <= 1 &&
abs(
hit.diphi(centerhit)) <= 2 &&
589 mc1.cWeightedEta_ +=
float(
hit.pt()) *
float(
hit.position().eta());
590 mc1.cWeightedPhi_ = mc1.cWeightedPhi_ + (
float(
hit.pt()) *
float(
hit.position().phi()));
593 if (
do_brem && (rightlobe > 0.10 * mc1.cpt
or leftlobe > 0.10 * mc1.cpt)) {
594 for (
auto&
hit : ecalhits) {
602 if (rightlobe > 0.10 * mc1.cpt && (leftlobe < 0.10 * mc1.cpt or rightlobe > leftlobe) &&
603 abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) > 2 &&
hit.diphi(centerhit) <= 7) {
608 if (leftlobe > 0.10 * mc1.cpt && (rightlobe < 0.10 * mc1.cpt or leftlobe >= rightlobe) &&
609 abs(
hit.dieta(centerhit)) <= 1 &&
hit.diphi(centerhit) < -2 &&
hit.diphi(centerhit) >= -7) {
618 mc1.c2x5_ =
max(e2x5_1, e2x5_2);
620 if (e2x2_2 > mc1.c2x2_)
622 if (e2x2_3 > mc1.c2x2_)
624 if (e2x2_4 > mc1.c2x2_)
626 mc1.cWeightedEta_ = mc1.cWeightedEta_ / mc1.cpt;
627 mc1.cWeightedPhi_ = mc1.cWeightedPhi_ / mc1.cpt;
630 mc1.crawphi_ = centerhit.position().phi();
631 mc1.craweta_ = centerhit.position().eta();
632 cluster_list[
cc].push_back(mc1);
636 std::sort(
begin(cluster_list[
cc]),
end(cluster_list[
cc]), [](mycluster
a, mycluster
b) {
return a.cpt >
b.cpt; });
639 for (
unsigned int jj = 0;
jj < unsigned(cluster_list[
cc].
size()); ++
jj) {
640 for (
unsigned int kk =
jj + 1;
kk < unsigned(cluster_list[
cc].
size()); ++
kk) {
641 if (
std::abs(cluster_list[
cc][
jj].ceta_ - cluster_list[
cc][
kk].ceta_) < 2 &&
643 if (cluster_list[
cc][
kk].cpt > cluster_list[
cc][
jj].cpt) {
644 cluster_list[
cc][
kk].cpt += cluster_list[
cc][
jj].cpt;
645 cluster_list[
cc][
kk].c5x5_ += cluster_list[
cc][
jj].c5x5_;
646 cluster_list[
cc][
kk].c2x5_ += cluster_list[
cc][
jj].c2x5_;
647 cluster_list[
cc][
jj].cpt = 0;
648 cluster_list[
cc][
jj].c5x5_ = 0;
649 cluster_list[
cc][
jj].c2x5_ = 0;
650 cluster_list[
cc][
jj].c2x2_ = 0;
652 cluster_list[
cc][
jj].cpt += cluster_list[
cc][
kk].cpt;
653 cluster_list[
cc][
jj].c5x5_ += cluster_list[
cc][
kk].c5x5_;
654 cluster_list[
cc][
jj].c2x5_ += cluster_list[
cc][
kk].c2x5_;
655 cluster_list[
cc][
kk].cpt = 0;
656 cluster_list[
cc][
kk].c2x2_ = 0;
657 cluster_list[
cc][
kk].c2x5_ = 0;
658 cluster_list[
cc][
kk].c5x5_ = 0;
662 if (cluster_list[
cc][
jj].cpt > 0) {
663 cluster_list[
cc][
jj].cpt =
664 cluster_list[
cc][
jj].cpt *
667 cluster_list_merged[
cc].push_back(cluster_list[
cc][
jj]);
670 std::sort(
begin(cluster_list_merged[
cc]),
end(cluster_list_merged[
cc]), [](mycluster
a, mycluster
b) {
671 return a.cpt >
b.cpt;
683 cluster_list_merged[
cc][
jj].c2x5_ / cluster_list_merged[
cc][
jj].c5x5_))
688 cluster_list_merged[
cc][
jj].c2x5_ / cluster_list_merged[
cc][
jj].c5x5_))
693 cluster_list_merged[
cc][
jj].c2x2_ / cluster_list_merged[
cc][
jj].c2x5_))
700 for (
const auto&
hit : ecalhits) {
719 static constexpr
float tower_width = 0.0873;
724 (
ii + 0.5) * tower_width;
734 for (
const auto&
hit : hcalhits) {
743 HCAL_tower_L1Card[
jj][
ii][
cc] +=
hit.pt();
755 if (cluster_list_merged[
cc][
kk].cpt > 0) {
786 HCAL_tower_L2Card[
ii][
jj][ll] = 0;
787 ECAL_tower_L2Card[
ii][
jj][ll] = 0;
788 iEta_tower_L2Card[
ii][
jj][ll] = 0;
789 iPhi_tower_L2Card[
ii][
jj][ll] = 0;
796 energy_cluster_L2Card[
ii][
jj][ll] = 0;
797 brem_cluster_L2Card[
ii][
jj][ll] = 0;
798 towerID_cluster_L2Card[
ii][
jj][ll] = 0;
799 crystalID_cluster_L2Card[
ii][
jj][ll] = 0;
800 isolation_cluster_L2Card[
ii][
jj][ll] = 0;
801 HE_cluster_L2Card[
ii][
jj][ll] = 0;
802 photonShowerShape_cluster_L2Card[
ii][
jj][ll] = 0;
803 showerShape_cluster_L2Card[
ii][
jj][ll] = 0;
804 showerShapeLooseTk_cluster_L2Card[
ii][
jj][ll] = 0;
815 int card_left = 2 *
ii +
jj;
816 int card_right = 2 *
ii +
jj + 2;
853 int card_left = 2 *
ii +
jj;
854 int card_right = 2 *
ii +
jj + 2;
905 int card_bottom = 2 *
ii;
906 int card_top = 2 *
ii + 1;
946 cluster_list_L2[
ii].push_back(mc1);
950 begin(cluster_list_L2[
ii]),
end(cluster_list_L2[
ii]), [](mycluster
a, mycluster
b) {
return a.cpt >
b.cpt; });
956 if (cluster_list_L2[
ii][
jj].cpt > 0) {
959 cluster_list_L2[
ii][
jj].cpt = 0;
960 cluster_list_L2[
ii][
jj].ctowerid_ = 0;
961 cluster_list_L2[
ii][
jj].ccrystalid_ = 0;
968 for (
unsigned int jj = 0;
jj < 8 &&
jj < cluster_list_L2[
ii].size(); ++
jj) {
971 float hcal_nrj = 0.0;
975 for (
unsigned int jjj = 0; jjj < 8 && jjj < cluster_list_L2[iii].size(); ++jjj) {
976 if (!(iii ==
ii && jjj ==
jj)) {
979 if (
abs(cluster2_eta - cluster_etaOfTower_fullDetector) <= 2 &&
980 (
abs(cluster2_phi - cluster_phiOfTower_fullDetector) <= 2
or
981 abs(cluster2_phi -
n_towers_Phi - cluster_phiOfTower_fullDetector) <= 2)) {
982 isolation += cluster_list_L2[iii][jjj].cpt;
994 if (
abs(etaOftower_fullDetector - cluster_etaOfTower_fullDetector) <= 2 &&
995 (
abs(phiOftower_fullDetector - cluster_phiOfTower_fullDetector) <= 2
or
996 abs(phiOftower_fullDetector -
n_towers_Phi - cluster_phiOfTower_fullDetector) <= 2)) {
998 if (!((cluster_phiOfTower_fullDetector == 0 && phiOftower_fullDetector == 71)
or
999 (cluster_phiOfTower_fullDetector == 23 && phiOftower_fullDetector == 26)
or
1000 (cluster_phiOfTower_fullDetector == 24 && phiOftower_fullDetector == 21)
or
1001 (cluster_phiOfTower_fullDetector == 47 && phiOftower_fullDetector == 50)
or
1002 (cluster_phiOfTower_fullDetector == 48 && phiOftower_fullDetector == 45)
or
1003 (cluster_phiOfTower_fullDetector == 71 && phiOftower_fullDetector == 2))) {
1010 if (
abs(etaOftower_fullDetector - cluster_etaOfTower_fullDetector) <= 2 &&
1011 (
abs(phiOftower_fullDetector - cluster_phiOfTower_fullDetector) <= 2
or
1012 abs(phiOftower_fullDetector -
n_towers_Phi - cluster_phiOfTower_fullDetector) <= 2)) {
1013 hcal_nrj += HCAL_tower_L1Card[ll][mm][
kk];
1018 cluster_list_L2[
ii][
jj].ciso_ = ((
isolation) * (25.0 / ntowers)) / cluster_list_L2[
ii][
jj].cpt;
1019 cluster_list_L2[
ii][
jj].chovere_ = hcal_nrj / cluster_list_L2[
ii][
jj].cpt;
1027 for (
int ll = 0; ll < 3; ++ll) {
1028 ECAL_tower_L2Card[
ii][
jj][ll] =
1030 HCAL_tower_L2Card[
ii][
jj][ll] =
1032 iEta_tower_L2Card[
ii][
jj][ll] =
1034 iPhi_tower_L2Card[
ii][
jj][ll] =
1064 auto L1EGXtalClusters = std::make_unique<l1tp2::CaloCrystalClusterCollection>();
1065 auto L1EGammas = std::make_unique<l1t::EGammaBxCollection>();
1066 auto L1CaloTowers = std::make_unique<l1tp2::CaloTowerCollection>();
1072 for (
int jj = 0;
jj < 2; ++
jj) {
1073 if (energy_cluster_L2Card[
ii][
jj][ll] > 0.45) {
1075 energy_cluster_L2Card[
ii][
jj][ll],
1077 ii, ll, towerID_cluster_L2Card[
ii][
jj][ll], crystalID_cluster_L2Card[
ii][
jj][ll]),
1079 ii, ll, towerID_cluster_L2Card[
ii][
jj][ll], crystalID_cluster_L2Card[
ii][
jj][ll]),
1081 SimpleCaloHit centerhit;
1082 bool is_iso =
passes_iso(energy_cluster_L2Card[
ii][
jj][ll], isolation_cluster_L2Card[
ii][
jj][ll]);
1083 bool is_looseTkiso =
1085 bool is_ss = (showerShape_cluster_L2Card[
ii][
jj][ll] == 1);
1086 bool is_photon = (photonShowerShape_cluster_L2Card[
ii][
jj][ll] == 1) && is_ss && is_iso;
1087 bool is_looseTkss = (showerShapeLooseTk_cluster_L2Card[
ii][
jj][ll] == 1);
1090 energy_cluster_L2Card[
ii][
jj][ll],
1091 HE_cluster_L2Card[
ii][
jj][ll],
1092 isolation_cluster_L2Card[
ii][
jj][ll],
1098 energy_cluster_L2Card[
ii][
jj][ll],
1104 is_looseTkiso&& is_looseTkss,
1107 std::map<std::string, float>
params;
1108 params[
"standaloneWP_showerShape"] = is_ss;
1109 params[
"standaloneWP_isolation"] = is_iso;
1110 params[
"trkMatchWP_showerShape"] = is_looseTkss;
1111 params[
"trkMatchWP_isolation"] = is_looseTkiso;
1114 cluster.setExperimentalParams(
params);
1115 L1EGXtalClusters->push_back(cluster);
1117 int standaloneWP = (
int)(is_iso && is_ss);
1118 int looseL1TkMatchWP = (
int)(is_looseTkiso && is_looseTkss);
1119 int photonWP = (
int)(is_photon);
1122 L1EGammas->push_back(
1123 0,
l1t::EGamma(p4calibrated, p4calibrated.pt(), p4calibrated.eta(), p4calibrated.phi(),
quality, 1));
1141 static float constexpr towerEtaUpperUnitialized = -80;
1142 static float constexpr towerPhiUpperUnitialized = -90;
1143 if (l1CaloTower.
towerEta() < towerEtaUpperUnitialized && l1CaloTower.
towerPhi() < towerPhiUpperUnitialized) {
1151 for (
const auto& l1eg : *L1EGXtalClusters) {
1152 if (l1eg.experimentalParam(
"TTiEta") != l1CaloTower.
towerIEta())
1154 if (l1eg.experimentalParam(
"TTiPhi") != l1CaloTower.
towerIPhi())
1157 int n_L1eg = l1CaloTower.
nL1eg();
1161 if (l1CaloTower.
nL1eg() > 1)
1163 l1CaloTower.
setL1egTrkSS(l1eg.experimentalParam(
"trkMatchWP_showerShape"));
1164 l1CaloTower.
setL1egTrkIso(l1eg.experimentalParam(
"trkMatchWP_isolation"));
1169 L1CaloTowers->push_back(l1CaloTower);