CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EGammaUnpacker.cc
Go to the documentation of this file.
2 
4 
6 
7 #include "L1TObjectCollections.h"
8 
10 
11 namespace l1t {
12  namespace stage2 {
13  class EGammaUnpacker : public Unpacker {
14  public:
15  virtual bool unpack(const Block& block, UnpackerCollections *coll) override;
16  };
17  }
18 }
19 
20 // Implementation
21 
22 namespace l1t {
23 namespace stage2 {
24  bool
26  {
27 
28  using namespace l1t::stage2::layer2;
29 
30  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
31 
32  int nBX = int(ceil(block.header().getSize() / (double) demux::nOutputFramePerBX)); // 6 link frames per BX
33 
34  // Find the central, first and last BXs
35  int firstBX = -(ceil((double)nBX/2.)-1);
36  int lastBX;
37  if (nBX % 2 == 0) {
38  lastBX = ceil((double)nBX/2.);
39  } else {
40  lastBX = ceil((double)nBX/2.)-1;
41  }
42 
43  auto res_ = static_cast<L1TObjectCollections*>(coll)->getEGammas();
44  res_->setBXRange(firstBX, lastBX);
45 
46  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
47 
48  // Loop over multiple BX and then number of EG cands filling collection
49  for (int bx=firstBX; bx<=lastBX; bx++){
50 
51  for (unsigned iEG=0; iEG < demux::nEGPerLink && iEG < block.header().getSize(); iEG++){
52 
53  int iFrame = (bx-firstBX) * demux::nOutputFramePerBX + iEG;
54  uint32_t raw_data = block.payload().at(iFrame);
55 
56  // skip padding to bring EG candidates up to 12 pre BX
57  if (raw_data == 0)
58  continue;
59 
60  l1t::EGamma eg = l1t::EGamma();
61 
62  eg.setHwPt(raw_data & 0x1FF);
63 
64  if (eg.hwPt()==0) continue;
65 
66  int abs_eta = (raw_data >> 9) & 0x7F;
67  if ((raw_data >> 16) & 0x1) {
68  eg.setHwEta(-1*(128-abs_eta));
69  } else {
70  eg.setHwEta(abs_eta);
71  }
72 
73  eg.setHwPhi((raw_data >> 17) & 0xFF);
74  eg.setHwIso((raw_data >> 25) & 0x3);
75  eg.setHwQual((raw_data >> 27) & 0x7); // Assume 3 bits for now? leaves 2 spare bits
76 
77  LogDebug("L1T") << "EG: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " iso " << eg.hwIso() << " qual " << eg.hwQual();
78 
79  eg.setP4( l1t::CaloTools::p4Demux(&eg) );
80 
81  res_->push_back(bx,eg);
82 
83  }
84 
85  }
86 
87  return true;
88  }
89 }
90 }
91 
#define LogDebug(id)
unsigned int getID() const
Definition: Block.h:22
BlockHeader header() const
Definition: Block.h:56
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
int hwIso() const
Definition: L1Candidate.cc:84
int hwEta() const
Definition: L1Candidate.cc:74
int hwQual() const
Definition: L1Candidate.cc:89
void setHwPhi(int phi)
Definition: L1Candidate.cc:54
void setHwIso(int iso)
Definition: L1Candidate.cc:59
JetCorrectorParametersCollection coll
Definition: classes.h:10
int hwPt() const
Definition: L1Candidate.cc:69
virtual void setP4(const LorentzVector &p4) final
set 4-momentum
void setHwPt(int pt)
Definition: L1Candidate.cc:44
unsigned int getSize() const
Definition: Block.h:23
void setHwEta(int eta)
Definition: L1Candidate.cc:49
static math::PtEtaPhiMLorentzVector p4Demux(l1t::L1Candidate *)
Definition: CaloTools.cc:256
virtual bool unpack(const Block &block, UnpackerCollections *coll) override