File indexing completed on 2024-04-06 12:21:01
0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002
0003 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConfiguration.h"
0004 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConstants.h"
0005 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0006 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/SubsystemTags.h"
0007 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/TPrimitives.h"
0008 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0009 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/CSCUtils.h"
0010
0011 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/CSCTPSelector.h"
0012
0013 using namespace emtf::phase2;
0014
0015 CSCTPSelector::CSCTPSelector(const EMTFContext& context, const int& endcap, const int& sector)
0016 : context_(context), endcap_(endcap), sector_(sector) {}
0017
0018 void CSCTPSelector::select(const TriggerPrimitive& tp, TPInfo tp_info, ILinkTPCMap& ilink_tpc_map) const {
0019 emtf_assert(tp.subsystem() == L1TMuon::kCSC);
0020
0021
0022 int ilink = getInputLink(tp, tp_info);
0023
0024
0025 if (ilink < 0) {
0026 return;
0027 }
0028
0029
0030 if (ilink_tpc_map[ilink].size() < 2) {
0031 ilink_tpc_map[ilink].emplace_back(tp, tp_info);
0032 } else {
0033 edm::LogWarning("L1TEMTFpp") << "\n******************* EMTF EMULATOR: SUPER-BIZZARE CASE *******************";
0034 edm::LogWarning("L1TEMTFpp") << "Found 3 CSC trigger primitives in the same chamber";
0035
0036 for (unsigned int i_tp = 0; i_tp < 3; i_tp++) {
0037 const auto& tp_err = ((i_tp < 2) ? ilink_tpc_map[ilink].at(i_tp).tp_ : tp);
0038
0039 edm::LogWarning("L1TEMTFpp") << "LCT #" << i_tp + 1 << ": BX " << tp_err.getBX() << ", endcap "
0040 << tp_err.detId<CSCDetId>().endcap() << ", sector "
0041 << tp_err.detId<CSCDetId>().triggerSector() << ", station "
0042 << tp_err.detId<CSCDetId>().station() << ", ring " << tp_err.detId<CSCDetId>().ring()
0043 << ", chamber " << tp_err.detId<CSCDetId>().chamber() << ", CSC ID "
0044 << tp_err.getCSCData().cscID << ": strip " << tp_err.getStrip() << ", wire "
0045 << tp_err.getWire();
0046 }
0047
0048 edm::LogWarning("L1TEMTFpp") << "************************* ONLY KEEP FIRST TWO *************************\n\n";
0049 }
0050 }
0051
0052
0053
0054
0055 int CSCTPSelector::getInputLink(const TriggerPrimitive& tp, TPInfo& tp_info) const {
0056 int ilink = -1;
0057
0058
0059 const int tp_endcap = tp_info.endcap;
0060 const int tp_sector = tp_info.sector;
0061 const int tp_subsector = tp_info.subsector;
0062 const int tp_station = tp_info.station;
0063 const int tp_ring = tp_info.ring;
0064 const int tp_csc_id = tp_info.csc_id;
0065
0066
0067 auto tp_selection = TPSelection::kNone;
0068
0069 if (csc::isTPInSector(endcap_, sector_, tp_endcap, tp_sector)) {
0070 tp_selection = TPSelection::kNative;
0071 } else if (this->context_.config_.include_neighbor_en_ &&
0072 csc::isTPInNeighborSector(endcap_, sector_, tp_endcap, tp_sector, tp_subsector, tp_station, tp_csc_id)) {
0073 tp_selection = TPSelection::kNeighbor;
0074 } else {
0075 return ilink;
0076 }
0077
0078
0079 ilink = calcInputLink(tp_subsector, tp_station, tp_ring, tp_csc_id, tp_selection);
0080
0081
0082 tp_info.ilink = ilink;
0083 tp_info.selection = tp_selection;
0084
0085 return ilink;
0086 }
0087
0088
0089 int CSCTPSelector::calcInputLink(const int& tp_subsector,
0090 const int& tp_station,
0091 const int& tp_ring,
0092 const int& tp_csc_id,
0093 const TPSelection& tp_selection) const {
0094 int ilink = -1;
0095
0096
0097
0098
0099
0100 if (tp_selection == TPSelection::kNative) {
0101 const int ilink_offset = 0;
0102
0103 if (tp_station == 1) {
0104 ilink = ilink_offset + (tp_subsector - 1) * 9 + (tp_csc_id - 1);
0105 } else {
0106 ilink = ilink_offset + tp_station * 9 + (tp_csc_id - 1);
0107 }
0108
0109 emtf_assert((0 <= ilink) && (ilink < 45));
0110 } else {
0111 const int ilink_offset = 45;
0112
0113 if (tp_station == 1) {
0114 ilink = ilink_offset + ((tp_station - 1) * 2) + (tp_csc_id - 1) / 3;
0115 } else if (tp_ring == 1) {
0116 ilink = ilink_offset + ((tp_station - 1) * 2) + 1;
0117 } else {
0118 ilink = ilink_offset + ((tp_station - 1) * 2) + 2;
0119 }
0120
0121 emtf_assert((45 <= ilink) && (ilink < 54));
0122 }
0123
0124 return ilink;
0125 }