CMS 3D CMS Logo

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

Public Member Functions

 DistortedMuonProducer (const edm::ParameterSet &)
 
 ~DistortedMuonProducer () 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 beginJob () override
 
void endJob () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::vector< double > efficiencyRatioOverMC_
 
std::vector< double > etaBinEdges_
 
edm::EDGetTokenT< reco::GenParticleMatchgenMatchMapToken_
 
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
 
std::vector< double > relativeShiftOnPt_
 
std::vector< double > relativeUncertaintyOnPt_
 
std::vector< double > shiftOnOneOverPt_
 
std::vector< double > uncertaintyOnOneOverPt_
 

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 17 of file DistortedMuonProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 48 of file DistortedMuonProducer.cc.

References efficiencyRatioOverMC_, etaBinEdges_, genMatchMapToken_, edm::ParameterSet::getUntrackedParameter(), mps_fire::i, HLT_2018_cff::InputTag, muonToken_, relativeShiftOnPt_, relativeUncertaintyOnPt_, shiftOnOneOverPt_, and uncertaintyOnOneOverPt_.

48  {
49  // What is being produced
50  produces<std::vector<reco::Muon> >();
51 
52  // Input products
53  muonToken_ =
54  consumes<edm::View<reco::Muon> >(pset.getUntrackedParameter<edm::InputTag>("MuonTag", edm::InputTag("muons")));
55  genMatchMapToken_ = consumes<reco::GenParticleMatch>(
56  pset.getUntrackedParameter<edm::InputTag>("GenMatchMapTag", edm::InputTag("genMatchMap")));
57 
58  // Eta edges
59  std::vector<double> defEtaEdges;
60  defEtaEdges.push_back(-999999.);
61  defEtaEdges.push_back(999999.);
62  etaBinEdges_ = pset.getUntrackedParameter<std::vector<double> >("EtaBinEdges", defEtaEdges);
63  unsigned int ninputs_expected = etaBinEdges_.size() - 1;
64 
65  // Distortions in muon momentum
66  std::vector<double> defDistortion;
67  defDistortion.push_back(0.);
68 
70  pset.getUntrackedParameter<std::vector<double> >("ShiftOnOneOverPt", defDistortion); // in [1/GeV]
71  if (shiftOnOneOverPt_.size() == 1 && ninputs_expected > 1) {
72  for (unsigned int i = 1; i < ninputs_expected; i++) {
74  }
75  }
76 
77  relativeShiftOnPt_ = pset.getUntrackedParameter<std::vector<double> >("RelativeShiftOnPt", defDistortion);
78  if (relativeShiftOnPt_.size() == 1 && ninputs_expected > 1) {
79  for (unsigned int i = 1; i < ninputs_expected; i++) {
81  }
82  }
83 
85  pset.getUntrackedParameter<std::vector<double> >("UncertaintyOnOneOverPt", defDistortion); // in [1/GeV]
86  if (uncertaintyOnOneOverPt_.size() == 1 && ninputs_expected > 1) {
87  for (unsigned int i = 1; i < ninputs_expected; i++) {
89  }
90  }
91 
92  relativeUncertaintyOnPt_ = pset.getUntrackedParameter<std::vector<double> >("RelativeUncertaintyOnPt", defDistortion);
93  if (relativeUncertaintyOnPt_.size() == 1 && ninputs_expected > 1) {
94  for (unsigned int i = 1; i < ninputs_expected; i++) {
96  }
97  }
98 
99  // Data/MC efficiency ratios
100  std::vector<double> defEfficiencyRatio;
101  defEfficiencyRatio.push_back(1.);
103  pset.getUntrackedParameter<std::vector<double> >("EfficiencyRatioOverMC", defEfficiencyRatio);
104  if (efficiencyRatioOverMC_.size() == 1 && ninputs_expected > 1) {
105  for (unsigned int i = 1; i < ninputs_expected; i++) {
107  }
108  }
109 
110  // Send a warning if there are inconsistencies in vector sizes !!
111  bool effWrong = efficiencyRatioOverMC_.size() != ninputs_expected;
112  bool momWrong = shiftOnOneOverPt_.size() != ninputs_expected || relativeShiftOnPt_.size() != ninputs_expected ||
113  uncertaintyOnOneOverPt_.size() != ninputs_expected ||
114  relativeUncertaintyOnPt_.size() != ninputs_expected;
115  if (effWrong and momWrong) {
116  edm::LogError("")
117  << "WARNING: DistortedMuonProducer : Size of some parameters do not match the EtaBinEdges vector!!";
118  }
119 }
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > etaBinEdges_
edm::EDGetTokenT< reco::GenParticleMatch > genMatchMapToken_
std::vector< double > efficiencyRatioOverMC_
std::vector< double > shiftOnOneOverPt_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
std::vector< double > relativeUncertaintyOnPt_
std::vector< double > relativeShiftOnPt_
std::vector< double > uncertaintyOnOneOverPt_
DistortedMuonProducer::~DistortedMuonProducer ( )
override

