CMS 3D CMS Logo

RPCTrigger.cc

Go to the documentation of this file.
00001 #include "L1Trigger/RPCTrigger/interface/RPCTrigger.h"
00002 
00003 // Configuration via eventsetup:
00004 #include "CondFormats/DataRecord/interface/L1RPCConfigRcd.h"
00005 #include "CondFormats/L1TObjects/interface/L1RPCConfig.h"
00006 
00007 #include "CondFormats/DataRecord/interface/L1RPCConeBuilderRcd.h"
00008 #include "CondFormats/RPCObjects/interface/L1RPCConeBuilder.h"
00009 
00010 #include "CondFormats/DataRecord/interface/L1RPCHwConfigRcd.h"
00011 #include "CondFormats/RPCObjects/interface/L1RPCHwConfig.h"
00012 //#define ML_DEBUG 
00013 
00014 
00015 
00016 
00017 
00018 RPCTrigger::RPCTrigger(const edm::ParameterSet& iConfig):
00019    m_pacTrigger(0),
00020    m_trigConfig(0)
00021 {
00022   produces<std::vector<L1MuRegionalCand> >("RPCb");
00023   produces<std::vector<L1MuRegionalCand> >("RPCf");
00024   
00025 
00026   m_firstRun = true;
00027   m_cacheID = 0;
00028 
00029 
00030   m_triggerDebug = iConfig.getUntrackedParameter<int>("RPCTriggerDebug",0);
00031   
00032   // 0 - no debug
00033   // 2 - technical debug
00034   // 1 - human readable debug
00035   if ( m_triggerDebug != 1 && m_triggerDebug != 2)
00036      m_triggerDebug = 0;
00037    
00038   m_label = iConfig.getParameter<std::string>("label");
00039   m_buildOwnLinkSystem = iConfig.getParameter<bool>("buildOwnLinkSystem");
00040 }
00041 
00042 
00043 
00044 
00045 RPCTrigger::~RPCTrigger(){ 
00046    if (m_pacTrigger != 0) delete m_pacTrigger;
00047    if (m_trigConfig != 0) delete m_trigConfig;
00048 }
00049 
00050 
00051 
00052 void
00053 RPCTrigger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00054 {
00055  
00056 
00057 
00058   if (m_firstRun){
00059 
00060      m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
00061      m_firstRun = false;  
00062      edm::ESHandle<L1RPCConfig> conf;
00063      iSetup.get<L1RPCConfigRcd>().get(conf);
00064      const L1RPCConfig *rpcconf = conf.product();
00065 
00066 
00067      m_pacManager.init(rpcconf);
00068      m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
00069      m_trigConfig->setDebugLevel(m_triggerDebug);
00070      m_pacTrigger = new RPCPacTrigger(m_trigConfig);
00071 
00072       
00073   }
00074 
00075   if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {
00076 
00077       //std::cout << " New pats: " << iSetup.get<L1RPCConfigRcd>().cacheIdentifier() << std::endl ; 
00078       m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
00079 
00080      edm::ESHandle<L1RPCConfig> conf;
00081      iSetup.get<L1RPCConfigRcd>().get(conf);
00082      const L1RPCConfig *rpcconf = conf.product();
00083 
00084      m_pacManager.init(rpcconf);
00085      delete m_trigConfig;
00086      m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
00087      m_trigConfig->setDebugLevel(m_triggerDebug);
00088 
00089      delete m_pacTrigger;
00090      m_pacTrigger = new RPCPacTrigger(m_trigConfig);
00091 
00092 
00093        
00094   }
00095 
00096  
00097   // Build the trigger linksystem geometry (if not, use cone definitions from ES)
00098   if (m_buildOwnLinkSystem && !m_theLinksystem.isGeometryBuilt()){
00099 
00100     edm::LogInfo("RPC") << "Building RPC links map for a RPCTrigger";
00101     edm::ESHandle<RPCGeometry> rpcGeom;
00102     iSetup.get<MuonGeometryRecord>().get( rpcGeom );     
00103     m_theLinksystem.buildGeometry(rpcGeom);
00104     edm::LogInfo("RPC") << "RPC links map for a RPCTrigger built";
00105 
00106   } 
00107 
00108   
00109   edm::Handle<RPCDigiCollection> rpcDigis;
00110 //  iEvent.getByType(rpcDigis);
00111   //iEvent.getByLabel("muonRPCDigis",rpcDigis);
00112   iEvent.getByLabel(m_label, rpcDigis);
00113   std::auto_ptr<std::vector<L1MuRegionalCand> > candBarell(new std::vector<L1MuRegionalCand>);
00114   std::auto_ptr<std::vector<L1MuRegionalCand> > candForward(new std::vector<L1MuRegionalCand>);
00115     
00116   for (int iBx = -1; iBx < 2; ++ iBx) {
00117     
00118     L1RpcLogConesVec ActiveCones;
00119     if (m_buildOwnLinkSystem){
00120       ActiveCones = m_theLinksystem.getCones(rpcDigis, iBx);
00121     } else { //use es
00122       edm::ESHandle<L1RPCConeBuilder> coneBuilder;
00123       iSetup.get<L1RPCConeBuilderRcd>().get(coneBuilder);
00124 
00125       edm::ESHandle<L1RPCHwConfig> hwConfig;
00126       iSetup.get<L1RPCHwConfigRcd>().get(hwConfig);
00127 
00128       ActiveCones = m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, hwConfig, iBx);
00129       
00130     }
00131     
00132     L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones);
00133   
00134     int maxFiredPlanes = 0;
00135     
00136     for (unsigned int i=0;i<ActiveCones.size();i++){
00137         int fpCnt = ActiveCones[i].getFiredPlanesCnt();
00138         if (fpCnt > maxFiredPlanes)
00139           maxFiredPlanes = fpCnt;
00140     }
00141   
00142     // Fill out the products
00143     // finalMuons[0]=barell, finalMuons[1]=endcap
00144     LogDebug("RPCTrigger") << "---Filling candindates in new event--- " 
00145                           << maxFiredPlanes << std::endl;
00146     
00147     std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
00148     std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
00149       
00150     
00151     candBarell->insert(candBarell->end(), RPCb.begin(), RPCb.end());
00152   
00153 
00154     candForward->insert(candForward->end(), RPCf.begin(), RPCf.end());
00155 
00156   }  
00157   iEvent.put(candBarell, "RPCb");
00158   iEvent.put(candForward, "RPCf");
00159   
00160 }
00162 
00169 
00170 std::vector<L1MuRegionalCand> RPCTrigger::giveFinallCandindates(L1RpcTBMuonsVec finalMuons, int type, int bx){
00171 
00172   std::vector<L1MuRegionalCand> RPCCand;
00173   
00174   for(unsigned int iMu = 0; iMu < finalMuons.size(); iMu++)
00175   {
00176 
00177     if (finalMuons[iMu].getPtCode()==0){
00178       continue; 
00179     } 
00180 
00181     L1MuRegionalCand l1Cand;
00182     
00183     l1Cand.setBx(bx);
00184     
00185     
00186     l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
00187     l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
00188     
00189     l1Cand.setType(type); 
00190     
00191     int charge=finalMuons[iMu].getSign();
00192     
00193     if (charge == 0)  // negative
00194       l1Cand.setChargePacked(1);
00195     else  
00196       l1Cand.setChargePacked(0);
00197     
00198     //RPCConst::l1RpcConeCrdnts cone = finalMuons[iMu].getConeCrdnts();    
00199     
00200     /*
00201     int pac = cone.m_LogSector*12+cone.m_LogSegment;
00202     const float pi = 3.14159265;
00203     const float offset = 5*(2*pi/360); // redefinition! Defined also in RPCRingFromRolls::phiMapCompare
00204     float phi = 2*pi*pac/144-offset;
00205     if (phi<0)
00206       phi+=2*pi;
00207     
00208     l1Cand.setPhiValue(phi);
00209     */
00210 
00211     //Note: pac numbering begins at 5 deg and goes from 1 to 144.
00212     // we want phi values from 0 to 2.5 deg to be phiPacked=0 
00213     // max phiPacked value is 143 (see CMS IN 2004-022)
00214     //int phiPacked = (finalMuons[iMu].getPhiAddr()+2)%144;
00215     int phiPacked = finalMuons[iMu].getPhiAddr();
00216     l1Cand.setPhiPacked(phiPacked);
00217 /*
00218     float eta = RPCConst::etaFromTowerNum(cone.m_Tower);
00219     l1Cand.setEtaValue(eta);
00220 */
00221     //Note: etaAddr is packed in special way: see CMS IN 2004-022
00222     signed short etaAddr = finalMuons[iMu].getEtaAddr(); // 
00223 //    signed short etaAddr = finalMuons[iMu].getEtaAddr()-16; // -16..16
00224 //    bool etaNegative = false;
00225 //    if (etaAddr < 0){
00226 //      etaNegative = true;
00227 //      etaAddr = ~(-etaAddr)+1; // convert to negative :)
00228 //    }
00229 
00230 //    etaAddr &= 63; // 6 bits only
00231          
00232     l1Cand.setEtaPacked(etaAddr);
00233     l1Cand.setChargeValid(true);
00234 
00235     /*    
00236     std::cout<< std::endl << "RBMuon::" << finalMuons[iMu].getEtaAddr() << " " 
00237              << finalMuons[iMu].getPhiAddr() << std::endl ;
00238     std::cout<< "cand " <<  l1Cand.eta_packed() << " " 
00239              << l1Cand.phi_packed() << std::endl ;
00240     */
00241 
00242     RPCCand.push_back(l1Cand);
00243         
00244     LogDebug("RPCTrigger") << "Found muonf of pt " 
00245         << finalMuons[iMu].getPtCode()
00246         << " bx " << l1Cand.bx()
00247         << " L1Charge " << l1Cand.charge_packed()
00248         << " ql " << l1Cand.quality()
00249         << " fp " << finalMuons[iMu].getFiredPlanes()
00250         << " b/f " << l1Cand.type_idx()
00251         << " phi " <<  l1Cand.phi_packed()
00252         << " eta " << l1Cand.eta_packed()
00253         //<< " eta l1 " << l1Cand.etaValue() // will drop out soon 
00254         << " killed " << finalMuons[iMu].wasKilled();
00255         
00256     
00257   }
00258 
00259   return RPCCand;
00260 }
00261 

Generated on Tue Jun 9 17:40:21 2009 for CMSSW by  doxygen 1.5.4