Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
CommonTools
UtilAlgos
interface
Matcher.h
Go to the documentation of this file.
1
#ifndef UtilAlgos_Matcher_h
2
#define UtilAlgos_Matcher_h
3
/* \class Matcher
4
*
5
* \author Luca Lista, INFN
6
*
7
*/
8
#include "
FWCore/Framework/interface/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 "
FWCore/Framework/interface/Event.h
"
13
#include "
DataFormats/Common/interface/Handle.h
"
14
#include "
DataFormats/Common/interface/AssociationMap.h
"
15
#include "
DataFormats/Common/interface/OneToOne.h
"
16
#include "
DataFormats/Common/interface/getRef.h
"
17
18
namespace
reco
{
19
namespace
modules {
20
template
<
typename
C1,
typename
C2,
typename
M = edm::AssociationMap<edm::OneToOne<C1, C2> > >
21
class
MatcherBase
:
public
edm::EDProducer
{
22
public
:
23
MatcherBase
(
const
edm::ParameterSet
& );
24
~MatcherBase
();
25
26
protected
:
27
typedef
typename
C1::value_type
T1
;
28
typedef
typename
C2::value_type
T2
;
29
typedef
M
MatchMap
;
30
31
private
:
32
void
produce
(
edm::Event
&,
const
edm::EventSetup
&)
override
;
33
edm::InputTag
src_
;
34
edm::InputTag
matched_
;
35
double
distMin_
;
36
virtual
double
matchDistance
(
const
T1
&,
const
T2
& )
const
= 0;
37
virtual
bool
select
(
const
T1
&,
const
T2
& )
const
= 0;
38
};
39
40
template
<
typename
C1,
typename
C2,
41
typename
S,
typename
D
=
DeltaR<typename C1::value_type, typename C2::value_type>
,
42
typename
M =
edm::AssociationMap<edm::OneToOne<C1, C2>
> >
43
class
Matcher
:
public
MatcherBase
<C1, C2, M> {
44
public
:
45
Matcher
(
const
edm::ParameterSet
& cfg ) :
46
MatcherBase
<C1, C2, M>( cfg ),
47
select_
(
reco
::modules::
make
<S>( cfg ) ),
48
distance_
(
reco
::modules::
make
<
D
>( cfg ) ) { }
49
~Matcher
() { }
50
private
:
51
typedef
typename
MatcherBase<C1, C2, M>::T1
T1
;
52
typedef
typename
MatcherBase<C1, C2, M>::T2
T2
;
53
typedef
typename
MatcherBase<C1, C2, M>::MatchMap
MatchMap
;
54
55
double
matchDistance
(
const
T1
&
c1
,
const
T2
& c2 )
const
{
56
return
distance_
( c1, c2 );
57
}
58
bool
select
(
const
T1
&
c1
,
const
T2
& c2 )
const
{
59
return
select_
( c1, c2 );
60
}
61
S
select_
;
62
D
distance_
;
63
};
64
65
namespace
helper {
66
typedef
std::pair<size_t, double>
MatchPair
;
67
68
struct
SortBySecond
{
69
bool
operator()
(
const
MatchPair
&
p1
,
const
MatchPair
&
p2
)
const
{
70
return
p1.second < p2.second;
71
}
72
};
73
}
74
75
template
<
typename
C1,
typename
C2,
typename
M>
76
MatcherBase<C1, C2, M>::MatcherBase
(
const
edm::ParameterSet
& cfg ) :
77
src_( cfg.
template
getParameter<edm::InputTag>(
"src"
) ),
78
matched_( cfg.
template
getParameter<edm::InputTag>(
"matched"
) ),
79
distMin_( cfg.
template
getParameter<double>(
"distMin"
) ) {
80
produces<MatchMap>();
81
}
82
83
template
<
typename
C1,
typename
C2,
typename
M>
84
MatcherBase<C1, C2, M>::~MatcherBase
() { }
85
86
template
<
typename
C1,
typename
C2,
typename
M>
87
void
MatcherBase<C1, C2, M>::produce
(
edm::Event
& evt,
const
edm::EventSetup
& ) {
88
using namespace
edm;
89
using namespace
std;
90
Handle<C2>
matched;
91
evt.
getByLabel
( matched_, matched );
92
Handle<C1>
cands;
93
evt.
getByLabel
( src_, cands );
94
typedef
typename
MatchMap::ref_type ref_type;
95
typedef
typename
ref_type::key_type key_ref_type;
96
typedef
typename
ref_type::value_type
value_ref_type;
97
auto_ptr<MatchMap> matchMap(
new
MatchMap
( ref_type( key_ref_type( cands ),
98
value_ref_type( matched ) ) ) );
99
for
(
size_t
c
= 0;
c
!= cands->size(); ++
c
) {
100
const
T1
& cand = (*cands)[
c
];
101
vector<helper::MatchPair>
v
;
102
for
(
size_t
m
= 0;
m
!= matched->size(); ++
m
) {
103
const
T2
&
match
= ( * matched )[
m
];
104
if
(
select
( cand, match ) ) {
105
double
dist = matchDistance( cand, match );
106
if
( dist < distMin_ ) v.push_back( make_pair(
m
, dist ) );
107
}
108
}
109
if
( v.size() > 0 ) {
110
size_t
mMin = min_element( v.begin(), v.end(),
helper::SortBySecond
() )->
first
;
111
typedef
typename
MatchMap::key_type key_type;
112
typedef
typename
MatchMap::data_type data_type;
113
matchMap->insert(
edm::getRef
( cands,
c
),
edm::getRef
( matched, mMin ) );
114
}
115
}
116
evt.
put
( matchMap );
117
}
118
119
}
120
}
121
122
#endif
edm::getRef
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition:
getRef.h:28
reco::modules::MatcherBase::select
virtual bool select(const T1 &, const T2 &) const =0
AssociationMap.h
DeltaR
Definition:
deltaR.h:79
reco::modules::helper::SortBySecond
Definition:
Matcher.h:68
reco::modules::Matcher::matchDistance
double matchDistance(const T1 &c1, const T2 &c2) const
Definition:
Matcher.h:55
Event.h
alignmentValidation.c1
tuple c1
do drawing
Definition:
alignmentValidation.py:1023
DeltaR.h
reco::modules::Matcher::Matcher
Matcher(const edm::ParameterSet &cfg)
Definition:
Matcher.h:45
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition:
ParameterAdapter.h:17
reco::modules::MatcherBase::~MatcherBase
~MatcherBase()
Definition:
Matcher.h:84
findQualityFiles.v
v
Definition:
findQualityFiles.py:177
OneToOne.h
Handle.h
edm::Handle
Definition:
AssociativeIterator.h:48
reco::modules::Matcher
Definition:
Matcher.h:43
reco::p2
Float p2
Definition:
deltaR.h:21
reco::modules::MatcherBase::matched_
edm::InputTag matched_
Definition:
Matcher.h:34
edm::EDProducer
Definition:
EDProducer.h:22
reco::modules::MatcherBase::distMin_
double distMin_
Definition:
Matcher.h:35
ParameterSet.h
reco::modules::Matcher::select
bool select(const T1 &c1, const T2 &c2) const
Definition:
Matcher.h:58
reco::modules::Matcher::T2
MatcherBase< C1, C2, M >::T2 T2
Definition:
Matcher.h:52
reco::modules::MatcherBase
Definition:
Matcher.h:21
edm::Event::put
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition:
Event.h:94
L1Trigger_dataformats.reco
dictionary reco
Definition:
L1Trigger_dataformats.py:9
reco::p1
Float p1
Definition:
deltaR.h:20
reco::modules::MatcherBase::matchDistance
virtual double matchDistance(const T1 &, const T2 &) const =0
edm::AssociationMap
Definition:
AssociationMap.h:21
edm::EventSetup
Definition:
EventSetup.h:44
first
bool first
Definition:
L1TdeRCT.cc:94
cond::ecalcond::value_type
Container::value_type value_type
Definition:
EcalChannelStatusPyWrapper.cc:33
edm::Event::getByLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition:
Event.h:361
EDProducer.h
m
int m
Definition:
DTDataIntegrityTask.cc:33
reco::modules::Matcher::distance_
D distance_
Definition:
Matcher.h:62
reco::modules::MatcherBase::T1
C1::value_type T1
Definition:
Matcher.h:27
reco::modules::Matcher::T1
MatcherBase< C1, C2, M >::T1 T1
Definition:
Matcher.h:51
trackerHits.c
tuple c
Definition:
trackerHits.py:26
reco::modules::MatcherBase::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
Matcher.h:87
reco::modules::MatcherBase::T2
C2::value_type T2
Definition:
Matcher.h:28
reco::modules::Matcher::~Matcher
~Matcher()
Definition:
Matcher.h:49
reco::modules::MatcherBase::MatchMap
M MatchMap
Definition:
Matcher.h:29
reco::modules::MatcherBase::src_
edm::InputTag src_
Definition:
Matcher.h:33
benchmark_cfg.select
tuple select
Definition:
benchmark_cfg.py:25
reco::modules::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
Matcher.h:66
edm::InputTag
Definition:
InputTag.h:17
InputTag.h
reco::modules::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
Matcher.h:69
edm::ParameterSet
Definition:
ParameterSet.h:35
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:6
edm::Event
Definition:
Event.h:56
reco::modules::Matcher::select_
S select_
Definition:
Matcher.h:61
reco::modules::Matcher::MatchMap
MatcherBase< C1, C2, M >::MatchMap MatchMap
Definition:
Matcher.h:53
getRef.h
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition:
Factorize.h:150
svgfig.template
def template
Definition:
svgfig.py:520
reco::modules::MatcherBase::MatcherBase
MatcherBase(const edm::ParameterSet &)
Definition:
Matcher.h:76
Generated for CMSSW Reference Manual by
1.8.5