CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
DistortedMuonProducerFromDB Class Reference
Inheritance diagram for DistortedMuonProducerFromDB:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 DistortedMuonProducerFromDB (const edm::ParameterSet &)
 
 ~DistortedMuonProducerFromDB () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void beginRun (const edm::Run &, const edm::EventSetup &) override
 
void endJob () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::string dbDataResolutionLabel_
 
std::string dbMCResolutionLabel_
 
std::string dbScaleLabel_
 
std::unique_ptr< MomentumScaleCorrectormomCorrector_
 
std::unique_ptr< ResolutionFunctionmomResolutionData_
 
std::unique_ptr< ResolutionFunctionmomResolutionMC_
 
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 16 of file DistortedMuonProducerFromDB.cc.

Constructor & Destructor Documentation

DistortedMuonProducerFromDB::DistortedMuonProducerFromDB ( const edm::ParameterSet pset)
explicit

Definition at line 51 of file DistortedMuonProducerFromDB.cc.

References dbDataResolutionLabel_, dbMCResolutionLabel_, dbScaleLabel_, edm::ParameterSet::getUntrackedParameter(), HLT_2018_cff::InputTag, muonToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

51  {
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 }
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
DistortedMuonProducerFromDB::~DistortedMuonProducerFromDB ( )
override

Definition at line 64 of file DistortedMuonProducerFromDB.cc.

64 {}

Member Function Documentation

void DistortedMuonProducerFromDB::beginRun ( const edm::Run ,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 67 of file DistortedMuonProducerFromDB.cc.

References dbDataResolutionLabel_, dbMCResolutionLabel_, dbScaleLabel_, edm::EventSetup::get(), LogTrace, momCorrector_, momResolutionData_, momResolutionMC_, and edm::ESHandle< T >::product().

67  {
69  iSetup.get<MuScleFitDBobjectRcd>().get(dbScaleLabel_, dbObject1);
70  momCorrector_.reset(new MomentumScaleCorrector(dbObject1.product()));
71 
72  LogTrace("") << ">>> Using database for momentum scale corrections !!";
73 
75  iSetup.get<MuScleFitDBobjectRcd>().get(dbDataResolutionLabel_, dbObject2);
76  momResolutionData_.reset(new ResolutionFunction(dbObject2.product()));
77 
79  iSetup.get<MuScleFitDBobjectRcd>().get(dbMCResolutionLabel_, dbObject3);
80  momResolutionMC_.reset(new ResolutionFunction(dbObject3.product()));
81 
82  LogTrace("") << ">>> Using database for momentum resolution corrections !!";
83 }
std::unique_ptr< ResolutionFunction > momResolutionData_
std::unique_ptr< ResolutionFunction > momResolutionMC_
std::unique_ptr< MomentumScaleCorrector > momCorrector_
#define LogTrace(id)
T get() const
Definition: EventSetup.h:73
T const * product() const
Definition: ESHandle.h:86
void DistortedMuonProducerFromDB::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 86 of file DistortedMuonProducerFromDB.cc.

86 {}
void DistortedMuonProducerFromDB::produce ( edm::Event ev,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 89 of file DistortedMuonProducerFromDB.cc.

References reco::Muon::clone(), DEFINE_FWK_MODULE, reco::LeafCandidate::eta(), edm::Event::getByToken(), mps_fire::i, edm::EventBase::isRealData(), LogTrace, reco::LeafCandidate::mass(), momResolutionData_, momResolutionMC_, eostools::move(), amptDefaultParameters_cff::mu, pdwgLeptonRecoSkim_cfi::muonCollection, muonToken_, MuonAlignmentFromReference_cff::newmuons, reco::LeafCandidate::phi(), funct::pow(), reco::LeafCandidate::pt(), edm::Event::put(), reco::LeafCandidate::setP4(), edm::shift, and mathSSE::sqrt().

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

89  {
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++) {
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 }
std::unique_ptr< ResolutionFunction > momResolutionData_
std::unique_ptr< ResolutionFunction > momResolutionMC_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
double eta() const final
momentum pseudorapidity
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
double pt() const final
transverse momentum
bool isRealData() const
Definition: EventBase.h:62
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
T sqrt(T t)
Definition: SSEVec.h:19
#define LogTrace(id)
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
static unsigned int const shift
double phi() const final
momentum azimuthal angle
void setP4(const LorentzVector &p4) final
set 4-momentum
Muon * clone() const override
create a clone
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
def move(src, dest)
Definition: eostools.py:511
double mass() const final
mass
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_

Member Data Documentation

std::string DistortedMuonProducerFromDB::dbDataResolutionLabel_
private

Definition at line 29 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and DistortedMuonProducerFromDB().

std::string DistortedMuonProducerFromDB::dbMCResolutionLabel_
private

Definition at line 30 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and DistortedMuonProducerFromDB().

std::string DistortedMuonProducerFromDB::dbScaleLabel_
private

Definition at line 28 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and DistortedMuonProducerFromDB().

std::unique_ptr<MomentumScaleCorrector> DistortedMuonProducerFromDB::momCorrector_
private

Definition at line 32 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun().

std::unique_ptr<ResolutionFunction> DistortedMuonProducerFromDB::momResolutionData_
private

Definition at line 33 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and produce().

std::unique_ptr<ResolutionFunction> DistortedMuonProducerFromDB::momResolutionMC_
private

Definition at line 34 of file DistortedMuonProducerFromDB.cc.

Referenced by beginRun(), and produce().

edm::EDGetTokenT<edm::View<reco::Muon> > DistortedMuonProducerFromDB::muonToken_
private

Definition at line 26 of file DistortedMuonProducerFromDB.cc.

Referenced by DistortedMuonProducerFromDB(), and produce().