Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
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 <iostream>
4
5
class
DimuonMCMatcher
:
public
edm::EDProducer
{
6
public
:
7
DimuonMCMatcher
(
const
edm::ParameterSet
& cfg);
8
virtual
void
produce
(
edm::Event
&,
const
edm::EventSetup
&);
9
private
:
10
edm::InputTag
src_
;
11
};
12
13
#include "
DataFormats/Candidate/interface/Candidate.h
"
14
#include "
DataFormats/Candidate/interface/CandidateFwd.h
"
15
#include "
DataFormats/HepMCCandidate/interface/GenParticle.h
"
16
#include "
DataFormats/HepMCCandidate/interface/GenParticleFwd.h
"
17
#include "
FWCore/Framework/interface/Event.h
"
18
#include "
DataFormats/Common/interface/Handle.h
"
19
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
20
#include "
DataFormats/PatCandidates/interface/Muon.h
"
21
#include "
DataFormats/PatCandidates/interface/GenericParticle.h
"
22
using namespace
std;
23
using namespace
reco
;
24
using namespace
edm;
25
26
DimuonMCMatcher::DimuonMCMatcher
(
const
edm::ParameterSet
& cfg) :
27
src_(cfg.getParameter<
InputTag
>(
"src"
)) {
28
produces<vector<GenParticleRef> >();
29
}
30
31
void
DimuonMCMatcher::produce
(
edm::Event
& evt,
const
edm::EventSetup
&) {
32
Handle<CandidateView>
src
;
33
evt.
getByLabel
(
src_
, src);
34
auto_ptr<vector<GenParticleRef> > matched(
new
vector<GenParticleRef>);
35
matched->reserve(src->size());
36
int
j
=0;
37
for
(
CandidateView::const_iterator
i
= src->begin();
i
!= src->end(); ++
i
) {
38
j++;
39
const
Candidate
* dau1 =
i
->daughter(0);
40
const
Candidate
* dau2 =
i
->daughter(1);
41
if
(dau1 == 0|| dau2 == 0)
42
throw
Exception
(
errors::InvalidReference
) <<
43
"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 != 0) {
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 == 0)
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 != 0) {
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 == 0)
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
(matched);
89
}
90
91
92
#include "
FWCore/Framework/interface/MakerMacros.h
"
93
94
DEFINE_FWK_MODULE
(
DimuonMCMatcher
);
DimuonMCMatcher::src_
edm::InputTag src_
Definition:
DimuonMCMatcher.cc:10
i
int i
Definition:
DBlmapReader.cc:9
GenericParticle.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition:
View.h:81
DimuonMCMatcher::produce
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition:
DimuonMCMatcher.cc:31
pat::PATObject::genParticleRef
reco::GenParticleRef genParticleRef(size_t idx=0) const
Definition:
PATObject.h:215
GenParticle.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:17
Event.h
alignmentValidation.c1
tuple c1
do drawing
Definition:
alignmentValidation.py:1023
reco::GenParticleRef
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
Definition:
GenParticleFwd.h:14
MakerMacros.h
reco::Candidate
Definition:
Candidate.h:32
Handle.h
edm::Handle
Definition:
AssociativeIterator.h:48
DimuonMCMatcher::DimuonMCMatcher
DimuonMCMatcher(const edm::ParameterSet &cfg)
Definition:
DimuonMCMatcher.cc:26
edm::EDProducer
Definition:
EDProducer.h:22
ParameterSet.h
Candidate.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition:
Ref.h:250
pat::GenericParticle
Analysis-level Generic Particle class (e.g. for hadron or muon not fully reconstructed) ...
Definition:
GenericParticle.h:42
edm::Event::put
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition:
Event.h:94
L1Trigger_dataformats.reco
dictionary reco
Definition:
L1Trigger_dataformats.py:9
j
int j
Definition:
DBlmapReader.cc:9
GenParticleFwd.h
edm::EventSetup
Definition:
EventSetup.h:44
alcazmumu_cfi.src
tuple src
Definition:
alcazmumu_cfi.py:30
edm::Event::getByLabel
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition:
Event.h:361
edm::errors::InvalidReference
Definition:
EDMException.h:43
DimuonMCMatcher
Definition:
DimuonMCMatcher.cc:5
gen::k
int k[5][pyjets_maxn]
Definition:
Cascade2Hadronizer.cc:81
EDProducer.h
edm::hlt::Exception
error
Definition:
HLTenums.h:24
Muon.h
edm::InputTag
Definition:
InputTag.h:17
InputTag.h
edm::ParameterSet
Definition:
ParameterSet.h:35
CandidateFwd.h
edm::Event
Definition:
Event.h:56
pat::Muon
Analysis-level muon class.
Definition:
Muon.h:51
edm::RefToBase::get
value_type const * get() const
Definition:
RefToBase.h:212
edm::Ref< GenParticleCollection >
reco::Candidate::masterClone
virtual const CandidateBaseRef & masterClone() const =0
Generated for CMSSW Reference Manual by
1.8.5