ElectroWeakAnalysis
Utilities
src
DistortedMuonProducerFromDB.cc
Go to the documentation of this file.
1
#include <memory>
2
#include "
FWCore/Framework/interface/Frameworkfwd.h
"
3
#include "
FWCore/Framework/interface/MakerMacros.h
"
4
#include "
FWCore/Framework/interface/EDProducer.h
"
5
#include "
FWCore/Framework/interface/Event.h
"
6
7
#include "
DataFormats/Common/interface/View.h
"
8
#include "
DataFormats/MuonReco/interface/Muon.h
"
9
10
#include "
MuonAnalysis/MomentumScaleCalibration/interface/MomentumScaleCorrector.h
"
11
#include "
MuonAnalysis/MomentumScaleCalibration/interface/ResolutionFunction.h
"
12
13
//
14
// class declaration
15
//
16
class
DistortedMuonProducerFromDB
:
public
edm::EDProducer
{
17
public
:
18
explicit
DistortedMuonProducerFromDB
(
const
edm::ParameterSet
&);
19
~DistortedMuonProducerFromDB
()
override
;
20
21
private
:
22
void
beginRun
(
const
edm::Run
&,
const
edm::EventSetup
&)
override
;
23
void
produce
(
edm::Event
&,
const
edm::EventSetup
&)
override
;
24
void
endJob
()
override
;
25
26
edm::EDGetTokenT<edm::View<reco::Muon>
>
muonToken_
;
27
28
std::string
dbScaleLabel_
;
29
std::string
dbDataResolutionLabel_
;
30
std::string
dbMCResolutionLabel_
;
31
32
std::unique_ptr<MomentumScaleCorrector>
momCorrector_
;
33
std::unique_ptr<ResolutionFunction>
momResolutionData_
;
34
std::unique_ptr<ResolutionFunction>
momResolutionMC_
;
35
};
36
37
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
38
#include "
DataFormats/Common/interface/Handle.h
"
39
#include "
DataFormats/MuonReco/interface/MuonFwd.h
"
40
41
#include <CLHEP/Random/RandGauss.h>
42
43
#include "
FWCore/Framework/interface/ESHandle.h
"
44
#include "
FWCore/Framework/interface/EventSetup.h
"
45
#include "
CondFormats/RecoMuonObjects/interface/MuScleFitDBobject.h
"
46
#include "
CondFormats/DataRecord/interface/MuScleFitDBobjectRcd.h
"
47
#include "
MuonAnalysis/MomentumScaleCalibration/interface/BaseFunction.h
"
48
#include "
MuonAnalysis/MomentumScaleCalibration/interface/Functions.h
"
49
51
DistortedMuonProducerFromDB::DistortedMuonProducerFromDB
(
const
edm::ParameterSet
&
pset
) {
52
// What is being produced
53
produces<std::vector<reco::Muon> >();
54
55
// Input products
56
muonToken_
=
57
consumes<edm::View<reco::Muon> >(
pset
.getUntrackedParameter<
edm::InputTag
>(
"MuonTag"
,
edm::InputTag
(
"muons"
)));
58
dbScaleLabel_
=
pset
.getUntrackedParameter<
std::string
>(
"DBScaleLabel"
,
"scale"
);
59
dbDataResolutionLabel_
=
pset
.getUntrackedParameter<
std::string
>(
"DBDataResolutionLabel"
,
"datareso"
);
60
dbMCResolutionLabel_
=
pset
.getUntrackedParameter<
std::string
>(
"DBMCResolutionLabel"
,
"mcreso"
);
61
}
62
64
DistortedMuonProducerFromDB::~DistortedMuonProducerFromDB
() {}
65
67
void
DistortedMuonProducerFromDB::beginRun
(
const
edm::Run
&,
const
edm::EventSetup
& iSetup) {
68
edm::ESHandle<MuScleFitDBobject>
dbObject1;
69
iSetup.
get
<
MuScleFitDBobjectRcd
>().
get
(
dbScaleLabel_
, dbObject1);
70
momCorrector_
= std::make_unique<MomentumScaleCorrector>(dbObject1.
product
());
71
72
LogTrace
(
""
) <<
">>> Using database for momentum scale corrections !!"
;
73
74
edm::ESHandle<MuScleFitDBobject>
dbObject2;
75
iSetup.
get
<
MuScleFitDBobjectRcd
>().
get
(
dbDataResolutionLabel_
, dbObject2);
76
momResolutionData_
= std::make_unique<ResolutionFunction>(dbObject2.
product
());
77
78
edm::ESHandle<MuScleFitDBobject>
dbObject3;
79
iSetup.
get
<
MuScleFitDBobjectRcd
>().
get
(
dbMCResolutionLabel_
, dbObject3);
80
momResolutionMC_
= std::make_unique<ResolutionFunction>(dbObject3.product());
81
82
LogTrace
(
""
) <<
">>> Using database for momentum resolution corrections !!"
;
83
}
84
86
void
DistortedMuonProducerFromDB::endJob
() {}
87
89
void
DistortedMuonProducerFromDB::produce
(
edm::Event
&
ev
,
const
edm::EventSetup
& iSetup) {
90
if
(
ev
.isRealData())
91
return
;
92
93
// Muon collection
94
edm::Handle<edm::View<reco::Muon>
>
muonCollection
;
95
if
(!
ev
.getByToken(
muonToken_
,
muonCollection
)) {
96
edm::LogError
(
""
) <<
">>> Muon collection does not exist !!!"
;
97
return
;
98
}
99
unsigned
int
muonCollectionSize =
muonCollection
->size();
100
101
std::unique_ptr<reco::MuonCollection>
newmuons
(
new
reco::MuonCollection
);
102
103
for
(
unsigned
int
i
= 0;
i
< muonCollectionSize;
i
++) {
104
edm::RefToBase<reco::Muon>
mu
=
muonCollection
->refAt(
i
);
105
106
// Set shift
107
double
shift
= (*momCorrector_)(*mu) -
mu
->pt();
108
LogTrace
(
""
) <<
"\tmomentumScaleShift= "
<<
shift
<<
" [GeV]"
;
109
110
// Set resolutions
111
double
sigma =
pow
(
momResolutionData_
->sigmaPt(*
mu
), 2) -
pow
(
momResolutionMC_
->sigmaPt(*
mu
), 2);
112
if
(sigma > 0.)
113
sigma =
sqrt
(sigma);
114
else
115
sigma = 0.;
116
LogTrace
(
""
) <<
"\tPt additional smearing= "
<< sigma <<
" [GeV]"
;
117
118
// Gaussian Random number for smearing
119
double
rndg = CLHEP::RandGauss::shoot();
120
121
// New muon
122
double
ptmu =
mu
->pt();
123
ptmu +=
shift
+ sigma * rndg;
124
reco::Muon
* newmu =
mu
->clone();
125
newmu->
setP4
(
reco::Particle::PolarLorentzVector
(ptmu,
mu
->eta(),
mu
->phi(),
mu
->mass()));
126
newmuons
->push_back(*newmu);
127
}
128
129
ev
.put(
std::move
(
newmuons
));
130
}
131
132
DEFINE_FWK_MODULE
(
DistortedMuonProducerFromDB
);
MuScleFitDBobjectRcd.h
edm::ESHandle::product
T const * product() const
Definition:
ESHandle.h:86
MuonAlignmentFromReference_cff.newmuons
newmuons
Definition:
MuonAlignmentFromReference_cff.py:26
DistortedMuonProducerFromDB::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition:
DistortedMuonProducerFromDB.cc:67
Handle.h
mps_fire.i
i
Definition:
mps_fire.py:428
Muon.h
MessageLogger.h
EDProducer.h
ESHandle.h
amptDefaultParameters_cff.mu
mu
Definition:
amptDefaultParameters_cff.py:16
edm::Run
Definition:
Run.h:45
edm::EDGetTokenT
Definition:
EDGetToken.h:33
DistortedMuonProducerFromDB::dbScaleLabel_
std::string dbScaleLabel_
Definition:
DistortedMuonProducerFromDB.cc:28
HLT_FULL_cff.InputTag
InputTag
Definition:
HLT_FULL_cff.py:89287
MuScleFitDBobjectRcd
Definition:
MuScleFitDBobjectRcd.h:6
DistortedMuonProducerFromDB::dbMCResolutionLabel_
std::string dbMCResolutionLabel_
Definition:
DistortedMuonProducerFromDB.cc:30
edm::Handle
Definition:
AssociativeIterator.h:50
reco::Muon
Definition:
Muon.h:27
DistortedMuonProducerFromDB::dbDataResolutionLabel_
std::string dbDataResolutionLabel_
Definition:
DistortedMuonProducerFromDB.cc:29
MakerMacros.h
edm::EventSetup::get
T get() const
Definition:
EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition:
MakerMacros.h:16
MuScleFitDBobject.h
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition:
MuonFwd.h:9
mathSSE::sqrt
T sqrt(T t)
Definition:
SSEVec.h:19
ResolutionFunction.h
DistortedMuonProducerFromDB::muonToken_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
Definition:
DistortedMuonProducerFromDB.cc:26
edm::ESHandle< MuScleFitDBobject >
DistortedMuonProducerFromDB::momResolutionData_
std::unique_ptr< ResolutionFunction > momResolutionData_
Definition:
DistortedMuonProducerFromDB.cc:33
reco::Particle::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition:
Particle.h:23
DistortedMuonProducerFromDB::momResolutionMC_
std::unique_ptr< ResolutionFunction > momResolutionMC_
Definition:
DistortedMuonProducerFromDB.cc:34
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition:
ParameterSet.h:47
DistortedMuonProducerFromDB::endJob
void endJob() override
Definition:
DistortedMuonProducerFromDB.cc:86
DistortedMuonProducerFromDB
Definition:
DistortedMuonProducerFromDB.cc:16
Event.h
DistortedMuonProducerFromDB::~DistortedMuonProducerFromDB
~DistortedMuonProducerFromDB() override
Definition:
DistortedMuonProducerFromDB.cc:64
DistortedMuonProducerFromDB::DistortedMuonProducerFromDB
DistortedMuonProducerFromDB(const edm::ParameterSet &)
Definition:
DistortedMuonProducerFromDB.cc:51
edm::EventSetup
Definition:
EventSetup.h:57
BaseFunction.h
edm::LogError
Log< level::Error, false > LogError
Definition:
MessageLogger.h:123
get
#define get
pdwgLeptonRecoSkim_cfi.muonCollection
muonCollection
Definition:
pdwgLeptonRecoSkim_cfi.py:7
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition:
LeafCandidate.h:158
eostools.move
def move(src, dest)
Definition:
eostools.py:511
edm::shift
static unsigned const int shift
Definition:
LuminosityBlockID.cc:7
Frameworkfwd.h
ev
bool ev
Definition:
Hydjet2Hadronizer.cc:95
EventSetup.h
edm::EDProducer
Definition:
EDProducer.h:35
edm::RefToBase
Definition:
AssociativeIterator.h:54
DistortedMuonProducerFromDB::momCorrector_
std::unique_ptr< MomentumScaleCorrector > momCorrector_
Definition:
DistortedMuonProducerFromDB.cc:32
DistortedMuonProducerFromDB::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition:
DistortedMuonProducerFromDB.cc:89
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition:
Power.h:29
Functions.h
LogTrace
#define LogTrace(id)
Definition:
MessageLogger.h:224
View.h
edm::Event
Definition:
Event.h:73
MomentumScaleCorrector.h
edm::InputTag
Definition:
InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition:
muonDTDigis_cfi.py:27
Generated for CMSSW Reference Manual by
1.8.16