Back to home page

Project CMSSW displayed by LXR

 
 

    


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/HitmapLayer.h"
0007 
0008 using namespace emtf::phase2::algo;
0009 
0010 HitmapLayer::HitmapLayer(const EMTFContext& context) : context_(context) {}
0011 
0012 void HitmapLayer::apply(const segment_collection_t& segments, std::vector<hitmap_t>& zone_hitmaps) const {
0013   const hitmap_row_t padded_one = 1;
0014 
0015   auto& model = context_.model_;
0016 
0017   // Create Images
0018   auto n_zones = model.zones_.size();
0019 
0020   for (unsigned int zone_id = 0; zone_id < n_zones; ++zone_id) {  // Begin zones
0021     unsigned int zone_mask = (1u << zone_id);
0022     unsigned int tzone_mask = (1u << 0);  // Only looking at BX=0 for now
0023 
0024     const auto& model_hm = model.zones_[zone_id].hitmap;
0025     auto& hitmap = zone_hitmaps.emplace_back();
0026     bool hitmap_is_blank = true;
0027 
0028     auto n_rows = model_hm.size();
0029 
0030     for (unsigned int row_id = 0; row_id < n_rows; ++row_id) {  // Begin loop rows
0031 
0032       const auto& model_hm_row = model_hm[row_id];
0033       auto& row = hitmap[row_id];
0034       row = 0;  // Clear Row Image
0035 
0036       for (const auto& model_hm_site : model_hm_row) {  // Begin loop sites in row
0037 
0038         for (const auto& model_hm_chamber : model_hm_site.chambers) {  // Begin loop chambers in site
0039 
0040           for (unsigned int i_ch_seg = 0; i_ch_seg < v3::kChamberSegments; ++i_ch_seg) {  // Begin loop segments
0041 
0042             const int seg_id = model_hm_chamber.id * v3::kChamberSegments + i_ch_seg;
0043             const auto& seg = segments[seg_id];
0044 
0045             // Short-Circuit: Must be valid
0046             if (seg.valid != 1) {
0047               continue;
0048             }
0049 
0050             // Short-Circuit: Must be same zone
0051             if ((seg.zones & zone_mask) != zone_mask) {
0052               // Debug Info
0053               if (this->context_.config_.verbosity_ > 4) {
0054                 edm::LogInfo("L1TEMTFpp")
0055                     << "Hitmap Segment not in zone: "
0056                     << " zone " << zone_id << " row " << row_id << " seg_id " << seg_id << " seg_phi " << seg.phi
0057                     << " seg_zones " << seg.zones << " seg_tzones " << seg.tzones << std::endl;
0058               }
0059 
0060               continue;
0061             }
0062 
0063             // Short-Circuit: Must be same timezone
0064             if ((seg.tzones & tzone_mask) != tzone_mask) {
0065               // Debug Info
0066               if (this->context_.config_.verbosity_ > 4) {
0067                 edm::LogInfo("L1TEMTFpp")
0068                     << "Hitmap Segment not in timezone: "
0069                     << " zone " << zone_id << " row " << row_id << " seg_id " << seg_id << " seg_phi " << seg.phi
0070                     << " seg_zones " << seg.zones << " seg_tzones " << seg.tzones << std::endl;
0071               }
0072 
0073               continue;
0074             }
0075 
0076             // Convert emtf_phi to col: truncate the last 4 bits, hence dividing by 16
0077             auto col_id = static_cast<unsigned int>(seg.phi >> v3::kHitmapColFactorLog2);
0078 
0079             // Debug Info
0080             // Seg col should be in the range specified by the model chamber
0081             if (this->context_.config_.verbosity_ > 4) {
0082               edm::LogInfo("L1TEMTFpp") << "Hitmap Segment Before Assert"
0083                                         << " zone " << zone_id << " row " << row_id << " col " << col_id << " seg_id "
0084                                         << seg_id << " seg_phi " << seg.phi << " seg_zones " << seg.zones
0085                                         << " seg_tzones " << seg.tzones << " ch_col_begin " << model_hm_chamber.begin
0086                                         << " ch_col_end " << model_hm_chamber.end << std::endl;
0087             }
0088 
0089             emtf_assert(model_hm_chamber.begin <= col_id && col_id < model_hm_chamber.end);
0090 
0091             // Short-Circuit: Joined chamber hitmap has more columns than the final image,
0092             // so we skip the columns outside of the final hitmaps's range
0093             // i.e. cropping the originl image
0094             if (!(v3::kHitmapCropColStart <= col_id && col_id < v3::kHitmapCropColStop)) {
0095               // Debug Info
0096               if (this->context_.config_.verbosity_ > 4) {
0097                 edm::LogInfo("L1TEMTFpp") << "Hitmap Segment out of bounds: "
0098                                           << " zone " << zone_id << " row " << row_id << " col " << col_id << " seg_id "
0099                                           << seg_id << " seg_phi " << seg.phi << " seg_zones " << seg.zones
0100                                           << " seg_tzones " << seg.tzones << std::endl;
0101               }
0102 
0103               continue;
0104             }
0105 
0106             // Adjust col_id so kHitmapCropColStart is col 0 in the image
0107             col_id -= v3::kHitmapCropColStart;
0108 
0109             // Calculate the 0-padded int for that column and or-it into the image
0110             hitmap_row_t col_mask = padded_one << col_id;
0111             row |= col_mask;
0112 
0113             // Debug Info
0114             if (this->context_.config_.verbosity_ > 1) {
0115               edm::LogInfo("L1TEMTFpp") << "Hitmap Segment"
0116                                         << " zone " << zone_id << " row " << row_id << " col " << col_id << " seg_id "
0117                                         << seg_id << " seg_phi " << seg.phi << " seg_zones " << seg.zones
0118                                         << " seg_tzones " << seg.tzones << std::endl;
0119             }
0120           }  // End loop segments
0121 
0122         }  // End loop chambers in site
0123 
0124       }  // End loop sites in row
0125 
0126       // Check if hitmap is blank
0127       if (hitmap_is_blank && row != 0) {
0128         hitmap_is_blank = false;
0129       }
0130     }  // End loop rows
0131 
0132     // Debug Info
0133     if (this->context_.config_.verbosity_ > 3) {
0134       // Short-Circuit: the image is blank
0135       if (hitmap_is_blank) {
0136         continue;
0137       }
0138 
0139       // Pretty print
0140       edm::LogInfo("L1TEMTFpp") << std::endl;
0141       edm::LogInfo("L1TEMTFpp") << "Zone " << zone_id << " Image" << std::endl;
0142 
0143       // Print rows in reverse order
0144       for (int row_id = (model_hm.size() - 1); 0 <= row_id; --row_id) {
0145         const auto& row = hitmap[row_id];
0146 
0147         edm::LogInfo("L1TEMTFpp") << row_id << " ";
0148 
0149         for (unsigned int col_id = 0; col_id < v3::kHitmapNCols; ++col_id) {
0150           hitmap_row_t pixel_mask = 1;
0151           pixel_mask = pixel_mask << col_id;
0152 
0153           bool is_present = (row & pixel_mask) == pixel_mask;
0154 
0155           if (is_present) {
0156             edm::LogInfo("L1TEMTFpp") << "X";
0157           } else {
0158             edm::LogInfo("L1TEMTFpp") << "-";
0159           }
0160         }
0161 
0162         edm::LogInfo("L1TEMTFpp") << std::endl;
0163       }
0164 
0165       edm::LogInfo("L1TEMTFpp") << std::endl;
0166     }
0167   }  // End loop zones
0168 }