CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CaloLayer1Packer.cc
Go to the documentation of this file.
3 
5 
6 #include "CaloLayer1Packer.h"
7 
8 namespace l1t {
9  namespace stage2 {
10 
11  // max_iEta_HcalTP = 41; // barrel <= 16, endcap <= 28, hf <= 41
12  // there are two TT29’s: one in HE readout in TT28 and another in HF readout in TT30
13  // max_iPhi_HcalTP = 72;
14 
17  event.getByToken(static_cast<const CaloLayer1Tokens*>(toks)->getEcalDigiToken(), ecalDigis);
19  event.getByToken(static_cast<const CaloLayer1Tokens*>(toks)->getHcalDigiToken(), hcalDigis);
21  event.getByToken(static_cast<const CaloLayer1Tokens*>(toks)->getCaloRegionToken(), caloRegions);
22 
23  std::vector<uint32_t> load;
24  load.resize(192, 0u);
25 
26  auto ctp7_phi = board();
27  uint32_t* ptr = load.data();
28  UCTCTP7RawData ctp7Data(ptr);
29  makeECalTPGs(ctp7_phi, ctp7Data, ecalDigis.product());
30  makeHCalTPGs(ctp7_phi, ctp7Data, hcalDigis.product());
31  makeHFTPGs(ctp7_phi, ctp7Data, hcalDigis.product());
32  makeRegions(ctp7_phi, ctp7Data, caloRegions.product());
33 
34  unsigned bx_per_l1a = 1;
35  // CTP7 uses CMS scheme, starting at 0
36  // TODO: expected +2, but +1 apparently?
37  unsigned calo_bxid = (event.bunchCrossing() + 1) % 3564;
38 
39  // a la CTP7Payload::getHeader()
40  unsigned blockId = 0;
41  unsigned blockSize = 192;
42  unsigned capId = 0;
43  unsigned blockFlags = ((bx_per_l1a & 0xf) << 16) | (calo_bxid & 0xfff);
44  BlockHeader hdr(blockId, blockSize, capId, blockFlags, CTP7);
45  Block block(hdr, &*load.begin(), &*load.end());
46 
47  Blocks res;
48  res.push_back(block);
49  return res;
50  }
51 
52  void CaloLayer1Packer::makeECalTPGs(uint32_t lPhi,
53  UCTCTP7RawData& ctp7Data,
54  const EcalTrigPrimDigiCollection* ecalTPGs) {
56  for (uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
57  int cPhi = -1 + lPhi * 4 + iPhi; // Calorimeter phi index
58  if (cPhi == 0)
59  cPhi = 72;
60  else if (cPhi == -1)
61  cPhi = 71;
62  else if (cPhi < -1) {
63  edm::LogError("CaloLayer1Packer") << "Major error in makeECalTPGs" << std::endl;
64  return;
65  }
66  for (int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
67  if (cEta != 0) { // Calorimeter eta = 0 is invalid
68  bool negativeEta = false;
69  if (cEta < 0)
70  negativeEta = true;
71  uint32_t iEta = abs(cEta);
72 
73  int zSide = cEta / ((int)iEta);
74  const EcalSubdetector ecalTriggerTower =
76  EcalTrigTowerDetId id(zSide, ecalTriggerTower, iEta, cPhi);
77  const auto& tp = ecalTPGs->find(id);
78  if (tp != ecalTPGs->end()) {
79  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->compressedEt());
80  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, tp->fineGrain());
81  }
82  }
83  }
84  }
85  }
86 
87  void CaloLayer1Packer::makeHCalTPGs(uint32_t lPhi,
88  UCTCTP7RawData& ctp7Data,
89  const HcalTrigPrimDigiCollection* hcalTPGs) {
91  for (uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
92  int cPhi = -1 + lPhi * 4 + iPhi; // Calorimeter phi index
93  if (cPhi == 0)
94  cPhi = 72;
95  else if (cPhi == -1)
96  cPhi = 71;
97  else if (cPhi < -1) {
98  edm::LogError("CaloLayer1Packer") << "Major error in makeHCalTPGs" << std::endl;
99  return;
100  }
101  for (int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
102  if (cEta != 0) { // Calorimeter eta = 0 is invalid
103  bool negativeEta = false;
104  if (cEta < 0)
105  negativeEta = true;
106  uint32_t iEta = abs(cEta);
107 
108  HcalTrigTowerDetId id(cEta, cPhi);
109  const auto tp = hcalTPGs->find(id);
110  if (tp != hcalTPGs->end()) {
111  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->SOI_compressedEt());
112  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, tp->SOI_fineGrain());
113  }
114  }
115  }
116  }
117  }
118 
119  void CaloLayer1Packer::makeHFTPGs(uint32_t lPhi,
120  UCTCTP7RawData& ctp7Data,
121  const HcalTrigPrimDigiCollection* hcalTPGs) {
123  for (uint32_t side = 0; side <= 1; side++) {
124  bool negativeEta = false;
125  if (side == 0)
126  negativeEta = true;
127  for (uint32_t iEta = 30; iEta <= 40; iEta++) {
128  for (uint32_t iPhi = 0; iPhi < 2; iPhi++) {
129  if (iPhi == 1 && iEta == 40)
130  iEta = 41;
131  int cPhi = 1 + lPhi * 4 + iPhi * 2; // Calorimeter phi index: 1, 3, 5, ... 71
132  if (iEta == 41)
133  cPhi -= 2; // Last two HF are 3, 7, 11, ...
134  cPhi = (cPhi + 69) % 72 + 1; // cPhi -= 2 mod 72
135  int cEta = iEta;
136  if (negativeEta)
137  cEta = -iEta;
138 
139  HcalTrigTowerDetId id(cEta, cPhi);
140  id.setVersion(1); // To not process these 1x1 HF TPGs with RCT
141  const auto tp = hcalTPGs->find(id);
142  if (tp != hcalTPGs->end()) {
143  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->SOI_compressedEt());
144  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, ((tp->SOI_fineGrain(1) << 1) | tp->SOI_fineGrain(0)));
145  }
146  }
147  }
148  }
149  }
150 
152  for (uint32_t side = 0; side <= 1; side++) {
153  bool negativeEta = false;
154  if (side == 0)
155  negativeEta = true;
156  for (uint32_t region = 0; region <= 6; region++) {
157  uint32_t lEta = 10 - region; // GCT eta goes 0-21, 0-3 -HF, 4-10 -B/E, 11-17 +B/E, 18-21 +HF
158  if (!negativeEta)
159  lEta = region + 11;
160 
161  L1CaloRegionDetId id(lEta, lPhi);
162  // Can't use find since not an edm::SortedCollection
163  // const L1CaloRegion& rtp = *regions->find(id);
164  for (const auto& rtp : *regions) {
165  if (rtp.id() == id) {
166  ctp7Data.setRegionSummary(negativeEta, region, rtp.raw());
167  break;
168  }
169  }
170  }
171  }
172  }
173 
174  } // namespace stage2
175 } // namespace l1t
176 
uint16_t *__restrict__ id
void setET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t et)
void makeHCalTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, const HcalTrigPrimDigiCollection *hcalTPGs)
Log< level::Error, false > LogError
void setRegionSummary(bool negativeEta, uint32_t region, uint32_t regionData)
void makeECalTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, const EcalTrigPrimDigiCollection *ecalTPGs)
def load
Definition: svgfig.py:547
std::vector< Block > Blocks
Definition: Block.h:99
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void setFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi, uint32_t fb)
Blocks pack(const edm::Event &, const PackerTokens *) override
const_iterator end() const
#define DEFINE_L1T_PACKER(type)
Definition: PackerFactory.h:23
T const * product() const
Definition: Handle.h:70
void makeHFTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, const HcalTrigPrimDigiCollection *hcalTPGs)
void makeRegions(uint32_t lPhi, UCTCTP7RawData &ctp7Data, const L1CaloRegionCollection *regions)
iterator find(key_type k)
unsigned board()
Definition: Packer.h:18
std::vector< L1CaloRegion > L1CaloRegionCollection
EcalSubdetector