Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
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/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
);
first
auto first
Definition:
CAHitNtupletGeneratorKernelsImpl.h:127
reco::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
CandOneToManyDeltaRMatcher.cc:59
CandMatchMap.h
EDProducer.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
c
const edm::EventSetup & c
Definition:
SiStripLAProfileBooker.cc:66
looper.cfg
tuple cfg
Definition:
looper.py:296
CandOneToManyDeltaRMatcher::~CandOneToManyDeltaRMatcher
~CandOneToManyDeltaRMatcher() override
Definition:
CandOneToManyDeltaRMatcher.cc:71
MessageLogger.h
LeafCandidate.h
fireworks::p2
const TString p2
Definition:
fwPaths.cc:13
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:539
reco::Candidate::et
virtual double et() const =0
transverse energy
funct::false
false
Definition:
Factorize.h:29
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
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
MakerMacros.h
edm::Handle
Definition:
AssociativeIterator.h:50
EventSetup.h
reco::Candidate
Definition:
Candidate.h:27
reco::helper::SortBySecond
Definition:
CandOneToManyDeltaRMatcher.cc:58
findQualityFiles.v
v
Definition:
findQualityFiles.py:179
dt_dqm_sourceclient_common_cff.reco
tuple reco
Definition:
dt_dqm_sourceclient_common_cff.py:111
edm::EDGetTokenT< reco::CandidateCollection >
ParameterSetfwd.h
CandOneToManyDeltaRMatcher::sourceToken_
edm::EDGetTokenT< reco::CandidateCollection > sourceToken_
Definition:
CandOneToManyDeltaRMatcher.cc:27
ParameterSet.h
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
visualization-live-secondInstance_cfg.m
tuple m
Definition:
visualization-live-secondInstance_cfg.py:79
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
eostools.move
def move
Definition:
eostools.py:511
fireworks::p1
const TString p1
Definition:
fwPaths.cc:12
ESHandle.h
edm::EventSetup
Definition:
EventSetup.h:59
alcazmumu_cfi.src
tuple src
Definition:
alcazmumu_cfi.py:30
edm::global::EDProducer
Definition:
EDProducer.h:32
CandMatchMapMany.h
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
reco::modules::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
Matcher.h:63
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:63
edm::ParameterSet
Definition:
ParameterSet.h:47
gather_cfg.cout
tuple cout
Definition:
gather_cfg.py:144
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
HLT_FULL_cff.DeltaR
tuple DeltaR
Definition:
HLT_FULL_cff.py:321
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
source
static std::string const source
Definition:
EdmProvDump.cc:46
reco::Candidate::phi
virtual double phi() const =0
momentum azimuthal angle
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
Handle.h
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
Generated for CMSSW Reference Manual by
1.8.5