ElectroWeakAnalysis
ZMuMu
plugins
DimuonMCMatcher.cc
Go to the documentation of this file.
1
#include "
FWCore/Framework/interface/EDProducer.h
"
2
#include "
FWCore/Utilities/interface/InputTag.h
"
3
#include "
DataFormats/Candidate/interface/Candidate.h
"
4
#include "
DataFormats/Candidate/interface/CandidateFwd.h
"
5
#include <iostream>
6
7
class
DimuonMCMatcher
:
public
edm::EDProducer
{
8
public
:
9
DimuonMCMatcher
(
const
edm::ParameterSet
&
cfg
);
10
void
produce
(
edm::Event
&,
const
edm::EventSetup
&)
override
;
11
12
private
:
13
edm::EDGetTokenT<reco::CandidateView>
srcToken_
;
14
};
15
16
#include "
DataFormats/HepMCCandidate/interface/GenParticle.h
"
17
#include "
DataFormats/HepMCCandidate/interface/GenParticleFwd.h
"
18
#include "
FWCore/Framework/interface/Event.h
"
19
#include "
DataFormats/Common/interface/Handle.h
"
20
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
21
#include "
DataFormats/PatCandidates/interface/Muon.h
"
22
#include "
DataFormats/PatCandidates/interface/GenericParticle.h
"
23
using namespace
std
;
24
using namespace
reco
;
25
using namespace
edm
;
26
27
DimuonMCMatcher::DimuonMCMatcher
(
const
edm::ParameterSet
&
cfg
)
28
: srcToken_(consumes<
CandidateView
>(
cfg
.getParameter<
InputTag
>(
"src"
))) {
29
produces<vector<GenParticleRef> >();
30
}
31
32
void
DimuonMCMatcher::produce
(
edm::Event
& evt,
const
edm::EventSetup
&) {
33
Handle<CandidateView>
src
;
34
evt.
getByToken
(
srcToken_
,
src
);
35
unique_ptr<vector<GenParticleRef> >
matched
(
new
vector<GenParticleRef>);
36
matched
->reserve(
src
->size());
37
int
j
= 0;
38
for
(
CandidateView::const_iterator
i
=
src
->begin();
i
!=
src
->end(); ++
i
) {
39
j
++;
40
const
Candidate
* dau1 =
i
->daughter(0);
41
const
Candidate
* dau2 =
i
->daughter(1);
42
if
(dau1 ==
nullptr
|| dau2 ==
nullptr
)
43
throw
Exception
(
errors::InvalidReference
) <<
"one of the two daughter does not exist\n"
;
44
const
Candidate
*
c1
= dau1->
masterClone
().
get
();
45
GenParticleRef
mc1;
46
const
pat::Muon
* mu1 = dynamic_cast<const pat::Muon*>(
c1
);
47
if
(mu1 !=
nullptr
) {
48
mc1 = mu1->
genParticleRef
();
49
// if (mc1.isNonnull()) cout << "DimuonMCMatcher> genParticleRef1 " << mc1->pdgId() << endl;
50
}
else
{
51
const
pat::GenericParticle
* gp1 = dynamic_cast<const pat::GenericParticle*>(
c1
);
52
if
(gp1 ==
nullptr
)
53
throw
Exception
(
errors::InvalidReference
)
54
<<
"first of two daughter is neither a pat::Muon not pat::GenericParticle\n"
;
55
mc1 = gp1->
genParticleRef
();
56
}
57
const
Candidate
* c2 = dau2->
masterClone
().
get
();
58
GenParticleRef
mc2;
59
const
pat::Muon
* mu2 = dynamic_cast<const pat::Muon*>(c2);
60
if
(mu2 !=
nullptr
) {
61
mc2 = mu2->
genParticleRef
();
62
// if (mc2.isNonnull()) cout << "DimuonMCMatcher> genParticleRef2 " << mc2->pdgId() << endl;
63
}
else
{
64
const
pat::GenericParticle
* gp2 = dynamic_cast<const pat::GenericParticle*>(c2);
65
if
(gp2 ==
nullptr
)
66
throw
Exception
(
errors::InvalidReference
)
67
<<
"first of two daughter is neither a pat::Muon not pat::GenericParticle\n"
;
68
mc2 = gp2->
genParticleRef
();
69
}
70
GenParticleRef
dimuonMatch;
71
// cout << "DimuonMatcher> mc1 " << mc1.isNonnull() << " mc2 " << mc2.isNonnull() << endl;
72
if
(mc1.
isNonnull
() && mc2.
isNonnull
()) {
73
int
k
= 0;
74
do
{
75
k
++;
76
mc1 = mc1->numberOfMothers() > 0 ? mc1->motherRef() :
GenParticleRef
();
77
mc2 = mc2->numberOfMothers() > 0 ? mc2->motherRef() :
GenParticleRef
();
78
// cout << "DimuonMCMatcher> do loop: " << k << " id1 " << mc1->pdgId() << " id2 " << mc2->pdgId() << endl;
79
}
while
(mc1 != mc2 && mc1.
isNonnull
() && mc2.
isNonnull
());
80
if
(mc1.
isNonnull
() && mc2.
isNonnull
() && mc1->pdgId() == 23) {
81
dimuonMatch = mc1;
82
}
83
}
84
// cout << "DimuonMatcher> dimuonMatch " << dimuonMatch.isNonnull() << endl;
85
matched
->push_back(dimuonMatch);
86
}
87
88
evt.
put
(
std::move
(
matched
));
89
}
90
91
#include "
FWCore/Framework/interface/MakerMacros.h
"
92
93
DEFINE_FWK_MODULE
(
DimuonMCMatcher
);
muonTagProbeFilters_cff.matched
matched
Definition:
muonTagProbeFilters_cff.py:62
Handle.h
mps_fire.i
i
Definition:
mps_fire.py:428
EDProducer.h
edm::errors::InvalidReference
Definition:
EDMException.h:39
edm::EDGetTokenT
Definition:
EDGetToken.h:33
edm
HLT enums.
Definition:
AlignableModifier.h:19
Muon.h
GenericParticle.h
GenParticleRef
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
Definition:
MultiTrackValidator.cc:43
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:45
pat::Muon
Analysis-level muon class.
Definition:
Muon.h:51
edm::Handle
Definition:
AssociativeIterator.h:50
edm::Ref< GenParticleCollection >
GenParticle.h
CandidateFwd.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
GenParticleFwd.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:531
dqmdumpme.k
k
Definition:
dqmdumpme.py:60
edm::RefToBase::get
value_type const * get() const
Definition:
RefToBase.h:209
edm::View
Definition:
CaloClusterFwd.h:14
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed)
Definition:
GenericParticle.h:38
edm::ParameterSet
Definition:
ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition:
TrackRefitter_38T_cff.py:24
Event.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition:
Ref.h:238
DimuonMCMatcher::DimuonMCMatcher
DimuonMCMatcher(const edm::ParameterSet &cfg)
Definition:
DimuonMCMatcher.cc:27
alignmentValidation.c1
c1
do drawing
Definition:
alignmentValidation.py:1025
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition:
Event.h:133
DimuonMCMatcher::srcToken_
edm::EDGetTokenT< reco::CandidateView > srcToken_
Definition:
DimuonMCMatcher.cc:13
edm::EventSetup
Definition:
EventSetup.h:57
DimuonMCMatcher
Definition:
DimuonMCMatcher.cc:7
InputTag.h
looper.cfg
cfg
Definition:
looper.py:297
reco::Candidate
Definition:
Candidate.h:27
eostools.move
def move(src, dest)
Definition:
eostools.py:511
std
Definition:
JetResolutionObject.h:76
Exception
Definition:
hltDiff.cc:246
edm::EDProducer
Definition:
EDProducer.h:35
reco::Candidate::masterClone
virtual const CandidateBaseRef & masterClone() const =0
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition:
View.h:86
Candidate.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition:
dqmiolumiharvest.py:66
edm::Event
Definition:
Event.h:73
edm::InputTag
Definition:
InputTag.h:15
pat::PATObject::genParticleRef
reco::GenParticleRef genParticleRef(size_t idx=0) const
Definition:
PATObject.h:267
DimuonMCMatcher::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
DimuonMCMatcher.cc:32
Generated for CMSSW Reference Manual by
1.8.16