src
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 "
CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h
"
22
#include "
CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h
"
23
#include "
DataFormats/Candidate/interface/LeafCandidate.h
"
24
#include "
DataFormats/MuonReco/interface/Muon.h
"
25
#include "
DataFormats/MuonReco/interface/MuonFwd.h
"
26
#include "
DataFormats/PatCandidates/interface/CompositeCandidate.h
"
27
#include "
DataFormats/PatCandidates/interface/Muon.h
"
28
#include "
DataFormats/TrackReco/interface/Track.h
"
29
#include "
FWCore/Framework/interface/stream/EDProducer.h
"
30
#include "
FWCore/Framework/interface/ESHandle.h
"
31
#include "
FWCore/Framework/interface/Event.h
"
32
#include "
FWCore/Framework/interface/EventSetup.h
"
33
#include "
FWCore/Framework/interface/Frameworkfwd.h
"
34
#include "
FWCore/Framework/interface/MakerMacros.h
"
35
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
36
#include "
FWCore/Utilities/interface/InputTag.h
"
37
#include "
MuonAnalysis/MomentumScaleCalibration/interface/Functions.h
"
38
#include "
MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h
"
39
40
class
MuScleFitMuonProducer
:
public
edm::stream::EDProducer
<> {
41
public
:
42
explicit
MuScleFitMuonProducer
(
const
edm::ParameterSet
&);
43
~MuScleFitMuonProducer
()
override
;
44
45
private
:
46
void
produce
(
edm::Event
&,
const
edm::EventSetup
&)
override
;
47
template
<
class
T>
48
std::unique_ptr<T>
applyCorrection
(
const
edm::Handle<T>
&
allMuons
);
49
const
edm::ESGetToken<MuScleFitDBobject, MuScleFitDBobjectRcd>
muToken_
;
50
const
edm::InputTag
theMuonLabel_
;
51
const
edm::EDGetTokenT<pat::MuonCollection>
thePatMuonToken_
;
52
const
edm::EDGetTokenT<reco::MuonCollection>
theRecoMuonToken_
;
53
const
bool
patMuons_
;
54
55
edm::ESHandle<MuScleFitDBobject>
dbObject_
;
56
unsigned
long
long
dbObjectCacheId_
;
57
std::shared_ptr<MomentumScaleCorrector>
corrector_
;
58
};
59
60
MuScleFitMuonProducer::MuScleFitMuonProducer
(
const
edm::ParameterSet
& iConfig)
61
: muToken_(
esConsumes
(
edm
::
ESInputTag
(
""
, iConfig.getUntrackedParameter<
std
::
string
>(
"DbObjectLabel"
,
""
)))),
62
theMuonLabel_(iConfig.getParameter<
edm
::
InputTag
>(
"MuonLabel"
)),
63
thePatMuonToken_(mayConsume<
pat
::
MuonCollection
>(theMuonLabel_)),
64
theRecoMuonToken_(mayConsume<
reco
::
MuonCollection
>(theMuonLabel_)),
65
patMuons_(iConfig.getParameter<
bool
>(
"PatMuons"
)),
66
dbObjectCacheId_(0) {
67
if
(
patMuons_
==
true
) {
68
produces<pat::MuonCollection>();
69
}
else
{
70
produces<reco::MuonCollection>();
71
}
72
}
73
74
MuScleFitMuonProducer::~MuScleFitMuonProducer
() =
default
;
75
76
template
<
class
T>
77
std::unique_ptr<T>
MuScleFitMuonProducer::applyCorrection
(
const
edm::Handle<T>
&
allMuons
) {
78
std::unique_ptr<T> pOut(
new
T
);
79
80
// Apply the correction and produce the new muons
81
for
(
typename
T::const_iterator
muon
=
allMuons
->begin();
muon
!=
allMuons
->end(); ++
muon
) {
82
//std::cout << "Pt before correction = " << muon->pt() << std::endl;
83
double
pt
= (*corrector_)(*muon);
84
//std::cout << "Pt after correction = " << pt << std::endl;
85
double
eta
=
muon
->eta();
86
double
phi
=
muon
->phi();
87
88
typename
T::value_type
* newMuon =
muon
->clone();
89
newMuon->setP4(
reco::Particle::PolarLorentzVector
(
pt
,
eta
,
phi
,
muon
->mass()));
90
91
pOut->push_back(*newMuon);
92
}
93
return
pOut;
94
}
95
96
// ------------ method called to produce the data ------------
97
void
MuScleFitMuonProducer::produce
(
edm::Event
&
iEvent
,
const
edm::EventSetup
& iSetup) {
98
unsigned
long
long
dbObjectCacheId = iSetup.
get
<
MuScleFitDBobjectRcd
>().cacheIdentifier();
99
if
(dbObjectCacheId !=
dbObjectCacheId_
) {
100
dbObject_
= iSetup.
getHandle
(
muToken_
);
101
}
102
103
//std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
104
//std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
105
106
// Create the corrector and set the parameters
107
corrector_
.reset(
new
MomentumScaleCorrector
(
dbObject_
.
product
()));
108
109
if
(
patMuons_
==
true
) {
110
edm::Handle<pat::MuonCollection>
allMuons
;
111
iEvent
.getByToken(
thePatMuonToken_
,
allMuons
);
112
iEvent
.put(
applyCorrection
(
allMuons
));
113
}
else
{
114
edm::Handle<reco::MuonCollection>
allMuons
;
115
iEvent
.getByToken(
theRecoMuonToken_
,
allMuons
);
116
iEvent
.put(
applyCorrection
(
allMuons
));
117
}
118
119
// put into the Event
120
// iEvent.put(std::move(pOut));
121
// iEvent.put(applyCorrection(allMuons);
122
123
/* std::unique_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
124
125
// Apply the correction and produce the new muons
126
for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
127
128
double pt = (*corrector_)(*muon);
129
double eta = muon->eta();
130
double phi = muon->phi();
131
132
reco::Muon * newMuon = muon->clone();
133
newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
134
135
pOut->push_back(*newMuon);
136
}
137
*/
138
}
139
140
//define this as a plug-in
141
DEFINE_FWK_MODULE
(
MuScleFitMuonProducer
);
MuScleFitMuonProducer::patMuons_
const bool patMuons_
Definition:
MuScleFitMuonProducer.cc:53
deDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition:
DeDxTools.cc:283
MuScleFitDBobjectRcd.h
MuScleFitMuonProducer
Definition:
MuScleFitMuonProducer.cc:40
MuScleFitMuonProducer::theRecoMuonToken_
const edm::EDGetTokenT< reco::MuonCollection > theRecoMuonToken_
Definition:
MuScleFitMuonProducer.cc:52
EDProducer.h
LeafCandidate.h
MuScleFitMuonProducer::applyCorrection
std::unique_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
Definition:
MuScleFitMuonProducer.cc:77
Event.h
edm::Handle
Definition:
AssociativeIterator.h:50
EventSetup.h
MuScleFitMuonProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
MuScleFitMuonProducer.cc:97
MuScleFitDBobject.h
HLT_2022v15_cff.InputTag
InputTag
Definition:
HLT_2022v15_cff.py:60417
PVValHelper::eta
Definition:
PVValidationHelpers.h:70
std
Definition:
JetResolutionObject.h:76
muon
Definition:
MuonCocktails.h:17
edm::EDGetTokenT< pat::MuonCollection >
Frameworkfwd.h
DDAxes::phi
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition:
MuonFwd.h:9
DiDispStaMuonMonitor_cfi.pt
pt
Definition:
DiDispStaMuonMonitor_cfi.py:39
MuonFwd.h
pat
Definition:
HeavyIon.h:7
ParameterSet.h
MuScleFitMuonProducer::~MuScleFitMuonProducer
~MuScleFitMuonProducer() override
MomentumScaleCorrector.h
edm::ESGetToken< MuScleFitDBobject, MuScleFitDBobjectRcd >
iEvent
int iEvent
Definition:
GenABIO.cc:224
edm::ESHandle::product
T const * product() const
Definition:
ESHandle.h:86
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition:
JetExtendedAssociation.h:30
MuScleFitMuonProducer::dbObject_
edm::ESHandle< MuScleFitDBobject > dbObject_
Definition:
MuScleFitMuonProducer.cc:55
edm::ESHandle< MuScleFitDBobject >
ESHandle.h
edm::EventSetup::get
T get() const
Definition:
EventSetup.h:82
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
edm::EventSetup
Definition:
EventSetup.h:59
MuScleFitMuonProducer::thePatMuonToken_
const edm::EDGetTokenT< pat::MuonCollection > thePatMuonToken_
Definition:
MuScleFitMuonProducer.cc:51
Muon.h
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition:
EventSetup.h:151
MuScleFitMuonProducer::theMuonLabel_
const edm::InputTag theMuonLabel_
Definition:
MuScleFitMuonProducer.cc:50
electrons_cff.bool
bool
Definition:
electrons_cff.py:319
MuScleFitMuonProducer::dbObjectCacheId_
unsigned long long dbObjectCacheId_
Definition:
MuScleFitMuonProducer.cc:56
CompositeCandidate.h
edm::stream::EDProducer
Definition:
EDProducer.h:36
MuScleFitMuonProducer::corrector_
std::shared_ptr< MomentumScaleCorrector > corrector_
Definition:
MuScleFitMuonProducer.cc:57
MuScleFitDBobjectRcd
Definition:
MuScleFitDBobjectRcd.h:6
allMuons_cfi.allMuons
allMuons
Definition:
allMuons_cfi.py:3
Muon.h
reco
fixed size matrix
Definition:
AlignmentAlgorithmBase.h:46
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::InputTag
Definition:
InputTag.h:15
InputTag.h
MuScleFitMuonProducer::muToken_
const edm::ESGetToken< MuScleFitDBobject, MuScleFitDBobjectRcd > muToken_
Definition:
MuScleFitMuonProducer.cc:49
reco::Particle::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition:
Particle.h:23
MuScleFitMuonProducer::MuScleFitMuonProducer
MuScleFitMuonProducer(const edm::ParameterSet &)
Definition:
MuScleFitMuonProducer.cc:60
Track.h
edm::ParameterSet
Definition:
ParameterSet.h:47
HLT_2022v15_cff.muon
muon
Definition:
HLT_2022v15_cff.py:9645
MomentumScaleCorrector
Definition:
MomentumScaleCorrector.h:25
edm::Event
Definition:
Event.h:73
T
long double T
Definition:
Basic3DVectorLD.h:48
MakerMacros.h
ESInputTag
Functions.h
Generated for CMSSW Reference Manual by
1.8.14