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