Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-30 01:18:19

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