Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-26 00:19:25

0001 #include "HLTMuonTrkL1TkMuFilter.h"
0002 
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
0005 #include "DataFormats/HLTReco/interface/TriggerRefsCollections.h"
0006 #include "DataFormats/Math/interface/deltaR.h"
0007 #include "DataFormats/TrackReco/interface/Track.h"
0008 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
0009 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
0010 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0011 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0012 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
0013 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
0014 
0015 #include "TrackingTools/PatternTools/interface/ClosestApproachInRPhi.h"
0016 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0017 #include "MagneticField/Engine/interface/MagneticField.h"
0018 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0019 
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0023 #include "FWCore/Utilities/interface/InputTag.h"
0024 #include "FWCore/Utilities/interface/EDMException.h"
0025 
0026 HLTMuonTrkL1TkMuFilter::HLTMuonTrkL1TkMuFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) {
0027   m_muonsTag = iConfig.getParameter<edm::InputTag>("inputMuonCollection");
0028   m_muonsToken = consumes<reco::MuonCollection>(m_muonsTag);
0029   m_candsTag = iConfig.getParameter<edm::InputTag>("inputCandCollection");
0030   m_candsToken = consumes<reco::RecoChargedCandidateCollection>(m_candsTag);
0031   m_previousCandTag = iConfig.getParameter<edm::InputTag>("previousCandTag");
0032   m_previousCandToken = consumes<trigger::TriggerFilterObjectWithRefs>(m_previousCandTag);
0033   m_minTrkHits = iConfig.getParameter<int>("minTrkHits");
0034   m_minMuonHits = iConfig.getParameter<int>("minMuonHits");
0035   m_minMuonStations = iConfig.getParameter<int>("minMuonStations");
0036   m_maxNormalizedChi2 = iConfig.getParameter<double>("maxNormalizedChi2");
0037   m_minPt = iConfig.getParameter<double>("minPt");
0038   m_minN = iConfig.getParameter<unsigned int>("minN");
0039   m_maxAbsEta = iConfig.getParameter<double>("maxAbsEta");
0040 }
0041 
0042 void HLTMuonTrkL1TkMuFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0043   edm::ParameterSetDescription desc;
0044   makeHLTFilterDescription(desc);
0045   desc.add<edm::InputTag>("inputMuonCollection", edm::InputTag(""));
0046   desc.add<edm::InputTag>("inputCandCollection", edm::InputTag(""));
0047   desc.add<edm::InputTag>("previousCandTag", edm::InputTag(""));
0048   desc.add<int>("minTrkHits", -1);
0049   desc.add<int>("minMuonHits", -1);
0050   desc.add<int>("minMuonStations", -1);
0051   desc.add<double>("maxNormalizedChi2", 1e99);
0052   desc.add<unsigned int>("trkMuonId", 0);
0053   desc.add<double>("minPt", 24);
0054   desc.add<unsigned int>("minN", 1);
0055   desc.add<double>("maxAbsEta", 1e99);
0056   descriptions.add("hltMuonTrkL1TkMuFilter", desc);
0057 }
0058 
0059 bool HLTMuonTrkL1TkMuFilter::hltFilter(edm::Event& iEvent,
0060                                        const edm::EventSetup& iSetup,
0061                                        trigger::TriggerFilterObjectWithRefs& filterproduct) const {
0062   edm::Handle<reco::MuonCollection> muons;
0063   iEvent.getByToken(m_muonsToken, muons);
0064   edm::Handle<reco::RecoChargedCandidateCollection> cands;
0065   iEvent.getByToken(m_candsToken, cands);
0066   if (saveTags())
0067     filterproduct.addCollectionTag(m_candsTag);
0068   if (cands->size() != muons->size())
0069     throw edm::Exception(edm::errors::Configuration)
0070         << "Both input collection must be aligned and represent same physical muon objects";
0071 
0072   edm::Handle<trigger::TriggerFilterObjectWithRefs> previousLevelCands;
0073   std::vector<l1t::TrackerMuonRef> vl1cands;
0074 
0075   bool check_l1match = true;
0076   if (m_previousCandTag == edm::InputTag(""))
0077     check_l1match = false;
0078   if (check_l1match) {
0079     iEvent.getByToken(m_previousCandToken, previousLevelCands);
0080     previousLevelCands->getObjects(trigger::TriggerL1TkMu, vl1cands);
0081   }
0082 
0083   std::vector<unsigned int> filteredMuons;
0084   for (unsigned int i = 0; i < muons->size(); ++i) {
0085     const reco::Muon& muon(muons->at(i));
0086     // check for dR match to L1 muons
0087     if (check_l1match) {
0088       bool matchl1 = false;
0089       for (auto const& l1cand : vl1cands) {
0090         if (deltaR2(muon, *l1cand) < 0.3 * 0.3) {
0091           matchl1 = true;
0092           break;
0093         }
0094       }
0095       if (!matchl1)
0096         continue;
0097     }
0098 
0099     if (muon.numberOfMatchedStations() < m_minMuonStations)
0100       continue;
0101 
0102     if (!muon.innerTrack().isNull()) {
0103       if (muon.innerTrack()->numberOfValidHits() < m_minTrkHits)
0104         continue;
0105     }
0106 
0107     if (!muon.globalTrack().isNull()) {
0108       if (muon.globalTrack()->normalizedChi2() > m_maxNormalizedChi2)
0109         continue;
0110       if (muon.globalTrack()->hitPattern().numberOfValidMuonHits() < m_minMuonHits)
0111         continue;
0112     }
0113 
0114     if (muon.pt() < m_minPt)
0115       continue;
0116 
0117     if (std::abs(muon.eta()) > m_maxAbsEta)
0118       continue;
0119 
0120     filteredMuons.push_back(i);
0121   }
0122 
0123   for (std::vector<unsigned int>::const_iterator itr = filteredMuons.begin(); itr != filteredMuons.end(); ++itr)
0124     filterproduct.addObject(trigger::TriggerMuon, reco::RecoChargedCandidateRef(cands, *itr));
0125 
0126   return filteredMuons.size() >= m_minN;
0127 }
0128 
0129 // declare this class as a framework plugin
0130 #include "FWCore/Framework/interface/MakerMacros.h"
0131 DEFINE_FWK_MODULE(HLTMuonTrkL1TkMuFilter);