CMS 3D CMS Logo

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