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 useHMTBits_ = getAlgoVersion() >= 11306; // FW versions >= 10.01.2022
182 
183  static constexpr int nominalShower_ = 1;
184  static constexpr int tightShower_ = 3;
185 
186  // Check Format of Payload
187  l1t::emtf::SP SP_;
188  for (int err = 0; err < checkFormat(block); err++)
189  SP_.add_format_error();
190 
191  // Assign payload to 16-bit words
192  uint16_t SP1a = payload[0];
193  uint16_t SP1b = payload[1];
194  uint16_t SP1c = payload[2];
195  uint16_t SP1d = payload[3];
196  uint16_t SP2a = payload[4];
197  uint16_t SP2b = payload[5];
198  uint16_t SP2c = payload[6];
199  uint16_t SP2d = payload[7];
200 
201  // res is a pointer to a collection of EMTFDaqOut class objects
202  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
204  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
205  int iOut = res->size() - 1;
206  std::vector<int> conv_vals_SP;
207  std::vector<int> conv_vals_pT_LUT;
208 
209  EMTFHitCollection* res_hit;
210  res_hit = static_cast<EMTFCollections*>(coll)->getEMTFHits();
211 
212  EMTFTrackCollection* res_track;
213  res_track = static_cast<EMTFCollections*>(coll)->getEMTFTracks();
214  EMTFTrack Track_;
215 
217  res_cand = static_cast<EMTFCollections*>(coll)->getRegionalMuonCands();
218  RegionalMuonCand mu_(0, 0, 0, 0, 0, 0, 0, tftype::emtf_pos);
219 
220  RegionalMuonShowerBxCollection* res_shower;
221  res_shower = static_cast<EMTFCollections*>(coll)->getRegionalMuonShowers();
222  RegionalMuonShower muShower_(false, false, false, false, false, false);
223 
225  // Unpack the SP Output Data Record
227 
228  SP_.set_phi_full(GetHexBits(SP1a, 0, 12));
229  SP_.set_c(GetHexBits(SP1a, 13, 13));
230  SP_.set_hl(GetHexBits(SP1a, 14, 14));
231 
232  SP_.set_phi_GMT(TwosCompl(8, GetHexBits(SP1b, 0, 7)));
233  SP_.set_quality_GMT(GetHexBits(SP1b, 8, 11));
234  SP_.set_bc0(GetHexBits(SP1b, 12, 12));
235  SP_.set_se(GetHexBits(SP1b, 13, 13));
236  SP_.set_vc(GetHexBits(SP1b, 14, 14));
237 
238  SP_.set_eta_GMT(TwosCompl(9, GetHexBits(SP1c, 0, 8)));
239  SP_.set_mode(GetHexBits(SP1c, 9, 12));
240 
241  if (useHMTBits_) {
242  SP_.set_hmt(GetHexBits(SP1c, 13, 14));
243  } else {
244  SP_.set_bx(GetHexBits(SP1c, 13, 14));
245  }
246 
247  SP_.set_pt_GMT(GetHexBits(SP1d, 0, 8));
248  SP_.set_me1_stub_num(GetHexBits(SP1d, 9, 9));
249  SP_.set_me1_CSC_ID(GetHexBits(SP1d, 10, 13));
250  SP_.set_me1_subsector(GetHexBits(SP1d, 14, 14));
251 
252  SP_.set_me2_stub_num(GetHexBits(SP2a, 0, 0));
253  SP_.set_me2_CSC_ID(GetHexBits(SP2a, 1, 4));
254  SP_.set_me3_stub_num(GetHexBits(SP2a, 5, 5));
255  SP_.set_me3_CSC_ID(GetHexBits(SP2a, 6, 9));
256  SP_.set_me4_stub_num(GetHexBits(SP2a, 10, 10));
257  SP_.set_me4_CSC_ID(GetHexBits(SP2a, 11, 14));
258 
259  SP_.set_me1_delay(GetHexBits(SP2b, 0, 2));
260  SP_.set_me2_delay(GetHexBits(SP2b, 3, 5));
261  SP_.set_me3_delay(GetHexBits(SP2b, 6, 8));
262  SP_.set_me4_delay(GetHexBits(SP2b, 9, 11));
263  SP_.set_tbin(GetHexBits(SP2b, 12, 14));
264 
265  if (useNNBits_) {
266  SP_.set_pt_dxy_GMT(GetHexBits(SP2c, 0, 7));
267  SP_.set_dxy_GMT(GetHexBits(SP2c, 8, 10));
268  SP_.set_nn_pt_valid(GetHexBits(SP2c, 11, 11));
269  } else {
270  SP_.set_pt_LUT_addr(GetHexBits(SP2c, 0, 14, SP2d, 0, 14));
271  }
272 
273  // SP_.set_dataword ( uint64_t dataword );
274 
275  ImportSP(Track_, SP_, (res->at(iOut)).PtrEventHeader()->Endcap(), (res->at(iOut)).PtrEventHeader()->Sector());
276  // Track_.ImportPtLUT( Track_.Mode(), Track_.Pt_LUT_addr() ); // Deprecated ... replace? - AWB 15.03.17
277 
278  if (!(res->at(iOut)).PtrSPCollection()->empty())
279  if (SP_.TBIN() == (res->at(iOut)).PtrSPCollection()->at((res->at(iOut)).PtrSPCollection()->size() - 1).TBIN())
280  Track_.set_track_num((res->at(iOut)).PtrSPCollection()->size());
281  else
282  Track_.set_track_num(0);
283  else
284  Track_.set_track_num(0);
285 
286  // For single-LCT tracks, "Track_num" = 2 (last in collection)
287  if (SP_.Quality_GMT() == 0)
288  Track_.set_track_num(2);
289 
290  mu_.setHwSign(SP_.C());
291  mu_.setHwSignValid(SP_.VC());
292  mu_.setHwQual(SP_.Quality_GMT());
293  mu_.setHwEta(SP_.Eta_GMT());
294  mu_.setHwPhi(SP_.Phi_GMT());
295  mu_.setHwPt(SP_.Pt_GMT());
296  if (useNNBits_) {
297  mu_.setHwPtUnconstrained(SP_.Pt_dxy_GMT());
298  mu_.setHwDXY(SP_.Dxy_GMT());
299  }
300  mu_.setTFIdentifiers(Track_.Sector() - 1, (Track_.Endcap() == 1) ? emtf_pos : emtf_neg);
302  // Truncated to 11 bits and offset by 25 from global event BX in EMTF firmware
303  int EMTF_kBX = ((res->at(iOut)).PtrEventHeader()->L1A_BXN() % 2048) - 25 + Track_.BX();
304  if (EMTF_kBX < 0)
305  EMTF_kBX += 2048;
307  // mu_.set_dataword ( SP_.Dataword() );
308  // Track_.set_GMT(mu_);
309 
310  // Set Regional Muon Showers
311  if (useHMTBits_) {
312  muShower_.setTFIdentifiers(Track_.Sector() - 1, (Track_.Endcap() == 1) ? emtf_pos : emtf_neg);
313  muShower_.setOneNominalInTime(SP_.HMT() == nominalShower_ ? true : false);
314  muShower_.setOneTightInTime(SP_.HMT() == tightShower_ ? true : false);
315  }
316 
318  // Match hits to tracks
320 
321  // Find the track delay
322  int nDelay[3] = {0, 0, 0}; // Number of hits in the track with delay 0, 1, or 2
323  if (Track_.Mode() >= 8)
324  nDelay[SP_.ME1_delay()] += 1;
325  if ((Track_.Mode() % 8) >= 4)
326  nDelay[SP_.ME2_delay()] += 1;
327  if ((Track_.Mode() % 4) >= 2)
328  nDelay[SP_.ME3_delay()] += 1;
329  if ((Track_.Mode() % 2) == 1)
330  nDelay[SP_.ME4_delay()] += 1;
331 
332  int trk_delay = -99;
333  // Assume 2nd-earliest LCT configuration
334  if (nDelay[2] >= 2)
335  trk_delay = 2;
336  else if (nDelay[2] + nDelay[1] >= 2)
337  trk_delay = 1;
338  else if (nDelay[2] + nDelay[1] + nDelay[0] >= 2)
339  trk_delay = 0;
340 
341  // // For earliest LCT configuration
342  // if (nDelay[2] >= 1) trk_delay = 2;
343  // else if (nDelay[2] + nDelay[1] >= 1) trk_delay = 1;
344  // else if (nDelay[2] + nDelay[1] + nDelay[0] >= 1) trk_delay = 0;
345 
346  // Reverse 'rotate by 2' to get CPPF subsector number
347  auto get_subsector_rpc_cppf = [](int subsector_rpc) { return ((subsector_rpc + 3) % 6) + 1; };
348 
349  std::array<int, 4> St_hits{{0, 0, 0, 0}}; // Number of matched hits in each station
350 
351  for (auto const& Hit : *res_hit) {
352  if (Track_.Mode() == 1)
353  continue; // Special case dealt with later
354  if (Hit.Endcap() != Track_.Endcap())
355  continue;
356 
357  int hit_delay = -99;
358  if (Hit.Station() == 1)
359  hit_delay = SP_.ME1_delay();
360  else if (Hit.Station() == 2)
361  hit_delay = SP_.ME2_delay();
362  else if (Hit.Station() == 3)
363  hit_delay = SP_.ME3_delay();
364  else if (Hit.Station() == 4)
365  hit_delay = SP_.ME4_delay();
366 
367  // Require exact matching according to TBIN and delays
368  if (Hit.BX() + 3 + hit_delay != SP_.TBIN() + trk_delay)
369  continue;
370 
371  // Match hit in station 1
372  conv_vals_SP =
373  convert_SP_location(SP_.ME1_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), SP_.ME1_subsector(), 1);
374 
375  if (Hit.Station() == 1 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
376  Hit.Stub_num() == SP_.ME1_stub_num()) {
377  if (Hit.Is_CSC() == 1 && (Hit.CSC_ID() != conv_vals_SP.at(0) || Hit.Subsector() != conv_vals_SP.at(2)))
378  continue;
379 
380  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
381  int RPC_subsector = ((tmp_subsector - 1) / 3) + 1; // Map RPC subsector to equivalent CSC subsector
382  int RPC_CSC_ID = ((tmp_subsector - 1) % 3) + 4; // Map RPC subsector and ring to equivalent CSC ID
383 
384  if (Hit.Is_RPC() == 1 && (RPC_CSC_ID != conv_vals_SP.at(0) || RPC_subsector != conv_vals_SP.at(2)))
385  continue;
386 
387  if (St_hits.at(0) == 0) { // Only add the first matched hit to the track
388  Track_.push_Hit((Hit));
390  mu_.setTrackSubAddress(
392  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 1));
393  }
394  St_hits.at(0) += 1; // Count the total number of matches for debugging purposes
395  } // End conditional: if ( Hit.Station() == 1
396 
397  // Match hit in station 2
398  conv_vals_SP = convert_SP_location(SP_.ME2_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 2);
399 
400  if (Hit.Station() == 2 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
401  Hit.Stub_num() == SP_.ME2_stub_num()) {
402  if (Hit.Is_CSC() == 1 && Hit.CSC_ID() != conv_vals_SP.at(0))
403  continue;
404 
405  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
406  if (Hit.Is_RPC() == 1 && tmp_subsector + 3 != conv_vals_SP.at(0))
407  continue;
408 
409  if (St_hits.at(1) == 0) {
410  Track_.push_Hit((Hit));
412  mu_.setTrackSubAddress(
414  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 2));
415  }
416  St_hits.at(1) += 1;
417  } // End conditional: if ( Hit.Station() == 2
418 
419  // Match hit in station 3
420  conv_vals_SP = convert_SP_location(SP_.ME3_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 3);
421 
422  if (Hit.Station() == 3 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
423  Hit.Stub_num() == SP_.ME3_stub_num()) {
424  if (Hit.Is_CSC() == 1 && Hit.CSC_ID() != conv_vals_SP.at(0))
425  continue;
426 
427  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
428  if (Hit.Is_RPC() == 1 && tmp_subsector + 3 != conv_vals_SP.at(0))
429  continue;
430 
431  if (St_hits.at(2) == 0) {
432  Track_.push_Hit((Hit));
434  mu_.setTrackSubAddress(
436  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 3));
437  }
438  St_hits.at(2) += 1;
439  } // End conditional: if ( Hit.Station() == 3
440 
441  // Match hit in station 4
442  conv_vals_SP = convert_SP_location(SP_.ME4_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 4);
443 
444  if (Hit.Station() == 4 && Hit.Sector() == conv_vals_SP.at(1) && Hit.Neighbor() == conv_vals_SP.at(3) &&
445  Hit.Stub_num() == SP_.ME4_stub_num()) {
446  if (Hit.Is_CSC() == 1 && Hit.CSC_ID() != conv_vals_SP.at(0))
447  continue;
448 
449  int tmp_subsector = get_subsector_rpc_cppf(Hit.Subsector_RPC());
450  if (Hit.Is_RPC() == 1 && tmp_subsector + 3 != conv_vals_SP.at(0))
451  continue;
452 
453  if (St_hits.at(3) == 0) {
454  Track_.push_Hit((Hit));
456  mu_.setTrackSubAddress(
458  L1TMuonEndCap::calc_uGMT_chamber(conv_vals_SP.at(0), conv_vals_SP.at(2), conv_vals_SP.at(3), 4));
459  }
460  St_hits.at(3) += 1;
461  } // End conditional: if ( Hit.Station() == 4
462 
463  } // End loop: for (auto const & Hit : *res_hit)
464 
465  // Special configuration for single-stub tracks from ME1/1
466  if (Track_.Mode() == 1) {
467  // Infer ME1/1 chamber based on track phi
468  int chamber_min = ((Track_.GMT_phi() - 17) / 16) + Track_.Sector() * 6 - 3;
469  int chamber_max = ((Track_.GMT_phi() + 1) / 16) + Track_.Sector() * 6 - 3;
470  for (int iChamb = chamber_max; iChamb >= chamber_min; iChamb--) {
471  int chamber = (iChamb < 37 ? iChamb : (iChamb % 36));
472 
473  for (auto const& Hit : *res_hit) {
474  if (Hit.Sector_idx() != Track_.Sector_idx())
475  continue;
476  if (Hit.BX() != Track_.BX())
477  continue;
478  if (Hit.Chamber() != chamber)
479  continue;
480  if (Hit.Is_CSC() != 1)
481  continue;
482  if (Hit.Station() != 1)
483  continue;
484  if ((Hit.Ring() % 3) != 1)
485  continue;
486  if (Hit.Neighbor() == 1)
487  continue;
488 
489  // Don't use LCTs that were already used in a multi-station track
490  bool hit_already_used = false;
491  for (auto const& Trk : *res_track) {
492  if (Trk.Sector_idx() != Track_.Sector_idx())
493  continue;
494  if (Trk.NumHits() < 1)
495  continue;
496 
497  if (Trk.Hits().at(0).Station() == 1 && Trk.Hits().at(0).Chamber() == chamber &&
498  Trk.Hits().at(0).BX() == Hit.BX() && Trk.Hits().at(0).Ring() == Hit.Ring() &&
499  Trk.Hits().at(0).Strip() == Hit.Strip() && Trk.Hits().at(0).Wire() == Hit.Wire()) {
500  hit_already_used = true;
501  break;
502  }
503  } // End loop: for (auto const & Trk : *res_track)
504 
505  if (!hit_already_used) {
506  Track_.push_Hit((Hit));
507  break;
508  }
509  } // End loop: for (auto const & Hit : *res_hit)
510  if (Track_.NumHits() > 0)
511  break;
512  } // End loop: for (int iChamb = chamber_max; iChamb >= chamber_min; iChamb--)
513 
514  // if (Track_.NumHits() != 1) {
515  // std::cout << "\n\n***********************************************************" << std::endl;
516  // std::cout << "Bug in unpacked EMTF event! Mode " << Track_.Mode() << " track in sector " << Track_.Sector()*Track_.Endcap()
517  // << ", BX " << Track_.BX() << ", GMT phi " << Track_.GMT_phi() << ", GMT eta " << Track_.GMT_eta()
518  // << " should have found an LCT between chamber " << chamber_min << " and " << chamber_max << std::endl;
519  // std::cout << "All available LCTs as follows:" << std::endl;
520  // for (auto const & Hit : *res_hit) {
521  // std::cout << "Hit: Is CSC = " << Hit.Is_CSC() << ", CSC ID = " << Hit.CSC_ID()
522  // << ", sector = " << Hit.Sector()*Hit.Endcap() << ", sub = " << Hit.Subsector()
523  // << ", neighbor = " << Hit.Neighbor() << ", station = " << Hit.Station()
524  // << ", ring = " << Hit.Ring() << ", chamber = " << Hit.Chamber()
525  // << ", stub = " << Hit.Stub_num() << ", BX = " << Hit.BX() << std::endl;
526  // std::cout << "All other tracks are as follows:" << std::endl;
527  // for (auto Trk = res_hit->begin(); Trk != res_hit->end(); ++Trk) {
528  // std::cout << "Track: mode " << Trk.Mode() << " track in sector " << Trk.Sector()*Trk.Endcap()
529  // << ", BX " << Trk.BX() << ", GMT phi " << Trk.GMT_phi() << ", GMT eta " << Trk.GMT_eta() << std::endl;
530  // }
531  // std::cout << "***********************************************************\n\n" << std::endl;
532  // } // End conditional: if (Track_.NumHits() != 1)
533 
534  } // End conditional: if (Track_.Mode() == 1)
535 
536  // 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) {
537  // std::cout << "\n\n***********************************************************" << std::endl;
538  // std::cout << "Bug in unpacked EMTF event! Mode " << Track_.Mode() << " track in sector " << Track_.Sector()*Track_.Endcap()
539  // << ", BX " << Track_.BX() << " (delay = " << trk_delay << ") with (" << St_hits.at(0) << ", " << St_hits.at(1)
540  // << ", " << St_hits.at(2) << ", " << St_hits.at(3) << ") hits in stations (1, 2, 3, 4)" << std::endl;
541 
542  // std::cout << "\nME1_stub_num = " << SP_.ME1_stub_num() << ", ME1_delay = " << SP_.ME1_delay()
543  // << ", ME1_CSC_ID = " << SP_.ME1_CSC_ID() << ", ME1_subsector = " << SP_.ME1_subsector() << std::endl;
544  // std::cout << "ME2_stub_num = " << SP_.ME2_stub_num() << ", ME2_delay = " << SP_.ME2_delay()
545  // << ", ME2_CSC_ID = " << SP_.ME2_CSC_ID() << std::endl;
546  // std::cout << "ME3_stub_num = " << SP_.ME3_stub_num() << ", ME3_delay = " << SP_.ME3_delay()
547  // << ", ME3_CSC_ID = " << SP_.ME3_CSC_ID() << std::endl;
548  // std::cout << "ME4_stub_num = " << SP_.ME4_stub_num() << ", ME4_delay = " << SP_.ME4_delay()
549  // << ", ME4_CSC_ID = " << SP_.ME4_CSC_ID() << std::endl;
550 
551  // conv_vals_SP = convert_SP_location( SP_.ME1_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), SP_.ME1_subsector(), 1 );
552  // std::cout << "\nConverted ME1 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
553  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << std::endl;
554  // conv_vals_SP = convert_SP_location( SP_.ME2_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 2 );
555  // std::cout << "Converted ME2 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
556  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << std::endl;
557  // conv_vals_SP = convert_SP_location( SP_.ME3_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 3 );
558  // std::cout << "Converted ME3 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
559  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << std::endl;
560  // conv_vals_SP = convert_SP_location( SP_.ME4_CSC_ID(), (res->at(iOut)).PtrEventHeader()->Sector(), -99, 4 );
561  // std::cout << "Converted ME4 CSC ID = " << conv_vals_SP.at(0) << ", sector = " << conv_vals_SP.at(1)
562  // << ", subsector = " << conv_vals_SP.at(2) << ", neighbor = " << conv_vals_SP.at(3) << "\n" << std::endl;
563 
564  // for (auto const & Hit : *res_hit)
565  // std::cout << "Hit: Is CSC = " << Hit.Is_CSC() << ", CSC ID = " << Hit.CSC_ID()
566  // << ", sector = " << Hit.Sector() << ", sub = " << Hit.Subsector()
567  // << ", neighbor = " << Hit.Neighbor() << ", station = " << Hit.Station()
568  // << ", ring = " << Hit.Ring() << ", chamber = " << Hit.Chamber()
569  // << ", stub = " << Hit.Stub_num() << ", BX = " << Hit.BX() << std::endl;
570 
571  // // int iHit = 0;
572  // // for (auto const & Hit : *res_hit) {
573  // // if (iHit == 0) Hit.PrintSimulatorHeader();
574  // // Hit.PrintForSimulator();
575  // // iHit += 1;
576  // // }
577  // std::cout << "***********************************************************\n\n" << std::endl;
578  // }
579 
580  (res->at(iOut)).push_SP(SP_);
581 
582  res_track->push_back(Track_);
583 
584  // TBIN_num can range from 0 through 7, i.e. BX = -3 through +4. - AWB 04.04.16
585  res_cand->setBXRange(-3, 4);
586  res_cand->push_back(SP_.TBIN() - 3, mu_);
587 
588  res_shower->setBXRange(-3, 4);
589  res_shower->push_back(SP_.TBIN() - 3, muShower_);
590 
591  // Finished with unpacking one SP Output Data Record
592  return true;
593 
594  } // End bool SPBlockUnpacker::unpack
595 
596  // bool SPBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
597  // std::cout << "Inside SPBlockPacker::pack" << std::endl;
598  // return true;
599  // } // End bool SPBlockPacker::pack
600 
601  } // End namespace emtf
602  } // End namespace stage2
603 } // End namespace l1t
604 
606 // 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)
int HMT() const
Definition: SP.h:121
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
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
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
virtual int checkFormat(const Block &block)
Definition: EMTFBlockSP.cc:34
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
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:366
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
void set_hmt(int bits)
Definition: SP.h:63
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)
int ME3_CSC_ID() const
Definition: SP.h:108
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)
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