src
PhysicsTools
JetMCAlgos
plugins
CandOneToManyDeltaRMatcher.cc
Go to the documentation of this file.
1
/* \class CandOneToManyDeltaRMatcher
2
*
3
* Producer for simple match map:
4
* class to match two collections of candidate
5
* with one-to-Many matching
6
* All elements of class "matched" are matched to each element
7
* of class "source" orderd in DeltaR
8
*
9
*/
10
11
#include "
FWCore/Framework/interface/global/EDProducer.h
"
12
#include "
FWCore/ParameterSet/interface/ParameterSetfwd.h
"
13
14
#include "
DataFormats/Candidate/interface/Candidate.h
"
15
16
#include <vector>
17
#include <iostream>
18
19
class
CandOneToManyDeltaRMatcher
:
public
edm::global::EDProducer
<> {
20
public
:
21
CandOneToManyDeltaRMatcher
(
const
edm::ParameterSet
&);
22
~CandOneToManyDeltaRMatcher
()
override
;
23
24
private
:
25
void
produce
(
edm::StreamID
,
edm::Event
&,
const
edm::EventSetup
&)
const override
;
26
27
edm::EDGetTokenT<reco::CandidateCollection>
sourceToken_
;
28
edm::EDGetTokenT<reco::CandidateCollection>
matchedToken_
;
29
bool
printdebug_
;
30
};
31
32
#include "
FWCore/Framework/interface/ESHandle.h
"
33
#include "
FWCore/Framework/interface/Event.h
"
34
#include "
FWCore/Framework/interface/EventSetup.h
"
35
#include "
FWCore/Utilities/interface/InputTag.h
"
36
#include "
FWCore/Utilities/interface/EDMException.h
"
37
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
38
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
39
40
#include "
DataFormats/Common/interface/Handle.h
"
41
#include "
DataFormats/Candidate/interface/LeafCandidate.h
"
42
#include "
DataFormats/Candidate/interface/CandMatchMap.h
"
43
#include "
DataFormats/Candidate/interface/CandMatchMapMany.h
"
44
#include "
DataFormats/Candidate/interface/CandidateFwd.h
"
45
46
#include <Math/VectorUtil.h>
47
#include <TMath.h>
48
49
using namespace
edm
;
50
using namespace
std
;
51
using namespace
reco
;
52
using namespace
ROOT::Math::VectorUtil
;
53
54
namespace
reco
{
55
namespace
helper
{
56
typedef
pair<size_t, double>
MatchPair
;
57
58
struct
SortBySecond
{
59
bool
operator()
(
const
MatchPair
&
p1
,
const
MatchPair
&
p2
)
const
{
return
p1
.second <
p2
.second; }
60
};
61
}
// namespace helper
62
}
// namespace reco
63
64
CandOneToManyDeltaRMatcher::CandOneToManyDeltaRMatcher
(
const
ParameterSet
&
cfg
)
65
: sourceToken_(consumes<
CandidateCollection
>(
cfg
.getParameter<
InputTag
>(
"src"
))),
66
matchedToken_(consumes<
CandidateCollection
>(
cfg
.getParameter<
InputTag
>(
"matched"
))),
67
printdebug_(
cfg
.getUntrackedParameter<
bool
>(
"printDebug"
,
false
)) {
68
produces<CandMatchMapMany>();
69
}
70
71
CandOneToManyDeltaRMatcher::~CandOneToManyDeltaRMatcher
() {}
72
73
void
CandOneToManyDeltaRMatcher::produce
(
edm::StreamID
,
Event
& evt,
const
EventSetup
& es)
const
{
74
Handle<CandidateCollection>
source
;
75
Handle<CandidateCollection>
matched
;
76
evt.
getByToken
(
sourceToken_
,
source
);
77
evt.
getByToken
(
matchedToken_
,
matched
);
78
79
if
(
printdebug_
) {
80
for
(
CandidateCollection::const_iterator
c
=
source
->begin();
c
!=
source
->end(); ++
c
) {
81
cout
<<
"[CandOneToManyDeltaRMatcher] Et source "
<<
c
->et() << endl;
82
}
83
for
(
CandidateCollection::const_iterator
c
=
matched
->begin();
c
!=
matched
->end(); ++
c
) {
84
cout
<<
"[CandOneToManyDeltaRMatcher] Et matched "
<<
c
->et() << endl;
85
}
86
}
87
88
auto
matchMap = std::make_unique<CandMatchMapMany>(
89
CandMatchMapMany::ref_type
(
CandidateRefProd
(
source
),
CandidateRefProd
(
matched
)));
90
for
(
size_t
c
= 0;
c
!=
source
->size(); ++
c
) {
91
const
Candidate
&
src
= (*source)[
c
];
92
if
(
printdebug_
)
93
cout
<<
"[CandOneToManyDeltaRMatcher] source (Et,Eta,Phi) =("
<<
src
.et() <<
","
<<
src
.eta() <<
","
<<
src
.phi()
94
<<
")"
<< endl;
95
vector<reco::helper::MatchPair>
v
;
96
for
(
size_t
m
= 0;
m
!=
matched
->size(); ++
m
) {
97
const
Candidate
&
match
= (*matched)[
m
];
98
double
dist =
DeltaR
(
src
.p4(),
match
.p4());
99
v
.push_back(make_pair(
m
, dist));
100
}
101
if
(!
v
.empty()) {
102
sort
(
v
.begin(),
v
.end(),
reco::helper::SortBySecond
());
103
for
(
size_t
m
= 0;
m
!=
v
.size(); ++
m
) {
104
if
(
printdebug_
)
105
cout
<<
"[CandOneToManyDeltaRMatcher] match (Et,Eta,Phi) =("
<< (*matched)[
v
[
m
].first].et() <<
","
106
<< (*matched)[
v
[
m
].first].eta() <<
","
<< (*matched)[
v
[
m
].first].phi() <<
") DeltaR="
<<
v
[
m
].second
107
<< endl;
108
matchMap->insert(
CandidateRef
(
source
,
c
), make_pair(
CandidateRef
(
matched
,
v
[
m
].
first
),
v
[
m
].
second
));
109
}
110
}
111
}
112
113
evt.
put
(
std::move
(matchMap));
114
}
115
116
#include "
FWCore/PluginManager/interface/ModuleDef.h
"
117
#include "
FWCore/Framework/interface/MakerMacros.h
"
118
119
DEFINE_FWK_MODULE
(
CandOneToManyDeltaRMatcher
);
jetUpdater_cfi.sort
sort
Definition:
jetUpdater_cfi.py:30
CandMatchMap.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
CandOneToManyDeltaRMatcher::~CandOneToManyDeltaRMatcher
~CandOneToManyDeltaRMatcher() override
Definition:
CandOneToManyDeltaRMatcher.cc:71
helper
Definition:
helper.py:1
electronAnalyzer_cfi.DeltaR
DeltaR
Definition:
electronAnalyzer_cfi.py:33
SiStripOfflineCRack_cfg.p2
p2
Definition:
SiStripOfflineCRack_cfg.py:140
muonTagProbeFilters_cff.matched
matched
Definition:
muonTagProbeFilters_cff.py:62
MessageLogger.h
LeafCandidate.h
funct::false
false
Definition:
Factorize.h:29
edm::StreamID
Definition:
StreamID.h:30
Event.h
CandOneToManyDeltaRMatcher::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition:
CandOneToManyDeltaRMatcher.cc:73
edm::Handle
Definition:
AssociativeIterator.h:50
EventSetup.h
reco::Candidate
Definition:
Candidate.h:27
std
Definition:
JetResolutionObject.h:76
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:540
reco::helper::SortBySecond
Definition:
CandOneToManyDeltaRMatcher.cc:58
findQualityFiles.v
v
Definition:
findQualityFiles.py:179
reco::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
CandOneToManyDeltaRMatcher.cc:59
edm::EDGetTokenT
Definition:
EDGetToken.h:37
HltBtagPostValidation_cff.c
c
Definition:
HltBtagPostValidation_cff.py:31
ParameterSetfwd.h
CandOneToManyDeltaRMatcher::sourceToken_
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
Definition:
CandOneToManyDeltaRMatcher.cc:27
ParameterSet.h
LaserDQM_cfg.p1
p1
Definition:
LaserDQM_cfg.py:42
CandOneToManyDeltaRMatcher::printdebug_
bool printdebug_
Definition:
CandOneToManyDeltaRMatcher.cc:29
edm::second
U second(std::pair< T, U > const &p)
Definition:
ParameterSet.cc:222
Candidate.h
CandOneToManyDeltaRMatcher::CandOneToManyDeltaRMatcher
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
Definition:
CandOneToManyDeltaRMatcher.cc:64
CandOneToManyDeltaRMatcher::matchedToken_
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
Definition:
CandOneToManyDeltaRMatcher.cc:28
edm::OwnVector
Definition:
OwnVector.h:24
EDMException.h
reco::helper::MatchPair
pair< size_t, double > MatchPair
Definition:
CandOneToManyDeltaRMatcher.cc:56
visualization-live-secondInstance_cfg.m
m
Definition:
visualization-live-secondInstance_cfg.py:80
ESHandle.h
VectorUtil
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
edm::EventSetup
Definition:
EventSetup.h:56
edm::global::EDProducer
Definition:
EDProducer.h:32
CandMatchMapMany.h
looper.cfg
cfg
Definition:
looper.py:296
electrons_cff.bool
bool
Definition:
electrons_cff.py:315
TrackRefitter_38T_cff.src
src
Definition:
TrackRefitter_38T_cff.py:24
CandOneToManyDeltaRMatcher
Definition:
CandOneToManyDeltaRMatcher.cc:19
reco::CandidateRef
edm::Ref< CandidateCollection > CandidateRef
persistent reference to an object in a collection of Candidate objects
Definition:
CandidateFwd.h:29
EDProducer.h
dqmdumpme.first
first
Definition:
dqmdumpme.py:55
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:46
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::InputTag
Definition:
InputTag.h:15
edm::OwnVector::const_iterator
Definition:
OwnVector.h:41
InputTag.h
edm::AssociationMap::ref_type
Tag::ref_type ref_type
Holds the RefProd or RefToBaseProd of 1 or 2 collections.
Definition:
AssociationMap.h:65
edm::ParameterSet
Definition:
ParameterSet.h:48
CandidateFwd.h
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
edm::Event
Definition:
Event.h:73
reco::CandidateRefProd
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition:
CandidateFwd.h:37
ModuleDef.h
MakerMacros.h
source
static std::string const source
Definition:
EdmProvDump.cc:49
eostools.move
def move(src, dest)
Definition:
eostools.py:511
Handle.h
Generated for CMSSW Reference Manual by
1.8.14