CMS 3D CMS Logo

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 
111  if (tp != hcalTPGs->end()) {
112  uint32_t fg_bits = 0;
113  for (int index = 0; index < 6; index++)
114  fg_bits |= tp->SOI_fineGrain(index) << index;
115 
116  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->SOI_compressedEt());
117  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, fg_bits);
118  }
119  }
120  }
121  }
122  }
123 
124  void CaloLayer1Packer::makeHFTPGs(uint32_t lPhi,
125  UCTCTP7RawData& ctp7Data,
126  const HcalTrigPrimDigiCollection* hcalTPGs) {
128  for (uint32_t side = 0; side <= 1; side++) {
129  bool negativeEta = false;
130  if (side == 0)
131  negativeEta = true;
132  for (uint32_t iEta = 30; iEta <= 40; iEta++) {
133  for (uint32_t iPhi = 0; iPhi < 2; iPhi++) {
134  if (iPhi == 1 && iEta == 40)
135  iEta = 41;
136  int cPhi = 1 + lPhi * 4 + iPhi * 2; // Calorimeter phi index: 1, 3, 5, ... 71
137  if (iEta == 41)
138  cPhi -= 2; // Last two HF are 3, 7, 11, ...
139  cPhi = (cPhi + 69) % 72 + 1; // cPhi -= 2 mod 72
140  int cEta = iEta;
141  if (negativeEta)
142  cEta = -iEta;
143 
144  HcalTrigTowerDetId id(cEta, cPhi);
145  id.setVersion(1); // To not process these 1x1 HF TPGs with RCT
146  const auto tp = hcalTPGs->find(id);
147  if (tp != hcalTPGs->end()) {
148  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->SOI_compressedEt());
149  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, ((tp->SOI_fineGrain(1) << 1) | tp->SOI_fineGrain(0)));
150  }
151  }
152  }
153  }
154  }
155 
157  for (uint32_t side = 0; side <= 1; side++) {
158  bool negativeEta = false;
159  if (side == 0)
160  negativeEta = true;
161  for (uint32_t region = 0; region <= 6; region++) {
162  uint32_t lEta = 10 - region; // GCT eta goes 0-21, 0-3 -HF, 4-10 -B/E, 11-17 +B/E, 18-21 +HF
163  if (!negativeEta)
164  lEta = region + 11;
165 
166  L1CaloRegionDetId id(lEta, lPhi);
167  // Can't use find since not an edm::SortedCollection
168  // const L1CaloRegion& rtp = *regions->find(id);
169  for (const auto& rtp : *regions) {
170  if (rtp.id() == id) {
171  ctp7Data.setRegionSummary(negativeEta, region, rtp.raw());
172  break;
173  }
174  }
175  }
176  }
177  }
178 
179  } // namespace stage2
180 } // namespace l1t
181 
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)
delete x;
Definition: CaloConfig.h:22
Log< level::Error, false > LogError
Definition: Electron.h:6
void setRegionSummary(bool negativeEta, uint32_t region, uint32_t regionData)
void makeECalTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, const EcalTrigPrimDigiCollection *ecalTPGs)
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
def load(fileName)
Definition: svgfig.py:547
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
Definition: event.py:1