File indexing completed on 2021-02-14 14:23:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022 #include <fstream>
0023
0024
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/stream/EDProducer.h"
0027
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/Exception.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034
0035 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0036 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0037 #include "DataFormats/L1TMuon/interface/MuonCaloSumFwd.h"
0038 #include "DataFormats/L1TMuon/interface/MuonCaloSum.h"
0039
0040 #include <iostream>
0041
0042
0043
0044 using namespace l1t;
0045
0046 class L1TMicroGMTInputProducer : public edm::stream::EDProducer<> {
0047 public:
0048 explicit L1TMicroGMTInputProducer(const edm::ParameterSet&);
0049 ~L1TMicroGMTInputProducer() override;
0050
0051 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052
0053 private:
0054 void produce(edm::Event&, const edm::EventSetup&) override;
0055
0056 void beginRun(const edm::Run&, edm::EventSetup const&) override;
0057 void endRun(const edm::Run&, edm::EventSetup const&) override;
0058 void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0059 void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0060
0061 void openFile();
0062 void skipHeader();
0063 int convertToInt(std::string& bitstr) const;
0064 static bool cmpProc(const RegionalMuonCand&, const RegionalMuonCand&);
0065
0066
0067 std::string m_fname;
0068 std::ifstream m_filestream;
0069 bool m_endOfBx;
0070 bool m_lastMuInBx;
0071 int m_currType;
0072 int m_currEvt;
0073 };
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 L1TMicroGMTInputProducer::L1TMicroGMTInputProducer(const edm::ParameterSet& iConfig)
0087 : m_endOfBx(false), m_currType(0), m_currEvt(0) {
0088
0089 produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
0090 produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
0091 produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
0092 produces<MuonCaloSumBxCollection>("TriggerTowerSums");
0093
0094
0095 m_fname = iConfig.getParameter<std::string>("inputFileName");
0096
0097 openFile();
0098 skipHeader();
0099 }
0100
0101 L1TMicroGMTInputProducer::~L1TMicroGMTInputProducer() {
0102
0103
0104 m_filestream.close();
0105 }
0106
0107
0108
0109
0110 bool L1TMicroGMTInputProducer::cmpProc(const RegionalMuonCand& mu1, const RegionalMuonCand& mu2) {
0111 return mu1.processor() < mu2.processor();
0112 }
0113
0114 void L1TMicroGMTInputProducer::openFile() {
0115 if (!m_filestream.is_open()) {
0116 m_filestream.open(m_fname.c_str());
0117 if (!m_filestream.good()) {
0118 cms::Exception("FileOpenError") << "Failed to open input file";
0119 }
0120 }
0121 }
0122
0123 void L1TMicroGMTInputProducer::skipHeader() {
0124 while (m_filestream.peek() == '#') {
0125 std::string tmp;
0126 getline(m_filestream, tmp);
0127 }
0128 }
0129
0130 int L1TMicroGMTInputProducer::convertToInt(std::string& bitstr) const {
0131 int num = 0;
0132 for (size_t cntr = 0; cntr < bitstr.size(); ++cntr) {
0133 char c = bitstr[cntr];
0134 num = (num << 1) |
0135 (c - '0');
0136 }
0137 return num;
0138 }
0139
0140
0141 void L1TMicroGMTInputProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0142 using namespace edm;
0143
0144 std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons(new RegionalMuonCandBxCollection());
0145 std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons(new RegionalMuonCandBxCollection());
0146 std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons(new RegionalMuonCandBxCollection());
0147 std::unique_ptr<MuonCaloSumBxCollection> towerSums(new MuonCaloSumBxCollection());
0148
0149 RegionalMuonCand mu;
0150 MuonCaloSum tSum;
0151 m_endOfBx = false;
0152 int caloCounter = 0;
0153 std::vector<int> bar{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0154 std::vector<int> ovl_neg{0, 0, 0, 0, 0, 0};
0155 std::vector<int> ovl_pos{0, 0, 0, 0, 0, 0};
0156 std::vector<int> fwd_neg{0, 0, 0, 0, 0, 0};
0157 std::vector<int> fwd_pos{0, 0, 0, 0, 0, 0};
0158 while (!m_endOfBx && !m_filestream.eof()) {
0159 std::string lineID;
0160 m_filestream >> lineID;
0161 std::string restOfLine;
0162
0163 if (lineID == "BAR" || lineID == "OVL-" || lineID == "FWD-" || lineID == "OVL+" || lineID == "FWD+") {
0164 int tmp;
0165 m_filestream >> tmp;
0166
0167
0168
0169
0170
0171
0172 m_filestream >> tmp;
0173 mu.setHwPt(tmp);
0174
0175 m_filestream >> tmp;
0176
0177 int globalPhi = int(tmp * 0.560856864654333f);
0178 int globalWedgePhi = (globalPhi + 24) % 576;
0179 int globalSectorPhi = (globalPhi - 24);
0180 if (globalSectorPhi < 0) {
0181 globalSectorPhi += 576;
0182 }
0183
0184
0185 bool skip = false;
0186 if (lineID == "BAR") {
0187 int processor = globalWedgePhi / 48 + 1;
0188 int localPhi = globalWedgePhi % 48;
0189 mu.setTFIdentifiers(processor, tftype::bmtf);
0190 mu.setHwPhi(localPhi);
0191 bar[processor - 1]++;
0192 if (bar[processor - 1] > 3)
0193 skip = true;
0194 }
0195 if (lineID == "OVL-") {
0196 int processor = globalSectorPhi / 96 + 1;
0197 int localPhi = globalSectorPhi % 96;
0198 mu.setTFIdentifiers(processor, tftype::omtf_neg);
0199 mu.setHwPhi(localPhi);
0200 ovl_neg[processor - 1]++;
0201 if (ovl_neg[processor - 1] > 3)
0202 skip = true;
0203 }
0204 if (lineID == "OVL+") {
0205 int processor = globalSectorPhi / 96 + 1;
0206 int localPhi = globalSectorPhi % 96;
0207 mu.setTFIdentifiers(processor, tftype::omtf_pos);
0208 mu.setHwPhi(localPhi);
0209 ovl_pos[processor - 1]++;
0210 if (ovl_pos[processor - 1] > 3)
0211 skip = true;
0212 }
0213 if (lineID == "FWD-") {
0214 int processor = globalSectorPhi / 96 + 1;
0215 int localPhi = globalSectorPhi % 96;
0216 mu.setTFIdentifiers(processor, tftype::emtf_neg);
0217 mu.setHwPhi(localPhi);
0218 fwd_neg[processor - 1]++;
0219 if (fwd_neg[processor - 1] > 3)
0220 skip = true;
0221 }
0222 if (lineID == "FWD+") {
0223 int processor = globalSectorPhi / 96 + 1;
0224 int localPhi = globalSectorPhi % 96;
0225 mu.setTFIdentifiers(processor, tftype::emtf_pos);
0226 mu.setHwPhi(localPhi);
0227 fwd_pos[processor - 1]++;
0228 if (fwd_pos[processor - 1] > 3)
0229 skip = true;
0230 }
0231
0232 m_filestream >> tmp;
0233 tmp = int(tmp * 0.9090909090f);
0234 mu.setHwEta(tmp);
0235
0236 m_filestream >> tmp;
0237 mu.setHwSign(tmp);
0238
0239 m_filestream >> tmp;
0240 mu.setHwSignValid(tmp);
0241
0242 m_filestream >> tmp;
0243 mu.setHwQual(tmp);
0244
0245 if (lineID == "BAR")
0246 m_currType = 0;
0247 if (lineID == "OVL-")
0248 m_currType = 1;
0249 if (lineID == "OVL+")
0250 m_currType = 2;
0251 if (lineID == "FWD-")
0252 m_currType = 3;
0253 if (lineID == "FWD+")
0254 m_currType = 4;
0255
0256 if (m_currType == 0 && !skip)
0257 barrelMuons->push_back(0, mu);
0258 if ((m_currType == 1 || m_currType == 2) && !skip)
0259 overlapMuons->push_back(0, mu);
0260 if ((m_currType == 3 || m_currType == 4) && !skip)
0261 endcapMuons->push_back(0, mu);
0262 }
0263
0264 if (lineID == "EVT" && m_currEvt != 0) {
0265 m_endOfBx = true;
0266 } else if (lineID == "EVT") {
0267 m_currEvt++;
0268 }
0269
0270 if (lineID == "CALO") {
0271 for (int i = 0; i < 28; ++i) {
0272 int ieta = i;
0273 int iphi = caloCounter;
0274 int et;
0275
0276 m_filestream >> et;
0277 tSum.setEtBits(et);
0278 tSum.setEtaBits(ieta);
0279 tSum.setPhiBits(iphi);
0280 tSum.setIndex(caloCounter * 28 + i);
0281 towerSums->push_back(0, tSum);
0282 }
0283 caloCounter++;
0284 }
0285 getline(m_filestream, restOfLine);
0286
0287 }
0288
0289
0290
0291
0292
0293 iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
0294 iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
0295 iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
0296 iEvent.put(std::move(towerSums), "TriggerTowerSums");
0297 m_currEvt++;
0298 }
0299
0300
0301 void L1TMicroGMTInputProducer::beginRun(const edm::Run&, edm::EventSetup const&) {}
0302
0303
0304 void L1TMicroGMTInputProducer::endRun(const edm::Run&, edm::EventSetup const&) {}
0305
0306
0307 void L1TMicroGMTInputProducer::beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0308
0309
0310 void L1TMicroGMTInputProducer::endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0311
0312
0313 void L1TMicroGMTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0314
0315
0316 edm::ParameterSetDescription desc;
0317 desc.setUnknown();
0318 descriptions.addDefault(desc);
0319 }
0320
0321
0322 DEFINE_FWK_MODULE(L1TMicroGMTInputProducer);