CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PATMuonProducer.cc
Go to the documentation of this file.
1 
53 
54 namespace pat {
55 
57  public:
59 
62 
64 
65  private:
66  std::unique_ptr<const pat::MuonMvaEstimator> muonLowPtMvaEstimator_;
67  std::unique_ptr<const pat::MuonMvaEstimator> muonMvaEstimator_;
68  std::unique_ptr<const pat::SoftMuonMvaEstimator> softMuonMvaEstimator_;
69  };
70 
72  class TrackerIsolationPt;
73  class CaloIsolationEnergy;
74 
76  class PATMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<PATMuonHeavyObjectCache>> {
77  public:
81  ~PATMuonProducer() override;
82 
83  static std::unique_ptr<PATMuonHeavyObjectCache> initializeGlobalCache(const edm::ParameterSet& iConfig) {
84  return std::make_unique<PATMuonHeavyObjectCache>(iConfig);
85  }
86 
88 
90  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
92  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
93 
94  private:
97  typedef std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> GenAssociations;
98  typedef std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> IsoDepositMaps;
99  typedef std::vector<edm::Handle<edm::ValueMap<double>>> IsolationValueMaps;
100  typedef std::pair<pat::IsolationKeys, edm::InputTag> IsolationLabel;
101  typedef std::vector<IsolationLabel> IsolationLabels;
102 
104  void fillMuon(Muon& aMuon,
105  const MuonBaseRef& muonRef,
106  const reco::CandidateBaseRef& baseRef,
107  const GenAssociations& genMatches,
108  const IsoDepositMaps& deposits,
109  const IsolationValueMaps& isolationValues) const;
112  template <typename T>
113  void readIsolationLabels(const edm::ParameterSet& iConfig,
114  const char* psetName,
117 
119  double getRelMiniIsoPUCorrected(const pat::Muon& muon, double rho, const std::vector<double>& area);
120 
122  bool isNeutralHadron(long pdgid);
123  bool isChargedHadron(long pdgid);
124  bool isPhoton(long pdgid);
125 
126  // embed various impact parameters with errors
127  // embed high level selection
128  void embedHighLevel(pat::Muon& aMuon,
132  bool primaryVertexIsValid,
134  bool beamspotIsValid);
135  double relMiniIsoPUCorrected(const pat::Muon& aMuon, double rho);
136  std::optional<GlobalPoint> getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
138  const DetId& chamberId);
140  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
141  const edm::TriggerNames& names,
144  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
145  const edm::TriggerNames& names,
146  const std::vector<std::string>& collection_names);
147 
148  private:
151 
152  // for mini-iso calculation
156  std::vector<double> effectiveAreaVec_;
157  std::vector<double> miniIsoParams_;
159 
193  std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>> genMatchTokens_;
214  std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit>>> isoDepositTokens_;
217  std::vector<edm::EDGetTokenT<edm::ValueMap<double>>> isolationValueTokens_;
226  //PUPPI isolation tokens
230  //PUPPINoLeptons isolation tokens
243 
253 
256 
261  std::vector<std::string> hltCollectionFilters_;
262 
265 
267  };
268 
269 } // namespace pat
270 
271 template <typename T>
273  const char* psetName,
276  labels.clear();
277 
278  if (iConfig.exists(psetName)) {
279  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>(psetName);
280 
281  if (depconf.exists("tracker"))
282  labels.emplace_back(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker"));
283  if (depconf.exists("ecal"))
284  labels.emplace_back(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal"));
285  if (depconf.exists("hcal"))
286  labels.emplace_back(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal"));
287  if (depconf.exists("pfAllParticles")) {
288  labels.emplace_back(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles"));
289  }
290  if (depconf.exists("pfChargedHadrons")) {
291  labels.emplace_back(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons"));
292  }
293  if (depconf.exists("pfChargedAll")) {
294  labels.emplace_back(pat::PfChargedAllIso, depconf.getParameter<edm::InputTag>("pfChargedAll"));
295  }
296  if (depconf.exists("pfPUChargedHadrons")) {
297  labels.emplace_back(pat::PfPUChargedHadronIso, depconf.getParameter<edm::InputTag>("pfPUChargedHadrons"));
298  }
299  if (depconf.exists("pfNeutralHadrons")) {
300  labels.emplace_back(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons"));
301  }
302  if (depconf.exists("pfPhotons")) {
303  labels.emplace_back(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons"));
304  }
305  if (depconf.exists("user")) {
306  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
307  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
309  for (; it != ed; ++it, ++key) {
310  labels.push_back(std::make_pair(pat::IsolationKeys(key), *it));
311  }
312  tokens = edm::vector_transform(
313  labels, [this](IsolationLabel const& label) { return consumes<edm::ValueMap<T>>(label.second); });
314  }
315  }
316  tokens = edm::vector_transform(labels, [this](pat::PATMuonProducer::IsolationLabel const& label) {
317  return consumes<edm::ValueMap<T>>(label.second);
318  });
319 }
320 
321 using namespace pat;
322 using namespace std;
323 
325  if (iConfig.getParameter<bool>("computeMuonMVA")) {
326  edm::FileInPath mvaTrainingFile = iConfig.getParameter<edm::FileInPath>("mvaTrainingFile");
327  edm::FileInPath mvaLowPtTrainingFile = iConfig.getParameter<edm::FileInPath>("lowPtmvaTrainingFile");
328  float mvaDrMax = iConfig.getParameter<double>("mvaDrMax");
329  muonMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaTrainingFile, mvaDrMax);
330  muonLowPtMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaLowPtTrainingFile, mvaDrMax);
331  }
332 
333  if (iConfig.getParameter<bool>("computeSoftMuonMVA")) {
334  edm::FileInPath softMvaTrainingFile = iConfig.getParameter<edm::FileInPath>("softMvaTrainingFile");
335  softMuonMvaEstimator_ = std::make_unique<SoftMuonMvaEstimator>(softMvaTrainingFile);
336  }
337 }
338 
340  : relMiniIsoPUCorrected_(0),
341  useUserData_(iConfig.exists("userData")),
342  computeMuonMVA_(false),
343  computeSoftMuonMVA_(false),
344  recomputeBasicSelectors_(false),
345  mvaUseJec_(false),
346  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation")
347  : edm::ParameterSet(),
348  consumesCollector(),
349  false),
350  geometryToken_{esConsumes()},
351  transientTrackBuilderToken_{esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))},
352  patMuonPutToken_{produces<std::vector<Muon>>()} {
353  // input source
354  muonToken_ = consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("muonSource"));
355  // embedding of tracks
356  embedBestTrack_ = iConfig.getParameter<bool>("embedMuonBestTrack");
357  embedTunePBestTrack_ = iConfig.getParameter<bool>("embedTunePMuonBestTrack");
358  forceEmbedBestTrack_ = iConfig.getParameter<bool>("forceBestTrackEmbedding");
359  embedTrack_ = iConfig.getParameter<bool>("embedTrack");
360  embedCombinedMuon_ = iConfig.getParameter<bool>("embedCombinedMuon");
361  embedStandAloneMuon_ = iConfig.getParameter<bool>("embedStandAloneMuon");
362  // embedding of muon MET correction information
363  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs");
364  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs");
365  caloMETMuonCorrsToken_ =
366  mayConsume<edm::ValueMap<reco::MuonMETCorrectionData>>(iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs"));
367  tcMETMuonCorrsToken_ =
368  mayConsume<edm::ValueMap<reco::MuonMETCorrectionData>>(iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs"));
369  // pflow specific configurables
370  useParticleFlow_ = iConfig.getParameter<bool>("useParticleFlow");
371  embedPFCandidate_ = iConfig.getParameter<bool>("embedPFCandidate");
372  pfMuonToken_ = mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfMuonSource"));
373  embedPfEcalEnergy_ = iConfig.getParameter<bool>("embedPfEcalEnergy");
374  // embedding of tracks from TeV refit
375  embedPickyMuon_ = iConfig.getParameter<bool>("embedPickyMuon");
376  embedTpfmsMuon_ = iConfig.getParameter<bool>("embedTpfmsMuon");
377  embedDytMuon_ = iConfig.getParameter<bool>("embedDytMuon");
378  // embedding of inverse beta variable information
379  addInverseBeta_ = iConfig.getParameter<bool>("addInverseBeta");
380  if (addInverseBeta_) {
381  muonTimeExtraToken_ =
382  consumes<edm::ValueMap<reco::MuonTimeExtra>>(iConfig.getParameter<edm::InputTag>("sourceMuonTimeExtra"));
383  }
384  // Monte Carlo matching
385  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
386  if (addGenMatch_) {
387  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
388  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
389  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection>>(
390  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
391  } else {
392  genMatchTokens_ = edm::vector_transform(
393  iConfig.getParameter<std::vector<edm::InputTag>>("genParticleMatch"),
394  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
395  }
396  }
397  // efficiencies
398  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
399  if (addEfficiencies_) {
400  efficiencyLoader_ =
401  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
402  }
403  // resolutions
404  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
405  if (addResolutions_) {
406  resolutionLoader_ =
407  pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"), consumesCollector());
408  }
409  // puppi
410  addPuppiIsolation_ = iConfig.getParameter<bool>("addPuppiIsolation");
411  if (addPuppiIsolation_) {
412  PUPPIIsolation_charged_hadrons_ =
413  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
414  PUPPIIsolation_neutral_hadrons_ =
415  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
416  PUPPIIsolation_photons_ =
417  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
418  //puppiNoLeptons
419  PUPPINoLeptonsIsolation_charged_hadrons_ =
420  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
421  PUPPINoLeptonsIsolation_neutral_hadrons_ =
422  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
423  PUPPINoLeptonsIsolation_photons_ =
424  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
425  }
426  // read isoDeposit labels, for direct embedding
427  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
428  // read isolation value labels, for direct embedding
429  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_, isolationValueTokens_);
430  // check to see if the user wants to add user data
431  if (useUserData_) {
432  userDataHelper_ = PATUserDataHelper<Muon>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
433  }
434  // embed high level selection variables
435  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
436  if (embedHighLevelSelection_) {
437  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
438  pvToken_ = consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvSrc"));
439  }
440 
441  //for mini-isolation calculation
442  computeMiniIso_ = iConfig.getParameter<bool>("computeMiniIso");
443 
444  computePuppiCombinedIso_ = iConfig.getParameter<bool>("computePuppiCombinedIso");
445 
446  effectiveAreaVec_ = iConfig.getParameter<std::vector<double>>("effectiveAreaVec");
447 
448  miniIsoParams_ = iConfig.getParameter<std::vector<double>>("miniIsoParams");
449  if (computeMiniIso_ && miniIsoParams_.size() != 9) {
450  throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 9 elements.\n";
451  }
452  if (computeMiniIso_ || computePuppiCombinedIso_)
453  pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
454 
455  // standard selectors
456  recomputeBasicSelectors_ = iConfig.getParameter<bool>("recomputeBasicSelectors");
457  computeMuonMVA_ = iConfig.getParameter<bool>("computeMuonMVA");
458  if (computeMuonMVA_ and not computeMiniIso_)
459  throw cms::Exception("ConfigurationError") << "MiniIso is needed for Muon MVA calculation.\n";
460 
461  if (computeMuonMVA_) {
462  // pfCombinedInclusiveSecondaryVertexV2BJetTags
463  mvaBTagCollectionTag_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("mvaJetTag"));
464  mvaL1Corrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1Corrector"));
465  mvaL1L2L3ResCorrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1L2L3ResCorrector"));
466  rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
467  mvaUseJec_ = iConfig.getParameter<bool>("mvaUseJec");
468  }
469 
470  computeSoftMuonMVA_ = iConfig.getParameter<bool>("computeSoftMuonMVA");
471 
472  // MC info
473  simInfo_ = consumes<edm::ValueMap<reco::MuonSimInfo>>(iConfig.getParameter<edm::InputTag>("muonSimInfo"));
474 
475  addTriggerMatching_ = iConfig.getParameter<bool>("addTriggerMatching");
476  if (addTriggerMatching_) {
477  triggerObjects_ =
478  consumes<std::vector<pat::TriggerObjectStandAlone>>(iConfig.getParameter<edm::InputTag>("triggerObjects"));
479  triggerResults_ = consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("triggerResults"));
480  }
481  hltCollectionFilters_ = iConfig.getParameter<std::vector<std::string>>("hltCollectionFilters");
482 }
483 
485 
486 std::optional<GlobalPoint> PATMuonProducer::getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
488  const DetId& chamberId) {
489  const GeomDet* chamberGeometry = geometry->idToDet(chamberId);
490  if (chamberGeometry) {
491  LocalPoint localPosition(chamberMatch.x, chamberMatch.y, 0);
492  return std::optional<GlobalPoint>(std::in_place, chamberGeometry->toGlobal(localPosition));
493  }
494  return std::optional<GlobalPoint>();
495 }
496 
498  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
499  const edm::TriggerNames& names,
501  // L1 trigger object parameters are defined at MB2/ME2. Use the muon
502  // chamber matching information to get the local direction of the
503  // muon trajectory and convert it to a global direction to match the
504  // trigger objects
505 
506  std::optional<GlobalPoint> muonPosition;
507  // Loop over chambers
508  // initialize muonPosition with any available match, just in case
509  // the second station is missing - it's better folling back to
510  // dR matching at IP
511  for (const auto& chamberMatch : aMuon.matches()) {
512  if (chamberMatch.id.subdetId() == MuonSubdetId::DT) {
513  DTChamberId detId(chamberMatch.id.rawId());
514  if (abs(detId.station()) > 3)
515  continue;
516  muonPosition = getMuonDirection(chamberMatch, geometry, detId);
517  if (abs(detId.station()) == 2)
518  break;
519  }
520  if (chamberMatch.id.subdetId() == MuonSubdetId::CSC) {
521  CSCDetId detId(chamberMatch.id.rawId());
522  if (abs(detId.station()) > 3)
523  continue;
524  muonPosition = getMuonDirection(chamberMatch, geometry, detId);
525  if (abs(detId.station()) == 2)
526  break;
527  }
528  }
529  if (not muonPosition)
530  return;
531  for (const auto& triggerObject : *triggerObjects) {
532  if (triggerObject.hasTriggerObjectType(trigger::TriggerL1Mu)) {
533  if (std::abs(triggerObject.eta()) < 0.001) {
534  // L1 is defined in X-Y plain
535  if (deltaPhi(triggerObject.phi(), muonPosition->phi()) > 0.1)
536  continue;
537  } else {
538  // 3D L1
539  if (deltaR(triggerObject.p4(), *muonPosition) > 0.15)
540  continue;
541  }
542  pat::TriggerObjectStandAlone obj(triggerObject);
543  obj.unpackPathNames(names);
544  aMuon.addTriggerObjectMatch(obj);
545  }
546  }
547 }
548 
550  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
551  const edm::TriggerNames& names,
552  const std::vector<std::string>& collection_filter_names) {
553  // WARNING: in a case of close-by muons the dR matching may select both muons.
554  // It's better to select the best match for a given collection.
555  for (const auto& triggerObject : *triggerObjects) {
556  if (triggerObject.hasTriggerObjectType(trigger::TriggerMuon)) {
557  bool keepIt = false;
558  for (const auto& name : collection_filter_names) {
559  if (triggerObject.hasCollection(name)) {
560  keepIt = true;
561  break;
562  }
563  }
564  if (not keepIt)
565  continue;
566  if (deltaR(triggerObject.p4(), muon) > 0.1)
567  continue;
568  pat::TriggerObjectStandAlone obj(triggerObject);
569  obj.unpackPathNames(names);
570  muon.addTriggerObjectMatch(obj);
571  }
572  }
573 }
574 
576  // get the tracking Geometry
577  auto geometry = iSetup.getHandle(geometryToken_);
578  if (!geometry.isValid())
579  throw cms::Exception("FatalError") << "Unable to find GlobalTrackingGeometryRecord in event!\n";
580 
581  // switch off embedding (in unschedules mode)
582  if (iEvent.isRealData()) {
583  addGenMatch_ = false;
584  embedGenMatch_ = false;
585  }
586 
588  iEvent.getByToken(muonToken_, muons);
589 
592  iEvent.getByToken(pcToken_, pc);
593 
594  // get the ESHandle for the transient track builder,
595  // if needed for high level selection embedding
596  TransientTrackBuilder const* trackBuilder = nullptr;
597 
598  if (isolator_.enabled())
599  isolator_.beginEvent(iEvent, iSetup);
601  efficiencyLoader_.newEvent(iEvent);
603  resolutionLoader_.newEvent(iEvent, iSetup);
604 
605  IsoDepositMaps deposits(isoDepositTokens_.size());
606  for (size_t j = 0; j < isoDepositTokens_.size(); ++j) {
607  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
608  }
609 
610  IsolationValueMaps isolationValues(isolationValueTokens_.size());
611  for (size_t j = 0; j < isolationValueTokens_.size(); ++j) {
612  iEvent.getByToken(isolationValueTokens_[j], isolationValues[j]);
613  }
614 
615  //value maps for puppi isolation
616  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
617  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
618  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
619  //value maps for puppiNoLeptons isolation
620  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
621  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
622  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
623  if (addPuppiIsolation_) {
624  //puppi
625  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
626  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
627  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
628  //puppiNoLeptons
629  iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
630  iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
631  iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
632  }
633 
634  // inputs for muon mva
635  edm::Handle<reco::JetTagCollection> mvaBTagCollectionTag;
636  edm::Handle<reco::JetCorrector> mvaL1Corrector;
637  edm::Handle<reco::JetCorrector> mvaL1L2L3ResCorrector;
638  if (computeMuonMVA_) {
639  iEvent.getByToken(mvaBTagCollectionTag_, mvaBTagCollectionTag);
640  iEvent.getByToken(mvaL1Corrector_, mvaL1Corrector);
641  iEvent.getByToken(mvaL1L2L3ResCorrector_, mvaL1L2L3ResCorrector);
642  }
643 
644  // prepare the MC genMatchTokens_
645  GenAssociations genMatches(genMatchTokens_.size());
646  if (addGenMatch_) {
647  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
648  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
649  }
650  }
651 
652  // prepare the high level selection: needs beamline
653  // OR primary vertex, depending on user selection
656  bool beamSpotIsValid = false;
657  bool primaryVertexIsValid = false;
659  // get the beamspot
660  edm::Handle<reco::BeamSpot> beamSpotHandle;
661  iEvent.getByToken(beamLineToken_, beamSpotHandle);
662 
663  // get the primary vertex
665  iEvent.getByToken(pvToken_, pvHandle);
666 
667  if (beamSpotHandle.isValid()) {
668  beamSpot = *beamSpotHandle;
669  beamSpotIsValid = true;
670  } else {
671  edm::LogError("DataNotAvailable") << "No beam spot available from EventSetup, not adding high level selection \n";
672  }
673  if (pvHandle.isValid() && !pvHandle->empty()) {
674  primaryVertex = pvHandle->at(0);
675  primaryVertexIsValid = true;
676  } else {
677  edm::LogError("DataNotAvailable")
678  << "No primary vertex available from EventSetup, not adding high level selection \n";
679  }
680  // this is needed by the IPTools methods from the tracking group
681  trackBuilder = &iSetup.getData(transientTrackBuilderToken_);
682  }
683 
684  // MC info
686  bool simInfoIsAvailalbe = iEvent.getByToken(simInfo_, simInfo);
687 
688  // this will be the new object collection
689  std::vector<Muon> patMuons;
690 
692  if (useParticleFlow_) {
693  // get the PFCandidates of type muons
694  iEvent.getByToken(pfMuonToken_, pfMuons);
695 
696  unsigned index = 0;
697  for (reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
698  const reco::PFCandidate& pfmu = *i;
699  //const reco::IsolaPFCandidate& pfmu = *i;
700  const reco::MuonRef& muonRef = pfmu.muonRef();
701  assert(muonRef.isNonnull());
702 
703  MuonBaseRef muonBaseRef(muonRef);
704  Muon aMuon(muonBaseRef);
705 
706  if (useUserData_) {
707  userDataHelper_.add(aMuon, iEvent, iSetup);
708  }
709 
710  // embed high level selection
712  // get the tracks
713  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
714  reco::TrackRef globalTrack = muonBaseRef->globalTrack();
715  reco::TrackRef bestTrack = muonBaseRef->muonBestTrack();
716  reco::TrackRef chosenTrack = innerTrack;
717  // Make sure the collection it points to is there
718  if (bestTrack.isNonnull() && bestTrack.isAvailable())
719  chosenTrack = bestTrack;
720 
721  if (chosenTrack.isNonnull() && chosenTrack.isAvailable()) {
722  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
723  aMuon.setNumberOfValidHits(nhits);
724 
725  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
726  embedHighLevel(aMuon, chosenTrack, tt, primaryVertex, primaryVertexIsValid, beamSpot, beamSpotIsValid);
727  }
728 
729  if (globalTrack.isNonnull() && globalTrack.isAvailable() && !embedCombinedMuon_) {
730  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
731  aMuon.setNormChi2(norm_chi2);
732  }
733  }
734  reco::PFCandidateRef pfRef(pfMuons, index);
735  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
736  reco::CandidateBaseRef pfBaseRef(pfRef);
737 
738  aMuon.setPFCandidateRef(pfRef);
739  if (embedPFCandidate_)
740  aMuon.embedPFCandidate();
741  fillMuon(aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues);
742 
743  if (computeMiniIso_)
744  setMuonMiniIso(aMuon, pc.product());
745 
746  if (addPuppiIsolation_) {
747  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonBaseRef],
748  (*PUPPIIsolation_neutral_hadrons)[muonBaseRef],
749  (*PUPPIIsolation_photons)[muonBaseRef]);
750 
751  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonBaseRef],
752  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonBaseRef],
753  (*PUPPINoLeptonsIsolation_photons)[muonBaseRef]);
754  } else {
755  aMuon.setIsolationPUPPI(-999., -999., -999.);
756  aMuon.setIsolationPUPPINoLeptons(-999., -999., -999.);
757  }
758 
759  if (embedPfEcalEnergy_) {
760  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
761  }
762 
763  patMuons.push_back(aMuon);
764  }
765  } else {
767  iEvent.getByToken(muonToken_, muons);
768 
769  // embedding of muon MET corrections
771  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
773  iEvent.getByToken(caloMETMuonCorrsToken_, caloMETMuonCorrs);
774  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
775  }
777  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
778  if (embedTcMETMuonCorrs_) {
779  iEvent.getByToken(tcMETMuonCorrsToken_, tcMETMuonCorrs);
780  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
781  }
782 
784  // get the PFCandidates of type muons
785  iEvent.getByToken(pfMuonToken_, pfMuons);
786  }
787 
789  if (addInverseBeta_) {
790  // get MuonTimerExtra value map
791  iEvent.getByToken(muonTimeExtraToken_, muonsTimeExtra);
792  }
793 
794  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
795  // construct the Muon from the ref -> save ref to original object
796  unsigned int idx = itMuon - muons->begin();
797  MuonBaseRef muonRef = muons->refAt(idx);
798  reco::CandidateBaseRef muonBaseRef(muonRef);
799 
800  Muon aMuon(muonRef);
801  fillMuon(aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
802  if (computeMiniIso_)
803  setMuonMiniIso(aMuon, pc.product());
804  if (addPuppiIsolation_) {
805  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonRef],
806  (*PUPPIIsolation_neutral_hadrons)[muonRef],
807  (*PUPPIIsolation_photons)[muonRef]);
808  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonRef],
809  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonRef],
810  (*PUPPINoLeptonsIsolation_photons)[muonRef]);
811  } else {
812  aMuon.setIsolationPUPPI(-999., -999., -999.);
813  aMuon.setIsolationPUPPINoLeptons(-999., -999., -999.);
814  }
815 
816  // Isolation
817  if (isolator_.enabled()) {
818  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
819  isolator_.fill(*muons, idx, isolatorTmpStorage_);
820  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
821  // better to loop backwards, so the vector is resized less times
822  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
823  ed = isolatorTmpStorage_.rend();
824  it != ed;
825  ++it) {
826  aMuon.setIsolation(it->first, it->second);
827  }
828  }
829 
830  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
831  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
832  // (*deposits[j])[muonRef]);
833  // }
834 
835  // add sel to selected
836  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
837  if (useUserData_) {
838  userDataHelper_.add(aMuon, iEvent, iSetup);
839  }
840 
841  // embed high level selection
843  // get the tracks
844  reco::TrackRef innerTrack = itMuon->innerTrack();
845  reco::TrackRef globalTrack = itMuon->globalTrack();
846  reco::TrackRef bestTrack = itMuon->muonBestTrack();
847  reco::TrackRef chosenTrack = innerTrack;
848  // Make sure the collection it points to is there
849  if (bestTrack.isNonnull() && bestTrack.isAvailable())
850  chosenTrack = bestTrack;
851  if (chosenTrack.isNonnull() && chosenTrack.isAvailable()) {
852  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
853  aMuon.setNumberOfValidHits(nhits);
854 
855  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
856  embedHighLevel(aMuon, chosenTrack, tt, primaryVertex, primaryVertexIsValid, beamSpot, beamSpotIsValid);
857  }
858 
859  if (globalTrack.isNonnull() && globalTrack.isAvailable()) {
860  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
861  aMuon.setNormChi2(norm_chi2);
862  }
863  }
864 
865  // embed MET muon corrections
867  aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
869  aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs)[muonRef]);
870 
872  if (embedPfEcalEnergy_)
873  aMuon.setPfEcalEnergy(-99.0);
874  unsigned index = 0;
875  for (const reco::PFCandidate& pfmu : *pfMuons) {
876  if (pfmu.muonRef().isNonnull()) {
877  if (pfmu.muonRef().id() != muonRef.id())
878  throw cms::Exception("Configuration")
879  << "Muon reference within PF candidates does not point to the muon collection." << std::endl;
880  if (pfmu.muonRef().key() == muonRef.key()) {
881  reco::PFCandidateRef pfRef(pfMuons, index);
882  aMuon.setPFCandidateRef(pfRef);
883  if (embedPfEcalEnergy_)
884  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
885  if (embedPFCandidate_)
886  aMuon.embedPFCandidate();
887  break;
888  }
889  }
890  index++;
891  }
892  }
893 
894  if (addInverseBeta_) {
895  aMuon.readTimeExtra((*muonsTimeExtra)[muonRef]);
896  }
897  // MC info
898  aMuon.initSimInfo();
899  if (simInfoIsAvailalbe) {
900  const auto& msi = (*simInfo)[muonBaseRef];
901  aMuon.setSimType(msi.primaryClass);
902  aMuon.setExtSimType(msi.extendedClass);
903  aMuon.setSimFlavour(msi.flavour);
904  aMuon.setSimHeaviestMotherFlavour(msi.heaviestMotherFlavour);
905  aMuon.setSimPdgId(msi.pdgId);
906  aMuon.setSimMotherPdgId(msi.motherPdgId);
907  aMuon.setSimBX(msi.tpBX);
908  aMuon.setSimTpEvent(msi.tpEvent);
909  aMuon.setSimProdRho(msi.vertex.Rho());
910  aMuon.setSimProdZ(msi.vertex.Z());
911  aMuon.setSimPt(msi.p4.pt());
912  aMuon.setSimEta(msi.p4.eta());
913  aMuon.setSimPhi(msi.p4.phi());
914  aMuon.setSimMatchQuality(msi.tpAssoQuality);
915  }
916  patMuons.push_back(aMuon);
917  }
918  }
919 
920  // sort muons in pt
921  std::sort(patMuons.begin(), patMuons.end(), [](auto const& t1, auto const& t2) { return t1.pt() > t2.pt(); });
922 
923  // Store standard muon selection decisions and jet related
924  // quantaties.
925  // Need a separate loop over muons to have all inputs properly
926  // computed and stored in the object.
928  if (computeMuonMVA_)
929  iEvent.getByToken(rho_, rho);
930  const reco::Vertex* pv(nullptr);
931  if (primaryVertexIsValid)
932  pv = &primaryVertex;
933 
936  bool triggerObjectsAvailable = false;
937  bool triggerResultsAvailable = false;
938  if (addTriggerMatching_) {
939  triggerObjectsAvailable = iEvent.getByToken(triggerObjects_, triggerObjects);
940  triggerResultsAvailable = iEvent.getByToken(triggerResults_, triggerResults);
941  }
942 
943  for (auto& muon : patMuons) {
944  // trigger info
945  if (addTriggerMatching_ and triggerObjectsAvailable and triggerResultsAvailable) {
946  const edm::TriggerNames& triggerNames(iEvent.triggerNames(*triggerResults));
947  fillL1TriggerInfo(muon, triggerObjects, triggerNames, geometry);
949  }
950 
952  muon.setSelectors(0);
953  bool isRun2016BCDEF = (272728 <= iEvent.run() && iEvent.run() <= 278808);
954  muon.setSelectors(muon::makeSelectorBitset(muon, pv, isRun2016BCDEF));
955  }
956  float miniIsoValue = -1;
957  if (computeMiniIso_) {
958  // MiniIsolation working points
959 
960  miniIsoValue = getRelMiniIsoPUCorrected(muon, *rho, effectiveAreaVec_);
961 
962  muon.setSelector(reco::Muon::MiniIsoLoose, miniIsoValue < 0.40);
963  muon.setSelector(reco::Muon::MiniIsoMedium, miniIsoValue < 0.20);
964  muon.setSelector(reco::Muon::MiniIsoTight, miniIsoValue < 0.10);
965  muon.setSelector(reco::Muon::MiniIsoVeryTight, miniIsoValue < 0.05);
966  }
967 
968  double puppiCombinedIsolationPAT = -1;
970  puppiCombinedIsolationPAT = puppiCombinedIsolation(muon, pc.product());
971  muon.setSelector(reco::Muon::PuppiIsoLoose, puppiCombinedIsolationPAT < 0.27);
972  muon.setSelector(reco::Muon::PuppiIsoMedium, puppiCombinedIsolationPAT < 0.22);
973  muon.setSelector(reco::Muon::PuppiIsoTight, puppiCombinedIsolationPAT < 0.12);
974  }
975 
976  float jetPtRatio = 0.0;
977  float jetPtRel = 0.0;
978  float mva = 0.0;
979  float mva_lowpt = 0.0;
980  if (computeMuonMVA_ && primaryVertexIsValid && computeMiniIso_) {
981  if (mvaUseJec_) {
982  mva = globalCache()->muonMvaEstimator().computeMva(muon,
983  primaryVertex,
984  *(mvaBTagCollectionTag.product()),
985  jetPtRatio,
986  jetPtRel,
987  miniIsoValue,
988  mvaL1Corrector.product(),
989  mvaL1L2L3ResCorrector.product());
990  mva_lowpt = globalCache()->muonLowPtMvaEstimator().computeMva(muon,
991  primaryVertex,
992  *(mvaBTagCollectionTag.product()),
993  jetPtRatio,
994  jetPtRel,
995  miniIsoValue,
996  mvaL1Corrector.product(),
997  mvaL1L2L3ResCorrector.product());
998 
999  } else {
1000  mva = globalCache()->muonMvaEstimator().computeMva(
1001  muon, primaryVertex, *mvaBTagCollectionTag, jetPtRatio, jetPtRel, miniIsoValue);
1002  mva_lowpt = globalCache()->muonLowPtMvaEstimator().computeMva(
1003  muon, primaryVertex, *mvaBTagCollectionTag, jetPtRatio, jetPtRel, miniIsoValue);
1004  }
1005 
1006  muon.setMvaValue(mva);
1007  muon.setLowPtMvaValue(mva_lowpt);
1008  muon.setJetPtRatio(jetPtRatio);
1009  muon.setJetPtRel(jetPtRel);
1010 
1011  // multi-isolation
1012  if (computeMiniIso_) {
1013  muon.setSelector(reco::Muon::MultiIsoMedium,
1014  miniIsoValue < 0.11 && (muon.jetPtRatio() > 0.74 || muon.jetPtRel() > 6.8));
1015  }
1016 
1017  // MVA working points
1018  // https://twiki.cern.ch/twiki/bin/viewauth/CMS/LeptonMVA
1019  const double dB2D = std::abs(muon.dB(pat::Muon::PV2D));
1020  const double dB3D = std::abs(muon.dB(pat::Muon::PV3D));
1021  const double edB3D = std::abs(muon.edB(pat::Muon::PV3D));
1022  const double sip3D = edB3D > 0 ? dB3D / edB3D : 0.0;
1023  const double dz = std::abs(muon.muonBestTrack()->dz(primaryVertex.position()));
1024 
1025  // muon preselection
1026  if (muon.pt() > 5 and muon.isLooseMuon() and muon.passed(reco::Muon::MiniIsoLoose) and sip3D < 8.0 and
1027  dB2D < 0.05 and dz < 0.1) {
1028  muon.setSelector(reco::Muon::MvaLoose, muon.mvaValue() > -0.60);
1029  muon.setSelector(reco::Muon::MvaMedium, muon.mvaValue() > -0.20);
1030  muon.setSelector(reco::Muon::MvaTight, muon.mvaValue() > 0.15);
1031  muon.setSelector(reco::Muon::MvaVTight, muon.mvaValue() > 0.45);
1032  muon.setSelector(reco::Muon::MvaVVTight, muon.mvaValue() > 0.9);
1033  }
1034  if (muon.pt() > 5 and muon.isLooseMuon() and sip3D < 4 and dB2D < 0.5 and dz < 1) {
1035  muon.setSelector(reco::Muon::LowPtMvaLoose, muon.lowptMvaValue() > -0.60);
1036  muon.setSelector(reco::Muon::LowPtMvaMedium, muon.lowptMvaValue() > -0.20);
1037  }
1038  }
1039 
1040  //SOFT MVA
1041  if (computeSoftMuonMVA_) {
1042  float mva = globalCache()->softMuonMvaEstimator().computeMva(muon);
1043  muon.setSoftMvaValue(mva);
1044  //preselection in SoftMuonMvaEstimator.cc
1045  muon.setSelector(reco::Muon::SoftMvaId, muon.softMvaValue() > 0.58); //WP choose for bmm4
1046  }
1047  }
1048 
1049  // put products in Event
1050  iEvent.emplace(patMuonPutToken_, std::move(patMuons));
1051 
1052  if (isolator_.enabled())
1053  isolator_.endEvent();
1054 }
1055 
1057  const MuonBaseRef& muonRef,
1058  const reco::CandidateBaseRef& baseRef,
1059  const GenAssociations& genMatches,
1060  const IsoDepositMaps& deposits,
1061  const IsolationValueMaps& isolationValues) const {
1062  // in the particle flow algorithm,
1063  // the muon momentum is recomputed.
1064  // the new value is stored as the momentum of the
1065  // resulting PFCandidate of type Muon, and choosen
1066  // as the pat::Muon momentum
1067  if (useParticleFlow_)
1068  aMuon.setP4(aMuon.pfCandidateRef()->p4());
1069  if (embedTrack_)
1070  aMuon.embedTrack();
1072  aMuon.embedStandAloneMuon();
1073  if (embedCombinedMuon_)
1074  aMuon.embedCombinedMuon();
1075 
1076  // embed the TeV refit track refs (only available for globalMuons)
1077  if (aMuon.isGlobalMuon()) {
1079  aMuon.embedPickyMuon();
1081  aMuon.embedTpfmsMuon();
1083  aMuon.embedDytMuon();
1084  }
1085 
1086  // embed best tracks (at the end, so unless forceEmbedBestTrack_ is true we can save some space not embedding them twice)
1087  if (embedBestTrack_)
1091 
1092  // store the match to the generated final state muons
1093  if (addGenMatch_) {
1094  for (auto const& genMatch : genMatches) {
1095  reco::GenParticleRef genMuon = (*genMatch)[baseRef];
1096  aMuon.addGenParticleRef(genMuon);
1097  }
1098  if (embedGenMatch_)
1099  aMuon.embedGenParticle();
1100  }
1101  if (efficiencyLoader_.enabled()) {
1102  efficiencyLoader_.setEfficiencies(aMuon, muonRef);
1103  }
1104 
1105  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
1106  if (useParticleFlow_) {
1107  if (deposits[j]->contains(baseRef.id())) {
1108  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
1109  } else if (deposits[j]->contains(muonRef.id())) {
1110  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
1111  } else {
1112  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
1113  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
1114  }
1115  } else {
1116  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
1117  }
1118  }
1119 
1120  for (size_t j = 0; j < isolationValues.size(); ++j) {
1121  if (useParticleFlow_) {
1122  if (isolationValues[j]->contains(baseRef.id())) {
1123  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
1124  } else if (isolationValues[j]->contains(muonRef.id())) {
1125  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
1126  } else {
1127  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
1128  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
1129  }
1130  } else {
1131  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
1132  }
1133  }
1134 
1135  if (resolutionLoader_.enabled()) {
1137  }
1138 }
1139 
1142  aMuon.polarP4(),
1143  miniIsoParams_[0],
1144  miniIsoParams_[1],
1145  miniIsoParams_[2],
1146  miniIsoParams_[3],
1147  miniIsoParams_[4],
1148  miniIsoParams_[5],
1149  miniIsoParams_[6],
1150  miniIsoParams_[7],
1151  miniIsoParams_[8]);
1152  aMuon.setMiniPFIsolation(miniiso);
1153 }
1154 
1155 double PATMuonProducer::getRelMiniIsoPUCorrected(const pat::Muon& muon, double rho, const std::vector<double>& area) {
1156  double mindr(miniIsoParams_[0]);
1157  double maxdr(miniIsoParams_[1]);
1158  double kt_scale(miniIsoParams_[2]);
1159  double drcut = pat::miniIsoDr(muon.polarP4(), mindr, maxdr, kt_scale);
1160  return pat::muonRelMiniIsoPUCorrected(muon.miniPFIsolation(), muon.polarP4(), drcut, rho, area);
1161 }
1162 
1164  constexpr double dR_threshold = 0.4;
1165  constexpr double dR2_threshold = dR_threshold * dR_threshold;
1166  constexpr double mix_fraction = 0.5;
1167  enum particleType { CH = 0, NH = 1, PH = 2, OTHER = 100000 };
1168  double val_PuppiWithLep = 0.0;
1169  double val_PuppiWithoutLep = 0.0;
1170 
1171  for (const auto& cand : *pc) { //pat::pat::PackedCandidate loop start
1172 
1173  const particleType pType = isChargedHadron(cand.pdgId()) ? CH
1174  : isNeutralHadron(cand.pdgId()) ? NH
1175  : isPhoton(cand.pdgId()) ? PH
1176  : OTHER;
1177  if (pType == OTHER) {
1178  if (cand.pdgId() != 1 && cand.pdgId() != 2 && abs(cand.pdgId()) != 11 && abs(cand.pdgId()) != 13) {
1179  LogTrace("PATMuonProducer") << "candidate with PDGID = " << cand.pdgId()
1180  << " is not CH/NH/PH/e/mu or 1/2 (and this is removed from isolation calculation)"
1181  << std::endl;
1182  }
1183  continue;
1184  }
1185  double d_eta = std::abs(cand.eta() - muon.eta());
1186  if (d_eta > dR_threshold)
1187  continue;
1188 
1189  double d_phi = std::abs(reco::deltaPhi(cand.phi(), muon.phi()));
1190  if (d_phi > dR_threshold)
1191  continue;
1192 
1193  double dR2 = reco::deltaR2(cand, muon);
1194  if (dR2 > dR2_threshold)
1195  continue;
1196  if (pType == CH && dR2 < 0.0001 * 0.0001)
1197  continue;
1198  if (pType == NH && dR2 < 0.01 * 0.01)
1199  continue;
1200  if (pType == PH && dR2 < 0.01 * 0.01)
1201  continue;
1202  val_PuppiWithLep += cand.pt() * cand.puppiWeight();
1203  val_PuppiWithoutLep += cand.pt() * cand.puppiWeightNoLep();
1204 
1205  } //pat::pat::PackedCandidate loop end
1206 
1207  double reliso_Puppi_withLep = val_PuppiWithLep / muon.pt();
1208  double reliso_Puppi_withoutlep = val_PuppiWithoutLep / muon.pt();
1209  double reliso_Puppi_combined = mix_fraction * reliso_Puppi_withLep + (1.0 - mix_fraction) * reliso_Puppi_withoutlep;
1210  return reliso_Puppi_combined;
1211 }
1212 
1213 bool PATMuonProducer::isNeutralHadron(long pdgid) { return std::abs(pdgid) == 130; }
1214 
1215 bool PATMuonProducer::isChargedHadron(long pdgid) { return std::abs(pdgid) == 211; }
1216 
1217 bool PATMuonProducer::isPhoton(long pdgid) { return pdgid == 22; }
1218 
1219 // ParameterSet description for module
1222  iDesc.setComment("PAT muon producer module");
1223 
1224  // input source
1225  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
1226 
1227  // embedding
1228  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track (global pflow)");
1229  iDesc.add<bool>("embedTunePMuonBestTrack", true)->setComment("embed muon best track (muon only)");
1230  iDesc.add<bool>("forceBestTrackEmbedding", true)
1231  ->setComment(
1232  "force embedding separately the best tracks even if they're already embedded e.g. as tracker or global "
1233  "tracks");
1234  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
1235  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
1236  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
1237  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
1238  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
1239  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");
1240 
1241  // embedding of MET muon corrections
1242  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
1243  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer", "muCorrData"))
1244  ->setComment("source of MET muon corrections for caloMET");
1245  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
1246  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer", "muCorrData"))
1247  ->setComment("source of MET muon corrections for tcMET");
1248 
1249  // pf specific parameters
1250  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
1251  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
1252  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
1253  iDesc.add<bool>("embedPfEcalEnergy", true)->setComment("add ecal energy as reconstructed by PF");
1254 
1255  // inverse beta computation
1256  iDesc.add<bool>("addInverseBeta", true)->setComment("add combined inverse beta");
1257  iDesc.add<edm::InputTag>("sourceInverseBeta", edm::InputTag("muons", "combined"))
1258  ->setComment("source of inverse beta values");
1259 
1260  // MC matching configurables
1261  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
1262  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
1263  std::vector<edm::InputTag> emptySourceVector;
1264  iDesc
1265  .addNode(edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
1266  edm::ParameterDescription<std::vector<edm::InputTag>>("genParticleMatch", emptySourceVector, true))
1267  ->setComment("input with MC match information");
1268 
1269  // mini-iso
1270  iDesc.add<bool>("computeMiniIso", false)->setComment("whether or not to compute and store electron mini-isolation");
1271  iDesc.add<bool>("computePuppiCombinedIso", false)
1272  ->setComment("whether or not to compute and store puppi combined isolation");
1273 
1274  iDesc.add<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))
1275  ->setComment("collection to use to compute mini-iso");
1276  iDesc.add<std::vector<double>>("miniIsoParams", std::vector<double>())
1277  ->setComment("mini-iso parameters to use for muons");
1278 
1279  iDesc.add<bool>("addTriggerMatching", false)->setComment("add L1 and HLT matching to offline muon");
1280 
1282 
1283  // IsoDeposit configurables
1284  edm::ParameterSetDescription isoDepositsPSet;
1285  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
1286  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
1287  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
1288  isoDepositsPSet.addOptional<edm::InputTag>("particle");
1289  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
1290  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
1291  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
1292  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1293  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
1294  isoDepositsPSet.addOptional<std::vector<edm::InputTag>>("user");
1295  iDesc.addOptional("isoDeposits", isoDepositsPSet);
1296 
1297  // isolation values configurables
1298  edm::ParameterSetDescription isolationValuesPSet;
1299  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
1300  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
1301  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
1302  isolationValuesPSet.addOptional<edm::InputTag>("particle");
1303  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
1304  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
1305  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
1306  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1307  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
1308  iDesc.addOptional("isolationValues", isolationValuesPSet);
1309 
1310  iDesc.ifValue(edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
1312  "puppiIsolationChargedHadrons",
1313  edm::InputTag("muonPUPPIIsolation", "h+-DR030-ThresholdVeto000-ConeVeto000"),
1314  true) and
1316  "puppiIsolationNeutralHadrons",
1317  edm::InputTag("muonPUPPIIsolation", "h0-DR030-ThresholdVeto000-ConeVeto001"),
1318  true) and
1320  "puppiIsolationPhotons",
1321  edm::InputTag("muonPUPPIIsolation", "gamma-DR030-ThresholdVeto000-ConeVeto001"),
1322  true) and
1324  "puppiNoLeptonsIsolationChargedHadrons",
1325  edm::InputTag("muonPUPPINoLeptonsIsolation", "h+-DR030-ThresholdVeto000-ConeVeto000"),
1326  true) and
1328  "puppiNoLeptonsIsolationNeutralHadrons",
1329  edm::InputTag("muonPUPPINoLeptonsIsolation", "h0-DR030-ThresholdVeto000-ConeVeto001"),
1330  true) and
1332  "puppiNoLeptonsIsolationPhotons",
1333  edm::InputTag("muonPUPPINoLeptonsIsolation", "gamma-DR030-ThresholdVeto000-ConeVeto001"),
1334  true)) or
1335  false >> edm::EmptyGroupDescription());
1336 
1337  // Efficiency configurables
1338  edm::ParameterSetDescription efficienciesPSet;
1339  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
1340  iDesc.add("efficiencies", efficienciesPSet);
1341  iDesc.add<bool>("addEfficiencies", false);
1342 
1343  // Check to see if the user wants to add user data
1344  edm::ParameterSetDescription userDataPSet;
1346  iDesc.addOptional("userData", userDataPSet);
1347 
1348  edm::ParameterSetDescription isolationPSet;
1349  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
1350  iDesc.add("userIsolation", isolationPSet);
1351 
1352  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
1353  edm::ParameterSetDescription highLevelPSet;
1354  highLevelPSet.setAllowAnything();
1355  iDesc.addNode(edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true))
1356  ->setComment("input with high level selection");
1358  ->setComment("input with high level selection");
1359 
1360  //descriptions.add("PATMuonProducer", iDesc);
1361 }
1362 
1363 // embed various impact parameters with errors
1364 // embed high level selection
1369  bool primaryVertexIsValid,
1371  bool beamspotIsValid) {
1372  // Correct to PV
1373 
1374  // PV2D
1375  aMuon.setDB(track->dxy(primaryVertex.position()),
1376  track->dxyError(primaryVertex.position(), primaryVertex.covariance()),
1377  pat::Muon::PV2D);
1378 
1379  // PV3D
1380  std::pair<bool, Measurement1D> result =
1381  IPTools::signedImpactParameter3D(tt, GlobalVector(track->px(), track->py(), track->pz()), primaryVertex);
1382  double d0_corr = result.second.value();
1383  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1384  aMuon.setDB(d0_corr, d0_err, pat::Muon::PV3D);
1385 
1386  // Correct to beam spot
1387 
1388  // BS2D
1389  aMuon.setDB(track->dxy(beamspot), track->dxyError(beamspot), pat::Muon::BS2D);
1390 
1391  // make a fake vertex out of beam spot
1392  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
1393 
1394  // BS3D
1395  result = IPTools::signedImpactParameter3D(tt, GlobalVector(track->px(), track->py(), track->pz()), vBeamspot);
1396  d0_corr = result.second.value();
1397  d0_err = beamspotIsValid ? result.second.error() : -1.0;
1398  aMuon.setDB(d0_corr, d0_err, pat::Muon::BS3D);
1399 
1400  // PVDZ
1401  aMuon.setDB(
1402  track->dz(primaryVertex.position()), std::hypot(track->dzError(), primaryVertex.zError()), pat::Muon::PVDZ);
1403 }
1404 
1406 
bool embedTpfmsMuon_
embed track from tpfms muon fit into the muon
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_charged_hadrons_
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
bool useUserData_
add user data to the muon (this will be data members of th muon even w/o embedding) ...
void readIsolationLabels(const edm::ParameterSet &iConfig, const char *psetName, IsolationLabels &labels, std::vector< edm::EDGetTokenT< edm::ValueMap< T >>> &tokens)
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
bool isAvailable() const
Definition: Ref.h:537
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_photons_
double ecalEnergy() const
return corrected Ecal energy
Definition: PFCandidate.h:221
void setComment(std::string const &value)
Assists in assimilating all pat::UserData into pat objects.
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases)
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
bool addPuppiIsolation_
add puppi isolation
void embedDytMuon()
embed reference to the above dyt Track
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
void embedTpfmsMuon()
embed reference to the above tpfms Track
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > tcMETMuonCorrsToken_
source of tcMET muon corrections
void setIsolation(IsolationKeys key, float value)
Definition: Lepton.h:115
bool embedTcMETMuonCorrs_
embed muon MET correction info for tcMET into the muon
class definition
void embedTcMETMuonCorrs(const reco::MuonMETCorrectionData &t)
edm::EDGetTokenT< std::vector< reco::Vertex > > pvToken_
input source of the primary vertex
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37
double pt() const final
transverse momentum
static const int OTHER
edm::EDGetTokenT< edm::ValueMap< reco::MuonTimeExtra > > muonTimeExtraToken_
input tag for reading inverse beta
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_photons_
void embedCombinedMuon()
set reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon...
edm::EDGetTokenT< double > rho_
edm::EDGetTokenT< edm::View< reco::Muon > > muonToken_
input source
void embedTunePMuonBestTrack(bool force=false)
bool addEfficiencies_
add efficiencies to the muon (this will be data members of th muon even w/o embedding) ...
edm::EDGetTokenT< edm::ValueMap< reco::MuonMETCorrectionData > > caloMETMuonCorrsToken_
source of caloMET muon corrections
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
enum start value shifted to 81 so as to avoid clashes with PDG codes
void setAllowAnything()
allow any parameter label/value pairs
double zError() const
error on z
Definition: Vertex.h:141
void setSimFlavour(int f)
Definition: Muon.h:325
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
bool embedCaloMETMuonCorrs_
embed muon MET correction info for caloMET into the muon
bool isChargedHadron(long pdgid)
~PATMuonProducer() override
default destructur
edm::EDGetTokenT< edm::ValueMap< reco::MuonSimInfo > > simInfo_
MC info.
void embedMuonBestTrack(bool force=false)
std::vector< pat::PackedCandidate > PackedCandidateCollection
void setIsolationPUPPINoLeptons(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPINoLeptons isolations
Definition: Muon.h:207
void setMuonMiniIso(pat::Muon &aMuon, const pat::PackedCandidateCollection *pc)
reco::TransientTrack build(const reco::Track *p) const
PATMuonProducer(const edm::ParameterSet &iConfig, PATMuonHeavyObjectCache const *)
default constructir
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool addTriggerMatching_
Trigger.
void setSimBX(int bx)
Definition: Muon.h:329
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool embedBestTrack_
embed the track from best muon measurement (global pflow)
edm::EDGetTokenT< reco::JetCorrector > mvaL1Corrector_
std::pair< bool, Measurement1D > signedImpactParameter3D(const reco::TransientTrack &track, const GlobalVector &direction, const reco::Vertex &vertex)
Definition: IPTools.cc:81
const edm::ESGetToken< TransientTrackBuilder, TransientTrackRecord > transientTrackBuilderToken_
bool addResolutions_
add resolutions to the muon (this will be data members of th muon even w/o embedding) ...
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:148
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
void unpackPathNames(const edm::TriggerNames &names)
unpack trigger names into indices
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_charged_hadrons_
std::vector< double > miniIsoParams_
void setSimPhi(float phi)
Definition: Muon.h:335
Log< level::Error, false > LogError
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
void setSimProdRho(float rho)
Definition: Muon.h:331
void setSimHeaviestMotherFlavour(int id)
Definition: Muon.h:326
reco::Muon::Selector makeSelectorBitset(reco::Muon const &muon, reco::Vertex const *vertex=nullptr, bool run2016_hip_mitigation=false)
assert(be >=bs)
void setPFCandidateRef(const reco::PFCandidateRef &ref)
add a reference to the source IsolatedPFCandidate
Definition: Muon.h:141
bool isRealData() const
Definition: EventBase.h:62
const Point & position() const
position
Definition: Vertex.h:127
void embedHighLevel(pat::Muon &aMuon, reco::TrackRef track, reco::TransientTrack &tt, reco::Vertex &primaryVertex, bool primaryVertexIsValid, reco::BeamSpot &beamspot, bool beamspotIsValid)
std::vector< double > effectiveAreaVec_
ProductID id() const
Definition: RefToBase.h:214
const std::string names[nVars_]
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
void setSimType(reco::MuonSimType type)
Definition: Muon.h:323
void embedStandAloneMuon()
set reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
#define LogTrace(id)
edm::EDGetTokenT< reco::JetTagCollection > mvaBTagCollectionTag_
pat::MuonMvaEstimator const & muonMvaEstimator() const
edm::EDGetTokenT< reco::PFCandidateCollection > pfMuonToken_
input source pfCandidates that will be to be transformed into pat::Muons, when using PF2PAT ...
void setIsolationPUPPI(float chargedhadrons, float neutralhadrons, float photons)
sets PUPPI isolations
Definition: Muon.h:201
pat::helper::MultiIsolator isolator_
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
bool enabled() const
&#39;true&#39; if this there is at least one efficiency configured
tuple result
Definition: mps_fire.py:311
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
Definition: Lepton.h:191
void embedTrack()
set reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:275
static void fillDescription(edm::ParameterSetDescription &iDesc)
const PFIsolation & miniPFIsolation() const
Definition: Lepton.h:216
std::vector< IsolationLabel > IsolationLabels
edm::EDGetTokenT< reco::BeamSpot > beamLineToken_
input source of the primary vertex/beamspot
std::unique_ptr< const pat::MuonMvaEstimator > muonLowPtMvaEstimator_
bool getData(T &iHolder) const
Definition: EventSetup.h:128
bool addInverseBeta_
add combined inverse beta measurement into the muon
bool useParticleFlow_
switch to use particle flow (PF2PAT) or not
pat::PATUserDataHelper< pat::Muon > userDataHelper_
helper class to add userData to the muon
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:55
std::vector< edm::Handle< edm::ValueMap< IsoDeposit > > > IsoDepositMaps
char const * label
bool embedStandAloneMuon_
embed track from muon system into the muon
void setComment(std::string const &value)
edm::EDGetTokenT< edm::TriggerResults > triggerResults_
int iEvent
Definition: GenABIO.cc:224
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
pat::SoftMuonMvaEstimator const & softMuonMvaEstimator() const
bool embedTrack_
embed the track from inner tracker into the muon
void setDB(double dB, double edB, IPTYPE type=PV2D)
Definition: Muon.h:247
bool addGenMatch_
add generator match information
PATMuonHeavyObjectCache(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
description of config file parameters
void fillL1TriggerInfo(pat::Muon &muon, edm::Handle< std::vector< pat::TriggerObjectStandAlone >> &triggerObjects, const edm::TriggerNames &names, const edm::ESHandle< GlobalTrackingGeometry > &geometry)
double muonRelMiniIsoPUCorrected(const PFIsolation &iso, const reco::Candidate::PolarLorentzVector &p4, double dr, double rho, const std::vector< double > &area)
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > geometryToken_
bool embedPfEcalEnergy_
add ecal PF energy
void embedGenParticle()
Definition: PATObject.h:768
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
void embedPFCandidate()
embed the IsolatedPFCandidate pointed to by pfCandidateRef_
const PolarLorentzVector & polarP4() const final
four-momentum Lorentz vector
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
everything that needs to be done during the event loop
def move
Definition: eostools.py:511
std::unique_ptr< const pat::MuonMvaEstimator > muonMvaEstimator_
reco::PFCandidateRef pfCandidateRef() const
RunNumber_t run() const
Definition: Event.h:109
tuple key
prepare the HTCondor submission files and eventually submit them
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double relMiniIsoPUCorrected(const pat::Muon &aMuon, double rho)
edm::EDGetTokenT< pat::PackedCandidateCollection > pcToken_
std::pair< pat::IsolationKeys, edm::InputTag > IsolationLabel
static void globalEndJob(PATMuonHeavyObjectCache *)
static std::string const triggerResults
Definition: EdmProvDump.cc:44
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:70
double puppiCombinedIsolation(const pat::Muon &muon, const pat::PackedCandidateCollection *pc)
void readTimeExtra(const reco::MuonTimeExtra &t)
std::vector< std::string > hltCollectionFilters_
float miniIsoDr(const reco::Candidate::PolarLorentzVector &p4, float mindr, float maxdr, float kt_scale)
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:443
void fillHltTriggerInfo(pat::Muon &muon, edm::Handle< std::vector< pat::TriggerObjectStandAlone >> &triggerObjects, const edm::TriggerNames &names, const std::vector< std::string > &collection_names)
static std::unique_ptr< PATMuonHeavyObjectCache > initializeGlobalCache(const edm::ParameterSet &iConfig)
Definition: DetId.h:17
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
bool isAValidMuonTrack(const MuonTrackType &type) const
void initSimInfo(void)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void addGenParticleRef(const reco::GenParticleRef &ref)
Definition: PATObject.h:751
void setPfEcalEnergy(float pfEcalEnergy)
Definition: Muon.h:277
bool embedTunePBestTrack_
embed the track from best muon measurement (muon only)
T const * product() const
Definition: Handle.h:70
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:433
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
double getRelMiniIsoPUCorrected(const pat::Muon &muon, double rho, const std::vector< double > &area)
void setSimMotherPdgId(int id)
Definition: Muon.h:328
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
void addTriggerObjectMatch(const TriggerObjectStandAlone &trigObj)
add a trigger match
Definition: PATObject.h:238
void setExtSimType(reco::ExtendedMuonSimType type)
Definition: Muon.h:324
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:145
void setMiniPFIsolation(PFIsolation const &iso)
Definition: Lepton.h:217
std::unique_ptr< const pat::SoftMuonMvaEstimator > softMuonMvaEstimator_
std::vector< edm::Handle< edm::Association< reco::GenParticleCollection > > > GenAssociations
edm::EDGetTokenT< reco::JetCorrector > mvaL1L2L3ResCorrector_
void fillMuon(Muon &aMuon, const MuonBaseRef &muonRef, const reco::CandidateBaseRef &baseRef, const GenAssociations &genMatches, const IsoDepositMaps &deposits, const IsolationValueMaps &isolationValues) const
common muon filling, for both the standard and PF2PAT case
void setSimProdZ(float z)
Definition: Muon.h:332
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
std::vector< edm::Handle< edm::ValueMap< double > > > IsolationValueMaps
pat::helper::EfficiencyLoader efficiencyLoader_
helper class to add efficiencies to the muon
bool embedPickyMuon_
embed track from picky muon fit into the muon
void setNormChi2(double normChi2)
Definition: Muon.h:262
tuple muons
Definition: patZpeak.py:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
bool embedDytMuon_
embed track from DYT muon fit into the muon
void embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData &t)
void setSimPdgId(int id)
Definition: Muon.h:327
const edm::EDPutTokenT< std::vector< Muon > > patMuonPutToken_
void setSimPt(float pt)
Definition: Muon.h:333
Calculates a lepton&#39;s calorimetric isolation energy.
bool isPhoton(long pdgid)
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
isolation value pair for temporary storage before being folded into the muon
edm::EDGetTokenT< std::vector< pat::TriggerObjectStandAlone > > triggerObjects_
bool embedGenMatch_
embed the gen match information into the muon
const Point & position() const
position
Definition: BeamSpot.h:59
IsolationLabels isoDepositLabels_
input source for isoDeposits
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
input tags for generator match information
PFIsolation getMiniPFIsolation(const pat::PackedCandidateCollection *pfcands, const reco::Candidate::PolarLorentzVector &p4, float mindr=0.05, float maxdr=0.2, float kt_scale=10.0, float ptthresh=0.5, float deadcone_ch=0.0001, float deadcone_pu=0.01, float deadcone_ph=0.01, float deadcone_nh=0.01, float dZ_cut=0.0)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
Covariance3DMatrix rotatedCovariance3D() const
Definition: BeamSpot.cc:73
static constexpr int DT
Definition: MuonSubdetId.h:11
IsolationLabels isolationValueLabels_
input source isolation value maps
void embedPickyMuon()
embed reference to the above picky Track
double phi() const final
momentum azimuthal angle
static constexpr int CSC
Definition: MuonSubdetId.h:12
bool forceEmbedBestTrack_
force separate embed of the best track even if already embedded
edm::RefToBase< reco::Muon > MuonBaseRef
typedefs for convenience
bool embedPFCandidate_
embed pfCandidates into the muon
std::vector< edm::EDGetTokenT< edm::ValueMap< double > > > isolationValueTokens_
void setNumberOfValidHits(unsigned int numberOfValidHits)
Definition: Muon.h:255
bool computeMuonMVA_
standard muon selectors
void setSimEta(float eta)
Definition: Muon.h:334
bool embedCombinedMuon_
embed track of the combined fit into the muon
pat::MuonMvaEstimator const & muonLowPtMvaEstimator() const
Analysis-level muon class.
Definition: Muon.h:51
pat::helper::KinResolutionsLoader resolutionLoader_
helper class to add resolutions to the muon
static std::string const source
Definition: EdmProvDump.cc:46
bool isGlobalMuon() const override
Definition: Muon.h:299
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void setP4(const LorentzVector &p4) final
set 4-momentum
edm::EDGetTokenT< edm::ValueMap< float > > PUPPIIsolation_neutral_hadrons_
std::optional< GlobalPoint > getMuonDirection(const reco::MuonChamberMatch &chamberMatch, const edm::ESHandle< GlobalTrackingGeometry > &geometry, const DetId &chamberId)
bool isNeutralHadron(long pdgid)
Global3DVector GlobalVector
Definition: GlobalVector.h:10
Calculates a lepton&#39;s tracker isolation pt.
Analysis-level trigger object class (stand-alone)
void setSimMatchQuality(float quality)
Definition: Muon.h:336
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:84
tuple pfMuons
Definition: pfMuons_cff.py:8
void setSimTpEvent(int tpEvent)
Definition: Muon.h:330
bool embedHighLevelSelection_
embed high level selection variables
double eta() const final
momentum pseudorapidity