CMS 3D CMS Logo

ScGMTRawToDigi.cc
Go to the documentation of this file.
2 
4  using namespace edm;
5  srcInputTag = iConfig.getParameter<InputTag>("srcInputTag");
6  debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
7 
8  // initialize orbit buffer for BX 1->3564;
9  orbitBuffer_ = std::vector<std::vector<l1ScoutingRun3::Muon>>(3565);
10  for (auto& bxVec : orbitBuffer_) {
11  bxVec.reserve(8);
12  }
13  nMuonsOrbit_ = 0;
14 
15  produces<l1ScoutingRun3::MuonOrbitCollection>().setBranchAlias("MuonOrbitCollection");
16  rawToken = consumes<SDSRawDataCollection>(srcInputTag);
17 }
18 
20 
22  using namespace edm;
23 
24  Handle<SDSRawDataCollection> ScoutingRawDataCollection;
25  iEvent.getByToken(rawToken, ScoutingRawDataCollection);
26 
27  const FEDRawData& sourceRawData = ScoutingRawDataCollection->FEDData(SDSNumbering::GmtSDSID);
28  size_t orbitSize = sourceRawData.size();
29 
30  std::unique_ptr<l1ScoutingRun3::MuonOrbitCollection> unpackedMuons(new l1ScoutingRun3::MuonOrbitCollection);
31 
32  if ((sourceRawData.size() == 0) && debug_) {
33  std::cout << "No raw data for GMT FED\n";
34  }
35 
36  // unpack current orbit and store data into the orbitBufferr
37  unpackOrbit(sourceRawData.data(), orbitSize);
38 
39  // fill orbit collection and clear the Bx buffer vector
40  unpackedMuons->fillAndClear(orbitBuffer_, nMuonsOrbit_);
41 
42  // store collection in the event
43  iEvent.put(std::move(unpackedMuons));
44 }
45 
46 void ScGMTRawToDigi::unpackOrbit(const unsigned char* buf, size_t len) {
47  using namespace l1ScoutingRun3;
48 
49  // reset counters
50  nMuonsOrbit_ = 0;
51 
52  size_t pos = 0;
53 
54  while (pos < len) {
55  assert(pos + 4 <= len);
56 
57  // get BX header
58  uint32_t header = *((uint32_t*)(buf + pos));
59  pos += 4;
60  // count mA and mB
61  uint32_t mAcount = (header & header_masks::mAcount) >> header_shifts::mAcount;
62  uint32_t mBcount = (header & header_masks::mBcount) >> header_shifts::mBcount;
63 
64  // declare block to read
65  ugmt::block* bl = (ugmt::block*)(buf + pos);
66  pos += 4 + 4 + (mAcount + mBcount) * 12;
67  assert(pos <= len);
68 
69  uint32_t orbit = bl->orbit & 0x7FFFFFFF;
70  uint32_t bx = bl->bx;
71 
72  if (debug_) {
73  std::cout << "GMT Orbit " << orbit << ", BX -> " << bx << ", nMuons -> " << mAcount + mBcount << std::endl;
74  }
75 
76  // Unpack muons for this BX
77  orbitBuffer_[bx].reserve(mAcount + mBcount);
78 
79  for (unsigned int i = 0; i < mAcount + mBcount; i++) {
80  uint32_t interm = (bl->mu[i].extra >> ugmt::shiftsMuon::interm) & ugmt::masksMuon::interm;
81  if (interm == 1) {
82  if (debug_) {
83  std::cout << " -> Excluding intermediate muon\n";
84  }
85  continue;
86  }
87 
89  uint32_t ietaextu = (bl->mu[i].f >> ugmt::shiftsMuon::etaext) & ugmt::masksMuon::etaextv;
90  int32_t ietaext;
91  if (((bl->mu[i].f >> ugmt::shiftsMuon::etaext) & ugmt::masksMuon::etaexts) != 0) {
92  ietaext = ietaextu -= 256;
93  } else {
94  ietaext = ietaextu;
95  }
96 
97  // extract pt and quality and apply cut if required
98  int32_t iptuncon = (bl->mu[i].s >> ugmt::shiftsMuon::ptuncon) & ugmt::masksMuon::ptuncon;
99  int32_t ipt = (bl->mu[i].f >> ugmt::shiftsMuon::pt) & ugmt::masksMuon::pt;
100  if ((ipt - 1) < 0) {
101  continue;
102  }
103  uint32_t qual = (bl->mu[i].f >> ugmt::shiftsMuon::qual) & ugmt::masksMuon::qual;
104  if (qual == 0) {
105  continue;
106  }
107 
108  // extract integer value for extrapolated phi
109  int32_t iphiext = ((bl->mu[i].f >> ugmt::shiftsMuon::phiext) & ugmt::masksMuon::phiext);
110 
111  // extract integer value for extrapolated phi
112  int32_t idxy = ((bl->mu[i].s >> ugmt::shiftsMuon::dxy) & ugmt::masksMuon::dxy);
113 
114  // extract iso bits and charge
115  uint32_t iso = (bl->mu[i].s >> ugmt::shiftsMuon::iso) & ugmt::masksMuon::iso;
116  int32_t chrg = 0;
117  if (((bl->mu[i].s >> ugmt::shiftsMuon::chrgv) & ugmt::masksMuon::chrgv) == 1)
118  chrg = ((bl->mu[i].s >> ugmt::shiftsMuon::chrg) & ugmt::masksMuon::chrg) == 1 ? -1 : 1;
119 
120  // extract eta and phi at muon station
121  int32_t iphi = (bl->mu[i].s >> ugmt::shiftsMuon::phi) & ugmt::masksMuon::phi;
124 
125  uint32_t ieta_u;
126  int32_t ieta;
127  // checking if raw eta should be taken from muon 1 or muon 2
128  if ((bl->mu[i].extra & 0x1) == 0) {
129  ieta_u = ieta1;
130  } else {
131  ieta_u = ieta2;
132  }
133 
134  // two's complement
135  if (ieta_u > 256) {
136  ieta = ieta_u - 512;
137  } else {
138  ieta = ieta_u;
139  }
140 
141  // increment muon counter
142  nMuonsOrbit_++;
143 
144  l1ScoutingRun3::Muon muon(ipt, ieta, iphi, qual, chrg, chrg != 0, iso, index, ietaext, iphiext, iptuncon, idxy);
145 
146  orbitBuffer_[bx].push_back(muon);
147 
148  if (debug_) {
149  std::cout << "--- Muon " << i << " ---\n";
150  std::cout << " Raw f: 0x" << std::hex << bl->mu[i].f << std::dec << "\n";
151  std::cout << " Raw s: 0x" << std::hex << bl->mu[i].s << std::dec << "\n";
152  std::cout << " Raw extra: 0x" << std::hex << bl->mu[i].extra << std::dec << "\n";
153  printMuon(muon);
154  }
155 
156  } // end of bx
157 
158  } // end orbit while loop
159 
160  //muons->flatten();
161 }
162 
165  desc.setUnknown();
166  descriptions.addDefault(desc);
167 }
168 
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetToken rawToken
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void unpackOrbit(const unsigned char *buf, size_t len)
edm::InputTag srcInputTag
void printMuon(const Muon &muon, std::ostream &outs=std::cout)
const FEDRawData & FEDData(int sourceId) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:48
assert(be >=bs)
std::vector< std::vector< l1ScoutingRun3::Muon > > orbitBuffer_
void produce(edm::Event &, const edm::EventSetup &) override
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~ScGMTRawToDigi() override
ScGMTRawToDigi(const edm::ParameterSet &)
static constexpr int GmtSDSID
Definition: SDSNumbering.h:17
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
def move(src, dest)
Definition: eostools.py:511