Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:36

0001 #include "L1Trigger/RPCTrigger/interface/RPCTrigger.h"
0002 //#define ML_DEBUG
0003 
0004 #include "L1Trigger/RPCTrigger/interface/MuonsGrabber.h"
0005 
0006 RPCTrigger::RPCTrigger(const edm::ParameterSet& iConfig)
0007     : m_trigConfig(),
0008       m_pacTrigger(),
0009       // 0 - no debug
0010       // 1 - dump to xml
0011       m_triggerDebug{iConfig.getUntrackedParameter<int>("RPCTriggerDebug", 0) == 1 ? 1 : 0},
0012       m_cacheID{0},
0013       m_label{iConfig.getParameter<std::string>("label")},
0014       m_rpcDigiToken{consumes<RPCDigiCollection>(m_label)},
0015 
0016       m_brlCandPutToken{produces<std::vector<L1MuRegionalCand> >("RPCb")},
0017       m_fwdCandPutToken{produces<std::vector<L1MuRegionalCand> >("RPCf")},
0018 
0019       m_brlLinksPutToken{produces<std::vector<RPCDigiL1Link> >("RPCb")},
0020       m_fwdLinksPutToken{produces<std::vector<RPCDigiL1Link> >("RPCf")},
0021       m_configToken(esConsumes<L1RPCConfig, L1RPCConfigRcd>()),
0022       m_coneBuilderToken(esConsumes<L1RPCConeBuilder, L1RPCConeBuilderRcd>()),
0023       m_coneDefinitionToken(esConsumes<L1RPCConeDefinition, L1RPCConeDefinitionRcd>()),
0024       m_hwConfigToken(esConsumes<L1RPCHwConfig, L1RPCHwConfigRcd>()),
0025       m_BxOrConfigToken(esConsumes<L1RPCBxOrConfig, L1RPCBxOrConfigRcd>()),
0026       m_hsbConfigToken(esConsumes<L1RPCHsbConfig, L1RPCHsbConfigRcd>()) {
0027   //MuonsGrabber is a singleton
0028   usesResource("MuonsGrabber");
0029 }
0030 
0031 void RPCTrigger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0032   //static int ev=1;
0033   //std::cout << "----------------------------------- "  << ev++ << std::endl;
0034   if (m_triggerDebug == 1)
0035     MuonsGrabber::Instance().startNewEvent(iEvent.id().event(), iEvent.bunchCrossing());
0036 
0037   if (m_cacheID != iSetup.get<L1RPCConfigRcd>().cacheIdentifier()) {
0038     //std::cout << " New pats: " << iSetup.get<L1RPCConfigRcd>().cacheIdentifier() << std::endl ;
0039     m_cacheID = iSetup.get<L1RPCConfigRcd>().cacheIdentifier();
0040 
0041     edm::ESHandle<L1RPCConfig> conf = iSetup.getHandle(m_configToken);
0042     const L1RPCConfig* rpcconf = conf.product();
0043 
0044     m_pacManager.init(rpcconf);
0045     m_trigConfig = std::make_unique<RPCBasicTrigConfig>(&m_pacManager);
0046     m_trigConfig->setDebugLevel(m_triggerDebug);
0047 
0048     m_pacTrigger = std::make_unique<RPCPacTrigger>(m_trigConfig.get());
0049 
0050     if (m_triggerDebug == 1)
0051       MuonsGrabber::Instance().setRPCBasicTrigConfig(m_trigConfig.get());
0052   }
0053 
0054   edm::Handle<RPCDigiCollection> rpcDigis;
0055   iEvent.getByToken(m_rpcDigiToken, rpcDigis);
0056 
0057   std::vector<L1MuRegionalCand> candBarell;
0058   std::vector<L1MuRegionalCand> candForward;
0059   if (!rpcDigis.isValid()) {
0060     LogDebug("RPCTrigger")
0061         << "\nWarning: RPCDigiCollection with input tag " << m_label
0062         << "\nrequested in configuration, but not found in the event. Emulator will produce empty collection \n ";
0063 
0064     iEvent.emplace(m_brlCandPutToken, std::move(candBarell));
0065     iEvent.emplace(m_fwdCandPutToken, std::move(candForward));
0066 
0067     return;
0068   }
0069 
0070   if (rpcDigis->begin() == rpcDigis->end()) {
0071     LogDebug("RPCTrigger") << "\nWarning: RPCDigiCollection with input tag " << m_label
0072                            << "\n seems to be empty for this event. Emulator will run on empty collection ";
0073   }
0074 
0075   std::vector<RPCDigiL1Link> brlLinks;
0076   std::vector<RPCDigiL1Link> fwdLinks;
0077 
0078   edm::ESHandle<L1RPCConeBuilder> coneBuilder = iSetup.getHandle(m_coneBuilderToken);
0079 
0080   edm::ESHandle<L1RPCConeDefinition> l1RPCConeDefinition = iSetup.getHandle(m_coneDefinitionToken);
0081 
0082   edm::ESHandle<L1RPCHwConfig> hwConfig = iSetup.getHandle(m_hwConfigToken);
0083 
0084   edm::ESHandle<L1RPCBxOrConfig> bxOrConfig = iSetup.getHandle(m_BxOrConfigToken);
0085 
0086   edm::ESHandle<L1RPCHsbConfig> hsbConfig = iSetup.getHandle(m_hsbConfigToken);
0087 
0088   for (int iBx = -1; iBx < 2; ++iBx) {
0089     L1RpcLogConesVec ActiveCones =
0090         m_theLinksystemFromES.getConesFromES(rpcDigis, coneBuilder, l1RPCConeDefinition, bxOrConfig, hwConfig, iBx);
0091 
0092     L1RpcTBMuonsVec2 finalMuons = m_pacTrigger->runEvent(ActiveCones, hsbConfig);
0093 
0094     //int maxFiredPlanes = 0;
0095 
0096     /*
0097     for (unsigned int i=0;i<ActiveCones.size();i++){
0098         int fpCnt = ActiveCones[i].getFiredPlanesCnt();
0099         if (fpCnt > maxFiredPlanes)
0100           maxFiredPlanes = fpCnt;
0101     }
0102   
0103     // Fill out the products
0104     // finalMuons[0]=barell, finalMuons[1]=endcap
0105     LogDebug("RPCTrigger") << "---Filling candindates in new event--- " 
0106                           << maxFiredPlanes << std::endl;
0107 <<<<<<< RPCTrigger.cc
0108     */
0109 
0110     //    std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0],1, iBx);
0111     //    std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1],3, iBx);
0112     std::vector<RPCDigiL1Link> dlBrl;
0113     std::vector<RPCDigiL1Link> dlFwd;
0114     std::vector<L1MuRegionalCand> RPCb = giveFinallCandindates(finalMuons[0], 1, iBx, rpcDigis, dlBrl);
0115     std::vector<L1MuRegionalCand> RPCf = giveFinallCandindates(finalMuons[1], 3, iBx, rpcDigis, dlFwd);
0116 
0117     brlLinks.insert(brlLinks.end(), dlBrl.begin(), dlBrl.end());
0118     fwdLinks.insert(fwdLinks.end(), dlFwd.begin(), dlFwd.end());
0119 
0120     candBarell.insert(candBarell.end(), RPCb.begin(), RPCb.end());
0121     candForward.insert(candForward.end(), RPCf.begin(), RPCf.end());
0122 
0123     if (m_triggerDebug == 1)
0124       MuonsGrabber::Instance().writeDataForRelativeBX(iBx);
0125   }
0126 
0127   iEvent.emplace(m_fwdLinksPutToken, std::move(fwdLinks));
0128   iEvent.emplace(m_brlLinksPutToken, std::move(brlLinks));
0129   iEvent.emplace(m_brlCandPutToken, std::move(candBarell));
0130   iEvent.emplace(m_fwdCandPutToken, std::move(candForward));
0131 }
0132 ///////////////////////////////////////////////////////////////////////////////
0133 /**
0134  *
0135  * \brief Returns vector of L1MuRegionalCand (input of L1GMT)
0136  * \note - type is defined in L1MuRegionalCand 1 - barell, 3 - forward
0137  * \todo - we use offset value of 5 deegres. It should be stored centrally.
0138  *
0139  */
0140 ///////////////////////////////////////////////////////////////////////////////
0141 std::vector<L1MuRegionalCand> RPCTrigger::giveFinallCandindates(const L1RpcTBMuonsVec& finalMuons,
0142                                                                 int type,
0143                                                                 int bx,
0144                                                                 edm::Handle<RPCDigiCollection> rpcDigis,
0145                                                                 std::vector<RPCDigiL1Link>& retRPCDigiLink) {
0146   std::vector<L1MuRegionalCand> RPCCand;
0147 
0148   for (unsigned int iMu = 0; iMu < finalMuons.size(); iMu++) {
0149     if (finalMuons[iMu].getPtCode() == 0) {
0150       continue;
0151     }
0152 
0153     RPCDigiL1Link newDigiLink;
0154 
0155     //std::cout << "######################################## " << std::endl;
0156     //std::cout << finalMuons[iMu].getPhiAddr() << " " << finalMuons[iMu].getEtaAddr() << std::endl;
0157     RPCMuon::TDigiLinkVec digiIVec = finalMuons[iMu].getDigiIdxVec();
0158     // Here the iteration has to be the same as in
0159     short int digiIndex = 0;
0160     RPCDigiCollection::DigiRangeIterator detUnitIt;
0161     for (detUnitIt = rpcDigis->begin(); detUnitIt != rpcDigis->end(); ++detUnitIt) {
0162       const RPCDetId& id = (*detUnitIt).first;
0163       uint32_t rawId = id.rawId();
0164       const RPCDigiCollection::Range& range = (*detUnitIt).second;
0165 
0166       for (RPCDigiCollection::const_iterator digiIt = range.first; digiIt != range.second; ++digiIt) {
0167         ++digiIndex;
0168 
0169         RPCMuon::TDigiLinkVec::iterator it = digiIVec.begin();
0170         for (; it != digiIVec.end(); ++it) {
0171           if (digiIndex == it->m_digiIdx) {
0172             newDigiLink.setLink(it->m_layer + 1, rawId, digiIt->strip(), digiIt->bx());
0173             //std::cout << type << " " << iMu << " layer: " << it->m_layer <<  " index " << it->m_digiIdx << std::endl;
0174             //std::cout << "         " << id << " " << " |bx " << digiIt->bx() << " strip " << digiIt->strip() << std::endl;
0175           }
0176         }
0177       }
0178     }
0179     retRPCDigiLink.push_back(newDigiLink);
0180 
0181     L1MuRegionalCand l1Cand;
0182 
0183     l1Cand.setBx(bx);
0184 
0185     l1Cand.setQualityPacked(finalMuons[iMu].getQuality());
0186     l1Cand.setPtPacked(finalMuons[iMu].getPtCode());
0187 
0188     l1Cand.setType(type);
0189 
0190     int charge = finalMuons[iMu].getSign();
0191 
0192     if (charge == 0)  // negative
0193       l1Cand.setChargePacked(1);
0194     else
0195       l1Cand.setChargePacked(0);
0196 
0197     //RPCConst::l1RpcConeCrdnts cone = finalMuons[iMu].getConeCrdnts();
0198 
0199     /*
0200     int pac = cone.m_LogSector*12+cone.m_LogSegment;
0201     const float pi = 3.14159265;
0202     const float offset = 5*(2*pi/360); // redefinition! Defined also in RPCRingFromRolls::phiMapCompare
0203     float phi = 2*pi*pac/144-offset;
0204     if (phi<0)
0205       phi+=2*pi;
0206     
0207     l1Cand.setPhiValue(phi);
0208     */
0209 
0210     //Note: pac numbering begins at 5 deg and goes from 1 to 144.
0211     // we want phi values from 0 to 2.5 deg to be phiPacked=0
0212     // max phiPacked value is 143 (see CMS IN 2004-022)
0213     //int phiPacked = (finalMuons[iMu].getPhiAddr()+2)%144;
0214     int phiPacked = finalMuons[iMu].getPhiAddr();
0215     l1Cand.setPhiPacked(phiPacked);
0216     /*
0217     float eta = RPCConst::etaFromTowerNum(cone.m_Tower);
0218     l1Cand.setEtaValue(eta);
0219 */
0220     //Note: etaAddr is packed in special way: see CMS IN 2004-022
0221     signed short etaAddr = finalMuons[iMu].getEtaAddr();  //
0222     //    signed short etaAddr = finalMuons[iMu].getEtaAddr()-16; // -16..16
0223     //    bool etaNegative = false;
0224     //    if (etaAddr < 0){
0225     //      etaNegative = true;
0226     //      etaAddr = ~(-etaAddr)+1; // convert to negative :)
0227     //    }
0228 
0229     //    etaAddr &= 63; // 6 bits only
0230 
0231     l1Cand.setEtaPacked(etaAddr);
0232     l1Cand.setChargeValid(true);
0233 
0234     /*    
0235     std::cout<< std::endl << "RBMuon::" << finalMuons[iMu].getEtaAddr() << " " 
0236              << finalMuons[iMu].getPhiAddr() << std::endl ;
0237     std::cout<< "cand " <<  l1Cand.eta_packed() << " " 
0238              << l1Cand.phi_packed() << std::endl ;
0239     */
0240 
0241     RPCCand.push_back(l1Cand);
0242 
0243     LogDebug("RPCTrigger") << "Found muonf of pt " << finalMuons[iMu].getPtCode() << " bx " << l1Cand.bx()
0244                            << " L1Charge " << l1Cand.charge_packed() << " ql " << l1Cand.quality() << " fp "
0245                            << finalMuons[iMu].getFiredPlanes() << " b/f " << l1Cand.type_idx() << " phi "
0246                            << l1Cand.phi_packed() << " eta "
0247                            << l1Cand.eta_packed()
0248                            //<< " eta l1 " << l1Cand.etaValue() // will drop out soon
0249                            << " killed " << finalMuons[iMu].wasKilled();
0250   }
0251 
0252   return RPCCand;
0253 }