test
CMS 3D CMS Logo

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