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  l1t::EtSum etEm = l1t::EtSum();
92 
93  switch (block.header().getID()) {
94  case 123: // 61
96  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
97  break;
98  case 121: // 60
100  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
101  break;
102  case 127: // 63
104  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
105  break;
106  case 125: // 62
108  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
109  break;
110  case 131: // 65
112  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
113  break;
114  case 129: // 64
116  etNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
117  break;
118  default:
119  break;
120  }
121 
122  LogDebug("L1T") << "ET/METx/METy (no HF): pT " << etNoHF.hwPt();
123 
124  res2_->push_back(0, etNoHF);
125 
126  // ET EM
127  if (block.header().getID() == 123 || block.header().getID() == 125) {
129  etEm.setHwPt(static_cast<int32_t>(uint32_t((raw_data >> 16) & 0xFFFF)));
130  res2_->push_back(0, etEm);
131  }
132 
133  // HT / MHT(x)/ MHT (y) with HF
134 
135  raw_data = block.payload()[fht];
136 
137  l1t::EtSum hthf = l1t::EtSum();
138 
139  switch (block.header().getID()) {
140  case 123: // 61
142  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
143  break;
144  case 121: // 60
146  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
147  break;
148  case 127: // 63
150  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
151  break;
152  case 125: // 62
154  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
155  break;
156  case 131: // 65
158  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
159  break;
160  case 129: // 64
162  hthf.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
163  break;
164  default:
165  break;
166  }
167 
168  LogDebug("L1T") << "HTHF/MHTHFx/MHTHFy: pT " << hthf.hwPt();
169 
170  res2_->push_back(0, hthf);
171 
172  // HT / MHT(x)/ MHT (y) no HF
173 
174  raw_data = block.payload()[fht + 1];
175 
176  l1t::EtSum htNoHF = l1t::EtSum();
177 
178  switch (block.header().getID()) {
179  case 123: // 61
181  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
182  break;
183  case 121: // 60
185  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
186  break;
187  case 127: // 63
189  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
190  break;
191  case 125: // 62
193  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFF)));
194  break;
195  case 131: // 65
197  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
198  break;
199  case 129: // 64
201  htNoHF.setHwPt(static_cast<int32_t>(uint32_t(raw_data)));
202  break;
203  default:
204  break;
205  }
206 
207  LogDebug("L1T") << "HTNOHF/MHTNOHFx/MHTNOHFy: pT " << htNoHF.hwPt();
208 
209  res2_->push_back(0, htNoHF);
210 
211  // Two jets
212  for (unsigned nJet = 0; nJet < 2; nJet++) {
213  raw_data = block.payload()[fjet + nJet];
214 
215  if (raw_data == 0)
216  continue;
217 
218  l1t::Jet jet = l1t::Jet();
219 
220  int etasign = 1;
221  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
222  etasign = -1;
223  }
224 
225  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
226 
227  int mpEta = etasign * (raw_data & 0x3F);
228  jet.setHwEta(CaloTools::caloEta(mpEta));
229  jet.setHwPhi((raw_data >> 6) & 0x7F);
230  jet.setHwPt((raw_data >> 13) & 0xFFFF);
231  jet.setHwQual((raw_data >> 29) & 0x1);
232 
233  if (jet.hwPt() == 0)
234  continue;
235 
236  LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual "
237  << jet.hwQual();
238 
239  jet.setP4(l1t::CaloTools::p4MP(&jet));
240  res1_->push_back(0, jet);
241  }
242 
243  // ===== EGammas =====
244 
245  // Two EGammas
246 
247  for (unsigned nEG = 0; nEG < 2; nEG++) {
248  raw_data = block.payload()[feg + nEG];
249 
250  if (raw_data == 0)
251  continue;
252 
253  l1t::EGamma eg = l1t::EGamma();
254 
255  int etasign = 1;
256  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
257  etasign = -1;
258  }
259 
260  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
261 
262  eg.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
263  eg.setHwPhi((raw_data >> 9) & 0x7F);
264  eg.setHwPt((raw_data >> 20) & 0xFFF);
265  eg.setHwIso((raw_data >> 1) & 0x3);
266  eg.setHwQual((raw_data >> 16) & 0xf);
267 
268  if (eg.hwPt() == 0)
269  continue;
270 
271  LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual "
272  << eg.hwQual();
273 
274  eg.setP4(l1t::CaloTools::p4MP(&eg));
275  res3_->push_back(0, eg);
276  }
277 
278  // ===== Taus =====
279 
280  // Two taus
281 
282  for (unsigned nTau = 0; nTau < 2; nTau++) {
283  raw_data = block.payload()[ftau + nTau];
284 
285  if (raw_data == 0)
286  continue;
287 
288  l1t::Tau tau = l1t::Tau();
289 
290  int etasign = 1;
291  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
292  etasign = -1;
293  }
294 
295  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
296 
297  tau.setHwEta(etasign * ((raw_data >> 3) & 0x3F));
298  tau.setHwPhi((raw_data >> 9) & 0x7F);
299  tau.setHwPt((raw_data >> 20) & 0xFFF);
300  tau.setHwIso((raw_data >> 1) & 0x3);
301  tau.setHwQual((raw_data >> 16) & 0xf);
302 
303  if (tau.hwPt() == 0)
304  continue;
305 
306  LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual "
307  << tau.hwQual();
308 
309  tau.setP4(l1t::CaloTools::p4MP(&tau));
310  res4_->push_back(0, tau);
311  }
312 
313  // ===== Aux =====
314  raw_data = block.payload()[faux];
315 
316  // create a sum object for each type of HF sum
317  l1t::EtSum mbp0 = l1t::EtSum();
318  l1t::EtSum mbm0 = l1t::EtSum();
319  l1t::EtSum mbm1 = l1t::EtSum();
320  l1t::EtSum mbp1 = l1t::EtSum();
321  l1t::EtSum towCount = l1t::EtSum();
322 
323  // readout the sums only if the correct block is being processed (first frame of AUX)
324  switch (block.header().getID()) {
325  case 121: // this should correspond to the first link
326  // read 4 bits starting at position 24 (24 -> 28)
327  mbp0.setHwPt((raw_data >> 24) & 0xF);
329 
330  // read 4 bits starting at position 16 (16 -> 20)
331  mbm0.setHwPt((raw_data >> 16) & 0xF);
333 
334  // read 4 bits starting at position 8 (8 -> 12)
335  mbp1.setHwPt((raw_data >> 8) & 0xF);
337 
338  // read the first 4 bits by masking with 0xF
339  mbm1.setHwPt(raw_data & 0xF);
341 
342  LogDebug("L1T") << "mbp0 HF sum: " << mbp0.hwPt();
343  LogDebug("L1T") << "mbm0 HF sum: " << mbm0.hwPt();
344  LogDebug("L1T") << "mbp1 HF sum: " << mbp1.hwPt();
345  LogDebug("L1T") << "mbm1 HF sum: " << mbm1.hwPt();
346 
347  res2_->push_back(0, mbp0);
348  res2_->push_back(0, mbm0);
349  res2_->push_back(0, mbp1);
350  res2_->push_back(0, mbm1);
351  break;
352  case 127:
353  towCount.setHwPt(raw_data & 0x1FFF);
355  res2_->push_back(0, towCount);
356  break;
357  default:
358  break;
359  }
360 
361  return true;
362  }
363  } // namespace stage2
364 } // namespace l1t
365 
#define LogDebug(id)
const std::vector< uint32_t > & payload() const
Definition: Block.h:70
unsigned int getID() const
Definition: Block.h:27
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: Tau.h:20
BlockHeader header() const
Definition: Block.h:69
static math::PtEtaPhiMLorentzVector p4MP(l1t::L1Candidate *)
Definition: CaloTools.cc:369
void setHwQual(int qual)
Definition: L1Candidate.h:31
int hwPhi() const
Definition: L1Candidate.h:37
delete x;
Definition: CaloConfig.h:22
void setType(EtSumType type)
Definition: EtSum.cc:11
Definition: Jet.h:20
int hwEta() const
Definition: L1Candidate.h:36
int hwQual() const
Definition: L1Candidate.h:38
void setHwPhi(int phi)
Definition: L1Candidate.h:30
void setHwIso(int iso)
Definition: L1Candidate.h:32
JetCorrectorParametersCollection coll
Definition: classes.h:10
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)
unsigned int getSize() const
Definition: Block.h:28
void setHwEta(int eta)
Definition: L1Candidate.h:29
void amc(const amc::Header &h)
Definition: Block.h:72
void setP4(const LorentzVector &p4) final
set 4-momentum