CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CaloTowerUnpacker.cc
Go to the documentation of this file.
3 
5 
6 #include "CaloCollections.h"
7 #include "CaloTowerUnpacker.h"
9 
10 namespace l1t {
11  namespace stage2 {
13  // check this is the correct MP
14  unsigned int tmt = block.amc().getBoardID() - l1t::stage2::layer2::mp::offsetBoardId + 1;
15  unsigned int bxid = block.amc().getBX();
16 
17  LogDebug("L1T") << "Unpacking TMT # " << tmt << " for BX " << bxid;
18 
19  // Link number is block_ID / 2
20  unsigned link = block.header().getID() / 2;
21 
22  // Also need link number rounded down to even number
23  unsigned link_phi = (link % 2 == 0) ? link : (link - 1);
24 
25  // number of frames used in a few different places
26  unsigned nframes = 40;
27 
28  int nBX = int(ceil(
29  block.header().getSize() /
30  nframes)); // Since there are two Rx links per block with 2*28 slices in barrel and endcap + 2*13 for upgraded HF
31 
32  // Find the first and last BXs
33  int firstBX = -(std::ceil((double)nBX / 2.) - 1);
34  int lastBX;
35  if (nBX % 2 == 0) {
36  lastBX = std::ceil((double)nBX / 2.);
37  } else {
38  lastBX = std::ceil((double)nBX / 2.) - 1;
39  }
40 
41  auto res_ = static_cast<CaloCollections*>(coll)->getTowers();
42  res_->setBXRange(std::min(firstBX, res_->getFirstBX()), std::max(lastBX, res_->getLastBX()));
43 
44  LogDebug("L1T") << "Block : id=" << block.header().getID() << ", size=" << block.header().getSize()
45  << ", link=" << link << ", link_phi=" << link_phi << ", nBX=" << nBX << ", firstBX=" << firstBX
46  << ", lastBX=" << lastBX;
47 
48  // Loop over multiple BX and fill towers collection
49  for (int bx = firstBX; bx <= lastBX; bx++) {
50  for (unsigned iframe = 0; iframe < nframes && iframe < block.header().getSize(); ++iframe) {
51  uint32_t raw_data = block.payload().at(iframe);
52 
53  if ((raw_data & 0xFFFF) != 0) {
54  l1t::CaloTower tower1 = l1t::CaloTower();
55 
56  // First calo tower is in the LSW with phi
57  tower1.setHwPt(raw_data & 0x1FF);
58  tower1.setHwQual((raw_data >> 12) & 0xF);
59  tower1.setHwEtRatio((raw_data >> 9) & 0x7);
60  tower1.setHwPhi(link_phi + 1); // iPhi starts at 1
61 
62  int ieta = iframe + 1;
63  if (link % 2 != 0)
64  ieta = ieta * -1;
65 
66  tower1.setHwEta(CaloTools::caloEta(ieta));
67 
68  LogDebug("L1T") << "Tower 1: Eta " << tower1.hwEta() << " phi " << tower1.hwPhi() << " pT " << tower1.hwPt()
69  << " frame " << iframe << " qual " << tower1.hwQual() << " EtRatio " << tower1.hwEtRatio();
70 
71  res_->push_back(bx, tower1);
72  }
73 
74  if (((raw_data >> 16) & 0xFFFF) != 0) {
75  // Second calo tower is in the MSW with phi+1
76  l1t::CaloTower tower2 = l1t::CaloTower();
77 
78  tower2.setHwPt((raw_data >> 16) & 0x1FF);
79  tower2.setHwQual((raw_data >> 28) & 0xF);
80  tower2.setHwEtRatio((raw_data >> 25) & 0x7);
81  tower2.setHwPhi(link_phi + 2);
82 
83  int ieta = iframe + 1;
84  if (link % 2 != 0)
85  ieta = ieta * -1;
86  tower2.setHwEta(CaloTools::caloEta(ieta));
87 
88  LogDebug("L1T") << "Tower 2: Eta " << tower2.hwEta() << " phi " << tower2.hwPhi() << " pT " << tower2.hwPt()
89  << " frame " << iframe << " qual " << tower2.hwQual() << " EtRatio " << tower2.hwEtRatio();
90 
91  res_->push_back(bx, tower2);
92  }
93  }
94  }
95 
96  return true;
97  }
98  } // namespace stage2
99 } // namespace l1t
100 
constexpr int32_t ceil(float num)
const std::vector< uint32_t > & payload() const
Definition: Block.h:86
unsigned int getID() const
Definition: Block.h:43
BlockHeader header() const
Definition: Block.h:85
int hwEtRatio() const
Definition: CaloTower.cc:41
void setHwQual(int qual)
Definition: L1Candidate.h:31
int hwPhi() const
Definition: L1Candidate.h:37
int hwEta() const
Definition: L1Candidate.h:36
T min(T a, T b)
Definition: MathUtil.h:58
int hwQual() const
Definition: L1Candidate.h:38
void setHwEtRatio(int ratio)
Definition: CaloTower.cc:31
void setHwPhi(int phi)
Definition: L1Candidate.h:30
int hwPt() const
Definition: L1Candidate.h:35
bool unpack(const Block &block, UnpackerCollections *coll) override
static int caloEta(int ietaMP)
Definition: CaloTools.cc:234
void setHwPt(int pt)
Definition: L1Candidate.h:28
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:44
void setHwEta(int eta)
Definition: L1Candidate.h:29
void amc(const amc::Header &h)
Definition: Block.h:88
#define LogDebug(id)