CMS 3D CMS Logo

CaloLayer1Unpacker.cc
Go to the documentation of this file.
3 
4 #include "CaloLayer1Unpacker.h"
5 
6 using namespace edm;
7 
8 namespace l1t {
9  namespace stage2 {
10 
11  // max_iEta_HcalTP = 41; // barrel <= 16, endcap <= 29, 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  LogDebug("L1T") << "Block size = " << block.header().getSize();
17  LogDebug("L1T") << "Board ID = " << block.amc().getBoardID();
18 
19  auto res = static_cast<CaloLayer1Collections*>(coll);
20 
21  auto ctp7_phi = block.amc().getBoardID();
22  const uint32_t* ptr = block.payload().data();
23 
24  int N_BX = (block.header().getFlags() >> 16) & 0xf;
25  // std::cout << " N_BX calculated " << N_BX << std::endl;
26 
27  if (N_BX == 1) {
28  UCTCTP7RawData ctp7Data(ptr);
29  makeECalTPGs(ctp7_phi, ctp7Data, res->getEcalDigis());
30  makeHCalTPGs(ctp7_phi, ctp7Data, res->getHcalDigis());
31  makeHFTPGs(ctp7_phi, ctp7Data, res->getHcalDigis());
32  makeRegions(ctp7_phi, ctp7Data, res->getRegions());
33  } else if (N_BX == 5) {
34  const uint32_t* ptr5 = ptr;
35  ptr += 192 * 2;
36  UCTCTP7RawData ctp7Data(ptr);
37  makeECalTPGs(ctp7_phi, ctp7Data, res->getEcalDigis());
38  makeHCalTPGs(ctp7_phi, ctp7Data, res->getHcalDigis());
39  makeHFTPGs(ctp7_phi, ctp7Data, res->getHcalDigis());
40  makeRegions(ctp7_phi, ctp7Data, res->getRegions());
41  for (int i = 0; i < 5; i++) {
42  UCTCTP7RawData ctp7Data(ptr5);
43  makeECalTPGs(ctp7_phi, ctp7Data, res->getEcalDigisBx(i));
44  ptr5 += 192;
45  }
46  } else {
47  LogError("CaloLayer1Unpacker") << "Number of BXs to unpack is not 1 or 5, stop here !!! " << N_BX << std::endl;
48  return false;
49  }
50 
51  return true;
52  }
53 
54  void CaloLayer1Unpacker::makeECalTPGs(uint32_t lPhi,
55  UCTCTP7RawData& ctp7Data,
56  EcalTrigPrimDigiCollection* ecalTPGs) {
58  for (uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
59  int cPhi = -1 + lPhi * 4 + iPhi; // Calorimeter phi index
60  if (cPhi == 0)
61  cPhi = 72;
62  else if (cPhi == -1)
63  cPhi = 71;
64  else if (cPhi < -1) {
65  LogError("CaloLayer1Unpacker") << "Major error in makeECalTPGs" << std::endl;
66  return;
67  }
68  for (int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
69  if (cEta != 0) { // Calorimeter eta = 0 is invalid
70  bool negativeEta = false;
71  if (cEta < 0)
72  negativeEta = true;
73  uint32_t iEta = abs(cEta);
74  // This code is fragile! Note that towerDatum is packed as is done in EcalTriggerPrimitiveSample
75  // Bottom 8-bits are ET
76  // Then finegrain feature bit
77  // Then three bits have ttBits, which I have no clue about (not available on ECAL links so not set)
78  // Then there is a spare FG Veto bit, which is used for L1 spike detection (not available on ECAL links so not set)
79  // Top three bits seem to be unused. So, we steal those to set the tower masking, link masking and link status information
80  // To decode these custom three bits use ((EcalTriggerPrimitiveSample::raw() >> 13) & 0x7)
81  uint32_t towerDatum = ctp7Data.getET(cType, negativeEta, iEta, iPhi);
82  if (ctp7Data.getFB(cType, negativeEta, iEta, iPhi) != 0)
83  towerDatum |= 0x0100;
84  if (ctp7Data.isTowerMasked(cType, negativeEta, iEta, iPhi))
85  towerDatum |= 0x2000;
86  if (ctp7Data.isLinkMasked(cType, negativeEta, iEta, iPhi))
87  towerDatum |= 0x4000;
88  if (ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi) ||
89  ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi) ||
90  ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi))
91  towerDatum |= 0x8000;
93  int zSide = cEta / ((int)iEta);
94  // As far as I can tell, the ECal unpacker only uses barrel and endcap IDs, never EcalTriggerTower
95  const EcalSubdetector ecalTriggerTower =
97  EcalTrigTowerDetId id(zSide, ecalTriggerTower, iEta, cPhi);
99  tpg.setSize(1);
100  tpg.setSample(0, sample);
101  ecalTPGs->push_back(tpg);
102  }
103  }
104  }
105  }
106 
107  void CaloLayer1Unpacker::makeHCalTPGs(uint32_t lPhi,
108  UCTCTP7RawData& ctp7Data,
109  HcalTrigPrimDigiCollection* hcalTPGs) {
111  for (uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
112  int cPhi = -1 + lPhi * 4 + iPhi; // Calorimeter phi index
113  if (cPhi == 0)
114  cPhi = 72;
115  else if (cPhi == -1)
116  cPhi = 71;
117  else if (cPhi < -1) {
118  LogError("CaloLayer1Unpacker") << "Major error in makeHCalTPGs" << std::endl;
119  return;
120  }
121  for (int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
122  if (cEta != 0) { // Calorimeter eta = 0 is invalid
123  bool negativeEta = false;
124  if (cEta < 0)
125  negativeEta = true;
126  uint32_t iEta = abs(cEta);
127  // This code is fragile! Note that towerDatum is packed as is done in HcalTriggerPrimitiveSample
128  // Bottom 8-bits are ET
129  // Then feature bit
130  // The remaining bits are undefined presently
131  // We use next three bits for link details, which we did not have room in EcalTriggerPrimitiveSample case
132  // We use next three bits to set the tower masking, link masking and link status information as done for Ecal
133  // To decode these custom six bits use ((EcalTriggerPrimitiveSample::raw() >> 9) & 0x77)
134  uint32_t towerDatum = ctp7Data.getET(cType, negativeEta, iEta, iPhi);
135  if (ctp7Data.getFB(cType, negativeEta, iEta, iPhi) != 0)
136  towerDatum |= 0x0100;
137  if (ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi))
138  towerDatum |= 0x0200;
139  if (ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi))
140  towerDatum |= 0x0400;
141  if (ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi))
142  towerDatum |= 0x0800;
143  if (ctp7Data.isTowerMasked(cType, negativeEta, iEta, iPhi))
144  towerDatum |= 0x2000;
145  if (ctp7Data.isLinkMasked(cType, negativeEta, iEta, iPhi))
146  towerDatum |= 0x4000;
147  if (ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi) ||
148  ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi) ||
149  ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi))
150  towerDatum |= 0x8000;
152  HcalTrigTowerDetId id(cEta, cPhi);
153  HcalTriggerPrimitiveDigi tpg(id);
154  tpg.setSize(1);
155  tpg.setSample(0, sample);
156  hcalTPGs->push_back(tpg);
157  }
158  }
159  }
160  }
161 
162  void CaloLayer1Unpacker::makeHFTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, HcalTrigPrimDigiCollection* hcalTPGs) {
164  for (uint32_t side = 0; side <= 1; side++) {
165  bool negativeEta = false;
166  if (side == 0)
167  negativeEta = true;
168  for (uint32_t iEta = 30; iEta <= 40; iEta++) {
169  for (uint32_t iPhi = 0; iPhi < 2; iPhi++) {
170  if (iPhi == 1 && iEta == 40)
171  iEta = 41;
172  int cPhi = 1 + lPhi * 4 + iPhi * 2; // Calorimeter phi index: 1, 3, 5, ... 71
173  if (iEta == 41)
174  cPhi -= 2; // Last two HF are 3, 7, 11, ...
175  cPhi = (cPhi + 69) % 72 + 1; // cPhi -= 2 mod 72
176  int cEta = iEta;
177  if (negativeEta)
178  cEta = -iEta;
179  // This code is fragile! Note that towerDatum is packed as is done in HcalTriggerPrimitiveSample
180  // Bottom 8-bits are ET
181  // Then feature bit
182  // Then minBias ADC count bit
183  // The remaining bits are undefined presently
184  // We use next three bits for link details, which we did not have room in EcalTriggerPrimitiveSample case
185  // We use next three bits to set the tower masking, link masking and link status information as done for Ecal
186  // To decode these custom six bits use ((EcalTriggerPrimitiveSample::raw() >> 9) & 0x77)
187  uint32_t towerDatum = ctp7Data.getET(cType, negativeEta, iEta, iPhi);
188  towerDatum |= ctp7Data.getFB(cType, negativeEta, iEta, iPhi) << 8;
189  if (ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi))
190  towerDatum |= 0x0400;
191  if (ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi))
192  towerDatum |= 0x0800;
193  if (ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi))
194  towerDatum |= 0x1000;
195  if (ctp7Data.isTowerMasked(cType, negativeEta, iEta, iPhi))
196  towerDatum |= 0x2000;
197  if (ctp7Data.isLinkMasked(cType, negativeEta, iEta, iPhi))
198  towerDatum |= 0x4000;
199  if (ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi) ||
200  ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi) ||
201  ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi))
202  towerDatum |= 0x8000;
204  HcalTrigTowerDetId id(cEta, cPhi);
205  id.setVersion(1); // To not process these 1x1 HF TPGs with RCT
206  HcalTriggerPrimitiveDigi tpg(id);
207  tpg.setSize(1);
208  tpg.setSample(0, sample);
209  hcalTPGs->push_back(tpg);
210  }
211  }
212  }
213  }
214 
215  void CaloLayer1Unpacker::makeRegions(uint32_t lPhi, UCTCTP7RawData& ctp7Data, L1CaloRegionCollection* regions) {
216  for (uint32_t side = 0; side <= 1; side++) {
217  bool negativeEta = false;
218  if (side == 0)
219  negativeEta = true;
220  for (uint32_t region = 0; region <= 6; region++) {
221  uint32_t regionData = ctp7Data.getRegionSummary(negativeEta, region);
222  uint32_t lEta = 10 - region; // GCT eta goes 0-21, 0-3 -HF, 4-10 -B/E, 11-17 +B/E, 18-21 +HF
223  if (!negativeEta)
224  lEta = region + 11;
225  regions->push_back(L1CaloRegion((uint16_t)regionData, (unsigned)lEta, (unsigned)lPhi, (int16_t)0));
226  }
227  }
228  }
229 
230  } // namespace stage2
231 } // namespace l1t
232 
UCTCTP7RawData::HBHE
Definition: UCTCTP7RawData.h:9
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
UCTCTP7RawData::getRegionSummary
uint32_t getRegionSummary(bool negativeEta, uint32_t region)
Definition: UCTCTP7RawData.h:274
L1CaloRegion
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
simplePhotonAnalyzer_cfi.sample
sample
Definition: simplePhotonAnalyzer_cfi.py:12
UCTCTP7RawData::EBEE
Definition: UCTCTP7RawData.h:9
l1t::stage2::CaloLayer1Unpacker
Definition: CaloLayer1Unpacker.h:10
HcalTriggerPrimitiveSample
Definition: HcalTriggerPrimitiveSample.h:11
edm
HLT enums.
Definition: AlignableModifier.h:19
UCTCTP7RawData
Definition: UCTCTP7RawData.h:7
UCTCTP7RawData::CaloType
CaloType
Definition: UCTCTP7RawData.h:9
edm::SortedCollection
Definition: SortedCollection.h:49
EcalSubdetector
EcalSubdetector
Definition: EcalSubdetector.h:10
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
HcalTriggerPrimitiveDigi::setSample
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
Definition: HcalTriggerPrimitiveDigi.h:43
edm::SortedCollection::push_back
void push_back(T const &t)
Definition: SortedCollection.h:188
EcalBarrel
Definition: EcalSubdetector.h:10
UCTCTP7RawData::isLinkMasked
bool isLinkMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:327
UCTCTP7RawData::isLinkDown
bool isLinkDown(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:319
CaloLayer1Unpacker.h
UCTCTP7RawData::isTowerMasked
bool isTowerMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:290
UnpackerFactory.h
UCTCTP7RawData::isLinkInError
bool isLinkInError(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:311
EcalEndcap
Definition: EcalSubdetector.h:10
EcalTriggerPrimitiveDigi::setSize
void setSize(int size)
Definition: EcalTriggerPrimitiveDigi.cc:60
HcalTriggerPrimitiveDigi
Definition: HcalTriggerPrimitiveDigi.h:13
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
l1t
delete x;
Definition: CaloConfig.h:22
EcalTriggerPrimitiveDigi::setSample
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
Definition: EcalTriggerPrimitiveDigi.h:36
HLT_FULL_cff.region
region
Definition: HLT_FULL_cff.py:88271
createfilelist.int
int
Definition: createfilelist.py:10
UCTCTP7RawData::isLinkMisaligned
bool isLinkMisaligned(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:303
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
res
Definition: Electron.h:6
SiStripSourceConfigTier0_cff.stage2
stage2
Definition: SiStripSourceConfigTier0_cff.py:71
UCTCTP7RawData::getET
uint32_t getET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:166
L1CaloRegionCollection
std::vector< L1CaloRegion > L1CaloRegionCollection
Definition: L1CaloCollections.h:11
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
EcalTriggerPrimitiveDigi
Definition: EcalTriggerPrimitiveDigi.h:16
UCTCTP7RawData::getFB
uint32_t getFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Definition: UCTCTP7RawData.h:203
l1t::UnpackerCollections
Definition: UnpackerCollections.h:9
BeamSpotPI::unpack
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: BeamSpotPayloadInspectorHelper.h:23
DEFINE_L1T_UNPACKER
#define DEFINE_L1T_UNPACKER(type)
Definition: UnpackerFactory.h:23
L1TowerCalibrationProducer_cfi.iEta
iEta
Definition: L1TowerCalibrationProducer_cfi.py:60
EcalTriggerPrimitiveSample
Definition: EcalTriggerPrimitiveSample.h:12
AlignmentPI::regions
regions
Definition: AlignmentPayloadInspectorHelper.h:76
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
l1t::Block
Definition: Block.h:70
HcalTriggerPrimitiveDigi::setSize
void setSize(int size)
Definition: HcalTriggerPrimitiveDigi.cc:7
UCTCTP7RawData::HF
Definition: UCTCTP7RawData.h:9
lumi::N_BX
const unsigned int N_BX
Definition: ConstantDef.h:5
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14