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 
l1t::EtSum::kTotalHty
Definition: EtSum.h:30
l1t::CaloTools::caloEta
static int caloEta(int ietaMP)
Definition: CaloTools.cc:234
l1t::EtSum::setType
void setType(EtSumType type)
Definition: EtSum.cc:11
l1t::EtSum::kTotalEtx
Definition: EtSum.h:27
CaloTools.h
l1t::L1Candidate::hwPhi
int hwPhi() const
Definition: L1Candidate.h:37
MessageLogger.h
metsig::tau
Definition: SignAlgoResolutions.h:49
L1TRate_Offline_cfi.Tau
Tau
Definition: L1TRate_Offline_cfi.py:43
l1t::L1Candidate::hwQual
int hwQual() const
Definition: L1Candidate.h:38
l1t::EtSum::kTotalEty
Definition: EtSum.h:28
l1t::stage2::MPUnpacker::unpack
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: MPUnpacker.cc:14
l1t::stage2::MPUnpacker
Definition: MPUnpacker.h:8
l1t::EtSum::kTotalHt
Definition: EtSum.h:24
l1t::Tau
Definition: Tau.h:20
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
l1t::L1Candidate::hwEta
int hwEta() const
Definition: L1Candidate.h:36
l1t::L1Candidate::setHwQual
void setHwQual(int qual)
Definition: L1Candidate.h:31
L1TRate_cfi.Jet
Jet
Definition: L1TRate_cfi.py:43
UnpackerFactory.h
l1t::Jet
Definition: Jet.h:20
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
l1t
delete x;
Definition: CaloConfig.h:22
l1t::EtSum
Definition: EtSum.h:20
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
l1t::EGamma
Definition: EGamma.h:20
l1t::L1Candidate::setHwPt
void setHwPt(int pt)
Definition: L1Candidate.h:28
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
l1t::L1Candidate::setHwEta
void setHwEta(int eta)
Definition: L1Candidate.h:29
SiStripSourceConfigTier0_cff.stage2
stage2
Definition: SiStripSourceConfigTier0_cff.py:71
MPUnpacker.h
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
metsig::jet
Definition: SignAlgoResolutions.h:47
l1t::UnpackerCollections
Definition: UnpackerCollections.h:9
HLT_FULL_cff.EGamma
EGamma
Definition: HLT_FULL_cff.py:3928
l1t::L1Candidate::setHwIso
void setHwIso(int iso)
Definition: L1Candidate.h:32
l1t::L1Candidate::hwPt
int hwPt() const
Definition: L1Candidate.h:35
amc
Definition: AMCSpec.h:8
l1t::EtSum::kTotalHtx
Definition: EtSum.h:29
DEFINE_L1T_UNPACKER
#define DEFINE_L1T_UNPACKER(type)
Definition: UnpackerFactory.h:23
l1t::L1Candidate::setHwPhi
void setHwPhi(int phi)
Definition: L1Candidate.h:30
CaloCollections.h
l1t::Block
Definition: Block.h:70
l1t::EtSum::kTotalEt
Definition: EtSum.h:23
l1t::CaloTools::p4MP
static math::PtEtaPhiMLorentzVector p4MP(l1t::L1Candidate *)
Definition: CaloTools.cc:369