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  int abs_eta = (raw_data >> 9) & 0x7F;
65  if ((raw_data >> 16) & 0x1) {
66  eg.setHwEta(-1*(128-abs_eta));
67  } else {
68  eg.setHwEta(abs_eta);
69  }
70 
71  eg.setHwPhi((raw_data >> 17) & 0xFF);
72  eg.setHwIso((raw_data >> 25) & 0x3);
73  eg.setHwQual((raw_data >> 27) & 0x7); // Assume 3 bits for now? leaves 2 spare bits
74 
75  LogDebug("L1T") << "EG: eta " << eg.hwEta() << " phi " << eg.hwPhi() << " pT " << eg.hwPt() << " iso " << eg.hwIso() << " qual " << eg.hwQual();
76 
77  eg.setP4( l1t::CaloTools::p4Demux(&eg) );
78 
79  res_->push_back(bx,eg);
80 
81  }
82 
83  }
84 
85  return true;
86  }
87 }
88 }
89 
#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:252
virtual bool unpack(const Block &block, UnpackerCollections *coll) override