File indexing completed on 2024-04-06 12:21:01
0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002
0003 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0004 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Utils/DebugUtils.h"
0005
0006 #include "L1Trigger/L1TMuonEndCapPhase2/interface/Algo/PatternMatchingLayer.h"
0007
0008 using namespace emtf::phase2::algo;
0009
0010 PatternMatchingLayer::PatternMatchingLayer(const EMTFContext& context) : context_(context) {}
0011
0012 void PatternMatchingLayer::apply(const std::vector<hitmap_t>& zone_hitmaps,
0013 const bool& displaced_en,
0014 std::vector<road_collection_t>& zone_roads) const {
0015 typedef ap_uint<v3::kHitmapNCols + v3::kPatternMatchingPadding * 2> padded_row_t;
0016 typedef ap_uint<v3::kHitmapNRows> pattern_activation_t;
0017 typedef std::array<pattern_activation_t, v3::kHitmapNCols> pattern_activation_collection_t;
0018
0019 const padded_row_t padded_one = 1;
0020
0021 auto& model = context_.model_;
0022
0023 for (unsigned int i_zone = 0; i_zone < zone_hitmaps.size(); ++i_zone) {
0024 auto& hitmap = zone_hitmaps[i_zone];
0025 auto* model_pc = &(model.zones_[i_zone].prompt_patterns);
0026 auto* model_ql = &(model.zones_[i_zone].prompt_quality_lut);
0027
0028 if (displaced_en) {
0029 model_pc = &(model.zones_[i_zone].disp_patterns);
0030 model_ql = &(model.zones_[i_zone].disp_quality_lut);
0031 }
0032
0033
0034 auto& roads = zone_roads.emplace_back();
0035
0036 for (unsigned int i_col = 0; i_col < v3::kHitmapNCols; ++i_col) {
0037 roads[i_col].pattern = 0;
0038 roads[i_col].quality = 0;
0039 }
0040
0041
0042 for (unsigned int i_pattern = 0; i_pattern < model_pc->size(); ++i_pattern) {
0043 auto& model_pat = (*model_pc)[i_pattern];
0044
0045
0046 pattern_activation_collection_t pac;
0047
0048 for (unsigned int i_col = 0; i_col < v3::kHitmapNCols; ++i_col) {
0049 pac[i_col] = 0;
0050 }
0051
0052
0053 for (unsigned int i_row = 0; i_row < v3::kHitmapNRows; ++i_row) {
0054
0055
0056 const auto& hitmap_row = hitmap[i_row];
0057 auto& model_pat_row = model_pat[i_row];
0058
0059
0060
0061
0062
0063
0064 padded_row_t padded_hm_row = hitmap_row;
0065 padded_hm_row = padded_hm_row << v3::kPatternMatchingPadding;
0066
0067
0068 padded_row_t padded_pat_row = 0;
0069
0070 unsigned int offset = model_pat_row.begin;
0071
0072 unsigned int bw = model_pat_row.end - model_pat_row.begin + 1;
0073
0074 for (unsigned int i_bit = 0; i_bit < bw; ++i_bit)
0075 padded_pat_row |= (padded_one << (offset + i_bit));
0076
0077
0078 for (unsigned int i_col = 0; i_col < v3::kHitmapNCols; ++i_col) {
0079
0080
0081 padded_row_t result = padded_pat_row & padded_hm_row;
0082
0083 if (result > 0)
0084 pac[i_col] = pac[i_col] | (1 << i_row);
0085
0086
0087 padded_pat_row = padded_pat_row << 1;
0088 }
0089 }
0090
0091
0092
0093
0094
0095
0096
0097 for (unsigned int i_col = 0; i_col < v3::kHitmapNCols; ++i_col) {
0098 auto& activation = pac[i_col];
0099 auto quality = (*model_ql)[activation];
0100
0101 auto& current_road = roads[i_col];
0102
0103 if (current_road.quality < quality) {
0104 current_road.pattern = i_pattern;
0105 current_road.quality = quality;
0106 }
0107 }
0108 }
0109
0110
0111 if (this->context_.config_.verbosity_ > 1) {
0112 for (unsigned int i_col = 0; i_col < v3::kHitmapNCols; ++i_col) {
0113 if (roads[i_col].quality == 0) {
0114 continue;
0115 }
0116
0117 edm::LogInfo("L1TEMTFpp") << "Road"
0118 << " zone " << i_zone << " col " << i_col << " pat " << roads[i_col].pattern
0119 << " qual " << roads[i_col].quality << std::endl;
0120 }
0121 }
0122 }
0123 }