CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/L1Trigger/RPCTrigger/plugins/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 
00013 #include "CondFormats/DataRecord/interface/L1RPCBxOrConfigRcd.h"
00014 #include "CondFormats/L1TObjects/interface/L1RPCBxOrConfig.h"
00015 
00016 
00017 
00018 //#define ML_DEBUG 
00019 
00020 
00021 
00022 #include "L1Trigger/RPCTrigger/interface/MuonsGrabber.h"
00023 
00024 
00025 RPCTrigger::RPCTrigger(const edm::ParameterSet& iConfig):
00026    m_trigConfig(0),m_pacTrigger(0)
00027 {
00028   produces<std::vector<L1MuRegionalCand> >("RPCb");
00029   produces<std::vector<L1MuRegionalCand> >("RPCf");
00030 
00031   produces<std::vector<RPCDigiL1Link> >("RPCb");
00032   produces<std::vector<RPCDigiL1Link> >("RPCf");
00033 
00034   m_firstRun = true;
00035   m_cacheID = 0;
00036 
00037 
00038   m_triggerDebug = iConfig.getUntrackedParameter<int>("RPCTriggerDebug",0);
00039   
00040   // 0 - no debug
00041   // 1 - dump to xml
00042   if ( m_triggerDebug != 1){
00043      m_triggerDebug = 0;
00044   }
00045      
00046    
00047   m_label = iConfig.getParameter<std::string>("label");
00048 }
00049 
00050 
00051 
00052 
00053 RPCTrigger::~RPCTrigger(){ 
00054    if (m_pacTrigger != 0) delete m_pacTrigger;
00055    if (m_trigConfig != 0) delete m_trigConfig;
00056 }
00057 
00058 
00059 
00060 void
00061 RPCTrigger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00062 {
00063  
00064   //static int ev=1;
00065   //std::cout << "----------------------------------- "  << ev++ << std::endl;
00066   if ( m_triggerDebug == 1)  MuonsGrabber::Instance().startNewEvent(iEvent.id().event(), iEvent.bunchCrossing());  
00067 
00068   if (m_firstRun){
00069 
00070      m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
00071      m_firstRun = false;  
00072      edm::ESHandle<L1RPCConfig> conf;
00073      iSetup.get<L1RPCConfigRcd>().get(conf);
00074      const L1RPCConfig *rpcconf = conf.product();
00075 
00076 
00077      m_pacManager.init(rpcconf);
00078      m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
00079      m_trigConfig->setDebugLevel(m_triggerDebug);
00080      m_pacTrigger = new RPCPacTrigger(m_trigConfig);
00081      if ( m_triggerDebug == 1)  MuonsGrabber::Instance().setRPCBasicTrigConfig(m_trigConfig);
00082 
00083       
00084   }
00085 
00086   if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {
00087 
00088       //std::cout << " New pats: " << iSetup.get<L1RPCConfigRcd>().cacheIdentifier() << std::endl ; 
00089       m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
00090 
00091      edm::ESHandle<L1RPCConfig> conf;
00092      iSetup.get<L1RPCConfigRcd>().get(conf);
00093      const L1RPCConfig *rpcconf = conf.product();
00094 
00095      m_pacManager.init(rpcconf);
00096      delete m_trigConfig;
00097      m_trigConfig = new RPCBasicTrigConfig(&m_pacManager);
00098      m_trigConfig->setDebugLevel(m_triggerDebug);
00099 
00100      delete m_pacTrigger;
00101      m_pacTrigger = new RPCPacTrigger(m_trigConfig);
00102 
00103      if ( m_triggerDebug == 1)  MuonsGrabber::Instance().setRPCBasicTrigConfig(m_trigConfig);
00104 
00105        
00106   }
00107 
00108  
00109   
00110   edm::Handle<RPCDigiCollection> rpcDigis;
00111 //  iEvent.getByType(rpcDigis);
00112   //iEvent.getByLabel("muonRPCDigis",rpcDigis);
00113   iEvent.getByLabel(m_label, rpcDigis);
00114 
00115   std::auto_ptr<std::vector<L1MuRegionalCand> > candBarell(new std::vector<L1MuRegionalCand>);
00116   std::auto_ptr<std::vector<L1MuRegionalCand> > candForward(new std::vector<L1MuRegionalCand>);
00117   if (!rpcDigis.isValid()) 
00118   {
00119      LogDebug("RPCTrigger")
00120           << "\nWarning: RPCDigiCollection with input tag " << m_label
00121           << "\nrequested in configuration, but not found in the event. Emulator will produce empty collection \n ";
00122 
00123           iEvent.put(candBarell, "RPCb");
00124           iEvent.put(candForward, "RPCf");
00125  
00126           return;
00127   }
00128 
00129   
00130   if (rpcDigis->begin() == rpcDigis->end() )
00131   {
00132      LogDebug("RPCTrigger")
00133           << "\nWarning: RPCDigiCollection with input tag " << m_label
00134           << "\n seems to be empty for this event. Emulator will run on empty collection ";
00135 
00136   }
00137 
00138 
00139 
00140   std::auto_ptr<std::vector<RPCDigiL1Link> >  brlLinks(new std::vector<RPCDigiL1Link>);
00141   std::auto_ptr<std::vector<RPCDigiL1Link> >  fwdLinks(new std::vector<RPCDigiL1Link>);
00142     
00143   for (int iBx = -1; iBx < 2; ++ iBx) {
00144     
00145     L1RpcLogConesVec ActiveCones;
00146 
00147     edm::ESHandle<L1RPCConeBuilder> coneBuilder;
00148     iSetup.get<L1RPCConeBuilderRcd>().get(coneBuilder);
00149       
00150     edm::ESHandle<L1RPCConeDefinition> l1RPCConeDefinition;
00151     iSetup.get<L1RPCConeDefinitionRcd>().get(l1RPCConeDefinition);
00152 
00153     edm::ESHandle<L1RPCHwConfig> hwConfig;
00154     iSetup.get<L1RPCHwConfigRcd>().get(hwConfig);
00155 
00156     edm::ESHandle<L1RPCBxOrConfig> bxOrConfig;
00157     iSetup.get<L1RPCBxOrConfigRcd>().get(bxOrConfig);
00158 
00159 
00160 
00161     ActiveCones = m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, l1RPCConeDefinition, bxOrConfig, hwConfig, iBx);
00162     
00163     edm::ESHandle<L1RPCHsbConfig> hsbConfig;
00164     iSetup.get<L1RPCHsbConfigRcd>().get(hsbConfig);
00165 
00166     L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones, hsbConfig);
00167   
00168     //int maxFiredPlanes = 0;
00169     
00170     /*
00171     for (unsigned int i=0;i<ActiveCones.size();i++){
00172         int fpCnt = ActiveCones[i].getFiredPlanesCnt();
00173         if (fpCnt > maxFiredPlanes)
00174           maxFiredPlanes = fpCnt;
00175     }
00176   
00177     // Fill out the products
00178     // finalMuons[0]=barell, finalMuons[1]=endcap
00179     LogDebug("RPCTrigger") << "---Filling candindates in new event--- " 
00180                           << maxFiredPlanes << std::endl;
00181 <<<<<<< RPCTrigger.cc
00182     */
00183     
00184 //    std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
00185 //    std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
00186     std::vector<RPCDigiL1Link> dlBrl;  
00187     std::vector<RPCDigiL1Link> dlFwd;  
00188     std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx, rpcDigis, dlBrl);
00189     std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx, rpcDigis, dlFwd);
00190       
00191     
00192     brlLinks->insert(brlLinks->end(), dlBrl.begin(), dlBrl.end() );
00193     fwdLinks->insert(fwdLinks->end(), dlFwd.begin(), dlFwd.end() );
00194 
00195     candBarell->insert(candBarell->end(), RPCb.begin(), RPCb.end());
00196     candForward->insert(candForward->end(), RPCf.begin(), RPCf.end());
00197 
00198     if ( m_triggerDebug == 1)  MuonsGrabber::Instance().writeDataForRelativeBX(iBx);  
00199   }  
00200 
00201   iEvent.put(fwdLinks, "RPCf");
00202   iEvent.put(brlLinks, "RPCb");
00203   iEvent.put(candBarell, "RPCb");
00204   iEvent.put(candForward, "RPCf");
00205   
00206 }
00208 
00215 
00216 std::vector<L1MuRegionalCand> RPCTrigger::giveFinallCandindates(L1RpcTBMuonsVec finalMuons, int type, int bx,   
00217                                      edm::Handle<RPCDigiCollection> rpcDigis, std::vector<RPCDigiL1Link> & retRPCDigiLink)
00218 {
00219 
00220   std::vector<L1MuRegionalCand> RPCCand;
00221 
00222   for(unsigned int iMu = 0; iMu < finalMuons.size(); iMu++)
00223   {
00224 
00225     if (finalMuons[iMu].getPtCode()==0){
00226       continue; 
00227     } 
00228 
00229     RPCDigiL1Link newDigiLink;
00230 
00231     //std::cout << "######################################## " << std::endl;
00232     //std::cout << finalMuons[iMu].getPhiAddr() << " " << finalMuons[iMu].getEtaAddr() << std::endl;
00233     RPCMuon::TDigiLinkVec digiIVec = finalMuons[iMu].getDigiIdxVec();
00234     // Here the iteration has to be the same as in 
00235     short int digiIndex = 0;
00236     RPCDigiCollection::DigiRangeIterator detUnitIt;
00237     for (detUnitIt=rpcDigis->begin();
00238          detUnitIt!=rpcDigis->end();
00239          ++detUnitIt)
00240     {
00241 
00242       const RPCDetId& id = (*detUnitIt).first;
00243       uint32_t rawId = id.rawId();
00244       const RPCDigiCollection::Range& range = (*detUnitIt).second;
00245 
00246 
00247       for (RPCDigiCollection::const_iterator digiIt = range.first;
00248            digiIt!=range.second;
00249            ++digiIt)
00250       {
00251         ++digiIndex;
00252 
00253         RPCMuon::TDigiLinkVec::iterator it = digiIVec.begin();
00254         for(;it!=digiIVec.end();++it) {
00255            if (digiIndex==it->m_digiIdx) {
00256              newDigiLink.setLink(it->m_layer+1, rawId, digiIt->strip(), digiIt->bx() );
00257              //std::cout << type << " " << iMu << " layer: " << it->m_layer <<  " index " << it->m_digiIdx << std::endl;
00258              //std::cout << "         " << id << " " << " |bx " << digiIt->bx() << " strip " << digiIt->strip() << std::endl;  
00259            }
00260         }
00261       }
00262     }
00263     retRPCDigiLink.push_back(newDigiLink);
00264 
00265 
00266     L1MuRegionalCand l1Cand;
00267     
00268     l1Cand.setBx(bx);
00269     
00270     
00271     l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
00272     l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
00273     
00274     l1Cand.setType(type); 
00275     
00276     int charge=finalMuons[iMu].getSign();
00277     
00278     if (charge == 0)  // negative
00279       l1Cand.setChargePacked(1);
00280     else  
00281       l1Cand.setChargePacked(0);
00282     
00283     //RPCConst::l1RpcConeCrdnts cone = finalMuons[iMu].getConeCrdnts();    
00284     
00285     /*
00286     int pac = cone.m_LogSector*12+cone.m_LogSegment;
00287     const float pi = 3.14159265;
00288     const float offset = 5*(2*pi/360); // redefinition! Defined also in RPCRingFromRolls::phiMapCompare
00289     float phi = 2*pi*pac/144-offset;
00290     if (phi<0)
00291       phi+=2*pi;
00292     
00293     l1Cand.setPhiValue(phi);
00294     */
00295 
00296     //Note: pac numbering begins at 5 deg and goes from 1 to 144.
00297     // we want phi values from 0 to 2.5 deg to be phiPacked=0 
00298     // max phiPacked value is 143 (see CMS IN 2004-022)
00299     //int phiPacked = (finalMuons[iMu].getPhiAddr()+2)%144;
00300     int phiPacked = finalMuons[iMu].getPhiAddr();
00301     l1Cand.setPhiPacked(phiPacked);
00302 /*
00303     float eta = RPCConst::etaFromTowerNum(cone.m_Tower);
00304     l1Cand.setEtaValue(eta);
00305 */
00306     //Note: etaAddr is packed in special way: see CMS IN 2004-022
00307     signed short etaAddr = finalMuons[iMu].getEtaAddr(); // 
00308 //    signed short etaAddr = finalMuons[iMu].getEtaAddr()-16; // -16..16
00309 //    bool etaNegative = false;
00310 //    if (etaAddr < 0){
00311 //      etaNegative = true;
00312 //      etaAddr = ~(-etaAddr)+1; // convert to negative :)
00313 //    }
00314 
00315 //    etaAddr &= 63; // 6 bits only
00316          
00317     l1Cand.setEtaPacked(etaAddr);
00318     l1Cand.setChargeValid(true);
00319 
00320     /*    
00321     std::cout<< std::endl << "RBMuon::" << finalMuons[iMu].getEtaAddr() << " " 
00322              << finalMuons[iMu].getPhiAddr() << std::endl ;
00323     std::cout<< "cand " <<  l1Cand.eta_packed() << " " 
00324              << l1Cand.phi_packed() << std::endl ;
00325     */
00326 
00327     RPCCand.push_back(l1Cand);
00328         
00329     LogDebug("RPCTrigger") << "Found muonf of pt " 
00330         << finalMuons[iMu].getPtCode()
00331         << " bx " << l1Cand.bx()
00332         << " L1Charge " << l1Cand.charge_packed()
00333         << " ql " << l1Cand.quality()
00334         << " fp " << finalMuons[iMu].getFiredPlanes()
00335         << " b/f " << l1Cand.type_idx()
00336         << " phi " <<  l1Cand.phi_packed()
00337         << " eta " << l1Cand.eta_packed()
00338         //<< " eta l1 " << l1Cand.etaValue() // will drop out soon 
00339         << " killed " << finalMuons[iMu].wasKilled();
00340         
00341     
00342   }
00343 
00344   return RPCCand;
00345 }
00346