CMS 3D CMS Logo

PhysCandUnpacker.cc
Go to the documentation of this file.
3 
4 #include "CaloCollections.h"
5 #include "PhysCandUnpacker.h"
6 
7 template <typename T, typename F>
8 bool process(const l1t::Block& block, BXVector<T>* coll, F modify, bool isleft, bool isfirst, bool istau) {
9  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
10 
11  int nBX, firstBX, lastBX;
12  nBX = int(ceil(block.header().getSize() / 2.));
13  l1t::getBXRange(nBX, firstBX, lastBX);
14 
15  coll->setBXRange(firstBX, lastBX);
16 
17  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
18 
19  // Initialise index
20  int unsigned i = 0;
21 
22  // Loop over multiple BX and then number of jets filling jet collection
23  for (int bx = firstBX; bx <= lastBX; bx++) {
24  if (!istau)
25  coll->resize(bx, 8);
26  else
27  coll->resize(bx, 4);
28 
29  uint32_t raw_data0 = block.payload()[i++];
30  uint32_t raw_data1 = block.payload()[i++];
31 
32  uint16_t candbit[2];
33  candbit[0] = raw_data0 & 0xFFFF;
34  candbit[1] = raw_data1 & 0xFFFF;
35 
36  for (int icand = 0; icand < 2; icand++) {
37  int candPt = candbit[icand] & 0x3F;
38  int candEta = (candbit[icand] >> 6) & 0x7;
39  int candEtasign = (candbit[icand] >> 9) & 0x1;
40  int candPhi = (candbit[icand] >> 10) & 0x1F;
41 
42  T cand;
43  cand.setHwPt(candPt);
44  cand.setHwEta((candEtasign << 3) | candEta);
45  cand.setHwPhi(candPhi);
46  //int qualflag=cand.hwQual();
47  //qualflag|= (candPt == 0x3F);
48  //cand.setHwQual(qualflag);
49 
50  /* std::cout << "cand: eta " << cand.hwEta() << " phi " << cand.hwPhi() << " pT " << cand.hwPt() << " qual " << cand.hwQual() << std::endl; */
51  //std::cout << cand.hwPt() << " @ " << cand.hwEta() << ", " << cand.hwPhi() << " > " << cand.hwQual() << " > " << cand.hwIso() << std::endl;
52 
53  if (isfirst) {
54  if (isleft) {
55  coll->set(bx, 2 * icand, modify(cand));
56  } else if (!isleft) {
57  coll->set(bx, 2 * icand + 1, modify(cand));
58  }
59  } else if (!isfirst) {
60  if (isleft) {
61  coll->set(bx, 2 * icand + 4, modify(cand));
62  } else if (!isleft) {
63  coll->set(bx, 2 * icand + 5, modify(cand));
64  }
65  }
66  }
67  }
68 
69  return true;
70 }
71 
72 namespace l1t {
73  namespace stage1 {
75  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
76  return process(block,
77  res,
78  [](l1t::EGamma eg) {
79  eg.setHwIso(1);
80  return eg;
81  },
82  true,
83  true,
84  false);
85  }
86 
88  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
89  return process(block, res, [](const l1t::EGamma& eg) { return eg; }, true, false, false);
90  }
91 
93  auto res = static_cast<CaloCollections*>(coll)->getJets();
94  return process(block, res, [](const l1t::Jet& j) { return j; }, true, true, false);
95  }
96 
98  auto res = static_cast<CaloCollections*>(coll)->getJets();
99  return process(block,
100  res,
101  [](l1t::Jet j) {
102  j.setHwQual(j.hwQual() | 2);
103  return j;
104  },
105  true,
106  false,
107  false);
108  }
109 
111  auto res = static_cast<CaloCollections*>(coll)->getTaus();
112  return process(block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
113  }
114 
116  auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
117  return process(block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
118  }
119 
121  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
122  return process(block,
123  res,
124  [](l1t::EGamma eg) {
125  eg.setHwIso(1);
126  return eg;
127  },
128  false,
129  true,
130  false);
131  }
132 
134  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
135  return process(block, res, [](const l1t::EGamma& eg) { return eg; }, false, false, false);
136  }
137 
139  auto res = static_cast<CaloCollections*>(coll)->getJets();
140  return process(block, res, [](const l1t::Jet& j) { return j; }, false, true, false);
141  }
142 
144  auto res = static_cast<CaloCollections*>(coll)->getJets();
145  return process(block,
146  res,
147  [](l1t::Jet j) {
148  j.setHwQual(j.hwQual() | 2);
149  return j;
150  },
151  false,
152  false,
153  false);
154  }
155 
157  auto res = static_cast<CaloCollections*>(coll)->getTaus();
158  return process(block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
159  }
160 
162  auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
163  return process(block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
164  }
165  } // namespace stage1
166 } // namespace l1t
167 
#define LogDebug(id)
bool unpack(const Block &block, UnpackerCollections *coll) override
const std::vector< uint32_t > & payload() const
Definition: Block.h:70
unsigned int getID() const
Definition: Block.h:27
bool unpack(const Block &block, UnpackerCollections *coll) override
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: Tau.h:20
void getBXRange(int nbx, int &first, int &last)
BlockHeader header() const
Definition: Block.h:69
void setHwQual(int qual)
Definition: L1Candidate.h:31
delete x;
Definition: CaloConfig.h:22
constexpr int32_t ceil(float num)
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: Electron.h:6
bool unpack(const Block &block, UnpackerCollections *coll) override
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: Jet.h:20
bool unpack(const Block &block, UnpackerCollections *coll) override
int hwQual() const
Definition: L1Candidate.h:38
void set(int bx, unsigned i, const T &object)
bool unpack(const Block &block, UnpackerCollections *coll) override
void setHwIso(int iso)
Definition: L1Candidate.h:32
JetCorrectorParametersCollection coll
Definition: classes.h:10
bool unpack(const Block &block, UnpackerCollections *coll) override
void resize(int bx, unsigned size)
bool process(const l1t::Block &block, BXVector< T > *coll, F modify, bool isleft, bool isfirst, bool istau)
void setBXRange(int bxFirst, int bxLast)
bool unpack(const Block &block, UnpackerCollections *coll) override
bool unpack(const Block &block, UnpackerCollections *coll) override
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:28
bool unpack(const Block &block, UnpackerCollections *coll) override
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
long double T