CMS 3D CMS Logo

HitmapLayer.cc
Go to the documentation of this file.
2 
5 
7 
8 using namespace emtf::phase2::algo;
9 
11 
12 void HitmapLayer::apply(const segment_collection_t& segments, std::vector<hitmap_t>& zone_hitmaps) const {
13  const hitmap_row_t padded_one = 1;
14 
15  auto& model = context_.model_;
16 
17  // Create Images
18  auto n_zones = model.zones_.size();
19 
20  for (unsigned int zone_id = 0; zone_id < n_zones; ++zone_id) { // Begin zones
21  unsigned int zone_mask = (1u << zone_id);
22  unsigned int tzone_mask = (1u << 0); // Only looking at BX=0 for now
23 
24  const auto& model_hm = model.zones_[zone_id].hitmap;
25  auto& hitmap = zone_hitmaps.emplace_back();
26  bool hitmap_is_blank = true;
27 
28  auto n_rows = model_hm.size();
29 
30  for (unsigned int row_id = 0; row_id < n_rows; ++row_id) { // Begin loop rows
31 
32  const auto& model_hm_row = model_hm[row_id];
33  auto& row = hitmap[row_id];
34  row = 0; // Clear Row Image
35 
36  for (const auto& model_hm_site : model_hm_row) { // Begin loop sites in row
37 
38  for (const auto& model_hm_chamber : model_hm_site.chambers) { // Begin loop chambers in site
39 
40  for (unsigned int i_ch_seg = 0; i_ch_seg < v3::kChamberSegments; ++i_ch_seg) { // Begin loop segments
41 
42  const int seg_id = model_hm_chamber.id * v3::kChamberSegments + i_ch_seg;
43  const auto& seg = segments[seg_id];
44 
45  // Short-Circuit: Must be valid
46  if (seg.valid != 1) {
47  continue;
48  }
49 
50  // Short-Circuit: Must be same zone
51  if ((seg.zones & zone_mask) != zone_mask) {
52  // Debug Info
53  if (this->context_.config_.verbosity_ > 4) {
54  edm::LogInfo("L1TEMTFpp")
55  << "Hitmap Segment not in zone: "
56  << " zone " << zone_id << " row " << row_id << " seg_id " << seg_id << " seg_phi " << seg.phi
57  << " seg_zones " << seg.zones << " seg_tzones " << seg.tzones << std::endl;
58  }
59 
60  continue;
61  }
62 
63  // Short-Circuit: Must be same timezone
64  if ((seg.tzones & tzone_mask) != tzone_mask) {
65  // Debug Info
66  if (this->context_.config_.verbosity_ > 4) {
67  edm::LogInfo("L1TEMTFpp")
68  << "Hitmap Segment not in timezone: "
69  << " zone " << zone_id << " row " << row_id << " seg_id " << seg_id << " seg_phi " << seg.phi
70  << " seg_zones " << seg.zones << " seg_tzones " << seg.tzones << std::endl;
71  }
72 
73  continue;
74  }
75 
76  // Convert emtf_phi to col: truncate the last 4 bits, hence dividing by 16
77  auto col_id = static_cast<unsigned int>(seg.phi >> v3::kHitmapColFactorLog2);
78 
79  // Debug Info
80  // Seg col should be in the range specified by the model chamber
81  if (this->context_.config_.verbosity_ > 4) {
82  edm::LogInfo("L1TEMTFpp") << "Hitmap Segment Before Assert"
83  << " zone " << zone_id << " row " << row_id << " col " << col_id << " seg_id "
84  << seg_id << " seg_phi " << seg.phi << " seg_zones " << seg.zones
85  << " seg_tzones " << seg.tzones << " ch_col_begin " << model_hm_chamber.begin
86  << " ch_col_end " << model_hm_chamber.end << std::endl;
87  }
88 
89  emtf_assert(model_hm_chamber.begin <= col_id && col_id < model_hm_chamber.end);
90 
91  // Short-Circuit: Joined chamber hitmap has more columns than the final image,
92  // so we skip the columns outside of the final hitmaps's range
93  // i.e. cropping the originl image
94  if (!(v3::kHitmapCropColStart <= col_id && col_id < v3::kHitmapCropColStop)) {
95  // Debug Info
96  if (this->context_.config_.verbosity_ > 4) {
97  edm::LogInfo("L1TEMTFpp") << "Hitmap Segment out of bounds: "
98  << " zone " << zone_id << " row " << row_id << " col " << col_id << " seg_id "
99  << seg_id << " seg_phi " << seg.phi << " seg_zones " << seg.zones
100  << " seg_tzones " << seg.tzones << std::endl;
101  }
102 
103  continue;
104  }
105 
106  // Adjust col_id so kHitmapCropColStart is col 0 in the image
107  col_id -= v3::kHitmapCropColStart;
108 
109  // Calculate the 0-padded int for that column and or-it into the image
110  hitmap_row_t col_mask = padded_one << col_id;
111  row |= col_mask;
112 
113  // Debug Info
114  if (this->context_.config_.verbosity_ > 1) {
115  edm::LogInfo("L1TEMTFpp") << "Hitmap Segment"
116  << " zone " << zone_id << " row " << row_id << " col " << col_id << " seg_id "
117  << seg_id << " seg_phi " << seg.phi << " seg_zones " << seg.zones
118  << " seg_tzones " << seg.tzones << std::endl;
119  }
120  } // End loop segments
121 
122  } // End loop chambers in site
123 
124  } // End loop sites in row
125 
126  // Check if hitmap is blank
127  if (hitmap_is_blank && row != 0) {
128  hitmap_is_blank = false;
129  }
130  } // End loop rows
131 
132  // Debug Info
133  if (this->context_.config_.verbosity_ > 3) {
134  // Short-Circuit: the image is blank
135  if (hitmap_is_blank) {
136  continue;
137  }
138 
139  // Pretty print
140  edm::LogInfo("L1TEMTFpp") << std::endl;
141  edm::LogInfo("L1TEMTFpp") << "Zone " << zone_id << " Image" << std::endl;
142 
143  // Print rows in reverse order
144  for (int row_id = (model_hm.size() - 1); 0 <= row_id; --row_id) {
145  const auto& row = hitmap[row_id];
146 
147  edm::LogInfo("L1TEMTFpp") << row_id << " ";
148 
149  for (unsigned int col_id = 0; col_id < v3::kHitmapNCols; ++col_id) {
150  hitmap_row_t pixel_mask = 1;
151  pixel_mask = pixel_mask << col_id;
152 
153  bool is_present = (row & pixel_mask) == pixel_mask;
154 
155  if (is_present) {
156  edm::LogInfo("L1TEMTFpp") << "X";
157  } else {
158  edm::LogInfo("L1TEMTFpp") << "-";
159  }
160  }
161 
162  edm::LogInfo("L1TEMTFpp") << std::endl;
163  }
164 
165  edm::LogInfo("L1TEMTFpp") << std::endl;
166  }
167  } // End loop zones
168 }
HitmapLayer(const EMTFContext &)
Definition: HitmapLayer.cc:10
const EMTFContext & context_
Definition: HitmapLayer.h:18
constexpr int kHitmapNCols
Definition: EMTFConstants.h:48
void apply(const segment_collection_t &, std::vector< hitmap_t > &) const
Definition: HitmapLayer.cc:12
constexpr int kHitmapCropColStart
Definition: EMTFConstants.h:52
Log< level::Info, false > LogInfo
constexpr int kChamberSegments
Definition: EMTFConstants.h:29
#define emtf_assert(expr)
Definition: DebugTools.h:18
constexpr int kHitmapColFactorLog2
Definition: EMTFConstants.h:51
ap_uint< v3::kHitmapNCols > hitmap_row_t
Definition: EMTFTypes.h:145
constexpr int kHitmapCropColStop
Definition: EMTFConstants.h:53
EMTFConfiguration config_
Definition: EMTFContext.h:39
std::array< segment_t, v3::kNumSegments > segment_collection_t
Definition: EMTFTypes.h:93