Main Page
Namespaces
Classes
Package Documentation
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
();
23
private
:
24
void
produce
(
edm::StreamID
,
edm::Event
&,
const
edm::EventSetup
& )
const override
;
25
26
edm::EDGetTokenT<reco::CandidateCollection>
sourceToken_
;
27
edm::EDGetTokenT<reco::CandidateCollection>
matchedToken_
;
28
bool
printdebug_
;
29
};
30
31
#include "
FWCore/Framework/interface/ESHandle.h
"
32
#include "
FWCore/Framework/interface/Event.h
"
33
#include "
FWCore/Framework/interface/EventSetup.h
"
34
#include "
FWCore/Utilities/interface/InputTag.h
"
35
#include "
FWCore/Utilities/interface/EDMException.h
"
36
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
37
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
38
39
#include "
DataFormats/Common/interface/Handle.h
"
40
#include "
DataFormats/Candidate/interface/LeafCandidate.h
"
41
#include "
DataFormats/Candidate/interface/CandMatchMap.h
"
42
#include "
DataFormats/Candidate/interface/CandMatchMapMany.h
"
43
#include "
DataFormats/Candidate/interface/CandidateFwd.h
"
44
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
{
60
return
p1.second < p2.second;
61
}
62
};
63
}
64
}
65
66
CandOneToManyDeltaRMatcher::CandOneToManyDeltaRMatcher
(
const
ParameterSet
&
cfg
) :
67
sourceToken_
(
consumes
<
CandidateCollection
>( cfg.getParameter<
InputTag
>(
"src"
) ) ),
68
matchedToken_
(
consumes
<
CandidateCollection
>( cfg.getParameter<
InputTag
>(
"matched"
) ) ),
69
printdebug_
( cfg.getUntrackedParameter<
bool
>(
"printDebug"
,
false
) ) {
70
produces<CandMatchMapMany>();
71
}
72
73
CandOneToManyDeltaRMatcher::~CandOneToManyDeltaRMatcher
() {
74
}
75
76
void
CandOneToManyDeltaRMatcher::produce
(
edm::StreamID
,
Event
& evt,
const
EventSetup
& es )
const
{
77
78
Handle<CandidateCollection>
source
;
79
Handle<CandidateCollection>
matched
;
80
evt.
getByToken
(
sourceToken_
, source ) ;
81
evt.
getByToken
(
matchedToken_
, matched ) ;
82
83
if
(
printdebug_
) {
84
for
( CandidateCollection::const_iterator
c
= source->
begin
();
c
!= source->
end
(); ++
c
) {
85
cout
<<
"[CandOneToManyDeltaRMatcher] Et source "
<<
c
->et() << endl;
86
}
87
for
( CandidateCollection::const_iterator
c
= matched->
begin
();
c
!= matched->
end
(); ++
c
) {
88
cout
<<
"[CandOneToManyDeltaRMatcher] Et matched "
<<
c
->et() << endl;
89
}
90
}
91
92
93
auto
matchMap = std::make_unique<CandMatchMapMany>(
CandMatchMapMany::ref_type
(
CandidateRefProd
( source ),
94
CandidateRefProd
( matched )
95
) );
96
for
(
size_t
c
= 0;
c
!= source->
size
(); ++
c
) {
97
const
Candidate
&
src
= (*source)[
c
];
98
if
(
printdebug_
)
cout
<<
"[CandOneToManyDeltaRMatcher] source (Et,Eta,Phi) =("
<< src.
et
() <<
","
<<
99
src.
eta
() <<
","
<<
100
src.
phi
() <<
")"
<< endl;
101
vector<reco::helper::MatchPair>
v
;
102
for
(
size_t
m
= 0;
m
!= matched->
size
(); ++
m
) {
103
const
Candidate
&
match
= ( * matched )[
m
];
104
double
dist =
DeltaR
( src.
p4
() , match.
p4
() );
105
v.push_back( make_pair(
m
, dist ) );
106
}
107
if
( v.size() > 0 ) {
108
sort( v.begin(), v.end(),
reco::helper::SortBySecond
() );
109
for
(
size_t
m
= 0;
m
!= v.size(); ++
m
) {
110
if
(
printdebug_
)
cout
<<
"[CandOneToManyDeltaRMatcher] match (Et,Eta,Phi) =("
<< ( * matched )[ v[
m
].first ].et() <<
","
<<
111
( * matched )[ v[
m
].first ].eta() <<
","
<<
112
( * matched )[ v[
m
].first ].phi() <<
") DeltaR="
<<
113
v[
m
].second << endl;
114
matchMap->insert(
CandidateRef
( source,
c
), make_pair(
CandidateRef
( matched, v[
m
].
first
), v[
m
].
second
) );
115
}
116
}
117
}
118
119
evt.
put
(
std::move
(matchMap) );
120
121
}
122
123
#include "
FWCore/PluginManager/interface/ModuleDef.h
"
124
#include "
FWCore/Framework/interface/MakerMacros.h
"
125
126
DEFINE_FWK_MODULE
(
CandOneToManyDeltaRMatcher
);
reco::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
CandOneToManyDeltaRMatcher.cc:59
CandMatchMap.h
EDProducer.h
MessageLogger.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:127
helper
Definition:
helper.py:1
LeafCandidate.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:508
funct::false
false
Definition:
Factorize.h:35
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:17
edm::StreamID
Definition:
StreamID.h:30
Event.h
MakerMacros.h
EnergyCorrector.c
c
Definition:
EnergyCorrector.py:43
edm::Handle
Definition:
AssociativeIterator.h:47
EventSetup.h
edm::OwnVector::size
size_type size() const
Definition:
OwnVector.h:264
reco::Candidate
Definition:
Candidate.h:28
std
Definition:
JetResolutionObject.h:76
reco::helper::SortBySecond
Definition:
CandOneToManyDeltaRMatcher.cc:58
findQualityFiles.v
v
Definition:
findQualityFiles.py:177
edm::EDGetTokenT< reco::CandidateCollection >
ParameterSetfwd.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition:
EDConsumerBase.h:104
CandOneToManyDeltaRMatcher::sourceToken_
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
Definition:
CandOneToManyDeltaRMatcher.cc:26
edm::OwnVector::begin
iterator begin()
Definition:
OwnVector.h:244
ParameterSet.h
CandOneToManyDeltaRMatcher::printdebug_
bool printdebug_
Definition:
CandOneToManyDeltaRMatcher.cc:28
edm::second
U second(std::pair< T, U > const &p)
Definition:
ParameterSet.cc:250
Candidate.h
CandOneToManyDeltaRMatcher::CandOneToManyDeltaRMatcher
CandOneToManyDeltaRMatcher(const edm::ParameterSet &)
Definition:
CandOneToManyDeltaRMatcher.cc:66
reco::Candidate::et
virtual double et() const =0
transverse energy
CandOneToManyDeltaRMatcher::matchedToken_
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
Definition:
CandOneToManyDeltaRMatcher.cc:27
edm::OwnVector< Candidate >
EDMException.h
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
reco::helper::MatchPair
pair< size_t, double > MatchPair
Definition:
CandOneToManyDeltaRMatcher.cc:56
CandOneToManyDeltaRMatcher::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition:
CandOneToManyDeltaRMatcher.cc:76
HiRegitMuonDetachedTripletStep_cff.DeltaR
DeltaR
Definition:
HiRegitMuonDetachedTripletStep_cff.py:22
ESHandle.h
VectorUtil
edm::EventSetup
Definition:
EventSetup.h:44
edm::global::EDProducer
Definition:
EDProducer.h:32
CandMatchMapMany.h
electrons_cff.matched
matched
Definition:
electrons_cff.py:178
p2
double p2[4]
Definition:
TauolaWrapper.h:90
looper.cfg
cfg
Definition:
looper.py:293
edm::helpers::KeyVal
Definition:
AssociationMapHelpers.h:21
electrons_cff.bool
bool
Definition:
electrons_cff.py:154
TrackRefitter_38T_cff.src
src
Definition:
TrackRefitter_38T_cff.py:35
CandOneToManyDeltaRMatcher
Definition:
CandOneToManyDeltaRMatcher.cc:19
edm::OwnVector::end
iterator end()
Definition:
OwnVector.h:249
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
CandOneToManyDeltaRMatcher::~CandOneToManyDeltaRMatcher
~CandOneToManyDeltaRMatcher()
Definition:
CandOneToManyDeltaRMatcher.cc:73
reco::CandidateRef
edm::Ref< CandidateCollection > CandidateRef
persistent reference to an object in a collection of Candidate objects
Definition:
CandidateFwd.h:29
plotBeamSpotDB.first
first
Definition:
plotBeamSpotDB.py:379
funct::m
m
Definition:
Factorize.h:55
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:43
edm
HLT enums.
Definition:
AlignableModifier.h:17
p1
double p1[4]
Definition:
TauolaWrapper.h:89
edm::InputTag
Definition:
InputTag.h:15
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:36
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:145
edm::Event
Definition:
Event.h:69
reco::CandidateRefProd
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition:
CandidateFwd.h:37
ModuleDef.h
reco::Candidate::phi
virtual double phi() const =0
momentum azimuthal angle
source
static std::string const source
Definition:
EdmProvDump.cc:43
eostools.move
def move(src, dest)
Definition:
eostools.py:510
Handle.h
Generated for CMSSW Reference Manual by
1.8.11