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
 
std::vector< bool > const & recordProvenanceList () 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)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~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 &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
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
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
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
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (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)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 17 of file DistortedMuonProducer.cc.

Constructor & Destructor Documentation

◆ DistortedMuonProducer()

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

Definition at line 48 of file DistortedMuonProducer.cc.

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 }

References efficiencyRatioOverMC_, etaBinEdges_, genMatchMapToken_, mps_fire::i, HLT_2018_cff::InputTag, muonToken_, muonDTDigis_cfi::pset, relativeShiftOnPt_, relativeUncertaintyOnPt_, shiftOnOneOverPt_, and uncertaintyOnOneOverPt_.

◆ ~DistortedMuonProducer()

DistortedMuonProducer::~DistortedMuonProducer ( )
override

Definition at line 122 of file DistortedMuonProducer.cc.

122 {}

Member Function Documentation

◆ beginJob()

void DistortedMuonProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 125 of file DistortedMuonProducer.cc.

125 {}

◆ endJob()

void DistortedMuonProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 128 of file DistortedMuonProducer.cc.

128 {}

◆ produce()

void DistortedMuonProducer::produce ( edm::Event ev,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 131 of file DistortedMuonProducer.cc.

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++) {
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 }

References efficiencyRatioOverMC_, etaBin(), etaBinEdges_, ev, genMatchMapToken_, mps_fire::i, dqmiolumiharvest::j, LogTrace, eostools::move(), amptDefaultParameters_cff::mu, pdwgLeptonRecoSkim_cfi::muonCollection, muonToken_, LaserClient_cfi::nbins, MuonAlignmentFromReference_cff::newmuons, relativeShiftOnPt_, relativeUncertaintyOnPt_, shiftOnOneOverPt_, and uncertaintyOnOneOverPt_.

Member Data Documentation

◆ efficiencyRatioOverMC_

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

Definition at line 36 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ etaBinEdges_

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

Definition at line 29 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ genMatchMapToken_

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

Definition at line 28 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ muonToken_

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

Definition at line 27 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ relativeShiftOnPt_

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

Definition at line 32 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ relativeUncertaintyOnPt_

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

Definition at line 34 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ shiftOnOneOverPt_

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

Definition at line 31 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

◆ uncertaintyOnOneOverPt_

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

Definition at line 33 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

MuonAlignmentFromReference_cff.newmuons
newmuons
Definition: MuonAlignmentFromReference_cff.py:26
mps_fire.i
i
Definition: mps_fire.py:355
etaBin
int etaBin(const l1t::HGCalMulticluster *cl)
Definition: L1EGammaEEProducer.cc:19
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
DistortedMuonProducer::shiftOnOneOverPt_
std::vector< double > shiftOnOneOverPt_
Definition: DistortedMuonProducer.cc:31
DistortedMuonProducer::efficiencyRatioOverMC_
std::vector< double > efficiencyRatioOverMC_
Definition: DistortedMuonProducer.cc:36
DistortedMuonProducer::relativeShiftOnPt_
std::vector< double > relativeShiftOnPt_
Definition: DistortedMuonProducer.cc:32
edm::Handle
Definition: AssociativeIterator.h:50
reco::Muon
Definition: Muon.h:27
edm::Ref< GenParticleCollection >
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
reco::Particle::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
gen
Definition: PythiaDecays.h:13
DistortedMuonProducer::etaBinEdges_
std::vector< double > etaBinEdges_
Definition: DistortedMuonProducer.cc:29
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::LogError
Definition: MessageLogger.h:183
DistortedMuonProducer::muonToken_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
Definition: DistortedMuonProducer.cc:27
DistortedMuonProducer::uncertaintyOnOneOverPt_
std::vector< double > uncertaintyOnOneOverPt_
Definition: DistortedMuonProducer.cc:33
pdwgLeptonRecoSkim_cfi.muonCollection
muonCollection
Definition: pdwgLeptonRecoSkim_cfi.py:7
eostools.move
def move(src, dest)
Definition: eostools.py:511
DistortedMuonProducer::genMatchMapToken_
edm::EDGetTokenT< reco::GenParticleMatch > genMatchMapToken_
Definition: DistortedMuonProducer.cc:28
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
edm::RefToBase
Definition: AssociativeIterator.h:54
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
DistortedMuonProducer::relativeUncertaintyOnPt_
std::vector< double > relativeUncertaintyOnPt_
Definition: DistortedMuonProducer.cc:34
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27