CMS 3D CMS Logo

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