File indexing completed on 2024-04-06 12:21:01
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/ConsumesCollector.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004
0005 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConfiguration.h"
0006 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConstants.h"
0007 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0008 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/TPrimitives.h"
0009 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/SubsystemTags.h"
0010 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0011
0012 #include "L1Trigger/L1TMuonEndCapPhase2/interface/DAQ/CSCTPCollector.h"
0013
0014 using namespace emtf::phase2;
0015
0016 CSCTPCollector::CSCTPCollector(const EMTFContext& context, edm::ConsumesCollector& i_consumes_collector)
0017 : context_(context),
0018 input_token_(i_consumes_collector.consumes<CSCTag::collection_type>(context.config_.csc_input_)) {}
0019
0020 void CSCTPCollector::collect(const edm::Event& i_event, BXTPCMap& bx_tpc_map) const {
0021 edm::Handle<CSCTag::collection_type> csc_digis;
0022 i_event.getByToken(input_token_, csc_digis);
0023
0024
0025 TPCollection tpc;
0026
0027 auto chamber = csc_digis->begin();
0028 auto chend = csc_digis->end();
0029
0030 for (; chamber != chend; ++chamber) {
0031 auto digi = (*chamber).second.first;
0032 auto dend = (*chamber).second.second;
0033
0034 for (; digi != dend; ++digi) {
0035 tpc.emplace_back((*chamber).first, *digi);
0036 }
0037 }
0038
0039
0040 std::map<std::pair<uint32_t, uint16_t>, std::vector<uint16_t> > chamber_wires_map;
0041
0042 for (auto& tp_entry : tpc) {
0043 const auto& tp_det_id = tp_entry.tp_.detId<CSCDetId>();
0044
0045 const CSCData& tp_data = tp_entry.tp_.getCSCData();
0046 const int tp_bx = tp_data.bx + this->context_.config_.csc_bx_shift_;
0047 const int tp_wire = tp_data.keywire;
0048
0049 auto key = std::make_pair(tp_det_id.rawId(), tp_bx);
0050 auto res = chamber_wires_map.find(key);
0051
0052 if (res == chamber_wires_map.end()) {
0053
0054 chamber_wires_map[key].push_back(tp_wire);
0055 } else {
0056
0057
0058 bool wire_found = false;
0059
0060 auto& chamber_wires = res->second;
0061
0062 for (const auto& a_wire : chamber_wires) {
0063
0064 if (a_wire == tp_wire) {
0065 wire_found = true;
0066 break;
0067 }
0068 }
0069
0070
0071 if (!wire_found) {
0072 chamber_wires.push_back(tp_wire);
0073 }
0074 }
0075 }
0076
0077
0078 for (auto& tp_entry : tpc) {
0079 const auto& tp_det_id = tp_entry.tp_.detId<CSCDetId>();
0080 const CSCData& tp_data = tp_entry.tp_.getCSCData();
0081
0082 const int tp_endcap = tp_det_id.endcap();
0083 const int tp_endcap_pm = (tp_endcap == 2) ? -1 : tp_endcap;
0084 const int tp_sector = tp_det_id.triggerSector();
0085 const int tp_station = tp_det_id.station();
0086 const int tp_ring = tp_det_id.ring();
0087 const int tp_chamber = tp_det_id.chamber();
0088 const int tp_layer = tp_det_id.layer();
0089
0090 const int tp_csc_id = tp_data.cscID;
0091
0092 const int tp_bx = tp_data.bx + this->context_.config_.csc_bx_shift_;
0093
0094
0095 int tp_wire1 = tp_data.keywire;
0096 int tp_wire2 = -1;
0097
0098 auto tp_wire_key = std::make_pair(tp_det_id.rawId(), tp_bx);
0099 const auto& tp_wires = chamber_wires_map.at(tp_wire_key);
0100
0101 emtf_assert((!tp_wires.empty()) && (tp_wires.size() <= 2));
0102
0103 if (tp_wires.size() > 1) {
0104 tp_wire1 = tp_wires.at(0);
0105 tp_wire2 = tp_wires.at(1);
0106 }
0107
0108
0109 const int tp_subsector = csc::getTriggerSubsector(tp_station, tp_chamber);
0110 const auto tp_face_dir = csc::getFaceDirection(tp_station, tp_ring, tp_chamber);
0111
0112
0113 const auto& [max_strip, max_wire] = csc::getMaxStripAndWire(tp_station, tp_ring);
0114 const auto& [max_pattern, max_quality] = csc::getMaxPatternAndQuality(tp_station, tp_ring);
0115
0116 emtf_assert(kMinEndcap <= tp_endcap && tp_endcap <= kMaxEndcap);
0117 emtf_assert(kMinTrigSector <= tp_sector && tp_sector <= kMaxTrigSector);
0118 emtf_assert((0 <= tp_subsector) and (tp_subsector <= 2));
0119 emtf_assert(1 <= tp_station && tp_station <= 4);
0120 emtf_assert(1 <= tp_ring && tp_ring <= 4);
0121 emtf_assert(1 <= tp_chamber && tp_chamber <= 36);
0122 emtf_assert(1 <= tp_csc_id && tp_csc_id <= 9);
0123 emtf_assert(tp_data.strip < max_strip);
0124 emtf_assert(tp_data.keywire < max_wire);
0125 emtf_assert(tp_data.pattern < max_pattern);
0126 emtf_assert(0 < tp_data.quality && tp_data.quality < max_quality);
0127 emtf_assert(tp_data.valid);
0128
0129
0130
0131 if (!(tp_data.strip < max_strip)) {
0132 edm::LogWarning("L1TEMTFpp") << "Found error in LCT strip: " << tp_data.strip << " (allowed range: 0-"
0133 << max_strip - 1 << ").";
0134
0135 edm::LogWarning("L1TEMTFpp")
0136 << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
0137 << tp_ring << ", cscid " << tp_csc_id
0138 << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
0139
0140 continue;
0141 }
0142
0143 if (!(tp_data.keywire < max_wire)) {
0144 edm::LogWarning("L1TEMTFpp") << "Found error in LCT wire: " << tp_data.keywire << " (allowed range: 0-"
0145 << max_wire - 1 << ").";
0146
0147 edm::LogWarning("L1TEMTFpp")
0148 << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
0149 << tp_ring << ", cscid " << tp_csc_id
0150 << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
0151
0152 continue;
0153 }
0154
0155 if (!(tp_data.valid == true)) {
0156 edm::LogWarning("L1TEMTFpp") << "Found error in LCT valid: " << tp_data.valid << " (allowed value: 1).";
0157
0158 edm::LogWarning("L1TEMTFpp")
0159 << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
0160 << tp_ring << ", cscid " << tp_csc_id
0161 << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
0162
0163 continue;
0164 }
0165
0166 if (!(tp_data.pattern < max_pattern)) {
0167 edm::LogWarning("L1TEMTFpp") << "Found error in LCT pattern: " << tp_data.pattern << " (allowed range: 0-"
0168 << max_pattern - 1 << ").";
0169
0170 edm::LogWarning("L1TEMTFpp")
0171 << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
0172 << tp_ring << ", cscid " << tp_csc_id
0173 << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
0174
0175 continue;
0176 }
0177
0178 if (!(0 < tp_data.quality && tp_data.quality < max_quality)) {
0179 edm::LogWarning("L1TEMTFpp") << "Found error in LCT quality: " << tp_data.quality << " (allowed range: 1-"
0180 << max_quality - 1 << ").";
0181
0182 edm::LogWarning("L1TEMTFpp")
0183 << "From endcap " << tp_endcap << ", sector " << tp_sector << ", station " << tp_station << ", ring "
0184 << tp_ring << ", cscid " << tp_csc_id
0185 << ". (Note that this LCT may be reported multiple times. See source code for explanations.)";
0186
0187 continue;
0188 }
0189
0190
0191 tp_entry.info_.bx = tp_bx;
0192
0193 tp_entry.info_.endcap = tp_endcap;
0194 tp_entry.info_.endcap_pm = tp_endcap_pm;
0195 tp_entry.info_.sector = tp_sector;
0196 tp_entry.info_.subsector = tp_subsector;
0197 tp_entry.info_.station = tp_station;
0198 tp_entry.info_.ring = tp_ring;
0199 tp_entry.info_.chamber = tp_chamber;
0200 tp_entry.info_.layer = tp_layer;
0201
0202 tp_entry.info_.csc_id = tp_csc_id;
0203 tp_entry.info_.csc_facing = tp_face_dir;
0204 tp_entry.info_.csc_first_wire = tp_wire1;
0205 tp_entry.info_.csc_second_wire = tp_wire2;
0206
0207 bx_tpc_map[tp_bx].push_back(tp_entry);
0208 }
0209 }