MuonAnalysis
MomentumScaleCalibration
plugins
MuScleFitMuonProducer.cc
Go to the documentation of this file.
1
// -*- C++ -*-
2
//
3
// Package: MuScleFitMuonProducer
4
// Class: MuScleFitMuonProducer
5
//
10
//
11
// Original Author: Marco De Mattia,40 3-B32,+41227671551,
12
// Created: Tue Jun 22 13:50:22 CEST 2010
13
//
14
//
15
16
// system include files
17
#include <memory>
18
#include <string>
19
20
// user include files
21
#include "
FWCore/Framework/interface/Frameworkfwd.h
"
22
#include "
FWCore/Framework/interface/EDProducer.h
"
23
24
#include "
FWCore/Framework/interface/Event.h
"
25
#include "
FWCore/Framework/interface/MakerMacros.h
"
26
27
#include "
FWCore/Utilities/interface/InputTag.h
"
28
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
29
30
#include "
DataFormats/MuonReco/interface/Muon.h
"
31
#include "
DataFormats/MuonReco/interface/MuonFwd.h
"
32
#include "
DataFormats/Candidate/interface/LeafCandidate.h
"
33
34
#include "
DataFormats/TrackReco/interface/Track.h
"
35
#include "
DataFormats/PatCandidates/interface/Muon.h
"
36
#include "
DataFormats/PatCandidates/interface/CompositeCandidate.h
"
37
38
#include "
MuonAnalysis/MomentumScaleCalibration/interface/Functions.h
"
39
40
#include "
CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h
"
41
#include "
CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h
"
42
43
#include "
FWCore/Framework/interface/EventSetup.h
"
44
#include "
FWCore/Framework/interface/ESHandle.h
"
45
#include "
MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h
"
46
47
class
MuScleFitMuonProducer
:
public
edm::EDProducer
{
48
public
:
49
explicit
MuScleFitMuonProducer
(
const
edm::ParameterSet
&);
50
~MuScleFitMuonProducer
()
override
;
51
52
private
:
53
void
beginJob
()
override
;
54
void
produce
(
edm::Event
&,
const
edm::EventSetup
&)
override
;
55
void
endJob
()
override
;
56
template
<
class
T>
57
std::unique_ptr<T>
applyCorrection
(
const
edm::Handle<T>
&
allMuons
);
58
59
edm::InputTag
theMuonLabel_
;
60
edm::EDGetTokenT<pat::MuonCollection>
thePatMuonToken_
;
61
edm::EDGetTokenT<reco::MuonCollection>
theRecoMuonToken_
;
62
bool
patMuons_
;
63
edm::ESHandle<MuScleFitDBobject>
dbObject_
;
64
std::string
dbObjectLabel_
;
65
unsigned
long
long
dbObjectCacheId_
;
66
std::shared_ptr<MomentumScaleCorrector>
corrector_
;
67
};
68
69
MuScleFitMuonProducer::MuScleFitMuonProducer
(
const
edm::ParameterSet
& iConfig)
70
: theMuonLabel_(iConfig.getParameter<
edm
::
InputTag
>(
"MuonLabel"
)),
71
thePatMuonToken_(mayConsume<
pat
::
MuonCollection
>(theMuonLabel_)),
72
theRecoMuonToken_(mayConsume<
reco
::
MuonCollection
>(theMuonLabel_)),
73
patMuons_(iConfig.getParameter<
bool
>(
"PatMuons"
)),
74
dbObjectLabel_(iConfig.getUntrackedParameter<
std
::
string
>(
"DbObjectLabel"
,
""
)),
75
dbObjectCacheId_(0) {
76
if
(
patMuons_
==
true
) {
77
produces<pat::MuonCollection>();
78
}
else
{
79
produces<reco::MuonCollection>();
80
}
81
}
82
83
MuScleFitMuonProducer::~MuScleFitMuonProducer
() {}
84
85
template
<
class
T>
86
std::unique_ptr<T>
MuScleFitMuonProducer::applyCorrection
(
const
edm::Handle<T>
&
allMuons
) {
87
std::unique_ptr<T>
pOut
(
new
T
);
88
89
// Apply the correction and produce the new muons
90
for
(
typename
T::const_iterator
muon
=
allMuons
->begin();
muon
!=
allMuons
->end(); ++
muon
) {
91
//std::cout << "Pt before correction = " << muon->pt() << std::endl;
92
double
pt
= (*corrector_)(*muon);
93
//std::cout << "Pt after correction = " << pt << std::endl;
94
double
eta
=
muon
->eta();
95
double
phi
=
muon
->phi();
96
97
typename
T::value_type
* newMuon =
muon
->clone();
98
newMuon->setP4(
reco::Particle::PolarLorentzVector
(
pt
,
eta
,
phi
,
muon
->mass()));
99
100
pOut
->push_back(*newMuon);
101
}
102
return
pOut
;
103
}
104
105
// ------------ method called to produce the data ------------
106
void
MuScleFitMuonProducer::produce
(
edm::Event
&
iEvent
,
const
edm::EventSetup
& iSetup) {
107
unsigned
long
long
dbObjectCacheId = iSetup.
get
<
MuScleFitDBobjectRcd
>().cacheIdentifier();
108
if
(dbObjectCacheId !=
dbObjectCacheId_
) {
109
if
(!
dbObjectLabel_
.empty()) {
110
iSetup.
get
<
MuScleFitDBobjectRcd
>().
get
(
dbObjectLabel_
,
dbObject_
);
111
}
else
{
112
iSetup.
get
<
MuScleFitDBobjectRcd
>().
get
(
dbObject_
);
113
}
114
}
115
116
//std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
117
//std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
118
119
// Create the corrector and set the parameters
120
corrector_
.reset(
new
MomentumScaleCorrector
(
dbObject_
.
product
()));
121
122
if
(
patMuons_
==
true
) {
123
edm::Handle<pat::MuonCollection>
allMuons
;
124
iEvent
.getByToken(
thePatMuonToken_
,
allMuons
);
125
iEvent
.put(
applyCorrection
(
allMuons
));
126
}
else
{
127
edm::Handle<reco::MuonCollection>
allMuons
;
128
iEvent
.getByToken(
theRecoMuonToken_
,
allMuons
);
129
iEvent
.put(
applyCorrection
(
allMuons
));
130
}
131
132
// put into the Event
133
// iEvent.put(std::move(pOut));
134
// iEvent.put(applyCorrection(allMuons);
135
136
/* std::unique_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
137
138
// Apply the correction and produce the new muons
139
for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
140
141
double pt = (*corrector_)(*muon);
142
double eta = muon->eta();
143
double phi = muon->phi();
144
145
reco::Muon * newMuon = muon->clone();
146
newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
147
148
pOut->push_back(*newMuon);
149
}
150
*/
151
}
152
153
// ------------ method called once each job just before starting event loop ------------
154
void
MuScleFitMuonProducer::beginJob
() {}
155
156
// ------------ method called once each job just after ending the event loop ------------
157
void
MuScleFitMuonProducer::endJob
() {}
158
159
//define this as a plug-in
160
DEFINE_FWK_MODULE
(
MuScleFitMuonProducer
);
MuScleFitMuonProducer::dbObjectCacheId_
unsigned long long dbObjectCacheId_
Definition:
MuScleFitMuonProducer.cc:65
MuScleFitDBobjectRcd.h
edm::ESHandle::product
T const * product() const
Definition:
ESHandle.h:86
CompositeCandidate.h
electrons_cff.bool
bool
Definition:
electrons_cff.py:366
Muon.h
MomentumScaleCorrector
Definition:
MomentumScaleCorrector.h:25
EDProducer.h
ESHandle.h
muon
Definition:
MuonCocktails.h:17
DiDispStaMuonMonitor_cfi.pt
pt
Definition:
DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT< pat::MuonCollection >
edm
HLT enums.
Definition:
AlignableModifier.h:19
Muon.h
HLT_FULL_cff.InputTag
InputTag
Definition:
HLT_FULL_cff.py:89301
MuScleFitDBobjectRcd
Definition:
MuScleFitDBobjectRcd.h:6
L1TrackObjectNtupleMaker_cfg.pOut
pOut
Definition:
L1TrackObjectNtupleMaker_cfg.py:172
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:46
edm::Handle
Definition:
AssociativeIterator.h:50
MuScleFitMuonProducer
Definition:
MuScleFitMuonProducer.cc:47
MuScleFitMuonProducer::dbObjectLabel_
std::string dbObjectLabel_
Definition:
MuScleFitMuonProducer.cc:64
MakerMacros.h
MuScleFitMuonProducer::patMuons_
bool patMuons_
Definition:
MuScleFitMuonProducer.cc:62
Track.h
edm::EventSetup::get
T get() const
Definition:
EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
MuScleFitDBobject.h
HLT_FULL_cff.muon
muon
Definition:
HLT_FULL_cff.py:11725
PVValHelper::eta
Definition:
PVValidationHelpers.h:70
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition:
MuonFwd.h:9
MuScleFitMuonProducer::theMuonLabel_
edm::InputTag theMuonLabel_
Definition:
MuScleFitMuonProducer.cc:59
edm::ESHandle< MuScleFitDBobject >
LeafCandidate.h
MuScleFitMuonProducer::corrector_
std::shared_ptr< MomentumScaleCorrector > corrector_
Definition:
MuScleFitMuonProducer.cc:66
reco::Particle::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition:
Particle.h:23
allMuons_cfi.allMuons
allMuons
Definition:
allMuons_cfi.py:3
edm::ParameterSet
Definition:
ParameterSet.h:47
Event.h
MuScleFitMuonProducer::endJob
void endJob() override
Definition:
MuScleFitMuonProducer.cc:157
MuScleFitMuonProducer::MuScleFitMuonProducer
MuScleFitMuonProducer(const edm::ParameterSet &)
Definition:
MuScleFitMuonProducer.cc:69
MuScleFitMuonProducer::dbObject_
edm::ESHandle< MuScleFitDBobject > dbObject_
Definition:
MuScleFitMuonProducer.cc:63
MuScleFitMuonProducer::beginJob
void beginJob() override
Definition:
MuScleFitMuonProducer.cc:154
iEvent
int iEvent
Definition:
GenABIO.cc:224
edm::EventSetup
Definition:
EventSetup.h:58
pat
Definition:
HeavyIon.h:7
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
get
#define get
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
MuScleFitMuonProducer::applyCorrection
std::unique_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
Definition:
MuScleFitMuonProducer.cc:86
InputTag.h
DDAxes::phi
std
Definition:
JetResolutionObject.h:76
Frameworkfwd.h
T
long double T
Definition:
Basic3DVectorLD.h:48
EventSetup.h
edm::EDProducer
Definition:
EDProducer.h:35
Functions.h
ParameterSet.h
edm::Event
Definition:
Event.h:73
MuScleFitMuonProducer::theRecoMuonToken_
edm::EDGetTokenT< reco::MuonCollection > theRecoMuonToken_
Definition:
MuScleFitMuonProducer.cc:61
MomentumScaleCorrector.h
MuScleFitMuonProducer::thePatMuonToken_
edm::EDGetTokenT< pat::MuonCollection > thePatMuonToken_
Definition:
MuScleFitMuonProducer.cc:60
edm::InputTag
Definition:
InputTag.h:15
MuScleFitMuonProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
MuScleFitMuonProducer.cc:106
MuScleFitMuonProducer::~MuScleFitMuonProducer
~MuScleFitMuonProducer() override
Definition:
MuScleFitMuonProducer.cc:83
Generated for CMSSW Reference Manual by
1.8.16