CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/L1Trigger/GlobalMuonTrigger/src/L1MuGMTHWFileReader.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   \class L1MuGMTHWFileReader
00004 //
00005 //   Description: Puts the GMT input information from 
00006 //                a GMT ascii HW testfile into the Event
00007 //
00008 //
00009 //   $Date: 2012/11/19 21:03:41 $
00010 //   $Revision: 1.5 $
00011 //
00012 //   Author :
00013 //   Tobias Noebauer                 HEPHY Vienna
00014 //   Ivan Mikulec                    HEPHY Vienna
00015 //
00016 //--------------------------------------------------
00017 
00018 //-----------------------
00019 // This Class's Header --
00020 //-----------------------
00021 #include "L1Trigger/GlobalMuonTrigger/src/L1MuGMTHWFileReader.h"
00022 
00023 //---------------
00024 // C++ Headers --
00025 //---------------
00026 #include <stdexcept>
00027 
00028 //-------------------------------
00029 // Collaborating Class Headers --
00030 //-------------------------------
00031 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
00032 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
00033 
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 
00036 //----------------
00037 // Constructors --
00038 //----------------
00039 L1MuGMTHWFileReader::L1MuGMTHWFileReader(edm::ParameterSet const& ps,
00040                                          edm::InputSourceDescription const& desc) :
00041                                          ProducerSourceFromFiles(ps, desc, true) {
00042 
00043   produces<std::vector<L1MuRegionalCand> >("DT");
00044   produces<std::vector<L1MuRegionalCand> >("CSC");
00045   produces<std::vector<L1MuRegionalCand> >("RPCb");
00046   produces<std::vector<L1MuRegionalCand> >("RPCf");
00047 
00048   produces<L1CaloRegionCollection>();
00049 
00050   if(!fileNames().size()) {
00051     throw std::runtime_error("L1MuGMTHWFileReader: no input file");
00052   }
00053   edm::LogInfo("GMT_HWFileReader_info") << "opening file " << fileNames()[0];
00054   m_in.open((fileNames()[0].substr(fileNames()[0].find(":")+1)).c_str());
00055   if(!m_in) {
00056     throw std::runtime_error("L1MuGMTHWFileReader: file " + fileNames()[0]
00057                         + " could not be openned");
00058   }
00059 
00060 }
00061 
00062 //--------------
00063 // Destructor --
00064 //--------------
00065 L1MuGMTHWFileReader::~L1MuGMTHWFileReader() {
00066   m_in.close();
00067 }
00068 
00069 //--------------
00070 // Operations --
00071 //--------------
00072 bool L1MuGMTHWFileReader::setRunAndEventInfo(edm::EventID& id, edm::TimeValue_t& time) {
00073   readNextEvent();
00074   if(!m_evt.getRunNumber() && !m_evt.getEventNumber()) return false;
00075   id = edm::EventID(m_evt.getRunNumber(), id.luminosityBlock(), m_evt.getEventNumber());
00076 
00077   edm::LogInfo("GMT_HWFileReader_info") << "run: " << m_evt.getRunNumber() << 
00078           "   evt: " << m_evt.getEventNumber();
00079   return true;
00080 }
00081 
00082 void L1MuGMTHWFileReader::produce(edm::Event& e) {
00083   L1MuRegionalCand empty_mu;
00084 
00085 
00086   std::auto_ptr<std::vector<L1MuRegionalCand> > DTCands(new std::vector<L1MuRegionalCand>);
00087   for (unsigned i = 0; i < 4; i++) {
00088     const L1MuRegionalCand *mu = m_evt.getInputMuon("IND", i);
00089     if (!mu) mu = &empty_mu;
00090     DTCands->push_back(*mu);
00091   }
00092   e.put(DTCands,"DT");
00093 
00094   std::auto_ptr<std::vector<L1MuRegionalCand> > CSCCands(new std::vector<L1MuRegionalCand>);
00095   for (unsigned i = 0; i < 4; i++) {
00096     const L1MuRegionalCand *mu = m_evt.getInputMuon("INC", i);
00097     if (!mu) mu = &empty_mu;
00098     CSCCands->push_back(*mu);
00099   }
00100   e.put(CSCCands,"CSC");
00101 
00102   std::auto_ptr<std::vector<L1MuRegionalCand> > RPCbCands(new std::vector<L1MuRegionalCand>);
00103   for (unsigned i = 0; i < 4; i++) {
00104     const L1MuRegionalCand *mu = m_evt.getInputMuon("INB", i);
00105     if (!mu) mu = &empty_mu;
00106     RPCbCands->push_back(*mu);
00107   }
00108   e.put(RPCbCands,"RPCb");
00109 
00110   std::auto_ptr<std::vector<L1MuRegionalCand> > RPCfCands(new std::vector<L1MuRegionalCand>);
00111   for (unsigned i = 0; i < 4; i++) {
00112     const L1MuRegionalCand *mu = m_evt.getInputMuon("INF", i);
00113     if (!mu) mu = &empty_mu;
00114     RPCfCands->push_back(*mu);
00115   }
00116   e.put(RPCfCands,"RPCf");
00117 
00118   std::auto_ptr<L1CaloRegionCollection> rctRegions (new L1CaloRegionCollection);
00119   for(int ieta = 4; ieta < 18; ieta++) {
00120     for(int iphi = 0; iphi < 18; iphi++) {
00121       rctRegions->push_back(L1CaloRegion(0,false,true,m_evt.getMipBit(ieta-4,iphi),m_evt.getIsoBit(ieta-4,iphi),ieta,iphi));
00122     }
00123   }
00124 
00125   e.put(rctRegions);
00126 }
00127 
00128 void L1MuGMTHWFileReader::readNextEvent() {
00129   m_evt.reset();
00130 
00131   std::string line_id;
00132   do {
00133     int bx = 0;
00134 
00135     m_in >> line_id;
00136     if (line_id == "--") continue;
00137 
00138     if (line_id == "RUN") {
00139       unsigned long runnr;
00140       m_in >> runnr;
00141       m_evt.setRunNumber(runnr);
00142     }
00143 
00144     if (line_id == "EVT") {
00145       unsigned long evtnr;
00146       m_in >> evtnr;
00147       m_evt.setEventNumber(evtnr);
00148     }
00149 
00150 
00151     if (line_id == "DT" || line_id == "CSC" || line_id == "BRPC" || line_id == "FRPC")
00152     {
00153 
00154       // decode input muon
00155 
00156       unsigned inpmu = 0;
00157       unsigned val;
00158       m_in >> val; inpmu |= (val & 0x01) << 24; // valid charge
00159       m_in >> val; inpmu |= (val & 0x01) << 23; // charge
00160       m_in >> val; inpmu |= (val & 0x01) << 22; // halo / fine
00161       m_in >> val; inpmu |= (val & 0x3f) << 16; // eta
00162       m_in >> val; inpmu |= (val & 0x07) << 13; // quality
00163       m_in >> val; inpmu |= (val & 0x1f) <<  8; // pt
00164       m_in >> val; inpmu |= (val & 0xff)      ; // phi
00165 
00166       std::string chipid("IN");
00167       chipid += line_id[0];
00168 
00169       int type=0;
00170       if (line_id == "DT") type = 0;
00171       if (line_id == "CSC") type = 2;
00172       if (line_id == "BRPC") type = 1;
00173       if (line_id == "FRPC") type = 3;
00174 
00175 
00176       L1MuRegionalCand cand(inpmu);
00177       cand.setType(type);
00178       cand.setBx(bx);
00179       m_evt.addInputMuon(chipid, cand);
00180     }
00181 
00182     if (line_id == "MIP") {
00183       int nPairs;
00184       m_in >> nPairs;
00185       for (int i=0; i<nPairs; i++) {
00186         unsigned eta;
00187         unsigned phi;
00188         m_in >> eta;
00189         m_in >> phi;
00190         if (phi >= 9) phi-=9;
00191         else phi+=9;
00192         m_evt.setMipBit(eta, phi, true);
00193       }
00194     }
00195 
00196     if (line_id == "NQ") {
00197       int nPairs;
00198       m_in >> nPairs;
00199       for (int i=0; i<nPairs; i++) {
00200         unsigned eta;
00201         unsigned phi;
00202         m_in >> eta;
00203         m_in >> phi;
00204         if (phi >= 9) phi-=9;
00205         else phi+=9;
00206         m_evt.setIsoBit(eta, phi, false);
00207       }
00208     }
00209 
00210     //read the rest of the line
00211     const int sz=4000; char buf[sz];
00212     m_in.getline(buf, sz);
00213 
00214   } while (line_id != "NQ" && !m_in.eof());
00215 
00216 }