From 4ba981a24258192d674e05bb311479f5d9ba042f Mon Sep 17 00:00:00 2001 From: Alessio Boletti Date: Thu, 16 Nov 2017 16:01:24 +0100 Subject: [PATCH 1/2] Make the vertex filters robust to muon duplicates --- HLTrigger/btau/src/HLTmumutkFilter.cc | 39 +++++++++++-------------- HLTrigger/btau/src/HLTmumutktkFilter.cc | 10 +++---- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/HLTrigger/btau/src/HLTmumutkFilter.cc b/HLTrigger/btau/src/HLTmumutkFilter.cc index e91de43e24472..ef45ebc14fa29 100644 --- a/HLTrigger/btau/src/HLTmumutkFilter.cc +++ b/HLTrigger/btau/src/HLTmumutkFilter.cc @@ -131,35 +131,30 @@ bool HLTmumutkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetu reco::RecoChargedCandidateCollection::const_iterator tkcand ; int iFoundRefs = 0; - bool threeMuons = false; + bool track1Matched = false; + bool track2Matched = false; + bool track3Matched = false; for (auto cand=mucands->begin(); cand!=mucands->end(); cand++) { reco::TrackRef tkRef = cand->get(); - if (tkRef == vertextkRef1 && iFoundRefs==0) {mucand1 = cand; iFoundRefs++;} - else if(tkRef == vertextkRef1 && iFoundRefs==1) {mucand2 = cand; iFoundRefs++;} - else if(tkRef == vertextkRef1 && iFoundRefs==2) {threeMuons = true;} - if (tkRef == vertextkRef2 && iFoundRefs==0) {mucand1 = cand; iFoundRefs++;} - else if(tkRef == vertextkRef2 && iFoundRefs==1) {mucand2 = cand; iFoundRefs++;} - else if(tkRef == vertextkRef2 && iFoundRefs==2) {threeMuons = true;} - if (tkRef == vertextkRef3 && iFoundRefs==0) {mucand1 = cand; iFoundRefs++;} - else if(tkRef == vertextkRef3 && iFoundRefs==1) {mucand2 = cand; iFoundRefs++;} - else if(tkRef == vertextkRef3 && iFoundRefs==2) {threeMuons = true;} + if (tkRef == vertextkRef1 && iFoundRefs==0 && !track1Matched) {mucand1 = cand; iFoundRefs++; track1Matched = true;} + else if(tkRef == vertextkRef1 && iFoundRefs==1 && !track1Matched) {mucand2 = cand; iFoundRefs++; track1Matched = true;} + if (tkRef == vertextkRef2 && iFoundRefs==0 && !track2Matched) {mucand1 = cand; iFoundRefs++; track2Matched = true;} + else if(tkRef == vertextkRef2 && iFoundRefs==1 && !track2Matched) {mucand2 = cand; iFoundRefs++; track2Matched = true;} + if (tkRef == vertextkRef3 && iFoundRefs==0 && !track3Matched) {mucand1 = cand; iFoundRefs++; track3Matched = true;} + else if(tkRef == vertextkRef3 && iFoundRefs==1 && !track3Matched) {mucand2 = cand; iFoundRefs++; track3Matched = true;} } - if(threeMuons) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " - << " exactly two muons by definition." << std::endl; + if(iFoundRefs < 2) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " + << " at least two muons by definition." << std::endl; - bool twoTrks = false; int iTrkFoundRefs = 0; for (auto cand=trkcands->begin(); cand!=trkcands->end(); cand++) { reco::TrackRef tkRef = cand->get(); - if (tkRef == vertextkRef1 && iTrkFoundRefs==0) {tkcand = cand; iTrkFoundRefs++;} - else if(tkRef == vertextkRef1 && iTrkFoundRefs==1) {twoTrks = true;} - if (tkRef == vertextkRef2 && iTrkFoundRefs==0) {tkcand = cand; iTrkFoundRefs++;} - else if(tkRef == vertextkRef2 && iTrkFoundRefs==1) {twoTrks = true;} - if (tkRef == vertextkRef3 && iTrkFoundRefs==0) {tkcand = cand; iTrkFoundRefs++;} - else if(tkRef == vertextkRef3 && iTrkFoundRefs==1) {twoTrks = true;} + if (tkRef == vertextkRef1 && iTrkFoundRefs==0 && !track1Matched) {tkcand = cand; iTrkFoundRefs++; track1Matched = true;} + if (tkRef == vertextkRef2 && iTrkFoundRefs==0 && !track2Matched) {tkcand = cand; iTrkFoundRefs++; track2Matched = true;} + if (tkRef == vertextkRef3 && iTrkFoundRefs==0 && !track3Matched) {tkcand = cand; iTrkFoundRefs++; track3Matched = true;} } - if(twoTrks) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " - << " exactly one track by definition." << std::endl; + if(iTrkFoundRefs < 1) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " + << " at least one track by definition." << std::endl; // calculate three-track transverse momentum math::XYZVector pperp(mucand1->px() + mucand2->px() + tkcand->px(), @@ -209,4 +204,4 @@ bool HLTmumutkFilter::triggerdByPreviousLevel(const reco::RecoChargedCandidateRe if (candref == vcands[i]) return true; } return false; -} \ No newline at end of file +} diff --git a/HLTrigger/btau/src/HLTmumutktkFilter.cc b/HLTrigger/btau/src/HLTmumutktkFilter.cc index fffc28d0d9c30..fed550ea4f8c2 100644 --- a/HLTrigger/btau/src/HLTmumutktkFilter.cc +++ b/HLTrigger/btau/src/HLTmumutktkFilter.cc @@ -134,8 +134,8 @@ bool HLTmumutktkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSe if (tkRef == iVec) {mucandVec.push_back(cand); break;} } } - if(mucandVec.size()!= 2) throw cms::Exception("BadLogic") << "HLTmumutktkFilterr: ERROR: the vertex must have " - << " exactly two muons by definition." << std::endl; + if(mucandVec.size() < 2) throw cms::Exception("BadLogic") << "HLTmumutktkFilterr: ERROR: the vertex must have " + << " at least two muons by definition." << std::endl; for (auto cand=trkcands->begin(); cand!=trkcands->end(); cand++) { reco::TrackRef tkRef = cand->get(); @@ -143,8 +143,8 @@ bool HLTmumutktkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSe if (tkRef == iVec) {trkcandVec.push_back(cand); break;} } } - if(trkcandVec.size()!= 2 ) throw cms::Exception("BadLogic") << "HLTmumutktkFilterr: ERROR: the vertex must have " - << " exactly two tracks by definition." << std::endl; + if(trkcandVec.size() < 2 ) throw cms::Exception("BadLogic") << "HLTmumutktkFilterr: ERROR: the vertex must have " + << " at least two tracks by definition." << std::endl; // calculate four-track transverse momentum math::XYZVector pperp(mucandVec.at(0)->px() + mucandVec.at(1)->px() + trkcandVec.at(0)->px() + trkcandVec.at(1)->px(), @@ -198,4 +198,4 @@ bool HLTmumutktkFilter::triggerdByPreviousLevel(const reco::RecoChargedCandidate if (candref == vcands[i]) return true; } return false; -} \ No newline at end of file +} From 91e3196073b9141066031b94d1903ecb15d8c07f Mon Sep 17 00:00:00 2001 From: Alessio Boletti Date: Fri, 17 Nov 2017 21:26:11 +0100 Subject: [PATCH 2/2] minor fixes in code structure --- HLTrigger/btau/src/HLTmumutkFilter.cc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/HLTrigger/btau/src/HLTmumutkFilter.cc b/HLTrigger/btau/src/HLTmumutkFilter.cc index ef45ebc14fa29..f721b4b92f745 100644 --- a/HLTrigger/btau/src/HLTmumutkFilter.cc +++ b/HLTrigger/btau/src/HLTmumutkFilter.cc @@ -136,12 +136,18 @@ bool HLTmumutkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetu bool track3Matched = false; for (auto cand=mucands->begin(); cand!=mucands->end(); cand++) { reco::TrackRef tkRef = cand->get(); - if (tkRef == vertextkRef1 && iFoundRefs==0 && !track1Matched) {mucand1 = cand; iFoundRefs++; track1Matched = true;} - else if(tkRef == vertextkRef1 && iFoundRefs==1 && !track1Matched) {mucand2 = cand; iFoundRefs++; track1Matched = true;} - if (tkRef == vertextkRef2 && iFoundRefs==0 && !track2Matched) {mucand1 = cand; iFoundRefs++; track2Matched = true;} - else if(tkRef == vertextkRef2 && iFoundRefs==1 && !track2Matched) {mucand2 = cand; iFoundRefs++; track2Matched = true;} - if (tkRef == vertextkRef3 && iFoundRefs==0 && !track3Matched) {mucand1 = cand; iFoundRefs++; track3Matched = true;} - else if(tkRef == vertextkRef3 && iFoundRefs==1 && !track3Matched) {mucand2 = cand; iFoundRefs++; track3Matched = true;} + if (!track1Matched) { + if (tkRef == vertextkRef1 && iFoundRefs==0) {mucand1 = cand; iFoundRefs++; track1Matched = true;} + else if(tkRef == vertextkRef1 && iFoundRefs==1) {mucand2 = cand; iFoundRefs++; track1Matched = true;} + } + if (!track2Matched) { + if (tkRef == vertextkRef2 && iFoundRefs==0) {mucand1 = cand; iFoundRefs++; track2Matched = true;} + else if(tkRef == vertextkRef2 && iFoundRefs==1) {mucand2 = cand; iFoundRefs++; track2Matched = true;} + } + if (!track3Matched) { + if (tkRef == vertextkRef3 && iFoundRefs==0) {mucand1 = cand; iFoundRefs++; track3Matched = true;} + else if(tkRef == vertextkRef3 && iFoundRefs==1) {mucand2 = cand; iFoundRefs++; track3Matched = true;} + } } if(iFoundRefs < 2) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " << " at least two muons by definition." << std::endl; @@ -149,11 +155,11 @@ bool HLTmumutkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetu int iTrkFoundRefs = 0; for (auto cand=trkcands->begin(); cand!=trkcands->end(); cand++) { reco::TrackRef tkRef = cand->get(); - if (tkRef == vertextkRef1 && iTrkFoundRefs==0 && !track1Matched) {tkcand = cand; iTrkFoundRefs++; track1Matched = true;} - if (tkRef == vertextkRef2 && iTrkFoundRefs==0 && !track2Matched) {tkcand = cand; iTrkFoundRefs++; track2Matched = true;} - if (tkRef == vertextkRef3 && iTrkFoundRefs==0 && !track3Matched) {tkcand = cand; iTrkFoundRefs++; track3Matched = true;} + if (tkRef == vertextkRef1 && iTrkFoundRefs==0 && !track1Matched) {tkcand = cand; iTrkFoundRefs++; track1Matched = true; break;} + if (tkRef == vertextkRef2 && iTrkFoundRefs==0 && !track2Matched) {tkcand = cand; iTrkFoundRefs++; track2Matched = true; break;} + if (tkRef == vertextkRef3 && iTrkFoundRefs==0 && !track3Matched) {tkcand = cand; iTrkFoundRefs++; track3Matched = true; break;} } - if(iTrkFoundRefs < 1) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " + if(iTrkFoundRefs == 0) throw cms::Exception("BadLogic") << "HLTmumutkFilterr: ERROR: the vertex must have " << " at least one track by definition." << std::endl; // calculate three-track transverse momentum