CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/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: 2007/04/12 13:21:14 $
00010 //   $Revision: 1.4 $
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                                          ExternalInputSource(ps, desc) {
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 void L1MuGMTHWFileReader::setRunAndEventInfo() {
00073   readNextEvent();
00074   setRunNumber(m_evt.getRunNumber());
00075   setEventNumber(m_evt.getEventNumber());
00076 
00077   edm::LogInfo("GMT_HWFileReader_info") << "run: " << m_evt.getRunNumber() << 
00078           "   evt: " << m_evt.getEventNumber();
00079 }
00080 
00081 bool L1MuGMTHWFileReader::produce(edm::Event& e) {
00082   L1MuRegionalCand empty_mu;
00083 
00084   if(!m_evt.getRunNumber() && !m_evt.getEventNumber()) return false;
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   return true;
00128 }
00129 
00130 void L1MuGMTHWFileReader::readNextEvent() {
00131   m_evt.reset();
00132 
00133   std::string line_id;
00134   do {
00135     int bx = 0;
00136 
00137     m_in >> line_id;
00138     if (line_id == "--") continue;
00139 
00140     if (line_id == "RUN") {
00141       unsigned long runnr;
00142       m_in >> runnr;
00143       m_evt.setRunNumber(runnr);
00144     }
00145 
00146     if (line_id == "EVT") {
00147       unsigned long evtnr;
00148       m_in >> evtnr;
00149       m_evt.setEventNumber(evtnr);
00150     }
00151 
00152 
00153     if (line_id == "DT" || line_id == "CSC" || line_id == "BRPC" || line_id == "FRPC")
00154     {
00155 
00156       // decode input muon
00157 
00158       unsigned inpmu = 0;
00159       unsigned val;
00160       m_in >> val; inpmu |= (val & 0x01) << 24; // valid charge
00161       m_in >> val; inpmu |= (val & 0x01) << 23; // charge
00162       m_in >> val; inpmu |= (val & 0x01) << 22; // halo / fine
00163       m_in >> val; inpmu |= (val & 0x3f) << 16; // eta
00164       m_in >> val; inpmu |= (val & 0x07) << 13; // quality
00165       m_in >> val; inpmu |= (val & 0x1f) <<  8; // pt
00166       m_in >> val; inpmu |= (val & 0xff)      ; // phi
00167 
00168       std::string chipid("IN");
00169       chipid += line_id[0];
00170 
00171       int type=0;
00172       if (line_id == "DT") type = 0;
00173       if (line_id == "CSC") type = 2;
00174       if (line_id == "BRPC") type = 1;
00175       if (line_id == "FRPC") type = 3;
00176 
00177 
00178       L1MuRegionalCand cand(inpmu);
00179       cand.setType(type);
00180       cand.setBx(bx);
00181       m_evt.addInputMuon(chipid, cand);
00182     }
00183 
00184     if (line_id == "MIP") {
00185       int nPairs;
00186       m_in >> nPairs;
00187       for (int i=0; i<nPairs; i++) {
00188         unsigned eta;
00189         unsigned phi;
00190         m_in >> eta;
00191         m_in >> phi;
00192         if (phi >= 9) phi-=9;
00193         else phi+=9;
00194         m_evt.setMipBit(eta, phi, true);
00195       }
00196     }
00197 
00198     if (line_id == "NQ") {
00199       int nPairs;
00200       m_in >> nPairs;
00201       for (int i=0; i<nPairs; i++) {
00202         unsigned eta;
00203         unsigned phi;
00204         m_in >> eta;
00205         m_in >> phi;
00206         if (phi >= 9) phi-=9;
00207         else phi+=9;
00208         m_evt.setIsoBit(eta, phi, false);
00209       }
00210     }
00211 
00212     //read the rest of the line
00213     const int sz=4000; char buf[sz];
00214     m_in.getline(buf, sz);
00215 
00216   } while (line_id != "NQ" && !m_in.eof());
00217 
00218 }