Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
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/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::EDProducer
{
20
public
:
21
CandOneToManyDeltaRMatcher
(
const
edm::ParameterSet
& );
22
~CandOneToManyDeltaRMatcher
();
23
private
:
24
void
produce
(
edm::Event
&,
const
edm::EventSetup
& )
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
(
Event
& evt,
const
EventSetup
& es ) {
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_ptr<CandMatchMapMany> matchMap(
new
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
( 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
reco::CandMatchMapMany
edm::AssociationMap< edm::OneToManyWithQuality< reco::CandidateCollection, reco::CandidateCollection, double > > CandMatchMapMany
Definition:
CandMatchMapMany.h:19
MessageLogger.h
looper.cfg
tuple cfg
Definition:
looper.py:293
LeafCandidate.h
HLT_25ns10e33_v2_cff.DeltaR
tuple DeltaR
Definition:
HLT_25ns10e33_v2_cff.py:897
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:462
reco::Candidate::et
virtual double et() const =0
transverse energy
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:17
Event.h
MakerMacros.h
edm::Handle
Definition:
AssociativeIterator.h:47
EventSetup.h
reco::Candidate
Definition:
Candidate.h:28
reco::helper::SortBySecond
Definition:
CandOneToManyDeltaRMatcher.cc:58
findQualityFiles.v
v
Definition:
findQualityFiles.py:177
Handle.h
dt_dqm_sourceclient_common_cff.reco
tuple reco
Definition:
dt_dqm_sourceclient_common_cff.py:107
EnergyCorrector.c
tuple c
Definition:
EnergyCorrector.py:43
edm::EDGetTokenT< reco::CandidateCollection >
ParameterSetfwd.h
edm::EDProducer
Definition:
EDProducer.h:35
CandOneToManyDeltaRMatcher::sourceToken_
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
Definition:
CandOneToManyDeltaRMatcher.cc:26
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
visualization-live-secondInstance_cfg.m
tuple m
Definition:
visualization-live-secondInstance_cfg.py:46
CandOneToManyDeltaRMatcher::matchedToken_
edm::EDGetTokenT< reco::CandidateCollection > matchedToken_
Definition:
CandOneToManyDeltaRMatcher.cc:27
edm::OwnVector< Candidate >
EDMException.h
edm::Event::put
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition:
Event.h:121
reco::helper::MatchPair
pair< size_t, double > MatchPair
Definition:
CandOneToManyDeltaRMatcher.cc:56
ESHandle.h
edm::EventSetup
Definition:
EventSetup.h:45
alcazmumu_cfi.src
tuple src
Definition:
alcazmumu_cfi.py:30
CandMatchMapMany.h
p2
double p2[4]
Definition:
TauolaWrapper.h:90
edm::helpers::KeyVal
Definition:
AssociationMapHelpers.h:21
EDProducer.h
CandOneToManyDeltaRMatcher
Definition:
CandOneToManyDeltaRMatcher.cc:19
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
CandOneToManyDeltaRMatcher::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
CandOneToManyDeltaRMatcher.cc:76
reco::modules::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
Matcher.h:66
p1
double p1[4]
Definition:
TauolaWrapper.h:89
edm::InputTag
Definition:
InputTag.h:15
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:36
gather_cfg.cout
tuple cout
Definition:
gather_cfg.py:145
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
edm::false
volatile std::atomic< bool > shutdown_flag false
Definition:
UnixSignalHandlers.cc:22
edm::Event
Definition:
Event.h:65
reco::CandidateRefProd
edm::RefProd< CandidateCollection > CandidateRefProd
reference to a collection of Candidate objects
Definition:
CandidateFwd.h:37
ModuleDef.h
source
static std::string const source
Definition:
EdmProvDump.cc:43
plotBeamSpotDB.first
first
Definition:
plotBeamSpotDB.py:379
reco::Candidate::phi
virtual double phi() const =0
momentum azimuthal angle
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
Generated for CMSSW Reference Manual by
1.8.5