CMS 3D CMS Logo

MPUnpacker.cc
Go to the documentation of this file.
1 #define EDM_ML_DEBUG 1
2 
4 
6 
8 
9 #include "CaloCollections.h"
10 #include "MPUnpacker.h"
11 
12 namespace l1t {
13  namespace stage2 {
15  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize()
16  << " AMC = " << block.amc().getAMCNumber();
17 
18  // check this is the correct MP
19  unsigned int amc = block.amc().getAMCNumber();
20  unsigned int bxid = block.amc().getBX();
21  LogDebug("L1T") << "Unpacking AMC " << amc << " for BX " << bxid;
22 
23  auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
24  auto res2_ = static_cast<CaloCollections*>(coll)->getMPEtSums();
25  auto res3_ = static_cast<CaloCollections*>(coll)->getMPEGammas();
26  auto res4_ = static_cast<CaloCollections*>(coll)->getMPTaus();
27 
28  res1_->setBXRange(0, 0);
29  res2_->setBXRange(0, 0);
30  res3_->setBXRange(0, 0);
31  res4_->setBXRange(0, 0);
32 
33  // Initialise frame indices for each data type
34  int unsigned fet = 0;
35  int unsigned fht = 1;
36  int unsigned fjet = 6;
37  int unsigned feg = 2;
38  int unsigned ftau = 4;
39 
40  // ===== Jets and Sums =====
41 
42  // ET / MET(x) / MET (y)
43 
44  uint32_t raw_data = block.payload()[fet];
45 
47 
48  et.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFFFF) << 16) >> 16);
49  //et.setHwPt(raw_data & 0xFFFFF);
50  switch (block.header().getID()) {
51  case 123:
52  et.setType(l1t::EtSum::kTotalEt);
53  break;
54  case 121:
55  et.setType(l1t::EtSum::kTotalEtx);
56  break;
57  case 127:
58  et.setType(l1t::EtSum::kTotalEty);
59  break;
60  case 125:
61  et.setType(l1t::EtSum::kTotalEt);
62  break;
63  case 131:
64  et.setType(l1t::EtSum::kTotalEtx);
65  break;
66  case 129:
67  et.setType(l1t::EtSum::kTotalEty);
68  break;
69  default:
70  break;
71  }
72 
73  LogDebug("L1T") << "ET/METx/METy: pT " << et.hwPt();
74 
75  res2_->push_back(0, et);
76 
77  // HT / MHT(x)/ MHT (y)
78 
79  raw_data = block.payload()[fht];
80 
81  l1t::EtSum ht = l1t::EtSum();
82 
83  //ht.setHwPt(raw_data & 0xFFFFF);
84  ht.setHwPt(static_cast<int32_t>(uint32_t(raw_data & 0xFFFFFF) << 16) >> 16);
85  switch (block.header().getID()) {
86  case 123:
88  break;
89  case 121:
91  break;
92  case 127:
94  break;
95  case 125:
97  break;
98  case 131:
100  break;
101  case 129:
103  break;
104  default:
105  break;
106  }
107 
108  LogDebug("L1T") << "HT/MHTx/MHTy: pT " << ht.hwPt();
109 
110  res2_->push_back(0, ht);
111 
112  // Two jets
113  for (unsigned nJet = 0; nJet < 2; nJet++) {
114  raw_data = block.payload()[fjet + nJet];
115 
116  if (raw_data == 0)
117  continue;
118 
119  l1t::Jet jet = l1t::Jet();
120 
121  int etasign = 1;
122  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
123  etasign = -1;
124  }
125 
126  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
127 
128  int mpEta = etasign * (raw_data & 0x3F);
129  jet.setHwEta(CaloTools::caloEta(mpEta));
130  jet.setHwPhi((raw_data >> 6) & 0x7F);
131  jet.setHwPt((raw_data >> 13) & 0xFFFF);
132 
133  LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual "
134  << jet.hwQual();
135 
136  jet.setP4(l1t::CaloTools::p4MP(&jet));
137  res1_->push_back(0, jet);
138 
139  // Push them back in the right place (for checking sorting)
140  /*
141  int blockID = block.header().getID();
142  int nPos=0, nNeg=0;
143  for (unsigned i=0; i<res1_->size(0); i++)
144  res1_->at(0,i).hwEta()>0 ? nPos++ : nNeg++;
145 
146  if (nJet==1) res1_->push_back(0,jet);
147  else if (nJet==0) {
148  if (blockID==123) {
149  res1_->push_back(0,jet);
150  }
151  if (blockID==121) {
152  if (nPos==1) res1_->push_back(0,jet);
153  else if (nPos==2) res1_->insert(0,1,jet);
154  }
155  if (blockID==127) {
156  if (nPos==2) res1_->push_back(0,jet);
157  else if (nPos>2) res1_->insert(0,2,jet);
158  }
159  if (blockID==125) {
160  res1_->push_back(0,jet);
161  }
162  if (blockID==131) {
163  if (nNeg==1) res1_->push_back(0,jet);
164  else if (nNeg==2) res1_->insert(0,nPos+1,jet);
165  }
166  if (blockID==129) {
167  if (nNeg==2) res1_->push_back(0,jet);
168  else if (nNeg>2) res1_->insert(0,nPos+2,jet);
169  }
170  }
171  */
172  }
173 
174  // ===== EGammas =====
175 
176  // Two EGammas
177 
178  for (unsigned nEG = 0; nEG < 2; nEG++) {
179  raw_data = block.payload()[feg + nEG];
180 
181  if (raw_data == 0)
182  continue;
183 
184  l1t::EGamma eg = l1t::EGamma();
185 
186  int etasign = 1;
187  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
188  etasign = -1;
189  }
190 
191  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
192 
193  eg.setHwEta(etasign * ((raw_data >> 4) & 0x3F));
194  eg.setHwPhi((raw_data >> 10) & 0x7F);
195  eg.setHwPt((raw_data >> 21) & 0x3FF);
196  eg.setHwQual(((raw_data >> 3) & 0x1) + (((raw_data >> 1) & 0x1) << 2)); //ECalFG + EGammaLikeShape
197  eg.setHwIso(raw_data & 0x1);
198 
199  LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual "
200  << eg.hwQual();
201 
202  eg.setP4(l1t::CaloTools::p4MP(&eg));
203  res3_->push_back(0, eg);
204  }
205 
206  // ===== Taus =====
207 
208  // Two taus
209 
210  for (unsigned nTau = 0; nTau < 2; nTau++) {
211  raw_data = block.payload()[ftau + nTau];
212 
213  if (raw_data == 0)
214  continue;
215 
216  l1t::Tau tau = l1t::Tau();
217 
218  int etasign = 1;
219  if ((block.header().getID() == 125) || (block.header().getID() == 131) || (block.header().getID() == 129)) {
220  etasign = -1;
221  }
222 
223  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
224 
225  tau.setHwEta(etasign * ((raw_data >> 4) & 0x3F));
226  tau.setHwPhi((raw_data >> 10) & 0x7F);
227  tau.setHwPt((raw_data >> 21) & 0x3FF);
228  tau.setHwQual(((raw_data >> 3) & 0x1) + (((raw_data >> 1) & 0x1) << 2));
229  tau.setHwIso(raw_data & 0x1);
230 
231  // tau.setHwEta(etasign*((raw_data >> 9) & 0x7F));
232  // tau.setHwPhi((raw_data >> 17) & 0xFF);
233  // tau.setHwPt(raw_data & 0x1FF);
234  // tau.setHwQual(((raw_data >> 26) & 0x1)); //ECalFG + TauLikeShape
235  // tau.setHwIso(((raw_data >> 25) & 0x1) + ((raw_data >> 26) & 0x1) + ((raw_data >> 27) & 0x1));
236 
237  LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual "
238  << tau.hwQual();
239 
240  tau.setP4(l1t::CaloTools::p4MP(&tau));
241  res4_->push_back(0, tau);
242  }
243 
244  return true;
245  }
246  } // namespace stage2
247 } // namespace l1t
248 
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: MPUnpacker.cc:14
Definition: Tau.h:20
int hwPhi() const
Definition: L1Candidate.h:37
static math::PtEtaPhiMLorentzVector p4MP(l1t::L1Candidate *)
Definition: CaloTools.cc:369
void setHwQual(int qual)
Definition: L1Candidate.h:31
delete x;
Definition: CaloConfig.h:22
void setType(EtSumType type)
Definition: EtSum.cc:11
int hwQual() const
Definition: L1Candidate.h:38
Definition: Jet.h:20
int hwEta() const
Definition: L1Candidate.h:36
void setHwPhi(int phi)
Definition: L1Candidate.h:30
void setHwIso(int iso)
Definition: L1Candidate.h:32
int hwPt() const
Definition: L1Candidate.h:35
static int caloEta(int ietaMP)
Definition: CaloTools.cc:234
void setHwPt(int pt)
Definition: L1Candidate.h:28
#define DEFINE_L1T_UNPACKER(type)
void setHwEta(int eta)
Definition: L1Candidate.h:29
Definition: AMCSpec.h:8
void setP4(const LorentzVector &p4) final
set 4-momentum
#define LogDebug(id)