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