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.));
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(
77  block,
78  res,
79  [](l1t::EGamma eg) {
80  eg.setHwIso(1);
81  return eg;
82  },
83  true,
84  true,
85  false);
86  }
87 
89  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
90  return process(block, res, [](const l1t::EGamma& eg) { return eg; }, true, false, false);
91  }
92 
94  auto res = static_cast<CaloCollections*>(coll)->getJets();
95  return process(block, res, [](const l1t::Jet& j) { return j; }, true, true, false);
96  }
97 
99  auto res = static_cast<CaloCollections*>(coll)->getJets();
100  return process(
101  block,
102  res,
103  [](l1t::Jet j) {
104  j.setHwQual(j.hwQual() | 2);
105  return j;
106  },
107  true,
108  false,
109  false);
110  }
111 
113  auto res = static_cast<CaloCollections*>(coll)->getTaus();
114  return process(block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
115  }
116 
118  auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
119  return process(block, res, [](const l1t::Tau& t) { return t; }, true, true, true);
120  }
121 
123  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
124  return process(
125  block,
126  res,
127  [](l1t::EGamma eg) {
128  eg.setHwIso(1);
129  return eg;
130  },
131  false,
132  true,
133  false);
134  }
135 
137  auto res = static_cast<CaloCollections*>(coll)->getEGammas();
138  return process(block, res, [](const l1t::EGamma& eg) { return eg; }, false, false, false);
139  }
140 
142  auto res = static_cast<CaloCollections*>(coll)->getJets();
143  return process(block, res, [](const l1t::Jet& j) { return j; }, false, true, false);
144  }
145 
147  auto res = static_cast<CaloCollections*>(coll)->getJets();
148  return process(
149  block,
150  res,
151  [](l1t::Jet j) {
152  j.setHwQual(j.hwQual() | 2);
153  return j;
154  },
155  false,
156  false,
157  false);
158  }
159 
161  auto res = static_cast<CaloCollections*>(coll)->getTaus();
162  return process(block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
163  }
164 
166  auto res = static_cast<CaloCollections*>(coll)->getIsoTaus();
167  return process(block, res, [](const l1t::Tau& t) { return t; }, false, true, true);
168  }
169  } // namespace stage1
170 } // namespace l1t
171 
constexpr int32_t ceil(float num)
bool unpack(const Block &block, UnpackerCollections *coll) override
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)
delete x;
Definition: CaloConfig.h:22
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
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
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)
bool unpack(const Block &block, UnpackerCollections *coll) override
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
long double T
#define LogDebug(id)