CMS 3D CMS Logo

MPUnpacker_0x10010033.cc
Go to the documentation of this file.
1 #define EDM_ML_DEBUG 1
2 
4 
6 
8 
9 #include "CaloCollections.h"
11 #include "MPUnpacker_0x10010033.h"
12 
13 namespace l1t {
14  namespace stage2 {
16  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize()
17  << " AMC = " << block.amc().getAMCNumber();
18 
19  // check this is the correct MP
20  unsigned int tmt = block.amc().getBoardID() - l1t::stage2::layer2::mp::offsetBoardId + 1;
21  unsigned int bxid = block.amc().getBX();
22 
23  // handle offset between BC0 marker and actual BC0...
24  //if( (tmt-1) != ((bxid-1+3)%9) ) return true;
25  LogDebug("L1T") << "Unpacking TMT # " << tmt << " for BX " << bxid;
26 
27  auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
28  auto res2_ = static_cast<CaloCollections*>(coll)->getMPEtSums();
29  auto res3_ = static_cast<CaloCollections*>(coll)->getMPEGammas();
30  auto res4_ = static_cast<CaloCollections*>(coll)->getMPTaus();
31 
32  res1_->setBXRange(0, 0);
33  res2_->setBXRange(0, 0);
34  res3_->setBXRange(0, 0);
35  res4_->setBXRange(0, 0);
36 
37  // Initialise frame indices for each data type
38  int unsigned fet = 0;
39  int unsigned fht = 2;
40  int unsigned feg = 4;
41  int unsigned ftau = 6;
42  int unsigned fjet = 8;
43  int unsigned faux = 10;
44 
45  // ===== Jets and Sums =====
46 
47  // ET / MET(x) / MET (y) with HF (configurable)
48 
49  uint32_t raw_data = block.payload()[fet];
50 
51  l1t::EtSum ethf = l1t::EtSum();
52 
53  switch (block.header().getID()) {
54  case 123: // 61
56  ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
57  break;
58  case 121: // 60
60  ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
61  break;
62  case 127: // 63
64  ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
65  break;
66  case 125: // 62
68  ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
69  break;
70  case 131: // 65
72  ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
73  break;
74  case 129: // 64
76  ethf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
77  break;
78  default:
79  break;
80  }
81 
82  LogDebug("L1T") << "ET/METx/METy: pT " << ethf.hwPt();
83 
84  res2_->push_back(0, ethf);
85 
86  // ET / MET(x) / MET (y) without HF
87 
88  raw_data = block.payload()[fet + 1];
89 
90  l1t::EtSum etNoHF = l1t::EtSum();
91 
92  switch (block.header().getID()) {
93  case 123: // 61
95  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
96  break;
97  case 121: // 60
99  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
100  break;
101  case 127: // 63
103  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
104  break;
105  case 125: // 62
107  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
108  break;
109  case 131: // 65
111  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
112  break;
113  case 129: // 64
115  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
116  break;
117  default:
118  break;
119  }
120 
121  LogDebug("L1T") << "ET/METx/METy (no HF): pT " << etNoHF.hwPt();
122 
123  res2_->push_back(0, etNoHF);
124 
125  // ET EM
126  if (block.header().getID() == 123 || block.header().getID() == 125) {
128  etEm.setHwPt(static_cast<int32_t>(uint32_t((raw_data >> 16) & 0xFFFF)));
129  res2_->push_back(0, etEm);
130  }
131 
132  // HT / MHT(x)/ MHT (y) with HF
133 
134  raw_data = block.payload()[fht];
135 
136  l1t::EtSum hthf = l1t::EtSum();
137 
138  switch (block.header().getID()) {
139  case 123: // 61
141  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
142  break;
143  case 121: // 60
145  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
146  break;
147  case 127: // 63
149  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
150  break;
151  case 125: // 62
153  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
154  break;
155  case 131: // 65
157  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
158  break;
159  case 129: // 64
161  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
162  break;
163  default:
164  break;
165  }
166 
167  LogDebug("L1T") << "HTHF/MHTHFx/MHTHFy: pT " << hthf.hwPt();
168 
169  res2_->push_back(0, hthf);
170 
171  // HT / MHT(x)/ MHT (y) no HF
172 
173  raw_data = block.payload()[fht + 1];
174 
175  l1t::EtSum htNoHF = l1t::EtSum();
176 
177  switch (block.header().getID()) {
178  case 123: // 61
180  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
181  break;
182  case 121: // 60
184  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
185  break;
186  case 127: // 63
188  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
189  break;
190  case 125: // 62
192  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
193  break;
194  case 131: // 65
196  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
197  break;
198  case 129: // 64
200  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
201  break;
202  default:
203  break;
204  }
205 
206  LogDebug("L1T") << "HTNOHF/MHTNOHFx/MHTNOHFy: pT " << htNoHF.hwPt();
207 
208  res2_->push_back(0, htNoHF);
209 
210  // Two jets
211  for (unsigned nJet = 0; nJet < 2; nJet++) {
212  raw_data = block.payload()[fjet + nJet];
213 
214  if (raw_data == 0)
215  continue;
216 
217  l1t::Jet jet = l1t::Jet();
218 
219  int etasign = 1;
220  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
221  etasign = -1;
222  }
223 
224  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
225 
226  int mpEta = etasign * (raw_data & 0x3F);
227  jet.setHwEta(CaloTools::caloEta(mpEta));
228  jet.setHwPhi((raw_data >> 6) & 0x7F);
229  jet.setHwPt((raw_data >> 13) & 0xFFFF);
230  jet.setHwQual((raw_data >> 29) & 0x1);
231 
232  if (jet.hwPt() == 0)
233  continue;
234 
235  LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual "
236  << jet.hwQual();
237 
238  jet.setP4(l1t::CaloTools::p4MP(&jet));
239  res1_->push_back(0, jet);
240  }
241 
242  // ===== EGammas =====
243 
244  // Two EGammas
245 
246  for (unsigned nEG = 0; nEG < 2; nEG++) {
247  raw_data = block.payload()[feg + nEG];
248 
249  if (raw_data == 0)
250  continue;
251 
252  l1t::EGamma eg = l1t::EGamma();
253 
254  int etasign = 1;
255  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
256  etasign = -1;
257  }
258 
259  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
260 
261  eg.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
262  eg.setHwPhi((raw_data >> 9) & 0x7F);
263  eg.setHwPt((raw_data >> 20) & 0xFFF);
264  eg.setHwIso((raw_data >> 1) & 0x3);
265  eg.setHwQual((raw_data >> 16) & 0xf);
266 
267  if (eg.hwPt() == 0)
268  continue;
269 
270  LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual "
271  << eg.hwQual();
272 
273  eg.setP4(l1t::CaloTools::p4MP(&eg));
274  res3_->push_back(0, eg);
275  }
276 
277  // ===== Taus =====
278 
279  // Two taus
280 
281  for (unsigned nTau = 0; nTau < 2; nTau++) {
282  raw_data = block.payload()[ftau + nTau];
283 
284  if (raw_data == 0)
285  continue;
286 
287  l1t::Tau tau = l1t::Tau();
288 
289  int etasign = 1;
290  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
291  etasign = -1;
292  }
293 
294  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
295 
296  tau.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
297  tau.setHwPhi((raw_data >> 9) & 0x7F);
298  tau.setHwPt((raw_data >> 20) & 0xFFF);
299  tau.setHwIso((raw_data >> 1) & 0x3);
300  tau.setHwQual((raw_data >> 16) & 0xf);
301 
302  if (tau.hwPt() == 0)
303  continue;
304 
305  LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual "
306  << tau.hwQual();
307 
308  tau.setP4(l1t::CaloTools::p4MP(&tau));
309  res4_->push_back(0, tau);
310  }
311 
312  // ===== Aux =====
313  raw_data = block.payload()[faux];
314 
315  // create a sum object for each type of HF sum
316 
317  // readout the sums only if the correct block is being processed (first frame of AUX)
318  switch (block.header().getID()) {
319  case 121: // this should correspond to the first link
320  {
321  // read 4 bits starting at position 24 (24 -> 28)
323  mbp0.setHwPt((raw_data >> 24) & 0xF);
324 
325  // read 4 bits starting at position 16 (16 -> 20)
327  mbm0.setHwPt((raw_data >> 16) & 0xF);
328 
329  // read 4 bits starting at position 8 (8 -> 12)
331  mbp1.setHwPt((raw_data >> 8) & 0xF);
332 
333  // read the first 4 bits by masking with 0xF
335  mbm1.setHwPt(raw_data & 0xF);
336 
337  LogDebug("L1T") << "mbp0 HF sum: " << mbp0.hwPt();
338  LogDebug("L1T") << "mbm0 HF sum: " << mbm0.hwPt();
339  LogDebug("L1T") << "mbp1 HF sum: " << mbp1.hwPt();
340  LogDebug("L1T") << "mbm1 HF sum: " << mbm1.hwPt();
341 
342  res2_->push_back(0, mbp0);
343  res2_->push_back(0, mbm0);
344  res2_->push_back(0, mbp1);
345  res2_->push_back(0, mbm1);
346  break;
347  }
348  case 127: {
350  towCount.setHwPt(raw_data & 0x1FFF);
351  res2_->push_back(0, towCount);
352  break;
353  }
354  default:
355  break;
356  }
357 
358  return true;
359  }
360  } // namespace stage2
361 } // namespace l1t
362 
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: Tau.h:20
int hwPhi() const
Definition: L1Candidate.h:37
static math::PtEtaPhiMLorentzVector p4MP(l1t::L1Candidate *)
Definition: CaloTools.cc:369
void setHwQual(int qual)
Definition: L1Candidate.h:31
delete x;
Definition: CaloConfig.h:22
void setType(EtSumType type)
Definition: EtSum.cc:11
int hwQual() const
Definition: L1Candidate.h:38
Definition: Jet.h:20
int hwEta() const
Definition: L1Candidate.h:36
void setHwPhi(int phi)
Definition: L1Candidate.h:30
void setHwIso(int iso)
Definition: L1Candidate.h:32
int hwPt() const
Definition: L1Candidate.h:35
static int caloEta(int ietaMP)
Definition: CaloTools.cc:234
void setHwPt(int pt)
Definition: L1Candidate.h:28
#define DEFINE_L1T_UNPACKER(type)
void setHwEta(int eta)
Definition: L1Candidate.h:29
void setP4(const LorentzVector &p4) final
set 4-momentum
#define LogDebug(id)