Main Page
Namespaces
Classes
Package Documentation
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
private
:
26
edm::EDGetTokenT<CandidateView>
srcToken_
;
27
std::vector<edm::EDGetTokenT<reco::GenParticleMatch> >
matchMapTokens_
;
28
std::vector<int>
pdgId_
;
29
void
produce
(
edm::Event
& ,
const
edm::EventSetup
&)
override
;
30
};
31
32
MCTruthCompositeMatcher::MCTruthCompositeMatcher
(
const
edm::ParameterSet
&
cfg
) :
33
srcToken_
(
consumes
<
CandidateView
>(cfg.getParameter<
edm
::InputTag>(
"src"
))),
34
matchMapTokens_
(
edm
::
vector_transform
(cfg.
template
getParameter<
std
::vector<
edm
::InputTag> >(
"matchMaps"
), [this](
edm
::InputTag const &
tag
){
return
consumes<reco::GenParticleMatch>(
tag
);} ) ),
35
pdgId_
(
cfg
.getParameter<std::vector<int> >(
"matchPDGId"
)) {
36
produces<reco::GenParticleMatch>();
37
}
38
39
MCTruthCompositeMatcher::~MCTruthCompositeMatcher
() {
40
}
41
42
void
MCTruthCompositeMatcher::produce
(
edm::Event
& evt ,
const
edm::EventSetup
& ) {
43
using namespace
edm
;
44
using namespace
std
;
45
Handle<CandidateView>
cands
;
46
evt.
getByToken
(
srcToken_
, cands);
47
size_t
nMaps =
matchMapTokens_
.size();
48
std::vector<const GenParticleMatch *> maps;
49
maps.reserve( nMaps );
50
for
(
size_t
i
= 0;
i
!= nMaps; ++
i
) {
51
Handle<reco::GenParticleMatch>
matchMap;
52
evt.
getByToken
(
matchMapTokens_
[
i
], matchMap);
53
maps.push_back(& * matchMap);
54
}
55
utilsNew::CandMatcher<GenParticleCollection>
match
(maps);
56
auto
matchMap = std::make_unique<GenParticleMatch>(match.
ref
());
57
int
size
= cands->size();
58
vector<int>::const_iterator
begin
=
pdgId_
.begin(),
end
=
pdgId_
.end();
59
if
(size != 0) {
60
GenParticleMatch::Filler
filler
(*matchMap);
61
vector<int> indices(size);
62
for
(
int
i
= 0;
i
!=
size
; ++
i
) {
63
const
Candidate
&
cand
= (* cands)[
i
];
64
GenParticleRef
mc
= match[cand];
65
if
(mc.
isNull
()) {
66
indices[
i
] = -1;
67
}
else
{
68
bool
found
=
true
;
69
if
(begin!=
end
) found =
find
(begin,
end
,
std::abs
(mc->pdgId())) !=
end
;
70
indices[
i
] = found ?
int
(mc.
key
()) : -1;
71
}
72
}
73
CandidateBaseRefProd
ref(
edm::makeRefToBaseProdFrom
(cands->refAt(0), evt));
74
filler.
insert
(ref, indices.begin(), indices.end());
75
filler.
fill
();
76
}
77
evt.
put
(
std::move
(matchMap));
78
}
79
80
}
81
}
82
83
#include "
DataFormats/Candidate/interface/Candidate.h
"
84
#include "
FWCore/Framework/interface/MakerMacros.h
"
85
86
namespace
reco
{
87
namespace
modulesNew {
88
89
typedef
MCTruthCompositeMatcher
MCTruthCompositeMatcherNew
;
90
91
DEFINE_FWK_MODULE
( MCTruthCompositeMatcherNew );
92
93
}
94
}
95
findQualityFiles.size
size
Write out results.
Definition:
findQualityFiles.py:442
CaloTowersParam_cfi.mc
mc
Definition:
CaloTowersParam_cfi.py:8
edm::helper::Filler::fill
void fill()
Definition:
ValueMap.h:63
makeRefToBaseProdFrom.h
reco::modulesNew::MCTruthCompositeMatcher::srcToken_
edm::EDGetTokenT< CandidateView > srcToken_
Definition:
MCTruthCompositeMatcherNew.cc:26
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:137
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition:
GlobalPosition_Frontier_DevDB_cff.py:11
mps_fire.i
i
Definition:
mps_fire.py:277
Association.h
reco::modulesNew::MCTruthCompositeMatcher::matchMapTokens_
std::vector< edm::EDGetTokenT< reco::GenParticleMatch > > matchMapTokens_
Definition:
MCTruthCompositeMatcherNew.cc:27
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:579
edm::Ref< GenParticleCollection >
GenParticle.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:17
Event.h
MakerMacros.h
edm::Handle
Definition:
AssociativeIterator.h:48
reco::Candidate
Definition:
Candidate.h:28
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition:
ValueMap.h:53
std
Definition:
JetResolutionObject.h:80
reco::utilsNew::CandMatcher::ref
map_type::refprod_type ref() const
reference to matched collection
Definition:
CandMatcherNew.h:35
edm::Ref::key
key_type key() const
Accessor for product key.
Definition:
Ref.h:265
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:20
edm::EDGetTokenT< CandidateView >
runEdmFileComparison.found
found
Definition:
runEdmFileComparison.py:165
edm::EDProducer
Definition:
EDProducer.h:35
edm::Association::Filler
Definition:
Association.h:77
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition:
EDConsumerBase.h:105
ParameterSet.h
Candidate.h
edm::View
Definition:
CaloClusterFwd.h:14
createfilelist.int
int
Definition:
createfilelist.py:10
edm::RefToBaseProd< Candidate >
reco::utilsNew::CandMatcher
Definition:
CandMatcherNew.h:19
reco::modulesNew::MCTruthCompositeMatcher::MCTruthCompositeMatcher
MCTruthCompositeMatcher(const edm::ParameterSet &)
Definition:
MCTruthCompositeMatcherNew.cc:32
funct::abs
Abs< T >::type abs(const T &t)
Definition:
Abs.h:22
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition:
svgfig.py:520
edm::EventSetup
Definition:
EventSetup.h:51
reco::modulesNew::MCTruthCompositeMatcher::~MCTruthCompositeMatcher
~MCTruthCompositeMatcher() override
Definition:
MCTruthCompositeMatcherNew.cc:39
end
#define end
Definition:
vmac.h:39
objects.autophobj.filler
filler
Definition:
autophobj.py:25
looper.cfg
cfg
Definition:
looper.py:295
transform.h
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition:
Ref.h:250
reco::modulesNew::MCTruthCompositeMatcher::pdgId_
std::vector< int > pdgId_
Definition:
MCTruthCompositeMatcherNew.cc:28
EDProducer.h
CandMatcherNew.h
reco::modulesNew::MCTruthCompositeMatcher::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
MCTruthCompositeMatcherNew.cc:42
reco::modulesNew::MCTruthCompositeMatcherNew
MCTruthCompositeMatcher MCTruthCompositeMatcherNew
Definition:
MCTruthCompositeMatcherNew.cc:89
edm::makeRefToBaseProdFrom
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
Definition:
makeRefToBaseProdFrom.h:34
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:43
begin
#define begin
Definition:
vmac.h:32
edm
HLT enums.
Definition:
AlignableModifier.h:17
egammaForCoreTracking_cff.cands
cands
Definition:
egammaForCoreTracking_cff.py:39
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:36
cand
Definition:
decayParser.h:34
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
edm::Event
Definition:
Event.h:70
eostools.move
def move(src, dest)
Definition:
eostools.py:511
Handle.h
reco::modulesNew::MCTruthCompositeMatcher
Definition:
MCTruthCompositeMatcherNew.cc:21
Generated for CMSSW Reference Manual by
1.8.11