File indexing completed on 2021-02-14 14:22:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include "L1Trigger/GlobalMuonTrigger/test/L1MuGMTPattern.h"
0017
0018
0019
0020
0021
0022 #include <fstream>
0023 #include <iomanip>
0024 #include <cmath>
0025
0026
0027
0028
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/EDAnalyzer.h"
0031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0032
0033 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0034
0035 using namespace std;
0036
0037
0038
0039
0040 L1MuGMTPattern::L1MuGMTPattern(const edm::ParameterSet& ps) {
0041 m_inputTag = ps.getUntrackedParameter<edm::InputTag>("GMTInputTag", edm::InputTag("gmt"));
0042 m_inputCaloTag = ps.getUntrackedParameter<edm::InputTag>("GMTInputCaloTag", edm::InputTag("source"));
0043 m_outfilename = ps.getUntrackedParameter<string>("OutputFile", "gmt_testfile.dat");
0044 m_outputType = ps.getUntrackedParameter<int>("OutputType", 1);
0045 }
0046
0047
0048
0049
0050 L1MuGMTPattern::~L1MuGMTPattern() {}
0051
0052 void L1MuGMTPattern::beginJob() {
0053 ofstream of(m_outfilename.c_str(), ios::trunc);
0054 if (m_outputType == 1) {
0055 of << "-- GMT HW Test file generated by L1MuGMTPattern" << endl;
0056 of << "--" << endl;
0057 }
0058 of.close();
0059 if (m_outputType == 4) {
0060 of.open((m_outfilename + string("DT")).c_str(), ios::trunc);
0061 of.close();
0062 of.open((m_outfilename + string("CSC")).c_str(), ios::trunc);
0063 of.close();
0064 of.open((m_outfilename + string("BRPC")).c_str(), ios::trunc);
0065 of.close();
0066 of.open((m_outfilename + string("FRPC")).c_str(), ios::trunc);
0067 of.close();
0068 }
0069 }
0070
0071 void L1MuGMTPattern::endJob() {}
0072
0073
0074
0075
0076
0077 void L1MuGMTPattern::analyze(const edm::Event& e, const edm::EventSetup& es) {
0078
0079 if (m_outputType == 1) {
0080 ofstream of(m_outfilename.c_str(), ios::app);
0081 int runn = e.id().run();
0082 int eventn = e.id().event();
0083 of << "--" << endl;
0084 of << "RUN " << runn << endl;
0085 of << "EVT " << eventn << endl;
0086 of.close();
0087 }
0088
0089
0090
0091 edm::Handle<L1MuGMTReadoutCollection> gmtrc_handle;
0092 e.getByLabel(m_inputTag, gmtrc_handle);
0093 L1MuGMTReadoutCollection const* gmtrc = gmtrc_handle.product();
0094
0095 L1MuGMTReadoutRecord gmt_record = gmtrc->getRecord(0);
0096
0097
0098 printRegional("DT", gmt_record.getDTBXCands());
0099 printRegional("CSC", gmt_record.getCSCCands());
0100 printRegional("BRPC", gmt_record.getBrlRPCCands());
0101 printRegional("FRPC", gmt_record.getFwdRPCCands());
0102
0103
0104
0105
0106 edm::Handle<L1CaloRegionCollection> calocoll_h;
0107 e.getByLabel(m_inputCaloTag, calocoll_h);
0108 if (calocoll_h.isValid()) {
0109 printMipIso(calocoll_h.product());
0110 } else {
0111 edm::LogVerbatim("GMT_PSB_info") << " Calorimeter MIP/QUIET bits not found in the Event ";
0112 }
0113
0114
0115 printGMT("GMT", gmt_record.getGMTCands());
0116 printGMT("GMTB", gmt_record.getGMTBrlCands());
0117 printGMT("GMTF", gmt_record.getGMTFwdCands());
0118
0119 edm::Handle<vector<unsigned> > mi_h;
0120 e.getByLabel(m_inputTag, mi_h);
0121 if (mi_h.isValid()) {
0122 printMI(mi_h.product());
0123 } else {
0124 edm::LogVerbatim("GMT_PSB_info") << " MI product invalid ";
0125 }
0126
0127 printCANC();
0128 }
0129
0130 void L1MuGMTPattern::printRegional(string tag, const vector<L1MuRegionalCand>& rmc) {
0131 ofstream of;
0132 if (m_outputType == 4) {
0133 of.open((m_outfilename + tag).c_str(), ios::app);
0134 } else {
0135 of.open(m_outfilename.c_str(), ios::app);
0136 }
0137
0138 int i = 0;
0139 vector<L1MuRegionalCand>::const_iterator iter1;
0140 edm::LogVerbatim("GMTPattern") << "L1 " << tag.data() << " TRIGGER muons (bx0): " << endl;
0141 for (iter1 = rmc.begin(); iter1 != rmc.end(); iter1++) {
0142 if (i > 3)
0143 break;
0144 edm::LogVerbatim("GMTPattern") << " " << ++i << " : ";
0145 (*iter1).print();
0146
0147 if (m_outputType == 1 && !((*iter1).empty())) {
0148 of << left << setw(4) << tag.data() << right << " " << setw(1) << (*iter1).charge_valid_packed() << " " << setw(1)
0149 << (*iter1).charge_packed() << " " << setw(1) << (*iter1).finehalo_packed() << " " << setw(2)
0150 << (*iter1).eta_packed() << " " << setw(1) << (*iter1).quality_packed() << " " << setw(2)
0151 << (*iter1).pt_packed() << " " << setw(3) << (*iter1).phi_packed();
0152
0153 of << " -- " << left << setw(4) << tag.data() << right << " vch=" << (*iter1).charge_valid_packed()
0154 << " ch=" << (*iter1).chargeValue() << " hf=" << (*iter1).finehalo_packed() << " eta=" << (*iter1).etaValue()
0155 << " q=" << (*iter1).quality() << " pt=" << (*iter1).ptValue() << " phi=" << (*iter1).phiValue() << endl;
0156 }
0157 if (m_outputType == 2 || m_outputType == 4) {
0158 of << " " << hex << setfill('0') << setw(8) << invertQPt((*iter1).getDataWord()) << dec;
0159 }
0160 }
0161 if (m_outputType == 2 || m_outputType == 4) {
0162 for (; i < 4; i++) {
0163 of << " 0000ffff";
0164 }
0165 }
0166 if (m_outputType == 2) {
0167 of << " |";
0168 }
0169 if (m_outputType == 4) {
0170 of << endl;
0171 }
0172 }
0173
0174 void L1MuGMTPattern::printGMT(string tag, const vector<L1MuGMTExtendedCand>& exc) {
0175 ofstream of(m_outfilename.c_str(), ios::app);
0176 int i = 0;
0177 vector<L1MuGMTExtendedCand>::const_iterator gmt_iter;
0178 const char* sysign_txt[4] = {"POS ", "NEG ", "UNDEF", "SYNC "};
0179 edm::LogVerbatim("GMTPattern") << "L1 " << tag.data() << " muons (bx0): ";
0180 for (gmt_iter = exc.begin(); gmt_iter != exc.end(); gmt_iter++) {
0181 if (i > 3)
0182 break;
0183 edm::LogVerbatim("GMTPattern") << " " << ++i << " : ";
0184 (*gmt_iter).print();
0185
0186 if (m_outputType == 1 && !((*gmt_iter).empty())) {
0187 of << left << setw(4) << tag.data() << right << " " << setw(1) << (*gmt_iter).sysign() << " " << setw(1)
0188 << (*gmt_iter).mip() << " " << setw(1) << (*gmt_iter).isol() << " " << setw(2) << (*gmt_iter).etaIndex() << " "
0189 << setw(1) << (*gmt_iter).quality() << " " << setw(2) << (*gmt_iter).ptIndex() << " " << setw(3)
0190 << (*gmt_iter).phiIndex() << " " << setw(3) << (*gmt_iter).rank();
0191
0192 of << " -- " << left << setw(4) << tag.data() << right << " sy_sign/charge=" << sysign_txt[(*gmt_iter).sysign()]
0193 << " MIP=" << (*gmt_iter).mip() << " ISO=" << (*gmt_iter).isol() << " eta=" << (*gmt_iter).etaValue()
0194 << " q=" << (*gmt_iter).quality() << " pt=" << (*gmt_iter).ptValue() << " phi=" << (*gmt_iter).phiValue()
0195 << " rank=" << (*gmt_iter).rank() << endl;
0196 }
0197 if (m_outputType > 1 && tag == "GMT") {
0198 of << " " << hex << setfill('0') << setw(8) << (*gmt_iter).getDataWord() << dec;
0199 }
0200 }
0201 if (m_outputType > 1 && tag == "GMT") {
0202 for (; i < 4; i++) {
0203 of << " 00000000";
0204 }
0205 of << endl;
0206 }
0207 }
0208
0209 void L1MuGMTPattern::printMipIso(L1CaloRegionCollection const* regions) {
0210 int nmip = 0;
0211 int nnq = 0;
0212
0213 if (m_outputType == 1) {
0214 ofstream of(m_outfilename.c_str(), ios::app);
0215 L1CaloRegionCollection::const_iterator iter;
0216
0217 edm::LogVerbatim("GMT_PSB_info") << "MIP/QUIET bits rceived by the GMT :";
0218
0219 for (iter = regions->begin(); iter != regions->end(); iter++) {
0220 if ((*iter).id().ieta() < 4 || (*iter).id().ieta() > 17 || (*iter).id().iphi() > 17)
0221 continue;
0222 if ((*iter).mip())
0223 nmip++;
0224 if (!(*iter).quiet())
0225 nnq++;
0226
0227
0228
0229
0230
0231
0232 }
0233
0234 of << "MIP " << nmip << " ";
0235 for (iter = regions->begin(); iter != regions->end(); iter++) {
0236 if ((*iter).id().ieta() < 4 || (*iter).id().ieta() > 17 || (*iter).id().iphi() > 17)
0237 continue;
0238 if ((*iter).mip())
0239 of << (*iter).id().ieta() - 4 << " " << (((*iter).id().iphi() + 9) % 18) << " ";
0240 }
0241 of << endl;
0242
0243 of << "NQ " << nnq << " ";
0244 for (iter = regions->begin(); iter != regions->end(); iter++) {
0245 if ((*iter).id().ieta() < 4 || (*iter).id().ieta() > 17 || (*iter).id().iphi() > 17)
0246 continue;
0247 if (!(*iter).quiet())
0248 of << (*iter).id().ieta() - 4 << " " << (((*iter).id().iphi() + 9) % 18) << " ";
0249 }
0250 of << endl;
0251 }
0252 }
0253
0254 void L1MuGMTPattern::printMI(const vector<unsigned>* mi) {
0255 if (m_outputType == 1) {
0256 ofstream of(m_outfilename.c_str(), ios::app);
0257 of << "MI ";
0258 vector<unsigned>::const_iterator imi;
0259 for (imi = mi->begin(); imi != mi->end(); imi++) {
0260 of << " " << *imi;
0261 }
0262 of << endl;
0263 }
0264 }
0265
0266 void L1MuGMTPattern::printCANC() {
0267 if (m_outputType == 1) {
0268 ofstream of(m_outfilename.c_str(), ios::app);
0269 of << "CANC 0 0 0 0" << endl;
0270 }
0271 }
0272
0273 unsigned L1MuGMTPattern::invertQPt(unsigned w) {
0274 unsigned qpt = (w >> 8) & 0xff;
0275 w &= 0xffff00ff;
0276 w |= ((~qpt) << 8) & 0x0000ff00;
0277 return w;
0278 }
0279
0280
0281 DEFINE_FWK_MODULE(L1MuGMTPattern);