Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
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 "
PhysicsTools/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 "
DataFormats/Common/interface/Handle.h
"
16
17
namespace
reco
{
18
namespace
modulesNew {
19
20
class
MCTruthCompositeMatcher
:
public
edm::EDProducer
{
21
public
:
22
explicit
MCTruthCompositeMatcher
(
const
edm::ParameterSet
& );
23
~MCTruthCompositeMatcher
();
24
private
:
25
edm::EDGetTokenT<CandidateView>
srcToken_
;
26
std::vector<edm::EDGetTokenT<reco::GenParticleMatch> >
matchMapTokens_
;
27
std::vector<int>
pdgId_
;
28
void
produce
(
edm::Event
& ,
const
edm::EventSetup
&)
override
;
29
};
30
31
MCTruthCompositeMatcher::MCTruthCompositeMatcher
(
const
edm::ParameterSet
& cfg ) :
32
srcToken_(consumes<
CandidateView
>(cfg.getParameter<edm::InputTag>(
"src"
))),
33
matchMapTokens_( edm::
vector_transform
(cfg.
template
getParameter<std::vector<edm::InputTag> >(
"matchMaps"
), [this](edm::InputTag
const
&
tag
){
return
consumes<reco::GenParticleMatch>(
tag
);} ) ),
34
pdgId_
(cfg.getParameter<std::vector<int> >(
"matchPDGId"
)) {
35
produces<reco::GenParticleMatch>();
36
}
37
38
MCTruthCompositeMatcher::~MCTruthCompositeMatcher
() {
39
}
40
41
void
MCTruthCompositeMatcher::produce
(
edm::Event
& evt ,
const
edm::EventSetup
& ) {
42
using namespace
edm;
43
using namespace
std;
44
Handle<CandidateView>
cands;
45
evt.
getByToken
(
srcToken_
, cands);
46
size_t
nMaps =
matchMapTokens_
.size();
47
std::vector<const GenParticleMatch *> maps;
48
maps.reserve( nMaps );
49
for
(
size_t
i
= 0;
i
!= nMaps; ++
i
) {
50
Handle<reco::GenParticleMatch>
matchMap;
51
evt.
getByToken
(
matchMapTokens_
[
i
], matchMap);
52
maps.push_back(& * matchMap);
53
}
54
utilsNew::CandMatcher<GenParticleCollection>
match
(maps);
55
auto_ptr<GenParticleMatch> matchMap(
new
GenParticleMatch
(match.
ref
()));
56
int
size
= cands->size();
57
vector<int>::const_iterator
begin
=
pdgId_
.begin(),
end
=
pdgId_
.end();
58
if
(
size
!= 0) {
59
GenParticleMatch::Filler
filler(*matchMap);
60
vector<int> indices(
size
);
61
for
(
int
i
= 0;
i
!=
size
; ++
i
) {
62
const
Candidate
& cand = (* cands)[
i
];
63
GenParticleRef
mc = match[cand];
64
if
(mc.
isNull
()) {
65
indices[
i
] = -1;
66
}
else
{
67
bool
found
=
true
;
68
if
(
begin
!=
end
) found =
find
(
begin
,
end
,
std::abs
(mc->pdgId())) !=
end
;
69
indices[
i
] = found ? int(mc.
key
()) : -1;
70
}
71
}
72
CandidateBaseRefProd
ref(cands->refAt(0));
73
filler.
insert
(ref, indices.begin(), indices.end());
74
filler.
fill
();
75
}
76
evt.
put
(matchMap);
77
}
78
79
}
80
}
81
82
#include "
DataFormats/Candidate/interface/Candidate.h
"
83
#include "
FWCore/Framework/interface/MakerMacros.h
"
84
85
namespace
reco
{
86
namespace
modulesNew {
87
88
typedef
MCTruthCompositeMatcher
MCTruthCompositeMatcherNew
;
89
90
DEFINE_FWK_MODULE
(
MCTruthCompositeMatcherNew
);
91
92
}
93
}
94
edm::helper::Filler::fill
void fill()
Definition:
ValueMap.h:61
i
int i
Definition:
DBlmapReader.cc:9
reco::modulesNew::MCTruthCompositeMatcher::srcToken_
edm::EDGetTokenT< CandidateView > srcToken_
Definition:
MCTruthCompositeMatcherNew.cc:25
reco::modulesNew::MCTruthCompositeMatcher::~MCTruthCompositeMatcher
~MCTruthCompositeMatcher()
Definition:
MCTruthCompositeMatcherNew.cc:38
Association.h
reco::modulesNew::MCTruthCompositeMatcher::matchMapTokens_
std::vector< edm::EDGetTokenT< reco::GenParticleMatch > > matchMapTokens_
Definition:
MCTruthCompositeMatcherNew.cc:26
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:434
GenParticle.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:17
Event.h
MakerMacros.h
reco::Candidate
Definition:
Candidate.h:32
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition:
ValueMap.h:52
edm::View
Definition:
AssociativeIterator.h:46
reco::utilsNew::CandMatcher::ref
map_type::refprod_type ref() const
reference to matched collection
Definition:
CandMatcherNew.h:35
Handle.h
edm::Handle
Definition:
AssociativeIterator.h:47
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
dt_dqm_sourceclient_common_cff.reco
tuple reco
Definition:
dt_dqm_sourceclient_common_cff.py:107
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition:
FindCaloHit.cc:7
edm::EDGetTokenT
Definition:
EDGetToken.h:32
edm::EDProducer
Definition:
EDProducer.h:33
edm::Association::Filler
Definition:
Association.h:77
ParameterSet.h
Candidate.h
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition:
Ref.h:247
GlobalPosition_Frontier_DevDB_cff.tag
tuple tag
Definition:
GlobalPosition_Frontier_DevDB_cff.py:11
edm::RefToBaseProd< Candidate >
edm::Event::put
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition:
Event.h:116
reco::utilsNew::CandMatcher
Definition:
CandMatcherNew.h:19
reco::modulesNew::pdgId_
pdgId_(cfg.getParameter< std::vector< int > >("matchPDGId"))
Definition:
MCTruthCompositeMatcherNew.cc:34
reco::modulesNew::MCTruthCompositeMatcher::MCTruthCompositeMatcher
MCTruthCompositeMatcher(const edm::ParameterSet &)
Definition:
MCTruthCompositeMatcherNew.cc:31
funct::abs
Abs< T >::type abs(const T &t)
Definition:
Abs.h:22
edm::EventSetup
Definition:
EventSetup.h:44
end
#define end
Definition:
vmac.h:37
transform.h
CandMatcherNew.h
reco::modulesNew::MCTruthCompositeMatcher::pdgId_
std::vector< int > pdgId_
Definition:
MCTruthCompositeMatcherNew.cc:27
EDProducer.h
edm::Ref::key
key_type key() const
Accessor for product key.
Definition:
Ref.h:266
reco::modulesNew::MCTruthCompositeMatcher::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
MCTruthCompositeMatcherNew.cc:41
reco::modulesNew::MCTruthCompositeMatcherNew
MCTruthCompositeMatcher MCTruthCompositeMatcherNew
Definition:
MCTruthCompositeMatcherNew.cc:88
compareJSON.const
string const
Definition:
compareJSON.py:14
begin
#define begin
Definition:
vmac.h:30
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:35
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:6
edm::Event
Definition:
Event.h:62
newFWLiteAna.found
found
Definition:
newFWLiteAna.py:118
findQualityFiles.size
tuple size
Write out results.
Definition:
findQualityFiles.py:442
edm::Ref< GenParticleCollection >
svgfig.template
def template
Definition:
svgfig.py:520
reco::modulesNew::MCTruthCompositeMatcher
Definition:
MCTruthCompositeMatcherNew.cc:20
reco::GenParticleMatch
edm::Association< GenParticleCollection > GenParticleMatch
vector of reference to GenParticle in the same collection
Definition:
GenParticleFwd.h:20
Generated for CMSSW Reference Manual by
1.8.5