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 ()
 
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)
 
virtual ~ProducerBase () noexcept(false)
 
- 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
 
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
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
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)
 
- 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 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(), muonToken_, and AlCaHLTBitMon_QueryRunRegistry::string.

51  {
52 
53  // What is being produced
54  produces<std::vector<reco::Muon> >();
55 
56  // Input products
57  muonToken_ = 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 }
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
DistortedMuonProducerFromDB::~DistortedMuonProducerFromDB ( )
override

Definition at line 65 of file DistortedMuonProducerFromDB.cc.

65  {
66 }

Member Function Documentation

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

Definition at line 69 of file DistortedMuonProducerFromDB.cc.

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

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

Reimplemented from edm::EDProducer.

Definition at line 88 of file DistortedMuonProducerFromDB.cc.

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

Definition at line 92 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(), RPCpg::mu, HiRecoMuon_cff::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().

92  {
93 
94  if (ev.isRealData()) return;
95 
96  // Muon collection
98  if (!ev.getByToken(muonToken_, muonCollection)) {
99  edm::LogError("") << ">>> Muon collection does not exist !!!";
100  return;
101  }
102  unsigned int muonCollectionSize = muonCollection->size();
103 
104  std::unique_ptr<reco::MuonCollection> newmuons (new reco::MuonCollection);
105 
106  for (unsigned int i=0; i<muonCollectionSize; i++) {
107  edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);
108 
109  // Set shift
110  double shift = (*momCorrector_)(*mu) - mu->pt();
111  LogTrace("") << "\tmomentumScaleShift= " << shift << " [GeV]";
112 
113  // Set resolutions
114  double sigma = pow(momResolutionData_->sigmaPt(*mu),2) -
115  pow(momResolutionMC_->sigmaPt(*mu),2);
116  if (sigma>0.) sigma = sqrt(sigma); else sigma = 0.;
117  LogTrace("") << "\tPt additional smearing= " << sigma << " [GeV]";
118 
119  // Gaussian Random number for smearing
120  double rndg = CLHEP::RandGauss::shoot();
121 
122  // New muon
123  double ptmu = mu->pt();
124  ptmu += shift + sigma*rndg;
125  reco::Muon* newmu = mu->clone();
126  newmu->setP4 (
128  ptmu, mu->eta(), mu->phi(), mu->mass()
129  )
130  );
131  newmuons->push_back(*newmu);
132 
133  }
134 
135  ev.put(std::move(newmuons));
136 }
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:127
double eta() const final
momentum pseudorapidity
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
double pt() const final
transverse momentum
bool isRealData() const
Definition: EventBase.h:64
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
T sqrt(T t)
Definition: SSEVec.h:18
const int mu
Definition: Constants.h:22
#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:40
def move(src, dest)
Definition: eostools.py:510
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().