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