ElectroWeakAnalysis
ZMuMu
plugins
DimuonStatistics.cc
Go to the documentation of this file.
1
#include "
FWCore/Framework/interface/EDAnalyzer.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
DimuonStatistics
:
public
edm::EDAnalyzer
{
8
public
:
9
DimuonStatistics
(
const
edm::ParameterSet
&
cfg
);
10
void
analyze
(
const
edm::Event
&,
const
edm::EventSetup
&)
override
;
11
void
endJob
()
override
;
12
13
private
:
14
edm::InputTag
src_
;
15
edm::EDGetTokenT<reco::CandidateView>
srcToken_
;
16
std::vector<unsigned int>
matched_
,
unMatched_
;
17
double
ptMin_
,
massMin_
,
massMax_
,
etaMin_
,
etaMax_
,
trkIso_
;
18
};
19
20
#include "
DataFormats/HepMCCandidate/interface/GenParticle.h
"
21
#include "
DataFormats/HepMCCandidate/interface/GenParticleFwd.h
"
22
#include "
FWCore/Framework/interface/Event.h
"
23
#include "
DataFormats/Common/interface/Handle.h
"
24
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
25
#include "
DataFormats/PatCandidates/interface/Muon.h
"
26
#include "
DataFormats/PatCandidates/interface/GenericParticle.h
"
27
using namespace
std
;
28
using namespace
reco
;
29
using namespace
edm
;
30
const
unsigned
int
maxEntries
= 10;
31
32
DimuonStatistics::DimuonStatistics
(
const
edm::ParameterSet
&
cfg
)
33
: src_(
cfg
.getParameter<
InputTag
>(
"src"
)),
34
srcToken_(consumes<
CandidateView
>(src_)),
35
matched_(
maxEntries
+ 1, 0),
36
unMatched_(
maxEntries
+ 1, 0),
37
ptMin_(
cfg
.getUntrackedParameter<double>(
"ptMin"
)),
38
massMin_(
cfg
.getUntrackedParameter<double>(
"massMin"
)),
39
massMax_(
cfg
.getUntrackedParameter<double>(
"massMax"
)),
40
etaMin_(
cfg
.getUntrackedParameter<double>(
"etaMin"
)),
41
etaMax_(
cfg
.getUntrackedParameter<double>(
"etaMax"
)),
42
trkIso_(
cfg
.getUntrackedParameter<double>(
"trkIso"
)) {}
43
44
void
DimuonStatistics::endJob
() {
45
cout
<<
src_
.
encode
() << endl;
46
cout
<<
" == Matched == "
<< endl;
47
for
(
unsigned
int
i
= 0;
i
<=
maxEntries
; ++
i
) {
48
cout
<<
i
<<
": "
<<
matched_
[
i
];
49
if
(
i
<
maxEntries
)
50
cout
<<
", "
;
51
}
52
cout
<< endl;
53
cout
<<
" == unMatched == "
<< endl;
54
for
(
unsigned
int
i
= 0;
i
<=
maxEntries
; ++
i
) {
55
cout
<<
i
<<
": "
<<
unMatched_
[
i
];
56
if
(
i
<
maxEntries
)
57
cout
<<
", "
;
58
}
59
cout
<< endl;
60
}
61
62
void
DimuonStatistics::analyze
(
const
edm::Event
& evt,
const
edm::EventSetup
&) {
63
Handle<CandidateView>
src
;
64
evt.
getByToken
(
srcToken_
,
src
);
65
double
trackIso1 = -1;
66
double
trackIso2 = -1;
67
int
j
= 0;
68
unsigned
int
matched
= 0, unMatched = 0;
69
cout
<<
">> entries in "
<<
src_
<<
": "
<<
src
->size() << endl;
70
for
(
CandidateView::const_iterator
i
=
src
->begin();
i
!=
src
->end(); ++
i
) {
71
j
++;
72
const
Candidate
* dau1 =
i
->daughter(0);
73
const
Candidate
* dau2 =
i
->daughter(1);
74
if
(dau1 ==
nullptr
|| dau2 ==
nullptr
)
75
throw
Exception
(
errors::InvalidReference
) <<
"one of the two daughter does not exist\n"
;
76
const
Candidate
*
c1
= dau1->
masterClone
().
get
();
77
GenParticleRef
mc1;
78
const
pat::Muon
* mu1 = dynamic_cast<const pat::Muon*>(
c1
);
79
if
(mu1 !=
nullptr
) {
80
mc1 = mu1->
genParticleRef
();
81
// if (mc1.isNonnull()) cout << "DimuonStatistics> genParticleRef1 " << mc1->pdgId() << endl;
82
trackIso1 = mu1->
trackIso
();
83
}
else
{
84
const
pat::GenericParticle
* gp1 = dynamic_cast<const pat::GenericParticle*>(
c1
);
85
if
(gp1 ==
nullptr
)
86
throw
Exception
(
errors::InvalidReference
)
87
<<
"first of two daughter is neither a pat::Muon not pat::GenericParticle\n"
;
88
mc1 = gp1->
genParticleRef
();
89
}
90
const
Candidate
* c2 = dau2->
masterClone
().
get
();
91
GenParticleRef
mc2;
92
const
pat::Muon
* mu2 = dynamic_cast<const pat::Muon*>(c2);
93
if
(mu2 !=
nullptr
) {
94
mc2 = mu2->
genParticleRef
();
95
// if (mc2.isNonnull()) cout << "DimuonStatistics> genParticleRef2 " << mc2->pdgId() << endl;
96
trackIso2 = mu2->
trackIso
();
97
}
else
{
98
const
pat::GenericParticle
* gp2 = dynamic_cast<const pat::GenericParticle*>(c2);
99
if
(gp2 ==
nullptr
)
100
throw
Exception
(
errors::InvalidReference
)
101
<<
"first of two daughter is neither a pat::Muon not pat::GenericParticle\n"
;
102
mc2 = gp2->
genParticleRef
();
103
}
104
GenParticleRef
dimuonMatch;
105
if
(mc1.
isNonnull
() && mc2.
isNonnull
()) {
106
cout
<<
"DimuonStatistics> mc1: "
<< mc1->pdgId() <<
", mc2: "
<< mc2->pdgId() << endl;
107
int
k
= 0;
108
do
{
109
k
++;
110
mc1 = mc1->numberOfMothers() > 0 ? mc1->motherRef() :
GenParticleRef
();
111
mc2 = mc2->numberOfMothers() > 0 ? mc2->motherRef() :
GenParticleRef
();
112
// cout << "DimuonStatistics> do loop: " << k << " id1 " << mc1->pdgId() << " id2 " << mc2->pdgId() << endl;
113
}
while
(mc1 != mc2 && mc1.
isNonnull
() && mc2.
isNonnull
());
114
if
(mc1.
isNonnull
() && mc2.
isNonnull
() && mc1->pdgId() == 23) {
115
dimuonMatch = mc1;
116
}
117
}
118
// cout << "DimuonMatcher> dimuonMatch " << dimuonMatch.isNonnull() << endl;
119
if
((fabs(dau1->
eta
()) >
etaMin_
&& fabs(dau1->
eta
()) <
etaMax_
) && dau1->
pt
() >
ptMin_
&&
120
((fabs(dau2->
eta
()) >
etaMin_
) && (fabs(dau2->
eta
()) <
etaMax_
)) && dau2->
pt
() >
ptMin_
&&
121
trackIso1 <
trkIso_
&& trackIso2 <
trkIso_
&&
i
->mass() >
massMin_
&&
i
->mass() <
massMax_
) {
122
cout
<<
"dimuon mass "
<<
i
->mass() << endl;
123
if
(dimuonMatch.
isNonnull
())
124
++
matched
;
125
else
126
++unMatched;
127
}
128
}
129
cout
<<
"matched: "
<<
matched
<<
", unmatched: "
<< unMatched << endl;
130
131
if
(
matched
>
maxEntries
)
132
matched
=
maxEntries
;
133
if
(unMatched >
maxEntries
)
134
unMatched =
maxEntries
;
135
++
matched_
[
matched
];
136
++
unMatched_
[unMatched];
137
}
138
139
#include "
FWCore/Framework/interface/MakerMacros.h
"
140
141
DEFINE_FWK_MODULE
(
DimuonStatistics
);
muonTagProbeFilters_cff.matched
matched
Definition:
muonTagProbeFilters_cff.py:62
Handle.h
mps_fire.i
i
Definition:
mps_fire.py:355
DimuonStatistics::etaMax_
double etaMax_
Definition:
DimuonStatistics.cc:17
edm::errors::InvalidReference
Definition:
EDMException.h:39
DimuonStatistics::trkIso_
double trkIso_
Definition:
DimuonStatistics.cc:17
reco::Candidate::eta
virtual double eta() const =0
momentum pseudorapidity
edm::EDGetTokenT
Definition:
EDGetToken.h:33
edm
HLT enums.
Definition:
AlignableModifier.h:19
Muon.h
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
GenericParticle.h
DimuonStatistics::endJob
void endJob() override
Definition:
DimuonStatistics.cc:44
DimuonStatistics::srcToken_
edm::EDGetTokenT< reco::CandidateView > srcToken_
Definition:
DimuonStatistics.cc:15
GenParticleRef
edm::Ref< edm::HepMCProduct, HepMC::GenParticle > GenParticleRef
Definition:
MultiTrackValidator.cc:43
reco::Candidate::pt
virtual double pt() const =0
transverse momentum
DimuonStatistics::etaMin_
double etaMin_
Definition:
DimuonStatistics.cc:17
EDAnalyzer.h
DimuonStatistics::DimuonStatistics
DimuonStatistics(const edm::ParameterSet &cfg)
Definition:
DimuonStatistics.cc:32
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 >
edm::EDAnalyzer
Definition:
EDAnalyzer.h:29
GenParticle.h
CandidateFwd.h
MakerMacros.h
DimuonStatistics::matched_
std::vector< unsigned int > matched_
Definition:
DimuonStatistics.cc:16
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
pat::Muon::trackIso
float trackIso() const
Definition:
Muon.h:177
GenParticleFwd.h
DimuonStatistics::ptMin_
double ptMin_
Definition:
DimuonStatistics.cc:17
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Event.h:528
dqmdumpme.k
k
Definition:
dqmdumpme.py:60
DimuonStatistics::massMin_
double massMin_
Definition:
DimuonStatistics.cc:17
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:36
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
DimuonStatistics
Definition:
DimuonStatistics.cc:7
alignmentValidation.c1
c1
do drawing
Definition:
alignmentValidation.py:1025
DimuonStatistics::unMatched_
std::vector< unsigned int > unMatched_
Definition:
DimuonStatistics.cc:16
DimuonStatistics::massMax_
double massMax_
Definition:
DimuonStatistics.cc:17
edm::InputTag::encode
std::string encode() const
Definition:
InputTag.cc:159
edm::EventSetup
Definition:
EventSetup.h:57
InputTag.h
looper.cfg
cfg
Definition:
looper.py:297
reco::Candidate
Definition:
Candidate.h:27
DimuonStatistics::src_
edm::InputTag src_
Definition:
DimuonStatistics.cc:14
std
Definition:
JetResolutionObject.h:76
DimuonStatistics::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition:
DimuonStatistics.cc:62
Exception
Definition:
hltDiff.cc:246
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:270
maxEntries
const unsigned int maxEntries
Definition:
DimuonStatistics.cc:30
Generated for CMSSW Reference Manual by
1.8.16