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 
16  {
18  event.getByToken(static_cast<const CaloLayer1Tokens*>(toks)->getEcalDigiToken(), ecalDigis);
20  event.getByToken(static_cast<const CaloLayer1Tokens*>(toks)->getHcalDigiToken(), hcalDigis);
22  event.getByToken(static_cast<const CaloLayer1Tokens*>(toks)->getCaloRegionToken(), caloRegions);
23 
24  std::vector<uint32_t> load;
25  load.resize(192, 0u);
26 
27  auto ctp7_phi = board();
28  uint32_t * ptr = &*load.begin();
29  UCTCTP7RawData ctp7Data(ptr);
30  makeECalTPGs(ctp7_phi, ctp7Data, ecalDigis.product());
31  makeHCalTPGs(ctp7_phi, ctp7Data, hcalDigis.product());
32  makeHFTPGs(ctp7_phi, ctp7Data, hcalDigis.product());
33  makeRegions(ctp7_phi, ctp7Data, caloRegions.product());
34 
35  unsigned bx_per_l1a = 1;
36  // CTP7 uses CMS scheme, starting at 0
37  // TODO: expected +2, but +1 apparently?
38  unsigned calo_bxid = (event.bunchCrossing()+1) % 3564;
39 
40  // a la CTP7Payload::getHeader()
41  unsigned blockId = 0;
42  unsigned blockSize = 192;
43  unsigned capId = 0;
44  unsigned blockFlags = ((bx_per_l1a&0xf)<<16) | (calo_bxid&0xfff);
45  BlockHeader hdr(blockId, blockSize, capId, blockFlags, CTP7);
46  Block block(hdr, &*load.begin(), &*load.end());
47 
48  Blocks res;
49  res.push_back(block);
50  return res;
51  }
52 
53  void CaloLayer1Packer::makeECalTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, const EcalTrigPrimDigiCollection* ecalTPGs) {
55  for(uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
56  int cPhi = - 1 + lPhi * 4 + iPhi; // Calorimeter phi index
57  if(cPhi == 0) cPhi = 72;
58  else if(cPhi == -1) cPhi = 71;
59  else if(cPhi < -1) {
60  edm::LogError("CaloLayer1Packer") << "Major error in makeECalTPGs" << std::endl;
61  return;
62  }
63  for(int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
64  if(cEta != 0) { // Calorimeter eta = 0 is invalid
65  bool negativeEta = false;
66  if(cEta < 0) negativeEta = true;
67  uint32_t iEta = abs(cEta);
68 
69  int zSide = cEta / ((int) iEta);
70  const EcalSubdetector ecalTriggerTower = (iEta > 17 ) ? EcalSubdetector::EcalEndcap : EcalSubdetector::EcalBarrel;
71  EcalTrigTowerDetId id(zSide, ecalTriggerTower, iEta, cPhi);
72  const auto& tp = ecalTPGs->find(id);
73  if ( tp != ecalTPGs->end() ) {
74  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->compressedEt());
75  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, tp->fineGrain());
76  }
77  }
78  }
79  }
80 
81  }
82 
83  void CaloLayer1Packer::makeHCalTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, const HcalTrigPrimDigiCollection* hcalTPGs) {
85  for(uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
86  int cPhi = - 1 + lPhi * 4 + iPhi; // Calorimeter phi index
87  if(cPhi == 0) cPhi = 72;
88  else if(cPhi == -1) cPhi = 71;
89  else if(cPhi < -1) {
90  edm::LogError("CaloLayer1Packer") << "Major error in makeHCalTPGs" << std::endl;
91  return;
92  }
93  for(int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
94  if(cEta != 0) { // Calorimeter eta = 0 is invalid
95  bool negativeEta = false;
96  if(cEta < 0) negativeEta = true;
97  uint32_t iEta = abs(cEta);
98 
99  HcalTrigTowerDetId id(cEta, cPhi);
100  const auto tp = hcalTPGs->find(id);
101  if ( tp != hcalTPGs->end() ) {
102  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->SOI_compressedEt());
103  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, tp->SOI_fineGrain());
104  }
105  }
106  }
107  }
108 
109  }
110 
111  void CaloLayer1Packer::makeHFTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, const HcalTrigPrimDigiCollection* hcalTPGs) {
113  for(uint32_t side = 0; side <= 1; side++) {
114  bool negativeEta = false;
115  if(side == 0) negativeEta = true;
116  for(uint32_t iEta = 30; iEta <= 40; iEta++) {
117  for(uint32_t iPhi = 0; iPhi < 2; iPhi++) {
118  if(iPhi == 1 && iEta == 40) iEta = 41;
119  int cPhi = 1 + lPhi * 4 + iPhi * 2; // Calorimeter phi index: 1, 3, 5, ... 71
120  if(iEta == 41) cPhi -= 2; // Last two HF are 3, 7, 11, ...
121  cPhi = (cPhi+69)%72 + 1; // cPhi -= 2 mod 72
122  int cEta = iEta;
123  if(negativeEta) cEta = -iEta;
124 
125  HcalTrigTowerDetId id(cEta, cPhi);
126  id.setVersion(1); // To not process these 1x1 HF TPGs with RCT
127  const auto tp = hcalTPGs->find(id);
128  if ( tp != hcalTPGs->end() ) {
129  ctp7Data.setET(cType, negativeEta, iEta, iPhi, tp->SOI_compressedEt());
130  ctp7Data.setFB(cType, negativeEta, iEta, iPhi, ((tp->SOI_fineGrain(1)<<1) | tp->SOI_fineGrain(0)));
131  }
132  }
133  }
134  }
135  }
136 
137  void
138  CaloLayer1Packer::makeRegions(uint32_t lPhi, UCTCTP7RawData& ctp7Data, const L1CaloRegionCollection* regions) {
139  for(uint32_t side = 0; side <= 1; side++) {
140  bool negativeEta = false;
141  if(side == 0) negativeEta = true;
142  for(uint32_t region = 0; region <= 6; region++) {
143  uint32_t lEta = 10 - region; // GCT eta goes 0-21, 0-3 -HF, 4-10 -B/E, 11-17 +B/E, 18-21 +HF
144  if(!negativeEta) lEta = region + 11;
145 
146  L1CaloRegionDetId id(lEta, lPhi);
147  // Can't use find since not an edm::SortedCollection
148  // const L1CaloRegion& rtp = *regions->find(id);
149  for (const auto& rtp : *regions) {
150  if ( rtp.id() == id ) {
151  ctp7Data.setRegionSummary(negativeEta, region, rtp.raw());
152  break;
153  }
154  }
155  }
156  }
157  }
158 
159 
160 }
161 }
162 
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
Definition: Electron.h:4
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:72
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:22
T const * product() const
Definition: Handle.h:81
def load(fileName)
Definition: svgfig.py:546
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