Definition at line 122 of file DistortedMuonProducer.cc.

122 {}

Member Function Documentation

void DistortedMuonProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 125 of file DistortedMuonProducer.cc.

125 {}
void DistortedMuonProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 128 of file DistortedMuonProducer.cc.

128 {}
void DistortedMuonProducer::produce ( edm::Event ev,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 131 of file DistortedMuonProducer.cc.

References reco::Muon::clone(), DEFINE_FWK_MODULE, efficiencyRatioOverMC_, reco::LeafCandidate::eta(), muonRecoAnalyzer_cfi::etaBin, etaBinEdges_, genMatchMapToken_, edm::Event::getByToken(), mps_fire::i, edm::Ref< C, T, F >::isNull(), edm::EventBase::isRealData(), dqmiolumiharvest::j, LogTrace, reco::LeafCandidate::mass(), eostools::move(), amptDefaultParameters_cff::mu, pdwgLeptonRecoSkim_cfi::muonCollection, muonToken_, LaserClient_cfi::nbins, MuonAlignmentFromReference_cff::newmuons, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), edm::Event::put(), relativeShiftOnPt_, relativeUncertaintyOnPt_, reco::LeafCandidate::setP4(), shiftOnOneOverPt_, and uncertaintyOnOneOverPt_.

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

