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  jet.setHwEta(etasign*(raw_data & 0x3F));
122  jet.setHwPhi((raw_data >> 6) & 0x7F);
123  jet.setHwPt((raw_data >> 13) & 0xFFFF);
124 
125  LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual " << jet.hwQual();
126 
127  jet.setP4( l1t::CaloTools::p4MP(&jet) );
128  res1_->push_back(0,jet);
129 
130  // Push them back in the right place (for checking sorting)
131  /*
132  int blockID = block.header().getID();
133  int nPos=0, nNeg=0;
134  for (unsigned i=0; i<res1_->size(0); i++)
135  res1_->at(0,i).hwEta()>0 ? nPos++ : nNeg++;
136 
137  if (nJet==1) res1_->push_back(0,jet);
138  else if (nJet==0) {
139  if (blockID==123) {
140  res1_->push_back(0,jet);
141  }
142  if (blockID==121) {
143  if (nPos==1) res1_->push_back(0,jet);
144  else if (nPos==2) res1_->insert(0,1,jet);
145  }
146  if (blockID==127) {
147  if (nPos==2) res1_->push_back(0,jet);
148  else if (nPos>2) res1_->insert(0,2,jet);
149  }
150  if (blockID==125) {
151  res1_->push_back(0,jet);
152  }
153  if (blockID==131) {
154  if (nNeg==1) res1_->push_back(0,jet);
155  else if (nNeg==2) res1_->insert(0,nPos+1,jet);
156  }
157  if (blockID==129) {
158  if (nNeg==2) res1_->push_back(0,jet);
159  else if (nNeg>2) res1_->insert(0,nPos+2,jet);
160  }
161  }
162  */
163  }
164 
165  // ===== EGammas =====
166 
167  // Two EGammas
168 
169 
170  for (unsigned nEG=0; nEG < 2; nEG++){
171 
172  raw_data = block.payload()[feg+nEG];
173 
174  if (raw_data == 0)
175  continue;
176 
177  l1t::EGamma eg = l1t::EGamma();
178 
179  int etasign = 1;
180  if ((block.header().getID() == 125) ||
181  (block.header().getID() == 131) ||
182  (block.header().getID() == 129)) {
183  etasign = -1;
184  }
185 
186  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
187 
188  eg.setHwEta(etasign*((raw_data >> 4) & 0x3F));
189  eg.setHwPhi((raw_data >> 10) & 0x7F);
190  eg.setHwPt((raw_data >> 21) & 0x3FF);
191  eg.setHwQual(((raw_data >> 3) & 0x1) + (((raw_data >> 1) & 0x1) << 2)); //ECalFG + EGammaLikeShape
192  eg.setHwIso(raw_data & 0x1);
193 
194  LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual " << eg.hwQual();
195 
196  eg.setP4( l1t::CaloTools::p4MP(&eg) );
197  res3_->push_back(0,eg);
198  }
199 
200 
201  // ===== Taus =====
202 
203  // Two taus
204 
205  for (unsigned nTau=0; nTau < 2; nTau++){
206 
207  raw_data = block.payload()[ftau+nTau];
208 
209  if (raw_data == 0)
210  continue;
211 
212  l1t::Tau tau = l1t::Tau();
213 
214  int etasign = 1;
215  if ((block.header().getID() == 125) ||
216  (block.header().getID() == 131) ||
217  (block.header().getID() == 129)) {
218  etasign = -1;
219  }
220 
221  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
222 
223  tau.setHwEta(etasign*((raw_data >> 4) & 0x3F));
224  tau.setHwPhi((raw_data >> 10) & 0x7F);
225  tau.setHwPt((raw_data >> 21) & 0x3FF);
226  tau.setHwQual(((raw_data >> 3) & 0x1) + (((raw_data >> 1) & 0x1) << 2));
227  tau.setHwIso(raw_data & 0x1);
228 
229 
230  // tau.setHwEta(etasign*((raw_data >> 9) & 0x7F));
231  // tau.setHwPhi((raw_data >> 17) & 0xFF);
232  // tau.setHwPt(raw_data & 0x1FF);
233  // tau.setHwQual(((raw_data >> 26) & 0x1)); //ECalFG + TauLikeShape
234  // tau.setHwIso(((raw_data >> 25) & 0x1) + ((raw_data >> 26) & 0x1) + ((raw_data >> 27) & 0x1));
235 
236  LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual " << tau.hwQual();
237 
238  tau.setP4( l1t::CaloTools::p4MP(&tau) );
239  res4_->push_back(0,tau);
240  }
241 
242 
243 
244  return true;
245  }
246 }
247 }
248 
#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:242
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
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