Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-23 12:04:25

0001 #include "DataFormats/Common/interface/Handle.h"
0002 
0003 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0004 #include "DataFormats/HLTReco/interface/TriggerRefsCollections.h"
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "DataFormats/TrackReco/interface/Track.h"
0009 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0010 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0011 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0012 #include "HLTMuonTrkFilter.h"
0013 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0014 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
0015 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
0016 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
0017 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
0018 
0019 #include "TrackingTools/PatternTools/interface/ClosestApproachInRPhi.h"
0020 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0021 #include "MagneticField/Engine/interface/MagneticField.h"
0022 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0025 #include "FWCore/Utilities/interface/InputTag.h"
0026 #include "FWCore/Utilities/interface/EDMException.h"
0027 
0028 #include "DataFormats/Math/interface/deltaR.h"
0029 
0030 HLTMuonTrkFilter::HLTMuonTrkFilter(const edm::ParameterSet& iConfig)
0031     : HLTFilter(iConfig),
0032       propSetup_(iConfig, consumesCollector()),
0033       m_muonsTag(iConfig.getParameter<edm::InputTag>("inputMuonCollection")),
0034       m_muonsToken(consumes<reco::MuonCollection>(m_muonsTag)),
0035       m_candsTag(iConfig.getParameter<edm::InputTag>("inputCandCollection")),
0036       m_candsToken(consumes<reco::RecoChargedCandidateCollection>(m_candsTag)),
0037       m_previousCandTag(iConfig.getParameter<edm::InputTag>("previousCandTag")),
0038       m_previousCandToken(consumes<trigger::TriggerFilterObjectWithRefs>(m_previousCandTag)),
0039       m_minTrkHits(iConfig.getParameter<int>("minTrkHits")),
0040       m_minMuonHits(iConfig.getParameter<int>("minMuonHits")),
0041       m_minMuonStations(iConfig.getParameter<int>("minMuonStations")),
0042       m_maxNormalizedChi2(iConfig.getParameter<double>("maxNormalizedChi2")),
0043       m_allowedTypeMask(iConfig.getParameter<unsigned int>("allowedTypeMask")),
0044       m_requiredTypeMask(iConfig.getParameter<unsigned int>("requiredTypeMask")),
0045       m_trkMuonId(muon::SelectionType(iConfig.getParameter<unsigned int>("trkMuonId"))),
0046       m_minPt(iConfig.getParameter<double>("minPt")),
0047       m_minN(iConfig.getParameter<unsigned int>("minN")),
0048       m_maxAbsEta(iConfig.getParameter<double>("maxAbsEta")),
0049       m_l1MatchingdR(iConfig.getParameter<double>("L1MatchingdR")),
0050       m_l1MatchingdR2(m_l1MatchingdR * m_l1MatchingdR) {
0051   if (m_l1MatchingdR <= 0.) {
0052     throw cms::Exception("HLTMuonTrkFilterConfiguration")
0053         << "invalid value for parameter \"L1MatchingdR\" (must be > 0): " << m_l1MatchingdR;
0054   }
0055 }
0056 
0057 void HLTMuonTrkFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0058   edm::ParameterSetDescription desc;
0059   makeHLTFilterDescription(desc);
0060   desc.add<edm::InputTag>("inputMuonCollection", edm::InputTag(""));
0061   desc.add<edm::InputTag>("inputCandCollection", edm::InputTag(""));
0062   desc.add<edm::InputTag>("previousCandTag", edm::InputTag(""));
0063   desc.add<int>("minTrkHits", -1);
0064   desc.add<int>("minMuonHits", -1);
0065   desc.add<int>("minMuonStations", -1);
0066   desc.add<double>("maxNormalizedChi2", 1e99);
0067   desc.add<unsigned int>("allowedTypeMask", 255);
0068   desc.add<unsigned int>("requiredTypeMask", 0);
0069   desc.add<unsigned int>("trkMuonId", 0);
0070   desc.add<double>("minPt", 24);
0071   desc.add<unsigned int>("minN", 1);
0072   desc.add<double>("maxAbsEta", 1e99);
0073   desc.add<double>("L1MatchingdR", 0.3);
0074   PropagateToMuonSetup::fillPSetDescription(desc);
0075   descriptions.add("hltMuonTrkFilter", desc);
0076 }
0077 
0078 bool HLTMuonTrkFilter::hltFilter(edm::Event& iEvent,
0079                                  const edm::EventSetup& iSetup,
0080                                  trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0081   auto const prop = propSetup_.init(iSetup);
0082 
0083   edm::Handle<reco::MuonCollection> muons;
0084   iEvent.getByToken(m_muonsToken, muons);
0085   edm::Handle<reco::RecoChargedCandidateCollection> cands;
0086   iEvent.getByToken(m_candsToken, cands);
0087   if (saveTags())
0088     filterproduct.addCollectionTag(m_candsTag);
0089   if (cands->size() != muons->size())
0090     throw edm::Exception(edm::errors::Configuration)
0091         << "Both input collection must be aligned and represent same physical muon objects";
0092 
0093   edm::Handle<trigger::TriggerFilterObjectWithRefs> previousLevelCands;
0094   std::vector<l1extra::L1MuonParticleRef> vl1cands;
0095   std::vector<l1extra::L1MuonParticleRef>::iterator vl1cands_begin;
0096   std::vector<l1extra::L1MuonParticleRef>::iterator vl1cands_end;
0097 
0098   bool check_l1match = true;
0099   if (m_previousCandTag == edm::InputTag(""))
0100     check_l1match = false;
0101   if (check_l1match) {
0102     iEvent.getByToken(m_previousCandToken, previousLevelCands);
0103     previousLevelCands->getObjects(trigger::TriggerL1Mu, vl1cands);
0104     vl1cands_begin = vl1cands.begin();
0105     vl1cands_end = vl1cands.end();
0106   }
0107 
0108   std::vector<unsigned int> filteredMuons;
0109   for (unsigned int i = 0; i < muons->size(); ++i) {
0110     const reco::Muon& muon(muons->at(i));
0111     if (check_l1match) {
0112       const reco::RecoChargedCandidateRef cand(cands, i);
0113       const reco::TrackRef tk = cand->track();
0114       auto etaForMatch = cand->eta();
0115       auto phiForMatch = cand->phi();
0116       // check for dR match to L1 muons
0117       if (tk.isNonnull()) {
0118         auto const propagated = prop.extrapolate(*tk);
0119         if (propagated.isValid()) {
0120           etaForMatch = propagated.globalPosition().eta();
0121           phiForMatch = propagated.globalPosition().phi();
0122         }
0123       }
0124       bool matchl1 = false;
0125       for (auto l1cand = vl1cands_begin; l1cand != vl1cands_end; ++l1cand) {
0126         if (deltaR2(etaForMatch, phiForMatch, (*l1cand)->eta(), (*l1cand)->phi()) < m_l1MatchingdR2) {
0127           matchl1 = true;
0128           break;
0129         }
0130       }
0131       if (!matchl1)
0132         continue;
0133     }
0134     if ((muon.type() & m_allowedTypeMask) == 0)
0135       continue;
0136     if ((muon.type() & m_requiredTypeMask) != m_requiredTypeMask)
0137       continue;
0138     if (muon.numberOfMatchedStations() < m_minMuonStations)
0139       continue;
0140     if (!muon.innerTrack().isNull()) {
0141       if (muon.innerTrack()->numberOfValidHits() < m_minTrkHits)
0142         continue;
0143     }
0144     if (!muon.globalTrack().isNull()) {
0145       if (muon.globalTrack()->normalizedChi2() > m_maxNormalizedChi2)
0146         continue;
0147       if (muon.globalTrack()->hitPattern().numberOfValidMuonHits() < m_minMuonHits)
0148         continue;
0149     }
0150     if (muon.isTrackerMuon() && !muon::isGoodMuon(muon, m_trkMuonId))
0151       continue;
0152     if (muon.pt() < m_minPt)
0153       continue;
0154     if (std::abs(muon.eta()) > m_maxAbsEta)
0155       continue;
0156     filteredMuons.push_back(i);
0157   }
0158 
0159   for (std::vector<unsigned int>::const_iterator itr = filteredMuons.begin(); itr != filteredMuons.end(); ++itr)
0160     filterproduct.addObject(trigger::TriggerMuon, reco::RecoChargedCandidateRef(cands, *itr));
0161 
0162   return filteredMuons.size() >= m_minN;
0163 }
0164 
0165 // declare this class as a framework plugin
0166 #include "FWCore/Framework/interface/MakerMacros.h"
0167 DEFINE_FWK_MODULE(HLTMuonTrkFilter);