131  {
132  if (ev.isRealData())
133  return;
134 
135  // Muon collection
137  if (!ev.getByToken(muonToken_, muonCollection)) {
138  edm::LogError("") << ">>> Muon collection does not exist !!!";
139  return;
140  }
141 
143  if (!ev.getByToken(genMatchMapToken_, genMatchMap)) {
144  edm::LogError("") << ">>> Muon-GenParticle match map does not exist !!!";
145  return;
146  }
147 
148  unsigned int muonCollectionSize = muonCollection->size();
149 
150  std::unique_ptr<reco::MuonCollection> newmuons(new reco::MuonCollection);
151 
152  for (unsigned int i = 0; i < muonCollectionSize; i++) {
153  edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);
154 
155  double ptgen = mu->pt();
156  double etagen = mu->eta();
157  reco::GenParticleRef gen = (*genMatchMap)[mu];
158  if (!gen.isNull()) {
159  ptgen = gen->pt();
160  etagen = gen->eta();
161  LogTrace("") << ">>> Muon-GenParticle match found; ptmu= " << mu->pt() << ", ptgen= " << ptgen;
162  } else {
163  LogTrace("") << ">>> MUON-GENPARTICLE MATCH NOT FOUND!!!";
164  }
165 
166  // Initialize parameters
167  double effRatio = 0.;
168  double shift1 = 0.;
169  double shift2 = 0.;
170  double sigma1 = 0.;
171  double sigma2 = 0.;
172 
173  // Find out which eta bin should be used
174  unsigned int nbins = etaBinEdges_.size() - 1;
175  unsigned int etaBin = nbins;
176  if (etagen > etaBinEdges_[0] && etagen < etaBinEdges_[nbins]) {
177  for (unsigned int j = 1; j <= nbins; ++j) {
178  if (etagen > etaBinEdges_[j])
179  continue;
180  etaBin = j - 1;
181  break;
182  }
183  }
184  if (etaBin < nbins) {
185  LogTrace("") << ">>> etaBin: " << etaBin << ", for etagen =" << etagen;
186  } else {
187  // Muon is rejected if outside the considered eta range
188  LogTrace("") << ">>> Muon outside eta range: reject it; etagen = " << etagen;
189  continue;
190  }
191 
192  // Set shifts
193  shift1 = shiftOnOneOverPt_[etaBin];
194  shift2 = relativeShiftOnPt_[etaBin];
195  LogTrace("") << "\tshiftOnOneOverPt= " << shift1 * 100 << " [%]";
196  LogTrace("") << "\trelativeShiftOnPt= " << shift2 * 100 << " [%]";
197 
198  // Set resolutions
201  LogTrace("") << "\tuncertaintyOnOneOverPt= " << sigma1 << " [1/GeV]";
202  LogTrace("") << "\trelativeUncertaintyOnPt= " << sigma2 * 100 << " [%]";
203 
204  // Set efficiency ratio
205  effRatio = efficiencyRatioOverMC_[etaBin];
206  LogTrace("") << "\tefficiencyRatioOverMC= " << effRatio;
207 
208  // Reject muons according to efficiency ratio
209  double rndf = CLHEP::RandFlat::shoot();
210  if (rndf > effRatio)
211  continue;
212 
213  // Gaussian Random numbers for smearing
214  double rndg1 = CLHEP::RandGauss::shoot();
215  double rndg2 = CLHEP::RandGauss::shoot();
216 
217  // New muon
218  double ptmu = mu->pt();
219  ptmu += ptgen * (shift1 * ptgen + shift2 + sigma1 * rndg1 * ptgen + sigma2 * rndg2);
220  reco::Muon* newmu = mu->clone();
221  newmu->setP4(reco::Particle::PolarLorentzVector(ptmu, mu->eta(), mu->phi(), mu->mass()));
222  newmuons->push_back(*newmu);
223  }
224 
225  ev.put(std::move(newmuons));
226 }
std::vector< double > etaBinEdges_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
double eta() const final
momentum pseudorapidity
edm::EDGetTokenT< reco::GenParticleMatch > genMatchMapToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
double pt() const final
transverse momentum
std::vector< double > efficiencyRatioOverMC_
bool isRealData() const
Definition: EventBase.h:62
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::vector< double > shiftOnOneOverPt_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
std::vector< double > relativeUncertaintyOnPt_
bool isNull() const
Checks for null.
Definition: Ref.h:235
#define LogTrace(id)
std::vector< double > relativeShiftOnPt_
std::vector< double > uncertaintyOnOneOverPt_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
double phi() const final
momentum azimuthal angle
void setP4(const LorentzVector &p4) final
set 4-momentum
Muon * clone() const override
create a clone
def move(src, dest)
Definition: eostools.py:511
double mass() const final
mass

Member Data Documentation

std::vector<double> DistortedMuonProducer::efficiencyRatioOverMC_
private

Definition at line 36 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::etaBinEdges_
private

Definition at line 29 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

edm::EDGetTokenT<reco::GenParticleMatch> DistortedMuonProducer::genMatchMapToken_
private

Definition at line 28 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

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

Definition at line 27 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::relativeShiftOnPt_
private

Definition at line 32 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::relativeUncertaintyOnPt_
private

Definition at line 34 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::shiftOnOneOverPt_
private

Definition at line 31 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::uncertaintyOnOneOverPt_
private

Definition at line 33 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().