src
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/global/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/ParameterSet/interface/ParameterSetDescription.h
"
14
#include "
FWCore/ParameterSet/interface/ConfigurationDescriptions.h
"
15
#include "
FWCore/Utilities/interface/transform.h
"
16
#include "
FWCore/Framework/interface/Event.h
"
17
#include "
FWCore/Framework/interface/makeRefToBaseProdFrom.h
"
18
#include "
DataFormats/Common/interface/Handle.h
"
19
20
namespace
reco
{
21
namespace
modulesNew {
22
23
class
MCTruthCompositeMatcher
:
public
edm::global::EDProducer
<> {
24
public
:
25
explicit
MCTruthCompositeMatcher
(
const
edm::ParameterSet
&);
26
27
static
void
fillDescriptions
(
edm::ConfigurationDescriptions
&descriptions);
28
29
private
:
30
edm::EDGetTokenT<CandidateView>
srcToken_
;
31
std::vector<edm::EDGetTokenT<reco::GenParticleMatch>>
matchMapTokens_
;
32
std::vector<int>
pdgId_
;
33
void
produce
(
edm::StreamID
,
edm::Event
&,
const
edm::EventSetup
&)
const override
;
34
};
35
36
MCTruthCompositeMatcher::MCTruthCompositeMatcher
(
const
edm::ParameterSet
&
cfg
)
37
: srcToken_(consumes<
CandidateView
>(
cfg
.getParameter<
edm
::
InputTag
>(
"src"
))),
38
matchMapTokens_(
edm
::
vector_transform
(
39
cfg
.
template
getParameter<
std
::
vector
<
edm
::
InputTag
>>(
"matchMaps"
),
40
[this](
edm
::
InputTag
const
&
tag
) {
return
consumes<reco::GenParticleMatch>(
tag
); })),
41
pdgId_(
cfg
.getParameter<std::vector<int>>(
"matchPDGId"
)) {
42
produces<reco::GenParticleMatch>();
43
}
44
45
void
MCTruthCompositeMatcher::fillDescriptions
(
edm::ConfigurationDescriptions
&descriptions) {
46
edm::ParameterSetDescription
desc
;
47
desc
.add<
edm::InputTag
>(
"src"
);
48
desc
.add<std::vector<edm::InputTag>>(
"matchMaps"
);
49
desc
.add<std::vector<int>>(
"matchPDGId"
);
50
51
descriptions.
addDefault
(
desc
);
52
}
53
54
void
MCTruthCompositeMatcher::produce
(
edm::StreamID
,
edm::Event
&evt,
const
edm::EventSetup
&)
const
{
55
using namespace
edm
;
56
using namespace
std
;
57
Handle<CandidateView>
cands
;
58
evt.
getByToken
(
srcToken_
,
cands
);
59
size_t
nMaps =
matchMapTokens_
.size();
60
std::vector<const GenParticleMatch *> maps;
61
maps.reserve(nMaps);
62
for
(
size_t
i
= 0;
i
!= nMaps; ++
i
) {
63
Handle<reco::GenParticleMatch>
matchMap;
64
evt.
getByToken
(
matchMapTokens_
[
i
], matchMap);
65
maps.push_back(&*matchMap);
66
}
67
utilsNew::CandMatcher<GenParticleCollection>
match
(maps);
68
auto
matchMap = std::make_unique<GenParticleMatch>(
match
.ref());
69
int
size
=
cands
->size();
70
vector<int>::const_iterator begin =
pdgId_
.begin(),
end
=
pdgId_
.end();
71
if
(
size
!= 0) {
72
GenParticleMatch::Filler
filler
(*matchMap);
73
vector<int>
indices
(
size
);
74
for
(
int
i
= 0;
i
!=
size
; ++
i
) {
75
const
Candidate
&
cand
= (*cands)[
i
];
76
GenParticleRef
mc
=
match
[
cand
];
77
if
(
mc
.isNull()) {
78
indices
[
i
] = -1;
79
}
else
{
80
bool
found
=
true
;
81
if
(begin !=
end
)
82
found
=
find
(begin,
end
,
std::abs
(
mc
->pdgId())) !=
end
;
83
indices
[
i
] =
found
?
int
(
mc
.key()) : -1;
84
}
85
}
86
CandidateBaseRefProd
ref(
edm::makeRefToBaseProdFrom
(
cands
->refAt(0), evt));
87
filler
.insert(ref,
indices
.begin(),
indices
.end());
88
filler
.fill();
89
}
90
evt.
put
(
std::move
(matchMap));
91
}
92
93
}
// namespace modulesNew
94
}
// namespace reco
95
96
#include "
DataFormats/Candidate/interface/Candidate.h
"
97
#include "
FWCore/Framework/interface/MakerMacros.h
"
98
99
namespace
reco
{
100
namespace
modulesNew {
101
102
typedef
MCTruthCompositeMatcher
MCTruthCompositeMatcherNew
;
103
104
DEFINE_FWK_MODULE
(
MCTruthCompositeMatcherNew
);
105
106
}
// namespace modulesNew
107
}
// namespace reco
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:443
CaloTowersParam_cfi.mc
mc
Definition:
CaloTowersParam_cfi.py:8
makeRefToBaseProdFrom.h
EDProducer.h
reco::modulesNew::MCTruthCompositeMatcher::srcToken_
edm::EDGetTokenT< CandidateView > srcToken_
Definition:
MCTruthCompositeMatcherNew.cc:30
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
mps_fire.i
i
Definition:
mps_fire.py:428
Association.h
reco::modulesNew::MCTruthCompositeMatcher::matchMapTokens_
std::vector< edm::EDGetTokenT< reco::GenParticleMatch > > matchMapTokens_
Definition:
MCTruthCompositeMatcherNew.cc:31
reco::modulesNew::MCTruthCompositeMatcher::MCTruthCompositeMatcher
MCTruthCompositeMatcher(const edm::ParameterSet &)
Definition:
MCTruthCompositeMatcherNew.cc:36
runTheMatrix.const
const
Definition:
runTheMatrix.py:338
HLT_2022v12_cff.cands
cands
Definition:
HLT_2022v12_cff.py:11954
edm::Ref< GenParticleCollection >
GenParticle.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
edm::StreamID
Definition:
StreamID.h:30
Event.h
HLT_2022v12_cff.InputTag
InputTag
Definition:
HLT_2022v12_cff.py:65221
MakerMacros.h
edm::Handle
Definition:
AssociativeIterator.h:50
reco::Candidate
Definition:
Candidate.h:27
dqmdumpme.indices
indices
Definition:
dqmdumpme.py:50
std
Definition:
JetResolutionObject.h:76
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:539
reco::modulesNew::MCTruthCompositeMatcher::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition:
MCTruthCompositeMatcherNew.cc:54
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
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition:
FindCaloHit.cc:19
edm::EDGetTokenT< CandidateView >
edm::Association::Filler
Definition:
Association.h:78
edm::ParameterSetDescription
Definition:
ParameterSetDescription.h:52
ParameterSet.h
Candidate.h
edm::View
Definition:
CaloClusterFwd.h:14
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition:
ConfigurationDescriptions.cc:99
createfilelist.int
int
Definition:
createfilelist.py:10
ParameterSetDescription.h
edm::RefToBaseProd
Definition:
RefToBase.h:65
makeGlobalPositionRcd_cfg.tag
tag
Definition:
makeGlobalPositionRcd_cfg.py:6
reco::utilsNew::CandMatcher
Definition:
CandMatcherNew.h:19
submitPVResolutionJobs.desc
string desc
Definition:
submitPVResolutionJobs.py:251
funct::abs
Abs< T >::type abs(const T &t)
Definition:
Abs.h:22
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition:
svgfig.py:521
edm::EventSetup
Definition:
EventSetup.h:59
edm::global::EDProducer
Definition:
EDProducer.h:32
looper.cfg
cfg
Definition:
looper.py:296
transform.h
reco::modulesNew::MCTruthCompositeMatcher::pdgId_
std::vector< int > pdgId_
Definition:
MCTruthCompositeMatcherNew.cc:32
mps_fire.end
end
Definition:
mps_fire.py:242
CandMatcherNew.h
reco::modulesNew::MCTruthCompositeMatcherNew
MCTruthCompositeMatcher MCTruthCompositeMatcherNew
Definition:
MCTruthCompositeMatcherNew.cc:102
edm::makeRefToBaseProdFrom
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
Definition:
makeRefToBaseProdFrom.h:34
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:46
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::InputTag
Definition:
InputTag.h:15
trackerHitRTTI::vector
Definition:
trackerHitRTTI.h:21
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:47
cand
Definition:
decayParser.h:32
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
ConfigurationDescriptions.h
edm::Event
Definition:
Event.h:73
newFWLiteAna.found
found
Definition:
newFWLiteAna.py:118
trigObjTnPSource_cfi.filler
filler
Definition:
trigObjTnPSource_cfi.py:21
eostools.move
def move(src, dest)
Definition:
eostools.py:511
edm::ConfigurationDescriptions
Definition:
ConfigurationDescriptions.h:28
reco::modulesNew::MCTruthCompositeMatcher::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition:
MCTruthCompositeMatcherNew.cc:45
Handle.h
reco::modulesNew::MCTruthCompositeMatcher
Definition:
MCTruthCompositeMatcherNew.cc:23
Generated for CMSSW Reference Manual by
1.8.14