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