File indexing completed on 2024-04-06 12:20:47
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 openFile();
0057 void skipHeader();
0058 int convertToInt(std::string& bitstr) const;
0059 static bool cmpProc(const RegionalMuonCand&, const RegionalMuonCand&);
0060
0061
0062 std::string m_fname;
0063 std::ifstream m_filestream;
0064 bool m_endOfBx;
0065 bool m_lastMuInBx;
0066 int m_currType;
0067 int m_currEvt;
0068 };
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081 L1TMicroGMTInputProducer::L1TMicroGMTInputProducer(const edm::ParameterSet& iConfig)
0082 : m_endOfBx(false), m_currType(0), m_currEvt(0) {
0083
0084 produces<RegionalMuonCandBxCollection>("BarrelTFMuons");
0085 produces<RegionalMuonCandBxCollection>("OverlapTFMuons");
0086 produces<RegionalMuonCandBxCollection>("ForwardTFMuons");
0087 produces<MuonCaloSumBxCollection>("TriggerTowerSums");
0088
0089
0090 m_fname = iConfig.getParameter<std::string>("inputFileName");
0091
0092 openFile();
0093 skipHeader();
0094 }
0095
0096 L1TMicroGMTInputProducer::~L1TMicroGMTInputProducer() {
0097
0098
0099 m_filestream.close();
0100 }
0101
0102
0103
0104
0105 bool L1TMicroGMTInputProducer::cmpProc(const RegionalMuonCand& mu1, const RegionalMuonCand& mu2) {
0106 return mu1.processor() < mu2.processor();
0107 }
0108
0109 void L1TMicroGMTInputProducer::openFile() {
0110 if (!m_filestream.is_open()) {
0111 m_filestream.open(m_fname.c_str());
0112 if (!m_filestream.good()) {
0113 cms::Exception("FileOpenError") << "Failed to open input file";
0114 }
0115 }
0116 }
0117
0118 void L1TMicroGMTInputProducer::skipHeader() {
0119 while (m_filestream.peek() == '#') {
0120 std::string tmp;
0121 getline(m_filestream, tmp);
0122 }
0123 }
0124
0125 int L1TMicroGMTInputProducer::convertToInt(std::string& bitstr) const {
0126 int num = 0;
0127 for (size_t cntr = 0; cntr < bitstr.size(); ++cntr) {
0128 char c = bitstr[cntr];
0129 num = (num << 1) |
0130 (c - '0');
0131 }
0132 return num;
0133 }
0134
0135
0136 void L1TMicroGMTInputProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0137 using namespace edm;
0138
0139 std::unique_ptr<RegionalMuonCandBxCollection> barrelMuons(new RegionalMuonCandBxCollection());
0140 std::unique_ptr<RegionalMuonCandBxCollection> overlapMuons(new RegionalMuonCandBxCollection());
0141 std::unique_ptr<RegionalMuonCandBxCollection> endcapMuons(new RegionalMuonCandBxCollection());
0142 std::unique_ptr<MuonCaloSumBxCollection> towerSums(new MuonCaloSumBxCollection());
0143
0144 RegionalMuonCand mu;
0145 MuonCaloSum tSum;
0146 m_endOfBx = false;
0147 int caloCounter = 0;
0148 std::vector<int> bar{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0149 std::vector<int> ovl_neg{0, 0, 0, 0, 0, 0};
0150 std::vector<int> ovl_pos{0, 0, 0, 0, 0, 0};
0151 std::vector<int> fwd_neg{0, 0, 0, 0, 0, 0};
0152 std::vector<int> fwd_pos{0, 0, 0, 0, 0, 0};
0153 while (!m_endOfBx && !m_filestream.eof()) {
0154 std::string lineID;
0155 m_filestream >> lineID;
0156 std::string restOfLine;
0157
0158 if (lineID == "BAR" || lineID == "OVL-" || lineID == "FWD-" || lineID == "OVL+" || lineID == "FWD+") {
0159 int tmp;
0160 m_filestream >> tmp;
0161
0162
0163
0164
0165
0166
0167 m_filestream >> tmp;
0168 mu.setHwPt(tmp);
0169
0170 m_filestream >> tmp;
0171
0172 int globalPhi = int(tmp * 0.560856864654333f);
0173 int globalWedgePhi = (globalPhi + 24) % 576;
0174 int globalSectorPhi = (globalPhi - 24);
0175 if (globalSectorPhi < 0) {
0176 globalSectorPhi += 576;
0177 }
0178
0179
0180 bool skip = false;
0181 if (lineID == "BAR") {
0182 int processor = globalWedgePhi / 48 + 1;
0183 int localPhi = globalWedgePhi % 48;
0184 mu.setTFIdentifiers(processor, tftype::bmtf);
0185 mu.setHwPhi(localPhi);
0186 bar[processor - 1]++;
0187 if (bar[processor - 1] > 3)
0188 skip = true;
0189 }
0190 if (lineID == "OVL-") {
0191 int processor = globalSectorPhi / 96 + 1;
0192 int localPhi = globalSectorPhi % 96;
0193 mu.setTFIdentifiers(processor, tftype::omtf_neg);
0194 mu.setHwPhi(localPhi);
0195 ovl_neg[processor - 1]++;
0196 if (ovl_neg[processor - 1] > 3)
0197 skip = true;
0198 }
0199 if (lineID == "OVL+") {
0200 int processor = globalSectorPhi / 96 + 1;
0201 int localPhi = globalSectorPhi % 96;
0202 mu.setTFIdentifiers(processor, tftype::omtf_pos);
0203 mu.setHwPhi(localPhi);
0204 ovl_pos[processor - 1]++;
0205 if (ovl_pos[processor - 1] > 3)
0206 skip = true;
0207 }
0208 if (lineID == "FWD-") {
0209 int processor = globalSectorPhi / 96 + 1;
0210 int localPhi = globalSectorPhi % 96;
0211 mu.setTFIdentifiers(processor, tftype::emtf_neg);
0212 mu.setHwPhi(localPhi);
0213 fwd_neg[processor - 1]++;
0214 if (fwd_neg[processor - 1] > 3)
0215 skip = true;
0216 }
0217 if (lineID == "FWD+") {
0218 int processor = globalSectorPhi / 96 + 1;
0219 int localPhi = globalSectorPhi % 96;
0220 mu.setTFIdentifiers(processor, tftype::emtf_pos);
0221 mu.setHwPhi(localPhi);
0222 fwd_pos[processor - 1]++;
0223 if (fwd_pos[processor - 1] > 3)
0224 skip = true;
0225 }
0226
0227 m_filestream >> tmp;
0228 tmp = int(tmp * 0.9090909090f);
0229 mu.setHwEta(tmp);
0230
0231 m_filestream >> tmp;
0232 mu.setHwSign(tmp);
0233
0234 m_filestream >> tmp;
0235 mu.setHwSignValid(tmp);
0236
0237 m_filestream >> tmp;
0238 mu.setHwQual(tmp);
0239
0240 if (lineID == "BAR")
0241 m_currType = 0;
0242 if (lineID == "OVL-")
0243 m_currType = 1;
0244 if (lineID == "OVL+")
0245 m_currType = 2;
0246 if (lineID == "FWD-")
0247 m_currType = 3;
0248 if (lineID == "FWD+")
0249 m_currType = 4;
0250
0251 if (m_currType == 0 && !skip)
0252 barrelMuons->push_back(0, mu);
0253 if ((m_currType == 1 || m_currType == 2) && !skip)
0254 overlapMuons->push_back(0, mu);
0255 if ((m_currType == 3 || m_currType == 4) && !skip)
0256 endcapMuons->push_back(0, mu);
0257 }
0258
0259 if (lineID == "EVT" && m_currEvt != 0) {
0260 m_endOfBx = true;
0261 } else if (lineID == "EVT") {
0262 m_currEvt++;
0263 }
0264
0265 if (lineID == "CALO") {
0266 for (int i = 0; i < 28; ++i) {
0267 int ieta = i;
0268 int iphi = caloCounter;
0269 int et;
0270
0271 m_filestream >> et;
0272 tSum.setEtBits(et);
0273 tSum.setEtaBits(ieta);
0274 tSum.setPhiBits(iphi);
0275 tSum.setIndex(caloCounter * 28 + i);
0276 towerSums->push_back(0, tSum);
0277 }
0278 caloCounter++;
0279 }
0280 getline(m_filestream, restOfLine);
0281
0282 }
0283
0284
0285
0286
0287
0288 iEvent.put(std::move(barrelMuons), "BarrelTFMuons");
0289 iEvent.put(std::move(overlapMuons), "OverlapTFMuons");
0290 iEvent.put(std::move(endcapMuons), "ForwardTFMuons");
0291 iEvent.put(std::move(towerSums), "TriggerTowerSums");
0292 m_currEvt++;
0293 }
0294
0295
0296 void L1TMicroGMTInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0297
0298
0299 edm::ParameterSetDescription desc;
0300 desc.setUnknown();
0301 descriptions.addDefault(desc);
0302 }
0303
0304
0305 DEFINE_FWK_MODULE(L1TMicroGMTInputProducer);