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