From 2703878578044603600074a0755865fbc89e6f81 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 22 Mar 2022 13:51:07 +0100 Subject: [PATCH] backport the refactoring of the PropagateToMuon class and add the propagation to several HLT filters --- .../L1Trigger/interface/L1TMuonDQMOffline.h | 6 +- .../L1Trigger/python/L1TMuonDQMOffline_cfi.py | 5 + DQMOffline/L1Trigger/src/L1TMuonDQMOffline.cc | 13 +-- HLTrigger/Muon/plugins/BuildFile.xml | 1 + .../Muon/plugins/HLTMuonDimuonL3Filter.cc | 16 +++- .../Muon/plugins/HLTMuonDimuonL3Filter.h | 4 + HLTrigger/Muon/plugins/HLTMuonL3PreFilter.cc | 14 ++- HLTrigger/Muon/plugins/HLTMuonL3PreFilter.h | 3 + HLTrigger/Muon/plugins/HLTMuonTrkFilter.cc | 61 ++++++++---- HLTrigger/Muon/plugins/HLTMuonTrkFilter.h | 38 ++++---- HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.cc | 61 ++++++++---- HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.h | 38 ++++---- .../interface/L1AnalysisRecoMuon2.h | 5 +- .../plugins/L1Muon2RecoTreeProducer.cc | 1 - .../L1TNtuples/python/l1MuonRecoTree_cfi.py | 13 ++- .../L1TNtuples/src/L1AnalysisRecoMuon2.cc | 8 +- .../interface/L1MuonMatcherAlgo.h | 3 +- .../interface/PropagateToMuon.h | 49 +++++----- .../interface/PropagateToMuonSetup.h | 71 ++++++++++++++ .../interface/trackStateEnums.h | 7 ++ .../plugins/TriggerMatcherToHLTDebug.cc | 10 +- .../MuonAssociators/src/L1MuonMatcherAlgo.cc | 4 +- .../MuonAssociators/src/PropagateToMuon.cc | 93 +++++++------------ .../src/PropagateToMuonSetup.cc | 68 ++++++++++++++ 24 files changed, 407 insertions(+), 185 deletions(-) create mode 100644 MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h create mode 100644 MuonAnalysis/MuonAssociators/interface/trackStateEnums.h create mode 100644 MuonAnalysis/MuonAssociators/src/PropagateToMuonSetup.cc diff --git a/DQMOffline/L1Trigger/interface/L1TMuonDQMOffline.h b/DQMOffline/L1Trigger/interface/L1TMuonDQMOffline.h index dc27491c636d8..ff1a529e2bf3b 100644 --- a/DQMOffline/L1Trigger/interface/L1TMuonDQMOffline.h +++ b/DQMOffline/L1Trigger/interface/L1TMuonDQMOffline.h @@ -27,7 +27,7 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "DataFormats/MuonReco/interface/Muon.h" #include "DataFormats/MuonReco/interface/MuonFwd.h" -#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" #include "TrackingTools/TransientTrack/interface/TransientTrack.h" #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h" #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h" @@ -98,13 +98,13 @@ class L1TMuonDQMOffline : public DQMEDAnalyzer { double matchHlt(edm::Handle& triggerEvent, const reco::Muon* mu); // Cut and Matching - void getMuonGmtPairs(edm::Handle& gmtCands); + void getMuonGmtPairs(edm::Handle& gmtCands, PropagateToMuon const& propagator); void getTightMuons(edm::Handle& muons, const reco::Vertex& vertex); void getProbeMuons(edm::Handle& trigResults, edm::Handle& trigEvent); HLTConfigProvider m_hltConfig; - PropagateToMuon m_propagator; + PropagateToMuonSetup const m_propagatorSetup; std::vector getHistBinsEff(EffType eff); std::tuple getHistBinsRes(ResType res); diff --git a/DQMOffline/L1Trigger/python/L1TMuonDQMOffline_cfi.py b/DQMOffline/L1Trigger/python/L1TMuonDQMOffline_cfi.py index 6801cea1b1faa..c0c5b0e9921a8 100644 --- a/DQMOffline/L1Trigger/python/L1TMuonDQMOffline_cfi.py +++ b/DQMOffline/L1Trigger/python/L1TMuonDQMOffline_cfi.py @@ -66,6 +66,11 @@ useSimpleGeometry = cms.bool(True), useStation2 = cms.bool(True), fallbackToME1 = cms.bool(False), + cosmicPropagationHypothesis = cms.bool(False), + useMB2InOverlap = cms.bool(False), + propagatorAlong = cms.ESInputTag("", "SteppingHelixPropagatorAlong"), + propagatorAny = cms.ESInputTag("", "SteppingHelixPropagatorAny"), + propagatorOpposite = cms.ESInputTag("", "SteppingHelixPropagatorOpposite") ), verbose = cms.untracked.bool(False) diff --git a/DQMOffline/L1Trigger/src/L1TMuonDQMOffline.cc b/DQMOffline/L1Trigger/src/L1TMuonDQMOffline.cc index 51ae121daedee..882ee34aa9eea 100644 --- a/DQMOffline/L1Trigger/src/L1TMuonDQMOffline.cc +++ b/DQMOffline/L1Trigger/src/L1TMuonDQMOffline.cc @@ -108,7 +108,7 @@ double MuonGmtPair::getVar(const L1TMuonDQMOffline::EffType type) const { //__________DQM_base_class_______________________________________________ L1TMuonDQMOffline::L1TMuonDQMOffline(const ParameterSet& ps) - : m_propagator(ps.getParameter("muProp"), consumesCollector()), + : m_propagatorSetup(ps.getParameter("muProp"), consumesCollector()), m_effTypes({kEffPt, kEffPhi, kEffEta, kEffVtx}), m_resTypes({kResPt, kResQOverPt, kResPhi, kResEta}), m_etaRegions({kEtaRegionAll, kEtaRegionBmtf, kEtaRegionOmtf, kEtaRegionEmtf}), @@ -210,7 +210,7 @@ void L1TMuonDQMOffline::bookHistograms(DQMStore::IBooker& ibooker, const edm::Ru //_____________________________________________________________________ void L1TMuonDQMOffline::analyze(const Event& iEvent, const EventSetup& eventSetup) { - m_propagator.init(eventSetup); + auto const propagator = m_propagatorSetup.init(eventSetup); Handle muons; iEvent.getByToken(m_MuonInputTag, muons); @@ -231,7 +231,7 @@ void L1TMuonDQMOffline::analyze(const Event& iEvent, const EventSetup& eventSetu getTightMuons(muons, primaryVertex); getProbeMuons(trigResults, trigEvent); // CB add flag to run on orthogonal datasets (no T&P) - getMuonGmtPairs(gmtCands); + getMuonGmtPairs(gmtCands, propagator); if (m_verbose) cout << "[L1TMuonDQMOffline:] Computing efficiencies" << endl; @@ -553,7 +553,8 @@ void L1TMuonDQMOffline::getProbeMuons(Handle& trigResults, } //_____________________________________________________________________ -void L1TMuonDQMOffline::getMuonGmtPairs(edm::Handle& gmtCands) { +void L1TMuonDQMOffline::getMuonGmtPairs(edm::Handle& gmtCands, + PropagateToMuon const& propagator) { m_MuonGmtPairs.clear(); if (m_verbose) cout << "[L1TMuonDQMOffline:] Getting muon GMT pairs" << endl; @@ -565,7 +566,7 @@ void L1TMuonDQMOffline::getMuonGmtPairs(edm::Handle& gmtC l1t::MuonBxCollection::const_iterator gmtEnd = gmtCands->end(0); for (; probeMuIt != probeMuEnd; ++probeMuIt) { - MuonGmtPair pairBestCand((*probeMuIt), nullptr, m_propagator, m_useAtVtxCoord); + MuonGmtPair pairBestCand((*probeMuIt), nullptr, propagator, m_useAtVtxCoord); // Fill the control histograms with the probe muon kinematic variables used m_ControlHistos[kCtrlProbeEta]->Fill(pairBestCand.getVar(L1TMuonDQMOffline::kEffEta)); @@ -575,7 +576,7 @@ void L1TMuonDQMOffline::getMuonGmtPairs(edm::Handle& gmtC gmtIt = gmtCands->begin(0); // use only on L1T muons from BX 0 for (; gmtIt != gmtEnd; ++gmtIt) { - MuonGmtPair pairTmpCand((*probeMuIt), &(*gmtIt), m_propagator, m_useAtVtxCoord); + MuonGmtPair pairTmpCand((*probeMuIt), &(*gmtIt), propagator, m_useAtVtxCoord); if ((pairTmpCand.dR() < m_maxGmtMuonDR) && (pairTmpCand.dR() < pairBestCand.dR())) { pairBestCand = pairTmpCand; diff --git a/HLTrigger/Muon/plugins/BuildFile.xml b/HLTrigger/Muon/plugins/BuildFile.xml index c77c3e955e71a..05bcb2db2d0da 100644 --- a/HLTrigger/Muon/plugins/BuildFile.xml +++ b/HLTrigger/Muon/plugins/BuildFile.xml @@ -22,4 +22,5 @@ + diff --git a/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.cc b/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.cc index 5c969da1e8b4c..ca547e6bb3d05 100644 --- a/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.cc +++ b/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.cc @@ -49,6 +49,7 @@ namespace { HLTMuonDimuonL3Filter::HLTMuonDimuonL3Filter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig), + propSetup_(iConfig, consumesCollector()), idealMagneticFieldRecordToken_(esConsumes()), beamspotTag_(iConfig.getParameter("BeamSpotTag")), beamspotToken_(consumes(beamspotTag_)), @@ -89,6 +90,7 @@ HLTMuonDimuonL3Filter::HLTMuonDimuonL3Filter(const edm::ParameterSet& iConfig) theL3LinksLabel(iConfig.getParameter("InputLinks")), linkToken_(consumes(theL3LinksLabel)), L1MatchingdR_(iConfig.getParameter("L1MatchingdR")), + L1MatchingdR2_(L1MatchingdR_ * L1MatchingdR_), matchPreviousCand_(iConfig.getParameter("MatchToPreviousCand")), MuMass2_(0.106 * 0.106) { // check consistency of parameters for mass-window cuts @@ -117,6 +119,10 @@ HLTMuonDimuonL3Filter::HLTMuonDimuonL3Filter(const edm::ParameterSet& iConfig) << ") and \"MaxInvMass\" (" << max_InvMass_.size() << ") differ"; } + if (L1MatchingdR_ <= 0.) { + throw cms::Exception("HLTMuonDimuonL3FilterConfiguration") + << "invalid value for parameter \"L1MatchingdR\" (must be > 0): " << L1MatchingdR_; + } LogDebug("HLTMuonDimuonL3Filter") << " CandTag/FastAccept/MinN/MaxEta/MinNhits/MaxDr/MaxDz/MinPt1/MinPt2/MinInvMass/" "MaxInvMass/applyMinDiMuonDeltaRCut/MinDiMuonDeltaR" "MinAcop/MaxAcop/MinPtBalance/MaxPtBalance/NSigmaPt/MaxDzMuMu/MaxRapidityPair : " @@ -181,6 +187,7 @@ void HLTMuonDimuonL3Filter::fillDescriptions(edm::ConfigurationDescriptions& des desc.add("InputLinks", edm::InputTag("")); desc.add("L1MatchingdR", 0.3); desc.add("MatchToPreviousCand", true); + PropagateToMuonSetup::fillPSetDescription(desc); descriptions.add("hltMuonDimuonL3Filter", desc); } @@ -196,6 +203,8 @@ bool HLTMuonDimuonL3Filter::hltFilter(edm::Event& iEvent, // recording any reconstructed physics objects satisfying (or not) // this HLT filter, and place it in the Event. + auto const prop = propSetup_.init(iSetup); + // Read RecoChargedCandidates from L3MuonCandidateProducer: Handle mucands; if (saveTags()) @@ -282,12 +291,15 @@ bool HLTMuonDimuonL3Filter::hltFilter(edm::Event& iEvent, } //MTL loop if (not l1CandTag_.label().empty() and check_l1match) { + auto const propagated = prop.extrapolate(*tk); + auto const etaForMatch = propagated.isValid() ? propagated.globalPosition().eta() : cand->eta(); + auto const phiForMatch = propagated.isValid() ? (double)propagated.globalPosition().phi() : cand->phi(); iEvent.getByToken(l1CandToken_, level1Cands); level1Cands->getObjects(trigger::TriggerL1Mu, vl1cands); const unsigned int nL1Muons(vl1cands.size()); for (unsigned int il1 = 0; il1 != nL1Muons; ++il1) { - if (deltaR(cand->eta(), cand->phi(), vl1cands[il1]->eta(), vl1cands[il1]->phi()) < - L1MatchingdR_) { //was muon, non cand + if (deltaR2(etaForMatch, phiForMatch, vl1cands[il1]->eta(), vl1cands[il1]->phi()) < + L1MatchingdR2_) { //was muon, non cand MuonToL3s[i] = RecoChargedCandidateRef(cand); } } diff --git a/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.h b/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.h index a3d5a421b0a42..83827877b710c 100644 --- a/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.h +++ b/HLTrigger/Muon/plugins/HLTMuonDimuonL3Filter.h @@ -24,6 +24,7 @@ #include "FWCore/Framework/interface/ESHandle.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" namespace edm { class ConfigurationDescriptions; @@ -45,6 +46,8 @@ class HLTMuonDimuonL3Filter : public HLTFilter { const reco::RecoChargedCandidateRef&, const reco::BeamSpot&, const edm::ESHandle&) const; + + const PropagateToMuonSetup propSetup_; const edm::ESGetToken idealMagneticFieldRecordToken_; const edm::InputTag beamspotTag_; const edm::EDGetTokenT beamspotToken_; @@ -86,6 +89,7 @@ class HLTMuonDimuonL3Filter : public HLTFilter { const edm::InputTag theL3LinksLabel; //Needed to iterL3 const edm::EDGetTokenT linkToken_; //Needed to iterL3 const double L1MatchingdR_; + const double L1MatchingdR2_; const bool matchPreviousCand_; const double MuMass2_; }; diff --git a/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.cc b/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.cc index fd65e34fd9169..b5e1b2abec2b1 100644 --- a/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.cc +++ b/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.cc @@ -35,6 +35,7 @@ using namespace trigger; HLTMuonL3PreFilter::HLTMuonL3PreFilter(const ParameterSet& iConfig) : HLTFilter(iConfig), + propSetup_(iConfig, consumesCollector()), beamspotTag_(iConfig.getParameter("BeamSpotTag")), beamspotToken_(consumes(beamspotTag_)), candTag_(iConfig.getParameter("CandTag")), @@ -66,11 +67,16 @@ HLTMuonL3PreFilter::HLTMuonL3PreFilter(const ParameterSet& iConfig) maxNormalizedChi2_L3fromL1_(iConfig.getParameter("MaxNormalizedChi2_L3FromL1")), trkMuonId_(muon::SelectionType(iConfig.getParameter("trkMuonId"))), L1MatchingdR_(iConfig.getParameter("L1MatchingdR")), + L1MatchingdR2_(L1MatchingdR_ * L1MatchingdR_), matchPreviousCand_(iConfig.getParameter("MatchToPreviousCand")), devDebug_(false), theL3LinksLabel(iConfig.getParameter("InputLinks")), linkToken_(consumes(theL3LinksLabel)) { + if (L1MatchingdR_ <= 0.) { + throw cms::Exception("HLTMuonL3PreFilterConfiguration") + << "invalid value for parameter \"L1MatchingdR\" (must be > 0): " << L1MatchingdR_; + } LogDebug("HLTMuonL3PreFilter") << " CandTag/MinN/MaxEta/MinNhits/MaxDr/MinDr/MaxDz/MinDxySig/MinPt/NSigmaPt : " << candTag_.encode() << " " << min_N_ << " " << max_Eta_ << " " << min_Nhits_ << " " << max_Dr_ << " " << min_Dr_ << " " << max_Dz_ << " " << min_DxySig_ << " " << min_Pt_ @@ -113,6 +119,7 @@ void HLTMuonL3PreFilter::fillDescriptions(edm::ConfigurationDescriptions& descri desc.add("L1MatchingdR", 0.3); desc.add("MatchToPreviousCand", true); desc.add("InputLinks", edm::InputTag("")); + PropagateToMuonSetup::fillPSetDescription(desc); descriptions.add("hltMuonL3PreFilter", desc); } @@ -128,6 +135,8 @@ bool HLTMuonL3PreFilter::hltFilter(Event& iEvent, // recording any reconstructed physics objects satisfying (or not) // this HLT filter, and place it in the Event. + auto const prop = propSetup_.init(iSetup); + if (saveTags()) filterproduct.addCollectionTag(candTag_); @@ -224,11 +233,14 @@ bool HLTMuonL3PreFilter::hltFilter(Event& iEvent, } //MTL loop if (!l1CandTag_.label().empty() && check_l1match) { + auto const propagated = prop.extrapolate(*tk); + auto const etaForMatch = propagated.isValid() ? propagated.globalPosition().eta() : cand->eta(); + auto const phiForMatch = propagated.isValid() ? (double)propagated.globalPosition().phi() : cand->phi(); iEvent.getByToken(l1CandToken_, level1Cands); level1Cands->getObjects(trigger::TriggerL1Mu, vl1cands); const unsigned int nL1Muons(vl1cands.size()); for (unsigned int il1 = 0; il1 != nL1Muons; ++il1) { - if (deltaR(cand->eta(), cand->phi(), vl1cands[il1]->eta(), vl1cands[il1]->phi()) < L1MatchingdR_) { + if (deltaR2(etaForMatch, phiForMatch, vl1cands[il1]->eta(), vl1cands[il1]->phi()) < L1MatchingdR2_) { MuonToL3s[i] = RecoChargedCandidateRef(cand); } } diff --git a/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.h b/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.h index 6f4692b7a5407..b69afd15253ea 100644 --- a/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.h +++ b/HLTrigger/Muon/plugins/HLTMuonL3PreFilter.h @@ -24,6 +24,7 @@ #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h" #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" class HLTMuonL3PreFilter : public HLTFilter { public: @@ -38,6 +39,7 @@ class HLTMuonL3PreFilter : public HLTFilter { bool triggeredByLevel2(const reco::TrackRef& track, std::vector& vcands) const; bool applySelection(const reco::RecoChargedCandidateRef&, const reco::BeamSpot&) const; + const PropagateToMuonSetup propSetup_; const edm::InputTag beamspotTag_; const edm::EDGetTokenT beamspotToken_; const edm::InputTag candTag_; // input tag identifying product contains muons @@ -73,6 +75,7 @@ class HLTMuonL3PreFilter : public HLTFilter { double maxNormalizedChi2_L3fromL1_; muon::SelectionType trkMuonId_; const double L1MatchingdR_; + const double L1MatchingdR2_; const bool matchPreviousCand_; const bool devDebug_; diff --git a/HLTrigger/Muon/plugins/HLTMuonTrkFilter.cc b/HLTrigger/Muon/plugins/HLTMuonTrkFilter.cc index 9a50bbd62bd2f..83fbd64229ebd 100644 --- a/HLTrigger/Muon/plugins/HLTMuonTrkFilter.cc +++ b/HLTrigger/Muon/plugins/HLTMuonTrkFilter.cc @@ -27,23 +27,31 @@ #include "DataFormats/Math/interface/deltaR.h" -HLTMuonTrkFilter::HLTMuonTrkFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) { - m_muonsTag = iConfig.getParameter("inputMuonCollection"); - m_muonsToken = consumes(m_muonsTag); - m_candsTag = iConfig.getParameter("inputCandCollection"); - m_candsToken = consumes(m_candsTag); - m_previousCandTag = iConfig.getParameter("previousCandTag"); - m_previousCandToken = consumes(m_previousCandTag); - m_minTrkHits = iConfig.getParameter("minTrkHits"); - m_minMuonHits = iConfig.getParameter("minMuonHits"); - m_minMuonStations = iConfig.getParameter("minMuonStations"); - m_maxNormalizedChi2 = iConfig.getParameter("maxNormalizedChi2"); - m_allowedTypeMask = iConfig.getParameter("allowedTypeMask"); - m_requiredTypeMask = iConfig.getParameter("requiredTypeMask"); - m_trkMuonId = muon::SelectionType(iConfig.getParameter("trkMuonId")); - m_minPt = iConfig.getParameter("minPt"); - m_minN = iConfig.getParameter("minN"); - m_maxAbsEta = iConfig.getParameter("maxAbsEta"); +HLTMuonTrkFilter::HLTMuonTrkFilter(const edm::ParameterSet& iConfig) + : HLTFilter(iConfig), + propSetup_(iConfig, consumesCollector()), + m_muonsTag(iConfig.getParameter("inputMuonCollection")), + m_muonsToken(consumes(m_muonsTag)), + m_candsTag(iConfig.getParameter("inputCandCollection")), + m_candsToken(consumes(m_candsTag)), + m_previousCandTag(iConfig.getParameter("previousCandTag")), + m_previousCandToken(consumes(m_previousCandTag)), + m_minTrkHits(iConfig.getParameter("minTrkHits")), + m_minMuonHits(iConfig.getParameter("minMuonHits")), + m_minMuonStations(iConfig.getParameter("minMuonStations")), + m_maxNormalizedChi2(iConfig.getParameter("maxNormalizedChi2")), + m_allowedTypeMask(iConfig.getParameter("allowedTypeMask")), + m_requiredTypeMask(iConfig.getParameter("requiredTypeMask")), + m_trkMuonId(muon::SelectionType(iConfig.getParameter("trkMuonId"))), + m_minPt(iConfig.getParameter("minPt")), + m_minN(iConfig.getParameter("minN")), + m_maxAbsEta(iConfig.getParameter("maxAbsEta")), + m_l1MatchingdR(iConfig.getParameter("L1MatchingdR")), + m_l1MatchingdR2(m_l1MatchingdR * m_l1MatchingdR) { + if (m_l1MatchingdR <= 0.) { + throw cms::Exception("HLTMuonTrkFilterConfiguration") + << "invalid value for parameter \"L1MatchingdR\" (must be > 0): " << m_l1MatchingdR; + } } void HLTMuonTrkFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -62,12 +70,16 @@ void HLTMuonTrkFilter::fillDescriptions(edm::ConfigurationDescriptions& descript desc.add("minPt", 24); desc.add("minN", 1); desc.add("maxAbsEta", 1e99); + desc.add("L1MatchingdR", 0.3); + PropagateToMuonSetup::fillPSetDescription(desc); descriptions.add("hltMuonTrkFilter", desc); } bool HLTMuonTrkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { + auto const prop = propSetup_.init(iSetup); + edm::Handle muons; iEvent.getByToken(m_muonsToken, muons); edm::Handle cands; @@ -96,11 +108,22 @@ bool HLTMuonTrkFilter::hltFilter(edm::Event& iEvent, std::vector filteredMuons; for (unsigned int i = 0; i < muons->size(); ++i) { const reco::Muon& muon(muons->at(i)); - // check for dR match to L1 muons if (check_l1match) { + const reco::RecoChargedCandidateRef cand(cands, i); + const reco::TrackRef tk = cand->track(); + auto etaForMatch = cand->eta(); + auto phiForMatch = cand->phi(); + // check for dR match to L1 muons + if (tk.isNonnull()) { + auto const propagated = prop.extrapolate(*tk); + if (propagated.isValid()) { + etaForMatch = propagated.globalPosition().eta(); + phiForMatch = propagated.globalPosition().phi(); + } + } bool matchl1 = false; for (auto l1cand = vl1cands_begin; l1cand != vl1cands_end; ++l1cand) { - if (deltaR(muon, **l1cand) < 0.3) { + if (deltaR2(etaForMatch, phiForMatch, (*l1cand)->eta(), (*l1cand)->phi()) < m_l1MatchingdR2) { matchl1 = true; break; } diff --git a/HLTrigger/Muon/plugins/HLTMuonTrkFilter.h b/HLTrigger/Muon/plugins/HLTMuonTrkFilter.h index 37d7e2efb61d6..1b36769b7df93 100644 --- a/HLTrigger/Muon/plugins/HLTMuonTrkFilter.h +++ b/HLTrigger/Muon/plugins/HLTMuonTrkFilter.h @@ -6,6 +6,7 @@ #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h" #include "DataFormats/MuonReco/interface/MuonFwd.h" #include "DataFormats/MuonReco/interface/MuonSelectors.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" namespace edm { class ConfigurationDescriptions; @@ -21,25 +22,30 @@ class HLTMuonTrkFilter : public HLTFilter { trigger::TriggerFilterObjectWithRefs& filterproduct) const override; private: + const PropagateToMuonSetup propSetup_; // WARNING: two input collection represent should be aligned and represent // the same list of muons, just stored in different containers - edm::InputTag m_muonsTag; // input collection of muons - edm::EDGetTokenT m_muonsToken; // input collection of muons - edm::InputTag m_candsTag; // input collection of candidates to be referenced - edm::EDGetTokenT m_candsToken; // input collection of candidates to be referenced - edm::InputTag m_previousCandTag; // input tag identifying product contains muons passing the previous level - edm::EDGetTokenT + const edm::InputTag m_muonsTag; // input collection of muons + const edm::EDGetTokenT m_muonsToken; // input collection of muons + const edm::InputTag m_candsTag; // input collection of candidates to be referenced + const edm::EDGetTokenT + m_candsToken; // input collection of candidates to be referenced + const edm::InputTag m_previousCandTag; // input tag identifying product contains muons passing the previous level + const edm::EDGetTokenT m_previousCandToken; // token identifying product contains muons passing the previous level - int m_minTrkHits; - int m_minMuonHits; - int m_minMuonStations; - unsigned int m_allowedTypeMask; - unsigned int m_requiredTypeMask; - double m_maxNormalizedChi2; - double m_minPt; - unsigned int m_minN; - double m_maxAbsEta; - muon::SelectionType m_trkMuonId; + const int m_minTrkHits; + const int m_minMuonHits; + const int m_minMuonStations; + const double m_maxNormalizedChi2; + const unsigned int m_allowedTypeMask; + const unsigned int m_requiredTypeMask; + const muon::SelectionType m_trkMuonId; + const double m_minPt; + const unsigned int m_minN; + const double m_maxAbsEta; + const double m_l1MatchingdR; + const double m_l1MatchingdR2; + bool m_saveTags; }; diff --git a/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.cc b/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.cc index 69e0352d28004..a39928719dcbe 100644 --- a/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.cc +++ b/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.cc @@ -25,23 +25,31 @@ #include "DataFormats/Math/interface/deltaR.h" -HLTMuonTrkL1TFilter::HLTMuonTrkL1TFilter(const edm::ParameterSet& iConfig) : HLTFilter(iConfig) { - m_muonsTag = iConfig.getParameter("inputMuonCollection"); - m_muonsToken = consumes(m_muonsTag); - m_candsTag = iConfig.getParameter("inputCandCollection"); - m_candsToken = consumes(m_candsTag); - m_previousCandTag = iConfig.getParameter("previousCandTag"); - m_previousCandToken = consumes(m_previousCandTag); - m_minTrkHits = iConfig.getParameter("minTrkHits"); - m_minMuonHits = iConfig.getParameter("minMuonHits"); - m_minMuonStations = iConfig.getParameter("minMuonStations"); - m_maxNormalizedChi2 = iConfig.getParameter("maxNormalizedChi2"); - m_allowedTypeMask = iConfig.getParameter("allowedTypeMask"); - m_requiredTypeMask = iConfig.getParameter("requiredTypeMask"); - m_trkMuonId = muon::SelectionType(iConfig.getParameter("trkMuonId")); - m_minPt = iConfig.getParameter("minPt"); - m_minN = iConfig.getParameter("minN"); - m_maxAbsEta = iConfig.getParameter("maxAbsEta"); +HLTMuonTrkL1TFilter::HLTMuonTrkL1TFilter(const edm::ParameterSet& iConfig) + : HLTFilter(iConfig), + propSetup_(iConfig, consumesCollector()), + m_muonsTag(iConfig.getParameter("inputMuonCollection")), + m_muonsToken(consumes(m_muonsTag)), + m_candsTag(iConfig.getParameter("inputCandCollection")), + m_candsToken(consumes(m_candsTag)), + m_previousCandTag(iConfig.getParameter("previousCandTag")), + m_previousCandToken(consumes(m_previousCandTag)), + m_minTrkHits(iConfig.getParameter("minTrkHits")), + m_minMuonHits(iConfig.getParameter("minMuonHits")), + m_minMuonStations(iConfig.getParameter("minMuonStations")), + m_maxNormalizedChi2(iConfig.getParameter("maxNormalizedChi2")), + m_allowedTypeMask(iConfig.getParameter("allowedTypeMask")), + m_requiredTypeMask(iConfig.getParameter("requiredTypeMask")), + m_trkMuonId(muon::SelectionType(iConfig.getParameter("trkMuonId"))), + m_minPt(iConfig.getParameter("minPt")), + m_minN(iConfig.getParameter("minN")), + m_maxAbsEta(iConfig.getParameter("maxAbsEta")), + m_l1MatchingdR(iConfig.getParameter("L1MatchingdR")), + m_l1MatchingdR2(m_l1MatchingdR * m_l1MatchingdR) { + if (m_l1MatchingdR <= 0.) { + throw cms::Exception("HLTMuonTrkL1TFilterConfiguration") + << "invalid value for parameter \"L1MatchingdR\" (must be > 0): " << m_l1MatchingdR; + } } void HLTMuonTrkL1TFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { @@ -60,12 +68,16 @@ void HLTMuonTrkL1TFilter::fillDescriptions(edm::ConfigurationDescriptions& descr desc.add("minPt", 24); desc.add("minN", 1); desc.add("maxAbsEta", 1e99); + desc.add("L1MatchingdR", 0.3); + PropagateToMuonSetup::fillPSetDescription(desc); descriptions.add("hltMuonTrkL1TFilter", desc); } bool HLTMuonTrkL1TFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs& filterproduct) const { + auto const prop = propSetup_.init(iSetup); + edm::Handle muons; iEvent.getByToken(m_muonsToken, muons); edm::Handle cands; @@ -94,11 +106,22 @@ bool HLTMuonTrkL1TFilter::hltFilter(edm::Event& iEvent, std::vector filteredMuons; for (unsigned int i = 0; i < muons->size(); ++i) { const reco::Muon& muon(muons->at(i)); - // check for dR match to L1 muons if (check_l1match) { + const reco::RecoChargedCandidateRef cand(cands, i); + const reco::TrackRef tk = cand->track(); + auto etaForMatch = cand->eta(); + auto phiForMatch = cand->phi(); + // check for dR match to L1 muons + if (tk.isNonnull()) { + auto const propagated = prop.extrapolate(*tk); + if (propagated.isValid()) { + etaForMatch = propagated.globalPosition().eta(); + phiForMatch = propagated.globalPosition().phi(); + } + } bool matchl1 = false; for (auto l1cand = vl1cands_begin; l1cand != vl1cands_end; ++l1cand) { - if (deltaR(muon, **l1cand) < 0.3) { + if (deltaR2(etaForMatch, phiForMatch, (*l1cand)->eta(), (*l1cand)->phi()) < m_l1MatchingdR2) { matchl1 = true; break; } diff --git a/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.h b/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.h index ac50520e3c542..866f3349c9822 100644 --- a/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.h +++ b/HLTrigger/Muon/plugins/HLTMuonTrkL1TFilter.h @@ -6,6 +6,7 @@ #include "DataFormats/MuonReco/interface/MuonFwd.h" #include "DataFormats/MuonReco/interface/MuonSelectors.h" #include "DataFormats/L1Trigger/interface/Muon.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" namespace edm { class ConfigurationDescriptions; @@ -21,25 +22,30 @@ class HLTMuonTrkL1TFilter : public HLTFilter { trigger::TriggerFilterObjectWithRefs& filterproduct) const override; private: + const PropagateToMuonSetup propSetup_; // WARNING: two input collection represent should be aligned and represent // the same list of muons, just stored in different containers - edm::InputTag m_muonsTag; // input collection of muons - edm::EDGetTokenT m_muonsToken; // input collection of muons - edm::InputTag m_candsTag; // input collection of candidates to be referenced - edm::EDGetTokenT m_candsToken; // input collection of candidates to be referenced - edm::InputTag m_previousCandTag; // input tag identifying product contains muons passing the previous level - edm::EDGetTokenT + const edm::InputTag m_muonsTag; // input collection of muons + const edm::EDGetTokenT m_muonsToken; // input collection of muons + const edm::InputTag m_candsTag; // input collection of candidates to be referenced + const edm::EDGetTokenT + m_candsToken; // input collection of candidates to be referenced + const edm::InputTag m_previousCandTag; // input tag identifying product contains muons passing the previous level + const edm::EDGetTokenT m_previousCandToken; // token identifying product contains muons passing the previous level - int m_minTrkHits; - int m_minMuonHits; - int m_minMuonStations; - unsigned int m_allowedTypeMask; - unsigned int m_requiredTypeMask; - double m_maxNormalizedChi2; - double m_minPt; - unsigned int m_minN; - double m_maxAbsEta; - muon::SelectionType m_trkMuonId; + const int m_minTrkHits; + const int m_minMuonHits; + const int m_minMuonStations; + const double m_maxNormalizedChi2; + const unsigned int m_allowedTypeMask; + const unsigned int m_requiredTypeMask; + const muon::SelectionType m_trkMuonId; + const double m_minPt; + const unsigned int m_minN; + const double m_maxAbsEta; + const double m_l1MatchingdR; + const double m_l1MatchingdR2; + bool m_saveTags; }; diff --git a/L1Trigger/L1TNtuples/interface/L1AnalysisRecoMuon2.h b/L1Trigger/L1TNtuples/interface/L1AnalysisRecoMuon2.h index 52a99cadd919a..a91e23fbd0ce5 100644 --- a/L1Trigger/L1TNtuples/interface/L1AnalysisRecoMuon2.h +++ b/L1Trigger/L1TNtuples/interface/L1AnalysisRecoMuon2.h @@ -34,7 +34,7 @@ #include "L1Trigger/L1TNtuples/interface/L1AnalysisRecoVertexDataFormat.h" // track extrapolation -#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h" namespace L1Analysis { @@ -63,6 +63,9 @@ namespace L1Analysis { private: L1AnalysisRecoMuon2DataFormat recoMuon_; + const PropagateToMuonSetup muPropagatorSetup1st_; + const PropagateToMuonSetup muPropagatorSetup2nd_; + PropagateToMuon muPropagator1st_; PropagateToMuon muPropagator2nd_; }; diff --git a/L1Trigger/L1TNtuples/plugins/L1Muon2RecoTreeProducer.cc b/L1Trigger/L1TNtuples/plugins/L1Muon2RecoTreeProducer.cc index fe5117c7975d3..899ada8ad7c25 100644 --- a/L1Trigger/L1TNtuples/plugins/L1Muon2RecoTreeProducer.cc +++ b/L1Trigger/L1TNtuples/plugins/L1Muon2RecoTreeProducer.cc @@ -190,7 +190,6 @@ L1Muon2RecoTreeProducer::~L1Muon2RecoTreeProducer() { // // member functions // - // ------------ method called to for each event ------------ void L1Muon2RecoTreeProducer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) { muon->init(iSetup); diff --git a/L1Trigger/L1TNtuples/python/l1MuonRecoTree_cfi.py b/L1Trigger/L1TNtuples/python/l1MuonRecoTree_cfi.py index 5ddec88805274..89b4bcf84c136 100644 --- a/L1Trigger/L1TNtuples/python/l1MuonRecoTree_cfi.py +++ b/L1Trigger/L1TNtuples/python/l1MuonRecoTree_cfi.py @@ -37,7 +37,13 @@ useTrack = cms.string("tracker"), # 'none' to use Candidate P4; or 'tracker', 'muon', 'global' useState = cms.string("atVertex"), # 'innermost' and 'outermost' require the TrackExtra useSimpleGeometry = cms.bool(True), - useStation2 = cms.bool(False), + useStation2 = cms.bool(False), + fallbackToME1 = cms.bool(False), + cosmicPropagationHypothesis = cms.bool(False), + useMB2InOverlap = cms.bool(False), + propagatorAlong = cms.ESInputTag("", "SteppingHelixPropagatorAlong"), + propagatorAny = cms.ESInputTag("", "SteppingHelixPropagatorAny"), + propagatorOpposite = cms.ESInputTag("", "SteppingHelixPropagatorOpposite") ), # muon track extrapolation to 2nd station muProp2nd = cms.PSet( @@ -46,6 +52,11 @@ useSimpleGeometry = cms.bool(True), useStation2 = cms.bool(True), fallbackToME1 = cms.bool(False), + cosmicPropagationHypothesis = cms.bool(False), + useMB2InOverlap = cms.bool(False), + propagatorAlong = cms.ESInputTag("", "SteppingHelixPropagatorAlong"), + propagatorAny = cms.ESInputTag("", "SteppingHelixPropagatorAny"), + propagatorOpposite = cms.ESInputTag("", "SteppingHelixPropagatorOpposite") ), ) diff --git a/L1Trigger/L1TNtuples/src/L1AnalysisRecoMuon2.cc b/L1Trigger/L1TNtuples/src/L1AnalysisRecoMuon2.cc index 9a2471b7a498a..624aba3849637 100644 --- a/L1Trigger/L1TNtuples/src/L1AnalysisRecoMuon2.cc +++ b/L1Trigger/L1TNtuples/src/L1AnalysisRecoMuon2.cc @@ -8,8 +8,8 @@ using namespace std; using namespace muon; L1Analysis::L1AnalysisRecoMuon2::L1AnalysisRecoMuon2(const edm::ParameterSet& pset, edm::ConsumesCollector iC) - : muPropagator1st_(pset.getParameter("muProp1st"), iC), - muPropagator2nd_(pset.getParameter("muProp2nd"), iC) {} + : muPropagatorSetup1st_(pset.getParameter("muProp1st"), iC), + muPropagatorSetup2nd_(pset.getParameter("muProp2nd"), iC) {} L1Analysis::L1AnalysisRecoMuon2::~L1AnalysisRecoMuon2() {} @@ -92,6 +92,6 @@ void L1Analysis::L1AnalysisRecoMuon2::SetMuon(const edm::Event& event, } void L1Analysis::L1AnalysisRecoMuon2::init(const edm::EventSetup& eventSetup) { - muPropagator1st_.init(eventSetup); - muPropagator2nd_.init(eventSetup); + muPropagator1st_ = muPropagatorSetup1st_.init(eventSetup); + muPropagator2nd_ = muPropagatorSetup2nd_.init(eventSetup); } diff --git a/MuonAnalysis/MuonAssociators/interface/L1MuonMatcherAlgo.h b/MuonAnalysis/MuonAssociators/interface/L1MuonMatcherAlgo.h index f95659acd95c9..568370c928b70 100644 --- a/MuonAnalysis/MuonAssociators/interface/L1MuonMatcherAlgo.h +++ b/MuonAnalysis/MuonAssociators/interface/L1MuonMatcherAlgo.h @@ -24,7 +24,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" #include "CommonTools/Utils/interface/AnySelector.h" -#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" class L1MuonMatcherAlgo { public: @@ -238,6 +238,7 @@ class L1MuonMatcherAlgo { template int genericQuality(const T &cand) const; + PropagateToMuonSetup propSetup_; PropagateToMuon prop_; bool useStage2L1_; diff --git a/MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h b/MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h index cc0a984f0f3cd..afd9906ff8d5e 100644 --- a/MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h +++ b/MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h @@ -4,12 +4,10 @@ // /** - \class PropagateToMuon PropagateToMuon.h "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" - \brief Propagate an object (usually a track) to the second muon station. - Support for other muon stations will be added on request. - - \author Giovanni Petrucciani - \version $Id: PropagateToMuon.h,v 1.3 2010/07/01 07:41:09 gpetrucc Exp $ + \class PropagateToMuon PropagateToMuon.h "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" + + \brief Propagate an object (usually a track) to the second (default) or first muon station. + */ #include "DataFormats/Candidate/interface/Candidate.h" @@ -17,28 +15,35 @@ #include "DataFormats/GeometrySurface/interface/BoundDisk.h" #include "DataFormats/TrackReco/interface/Track.h" #include "FWCore/Framework/interface/ESHandle.h" -#include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/ConsumesCollector.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h" #include "TrackingTools/GeomPropagators/interface/Propagator.h" #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h" #include "SimDataFormats/Track/interface/SimTrackContainer.h" #include "SimDataFormats/Vertex/interface/SimVertexContainer.h" +#include "MuonAnalysis/MuonAssociators/interface/trackStateEnums.h" -class DetLayer; class IdealMagneticFieldRecord; class TrackingComponentsRecord; class MuonRecoGeometryRecord; class PropagateToMuon { public: - explicit PropagateToMuon(const edm::ParameterSet &iConfig, edm::ConsumesCollector); - ~PropagateToMuon(); - - /// Call this method at the beginning of each event, to initialize geometry, magnetic field and propagators - void init(const edm::EventSetup &iSetup); + explicit PropagateToMuon() {} + explicit PropagateToMuon(edm::ESHandle, + edm::ESHandle, + edm::ESHandle, + edm::ESHandle, + edm::ESHandle, + bool, + bool, + bool, + WhichTrack, + WhichState, + bool, + bool); + ~PropagateToMuon() {} /// Extrapolate reco::Track to the muon station 2, return an invalid TSOS if it fails TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const { return extrapolate(startingState(tk)); } @@ -57,13 +62,13 @@ class PropagateToMuon { TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &state) const; private: - enum WhichTrack { None, TrackerTk, MuonTk, GlobalTk }; - enum WhichState { AtVertex, Innermost, Outermost }; + // needed services for track propagation + edm::ESHandle magfield_; + edm::ESHandle propagator_, propagatorAny_, propagatorOpposite_; + edm::ESHandle muonGeometry_; - /// Use simplified geometry (cylinders and disks, not individual chambers) bool useSimpleGeometry_; - /// Propagate to MB2 (default) instead of MB1 bool useMB2_; /// Fallback to ME1 if propagation to ME2 fails @@ -78,14 +83,6 @@ class PropagateToMuon { bool useMB2InOverlap_; - // needed services for track propagation - edm::ESHandle magfield_; - edm::ESHandle propagator_, propagatorAny_, propagatorOpposite_; - edm::ESHandle muonGeometry_; - - edm::ESGetToken magfieldToken_; - edm::ESGetToken propagatorToken_, propagatorAnyToken_, propagatorOppositeToken_; - edm::ESGetToken muonGeometryToken_; // simplified geometry for track propagation const BoundCylinder *barrelCylinder_; const BoundDisk *endcapDiskPos_[3], *endcapDiskNeg_[3]; diff --git a/MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h b/MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h new file mode 100644 index 0000000000000..142b142b56a90 --- /dev/null +++ b/MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h @@ -0,0 +1,71 @@ +#ifndef MuonAnalysis_MuonAssociators_interface_PropagateToMuonSetup_h +#define MuonAnalysis_MuonAssociators_interface_PropagateToMuonSetup_h +// +// + +/** + \class PropagateToMuonSetup PropagateToMuonSetup.h "HLTriggerOffline/Muon/interface/PropagateToMuonSetup.h" + + \brief Propagate an object (usually a track) to the second (default) or first muon station. + +*/ + +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/ConsumesCollector.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" +#include "MuonAnalysis/MuonAssociators/interface/trackStateEnums.h" + +class IdealMagneticFieldRecord; +class TrackingComponentsRecord; +class MuonRecoGeometryRecord; + +class PropagateToMuonSetup { +public: + explicit PropagateToMuonSetup(const edm::ParameterSet &iConfig, edm::ConsumesCollector); + ~PropagateToMuonSetup(){}; + + /// Call this method at the beginning of each run, to initialize geometry, + /// magnetic field and propagators + PropagateToMuon init(const edm::EventSetup &iSetup) const; + static void fillPSetDescription(edm::ParameterSetDescription &desc) { + desc.add("useSimpleGeometry", true); + desc.add("useStation2", true); + desc.add("fallbackToME1", false); + desc.add("cosmicPropagationHypothesis", false); + desc.add("useMB2InOverlap", false); + desc.add("useTrack", "tracker"); + desc.add("useState", "atVertex"); + desc.add("propagatorAlong", edm::ESInputTag("", "hltESPSteppingHelixPropagatorAlong")); + desc.add("propagatorAny", edm::ESInputTag("", "SteppingHelixPropagatorAny")); + desc.add("propagatorOpposite", edm::ESInputTag("", "hltESPSteppingHelixPropagatorOpposite")); + } + +private: + /// Use simplified geometry (cylinders and disks, not individual chambers) + const bool useSimpleGeometry_; + + /// Propagate to MB2 (default) instead of MB1 + const bool useMB2_; + + /// Fallback to ME1 if propagation to ME2 fails + const bool fallbackToME1_; + + /// Labels for input collections + WhichTrack whichTrack_; + WhichState whichState_; + + /// for cosmics, some things change: the along-opposite is not in-out, nor the innermost/outermost states are in-out really + const bool cosmicPropagation_; + + const bool useMB2InOverlap_; + + const edm::ESGetToken magfieldToken_; + const edm::ESGetToken propagatorToken_, propagatorAnyToken_, + propagatorOppositeToken_; + const edm::ESGetToken muonGeometryToken_; +}; + +#endif diff --git a/MuonAnalysis/MuonAssociators/interface/trackStateEnums.h b/MuonAnalysis/MuonAssociators/interface/trackStateEnums.h new file mode 100644 index 0000000000000..371ec6c30bfc9 --- /dev/null +++ b/MuonAnalysis/MuonAssociators/interface/trackStateEnums.h @@ -0,0 +1,7 @@ +#ifndef MuonAnalysis_MuonAssociators_interface_trackStateEnums_h +#define MuonAnalysis_MuonAssociators_interface_trackStateEnums_h + +enum WhichTrack { None, TrackerTk, MuonTk, GlobalTk }; +enum WhichState { AtVertex, Innermost, Outermost }; + +#endif diff --git a/MuonAnalysis/MuonAssociators/plugins/TriggerMatcherToHLTDebug.cc b/MuonAnalysis/MuonAssociators/plugins/TriggerMatcherToHLTDebug.cc index d0627cdc8dd87..b776085819e7c 100644 --- a/MuonAnalysis/MuonAssociators/plugins/TriggerMatcherToHLTDebug.cc +++ b/MuonAnalysis/MuonAssociators/plugins/TriggerMatcherToHLTDebug.cc @@ -58,7 +58,7 @@ #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "CommonTools/Utils/interface/StringCutObjectSelector.h" -#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuon.h" +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h" class TriggerMatcherToHLTDebug : public edm::stream::EDProducer<> { @@ -78,7 +78,7 @@ class TriggerMatcherToHLTDebug : public edm::stream::EDProducer<> { edm::EDGetTokenT > tagToken_; edm::EDGetTokenT l1Token_; - PropagateToMuon l1matcher_; + PropagateToMuonSetup const l1matcherSetup_; std::string metname; @@ -131,7 +131,7 @@ using namespace reco; TriggerMatcherToHLTDebug::TriggerMatcherToHLTDebug(const edm::ParameterSet &pset) : tagToken_(consumes >(pset.getParameter("tags"))), l1Token_(consumes(pset.getParameter("l1s"))), - l1matcher_(pset.getParameter("l1matcherConfig"), consumesCollector()), + l1matcherSetup_(pset.getParameter("l1matcherConfig"), consumesCollector()), deltaR_(pset.getParameter("deltaR")), minL1Quality_(pset.getParameter("MinL1Quality")), beamspotToken_(consumes(pset.getParameter("BeamSpotTag"))), @@ -179,7 +179,7 @@ TriggerMatcherToHLTDebug::~TriggerMatcherToHLTDebug() {} // Analyzer void TriggerMatcherToHLTDebug::produce(Event &event, const EventSetup &eventSetup) { - l1matcher_.init(eventSetup); + auto const l1matcher = l1matcherSetup_.init(eventSetup); Handle > muons; event.getByToken(tagToken_, muons); @@ -222,7 +222,7 @@ void TriggerMatcherToHLTDebug::produce(Event &event, const EventSetup &eventSetu const reco::Muon &mu = (*muons)[i]; // Propagate to muon station (using the L1 tool) - TrajectoryStateOnSurface stateAtMB2 = l1matcher_.extrapolate(mu); + TrajectoryStateOnSurface stateAtMB2 = l1matcher.extrapolate(mu); if (!stateAtMB2.isValid()) continue; propagatesToM2[i] = 1; diff --git a/MuonAnalysis/MuonAssociators/src/L1MuonMatcherAlgo.cc b/MuonAnalysis/MuonAssociators/src/L1MuonMatcherAlgo.cc index 43720203c0ea8..c7f2dd6585b24 100644 --- a/MuonAnalysis/MuonAssociators/src/L1MuonMatcherAlgo.cc +++ b/MuonAnalysis/MuonAssociators/src/L1MuonMatcherAlgo.cc @@ -3,7 +3,7 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" L1MuonMatcherAlgo::L1MuonMatcherAlgo(const edm::ParameterSet &iConfig, edm::ConsumesCollector iCollector) - : prop_(iConfig, iCollector), + : propSetup_(iConfig, iCollector), useStage2L1_(iConfig.existsAs("useStage2L1") ? iConfig.getParameter("useStage2L1") : false), preselectionCut_( (iConfig.existsAs("preselection")) ? iConfig.getParameter("preselection") : ""), @@ -67,7 +67,7 @@ L1MuonMatcherAlgo::L1MuonMatcherAlgo(const edm::ParameterSet &iConfig, edm::Cons L1MuonMatcherAlgo::~L1MuonMatcherAlgo() {} -void L1MuonMatcherAlgo::init(const edm::EventSetup &iSetup) { prop_.init(iSetup); } +void L1MuonMatcherAlgo::init(const edm::EventSetup &iSetup) { prop_ = propSetup_.init(iSetup); } bool L1MuonMatcherAlgo::match(TrajectoryStateOnSurface &propagated, const l1extra::L1MuonParticle &l1, diff --git a/MuonAnalysis/MuonAssociators/src/PropagateToMuon.cc b/MuonAnalysis/MuonAssociators/src/PropagateToMuon.cc index fb6608a21a43f..5e95c171a25ca 100644 --- a/MuonAnalysis/MuonAssociators/src/PropagateToMuon.cc +++ b/MuonAnalysis/MuonAssociators/src/PropagateToMuon.cc @@ -3,70 +3,38 @@ #include #include "DataFormats/RecoCandidate/interface/RecoCandidate.h" - -#include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h" -#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" -#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h" #include "TrackingTools/DetLayers/interface/DetLayer.h" -#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h" #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h" +#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" +#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -PropagateToMuon::PropagateToMuon(const edm::ParameterSet &iConfig, edm::ConsumesCollector iC) - : useSimpleGeometry_(iConfig.getParameter("useSimpleGeometry")), - useMB2_(iConfig.existsAs("useStation2") ? iConfig.getParameter("useStation2") : true), - fallbackToME1_(iConfig.existsAs("fallbackToME1") ? iConfig.getParameter("fallbackToME1") : false), - whichTrack_(None), - whichState_(AtVertex), - cosmicPropagation_(iConfig.existsAs("cosmicPropagationHypothesis") - ? iConfig.getParameter("cosmicPropagationHypothesis") - : false), - useMB2InOverlap_(iConfig.existsAs("useMB2InOverlap") ? iConfig.getParameter("useMB2InOverlap") - : false), - magfieldToken_(iC.esConsumes<>()), - propagatorToken_(iC.esConsumes<>(edm::ESInputTag("", "SteppingHelixPropagatorAlong"))), - propagatorAnyToken_(iC.esConsumes<>(edm::ESInputTag("", "SteppingHelixPropagatorAny"))), - propagatorOppositeToken_(iC.esConsumes<>(edm::ESInputTag("", "SteppingHelixPropagatorOpposite"))), - muonGeometryToken_(iC.esConsumes<>()) { - std::string whichTrack = iConfig.getParameter("useTrack"); - if (whichTrack == "none") { - whichTrack_ = None; - } else if (whichTrack == "tracker") { - whichTrack_ = TrackerTk; - } else if (whichTrack == "muon") { - whichTrack_ = MuonTk; - } else if (whichTrack == "global") { - whichTrack_ = GlobalTk; - } else - throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n"; - if (whichTrack_ != None) { - std::string whichState = iConfig.getParameter("useState"); - if (whichState == "atVertex") { - whichState_ = AtVertex; - } else if (whichState == "innermost") { - whichState_ = Innermost; - } else if (whichState == "outermost") { - whichState_ = Outermost; - } else - throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', 'outermost'\n"; - } - if (cosmicPropagation_ && (whichTrack_ == None || whichState_ == AtVertex)) { - throw cms::Exception("Configuration") << "When using 'cosmicPropagationHypothesis' useTrack must not be 'none', " - "and the state must not be 'atVertex'\n"; - } -} - -PropagateToMuon::~PropagateToMuon() {} - -void PropagateToMuon::init(const edm::EventSetup &iSetup) { - magfield_ = iSetup.getHandle(magfieldToken_); - propagator_ = iSetup.getHandle(propagatorToken_); - propagatorOpposite_ = iSetup.getHandle(propagatorOppositeToken_); - propagatorAny_ = iSetup.getHandle(propagatorAnyToken_); - muonGeometry_ = iSetup.getHandle(muonGeometryToken_); - +PropagateToMuon::PropagateToMuon(edm::ESHandle magfield, + edm::ESHandle propagator, + edm::ESHandle propagatorAny, + edm::ESHandle propagatorOpposite, + edm::ESHandle muonGeometry, + bool useSimpleGeometry, + bool useMB2, + bool fallbackToME1, + WhichTrack whichTrack, + WhichState whichState, + bool cosmicPropagation, + bool useMB2InOverlap) + : magfield_(magfield), + propagator_(propagator), + propagatorAny_(propagatorAny), + propagatorOpposite_(propagatorOpposite), + muonGeometry_(muonGeometry), + useSimpleGeometry_(useSimpleGeometry), + useMB2_(useMB2), + fallbackToME1_(fallbackToME1), + whichTrack_(whichTrack), + whichState_(whichState), + cosmicPropagation_(cosmicPropagation), + useMB2InOverlap_(useMB2InOverlap) { // Get the barrel cylinder const DetLayer *dtLay = muonGeometry_->allDTLayers()[useMB2_ ? 1 : 0]; barrelCylinder_ = dynamic_cast(&dtLay->surface()); @@ -220,8 +188,9 @@ TrajectoryStateOnSurface PropagateToMuon::extrapolate(const FreeTrajectoryState TrajectoryStateOnSurface PropagateToMuon::getBestDet(const TrajectoryStateOnSurface &tsos, const DetLayer *layer) const { - TrajectoryStateOnSurface ret; // start as null - Chi2MeasurementEstimator estimator(1e10, 3.); // require compatibility at 3 sigma + TrajectoryStateOnSurface ret; // start as null + // require compatibility at 3 sigma + Chi2MeasurementEstimator estimator(1e10, 3.); std::vector dets = layer->compatibleDets(tsos, *propagatorAny_, estimator); if (!dets.empty()) { ret = dets.front().second; diff --git a/MuonAnalysis/MuonAssociators/src/PropagateToMuonSetup.cc b/MuonAnalysis/MuonAssociators/src/PropagateToMuonSetup.cc new file mode 100644 index 0000000000000..8c71e66ce295c --- /dev/null +++ b/MuonAnalysis/MuonAssociators/src/PropagateToMuonSetup.cc @@ -0,0 +1,68 @@ +#include "MuonAnalysis/MuonAssociators/interface/PropagateToMuonSetup.h" + +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h" +#include "TrackingTools/Records/interface/TrackingComponentsRecord.h" + +PropagateToMuonSetup::PropagateToMuonSetup(const edm::ParameterSet &iConfig, edm::ConsumesCollector iC) + : useSimpleGeometry_(iConfig.getParameter("useSimpleGeometry")), + useMB2_(iConfig.getParameter("useStation2")), + fallbackToME1_(iConfig.getParameter("fallbackToME1")), + whichTrack_(None), + whichState_(AtVertex), + cosmicPropagation_(iConfig.getParameter("cosmicPropagationHypothesis")), + useMB2InOverlap_(iConfig.getParameter("useMB2InOverlap")), + magfieldToken_(iC.esConsumes()), + propagatorToken_(iC.esConsumes(iConfig.getParameter("propagatorAlong"))), + propagatorAnyToken_(iC.esConsumes(iConfig.getParameter("propagatorAny"))), + propagatorOppositeToken_(iC.esConsumes(iConfig.getParameter("propagatorOpposite"))), + muonGeometryToken_(iC.esConsumes()) { + std::string whichTrack = iConfig.getParameter("useTrack"); + if (whichTrack == "none") { + whichTrack_ = None; + } else if (whichTrack == "tracker") { + whichTrack_ = TrackerTk; + } else if (whichTrack == "muon") { + whichTrack_ = MuonTk; + } else if (whichTrack == "global") { + whichTrack_ = GlobalTk; + } else + throw cms::Exception("Configuration") << "Parameter 'useTrack' must be 'none', 'tracker', 'muon', 'global'\n"; + if (whichTrack_ != None) { + std::string whichState = iConfig.getParameter("useState"); + if (whichState == "atVertex") { + whichState_ = AtVertex; + } else if (whichState == "innermost") { + whichState_ = Innermost; + } else if (whichState == "outermost") { + whichState_ = Outermost; + } else + throw cms::Exception("Configuration") << "Parameter 'useState' must be 'atVertex', 'innermost', " + "'outermost'\n"; + } + if (cosmicPropagation_ && (whichTrack_ == None || whichState_ == AtVertex)) { + throw cms::Exception("Configuration") << "When using 'cosmicPropagationHypothesis' useTrack must not be " + "'none', and the state must not be 'atVertex'\n"; + } +} + +PropagateToMuon PropagateToMuonSetup::init(const edm::EventSetup &iSetup) const { + auto const magfield = iSetup.getHandle(magfieldToken_); + auto const propagator = iSetup.getHandle(propagatorToken_); + auto const propagatorOpposite = iSetup.getHandle(propagatorOppositeToken_); + auto const propagatorAny = iSetup.getHandle(propagatorAnyToken_); + auto const muonGeometry = iSetup.getHandle(muonGeometryToken_); + + return PropagateToMuon(magfield, + propagator, + propagatorAny, + propagatorOpposite, + muonGeometry, + useSimpleGeometry_, + useMB2_, + fallbackToME1_, + whichTrack_, + whichState_, + cosmicPropagation_, + useMB2InOverlap_); +}