PhysicsTools
HepMCCandAlgos
plugins
MCTruthCompositeMatcherNew.cc
Go to the documentation of this file.
1
/* \class MCTruthCompositeMatcher
2
*
3
* \author Luca Lista, INFN
4
*
5
*/
6
7
#include "
FWCore/Framework/interface/EDProducer.h
"
8
#include "
FWCore/Utilities/interface/InputTag.h
"
9
#include "
CommonTools/CandUtils/interface/CandMatcherNew.h
"
10
#include "
DataFormats/HepMCCandidate/interface/GenParticle.h
"
11
#include "
DataFormats/Common/interface/Association.h
"
12
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
13
#include "
FWCore/Utilities/interface/transform.h
"
14
#include "
FWCore/Framework/interface/Event.h
"
15
#include "
FWCore/Framework/interface/makeRefToBaseProdFrom.h
"
16
#include "
DataFormats/Common/interface/Handle.h
"
17
18
namespace
reco
{
19
namespace
modulesNew {
20
21
class
MCTruthCompositeMatcher
:
public
edm::EDProducer
{
22
public
:
23
explicit
MCTruthCompositeMatcher
(
const
edm::ParameterSet
&);
24
~MCTruthCompositeMatcher
()
override
;
25
26
private
:
27
edm::EDGetTokenT<CandidateView>
srcToken_
;
28
std::vector<edm::EDGetTokenT<reco::GenParticleMatch> >
matchMapTokens_
;
29
std::vector<int>
pdgId_
;
30
void
produce
(
edm::Event
&,
const
edm::EventSetup
&)
override
;
31
};
32
33
MCTruthCompositeMatcher::MCTruthCompositeMatcher
(
const
edm::ParameterSet
&
cfg
)
34
: srcToken_(consumes<
CandidateView
>(
cfg
.getParameter<
edm
::
InputTag
>(
"src"
))),
35
matchMapTokens_(
edm
::
vector_transform
(
36
cfg
.
template
getParameter<
std
::
vector
<
edm
::
InputTag
> >(
"matchMaps"
),
37
[this](
edm
::
InputTag
const
&
tag
) {
return
consumes<reco::GenParticleMatch>(
tag
); })),
38
pdgId_(
cfg
.getParameter<std::vector<int> >(
"matchPDGId"
)) {
39
produces<reco::GenParticleMatch>();
40
}
41
42
MCTruthCompositeMatcher::~MCTruthCompositeMatcher
() {}
43
44
void
MCTruthCompositeMatcher::produce
(
edm::Event
&evt,
const
edm::EventSetup
&) {
45
using namespace
edm
;
46
using namespace
std
;
47
Handle<CandidateView>
cands
;
48
evt.
getByToken
(
srcToken_
,
cands
);
49
size_t
nMaps =
matchMapTokens_
.size();
50
std::vector<const GenParticleMatch *> maps;
51
maps.reserve(nMaps);
52
for
(
size_t
i
= 0;
i
!= nMaps; ++
i
) {
53
Handle<reco::GenParticleMatch>
matchMap;
54
evt.
getByToken
(
matchMapTokens_
[
i
], matchMap);
55
maps.push_back(&*matchMap);
56
}
57
utilsNew::CandMatcher<GenParticleCollection>
match
(maps);
58
auto
matchMap = std::make_unique<GenParticleMatch>(
match
.ref());
59
int
size
=
cands
->size();
60
vector<int>::const_iterator begin =
pdgId_
.begin(),
end
=
pdgId_
.end();
61
if
(
size
!= 0) {
62
GenParticleMatch::Filler
filler
(*matchMap);
63
vector<int>
indices
(
size
);
64
for
(
int
i
= 0;
i
!=
size
; ++
i
) {
65
const
Candidate
&
cand
= (*cands)[
i
];
66
GenParticleRef
mc
=
match
[
cand
];
67
if
(
mc
.isNull()) {
68
indices
[
i
] = -1;
69
}
else
{
70
bool
found
=
true
;
71
if
(begin !=
end
)
72
found
=
find
(begin,
end
,
std::abs
(
mc
->pdgId())) !=
end
;
73
indices
[
i
] =
found
?
int
(
mc
.key()) : -1;
74
}
75
}
76
CandidateBaseRefProd
ref(
edm::makeRefToBaseProdFrom
(
cands
->refAt(0), evt));
77
filler
.insert(ref,
indices
.begin(),
indices
.end());
78
filler
.fill();
79
}
80
evt.
put
(
std::move
(matchMap));
81
}
82
83
}
// namespace modulesNew
84
}
// namespace reco
85
86
#include "
DataFormats/Candidate/interface/Candidate.h
"
87
#include "
FWCore/Framework/interface/MakerMacros.h
"
88
89
namespace
reco
{
90
namespace
modulesNew {
91
92
typedef
MCTruthCompositeMatcher
MCTruthCompositeMatcherNew
;
93
94
DEFINE_FWK_MODULE
(
MCTruthCompositeMatcherNew
);
95
96
}
// namespace modulesNew
97
}
// namespace reco
bTagCombinedSVVariables_cff.indices
indices
Definition:
bTagCombinedSVVariables_cff.py:67
reco::modulesNew::MCTruthCompositeMatcher::~MCTruthCompositeMatcher
~MCTruthCompositeMatcher() override
Definition:
MCTruthCompositeMatcherNew.cc:42
Handle.h
mps_fire.i
i
Definition:
mps_fire.py:428
edm::Association::Filler
Definition:
Association.h:78
EDProducer.h
CaloTowersParam_cfi.mc
mc
Definition:
CaloTowersParam_cfi.py:8
edm::EDGetTokenT< CandidateView >
edm
HLT enums.
Definition:
AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition:
HLT_FULL_cff.py:89287
reco::modulesNew::MCTruthCompositeMatcher::matchMapTokens_
std::vector< edm::EDGetTokenT< reco::GenParticleMatch > > matchMapTokens_
Definition:
MCTruthCompositeMatcherNew.cc:28
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:45
Association.h
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition:
FindCaloHit.cc:19
watchdog.const
const
Definition:
watchdog.py:83
newFWLiteAna.found
found
Definition:
newFWLiteAna.py:118
edm::Handle
Definition:
AssociativeIterator.h:50
edm::Ref< GenParticleCollection >
GenParticle.h
reco::modulesNew::MCTruthCompositeMatcher::pdgId_
std::vector< int > pdgId_
Definition:
MCTruthCompositeMatcherNew.cc:29
reco::utilsNew::CandMatcher
Definition:
CandMatcherNew.h:19
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition:
GlobalPosition_Frontier_DevDB_cff.py:11
mps_fire.end
end
Definition:
mps_fire.py:242
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:531
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition:
transform.h:11
edm::View
Definition:
CaloClusterFwd.h:14
HLT_FULL_cff.cands
cands
Definition:
HLT_FULL_cff.py:15142
edm::ParameterSet
Definition:
ParameterSet.h:47
Event.h
edm::makeRefToBaseProdFrom
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
Definition:
makeRefToBaseProdFrom.h:34
reco::modulesNew::MCTruthCompositeMatcherNew
MCTruthCompositeMatcher MCTruthCompositeMatcherNew
Definition:
MCTruthCompositeMatcherNew.cc:92
trigObjTnPSource_cfi.filler
filler
Definition:
trigObjTnPSource_cfi.py:21
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
cand
Definition:
decayParser.h:32
CandMatcherNew.h
createfilelist.int
int
Definition:
createfilelist.py:10
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
trackerHitRTTI::vector
Definition:
trackerHitRTTI.h:21
edm::EventSetup
Definition:
EventSetup.h:57
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition:
svgfig.py:521
makeRefToBaseProdFrom.h
InputTag.h
looper.cfg
cfg
Definition:
looper.py:297
reco::Candidate
Definition:
Candidate.h:27
reco::modulesNew::MCTruthCompositeMatcher::srcToken_
edm::EDGetTokenT< CandidateView > srcToken_
Definition:
MCTruthCompositeMatcherNew.cc:27
eostools.move
def move(src, dest)
Definition:
eostools.py:511
std
Definition:
JetResolutionObject.h:76
reco::modulesNew::MCTruthCompositeMatcher
Definition:
MCTruthCompositeMatcherNew.cc:21
transform.h
reco::modulesNew::MCTruthCompositeMatcher::MCTruthCompositeMatcher
MCTruthCompositeMatcher(const edm::ParameterSet &)
Definition:
MCTruthCompositeMatcherNew.cc:33
edm::EDProducer
Definition:
EDProducer.h:35
Candidate.h
funct::abs
Abs< T >::type abs(const T &t)
Definition:
Abs.h:22
ParameterSet.h
edm::Event
Definition:
Event.h:73
reco::modulesNew::MCTruthCompositeMatcher::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
MCTruthCompositeMatcherNew.cc:44
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:443
edm::RefToBaseProd
Definition:
RefToBase.h:65
Generated for CMSSW Reference Manual by
1.8.16