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