CMS 3D CMS Logo

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