From 1bd5443939a6148221d8993e00b27906d8c4b855 Mon Sep 17 00:00:00 2001 From: Alessio Boletti Date: Thu, 16 Nov 2017 16:20:45 +0100 Subject: [PATCH 1/2] Make the vertex filters robust to muon duplicates --- HLTrigger/btau/src/HLTmumutkFilter.cc | 41 +++++++++++-------------- HLTrigger/btau/src/HLTmumutktkFilter.cc | 12 ++++---- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/HLTrigger/btau/src/HLTmumutkFilter.cc b/HLTrigger/btau/src/HLTmumutkFilter.cc index 369688133f159..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(), @@ -167,7 +162,7 @@ bool HLTmumutkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetu 0.); // get vertex position and error to calculate the decay length significance - reco::Vertex::Point vpoint=displacedVertex.position(); + const reco::Vertex::Point& vpoint=displacedVertex.position(); reco::Vertex::Error verr = displacedVertex.error(); GlobalPoint secondaryVertex (vpoint.x(), vpoint.y(), vpoint.z()); GlobalError err(verr.At(0,0), verr.At(1,0), verr.At(1,1), verr.At(2,0), verr.At(2,1), verr.At(2,2) ); @@ -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 e1badb770f374..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(), @@ -152,7 +152,7 @@ bool HLTmumutktkFilter::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSe 0.); // get vertex position and error to calculate the decay length significance - reco::Vertex::Point vpoint=displacedVertex.position(); + const reco::Vertex::Point& vpoint=displacedVertex.position(); reco::Vertex::Error verr = displacedVertex.error(); GlobalPoint secondaryVertex (vpoint.x(), vpoint.y(), vpoint.z()); GlobalError err(verr.At(0,0), verr.At(1,0), verr.At(1,1), verr.At(2,0), verr.At(2,1), verr.At(2,2) ); @@ -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 480e4140f4f17c2c629bfd20753358ab35626fb4 Mon Sep 17 00:00:00 2001 From: Alessio Boletti Date: Sat, 18 Nov 2017 09:58:04 +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