CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MPUnpacker_0x10010010.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 {
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 = 2;
50  int unsigned feg = 4;
51  int unsigned ftau = 6;
52  int unsigned fjet = 8;
53  // int unsigned faux = 10;
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  switch(block.header().getID()){
64  case 123:
66  et.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
67  break;
68  case 121:
70  et.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
71  break;
72  case 127:
74  et.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
75  break;
76  case 125:
78  et.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
79  break;
80  case 131:
82  et.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
83  break;
84  case 129:
86  et.setHwPt( static_cast<int32_t>( uint32_t(raw_data) ) );
87  break;
88  default:
89  break;
90  }
91 
92  LogDebug("L1T") << "ET/METx/METy: pT " << et.hwPt();
93 
94  res2_->push_back(0,et);
95 
96 
97  // HT / MHT(x)/ MHT (y)
98 
99  raw_data = block.payload()[fht];
100 
101  l1t::EtSum ht = l1t::EtSum();
102 
103  //ht.setHwPt(raw_data & 0xFFFFF);
104  ht.setHwPt( static_cast<int32_t>( uint32_t(raw_data & 0xFFFFFF) << 16 ) >> 16 );
105  switch(block.header().getID()){
106  case 123: ht.setType(l1t::EtSum::kTotalHt); break;
107  case 121: ht.setType(l1t::EtSum::kTotalHtx); break;
108  case 127: ht.setType(l1t::EtSum::kTotalHty); break;
109  case 125: ht.setType(l1t::EtSum::kTotalHt); break;
110  case 131: ht.setType(l1t::EtSum::kTotalHtx); break;
111  case 129: ht.setType(l1t::EtSum::kTotalHty); break;
112  default: break;
113  }
114 
115  LogDebug("L1T") << "HT/MHTx/MHTy: pT " << ht.hwPt();
116 
117  res2_->push_back(0,ht);
118 
119  // Two jets
120  for (unsigned nJet=0; nJet < 2; nJet++){
121 
122  raw_data = block.payload()[fjet+nJet];
123 
124  if (raw_data == 0)
125  continue;
126 
127  l1t::Jet jet = l1t::Jet();
128 
129  int etasign = 1;
130  if ((block.header().getID() == 125) ||
131  (block.header().getID() == 131) ||
132  (block.header().getID() == 129)) {
133  etasign = -1;
134  }
135 
136  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
137 
138  int mpEta = etasign*(raw_data & 0x3F);
139  jet.setHwEta(CaloTools::caloEta(mpEta));
140  jet.setHwPhi((raw_data >> 6) & 0x7F);
141  jet.setHwPt((raw_data >> 13) & 0xFFFF);
142  jet.setHwQual((raw_data>>29) & 0x1 );
143 
144  if (jet.hwPt()==0) continue;
145 
146  LogDebug("L1T") << "Jet: eta " << jet.hwEta() << " phi " << jet.hwPhi() << " pT " << jet.hwPt() << " qual " << jet.hwQual();
147 
148  jet.setP4( l1t::CaloTools::p4MP(&jet) );
149  res1_->push_back(0,jet);
150 
151  }
152 
153  // ===== EGammas =====
154 
155  // Two EGammas
156 
157 
158  for (unsigned nEG=0; nEG < 2; nEG++){
159 
160  raw_data = block.payload()[feg+nEG];
161 
162  if (raw_data == 0)
163  continue;
164 
165  l1t::EGamma eg = l1t::EGamma();
166 
167  int etasign = 1;
168  if ((block.header().getID() == 125) ||
169  (block.header().getID() == 131) ||
170  (block.header().getID() == 129)) {
171  etasign = -1;
172  }
173 
174  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
175 
176  eg.setHwEta(etasign*((raw_data >> 3) & 0x3F));
177  eg.setHwPhi((raw_data >> 9) & 0x7F);
178  eg.setHwPt((raw_data >> 20) & 0xFFF);
179  eg.setHwIso((raw_data>>1) & 0x3);
180  eg.setHwQual((raw_data>>16) & 0xf );
181 
182  if (eg.hwPt()==0) continue;
183 
184  LogDebug("L1T") << "Egamma: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " qual " << eg.hwQual();
185 
186  eg.setP4( l1t::CaloTools::p4MP(&eg) );
187  res3_->push_back(0,eg);
188  }
189 
190 
191  // ===== Taus =====
192 
193  // Two taus
194 
195  for (unsigned nTau=0; nTau < 2; nTau++){
196 
197  raw_data = block.payload()[ftau+nTau];
198 
199  if (raw_data == 0)
200  continue;
201 
202  l1t::Tau tau = l1t::Tau();
203 
204  int etasign = 1;
205  if ((block.header().getID() == 125) ||
206  (block.header().getID() == 131) ||
207  (block.header().getID() == 129)) {
208  etasign = -1;
209  }
210 
211  LogDebug("L1") << "block ID=" << block.header().getID() << " etasign=" << etasign;
212 
213  tau.setHwEta(etasign*((raw_data >> 3) & 0x3F));
214  tau.setHwPhi((raw_data >> 9) & 0x7F);
215  tau.setHwPt((raw_data >> 20) & 0xFFF);
216  tau.setHwIso((raw_data>>1) & 0x3);
217  tau.setHwQual((raw_data>>16) & 0xf );
218 
219  if (tau.hwPt()==0) continue;
220 
221  LogDebug("L1T") << "Tau: eta " << tau.hwEta() << " phi " << tau.hwPhi() << " pT " << tau.hwPt() << " qual " << tau.hwQual();
222 
223  tau.setP4( l1t::CaloTools::p4MP(&tau) );
224  res4_->push_back(0,tau);
225  }
226 
227  return true;
228  }
229 }
230 }
231 
#define LogDebug(id)
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
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
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