CMS 3D CMS Logo

DistortedMuonProducerFromDB.cc
Go to the documentation of this file.
1 #include <memory>
6 
9 
12 
13 //
14 // class declaration
15 //
17 public:
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 
27 
31 
32  std::unique_ptr<MomentumScaleCorrector> momCorrector_;
33  std::unique_ptr<ResolutionFunction> momResolutionData_;
34  std::unique_ptr<ResolutionFunction> momResolutionMC_;
35 };
36 
40 
41 #include <CLHEP/Random/RandGauss.h>
42 
49 
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 
65 
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 
75  iSetup.get<MuScleFitDBobjectRcd>().get(dbDataResolutionLabel_, dbObject2);
76  momResolutionData_ = std::make_unique<ResolutionFunction>(dbObject2.product());
77 
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 
87 
90  if (ev.isRealData())
91  return;
92 
93  // Muon collection
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++) {
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 
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