test
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 & 0xFFFFFF) << 16 ) >> 16 );
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 & 0xFFFFFF) << 16 ) >> 16 );
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 
97  switch(block.header().getID()){
98  case 123: // 61
100  etNoHF.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
101  break;
102  case 121: // 60
104  etNoHF.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
105  break;
106  case 127: // 63
108  etNoHF.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
109  break;
110  case 125: // 62
112  etNoHF.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
113  break;
114  case 131: // 65
116  etNoHF.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
117  break;
118  case 129: // 64
120  etNoHF.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
121  break;
122  default:
123  break;
124  }
125 
126  LogDebug("L1T") << "ET/METx/METy (no HF): pT " << etNoHF.hwPt();
127 
128  res2_->push_back(0,etNoHF);
129 
130 
131  // HT / MHT(x)/ MHT (y) with HF
132 
133  raw_data = block.payload()[fht];
134 
135  l1t::EtSum hthf = l1t::EtSum();
136 
137  switch(block.header().getID()){
138  case 123: // 61
140  hthf.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
141  break;
142  case 121: // 60
144  hthf.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
145  break;
146  case 127: // 63
148  hthf.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
149  break;
150  case 125: // 62
152  hthf.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
153  break;
154  case 131: // 65
156  hthf.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
157  break;
158  case 129: // 64
160  hthf.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
161  break;
162  default:
163  break;
164  }
165 
166  LogDebug("L1T") << "HTHF/MHTHFx/MHTHFy: pT " << hthf.hwPt();
167 
168  res2_->push_back(0,hthf);
169 
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 & 0xFFFFFF) << 16 ) >> 16 );
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 & 0xFFFFFF) << 16 ) >> 16 );
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 
207  LogDebug("L1T") << "HTNOHF/MHTNOHFx/MHTNOHFy: pT " << htNoHF.hwPt();
208 
209  res2_->push_back(0,htNoHF);
210 
211 
212  // Two jets
213  for (unsigned nJet=0; nJet < 2; nJet++){
214 
215  raw_data = block.payload()[fjet+nJet];
216 
217  if (raw_data == 0)
218  continue;
219 
220  l1t::Jet jet = l1t::Jet();
221 
222  int etasign = 1;
223  if ((block.header().getID() == 125) ||
224  (block.header().getID() == 131) ||
225  (block.header().getID() == 129)) {
226  etasign = -1;
227  }
228 
229  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
230 
231  int mpEta = etasign*(raw_data & 0x3F);
232  jet.setHwEta(CaloTools::caloEta(mpEta));
233  jet.setHwPhi((raw_data >> 6) & 0x7F);
234  jet.setHwPt((raw_data >> 13) & 0xFFFF);
235  jet.setHwQual((raw_data>>29) & 0x1 );
236 
237  if (jet.hwPt()==0) continue;
238 
239  LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual " << jet.hwQual();
240 
241  jet.setP4( l1t::CaloTools::p4MP(&jet) );
242  res1_->push_back(0,jet);
243 
244  }
245 
246  // ===== EGammas =====
247 
248  // Two EGammas
249 
250 
251  for (unsigned nEG=0; nEG < 2; nEG++){
252 
253  raw_data = block.payload()[feg+nEG];
254 
255  if (raw_data == 0)
256  continue;
257 
258  l1t::EGamma eg = l1t::EGamma();
259 
260  int etasign = 1;
261  if ((block.header().getID() == 125) ||
262  (block.header().getID() == 131) ||
263  (block.header().getID() == 129)) {
264  etasign = -1;
265  }
266 
267  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
268 
269  eg.setHwEta(etasign*((raw_data >> 3) & 0x3F));
270  eg.setHwPhi((raw_data >> 9) & 0x7F);
271  eg.setHwPt((raw_data >> 20) & 0xFFF);
272  eg.setHwIso((raw_data>>1) & 0x3);
273  eg.setHwQual((raw_data>>16) & 0xf );
274 
275  if (eg.hwPt()==0) continue;
276 
277  LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual " << eg.hwQual();
278 
279  eg.setP4( l1t::CaloTools::p4MP(&eg) );
280  res3_->push_back(0,eg);
281  }
282 
283 
284  // ===== Taus =====
285 
286  // Two taus
287 
288  for (unsigned nTau=0; nTau < 2; nTau++){
289 
290  raw_data = block.payload()[ftau+nTau];
291 
292  if (raw_data == 0)
293  continue;
294 
295  l1t::Tau tau = l1t::Tau();
296 
297  int etasign = 1;
298  if ((block.header().getID() == 125) ||
299  (block.header().getID() == 131) ||
300  (block.header().getID() == 129)) {
301  etasign = -1;
302  }
303 
304  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
305 
306  tau.setHwEta(etasign*((raw_data >> 3) & 0x3F));
307  tau.setHwPhi((raw_data >> 9) & 0x7F);
308  tau.setHwPt((raw_data >> 20) & 0xFFF);
309  tau.setHwIso((raw_data>>1) & 0x3);
310  tau.setHwQual((raw_data>>16) & 0xf );
311 
312  if (tau.hwPt()==0) continue;
313 
314  LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual " << tau.hwQual();
315 
316  tau.setP4( l1t::CaloTools::p4MP(&tau) );
317  res4_->push_back(0,tau);
318  }
319 
320  // ===== Aux =====
321  raw_data = block.payload()[faux];
322 
323  // create a sum object for each type of HF sum
324  l1t::EtSum mbp0 = l1t::EtSum();
325  l1t::EtSum mbm0 = l1t::EtSum();
326  l1t::EtSum mbm1 = l1t::EtSum();
327  l1t::EtSum mbp1 = l1t::EtSum();
328  l1t::EtSum towCount = l1t::EtSum();
329 
330  // readout the sums only if the correct block is being processed (first frame of AUX)
331  switch(block.header().getID()){
332  case 121: // this should correspond to the first link
333  // read 4 bits starting at position 24 (24 -> 28)
334  mbp0.setHwPt( ( raw_data >> 24 ) & 0xF );
336 
337  // read 4 bits starting at position 16 (16 -> 20)
338  mbm0.setHwPt( ( raw_data >> 16 ) & 0xF );
340 
341  // read 4 bits starting at position 8 (8 -> 12)
342  mbp1.setHwPt( ( raw_data >> 8 ) & 0xF );
344 
345  // read the first 4 bits by masking with 0xF
346  mbm1.setHwPt( raw_data & 0xF );
348 
349  LogDebug("L1T") << "mbp0 HF sum: " << mbp0.hwPt();
350  LogDebug("L1T") << "mbm0 HF sum: " << mbm0.hwPt();
351  LogDebug("L1T") << "mbp1 HF sum: " << mbp1.hwPt();
352  LogDebug("L1T") << "mbm1 HF sum: " << mbm1.hwPt();
353 
354  res2_->push_back(0,mbp0);
355  res2_->push_back(0,mbm0);
356  res2_->push_back(0,mbp1);
357  res2_->push_back(0,mbm1);
358  break;
359  case 127:
360  towCount.setHwPt( raw_data & 0x1FFF );
361  towCount.setType( l1t::EtSum::kTowerCount );
362  res2_->push_back(0,towCount);
363  break;
364  default:
365  break;
366  }
367 
368  return true;
369  }
370 }
371 }
372 
#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:372
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