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/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::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::Event
&,
const
edm::EventSetup
&)
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::Event
& evt,
const
edm::EventSetup
&) {
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
muonTagProbeFilters_cff.matched
matched
Definition:
muonTagProbeFilters_cff.py:62
Handle.h
EDProducer.h
modules
Definition:
ZHLTMatchFilter.cc:17
edm::EDGetTokenT< C1 >
edm
HLT enums.
Definition:
AlignableModifier.h:19
reco::modules::Matcher::matchDistance
double matchDistance(const T1 &c1, const T2 &c2) const override
Definition:
Matcher.h:56
AssociationMap.h
singleTopDQM_cfi.select
select
Definition:
singleTopDQM_cfi.py:50
reco::modules::MatcherBase::T1
C1::value_type T1
Definition:
Matcher.h:27
OneToOne.h
getRef.h
reco::modules::Matcher::select
bool select(const T1 &c1, const T2 &c2) const override
Definition:
Matcher.h:57
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition:
findQualityFiles.py:179
reco::modules::MatcherBase::T2
C2::value_type T2
Definition:
Matcher.h:28
DeltaR
Definition:
deltaR.h:58
edm::Handle
Definition:
AssociativeIterator.h:50
edm::AssociationMap::ref_type
Tag::ref_type ref_type
Holds the RefProd or RefToBaseProd of 1 or 2 collections.
Definition:
AssociationMap.h:63
edm::first
T first(std::pair< T, U > const &p)
Definition:
ParameterSet.cc:210
reco::modules::Matcher::T2
MatcherBase< C1, C2, M >::T2 T2
Definition:
Matcher.h:53
edm::AssociationMap::data_type
Tag::data_type data_type
insert data type
Definition:
AssociationMap.h:61
reco::modules::Matcher::~Matcher
~Matcher() override
Definition:
Matcher.h:49
visualization-live-secondInstance_cfg.m
m
Definition:
visualization-live-secondInstance_cfg.py:72
p2
double p2[4]
Definition:
TauolaWrapper.h:90
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:528
reco::modules::MatcherBase::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
Matcher.h:82
S
double S(const TLorentzVector &, const TLorentzVector &)
Definition:
Particle.cc:97
DeltaR.h
reco::modules::MatcherBase::matchDistance
virtual double matchDistance(const T1 &, const T2 &) const =0
reco::modules::MatcherBase
Definition:
Matcher.h:21
HLT_2018_cff.InputTag
InputTag
Definition:
HLT_2018_cff.py:79016
edm::ParameterSet
Definition:
ParameterSet.h:36
reco::modules::MatcherBase::~MatcherBase
~MatcherBase() override
Definition:
Matcher.h:79
Event.h
edm::getRef
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition:
getRef.h:28
edm::AssociationMap
Definition:
AssociationMap.h:48
reco::modules::Matcher::distance_
D distance_
Definition:
Matcher.h:59
helper
Definition:
helper.py:1
cand
Definition:
decayParser.h:34
alignmentValidation.c1
c1
do drawing
Definition:
alignmentValidation.py:1025
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:132
p1
double p1[4]
Definition:
TauolaWrapper.h:89
edm::EventSetup
Definition:
EventSetup.h:57
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition:
svgfig.py:521
HltBtagPostValidation_cff.c
c
Definition:
HltBtagPostValidation_cff.py:31
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition:
ParameterAdapter.h:21
reco::modules::MatcherBase::MatcherBase
MatcherBase(const edm::ParameterSet &)
Definition:
Matcher.h:71
InputTag.h
looper.cfg
cfg
Definition:
looper.py:297
reco::modules::MatcherBase::select
virtual bool select(const T1 &, const T2 &) const =0
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition:
Factorize.h:141
reco::modules::MatcherBase::matchedToken_
edm::EDGetTokenT< C2 > matchedToken_
Definition:
Matcher.h:34
eostools.move
def move(src, dest)
Definition:
eostools.py:511
std
Definition:
JetResolutionObject.h:76
edm::match
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
Definition:
BranchDescription.cc:351
reco::modules::MatcherBase::distMin_
double distMin_
Definition:
Matcher.h:35
reco::modules::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
Matcher.h:66
HLT_2018_cff.cands
cands
Definition:
HLT_2018_cff.py:13762
reco::modules::Matcher::Matcher
Matcher(const edm::ParameterSet &cfg)
Definition:
Matcher.h:47
edm::EDProducer
Definition:
EDProducer.h:36
edm::AssociationMap::key_type
Tag::key_type key_type
insert key type
Definition:
AssociationMap.h:59
reco::modules::Matcher::select_
S select_
Definition:
Matcher.h:58
S
Definition:
CSCDBL1TPParametersExtended.h:16
ParameterSet.h
reco::modules::MatcherBase::srcToken_
edm::EDGetTokenT< C1 > srcToken_
Definition:
Matcher.h:33
reco::modules::Matcher::T1
MatcherBase< C1, C2, M >::T1 T1
Definition:
Matcher.h:52
reco::modules::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
Matcher.h:63
reco::modules::MatcherBase::MatchMap
M MatchMap
Definition:
Matcher.h:29
edm::Event
Definition:
Event.h:73
reco::modules::Matcher::MatchMap
MatcherBase< C1, C2, M >::MatchMap MatchMap
Definition:
Matcher.h:54
reco::modules::helper::SortBySecond
Definition:
Matcher.h:65
Matcher
Definition:
Matcher.py:1
Generated for CMSSW Reference Manual by
1.8.16