CommonTools
CandUtils
interface
CandMatcherNew.h
Go to the documentation of this file.
1
#ifndef CandUtils_CandMatcherNew_h
2
#define CandUtils_CandMatcherNew_h
3
/* class CandMatcher
4
*
5
* \author Luca Lista, INFN
6
*
7
*/
8
#include "
DataFormats/Candidate/interface/Candidate.h
"
9
#include "
DataFormats/Common/interface/Association.h
"
10
#include "
FWCore/Utilities/interface/EDMException.h
"
11
#include <algorithm>
12
#include <iterator>
13
#include <set>
14
15
namespace
reco
{
16
namespace
utilsNew {
17
18
template
<
typename
C>
19
class
CandMatcher
{
20
public
:
22
typedef
edm::Association<C>
map_type
;
24
typedef
typename
edm::Association<C>::reference_type
reference_type
;
25
typedef
std::vector<const map_type *>
map_vector
;
27
explicit
CandMatcher
(
const
map_vector
&maps);
29
explicit
CandMatcher
(
const
map_type
&
map
);
31
virtual
~CandMatcher
();
33
reference_type
operator[]
(
const
reco::Candidate
&)
const
;
35
typename
map_type::refprod_type
ref
()
const
{
return
map_
.
ref
(); }
36
37
protected
:
39
map_type
map_
;
40
41
private
:
42
};
43
44
template
<
typename
C>
45
CandMatcher<C>::CandMatcher
(
const
typename
CandMatcher<C>::map_vector
&maps) : map_() {
46
for
(
typename
map_vector::const_iterator
i
= maps.begin();
i
!= maps.end(); ++
i
)
47
map_
+= **
i
;
48
}
49
50
template
<
typename
C>
51
CandMatcher<C>::CandMatcher
(
const
typename
CandMatcher<C>::map_type
&
map
) : map_(
map
) {}
52
53
template
<
typename
C>
54
CandMatcher<C>::~CandMatcher
() {}
55
56
template
<
typename
C>
57
typename
CandMatcher<C>::reference_type
CandMatcher<C>::operator[]
(
const
reco::Candidate
&
c
)
const
{
58
using namespace
reco
;
59
using namespace
std
;
60
if
(
c
.hasMasterClone()) {
61
const
CandidateBaseRef
&
master
=
c
.masterClone();
62
return
master
->numberOfDaughters() == 0 ? map_[
master
] : (*this)[*
master
];
63
}
64
size_t
nDau =
c
.numberOfDaughters();
65
if
(nDau == 0)
66
return
reference_type
();
67
set<size_t> momIdx,
common
,
tmp
;
68
for
(
size_t
i
= 0;
i
< nDau; ++
i
) {
69
const
Candidate
&
d
= *
c
.daughter(
i
);
70
reference_type
m
= (*this)[
d
];
71
if
(
m
.isNull())
72
return
reference_type
();
73
momIdx.clear();
74
while
(
m
->numberOfMothers() == 1) {
75
m
=
m
->motherRef();
76
momIdx.insert(
m
.key());
77
}
78
if
(momIdx.empty())
79
return
reference_type
();
80
if
(
common
.empty())
81
common
= momIdx;
82
else
{
83
tmp
.clear();
84
set_intersection(
common
.begin(),
common
.end(), momIdx.begin(), momIdx.end(), inserter(
tmp
,
tmp
.begin()));
85
swap
(
common
,
tmp
);
86
}
87
if
(
common
.empty())
88
return
reference_type
();
89
}
90
size_t
idx
= *max_element(
common
.begin(),
common
.end());
91
return
reference_type
(map_.ref(),
idx
);
92
}
93
94
}
// namespace utilsNew
95
}
// namespace reco
96
97
#endif
edm::RefProd
Definition:
EDProductfwd.h:25
mps_fire.i
i
Definition:
mps_fire.py:428
reco::utilsNew::CandMatcher::map_
map_type map_
match map at leaf level
Definition:
CandMatcherNew.h:39
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:45
Association.h
createJobs.tmp
tmp
align.sh
Definition:
createJobs.py:716
reco::utilsNew::CandMatcher::operator[]
reference_type operator[](const reco::Candidate &) const
get match from transient reference
Definition:
CandMatcherNew.h:57
edm::Ref
Definition:
AssociativeIterator.h:58
reco::utilsNew::CandMatcher::ref
map_type::refprod_type ref() const
reference to matched collection
Definition:
CandMatcherNew.h:35
reco::utilsNew::CandMatcher::~CandMatcher
virtual ~CandMatcher()
destructor
Definition:
CandMatcherNew.h:54
heavyIonCSV_trainingSettings.idx
idx
Definition:
heavyIonCSV_trainingSettings.py:5
EDMException.h
reco::utilsNew::CandMatcher
Definition:
CandMatcherNew.h:19
reco::utilsNew::CandMatcher::map_vector
std::vector< const map_type * > map_vector
Definition:
CandMatcherNew.h:25
visualization-live-secondInstance_cfg.m
m
Definition:
visualization-live-secondInstance_cfg.py:72
reco::utilsNew::CandMatcher::map_type
edm::Association< C > map_type
map type
Definition:
CandMatcherNew.h:22
edm::AssociationMap
Definition:
AssociationMap.h:48
reco::utilsNew::CandMatcher::CandMatcher
CandMatcher(const map_vector &maps)
constructor
edm::Association::ref
refprod_type ref() const
Definition:
Association.h:67
edm::Association
Definition:
Association.h:18
HltBtagPostValidation_cff.c
c
Definition:
HltBtagPostValidation_cff.py:31
reco::Candidate
Definition:
Candidate.h:27
std
Definition:
JetResolutionObject.h:76
reco::utilsNew::CandMatcher::reference_type
edm::Association< C >::reference_type reference_type
ref type
Definition:
CandMatcherNew.h:24
edm::RefToBase< Candidate >
reco::swap
void swap(reco::ClusterRemovalInfo &cri1, reco::ClusterRemovalInfo &cri2)
Definition:
ClusterRemovalInfo.cc:12
ztail.d
d
Definition:
ztail.py:151
Candidate.h
genParticles_cff.map
map
Definition:
genParticles_cff.py:11
volumeBasedMagneticField_160812_cfi.master
master
Definition:
volumeBasedMagneticField_160812_cfi.py:60
trackingPlots.common
common
Definition:
trackingPlots.py:206
common
Definition:
common.py:1
Generated for CMSSW Reference Manual by
1.8.16