Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
CommonTools
UtilAlgos
interface
NewMatcher.h
Go to the documentation of this file.
1
#ifndef UtilAlgos_NewMatcher_h
2
#define UtilAlgos_NewMatcher_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 "
CommonTools/UtilAlgos/interface/MasterCollectionHelper.h
"
13
#include "
FWCore/Framework/interface/Event.h
"
14
#include "
DataFormats/Common/interface/Handle.h
"
15
#include "
DataFormats/Common/interface/Association.h
"
16
#include "
DataFormats/Common/interface/getRef.h
"
17
#include "
DataFormats/Common/interface/View.h
"
18
19
namespace
reco
{
20
namespace
modulesNew {
21
22
template
<
typename
C1,
typename
C2,
23
typename
S,
typename
D
=
DeltaR<typename C1::value_type, typename C2::value_type>
>
24
class
Matcher
:
public
edm::EDProducer
{
25
public
:
26
Matcher
(
const
edm::ParameterSet
& cfg);
27
~Matcher
();
28
private
:
29
typedef
typename
C1::value_type
T1
;
30
typedef
typename
C2::value_type
T2
;
31
typedef
edm::Association<C2>
MatchMap
;
32
void
produce
(
edm::Event
&,
const
edm::EventSetup
&);
33
edm::InputTag
src_
;
34
edm::InputTag
matched_
;
35
double
distMin_
;
36
double
matchDistance
(
const
T1
&
c1
,
const
T2
& c2)
const
{
37
return
distance_
(c1, c2);
38
}
39
bool
select
(
const
T1
&
c1
,
const
T2
& c2)
const
{
40
return
select_
(c1, c2);
41
}
42
S
select_
;
43
D
distance_
;
44
};
45
46
namespace
helper {
47
typedef
std::pair<size_t, double>
MatchPair
;
48
49
struct
SortBySecond
{
50
bool
operator()
(
const
MatchPair
&
p1
,
const
MatchPair
&
p2
)
const
{
51
return
p1.second < p2.second;
52
}
53
};
54
}
55
56
template
<
typename
C1,
typename
C2,
typename
S,
typename
D>
57
Matcher<C1, C2, S, D>::Matcher
(
const
edm::ParameterSet
& cfg) :
58
src_(cfg.
template
getParameter<edm::InputTag>(
"src"
)),
59
matched_(cfg.
template
getParameter<edm::InputTag>(
"matched"
)),
60
distMin_(cfg.
template
getParameter<double>(
"distMin"
)),
61
select_(
reco
::modules::
make
<S>(cfg)),
62
distance_(
reco
::modules::
make
<
D
>(cfg)) {
63
produces<MatchMap>();
64
}
65
66
template
<
typename
C1,
typename
C2,
typename
S,
typename
D>
67
Matcher<C1, C2, S, D>::~Matcher
() { }
68
69
template
<
typename
C1,
typename
C2,
typename
S,
typename
D>
70
void
Matcher<C1, C2, S, D>::produce
(
edm::Event
& evt,
const
edm::EventSetup
&) {
71
using namespace
edm;
72
using namespace
std;
73
Handle<C2>
matched;
74
evt.
getByLabel
(matched_, matched);
75
Handle<C1>
cands;
76
evt.
getByLabel
(src_, cands);
77
auto_ptr<MatchMap> matchMap(
new
MatchMap
(matched));
78
size_t
size
= cands->size();
79
if
(
size
!= 0 ) {
80
typename
MatchMap::Filler
filler(*matchMap);
81
::helper::MasterCollection<C1>
master
(cands);
82
std::vector<int> indices(master.
size
(), -1);
83
for
(
size_t
c
= 0;
c
!=
size
; ++
c
) {
84
const
T1
& cand = (*cands)[
c
];
85
vector<helper::MatchPair>
v
;
86
for
(
size_t
m
= 0;
m
!= matched->size(); ++
m
) {
87
const
T2
&
match
= (* matched)[
m
];
88
if
(
select
(cand, match)) {
89
double
dist = matchDistance(cand, match);
90
if
(dist < distMin_) v.push_back(make_pair(
m
, dist));
91
}
92
}
93
if
(v.size() > 0) {
94
size_t
idx = master.
index
(
c
);
95
assert(idx < indices.size());
96
indices[idx] = min_element(v.begin(), v.end(),
helper::SortBySecond
())->
first
;
97
}
98
}
99
filler.
insert
(master.
get
(), indices.begin(), indices.end());
100
filler.
fill
();
101
}
102
evt.
put
(matchMap);
103
}
104
105
}
106
}
107
108
#endif
helper::MasterCollection::get
const edm::Handle< C1 > & get() const
Definition:
MasterCollectionHelper.h:27
funct::master
Master< F > master(const F &f)
Definition:
FunctClone.h:68
edm::helper::Filler::fill
void fill()
Definition:
ValueMap.h:61
MasterCollectionHelper.h
Association.h
helper::MasterCollection
Definition:
MasterCollectionHelper.h:21
DeltaR
Definition:
deltaR.h:51
Event.h
alignmentValidation.c1
tuple c1
do drawing
Definition:
alignmentValidation.py:888
DeltaR.h
reco::modulesNew::Matcher::MatchMap
edm::Association< C2 > MatchMap
Definition:
NewMatcher.h:31
reco::modulesNew::Matcher::select_
S select_
Definition:
NewMatcher.h:42
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition:
ParameterAdapter.h:17
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition:
ValueMap.h:52
reco::modulesNew::Matcher::src_
edm::InputTag src_
Definition:
NewMatcher.h:33
cond::ecalcond::value_type
Container::value_type value_type
Definition:
EcalChannelStatusPyWrapper.cc:33
reco::modulesNew::Matcher::T2
C2::value_type T2
Definition:
NewMatcher.h:30
reco::modulesNew::helper::SortBySecond::operator()
bool operator()(const MatchPair &p1, const MatchPair &p2) const
Definition:
NewMatcher.h:50
Handle.h
edm::Handle
Definition:
AssociativeIterator.h:48
edm::EDProducer
Definition:
EDProducer.h:21
edm::Association::Filler
Definition:
Association.h:77
ParameterSet.h
edm::Association
Definition:
Association.h:18
reco::modulesNew::Matcher::distMin_
double distMin_
Definition:
NewMatcher.h:35
dt_offlineAnalysis_common_cff.reco
tuple reco
Definition:
dt_offlineAnalysis_common_cff.py:54
edm::Event::put
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition:
Event.h:84
helper::MasterCollection::index
size_t index(size_t i) const
Definition:
MasterCollectionHelper.h:26
View.h
edm::EventSetup
Definition:
EventSetup.h:44
reco::modulesNew::Matcher::select
bool select(const T1 &c1, const T2 &c2) const
Definition:
NewMatcher.h:39
reco::modulesNew::Matcher::T1
C1::value_type T1
Definition:
NewMatcher.h:29
first
bool first
Definition:
L1TdeRCT.cc:79
p2
double p2[4]
Definition:
TauolaWrapper.h:90
edm::Event::getByLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition:
Event.h:359
reco::modulesNew::helper::SortBySecond
Definition:
NewMatcher.h:49
EDProducer.h
helper::MasterCollection::size
size_t size() const
Definition:
MasterCollectionHelper.h:25
m
int m
Definition:
DTDataIntegrityTask.cc:32
reco::modulesNew::Matcher::distance_
D distance_
Definition:
NewMatcher.h:43
reco::modulesNew::Matcher::matched_
edm::InputTag matched_
Definition:
NewMatcher.h:34
trackerHits.c
tuple c
Definition:
trackerHits.py:26
reco::modulesNew::Matcher::~Matcher
~Matcher()
Definition:
NewMatcher.h:67
benchmark_cfg.select
tuple select
Definition:
benchmark_cfg.py:25
p1
double p1[4]
Definition:
TauolaWrapper.h:89
edm::InputTag
Definition:
InputTag.h:12
InputTag.h
reco::modulesNew::helper::MatchPair
std::pair< size_t, double > MatchPair
Definition:
NewMatcher.h:47
edm::ParameterSet
Definition:
ParameterSet.h:31
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:6
reco::modulesNew::Matcher::matchDistance
double matchDistance(const T1 &c1, const T2 &c2) const
Definition:
NewMatcher.h:36
edm::Event
Definition:
Event.h:49
getRef.h
funct::D
DecomposeProduct< arg, typename Div::arg > D
Definition:
Factorize.h:150
findQualityFiles.size
tuple size
Write out results.
Definition:
findQualityFiles.py:322
v
mathSSE::Vec4< T > v
Definition:
newBasic3DVector.h:210
svgfig.template
def template
Definition:
svgfig.py:520
reco::modulesNew::Matcher::produce
void produce(edm::Event &, const edm::EventSetup &)
Definition:
NewMatcher.h:70
reco::modulesNew::Matcher
Definition:
NewMatcher.h:24
reco::modulesNew::Matcher::Matcher
Matcher(const edm::ParameterSet &cfg)
Definition:
NewMatcher.h:57
Generated for CMSSW Reference Manual by
1.8.5