Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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