test
CMS 3D CMS Logo

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