1 #ifndef MuonAnalysis_MuonAssociators_interface_L1MuonMatcherAlgo_h 2 #define MuonAnalysis_MuonAssociators_interface_L1MuonMatcherAlgo_h 11 #include <type_traits> 26 template <edm::Transition Tr>
101 const std::vector<l1extra::L1MuonParticle> &l1,
113 const std::vector<l1extra::L1MuonParticle> &l1,
126 const std::vector<l1extra::L1MuonParticle> &l1,
138 const std::vector<l1extra::L1MuonParticle> &l1,
148 const std::vector<l1t::Muon> &l1,
160 const std::vector<l1t::Muon> &l1,
173 const std::vector<l1t::Muon> &l1,
185 const std::vector<l1t::Muon> &l1,
195 template <
typename Collection,
typename Selector>
197 const Collection &l1,
210 template <
typename Collection,
typename Selector>
212 const Collection &l1,
225 template <
typename Collection,
typename Selector>
227 const Collection &l1,
264 template <edm::Transition Tr>
265 template <
typename Collection,
typename Selector>
267 const Collection &
l1s,
276 double minDeltaR2 = deltaR2_;
280 for (
int i = 0,
n =
l1s.size();
i <
n; ++
i) {
283 double thisDeltaPhi =
::deltaPhi(
double(
pos.phi()), l1.phi() + l1PhiOffset_);
284 double thisDeltaEta =
pos.eta() - l1.eta();
285 double thisDeltaR2 =
::deltaR2(
double(
pos.eta()),
double(
pos.phi()), l1.eta(), l1.phi() + l1PhiOffset_);
286 int thisQual = genericQuality<obj>(l1);
287 double thisPt = l1.pt();
288 if ((fabs(thisDeltaPhi) < deltaPhi_) && (fabs(thisDeltaEta) < deltaEta_) &&
289 (thisDeltaR2 < deltaR2_)) {
290 bool betterMatch = (
match == -1);
293 betterMatch = (thisDeltaR2 < minDeltaR2);
296 betterMatch = (fabs(thisDeltaEta) < fabs(
minDeltaEta));
299 betterMatch = (fabs(thisDeltaPhi) < fabs(
minDeltaPhi));
302 betterMatch = (thisPt >
maxPt);
306 betterMatch = (thisQual > maxQual || ((thisQual == maxQual) && (thisPt >
maxPt)));
313 minDeltaR2 = thisDeltaR2;
325 template <edm::Transition Tr>
327 : propSetup_(iConfig, iCollector),
328 useStage2L1_(iConfig.existsAs<
bool>(
"useStage2L1") ? iConfig.getParameter<
bool>(
"useStage2L1") :
false),
330 (iConfig.existsAs<
std::
string>(
"preselection")) ? iConfig.getParameter<
std::
string>(
"preselection") :
""),
331 deltaR2_(
std::
pow(iConfig.getParameter<double>(
"maxDeltaR"), 2)),
332 deltaPhi_(iConfig.existsAs<double>(
"maxDeltaPhi") ? iConfig.getParameter<double>(
"maxDeltaPhi") : 10),
333 deltaEta_(iConfig.existsAs<double>(
"maxDeltaEta") ? iConfig.getParameter<double>(
"maxDeltaEta") : 10),
334 l1PhiOffset_(iConfig.existsAs<double>(
"l1PhiOffset") ? iConfig.getParameter<double>(
"l1PhiOffset") : 0) {
335 bool reqQual = iConfig.
existsAs<
bool>(
"sortByQual") && iConfig.
getParameter<
bool>(
"sortByQual");
336 bool reqPhi = iConfig.
existsAs<
bool>(
"sortByDeltaPhi") && iConfig.
getParameter<
bool>(
"sortByDeltaPhi");
337 bool reqEta = iConfig.
existsAs<
bool>(
"sortByDeltaEta") && iConfig.
getParameter<
bool>(
"sortByDeltaEta");
340 if (reqPhi + reqEta + reqPt + reqQual > 1)
342 <<
"L1MuonMatcherAlgoT: Can't set more than one 'sortBy<XXX>' parameter to True.\n";
343 if (
sortBy ==
"deltaPhi") {
344 if (reqEta || reqPt || reqQual)
345 throw cms::Exception(
"Configuration") <<
"L1MuonMatcherAlgoT: Can't set sortBy = 'deltaPhi' and set also another " 346 "'sortBy<XXX>' parameter to True.\n";
350 if (
sortBy ==
"deltaEta") {
351 if (reqPhi || reqPt || reqQual)
352 throw cms::Exception(
"Configuration") <<
"L1MuonMatcherAlgoT: Can't set sortBy = 'deltaEta' and set also another " 353 "'sortBy<XXX>' parameter to True.\n";
358 if (reqPhi || reqEta || reqQual)
360 <<
"L1MuonMatcherAlgoT: Can't set sortBy = 'pt' and set also another 'sortBy<XXX>' parameter to True.\n";
364 if (
sortBy ==
"quality") {
365 if (reqPhi || reqEta || reqPt)
367 <<
"L1MuonMatcherAlgoT: Can't set sortBy = 'quality' and set also another 'sortBy<XXX>' parameter to True.\n";
372 if (reqPhi || reqEta || reqPt || reqQual)
374 <<
"L1MuonMatcherAlgoT: Can't set sortBy = 'deltaR' and set also another 'sortBy<XXX>' parameter to True.\n";
389 template <edm::Transition Tr>
391 prop_ = propSetup_.init(iSetup);
394 template <edm::Transition Tr>
399 if (preselectionCut_(l1)) {
401 double thisDeltaPhi =
::deltaPhi(
double(
pos.phi()), l1.
phi() + l1PhiOffset_);
402 double thisDeltaEta =
pos.eta() - l1.
eta();
403 double thisDeltaR2 =
::deltaR2(
double(
pos.eta()),
double(
pos.phi()), l1.
eta(), l1.
phi() + l1PhiOffset_);
404 if ((fabs(thisDeltaPhi) < deltaPhi_) && (fabs(thisDeltaEta) < deltaEta_) && (thisDeltaR2 < deltaR2_)) {
413 template <edm::Transition Tr>
415 const std::vector<l1extra::L1MuonParticle> &
l1s,
421 template <edm::Transition Tr>
423 const std::vector<l1t::Muon> &
l1s,
StringCutObjectSelector< reco::Candidate, true > L1Selector
~L1MuonMatcherAlgoT()=default
T getParameter(std::string const &) const
int genericQuality(l1extra::L1MuonParticle const &cand) const
int match(const SimTrack &tk, const edm::SimVertexContainer &vtxs, const std::vector< l1extra::L1MuonParticle > &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
const PropagateToMuon & propagatorToMuon() const
Return the propagator to second muon station (in case it's needed)
L1MuonMatcherAlgoT(const edm::ParameterSet &iConfig, edm::ConsumesCollector)
TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const
Extrapolate reco::Track to the muon station 2, return an invalid TSOS if it fails.
int match(const SimTrack &tk, const edm::SimVertexContainer &vtxs, const std::vector< l1t::Muon > &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
bool match(const reco::Track &tk, const l1extra::L1MuonParticle &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
int genericQuality(l1t::Muon const &cand) const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
L1Selector preselectionCut_
Preselection cut to apply to L1 candidates before matching.
int genericQuality(T const &cand) const
TrajectoryStateOnSurface extrapolate(const reco::Candidate &tk) const
Extrapolate reco::Candidate to the muon station 2, return an invalid TSOS if it fails.
int match(const reco::Track &tk, const std::vector< l1extra::L1MuonParticle > &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
void init(const edm::EventSetup &iSetup)
Call this method at the beginning of each run, to initialize geometry, magnetic field and propagators...
double l1PhiOffset_
offset to be added to the L1 phi before the match
bool match(const SimTrack &tk, const edm::SimVertexContainer &vtxs, const l1extra::L1MuonParticle &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
Propagate an object (usually a track) to the second (default) or first muon station.
Container::value_type value_type
GlobalPoint globalPosition() const
bool match(const reco::Candidate &c, const l1extra::L1MuonParticle &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
TrajectoryStateOnSurface extrapolate(const SimTrack &tk, const edm::SimVertexContainer &vtx) const
Extrapolate a SimTrack to the muon station 2, return an invalid TSOS if it fails. Requires SimVertice...
double deltaR2_
Matching cuts.
void setL1PhiOffset(double l1PhiOffset)
Add this offset to the L1 phi before doing the match, to correct for different scales in L1 vs offlin...
int matchGeneric(const reco::Track &tk, const Collection &l1, const Selector &sel, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
Functor that operates on <T>
PropagateToMuon & propagatorToMuon()
Return the propagator to second muon station (in case it's needed)
int match(const reco::Track &tk, const std::vector< l1t::Muon > &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
std::vector< SimVertex > SimVertexContainer
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &state) const
Extrapolate a FreeTrajectoryState to the muon station 2, return an invalid TSOS if it fails...
int matchGeneric(const reco::Candidate &c, const Collection &l1, const Selector &sel, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
PropagateToMuonSetupT< Tr > propSetup_
Matcher of reconstructed objects to L1 Muons.
SortBy
Sort by deltaPhi or deltaEta instead of deltaR.
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
int match(const reco::Candidate &c, const std::vector< l1t::Muon > &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
int match(const reco::Candidate &c, const std::vector< l1extra::L1MuonParticle > &l1, float &deltaR, float &deltaPhi, TrajectoryStateOnSurface &propagated) const
TrajectoryStateOnSurface extrapolate(const reco::Track &tk) const
Extrapolate reco::Track to the muon station 2, return an invalid TSOS if it fails.
double phi() const final
momentum azimuthal angle
double eta() const final
momentum pseudorapidity