src
CommonTools
UtilAlgos
interface
Matcher.h
Go to the documentation of this file.
1
#ifndef UtilAlgos_Matcher_h
2
#define UtilAlgos_Matcher_h
3
/* \class Matcher
4
*
5
* \author Luca Lista, INFN
6
*
7
*/
8
#include "
FWCore/Framework/interface/global/EDProducer.h
"
9
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
10
#include "
FWCore/Utilities/interface/InputTag.h
"
11
#include "
CommonTools/UtilAlgos/interface/DeltaR.h
"
12
#include "
FWCore/Framework/interface/Event.h
"
13
#include "
DataFormats/Common/interface/Handle.h
"
14
#include "
DataFormats/Common/interface/AssociationMap.h
"
15
#include "
DataFormats/Common/interface/OneToOne.h
"
16
#include "
DataFormats/Common/interface/getRef.h
"
17
18
namespace
reco
{
19
namespace
modules
{
20
template
<
typename
C1,
typename
C2,
typename
M = edm::AssociationMap<edm::OneToOne<C1, C2> > >
21
class
MatcherBase
:
public
edm::global::EDProducer
<> {
22
public
:
23
MatcherBase
(
const
edm::ParameterSet
&);
24
~MatcherBase
()
override
;
25
26
protected
:
27
typedef
typename
C1::value_type
T1
;
28
typedef
typename
C2::value_type
T2
;
29
typedef
M
MatchMap
;
30
31
private
:
32
void
produce
(
edm::StreamID
,
edm::Event
&,
const
edm::EventSetup
&)
const override
;
33
edm::EDGetTokenT<C1>
srcToken_
;
34
edm::EDGetTokenT<C2>
matchedToken_
;
35
double
distMin_
;
36
virtual
double
matchDistance
(
const
T1
&,
const
T2
&)
const
= 0;
37
virtual
bool
select
(
const
T1
&,
const
T2
&)
const
= 0;
38
};
39
40
template
<
typename
C1,
41
typename
C2,
42
typename
S
,
43
typename
D
=
DeltaR<typename C1::value_type, typename C2::value_type>
,
44
typename
M =
edm::AssociationMap<edm::OneToOne<C1, C2>
> >
45
class
Matcher
:
public
MatcherBase
<C1, C2, M> {
46
public
:
47
Matcher
(
const
edm::ParameterSet
&
cfg
)
48
:
MatcherBase
<C1, C2, M>(
cfg
),
select_
(
reco
::
modules
::
make
<
S
>(
cfg
)),
distance_
(
reco
::
modules
::
make
<
D
>(
cfg
)) {}
49
~Matcher
()
override
{}
50
51
private
:
52
typedef
typename
MatcherBase<C1, C2, M>::T1
T1
;
53
typedef
typename
MatcherBase<C1, C2, M>::T2
T2
;
54
typedef
typename
MatcherBase<C1, C2, M>::MatchMap
MatchMap
;
55
56
double
matchDistance
(
const
T1
&
c1
,
const
T2
& c2)
const override
{
return
distance_
(
c1
, c2); }
57
bool
select
(
const
T1
&
c1
,
const
T2
& c2)
const override
{
return
select_
(
c1
, c2); }
58
S
select_
;
59
D
distance_
;
60
};
61
62
namespace
helper
{
63
typedef
std::pair<size_t, double>
MatchPair
;
64
65
struct
SortBySecond
{
66
bool
operator()
(
const
MatchPair
&
p1
,
const
MatchPair
&
p2
)
const
{
return
p1
.second <
p2
.second; }
67
};
68
}
// namespace helper
69
70
template
<
typename
C1,
typename
C2,
typename
M>
71
MatcherBase<C1, C2, M>::MatcherBase
(
const
edm::ParameterSet
&
cfg
)
72
: srcToken_(consumes<C1>(
cfg
.
template
getParameter<
edm
::
InputTag
>(
"src"
))),
73
matchedToken_(consumes<C2>(
cfg
.
template
getParameter<
edm
::
InputTag
>(
"matched"
))),
74
distMin_(
cfg
.
template
getParameter<double>(
"distMin"
)) {
75
produces<MatchMap>();
76
}
77
78
template
<
typename
C1,
typename
C2,
typename
M>
79
MatcherBase<C1, C2, M>::~MatcherBase
() {}
80
81
template
<
typename
C1,
typename
C2,
typename
M>
82
void
MatcherBase<C1, C2, M>::produce
(
edm::StreamID
,
edm::Event
& evt,
const
edm::EventSetup
&)
const
{
83
using namespace
edm
;
84
using namespace
std
;
85
Handle<C2>
matched
;
86
evt.
getByToken
(matchedToken_,
matched
);
87
Handle<C1>
cands
;
88
evt.
getByToken
(srcToken_,
cands
);
89
typedef
typename
MatchMap::ref_type ref_type;
90
typedef
typename
ref_type::key_type key_ref_type;
91
typedef
typename
ref_type::value_type
value_ref_type;
92
unique_ptr<MatchMap> matchMap(
new
MatchMap
(ref_type(key_ref_type(
cands
), value_ref_type(
matched
))));
93
for
(
size_t
c
= 0;
c
!=
cands
->size(); ++
c
) {
94
const
T1
&
cand
= (*cands)[
c
];
95
vector<helper::MatchPair>
v
;
96
for
(
size_t
m
= 0;
m
!=
matched
->size(); ++
m
) {
97
const
T2
&
match
= (*matched)[
m
];
98
if
(
select
(
cand
,
match
)) {
99
double
dist = matchDistance(
cand
,
match
);
100
if
(dist < distMin_)
101
v
.push_back(make_pair(
m
, dist));
102
}
103
}
104
if
(!
v
.empty()) {
105
size_t
mMin = min_element(
v
.begin(),
v
.end(),
helper::SortBySecond
())->
first
;
106
typedef
typename
MatchMap::key_type key_type;
107
typedef
typename
MatchMap::data_type
data_type
;
108
matchMap->insert(
edm::getRef
(
cands
,
c
),
edm::getRef
(
matched
, mMin));
109
}
110
}
111
evt.
put
(
std::move
(matchMap));
112
}
113
114
}
// namespace modules
115
}
// namespace reco
116
117
#endif
edm::getRef
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition:
getRef.h:28
first
auto first
Definition:
CAHitNtupletGeneratorKernelsImpl.h:127
reco::modules::MatcherBase::select
virtual bool select(const T1 &, const T2 &) const =0
EDProducer.h
ecal::multifit::data_type
::ecal::reco::ComputationScalarType data_type
Definition:
EigenMatrixTypes_gpu.h:18
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
helper
Definition:
helper.py:1
SiStripOfflineCRack_cfg.p2
p2
Definition:
SiStripOfflineCRack_cfg.py:140
muonTagProbeFilters_cff.matched
matched
Definition:
muonTagProbeFilters_cff.py:62
HLT_2022v12_cff.cands
cands
Definition:
HLT_2022v12_cff.py:11954
AssociationMap.h
DeltaR
Definition:
deltaR.h:58
reco::modules::helper::SortBySecond
Definition:
Matcher.h:65
edm::StreamID
Definition:
StreamID.h:30
Event.h
DeltaR.h
reco::modules::Matcher::Matcher
Matcher(const edm::ParameterSet &cfg)
Definition:
Matcher.h:47
HLT_2022v12_cff.InputTag
InputTag
Definition:
HLT_2022v12_cff.py:65221
edm::Handle
Definition:
AssociativeIterator.h:50
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition:
ParameterAdapter.h:21
std
Definition:
JetResolutionObject.h:76
reco::modules::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
Matcher.h:66
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:539
findQualityFiles.v
v
Definition:
findQualityFiles.py:179
OneToOne.h
reco::modules::MatcherBase::srcToken_
edm::EDGetTokenT< C1 > srcToken_
Definition:
Matcher.h:33
edm::EDGetTokenT< C1 >
reco::modules::MatcherBase::distMin_
double distMin_
Definition:
Matcher.h:35
ParameterSet.h
LaserDQM_cfg.p1
p1
Definition:
LaserDQM_cfg.py:42
c
auto & c
Definition:
CAHitNtupletGeneratorKernelsImpl.h:56
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
Matcher
Definition:
Matcher.py:1
reco::modules::Matcher::T2
MatcherBase< C1, C2, M >::T2 T2
Definition:
Matcher.h:53
reco::modules::MatcherBase
Definition:
Matcher.h:21
reco::modules::MatcherBase::matchDistance
virtual double matchDistance(const T1 &, const T2 &) const =0
visualization-live-secondInstance_cfg.m
m
Definition:
visualization-live-secondInstance_cfg.py:80
S
Definition:
CSCDBL1TPParametersExtended.h:16
edm::AssociationMap
Definition:
AssociationMap.h:48
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition:
svgfig.py:521
edm::EventSetup
Definition:
EventSetup.h:59
edm::global::EDProducer
Definition:
EDProducer.h:32
looper.cfg
cfg
Definition:
looper.py:296
reco::modules::MatcherBase::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition:
Matcher.h:82
alignmentValidation.c1
c1
do drawing
Definition:
alignmentValidation.py:1025
reco::modules::Matcher::distance_
D distance_
Definition:
Matcher.h:59
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition:
Factorize.h:141
reco::modules::MatcherBase::T1
C1::value_type T1
Definition:
Matcher.h:27
reco::modules::Matcher::~Matcher
~Matcher() override
Definition:
Matcher.h:49
reco::modules::Matcher::T1
MatcherBase< C1, C2, M >::T1 T1
Definition:
Matcher.h:52
reco::modules::MatcherBase::T2
C2::value_type T2
Definition:
Matcher.h:28
reco::modules::MatcherBase::MatchMap
M MatchMap
Definition:
Matcher.h:29
reco::modules::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
Matcher.h:63
reco::modules::MatcherBase::matchedToken_
edm::EDGetTokenT< C2 > matchedToken_
Definition:
Matcher.h:34
singleTopDQM_cfi.select
select
Definition:
singleTopDQM_cfi.py:50
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:46
edm
HLT enums.
Definition:
AlignableModifier.h:19
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:48
reco::modules::Matcher::select
bool select(const T1 &c1, const T2 &c2) const override
Definition:
Matcher.h:57
cand
Definition:
decayParser.h:32
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
edm::Event
Definition:
Event.h:73
reco::modules::Matcher::select_
S select_
Definition:
Matcher.h:58
reco::modules::MatcherBase::~MatcherBase
~MatcherBase() override
Definition:
Matcher.h:79
reco::modules::Matcher::MatchMap
MatcherBase< C1, C2, M >::MatchMap MatchMap
Definition:
Matcher.h:54
getRef.h
eostools.move
def move(src, dest)
Definition:
eostools.py:511
reco::modules::Matcher::matchDistance
double matchDistance(const T1 &c1, const T2 &c2) const override
Definition:
Matcher.h:56
reco::modules::MatcherBase::MatcherBase
MatcherBase(const edm::ParameterSet &)
Definition:
Matcher.h:71
Handle.h
modules
Definition:
MuonCleanerBySegments.cc:35
Generated for CMSSW Reference Manual by
1.8.14