src
CommonTools
UtilAlgos
interface
NewMatcher.h
Go to the documentation of this file.
1
#ifndef UtilAlgos_NewMatcher_h
2
#define UtilAlgos_NewMatcher_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 "
CommonTools/UtilAlgos/interface/MasterCollectionHelper.h
"
13
#include "
FWCore/Framework/interface/Event.h
"
14
#include "
DataFormats/Common/interface/Handle.h
"
15
#include "
DataFormats/Common/interface/Association.h
"
16
#include "
DataFormats/Common/interface/getRef.h
"
17
#include "
DataFormats/Common/interface/View.h
"
18
19
namespace
reco
{
20
namespace
modulesNew {
21
22
template
<
typename
C1,
typename
C2,
typename
S,
typename
D = DeltaR<
typename
C1::value_type,
typename
C2::value_type> >
23
class
Matcher
:
public
edm::global::EDProducer
<> {
24
public
:
25
Matcher
(
const
edm::ParameterSet
&
cfg
);
26
~Matcher
()
override
;
27
28
private
:
29
typedef
typename
C1::value_type
T1
;
30
typedef
typename
C2::value_type
T2
;
31
typedef
edm::Association<C2>
MatchMap
;
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
double
matchDistance
(
const
T1
&
c1
,
const
T2
& c2)
const
{
return
distance_
(
c1
, c2); }
37
bool
select
(
const
T1
&
c1
,
const
T2
& c2)
const
{
return
select_
(
c1
, c2); }
38
S
select_
;
39
D
distance_
;
40
};
41
42
namespace
helper
{
43
typedef
std::pair<size_t, double>
MatchPair
;
44
45
struct
SortBySecond
{
46
bool
operator()
(
const
MatchPair
&
p1
,
const
MatchPair
&
p2
)
const
{
return
p1
.second <
p2
.second; }
47
};
48
}
// namespace helper
49
50
template
<
typename
C1,
typename
C2,
typename
S,
typename
D>
51
Matcher<C1, C2, S, D>::Matcher
(
const
edm::ParameterSet
&
cfg
)
52
: srcToken_(consumes<C1>(
cfg
.
template
getParameter<
edm
::
InputTag
>(
"src"
))),
53
matchedToken_(consumes<C2>(
cfg
.
template
getParameter<
edm
::
InputTag
>(
"matched"
))),
54
distMin_(
cfg
.
template
getParameter<double>(
"distMin"
)),
55
select_(
reco
::
modules
::
make
<
S
>(
cfg
)),
56
distance_
(
reco
::
modules
::
make
<
D
>(
cfg
)) {
57
produces<MatchMap>();
58
}
59
60
template
<
typename
C1,
typename
C2,
typename
S,
typename
D>
61
Matcher<C1, C2, S, D>::~Matcher
() {}
62
63
template
<
typename
C1,
typename
C2,
typename
S,
typename
D>
64
void
Matcher<C1, C2, S, D>::produce
(
edm::StreamID
,
edm::Event
& evt,
const
edm::EventSetup
&)
const
{
65
using namespace
edm
;
66
using namespace
std
;
67
Handle<C2>
matched
;
68
evt.
getByToken
(matchedToken_,
matched
);
69
Handle<C1>
cands
;
70
evt.
getByToken
(srcToken_,
cands
);
71
unique_ptr<MatchMap> matchMap(
new
MatchMap
(
matched
));
72
size_t
size
=
cands
->size();
73
if
(
size
!= 0) {
74
typename
MatchMap::Filler
filler
(*matchMap);
75
::helper::MasterCollection<C1>
master
(
cands
, evt);
76
std::vector<int>
indices
(
master
.size(), -1);
77
for
(
size_t
c
= 0;
c
!=
size
; ++
c
) {
78
const
T1
&
cand
= (*cands)[
c
];
79
vector<helper::MatchPair>
v
;
80
for
(
size_t
m
= 0;
m
!=
matched
->size(); ++
m
) {
81
const
T2
&
match
= (*matched)[
m
];
82
if
(
select
(
cand
,
match
)) {
83
double
dist = matchDistance(
cand
,
match
);
84
if
(dist < distMin_)
85
v
.push_back(make_pair(
m
, dist));
86
}
87
}
88
if
(!
v
.empty()) {
89
size_t
idx
=
master
.index(
c
);
90
assert
(
idx
<
indices
.size());
91
indices
[
idx
] = min_element(
v
.begin(),
v
.end(),
helper::SortBySecond
())->
first
;
92
}
93
}
94
filler
.insert(
master
.get(),
indices
.begin(),
indices
.end());
95
filler
.fill();
96
}
97
evt.
put
(
std::move
(matchMap));
98
}
99
100
}
// namespace modulesNew
101
}
// namespace reco
102
103
#endif
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:443
first
auto first
Definition:
CAHitNtupletGeneratorKernelsImpl.h:127
EDProducer.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
helper
Definition:
helper.py:1
MasterCollectionHelper.h
Association.h
SiStripOfflineCRack_cfg.p2
p2
Definition:
SiStripOfflineCRack_cfg.py:140
muonTagProbeFilters_cff.matched
matched
Definition:
muonTagProbeFilters_cff.py:62
reco::modulesNew::Matcher::srcToken_
edm::EDGetTokenT< C1 > srcToken_
Definition:
NewMatcher.h:33
HLT_2022v12_cff.cands
cands
Definition:
HLT_2022v12_cff.py:11954
heavyIonCSV_trainingSettings.idx
idx
Definition:
heavyIonCSV_trainingSettings.py:5
distance_
double distance_
Definition:
PFRecoTauChargedHadronFromGenericTrackPlugin.cc:196
edm::StreamID
Definition:
StreamID.h:30
Event.h
DeltaR.h
reco::modulesNew::Matcher::MatchMap
edm::Association< C2 > MatchMap
Definition:
NewMatcher.h:31
HLT_2022v12_cff.InputTag
InputTag
Definition:
HLT_2022v12_cff.py:65221
reco::modulesNew::Matcher::select_
S select_
Definition:
NewMatcher.h:38
edm::Handle
Definition:
AssociativeIterator.h:50
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition:
ParameterAdapter.h:21
dqmdumpme.indices
indices
Definition:
dqmdumpme.py:50
reco::modulesNew::Matcher::~Matcher
~Matcher() override
Definition:
NewMatcher.h:61
std
Definition:
JetResolutionObject.h:76
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:539
reco::modulesNew::Matcher::T2
C2::value_type T2
Definition:
NewMatcher.h:30
findQualityFiles.v
v
Definition:
findQualityFiles.py:179
reco::modulesNew::Matcher::matchedToken_
edm::EDGetTokenT< C2 > matchedToken_
Definition:
NewMatcher.h:34
cms::cuda::assert
assert(be >=bs)
edm::EDGetTokenT< C1 >
edm::Association::Filler
Definition:
Association.h:78
ParameterSet.h
LaserDQM_cfg.p1
p1
Definition:
LaserDQM_cfg.py:42
c
auto & c
Definition:
CAHitNtupletGeneratorKernelsImpl.h:56
edm::Association
Definition:
Association.h:18
reco::modulesNew::Matcher::distMin_
double distMin_
Definition:
NewMatcher.h:35
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
Matcher
Definition:
Matcher.py:1
volumeBasedMagneticField_160812_cfi.master
master
Definition:
volumeBasedMagneticField_160812_cfi.py:60
visualization-live-secondInstance_cfg.m
m
Definition:
visualization-live-secondInstance_cfg.py:80
S
Definition:
CSCDBL1TPParametersExtended.h:16
View.h
reco::modulesNew::Matcher::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition:
NewMatcher.h:64
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
reco::modulesNew::Matcher::T1
C1::value_type T1
Definition:
NewMatcher.h:29
looper.cfg
cfg
Definition:
looper.py:296
reco::modulesNew::helper::SortBySecond
Definition:
NewMatcher.h:45
alignmentValidation.c1
c1
do drawing
Definition:
alignmentValidation.py:1025
reco::modulesNew::Matcher::distance_
D distance_
Definition:
NewMatcher.h:39
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition:
Factorize.h:141
reco::modulesNew::Matcher::matchDistance
double matchDistance(const T1 &c1, const T2 &c2) const
Definition:
NewMatcher.h:36
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
reco::modulesNew::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
NewMatcher.h:43
reco::modulesNew::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
NewMatcher.h:46
edm::ParameterSet
Definition:
ParameterSet.h:47
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
trigObjTnPSource_cfi.filler
filler
Definition:
trigObjTnPSource_cfi.py:21
getRef.h
reco::modulesNew::Matcher::select
bool select(const T1 &c1, const T2 &c2) const
Definition:
NewMatcher.h:37
eostools.move
def move(src, dest)
Definition:
eostools.py:511
Handle.h
modules
Definition:
MuonCleanerBySegments.cc:35
reco::modulesNew::Matcher::Matcher
Matcher(const edm::ParameterSet &cfg)
Definition:
NewMatcher.h:51
Generated for CMSSW Reference Manual by
1.8.14