CMS 3D CMS Logo

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

Public Member Functions

 DistortedPFCandProducer (const edm::ParameterSet &)
 
 ~DistortedPFCandProducer () 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_
 
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfToken_
 
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 DistortedPFCandProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 51 of file DistortedPFCandProducer.cc.

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

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

Definition at line 127 of file DistortedPFCandProducer.cc.

127 {}

Member Function Documentation

void DistortedPFCandProducer::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 130 of file DistortedPFCandProducer.cc.

130 {}
void DistortedPFCandProducer::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 133 of file DistortedPFCandProducer.cc.

133 {}
void DistortedPFCandProducer::produce ( edm::Event ev,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 136 of file DistortedPFCandProducer.cc.

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

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

136  {
137  if (ev.isRealData())
138  return;
139 
140  // Muon collection
142  if (!ev.getByToken(muonToken_, muonCollection)) {
143  edm::LogError("") << ">>> Muon collection does not exist !!!";
144  return;
145  }
146 
148  if (!ev.getByToken(genMatchMapToken_, genMatchMap)) {
149  edm::LogError("") << ">>> Muon-GenParticle match map does not exist !!!";
150  return;
151  }
152 
153  // Get PFCandidate collection
155  if (!ev.getByToken(pfToken_, pfCollection)) {
156  edm::LogError("") << ">>> PFCandidate collection does not exist !!!";
157  return;
158  }
159 
160  unsigned int muonCollectionSize = muonCollection->size();
161  unsigned int pfCollectionSize = pfCollection->size();
162 
163  if (pfCollectionSize < 1)
164  return;
165 
166  // Ask for PfMuon consistency
167  bool pfMuonFound = false;
168 
169  std::unique_ptr<reco::PFCandidateCollection> newmuons(new reco::PFCandidateCollection);
170 
171  // Loop on all PF candidates
172  for (unsigned int j = 0; j < pfCollectionSize; j++) {
173  edm::RefToBase<reco::PFCandidate> pf = pfCollection->refAt(j);
174 
175  // New PF muon
176  double ptmu = pf->pt();
177 
178  for (unsigned int i = 0; i < muonCollectionSize; i++) {
179  edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);
180 
181  // Check the muon is in the PF collection
182  if (pf->particleId() == reco::PFCandidate::mu) {
183  reco::MuonRef muref = pf->muonRef();
184  if (muref.isNonnull()) {
185  if (muref.key() == mu.key()) {
186  if (mu->isStandAloneMuon() && ptmu == muref->standAloneMuon()->pt() &&
187  ((!mu->isGlobalMuon() || (mu->isGlobalMuon() && ptmu != muref->combinedMuon()->pt())) &&
188  (!mu->isTrackerMuon() || (mu->isTrackerMuon() && ptmu != mu->track()->pt())))) {
189  pfMuonFound = false;
190  } else if (!mu->isTrackerMuon()) {
191  pfMuonFound = false;
192  } else {
193  pfMuonFound = true;
194  }
195  } else {
196  pfMuonFound = false;
197  }
198  }
199  }
200 
201  // do nothing if StandAlone muon
202  //const reco::Track& track = *trackRef;
203 
204  if (!pfMuonFound)
205  continue;
206 
207  double ptgen = pf->pt();
208  double etagen = pf->eta();
209 
210  reco::GenParticleRef gen = (*genMatchMap)[mu];
211  if (!gen.isNull()) {
212  ptgen = gen->pt();
213  etagen = gen->eta();
214  LogTrace("") << ">>> Muon-GenParticle match found; ptmu= " << pf->pt() << ", ptgen= " << ptgen;
215  } else {
216  LogTrace("") << ">>> MUON-GENPARTICLE MATCH NOT FOUND!!!";
217  }
218 
219  // Initialize parameters
220  double effRatio = 0.;
221  double shift1 = 0.;
222  double shift2 = 0.;
223  double sigma1 = 0.;
224  double sigma2 = 0.;
225 
226  // Find out which eta bin should be used
227  unsigned int nbins = etaBinEdges_.size() - 1;
228  unsigned int etaBin = nbins;
229  if (etagen > etaBinEdges_[0] && etagen < etaBinEdges_[nbins]) {
230  for (unsigned int j = 1; j <= nbins; ++j) {
231  if (etagen > etaBinEdges_[j])
232  continue;
233  etaBin = j - 1;
234  break;
235  }
236  }
237  if (etaBin < nbins) {
238  LogTrace("") << ">>> etaBin: " << etaBin << ", for etagen =" << etagen;
239  } else {
240  // Muon is rejected if outside the considered eta range
241  LogTrace("") << ">>> Muon outside eta range: reject it; etagen = " << etagen;
242  pfMuonFound = false;
243  continue;
244  }
245 
246  if (!pfMuonFound)
247  continue;
248 
249  // Set shifts
250  shift1 = shiftOnOneOverPt_[etaBin];
251  shift2 = relativeShiftOnPt_[etaBin];
252  LogTrace("") << "\tshiftOnOneOverPt= " << shift1 * 100 << " [%]";
253  LogTrace("") << "\trelativeShiftOnPt= " << shift2 * 100 << " [%]";
254 
255  // Set resolutions
258  LogTrace("") << "\tuncertaintyOnOneOverPt= " << sigma1 << " [1/GeV]";
259  LogTrace("") << "\trelativeUncertaintyOnPt= " << sigma2 * 100 << " [%]";
260 
261  // Set efficiency ratio
262  effRatio = efficiencyRatioOverMC_[etaBin];
263  LogTrace("") << "\tefficiencyRatioOverMC= " << effRatio;
264 
265  // Reject muons according to efficiency ratio
266  double rndf = CLHEP::RandFlat::shoot();
267  if (rndf > effRatio)
268  continue;
269 
270  // Gaussian Random numbers for smearing
271  double rndg1 = CLHEP::RandGauss::shoot();
272  double rndg2 = CLHEP::RandGauss::shoot();
273 
274  // change here the pt of the candidate, if it is a muon
275 
276  ptmu += ptgen * (shift1 * ptgen + shift2 + sigma1 * rndg1 * ptgen + sigma2 * rndg2);
277  pfMuonFound = false;
278  }
279 
280  reco::PFCandidate* newmu = pf->clone();
281  newmu->setP4(reco::Particle::PolarLorentzVector(ptmu, pf->eta(), pf->phi(), pf->mass()));
282 
283  newmuons->push_back(*newmu);
284  }
285 
286  ev.put(std::move(newmuons));
287 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
double eta() const final
momentum pseudorapidity
bool isStandAloneMuon() const override
Definition: Muon.h:300
std::vector< double > relativeUncertaintyOnPt_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
edm::EDGetTokenT< edm::View< reco::PFCandidate > > pfToken_
double pt() const final
transverse momentum
key_type key() const
Accessor for product key.
Definition: Ref.h:250
bool isRealData() const
Definition: EventBase.h:62
bool isTrackerMuon() const override
Definition: Muon.h:299
edm::EDGetTokenT< reco::GenParticleMatch > genMatchMapToken_
bool isGlobalMuon() const override
Definition: Muon.h:298
std::vector< double > uncertaintyOnOneOverPt_
size_t key() const
Definition: RefToBase.h:219
bool isNull() const
Checks for null.
Definition: Ref.h:235
#define LogTrace(id)
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:421
PFCandidate * clone() const override
return a clone
Definition: PFCandidate.cc:197
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
std::vector< double > efficiencyRatioOverMC_
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
virtual ParticleType particleId() const
Definition: PFCandidate.h:366
std::vector< double > relativeShiftOnPt_
std::vector< double > shiftOnOneOverPt_
double phi() const final
momentum azimuthal angle
void setP4(const LorentzVector &p4) final
set 4-momentum
def move(src, dest)
Definition: eostools.py:511
std::vector< double > etaBinEdges_
double mass() const final
mass

Member Data Documentation

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

Definition at line 37 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 30 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 28 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 27 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

edm::EDGetTokenT<edm::View<reco::PFCandidate> > DistortedPFCandProducer::pfToken_
private

Definition at line 29 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 33 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 35 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 32 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 34 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().