CMS 3D CMS Logo

EMTFBlockSP.cc
Go to the documentation of this file.
1 // Code to unpack the "SP Output Data Record"
2 
4 
5 #include "EMTFCollections.h"
6 #include "EMTFUnpackerTools.h"
7 
8 // This is the "header" - no EMTFBlockSP.h file is needed
9 namespace l1t {
10  namespace stage2 {
11  namespace emtf {
12 
13  class SPBlockUnpacker : public Unpacker { // "SPBlockUnpacker" inherits from "Unpacker"
14  public:
15  virtual int checkFormat(const Block& block);
16  bool unpack(const Block& block,
17  UnpackerCollections* coll) override; // Apparently it's always good to use override in C++
18  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
19  };
20 
21  // class SPBlockPacker : public Packer { // "SPBlockPacker" inherits from "Packer"
22  // public:
23  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
24  // };
25 
26  } // namespace emtf
27  } // namespace stage2
28 } // namespace l1t
29 
30 namespace l1t {
31  namespace stage2 {
32  namespace emtf {
33 
35  auto payload = block.payload();
36  int errors = 0;
37 
38  // Check the number of 16-bit words
39  if (payload.size() != 8) {
40  errors += 1;
41  edm::LogError("L1T|EMTF") << "Payload size in 'SP Output Data Record' is different than expected";
42  }
43 
44  // Check that each word is 16 bits
45  for (unsigned int i = 0; i < 8; i++) {
46  if (GetHexBits(payload[i], 16, 31) != 0) {
47  errors += 1;
48  edm::LogError("L1T|EMTF") << "Payload[" << i << "] has more than 16 bits in 'SP Output Data Record'";
49  }
50  }
51 
52  uint16_t SP1a = payload[0];
53  uint16_t SP1b = payload[1];
54  uint16_t SP1c = payload[2];
55  uint16_t SP1d = payload[3];
56  uint16_t SP2a = payload[4];
57  uint16_t SP2b = payload[5];
58  uint16_t SP2c = payload[6];
59  uint16_t SP2d = payload[7];
60 
61  // Check Format
62  if (GetHexBits(SP1a, 15, 15) != 1) {
63  errors += 1;
64  edm::LogError("L1T|EMTF") << "Format identifier bits in SP1a are incorrect";
65  }
66  if (GetHexBits(SP1b, 15, 15) != 0) {
67  errors += 1;
68  edm::LogError("L1T|EMTF") << "Format identifier bits in SP1b are incorrect";
69  }
70  if (GetHexBits(SP1c, 15, 15) != 1) {
71  errors += 1;
72  edm::LogError("L1T|EMTF") << "Format identifier bits in SP1c are incorrect";
73  }
74  if (GetHexBits(SP1d, 15, 15) != 0) {
75  errors += 1;
76  edm::LogError("L1T|EMTF") << "Format identifier bits in SP1d are incorrect";
77  }
78  if (GetHexBits(SP2a, 15, 15) != 0) {
79  errors += 1;
80  edm::LogError("L1T|EMTF") << "Format identifier bits in SP2a are incorrect";
81  }
82  if (GetHexBits(SP2b, 15, 15) != 1) {
83  errors += 1;
84  edm::LogError("L1T|EMTF") << "Format identifier bits in SP2b are incorrect";
85  }
86  if (GetHexBits(SP2c, 15, 15) != 1) {
87  errors += 1;
88  edm::LogError("L1T|EMTF") << "Format identifier bits in SP2c are incorrect";
89  }
90  if (GetHexBits(SP2d, 15, 15) != 0) {
91  errors += 1;
92  edm::LogError("L1T|EMTF") << "Format identifier bits in SP2d are incorrect";
93  }
94 
95  return errors;
96  }
97 
98  // Converts CSC_ID, sector, subsector, and neighbor
99  std::vector<int> convert_SP_location(int _csc_ID, int _sector, int _subsector, int _station) {
100  int new_sector = _sector;
101  if (_station == 1) {
102  if (_csc_ID < 0) {
103  int arr[] = {_csc_ID, -99, -99, -99};
104  std::vector<int> vec(arr, arr + 4);
105  return vec;
106  } else if (_csc_ID == 0) {
107  int arr[] = {-1, -1, -1, -1};
108  std::vector<int> vec(arr, arr + 4);
109  return vec;
110  } else if (_csc_ID <= 9) {
111  int arr[] = {_csc_ID, new_sector, _subsector + 1, 0};
112  std::vector<int> vec(arr, arr + 4);
113  return vec;
114  } else
115  new_sector = (_sector != 1) ? _sector - 1 : 6;
116 
117  if (_csc_ID == 10) {
118  int arr[] = {3, new_sector, 2, 1};
119  std::vector<int> vec(arr, arr + 4);
120  return vec;
121  } else if (_csc_ID == 11) {
122  int arr[] = {6, new_sector, 2, 1};
123  std::vector<int> vec(arr, arr + 4);
124  return vec;
125  } else if (_csc_ID == 12) {
126  int arr[] = {9, new_sector, 2, 1};
127  std::vector<int> vec(arr, arr + 4);
128  return vec;
129  } else {
130  int arr[] = {_csc_ID, -99, -99, -99};
131  std::vector<int> vec(arr, arr + 4);
132  return vec;
133  }
134  } else if (_station == 2 || _station == 3 || _station == 4) {
135  if (_csc_ID < 0) {
136  int arr[] = {_csc_ID, -99, -99, -99};
137  std::vector<int> vec(arr, arr + 4);
138  return vec;
139  } else if (_csc_ID == 0) {
140  int arr[] = {-1, -1, -1, -1};
141  std::vector<int> vec(arr, arr + 4);
142  return vec;
143  } else if (_csc_ID <= 9) {
144  int arr[] = {_csc_ID, new_sector, -1, 0};
145  std::vector<int> vec(arr, arr + 4);
146  return vec;
147  } else
148  new_sector = (_sector != 1) ? _sector - 1 : 6;
149 
150  if (_csc_ID == 10) {
151  int arr[] = {3, new_sector, -1, 1};
152  std::vector<int> vec(arr, arr + 4);
153  return vec;
154  } else if (_csc_ID == 11) {
155  int arr[] = {9, new_sector, -1, 1};
156  std::vector<int> vec(arr, arr + 4);
157  return vec;
158  } else {
159  int arr[] = {_csc_ID, -99, -99, -99};
160  std::vector<int> vec(arr, arr + 4);
161  return vec;
162  }
163  } else {
164  int arr[] = {-99, -99, -99, -99};
165  std::vector<int> vec(arr, arr + 4);
166  return vec;
167  }
168  }
169 
171  // std::cout << "Inside EMTFBlockSP.cc: unpack" << std::endl;
172  // LogDebug("L1T|EMTF") << "Inside EMTFBlockSP.cc: unpack"; // Why doesn't this work? - AWB 09.04.16
173 
174  // Get the payload for this block, made up of 16-bit words (0xffff)
175  // Format defined in MTF7Payload::getBlock() in src/Block.cc
176  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
177  auto payload = block.payload();
178 
179  // FW version is computed as (Year - 2000)*2^9 + Month*2^5 + Day (see Block.cc and EMTFBlockTrailers.cc)
180  bool useNNBits_ = getAlgoVersion() >= 11098; // FW versions >= 26.10.2021
181  bool useMUSBits_ = getAlgoVersion() >= 11306; // FW versions >= 10.01.2022
182  bool reducedDAQWindow =
183  (getAlgoVersion() >=
184  11656); // Firmware from 08.12.22 which is used as a flag for new reduced readout window - EY 01.03.23
185 
186  static constexpr int looseShower_ = 1;
187  static constexpr int nominalShower_ = 2;
188  static constexpr int tightShower_ = 4;
189 
190  // Check Format of Payload
191  l1t::emtf::SP SP_;
192  for (int err = 0; err < checkFormat(block); err++)
193  SP_.add_format_error();
194 
195  // Assign payload to 16-bit words
196  uint16_t SP1a = payload[0];
197  uint16_t SP1b = payload[1];
198  uint16_t SP1c = payload[2];
199  uint16_t SP1d = payload[3];
200  uint16_t SP2a = payload[4];
201  uint16_t SP2b = payload[5];
202  uint16_t SP2c = payload[6];
203  uint16_t SP2d = payload[7];
204 
205  // res is a pointer to a collection of EMTFDaqOut class objects
206  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
208  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
209  int iOut = res->size() - 1;
210  std::vector<int> conv_vals_SP;
211  std::vector<int> conv_vals_pT_LUT;
212 
213  EMTFHitCollection* res_hit;
214  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
215 
216  EMTFTrackCollection* res_track;
217  res_track = static_cast<EMTFCollections*>(coll)->getEMTFTracks();
218  EMTFTrack Track_;
219 
221  res_cand = static_cast<EMTFCollections*>(coll)->getRegionalMuonCands();
222  RegionalMuonCand mu_(0, 0, 0, 0, 0, 0, 0, tftype::emtf_pos);
223 
224  RegionalMuonShowerBxCollection* res_shower;
225  res_shower = static_cast<EMTFCollections*>(coll)->getRegionalMuonShowers();
226  RegionalMuonShower muShower_(false, false, false, false, false, false);
227 
229  // Unpack the SP Output Data Record
231 
232  SP_.set_phi_full(GetHexBits(SP1a, 0, 12));
233  SP_.set_c(GetHexBits(SP1a, 13, 13));
234  SP_.set_hl(GetHexBits(SP1a, 14, 14));
235 
236  SP_.set_phi_GMT(TwosCompl(8, GetHexBits(SP1b, 0, 7)));
237  SP_.set_quality_GMT(GetHexBits(SP1b, 8, 11));
238  SP_.set_bc0(GetHexBits(SP1b, 12, 12));
239  SP_.set_vc(GetHexBits(SP1b, 14, 14));
240 
241  SP_.set_eta_GMT(TwosCompl(9, GetHexBits(SP1c, 0, 8)));
242  SP_.set_mode(GetHexBits(SP1c, 9, 12));
243 
244  if (useMUSBits_) {
245  SP_.set_mus(GetHexBits(SP1b, 13, 13, SP1c, 13, 14));
246  } else {
247  SP_.set_se(GetHexBits(SP1b, 13, 13));
248  SP_.set_bx(GetHexBits(SP1c, 13, 14));
249  }
250 
251  SP_.set_pt_GMT(GetHexBits(SP1d, 0, 8));
252  SP_.set_me1_stub_num(GetHexBits(SP1d, 9, 9));
253  SP_.set_me1_CSC_ID(GetHexBits(SP1d, 10, 13));
254  SP_.set_me1_subsector(GetHexBits(SP1d, 14, 14));
255 
256  SP_.set_me2_stub_num(GetHexBits(SP2a, 0, 0));
257  SP_.set_me2_CSC_ID(GetHexBits(SP2a, 1, 4));
258  SP_.set_me3_stub_num(GetHexBits(SP2a, 5, 5));
259  SP_.set_me3_CSC_ID(GetHexBits(SP2a, 6, 9));
260  SP_.set_me4_stub_num(GetHexBits(SP2a, 10, 10));
261  SP_.set_me4_CSC_ID(GetHexBits(SP2a, 11, 14));
262 
263  SP_.set_me1_delay(GetHexBits(SP2b, 0, 2));
264  SP_.set_me2_delay(GetHexBits(SP2b, 3, 5));
265  SP_.set_me3_delay(GetHexBits(SP2b, 6, 8));
266  SP_.set_me4_delay(GetHexBits(SP2b, 9, 11));
267  if (reducedDAQWindow) // reduced DAQ window is used only after run3 DAQ format
268  SP_.set_tbin(GetHexBits(SP2b, 12, 14) + 1);
269  else
270  SP_.set_tbin(GetHexBits(SP2b, 12, 14));
271 
272  if (useNNBits_) {
273  SP_.set_pt_dxy_GMT(GetHexBits(SP2c, 0, 7));
274  SP_.set_dxy_GMT(GetHexBits(SP2c, 8, 10));
275  SP_.set_nn_pt_valid(GetHexBits(SP2c, 11, 11));
276  } else {
277  SP_.set_pt_LUT_addr(GetHexBits(SP2c, 0, 14, SP2d, 0, 14));
278  }
279 
280  // SP_.set_dataword ( uint64_t dataword );
281 
282  ImportSP(Track_, SP_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector());
283  // Track_.ImportPtLUT( Track_.Mode(), Track_.Pt_LUT_addr() ); // Deprecated ... replace? - AWB 15.03.17
284 
285  if (!(res->at(iOut)).PtrSPCollection()->empty())
286  if (SP_.TBIN() == (res->at(iOut)).PtrSPCollection()->at((res->at(iOut)).PtrSPCollection()->size() - 1).TBIN())
287  Track_.set_track_num((res->at(iOut)).PtrSPCollection()->size());
288  else
289  Track_.set_track_num(0);
290  else
291  Track_.set_track_num(0);
292 
293  // For single-LCT tracks, "Track_num" = 2 (last in collection)
294  if (SP_.Quality_GMT() == 0)
295  Track_.set_track_num(2);
296 
297  mu_.setHwSign(SP_.C());
298  mu_.setHwSignValid(SP_.VC());
299  mu_.setHwQual(SP_.Quality_GMT());
300  mu_.setHwEta(SP_.Eta_GMT());
301  mu_.setHwPhi(SP_.Phi_GMT());
302  mu_.setHwPt(SP_.Pt_GMT());
303  if (useNNBits_) {
304  mu_.setHwPtUnconstrained(SP_.Pt_dxy_GMT());
305  mu_.setHwDXY(SP_.Dxy_GMT());
306  }
307  mu_.setTFIdentifiers(Track_.Sector() - 1, (Track_.Endcap() == 1) ? emtf_pos : emtf_neg);
309  // Truncated to 11 bits and offset by 25 from global event BX in EMTF firmware
310  int EMTF_kBX = ((res->at(iOut)).PtrEventHeader()->L1A_BXN() % 2048) - 25 + Track_.BX();
311  if (EMTF_kBX < 0)
312  EMTF_kBX += 2048;
314  // mu_.set_dataword ( SP_.Dataword() );
315  // Track_.set_GMT(mu_);
316 
317  // Set Regional Muon Showers
318  if (useMUSBits_) {
319  muShower_.setTFIdentifiers(Track_.Sector() - 1, (Track_.Endcap() == 1) ? emtf_pos : emtf_neg);
320  muShower_.setOneLooseInTime(SP_.MUS() >= looseShower_ ? true : false);
321  muShower_.setOneNominalInTime(SP_.MUS() >= nominalShower_ ? true : false);
322  muShower_.setOneTightInTime(SP_.MUS() >= tightShower_ ? true : false);
323  }
324 
326  // Match hits to tracks
328 
329  // Find the track delay
330  int nDelay[3] = {0, 0, 0}; // Number of hits in the track with delay 0, 1, or 2
331  if (Track_.Mode() >= 8)
332  nDelay[SP_.ME1_delay()] += 1;
333  if ((Track_.Mode() % 8) >= 4)
334  nDelay[SP_.ME2_delay()] += 1;
335  if ((Track_.Mode() % 4) >= 2)
336  nDelay[SP_.ME3_delay()] += 1;
337  if ((Track_.Mode() % 2) == 1)
338  nDelay[SP_.ME4_delay()] += 1;
339 
340  int trk_delay = -99;
341  // Assume 2nd-earliest LCT configuration
342  if (nDelay[2] >= 2)
343  trk_delay = 2;
344  else if (nDelay[2] + nDelay[1] >= 2)
345  trk_delay = 1;
346  else if (nDelay[2] + nDelay[1] + nDelay[0] >= 2)
347  trk_delay = 0;
348 
349  // // For earliest LCT configuration
350  // if (nDelay[2] >= 1) trk_delay = 2;
351  // else if (nDelay[2] + nDelay[1] >= 1) trk_delay = 1;
352  // else if (nDelay[2] + nDelay[1] + nDelay[0] >= 1) trk_delay = 0;
353 
354  // Reverse 'rotate by 2' to get CPPF subsector number
355  auto get_subsector_rpc_cppf = [](int subsector_rpc) { return ((subsector_rpc + 3) % 6) + 1; };
356 
357  std::array<int, 4> St_hits{{0, 0, 0, 0}}; // Number of matched hits in each station
358 
359  for (auto const& Hit : *res_hit) {
360  if (Track_.Mode() == 1)
361  continue; // Special case dealt with later
362  if (Hit.Endcap() != Track_.Endcap())
363  continue;
364 
365  int hit_delay = -99;
366  if (Hit.Station() == 1)
367  hit_delay = SP_.ME1_delay();
368  else if (Hit.Station() == 2)
369  hit_delay = SP_.ME2_delay();
370  else if (Hit.Station() == 3)
371  hit_delay = SP_.ME3_delay();
372  else if (Hit.Station() == 4)
373  hit_delay = SP_.ME4_delay();
374 
375  // Require exact matching according to TBIN and delays
376  if (Hit.BX() + 3 + hit_delay != SP_.TBIN() + trk_delay)
377  continue;
378 
379  // Match hit in station 1
380  conv_vals_SP =
381  convert_SP_location(SP_.ME1_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), SP_.ME1_subsector(), 1);
382 
383  if (Hit.Station() == 1 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
384  Hit.Stub_num() == SP_.ME1_stub_num()) {
385  if (Hit.Is_CSC() == 1 && (Hit.CSC_ID() != conv_vals_SP.at(0) || Hit.Subsector() != conv_vals_SP.at(2)))
386  continue;
387 
388  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
389  int RPC_subsector = ((tmp_subsector - 1) / 3) + 1; // Map RPC subsector to equivalent CSC subsector
390  int RPC_CSC_ID = ((tmp_subsector - 1) % 3) + 4; // Map RPC subsector and ring to equivalent CSC ID
391 
392  if (Hit.Is_RPC() == 1 && (RPC_CSC_ID != conv_vals_SP.at(0) || RPC_subsector != conv_vals_SP.at(2)))
393  continue;
394 
395  if (St_hits.at(0) == 0) { // Only add the first matched hit to the track
396  Track_.push_Hit((Hit));
398  mu_.setTrackSubAddress(
400  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 1));
401  }
402  St_hits.at(0) += 1; // Count the total number of matches for debugging purposes
403  } // End conditional: if ( Hit.Station() == 1
404 
405  // Match hit in station 2
406  conv_vals_SP = convert_SP_location(SP_.ME2_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 2);
407 
408  if (Hit.Station() == 2 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
409  Hit.Stub_num() == SP_.ME2_stub_num()) {
410  if (Hit.Is_CSC() == 1 && Hit.CSC_ID() != conv_vals_SP.at(0))
411  continue;
412 
413  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
414  if (Hit.Is_RPC() == 1 && tmp_subsector + 3 != conv_vals_SP.at(0))
415  continue;
416 
417  if (St_hits.at(1) == 0) {
418  Track_.push_Hit((Hit));
420  mu_.setTrackSubAddress(
422  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 2));
423  }
424  St_hits.at(1) += 1;
425  } // End conditional: if ( Hit.Station() == 2
426 
427  // Match hit in station 3
428  conv_vals_SP = convert_SP_location(SP_.ME3_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 3);
429 
430  if (Hit.Station() == 3 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
431  Hit.Stub_num() == SP_.ME3_stub_num()) {
432  if (Hit.Is_CSC() == 1 && Hit.CSC_ID() != conv_vals_SP.at(0))
433  continue;
434 
435  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
436  if (Hit.Is_RPC() == 1 && tmp_subsector + 3 != conv_vals_SP.at(0))
437  continue;
438 
439  if (St_hits.at(2) == 0) {
440  Track_.push_Hit((Hit));
442  mu_.setTrackSubAddress(
444  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 3));
445  }
446  St_hits.at(2) += 1;
447  } // End conditional: if ( Hit.Station() == 3
448 
449  // Match hit in station 4
450  conv_vals_SP = convert_SP_location(SP_.ME4_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 4);
451 
452  if (Hit.Station() == 4 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
453  Hit.Stub_num() == SP_.ME4_stub_num()) {
454  if (Hit.Is_CSC() == 1 && Hit.CSC_ID() != conv_vals_SP.at(0))
455  continue;
456 
457  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
458  if (Hit.Is_RPC() == 1 && tmp_subsector + 3 != conv_vals_SP.at(0))
459  continue;
460 
461  if (St_hits.at(3) == 0) {
462  Track_.push_Hit((Hit));
464  mu_.setTrackSubAddress(
466  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 4));
467  }
468  St_hits.at(3) += 1;
469  } // End conditional: if ( Hit.Station() == 4
470 
471  } // End loop: for (auto const & Hit : *res_hit)
472 
473  // Special configuration for single-stub tracks from ME1/1
474  if (Track_.Mode() == 1) {
475  // Infer ME1/1 chamber based on track phi
476  int chamber_min = ((Track_.GMT_phi() - 17) / 16) + Track_.Sector() * 6 - 3;
477  int chamber_max = ((Track_.GMT_phi() + 1) / 16) + Track_.Sector() * 6 - 3;
478  for (int iChamb = chamber_max; iChamb >= chamber_min; iChamb--) {
479  int chamber = (iChamb < 37 ? iChamb : (iChamb % 36));
480 
481  for (auto const& Hit : *res_hit) {
482  if (Hit.Sector_idx() != Track_.Sector_idx())
483  continue;
484  if (Hit.BX() != Track_.BX())
485  continue;
486  if (Hit.Chamber() != chamber)
487  continue;
488  if (Hit.Is_CSC() != 1)
489  continue;
490  if (Hit.Station() != 1)
491  continue;
492  if ((Hit.Ring() % 3) != 1)
493  continue;
494  if (Hit.Neighbor() == 1)
495  continue;
496 
497  // Don't use LCTs that were already used in a multi-station track
498  bool hit_already_used = false;
499  for (auto const& Trk : *res_track) {
500  if (Trk.Sector_idx() != Track_.Sector_idx())
501  continue;
502  if (Trk.NumHits() < 1)
503  continue;
504 
505  if (Trk.Hits().at(0).Station() == 1 && Trk.Hits().at(0).Chamber() == chamber &&
506  Trk.Hits().at(0).BX() == Hit.BX() && Trk.Hits().at(0).Ring() == Hit.Ring() &&
507  Trk.Hits().at(0).Strip() == Hit.Strip() && Trk.Hits().at(0).Wire() == Hit.Wire()) {
508  hit_already_used = true;
509  break;
510  }
511  } // End loop: for (auto const & Trk : *res_track)
512 
513  if (!hit_already_used) {
514  Track_.push_Hit((Hit));
515  break;
516  }
517  } // End loop: for (auto const & Hit : *res_hit)
518  if (Track_.NumHits() > 0)
519  break;
520  } // End loop: for (int iChamb = chamber_max; iChamb >= chamber_min; iChamb--)
521 
522  // if (Track_.NumHits() != 1) {
523  // std::cout << "\n\n***********************************************************" << std::endl;
524  // std::cout << "Bug in unpacked EMTF event! Mode " << Track_.Mode() << " track in sector " << Track_.Sector()*Track_.Endcap()
525  // << ", BX " << Track_.BX() << ", GMT phi " << Track_.GMT_phi() << ", GMT eta " << Track_.GMT_eta()
526  // << " should have found an LCT between chamber " << chamber_min << " and " << chamber_max << std::endl;
527  // std::cout << "All available LCTs as follows:" << std::endl;
528  // for (auto const & Hit : *res_hit) {
529  // std::cout << "Hit: Is CSC = " << Hit.Is_CSC() << ", CSC ID = " << Hit.CSC_ID()
530  // << ", sector = " << Hit.Sector()*Hit.Endcap() << ", sub = " << Hit.Subsector()
531  // << ", neighbor = " << Hit.Neighbor() << ", station = " << Hit.Station()
532  // << ", ring = " << Hit.Ring() << ", chamber = " << Hit.Chamber()
533  // << ", stub = " << Hit.Stub_num() << ", BX = " << Hit.BX() << std::endl;
534  // std::cout << "All other tracks are as follows:" << std::endl;
535  // for (auto Trk = res_hit->begin(); Trk != res_hit->end(); ++Trk) {
536  // std::cout << "Track: mode " << Trk.Mode() << " track in sector " << Trk.Sector()*Trk.Endcap()
537  // << ", BX " << Trk.BX() << ", GMT phi " << Trk.GMT_phi() << ", GMT eta " << Trk.GMT_eta() << std::endl;
538  // }
539  // std::cout << "***********************************************************\n\n" << std::endl;
540  // } // End conditional: if (Track_.NumHits() != 1)
541 
542  } // End conditional: if (Track_.Mode() == 1)
543 
544  // if ( Track_.Mode() != St_hits.at(0)*8 + St_hits.at(1)*4 + St_hits.at(2)*2 + St_hits.at(3) && Track_.BX() == 0) {
545  // std::cout << "\n\n***********************************************************" << std::endl;
546  // std::cout << "Bug in unpacked EMTF event! Mode " << Track_.Mode() << " track in sector " << Track_.Sector()*Track_.Endcap()
547  // << ", BX " << Track_.BX() << " (delay = " << trk_delay << ") with (" << St_hits.at(0) << ", " << St_hits.at(1)
548  // << ", " << St_hits.at(2) << ", " << St_hits.at(3) << ") hits in stations (1, 2, 3, 4)" << std::endl;
549 
550  // std::cout << "\nME1_stub_num = " << SP_.ME1_stub_num() << ", ME1_delay = " << SP_.ME1_delay()
551  // << ", ME1_CSC_ID = " << SP_.ME1_CSC_ID() << ", ME1_subsector = " << SP_.ME1_subsector() << std::endl;
552  // std::cout << "ME2_stub_num = " << SP_.ME2_stub_num() << ", ME2_delay = " << SP_.ME2_delay()
553  // << ", ME2_CSC_ID = " << SP_.ME2_CSC_ID() << std::endl;
554  // std::cout << "ME3_stub_num = " << SP_.ME3_stub_num() << ", ME3_delay = " << SP_.ME3_delay()
555  // << ", ME3_CSC_ID = " << SP_.ME3_CSC_ID() << std::endl;
556  // std::cout << "ME4_stub_num = " << SP_.ME4_stub_num() << ", ME4_delay = " << SP_.ME4_delay()
557  // << ", ME4_CSC_ID = " << SP_.ME4_CSC_ID() << std::endl;
558 
559  // conv_vals_SP = convert_SP_location( SP_.ME1_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), SP_.ME1_subsector(), 1 );
560  // std::cout << "\nConverted ME1 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
561  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << std::endl;
562  // conv_vals_SP = convert_SP_location( SP_.ME2_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 2 );
563  // std::cout << "Converted ME2 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
564  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << std::endl;
565  // conv_vals_SP = convert_SP_location( SP_.ME3_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 3 );
566  // std::cout << "Converted ME3 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
567  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << std::endl;
568  // conv_vals_SP = convert_SP_location( SP_.ME4_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 4 );
569  // std::cout << "Converted ME4 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
570  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << "\n" << std::endl;
571 
572  // for (auto const & Hit : *res_hit)
573  // std::cout << "Hit: Is CSC = " << Hit.Is_CSC() << ", CSC ID = " << Hit.CSC_ID()
574  // << ", sector = " << Hit.Sector() << ", sub = " << Hit.Subsector()
575  // << ", neighbor = " << Hit.Neighbor() << ", station = " << Hit.Station()
576  // << ", ring = " << Hit.Ring() << ", chamber = " << Hit.Chamber()
577  // << ", stub = " << Hit.Stub_num() << ", BX = " << Hit.BX() << std::endl;
578 
579  // // int iHit = 0;
580  // // for (auto const & Hit : *res_hit) {
581  // // if (iHit == 0) Hit.PrintSimulatorHeader();
582  // // Hit.PrintForSimulator();
583  // // iHit += 1;
584  // // }
585  // std::cout << "***********************************************************\n\n" << std::endl;
586  // }
587 
588  // Reject tracks with out-of-range BX values. This needs to be adjusted if we increase l1a_window parameter in EMTF config - EY 03.08.2022
589  if (Track_.BX() > 3 or Track_.BX() < -3) {
590  edm::LogWarning("L1T|EMTF") << "EMTF unpacked track with out-of-range BX! BX: " << Track_.BX()
591  << " endcap: " << (Track_.Endcap() == 1 ? 1 : 2) << " sector: " << Track_.Sector()
592  << " address: " << Track_.PtLUT().address << " mode: " << Track_.Mode()
593  << " eta: " << (Track_.GMT_eta() >= 0 ? Track_.GMT_eta() : Track_.GMT_eta() + 512)
594  << " phi: " << Track_.GMT_phi() << " charge: " << Track_.GMT_charge()
595  << " qual: " << Track_.GMT_quality() << " pt: " << Track_.Pt()
596  << " pt_dxy: " << Track_.Pt_dxy() << std::endl;
597  return true;
598  }
599 
600  (res->at(iOut)).push_SP(SP_);
601 
602  if (Track_.Mode() != 0) { // Mode == 0 means no track was found (only muon shower)
603  res_track->push_back(Track_);
604 
605  // TBIN_num can range from 0 through 7, i.e. BX = -3 through +4. - AWB 04.04.16
606  res_cand->setBXRange(-3, 4);
607  res_cand->push_back(SP_.TBIN() - 3, mu_);
608  }
609 
610  res_shower->setBXRange(-3, 4);
611  res_shower->push_back(SP_.TBIN() - 3, muShower_);
612 
613  // Finished with unpacking one SP Output Data Record
614  return true;
615 
616  } // End bool SPBlockUnpacker::unpack
617 
618  // bool SPBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
619  // std::cout << "Inside SPBlockPacker::pack" << std::endl;
620  // return true;
621  // } // End bool SPBlockPacker::pack
622 
623  } // End namespace emtf
624  } // End namespace stage2
625 } // End namespace l1t
626 
628 // DEFINE_L1T_PACKER(l1t::stage2::SPBlockPacker);
int ME3_stub_num() const
Definition: SP.h:109
int Quality_GMT() const
Definition: SP.h:95
int Sector_idx() const
Definition: EMTFTrack.h:167
void set_me3_stub_num(int bits)
Definition: SP.h:75
void setOneTightInTime(const bool bit)
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
float Pt() const
Definition: EMTFTrack.h:180
void set_mus(int bits)
Definition: SP.h:63
void set_me2_stub_num(int bits)
Definition: SP.h:73
void set_pt_dxy_GMT(int bits)
Definition: SP.h:67
int ME4_stub_num() const
Definition: SP.h:111
float Pt_dxy() const
Definition: EMTFTrack.h:182
int ME1_CSC_ID() const
Definition: SP.h:104
int Sector() const
Definition: EMTFTrack.h:166
void set_me3_CSC_ID(int bits)
Definition: SP.h:74
unsigned int getAlgoVersion()
Definition: Unpacker.h:18
int ME1_stub_num() const
Definition: SP.h:105
void setOneLooseInTime(const bool bit)
virtual int checkFormat(const Block &block)
Definition: EMTFBlockSP.cc:34
int MUS() const
Definition: SP.h:121
int GMT_charge() const
Definition: EMTFTrack.h:199
void set_bx(int bits)
Definition: SP.h:62
int calc_uGMT_chamber(int csc_ID, int subsector, int neighbor, int station)
Definition: TrackTools.cc:53
int Pt_dxy_GMT() const
Definition: SP.h:101
Definition: Event.h:15
delete x;
Definition: CaloConfig.h:22
int ME2_delay() const
Definition: SP.h:114
Log< level::Error, false > LogError
int Mode() const
Definition: EMTFTrack.h:168
Definition: Electron.h:6
void set_se(int bits)
Definition: SP.h:58
void set_me2_CSC_ID(int bits)
Definition: SP.h:72
int Pt_GMT() const
Definition: SP.h:100
void set_me1_stub_num(int bits)
Definition: SP.h:71
void set_pt_GMT(int bits)
Definition: SP.h:66
void set_me4_delay(int bits)
Definition: SP.h:82
void set_phi_GMT(int bits)
Definition: SP.h:61
int VC() const
Definition: SP.h:91
int TwosCompl(int nBits, int bits)
void set_me1_delay(int bits)
Definition: SP.h:79
void set_me2_delay(int bits)
Definition: SP.h:80
void set_hl(int bits)
Definition: SP.h:53
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
void set_tbin(int bits)
Definition: SP.h:78
int NumHits() const
Definition: EMTFTrack.h:124
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
int GMT_quality() const
Definition: EMTFTrack.h:198
int BX() const
Definition: EMTFTrack.h:177
int Eta_GMT() const
Definition: SP.h:99
int Endcap() const
Definition: EMTFTrack.h:165
std::vector< EMTFHit > EMTFHitCollection
Definition: EMTFHit.h:381
int Phi_GMT() const
Definition: SP.h:96
int ME4_CSC_ID() const
Definition: SP.h:110
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:179
void setTrackSubAddress(bmtfAddress subAddress, int value)
Set a part of the muon candidates track address; specialised for BMTF.
void set_bc0(int bits)
Definition: SP.h:59
void set_track_num(int bits)
Definition: EMTFTrack.h:163
void set_eta_GMT(int bits)
Definition: SP.h:65
int ME2_CSC_ID() const
Definition: SP.h:106
int C() const
Definition: SP.h:89
void set_c(int bits)
Definition: SP.h:54
void set_vc(int bits)
Definition: SP.h:56
int GMT_eta() const
Definition: EMTFTrack.h:197
void setHwQual(int bits)
Set compressed quality code as transmitted by hardware (4 bits)
void setHwPt(int bits)
Set compressed pT as transmitted by hardware LSB = 0.5 (9 bits)
void set_me4_CSC_ID(int bits)
Definition: SP.h:76
void setHwEta(int bits)
Set compressed eta as transmitted by hardware LSB = 0.010875 (9 bits)
void setHwDXY(int bits)
Set compressed impact parameter with respect to beamspot (4 bits)
void setOneNominalInTime(const bool bit)
void set_me4_stub_num(int bits)
Definition: SP.h:77
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockSP.cc:170
void set_me3_delay(int bits)
Definition: SP.h:81
void set_dxy_GMT(int bits)
Definition: SP.h:68
int ME3_delay() const
Definition: SP.h:115
int ME1_subsector() const
Definition: SP.h:103
void setBXRange(int bxFirst, int bxLast)
uint64_t address
Definition: EMTFTrack.h:25
int ME3_CSC_ID() const
Definition: SP.h:108
EMTFPtLUT PtLUT() const
Definition: EMTFTrack.h:129
void setTFIdentifiers(int processor, tftype trackFinder)
Set the processor ID, track-finder type. From these two, the link is set.
int ME1_delay() const
Definition: SP.h:113
void set_pt_LUT_addr(unsigned long bits)
Definition: SP.h:84
void ImportSP(EMTFTrack &_track, const l1t::emtf::SP _SP, const int _endcap, const int _evt_sector)
int ME4_delay() const
Definition: SP.h:116
int Track_num() const
Definition: EMTFTrack.h:201
void push_Hit(const EMTFHit &hit)
Definition: EMTFTrack.h:101
#define DEFINE_L1T_UNPACKER(type)
void set_me1_CSC_ID(int bits)
Definition: SP.h:70
void setHwSignValid(int bits)
Set whether charge measurement is valid (0 for high pT muons)
int TBIN() const
Definition: SP.h:112
std::vector< int > convert_SP_location(int _csc_ID, int _sector, int _subsector, int _station)
Definition: EMTFBlockSP.cc:99
Definition: errors.py:1
int ME2_stub_num() const
Definition: SP.h:107
std::vector< EMTFTrack > EMTFTrackCollection
Definition: EMTFTrack.h:251
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
Log< level::Warning, false > LogWarning
int GMT_phi() const
Definition: EMTFTrack.h:196
void set_me1_subsector(int bits)
Definition: SP.h:69
void setHwPtUnconstrained(int bits)
Set compressed second displaced pT as transmitted by hardware LSB = 1.0 (8 bits)
void set_quality_GMT(int bits)
Definition: SP.h:60
void add_format_error()
Definition: SP.h:85
void push_back(int bx, T object)
void set_phi_full(int bits)
Definition: SP.h:55
void setHwSign(int bits)
Set charge sign bit (charge = (-1)^(sign))
void set_mode(int bits)
Definition: SP.h:64
int Dxy_GMT() const
Definition: SP.h:102
void set_nn_pt_valid(int bits)
Definition: SP.h:83