Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:56

0001 //-------------------------------------------------
0002 //
0003 //   \class L1MuGMTHWFileReader
0004 //
0005 //   Description: Puts the GMT input information from
0006 //                a GMT ascii HW testfile into the Event
0007 //
0008 //
0009 //
0010 //   Author :
0011 //   Tobias Noebauer                 HEPHY Vienna
0012 //   Ivan Mikulec                    HEPHY Vienna
0013 //
0014 //--------------------------------------------------
0015 
0016 //-----------------------
0017 // This Class's Header --
0018 //-----------------------
0019 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTHWFileReader.h"
0020 
0021 //---------------
0022 // C++ Headers --
0023 //---------------
0024 #include <stdexcept>
0025 
0026 //-------------------------------
0027 // Collaborating Class Headers --
0028 //-------------------------------
0029 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
0030 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0031 
0032 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0033 
0034 //----------------
0035 // Constructors --
0036 //----------------
0037 L1MuGMTHWFileReader::L1MuGMTHWFileReader(edm::ParameterSet const& ps, edm::InputSourceDescription const& desc)
0038     : ProducerSourceFromFiles(ps, desc, true) {
0039   produces<std::vector<L1MuRegionalCand> >("DT");
0040   produces<std::vector<L1MuRegionalCand> >("CSC");
0041   produces<std::vector<L1MuRegionalCand> >("RPCb");
0042   produces<std::vector<L1MuRegionalCand> >("RPCf");
0043 
0044   produces<L1CaloRegionCollection>();
0045 
0046   if (fileNames(0).empty()) {
0047     throw std::runtime_error("L1MuGMTHWFileReader: no input file");
0048   }
0049   edm::LogInfo("GMT_HWFileReader_info") << "opening file " << fileNames(0)[0];
0050   m_in.open((fileNames(0)[0].substr(fileNames(0)[0].find(':') + 1)).c_str());
0051   if (!m_in) {
0052     throw std::runtime_error("L1MuGMTHWFileReader: file " + fileNames(0)[0] + " could not be openned");
0053   }
0054 }
0055 
0056 //--------------
0057 // Destructor --
0058 //--------------
0059 L1MuGMTHWFileReader::~L1MuGMTHWFileReader() { m_in.close(); }
0060 
0061 //--------------
0062 // Operations --
0063 //--------------
0064 bool L1MuGMTHWFileReader::setRunAndEventInfo(edm::EventID& id,
0065                                              edm::TimeValue_t& time,
0066                                              edm::EventAuxiliary::ExperimentType& eType) {
0067   readNextEvent();
0068   if (!m_evt.getRunNumber() && !m_evt.getEventNumber())
0069     return false;
0070   id = edm::EventID(m_evt.getRunNumber(), id.luminosityBlock(), m_evt.getEventNumber());
0071 
0072   edm::LogInfo("GMT_HWFileReader_info") << "run: " << m_evt.getRunNumber() << "   evt: " << m_evt.getEventNumber();
0073   return true;
0074 }
0075 
0076 void L1MuGMTHWFileReader::produce(edm::Event& e) {
0077   L1MuRegionalCand empty_mu;
0078 
0079   std::unique_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
0080   for (unsigned i = 0; i < 4; i++) {
0081     const L1MuRegionalCand* mu = m_evt.getInputMuon("IND", i);
0082     if (!mu)
0083       mu = &empty_mu;
0084     DTCands->push_back(*mu);
0085   }
0086   e.put(std::move(DTCands), "DT");
0087 
0088   std::unique_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
0089   for (unsigned i = 0; i < 4; i++) {
0090     const L1MuRegionalCand* mu = m_evt.getInputMuon("INC", i);
0091     if (!mu)
0092       mu = &empty_mu;
0093     CSCCands->push_back(*mu);
0094   }
0095   e.put(std::move(CSCCands), "CSC");
0096 
0097   std::unique_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
0098   for (unsigned i = 0; i < 4; i++) {
0099     const L1MuRegionalCand* mu = m_evt.getInputMuon("INB", i);
0100     if (!mu)
0101       mu = &empty_mu;
0102     RPCbCands->push_back(*mu);
0103   }
0104   e.put(std::move(RPCbCands), "RPCb");
0105 
0106   std::unique_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
0107   for (unsigned i = 0; i < 4; i++) {
0108     const L1MuRegionalCand* mu = m_evt.getInputMuon("INF", i);
0109     if (!mu)
0110       mu = &empty_mu;
0111     RPCfCands->push_back(*mu);
0112   }
0113   e.put(std::move(RPCfCands), "RPCf");
0114 
0115   std::unique_ptr<L1CaloRegionCollection> rctRegions(new L1CaloRegionCollection);
0116   for (int ieta = 4; ieta < 18; ieta++) {
0117     for (int iphi = 0; iphi < 18; iphi++) {
0118       rctRegions->push_back(
0119           L1CaloRegion(0, false, true, m_evt.getMipBit(ieta - 4, iphi), m_evt.getIsoBit(ieta - 4, iphi), ieta, iphi));
0120     }
0121   }
0122 
0123   e.put(std::move(rctRegions));
0124 }
0125 
0126 void L1MuGMTHWFileReader::readNextEvent() {
0127   m_evt.reset();
0128 
0129   std::string line_id;
0130   do {
0131     int bx = 0;
0132 
0133     m_in >> line_id;
0134     if (line_id == "--")
0135       continue;
0136 
0137     if (line_id == "RUN") {
0138       unsigned long runnr;
0139       m_in >> runnr;
0140       m_evt.setRunNumber(runnr);
0141     }
0142 
0143     if (line_id == "EVT") {
0144       unsigned long evtnr;
0145       m_in >> evtnr;
0146       m_evt.setEventNumber(evtnr);
0147     }
0148 
0149     if (line_id == "DT" || line_id == "CSC" || line_id == "BRPC" || line_id == "FRPC") {
0150       // decode input muon
0151 
0152       unsigned inpmu = 0;
0153       unsigned val;
0154       m_in >> val;
0155       inpmu |= (val & 0x01) << 24;  // valid charge
0156       m_in >> val;
0157       inpmu |= (val & 0x01) << 23;  // charge
0158       m_in >> val;
0159       inpmu |= (val & 0x01) << 22;  // halo / fine
0160       m_in >> val;
0161       inpmu |= (val & 0x3f) << 16;  // eta
0162       m_in >> val;
0163       inpmu |= (val & 0x07) << 13;  // quality
0164       m_in >> val;
0165       inpmu |= (val & 0x1f) << 8;  // pt
0166       m_in >> val;
0167       inpmu |= (val & 0xff);  // phi
0168 
0169       std::string chipid("IN");
0170       chipid += line_id[0];
0171 
0172       int type = 0;
0173       if (line_id == "DT")
0174         type = 0;
0175       if (line_id == "CSC")
0176         type = 2;
0177       if (line_id == "BRPC")
0178         type = 1;
0179       if (line_id == "FRPC")
0180         type = 3;
0181 
0182       L1MuRegionalCand cand(inpmu);
0183       cand.setType(type);
0184       cand.setBx(bx);
0185       m_evt.addInputMuon(chipid, cand);
0186     }
0187 
0188     if (line_id == "MIP") {
0189       int nPairs;
0190       m_in >> nPairs;
0191       for (int i = 0; i < nPairs; i++) {
0192         unsigned eta;
0193         unsigned phi;
0194         m_in >> eta;
0195         m_in >> phi;
0196         if (phi >= 9)
0197           phi -= 9;
0198         else
0199           phi += 9;
0200         m_evt.setMipBit(eta, phi, true);
0201       }
0202     }
0203 
0204     if (line_id == "NQ") {
0205       int nPairs;
0206       m_in >> nPairs;
0207       for (int i = 0; i < nPairs; i++) {
0208         unsigned eta;
0209         unsigned phi;
0210         m_in >> eta;
0211         m_in >> phi;
0212         if (phi >= 9)
0213           phi -= 9;
0214         else
0215           phi += 9;
0216         m_evt.setIsoBit(eta, phi, false);
0217       }
0218     }
0219 
0220     //read the rest of the line
0221     const int sz = 4000;
0222     char buf[sz];
0223     m_in.getline(buf, sz);
0224 
0225   } while (line_id != "NQ" && !m_in.eof());
0226 }