CMS 3D CMS Logo

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