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 
54 
55 namespace pat {
56 
58  public:
60 
65 
66  private:
67  std::unique_ptr<const pat::MuonMvaEstimator> muonLowPtMvaEstimator_;
68  std::unique_ptr<const pat::MuonMvaEstimator> muonMvaEstimator_;
69  std::unique_ptr<const pat::MuonMvaIDEstimator> muonMvaIDEstimator_;
70  std::unique_ptr<const pat::SoftMuonMvaEstimator> softMuonMvaEstimator_;
71  };
72 
74  class TrackerIsolationPt;
75  class CaloIsolationEnergy;
76 
78  class PATMuonProducer : public edm::stream::EDProducer<edm::GlobalCache<PATMuonHeavyObjectCache>> {
79  public:
83  ~PATMuonProducer() override;
84 
85  static std::unique_ptr<PATMuonHeavyObjectCache> initializeGlobalCache(const edm::ParameterSet& iConfig) {
86  return std::make_unique<PATMuonHeavyObjectCache>(iConfig);
87  }
88 
90 
92  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
94  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
95 
96  private:
99  typedef std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> GenAssociations;
100  typedef std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> IsoDepositMaps;
101  typedef std::vector<edm::Handle<edm::ValueMap<double>>> IsolationValueMaps;
102  typedef std::pair<pat::IsolationKeys, edm::InputTag> IsolationLabel;
103  typedef std::vector<IsolationLabel> IsolationLabels;
104 
106  void fillMuon(Muon& aMuon,
107  const MuonBaseRef& muonRef,
108  const reco::CandidateBaseRef& baseRef,
109  const GenAssociations& genMatches,
110  const IsoDepositMaps& deposits,
111  const IsolationValueMaps& isolationValues) const;
114  template <typename T>
115  void readIsolationLabels(const edm::ParameterSet& iConfig,
116  const char* psetName,
119 
121  double getRelMiniIsoPUCorrected(const pat::Muon& muon, double rho, const std::vector<double>& area);
122 
124  bool isNeutralHadron(long pdgid);
125  bool isChargedHadron(long pdgid);
126  bool isPhoton(long pdgid);
127 
128  // embed various impact parameters with errors
129  // embed high level selection
130  void embedHighLevel(pat::Muon& aMuon,
134  bool primaryVertexIsValid,
136  bool beamspotIsValid);
137  double relMiniIsoPUCorrected(const pat::Muon& aMuon, double rho);
138  std::optional<GlobalPoint> getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
140  const DetId& chamberId);
142  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
143  const edm::TriggerNames& names,
146  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
147  const edm::TriggerNames& names,
148  const std::vector<std::string>& collection_names);
149 
150  private:
153 
154  // for mini-iso calculation
158  std::vector<double> effectiveAreaVec_;
159  std::vector<double> miniIsoParams_;
161 
195  std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>> genMatchTokens_;
216  std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit>>> isoDepositTokens_;
219  std::vector<edm::EDGetTokenT<edm::ValueMap<double>>> isolationValueTokens_;
228  //PUPPI isolation tokens
232  //PUPPINoLeptons isolation tokens
246 
256 
259 
264  std::vector<std::string> hltCollectionFilters_;
265 
268 
270  };
271 
272 } // namespace pat
273 
274 template <typename T>
276  const char* psetName,
279  labels.clear();
280 
281  if (iConfig.exists(psetName)) {
282  edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>(psetName);
283 
284  if (depconf.exists("tracker"))
285  labels.emplace_back(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker"));
286  if (depconf.exists("ecal"))
287  labels.emplace_back(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal"));
288  if (depconf.exists("hcal"))
289  labels.emplace_back(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal"));
290  if (depconf.exists("pfAllParticles")) {
291  labels.emplace_back(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles"));
292  }
293  if (depconf.exists("pfChargedHadrons")) {
294  labels.emplace_back(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons"));
295  }
296  if (depconf.exists("pfChargedAll")) {
297  labels.emplace_back(pat::PfChargedAllIso, depconf.getParameter<edm::InputTag>("pfChargedAll"));
298  }
299  if (depconf.exists("pfPUChargedHadrons")) {
300  labels.emplace_back(pat::PfPUChargedHadronIso, depconf.getParameter<edm::InputTag>("pfPUChargedHadrons"));
301  }
302  if (depconf.exists("pfNeutralHadrons")) {
303  labels.emplace_back(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons"));
304  }
305  if (depconf.exists("pfPhotons")) {
306  labels.emplace_back(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons"));
307  }
308  if (depconf.exists("user")) {
309  std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
310  std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
312  for (; it != ed; ++it, ++key) {
313  labels.push_back(std::make_pair(pat::IsolationKeys(key), *it));
314  }
315  tokens = edm::vector_transform(
316  labels, [this](IsolationLabel const& label) { return consumes<edm::ValueMap<T>>(label.second); });
317  }
318  }
319  tokens = edm::vector_transform(labels, [this](pat::PATMuonProducer::IsolationLabel const& label) {
320  return consumes<edm::ValueMap<T>>(label.second);
321  });
322 }
323 
324 using namespace pat;
325 using namespace std;
326 
328  if (iConfig.getParameter<bool>("computeMuonMVA")) {
329  edm::FileInPath mvaTrainingFile = iConfig.getParameter<edm::FileInPath>("mvaTrainingFile");
330  edm::FileInPath mvaLowPtTrainingFile = iConfig.getParameter<edm::FileInPath>("lowPtmvaTrainingFile");
331  float mvaDrMax = iConfig.getParameter<double>("mvaDrMax");
332  muonMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaTrainingFile, mvaDrMax);
333  muonLowPtMvaEstimator_ = std::make_unique<MuonMvaEstimator>(mvaLowPtTrainingFile, mvaDrMax);
334  }
335 
336  if (iConfig.getParameter<bool>("computeMuonIDMVA")) {
337  edm::FileInPath mvaIDTrainingFile = iConfig.getParameter<edm::FileInPath>("mvaIDTrainingFile");
338  muonMvaIDEstimator_ = std::make_unique<MuonMvaIDEstimator>(mvaIDTrainingFile);
339  }
340 
341  if (iConfig.getParameter<bool>("computeSoftMuonMVA")) {
342  edm::FileInPath softMvaTrainingFile = iConfig.getParameter<edm::FileInPath>("softMvaTrainingFile");
343  softMuonMvaEstimator_ = std::make_unique<SoftMuonMvaEstimator>(softMvaTrainingFile);
344  }
345 }
346 
348  : relMiniIsoPUCorrected_(0),
349  useUserData_(iConfig.exists("userData")),
350  computeMuonMVA_(false),
351  computeMuonIDMVA_(false),
352  computeSoftMuonMVA_(false),
353  recomputeBasicSelectors_(false),
354  mvaUseJec_(false),
355  isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation")
356  : edm::ParameterSet(),
357  consumesCollector(),
358  false),
359  geometryToken_{esConsumes()},
360  transientTrackBuilderToken_{esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))},
361  patMuonPutToken_{produces<std::vector<Muon>>()} {
362  // input source
363  muonToken_ = consumes<edm::View<reco::Muon>>(iConfig.getParameter<edm::InputTag>("muonSource"));
364  // embedding of tracks
365  embedBestTrack_ = iConfig.getParameter<bool>("embedMuonBestTrack");
366  embedTunePBestTrack_ = iConfig.getParameter<bool>("embedTunePMuonBestTrack");
367  forceEmbedBestTrack_ = iConfig.getParameter<bool>("forceBestTrackEmbedding");
368  embedTrack_ = iConfig.getParameter<bool>("embedTrack");
369  embedCombinedMuon_ = iConfig.getParameter<bool>("embedCombinedMuon");
370  embedStandAloneMuon_ = iConfig.getParameter<bool>("embedStandAloneMuon");
371  // embedding of muon MET correction information
372  embedCaloMETMuonCorrs_ = iConfig.getParameter<bool>("embedCaloMETMuonCorrs");
373  embedTcMETMuonCorrs_ = iConfig.getParameter<bool>("embedTcMETMuonCorrs");
374  caloMETMuonCorrsToken_ =
375  mayConsume<edm::ValueMap<reco::MuonMETCorrectionData>>(iConfig.getParameter<edm::InputTag>("caloMETMuonCorrs"));
376  tcMETMuonCorrsToken_ =
377  mayConsume<edm::ValueMap<reco::MuonMETCorrectionData>>(iConfig.getParameter<edm::InputTag>("tcMETMuonCorrs"));
378  // pflow specific configurables
379  useParticleFlow_ = iConfig.getParameter<bool>("useParticleFlow");
380  embedPFCandidate_ = iConfig.getParameter<bool>("embedPFCandidate");
381  pfMuonToken_ = mayConsume<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfMuonSource"));
382  embedPfEcalEnergy_ = iConfig.getParameter<bool>("embedPfEcalEnergy");
383  // embedding of tracks from TeV refit
384  embedPickyMuon_ = iConfig.getParameter<bool>("embedPickyMuon");
385  embedTpfmsMuon_ = iConfig.getParameter<bool>("embedTpfmsMuon");
386  embedDytMuon_ = iConfig.getParameter<bool>("embedDytMuon");
387  // embedding of inverse beta variable information
388  addInverseBeta_ = iConfig.getParameter<bool>("addInverseBeta");
389  if (addInverseBeta_) {
390  muonTimeExtraToken_ =
391  consumes<edm::ValueMap<reco::MuonTimeExtra>>(iConfig.getParameter<edm::InputTag>("sourceMuonTimeExtra"));
392  }
393  // Monte Carlo matching
394  addGenMatch_ = iConfig.getParameter<bool>("addGenMatch");
395  if (addGenMatch_) {
396  embedGenMatch_ = iConfig.getParameter<bool>("embedGenMatch");
397  if (iConfig.existsAs<edm::InputTag>("genParticleMatch")) {
398  genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection>>(
399  iConfig.getParameter<edm::InputTag>("genParticleMatch")));
400  } else {
401  genMatchTokens_ = edm::vector_transform(
402  iConfig.getParameter<std::vector<edm::InputTag>>("genParticleMatch"),
403  [this](edm::InputTag const& tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
404  }
405  }
406  // efficiencies
407  addEfficiencies_ = iConfig.getParameter<bool>("addEfficiencies");
408  if (addEfficiencies_) {
409  efficiencyLoader_ =
410  pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
411  }
412  // resolutions
413  addResolutions_ = iConfig.getParameter<bool>("addResolutions");
414  if (addResolutions_) {
415  resolutionLoader_ =
416  pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"), consumesCollector());
417  }
418  // puppi
419  addPuppiIsolation_ = iConfig.getParameter<bool>("addPuppiIsolation");
420  if (addPuppiIsolation_) {
421  PUPPIIsolation_charged_hadrons_ =
422  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
423  PUPPIIsolation_neutral_hadrons_ =
424  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
425  PUPPIIsolation_photons_ =
426  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
427  //puppiNoLeptons
428  PUPPINoLeptonsIsolation_charged_hadrons_ =
429  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
430  PUPPINoLeptonsIsolation_neutral_hadrons_ =
431  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
432  PUPPINoLeptonsIsolation_photons_ =
433  consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
434  }
435  // read isoDeposit labels, for direct embedding
436  readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
437  // read isolation value labels, for direct embedding
438  readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_, isolationValueTokens_);
439  // check to see if the user wants to add user data
440  if (useUserData_) {
441  userDataHelper_ = PATUserDataHelper<Muon>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
442  }
443  // embed high level selection variables
444  embedHighLevelSelection_ = iConfig.getParameter<bool>("embedHighLevelSelection");
445  if (embedHighLevelSelection_) {
446  beamLineToken_ = consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"));
447  pvToken_ = consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvSrc"));
448  }
449 
450  //for mini-isolation calculation
451  computeMiniIso_ = iConfig.getParameter<bool>("computeMiniIso");
452 
453  computePuppiCombinedIso_ = iConfig.getParameter<bool>("computePuppiCombinedIso");
454 
455  effectiveAreaVec_ = iConfig.getParameter<std::vector<double>>("effectiveAreaVec");
456 
457  miniIsoParams_ = iConfig.getParameter<std::vector<double>>("miniIsoParams");
458  if (computeMiniIso_ && miniIsoParams_.size() != 9) {
459  throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 9 elements.\n";
460  }
461  if (computeMiniIso_ || computePuppiCombinedIso_)
462  pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
463 
464  // standard selectors
465  recomputeBasicSelectors_ = iConfig.getParameter<bool>("recomputeBasicSelectors");
466  computeMuonMVA_ = iConfig.getParameter<bool>("computeMuonMVA");
467  computeMuonIDMVA_ = iConfig.getParameter<bool>("computeMuonIDMVA");
468  if (computeMuonMVA_ and not computeMiniIso_)
469  throw cms::Exception("ConfigurationError") << "MiniIso is needed for Muon MVA calculation.\n";
470 
471  if (computeMuonMVA_) {
472  // pfCombinedInclusiveSecondaryVertexV2BJetTags
473  mvaBTagCollectionTag_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("mvaJetTag"));
474  mvaL1Corrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1Corrector"));
475  mvaL1L2L3ResCorrector_ = consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("mvaL1L2L3ResCorrector"));
476  rho_ = consumes<double>(iConfig.getParameter<edm::InputTag>("rho"));
477  mvaUseJec_ = iConfig.getParameter<bool>("mvaUseJec");
478  }
479 
480  computeSoftMuonMVA_ = iConfig.getParameter<bool>("computeSoftMuonMVA");
481 
482  // MC info
483  simInfo_ = consumes<edm::ValueMap<reco::MuonSimInfo>>(iConfig.getParameter<edm::InputTag>("muonSimInfo"));
484 
485  addTriggerMatching_ = iConfig.getParameter<bool>("addTriggerMatching");
486  if (addTriggerMatching_) {
487  triggerObjects_ =
488  consumes<std::vector<pat::TriggerObjectStandAlone>>(iConfig.getParameter<edm::InputTag>("triggerObjects"));
489  triggerResults_ = consumes<edm::TriggerResults>(iConfig.getParameter<edm::InputTag>("triggerResults"));
490  }
491  hltCollectionFilters_ = iConfig.getParameter<std::vector<std::string>>("hltCollectionFilters");
492 }
493 
495 
496 std::optional<GlobalPoint> PATMuonProducer::getMuonDirection(const reco::MuonChamberMatch& chamberMatch,
498  const DetId& chamberId) {
499  const GeomDet* chamberGeometry = geometry->idToDet(chamberId);
500  if (chamberGeometry) {
501  LocalPoint localPosition(chamberMatch.x, chamberMatch.y, 0);
502  return std::optional<GlobalPoint>(std::in_place, chamberGeometry->toGlobal(localPosition));
503  }
504  return std::optional<GlobalPoint>();
505 }
506 
508  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
509  const edm::TriggerNames& names,
511  // L1 trigger object parameters are defined at MB2/ME2. Use the muon
512  // chamber matching information to get the local direction of the
513  // muon trajectory and convert it to a global direction to match the
514  // trigger objects
515 
516  std::optional<GlobalPoint> muonPosition;
517  // Loop over chambers
518  // initialize muonPosition with any available match, just in case
519  // the second station is missing - it's better folling back to
520  // dR matching at IP
521  for (const auto& chamberMatch : aMuon.matches()) {
522  if (chamberMatch.id.subdetId() == MuonSubdetId::DT) {
523  DTChamberId detId(chamberMatch.id.rawId());
524  if (abs(detId.station()) > 3)
525  continue;
526  muonPosition = getMuonDirection(chamberMatch, geometry, detId);
527  if (abs(detId.station()) == 2)
528  break;
529  }
530  if (chamberMatch.id.subdetId() == MuonSubdetId::CSC) {
531  CSCDetId detId(chamberMatch.id.rawId());
532  if (abs(detId.station()) > 3)
533  continue;
534  muonPosition = getMuonDirection(chamberMatch, geometry, detId);
535  if (abs(detId.station()) == 2)
536  break;
537  }
538  }
539  if (not muonPosition)
540  return;
541  for (const auto& triggerObject : *triggerObjects) {
542  if (triggerObject.hasTriggerObjectType(trigger::TriggerL1Mu)) {
543  if (std::abs(triggerObject.eta()) < 0.001) {
544  // L1 is defined in X-Y plain
545  if (deltaPhi(triggerObject.phi(), muonPosition->phi()) > 0.1)
546  continue;
547  } else {
548  // 3D L1
549  if (deltaR(triggerObject.p4(), *muonPosition) > 0.15)
550  continue;
551  }
552  pat::TriggerObjectStandAlone obj(triggerObject);
553  obj.unpackPathNames(names);
554  aMuon.addTriggerObjectMatch(obj);
555  }
556  }
557 }
558 
560  edm::Handle<std::vector<pat::TriggerObjectStandAlone>>& triggerObjects,
561  const edm::TriggerNames& names,
562  const std::vector<std::string>& collection_filter_names) {
563  // WARNING: in a case of close-by muons the dR matching may select both muons.
564  // It's better to select the best match for a given collection.
565  for (const auto& triggerObject : *triggerObjects) {
566  if (triggerObject.hasTriggerObjectType(trigger::TriggerMuon)) {
567  bool keepIt = false;
568  for (const auto& name : collection_filter_names) {
569  if (triggerObject.hasCollection(name)) {
570  keepIt = true;
571  break;
572  }
573  }
574  if (not keepIt)
575  continue;
576  if (deltaR(triggerObject.p4(), muon) > 0.1)
577  continue;
578  pat::TriggerObjectStandAlone obj(triggerObject);
579  obj.unpackPathNames(names);
580  muon.addTriggerObjectMatch(obj);
581  }
582  }
583 }
584 
586  // get the tracking Geometry
587  auto geometry = iSetup.getHandle(geometryToken_);
588  if (!geometry.isValid())
589  throw cms::Exception("FatalError") << "Unable to find GlobalTrackingGeometryRecord in event!\n";
590 
591  // switch off embedding (in unschedules mode)
592  if (iEvent.isRealData()) {
593  addGenMatch_ = false;
594  embedGenMatch_ = false;
595  }
596 
598  iEvent.getByToken(muonToken_, muons);
599 
602  iEvent.getByToken(pcToken_, pc);
603 
604  // get the ESHandle for the transient track builder,
605  // if needed for high level selection embedding
606  TransientTrackBuilder const* trackBuilder = nullptr;
607 
608  if (isolator_.enabled())
609  isolator_.beginEvent(iEvent, iSetup);
611  efficiencyLoader_.newEvent(iEvent);
613  resolutionLoader_.newEvent(iEvent, iSetup);
614 
615  IsoDepositMaps deposits(isoDepositTokens_.size());
616  for (size_t j = 0; j < isoDepositTokens_.size(); ++j) {
617  iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
618  }
619 
620  IsolationValueMaps isolationValues(isolationValueTokens_.size());
621  for (size_t j = 0; j < isolationValueTokens_.size(); ++j) {
622  iEvent.getByToken(isolationValueTokens_[j], isolationValues[j]);
623  }
624 
625  //value maps for puppi isolation
626  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
627  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
628  edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
629  //value maps for puppiNoLeptons isolation
630  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
631  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
632  edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
633  if (addPuppiIsolation_) {
634  //puppi
635  iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
636  iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
637  iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
638  //puppiNoLeptons
639  iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
640  iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
641  iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
642  }
643 
644  // inputs for muon mva
645  edm::Handle<reco::JetTagCollection> mvaBTagCollectionTag;
646  edm::Handle<reco::JetCorrector> mvaL1Corrector;
647  edm::Handle<reco::JetCorrector> mvaL1L2L3ResCorrector;
648  if (computeMuonMVA_) {
649  iEvent.getByToken(mvaBTagCollectionTag_, mvaBTagCollectionTag);
650  iEvent.getByToken(mvaL1Corrector_, mvaL1Corrector);
651  iEvent.getByToken(mvaL1L2L3ResCorrector_, mvaL1L2L3ResCorrector);
652  }
653 
654  // prepare the MC genMatchTokens_
655  GenAssociations genMatches(genMatchTokens_.size());
656  if (addGenMatch_) {
657  for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
658  iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
659  }
660  }
661 
662  // prepare the high level selection: needs beamline
663  // OR primary vertex, depending on user selection
666  bool beamSpotIsValid = false;
667  bool primaryVertexIsValid = false;
669  // get the beamspot
670  edm::Handle<reco::BeamSpot> beamSpotHandle;
671  iEvent.getByToken(beamLineToken_, beamSpotHandle);
672 
673  // get the primary vertex
675  iEvent.getByToken(pvToken_, pvHandle);
676 
677  if (beamSpotHandle.isValid()) {
678  beamSpot = *beamSpotHandle;
679  beamSpotIsValid = true;
680  } else {
681  edm::LogError("DataNotAvailable") << "No beam spot available from EventSetup, not adding high level selection \n";
682  }
683  if (pvHandle.isValid() && !pvHandle->empty()) {
684  primaryVertex = pvHandle->at(0);
685  primaryVertexIsValid = true;
686  } else {
687  edm::LogError("DataNotAvailable")
688  << "No primary vertex available from EventSetup, not adding high level selection \n";
689  }
690  // this is needed by the IPTools methods from the tracking group
691  trackBuilder = &iSetup.getData(transientTrackBuilderToken_);
692  }
693 
694  // MC info
696  bool simInfoIsAvailalbe = iEvent.getByToken(simInfo_, simInfo);
697 
698  // this will be the new object collection
699  std::vector<Muon> patMuons;
700 
702  if (useParticleFlow_) {
703  // get the PFCandidates of type muons
704  iEvent.getByToken(pfMuonToken_, pfMuons);
705 
706  unsigned index = 0;
707  for (reco::PFCandidateConstIterator i = pfMuons->begin(); i != pfMuons->end(); ++i, ++index) {
708  const reco::PFCandidate& pfmu = *i;
709  //const reco::IsolaPFCandidate& pfmu = *i;
710  const reco::MuonRef& muonRef = pfmu.muonRef();
711  assert(muonRef.isNonnull());
712 
713  MuonBaseRef muonBaseRef(muonRef);
714  Muon aMuon(muonBaseRef);
715 
716  if (useUserData_) {
717  userDataHelper_.add(aMuon, iEvent, iSetup);
718  }
719 
720  // embed high level selection
722  // get the tracks
723  reco::TrackRef innerTrack = muonBaseRef->innerTrack();
724  reco::TrackRef globalTrack = muonBaseRef->globalTrack();
725  reco::TrackRef bestTrack = muonBaseRef->muonBestTrack();
726  reco::TrackRef chosenTrack = innerTrack;
727  // Make sure the collection it points to is there
728  if (bestTrack.isNonnull() && bestTrack.isAvailable())
729  chosenTrack = bestTrack;
730 
731  if (chosenTrack.isNonnull() && chosenTrack.isAvailable()) {
732  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
733  aMuon.setNumberOfValidHits(nhits);
734 
735  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
736  embedHighLevel(aMuon, chosenTrack, tt, primaryVertex, primaryVertexIsValid, beamSpot, beamSpotIsValid);
737  }
738 
739  if (globalTrack.isNonnull() && globalTrack.isAvailable() && !embedCombinedMuon_) {
740  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
741  aMuon.setNormChi2(norm_chi2);
742  }
743  }
744  reco::PFCandidateRef pfRef(pfMuons, index);
745  //reco::PFCandidatePtr ptrToMother(pfMuons,index);
746  reco::CandidateBaseRef pfBaseRef(pfRef);
747 
748  aMuon.setPFCandidateRef(pfRef);
749  if (embedPFCandidate_)
750  aMuon.embedPFCandidate();
751  fillMuon(aMuon, muonBaseRef, pfBaseRef, genMatches, deposits, isolationValues);
752 
753  if (computeMiniIso_)
754  setMuonMiniIso(aMuon, pc.product());
755 
756  if (addPuppiIsolation_) {
757  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonBaseRef],
758  (*PUPPIIsolation_neutral_hadrons)[muonBaseRef],
759  (*PUPPIIsolation_photons)[muonBaseRef]);
760 
761  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonBaseRef],
762  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonBaseRef],
763  (*PUPPINoLeptonsIsolation_photons)[muonBaseRef]);
764  } else {
765  aMuon.setIsolationPUPPI(-999., -999., -999.);
766  aMuon.setIsolationPUPPINoLeptons(-999., -999., -999.);
767  }
768 
769  if (embedPfEcalEnergy_) {
770  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
771  }
772 
773  patMuons.push_back(aMuon);
774  }
775  } else {
777  iEvent.getByToken(muonToken_, muons);
778 
779  // embedding of muon MET corrections
781  //edm::ValueMap<reco::MuonMETCorrectionData> caloMETmuCorValueMap;
783  iEvent.getByToken(caloMETMuonCorrsToken_, caloMETMuonCorrs);
784  //caloMETmuCorValueMap = *caloMETmuCorValueMap_h;
785  }
787  //edm::ValueMap<reco::MuonMETCorrectionData> tcMETmuCorValueMap;
788  if (embedTcMETMuonCorrs_) {
789  iEvent.getByToken(tcMETMuonCorrsToken_, tcMETMuonCorrs);
790  //tcMETmuCorValueMap = *tcMETmuCorValueMap_h;
791  }
792 
794  // get the PFCandidates of type muons
795  iEvent.getByToken(pfMuonToken_, pfMuons);
796  }
797 
799  if (addInverseBeta_) {
800  // get MuonTimerExtra value map
801  iEvent.getByToken(muonTimeExtraToken_, muonsTimeExtra);
802  }
803 
804  for (edm::View<reco::Muon>::const_iterator itMuon = muons->begin(); itMuon != muons->end(); ++itMuon) {
805  // construct the Muon from the ref -> save ref to original object
806  unsigned int idx = itMuon - muons->begin();
807  MuonBaseRef muonRef = muons->refAt(idx);
808  reco::CandidateBaseRef muonBaseRef(muonRef);
809 
810  Muon aMuon(muonRef);
811  fillMuon(aMuon, muonRef, muonBaseRef, genMatches, deposits, isolationValues);
812  if (computeMiniIso_)
813  setMuonMiniIso(aMuon, pc.product());
814  if (addPuppiIsolation_) {
815  aMuon.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[muonRef],
816  (*PUPPIIsolation_neutral_hadrons)[muonRef],
817  (*PUPPIIsolation_photons)[muonRef]);
818  aMuon.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[muonRef],
819  (*PUPPINoLeptonsIsolation_neutral_hadrons)[muonRef],
820  (*PUPPINoLeptonsIsolation_photons)[muonRef]);
821  } else {
822  aMuon.setIsolationPUPPI(-999., -999., -999.);
823  aMuon.setIsolationPUPPINoLeptons(-999., -999., -999.);
824  }
825 
826  // Isolation
827  if (isolator_.enabled()) {
828  //reco::CandidatePtr mother = ptrToMother->sourceCandidatePtr(0);
829  isolator_.fill(*muons, idx, isolatorTmpStorage_);
830  typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
831  // better to loop backwards, so the vector is resized less times
832  for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
833  ed = isolatorTmpStorage_.rend();
834  it != ed;
835  ++it) {
836  aMuon.setIsolation(it->first, it->second);
837  }
838  }
839 
840  // for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
841  // aMuon.setIsoDeposit(isoDepositLabels_[j].first,
842  // (*deposits[j])[muonRef]);
843  // }
844 
845  // add sel to selected
846  edm::Ptr<reco::Muon> muonsPtr = muons->ptrAt(idx);
847  if (useUserData_) {
848  userDataHelper_.add(aMuon, iEvent, iSetup);
849  }
850 
851  // embed high level selection
853  // get the tracks
854  reco::TrackRef innerTrack = itMuon->innerTrack();
855  reco::TrackRef globalTrack = itMuon->globalTrack();
856  reco::TrackRef bestTrack = itMuon->muonBestTrack();
857  reco::TrackRef chosenTrack = innerTrack;
858  // Make sure the collection it points to is there
859  if (bestTrack.isNonnull() && bestTrack.isAvailable())
860  chosenTrack = bestTrack;
861  if (chosenTrack.isNonnull() && chosenTrack.isAvailable()) {
862  unsigned int nhits = chosenTrack->numberOfValidHits(); // ????
863  aMuon.setNumberOfValidHits(nhits);
864 
865  reco::TransientTrack tt = trackBuilder->build(chosenTrack);
866  embedHighLevel(aMuon, chosenTrack, tt, primaryVertex, primaryVertexIsValid, beamSpot, beamSpotIsValid);
867  }
868 
869  if (globalTrack.isNonnull() && globalTrack.isAvailable()) {
870  double norm_chi2 = globalTrack->chi2() / globalTrack->ndof();
871  aMuon.setNormChi2(norm_chi2);
872  }
873  }
874 
875  // embed MET muon corrections
877  aMuon.embedCaloMETMuonCorrs((*caloMETMuonCorrs)[muonRef]);
879  aMuon.embedTcMETMuonCorrs((*tcMETMuonCorrs)[muonRef]);
880 
882  if (embedPfEcalEnergy_)
883  aMuon.setPfEcalEnergy(-99.0);
884  unsigned index = 0;
885  for (const reco::PFCandidate& pfmu : *pfMuons) {
886  if (pfmu.muonRef().isNonnull()) {
887  if (pfmu.muonRef().id() != muonRef.id())
888  throw cms::Exception("Configuration")
889  << "Muon reference within PF candidates does not point to the muon collection." << std::endl;
890  if (pfmu.muonRef().key() == muonRef.key()) {
891  reco::PFCandidateRef pfRef(pfMuons, index);
892  aMuon.setPFCandidateRef(pfRef);
893  if (embedPfEcalEnergy_)
894  aMuon.setPfEcalEnergy(pfmu.ecalEnergy());
895  if (embedPFCandidate_)
896  aMuon.embedPFCandidate();
897  break;
898  }
899  }
900  index++;
901  }
902  }
903 
904  if (addInverseBeta_) {
905  aMuon.readTimeExtra((*muonsTimeExtra)[muonRef]);
906  }
907  // MC info
908  aMuon.initSimInfo();
909  if (simInfoIsAvailalbe) {
910  const auto& msi = (*simInfo)[muonBaseRef];
911  aMuon.setSimType(msi.primaryClass);
912  aMuon.setExtSimType(msi.extendedClass);
913  aMuon.setSimFlavour(msi.flavour);
914  aMuon.setSimHeaviestMotherFlavour(msi.heaviestMotherFlavour);
915  aMuon.setSimPdgId(msi.pdgId);
916  aMuon.setSimMotherPdgId(msi.motherPdgId);
917  aMuon.setSimBX(msi.tpBX);
918  aMuon.setSimTpEvent(msi.tpEvent);
919  aMuon.setSimProdRho(msi.vertex.Rho());
920  aMuon.setSimProdZ(msi.vertex.Z());
921  aMuon.setSimPt(msi.p4.pt());
922  aMuon.setSimEta(msi.p4.eta());
923  aMuon.setSimPhi(msi.p4.phi());
924  aMuon.setSimMatchQuality(msi.tpAssoQuality);
925  }
926  patMuons.push_back(aMuon);
927  }
928  }
929 
930  // sort muons in pt
931  std::sort(patMuons.begin(), patMuons.end(), [](auto const& t1, auto const& t2) { return t1.pt() > t2.pt(); });
932 
933  // Store standard muon selection decisions and jet related
934  // quantaties.
935  // Need a separate loop over muons to have all inputs properly
936  // computed and stored in the object.
938  if (computeMuonMVA_)
939  iEvent.getByToken(rho_, rho);
940  const reco::Vertex* pv(nullptr);
941  if (primaryVertexIsValid)
942  pv = &primaryVertex;
943 
946  bool triggerObjectsAvailable = false;
947  bool triggerResultsAvailable = false;
948  if (addTriggerMatching_) {
949  triggerObjectsAvailable = iEvent.getByToken(triggerObjects_, triggerObjects);
950  triggerResultsAvailable = iEvent.getByToken(triggerResults_, triggerResults);
951  }
952 
953  for (auto& muon : patMuons) {
954  // trigger info
955  if (addTriggerMatching_ and triggerObjectsAvailable and triggerResultsAvailable) {
956  const edm::TriggerNames& triggerNames(iEvent.triggerNames(*triggerResults));
957  fillL1TriggerInfo(muon, triggerObjects, triggerNames, geometry);
959  }
960 
962  muon.setSelectors(0);
963  bool isRun2016BCDEF = (272728 <= iEvent.run() && iEvent.run() <= 278808);
964  muon.setSelectors(muon::makeSelectorBitset(muon, pv, isRun2016BCDEF));
965  }
966  float miniIsoValue = -1;
967  if (computeMiniIso_) {
968  // MiniIsolation working points
969 
970  miniIsoValue = getRelMiniIsoPUCorrected(muon, *rho, effectiveAreaVec_);
971 
972  muon.setSelector(reco::Muon::MiniIsoLoose, miniIsoValue < 0.40);
973  muon.setSelector(reco::Muon::MiniIsoMedium, miniIsoValue < 0.20);
974  muon.setSelector(reco::Muon::MiniIsoTight, miniIsoValue < 0.10);
975  muon.setSelector(reco::Muon::MiniIsoVeryTight, miniIsoValue < 0.05);
976  }
977 
978  double puppiCombinedIsolationPAT = -1;
980  puppiCombinedIsolationPAT = puppiCombinedIsolation(muon, pc.product());
981  muon.setSelector(reco::Muon::PuppiIsoLoose, puppiCombinedIsolationPAT < 0.27);
982  muon.setSelector(reco::Muon::PuppiIsoMedium, puppiCombinedIsolationPAT < 0.22);
983  muon.setSelector(reco::Muon::PuppiIsoTight, puppiCombinedIsolationPAT < 0.12);
984  }
985 
986  float jetPtRatio = 0.0;
987  float jetPtRel = 0.0;
988  float mva = 0.0;
989  float mva_lowpt = 0.0;
990  if (computeMuonMVA_ && primaryVertexIsValid && computeMiniIso_) {
991  if (mvaUseJec_) {
992  mva = globalCache()->muonMvaEstimator().computeMva(muon,
993  primaryVertex,
994  *(mvaBTagCollectionTag.product()),
995  jetPtRatio,
996  jetPtRel,
997  miniIsoValue,
998  mvaL1Corrector.product(),
999  mvaL1L2L3ResCorrector.product());
1000  mva_lowpt = globalCache()->muonLowPtMvaEstimator().computeMva(muon,
1001  primaryVertex,
1002  *(mvaBTagCollectionTag.product()),
1003  jetPtRatio,
1004  jetPtRel,
1005  miniIsoValue,
1006  mvaL1Corrector.product(),
1007  mvaL1L2L3ResCorrector.product());
1008 
1009  } else {
1010  mva = globalCache()->muonMvaEstimator().computeMva(
1011  muon, primaryVertex, *mvaBTagCollectionTag, jetPtRatio, jetPtRel, miniIsoValue);
1012  mva_lowpt = globalCache()->muonLowPtMvaEstimator().computeMva(
1013  muon, primaryVertex, *mvaBTagCollectionTag, jetPtRatio, jetPtRel, miniIsoValue);
1014  }
1015 
1016  muon.setMvaValue(mva);
1017  muon.setLowPtMvaValue(mva_lowpt);
1018  muon.setJetPtRatio(jetPtRatio);
1019  muon.setJetPtRel(jetPtRel);
1020 
1021  // multi-isolation
1022  if (computeMiniIso_) {
1023  muon.setSelector(reco::Muon::MultiIsoMedium,
1024  miniIsoValue < 0.11 && (muon.jetPtRatio() > 0.74 || muon.jetPtRel() > 6.8));
1025  }
1026 
1027  // MVA working points
1028  // https://twiki.cern.ch/twiki/bin/viewauth/CMS/LeptonMVA
1029  const double dB2D = std::abs(muon.dB(pat::Muon::PV2D));
1030  const double dB3D = std::abs(muon.dB(pat::Muon::PV3D));
1031  const double edB3D = std::abs(muon.edB(pat::Muon::PV3D));
1032  const double sip3D = edB3D > 0 ? dB3D / edB3D : 0.0;
1033  const double dz = std::abs(muon.muonBestTrack()->dz(primaryVertex.position()));
1034 
1035  // muon preselection
1036  if (muon.pt() > 5 and muon.isLooseMuon() and muon.passed(reco::Muon::MiniIsoLoose) and sip3D < 8.0 and
1037  dB2D < 0.05 and dz < 0.1) {
1038  muon.setSelector(reco::Muon::MvaLoose, muon.mvaValue() > -0.60);
1039  muon.setSelector(reco::Muon::MvaMedium, muon.mvaValue() > -0.20);
1040  muon.setSelector(reco::Muon::MvaTight, muon.mvaValue() > 0.15);
1041  muon.setSelector(reco::Muon::MvaVTight, muon.mvaValue() > 0.45);
1042  muon.setSelector(reco::Muon::MvaVVTight, muon.mvaValue() > 0.9);
1043  }
1044  if (muon.pt() > 5 and muon.isLooseMuon() and sip3D < 4 and dB2D < 0.5 and dz < 1) {
1045  muon.setSelector(reco::Muon::LowPtMvaLoose, muon.lowptMvaValue() > -0.60);
1046  muon.setSelector(reco::Muon::LowPtMvaMedium, muon.lowptMvaValue() > -0.20);
1047  }
1048  }
1049 
1050  // MVA ID
1051  float mvaID = 0.0;
1052  constexpr int MVAsentinelValue = -99;
1053  constexpr float mvaIDmediumCut = 0.08;
1054  constexpr float mvaIDtightCut = 0.49;
1055  if (computeMuonIDMVA_) {
1056  if (muon.isLooseMuon()) {
1057  mvaID = globalCache()->muonMvaIDEstimator().computeMVAID(muon)[1];
1058  } else {
1059  mvaID = MVAsentinelValue;
1060  }
1061  muon.setMvaIDValue(mvaID);
1062  muon.setSelector(reco::Muon::MvaIDwpMedium, muon.mvaIDValue() > mvaIDmediumCut);
1063  muon.setSelector(reco::Muon::MvaIDwpTight, muon.mvaIDValue() > mvaIDtightCut);
1064  }
1065 
1066  //SOFT MVA
1067  if (computeSoftMuonMVA_) {
1068  float mva = globalCache()->softMuonMvaEstimator().computeMva(muon);
1069  muon.setSoftMvaValue(mva);
1070  //preselection in SoftMuonMvaEstimator.cc
1071  muon.setSelector(reco::Muon::SoftMvaId, muon.softMvaValue() > 0.58); //WP choose for bmm4
1072  }
1073  }
1074 
1075  // put products in Event
1076  iEvent.emplace(patMuonPutToken_, std::move(patMuons));
1077 
1078  if (isolator_.enabled())
1079  isolator_.endEvent();
1080 }
1081 
1083  const MuonBaseRef& muonRef,
1084  const reco::CandidateBaseRef& baseRef,
1085  const GenAssociations& genMatches,
1086  const IsoDepositMaps& deposits,
1087  const IsolationValueMaps& isolationValues) const {
1088  // in the particle flow algorithm,
1089  // the muon momentum is recomputed.
1090  // the new value is stored as the momentum of the
1091  // resulting PFCandidate of type Muon, and choosen
1092  // as the pat::Muon momentum
1093  if (useParticleFlow_)
1094  aMuon.setP4(aMuon.pfCandidateRef()->p4());
1095  if (embedTrack_)
1096  aMuon.embedTrack();
1098  aMuon.embedStandAloneMuon();
1099  if (embedCombinedMuon_)
1100  aMuon.embedCombinedMuon();
1101 
1102  // embed the TeV refit track refs (only available for globalMuons)
1103  if (aMuon.isGlobalMuon()) {
1105  aMuon.embedPickyMuon();
1107  aMuon.embedTpfmsMuon();
1109  aMuon.embedDytMuon();
1110  }
1111 
1112  // embed best tracks (at the end, so unless forceEmbedBestTrack_ is true we can save some space not embedding them twice)
1113  if (embedBestTrack_)
1117 
1118  // store the match to the generated final state muons
1119  if (addGenMatch_) {
1120  for (auto const& genMatch : genMatches) {
1121  reco::GenParticleRef genMuon = (*genMatch)[baseRef];
1122  aMuon.addGenParticleRef(genMuon);
1123  }
1124  if (embedGenMatch_)
1125  aMuon.embedGenParticle();
1126  }
1127  if (efficiencyLoader_.enabled()) {
1128  efficiencyLoader_.setEfficiencies(aMuon, muonRef);
1129  }
1130 
1131  for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
1132  if (useParticleFlow_) {
1133  if (deposits[j]->contains(baseRef.id())) {
1134  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[baseRef]);
1135  } else if (deposits[j]->contains(muonRef.id())) {
1136  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
1137  } else {
1138  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
1139  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[source]);
1140  }
1141  } else {
1142  aMuon.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[muonRef]);
1143  }
1144  }
1145 
1146  for (size_t j = 0; j < isolationValues.size(); ++j) {
1147  if (useParticleFlow_) {
1148  if (isolationValues[j]->contains(baseRef.id())) {
1149  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[baseRef]);
1150  } else if (isolationValues[j]->contains(muonRef.id())) {
1151  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
1152  } else {
1153  reco::CandidatePtr source = aMuon.pfCandidateRef()->sourceCandidatePtr(0);
1154  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[source]);
1155  }
1156  } else {
1157  aMuon.setIsolation(isolationValueLabels_[j].first, (*isolationValues[j])[muonRef]);
1158  }
1159  }
1160 
1161  if (resolutionLoader_.enabled()) {
1163  }
1164 }
1165 
1168  aMuon.polarP4(),
1169  miniIsoParams_[0],
1170  miniIsoParams_[1],
1171  miniIsoParams_[2],
1172  miniIsoParams_[3],
1173  miniIsoParams_[4],
1174  miniIsoParams_[5],
1175  miniIsoParams_[6],
1176  miniIsoParams_[7],
1177  miniIsoParams_[8]);
1178  aMuon.setMiniPFIsolation(miniiso);
1179 }
1180 
1181 double PATMuonProducer::getRelMiniIsoPUCorrected(const pat::Muon& muon, double rho, const std::vector<double>& area) {
1182  double mindr(miniIsoParams_[0]);
1183  double maxdr(miniIsoParams_[1]);
1184  double kt_scale(miniIsoParams_[2]);
1185  double drcut = pat::miniIsoDr(muon.polarP4(), mindr, maxdr, kt_scale);
1186  return pat::muonRelMiniIsoPUCorrected(muon.miniPFIsolation(), muon.polarP4(), drcut, rho, area);
1187 }
1188 
1190  constexpr double dR_threshold = 0.4;
1191  constexpr double dR2_threshold = dR_threshold * dR_threshold;
1192  constexpr double mix_fraction = 0.5;
1193  enum particleType { CH = 0, NH = 1, PH = 2, OTHER = 100000 };
1194  double val_PuppiWithLep = 0.0;
1195  double val_PuppiWithoutLep = 0.0;
1196 
1197  for (const auto& cand : *pc) { //pat::pat::PackedCandidate loop start
1198 
1199  const particleType pType = isChargedHadron(cand.pdgId()) ? CH
1200  : isNeutralHadron(cand.pdgId()) ? NH
1201  : isPhoton(cand.pdgId()) ? PH
1202  : OTHER;
1203  if (pType == OTHER) {
1204  if (cand.pdgId() != 1 && cand.pdgId() != 2 && abs(cand.pdgId()) != 11 && abs(cand.pdgId()) != 13) {
1205  LogTrace("PATMuonProducer") << "candidate with PDGID = " << cand.pdgId()
1206  << " is not CH/NH/PH/e/mu or 1/2 (and this is removed from isolation calculation)"
1207  << std::endl;
1208  }
1209  continue;
1210  }
1211  double d_eta = std::abs(cand.eta() - muon.eta());
1212  if (d_eta > dR_threshold)
1213  continue;
1214 
1215  double d_phi = std::abs(reco::deltaPhi(cand.phi(), muon.phi()));
1216  if (d_phi > dR_threshold)
1217  continue;
1218 
1219  double dR2 = reco::deltaR2(cand, muon);
1220  if (dR2 > dR2_threshold)
1221  continue;
1222  if (pType == CH && dR2 < 0.0001 * 0.0001)
1223  continue;
1224  if (pType == NH && dR2 < 0.01 * 0.01)
1225  continue;
1226  if (pType == PH && dR2 < 0.01 * 0.01)
1227  continue;
1228  val_PuppiWithLep += cand.pt() * cand.puppiWeight();
1229  val_PuppiWithoutLep += cand.pt() * cand.puppiWeightNoLep();
1230 
1231  } //pat::pat::PackedCandidate loop end
1232 
1233  double reliso_Puppi_withLep = val_PuppiWithLep / muon.pt();
1234  double reliso_Puppi_withoutlep = val_PuppiWithoutLep / muon.pt();
1235  double reliso_Puppi_combined = mix_fraction * reliso_Puppi_withLep + (1.0 - mix_fraction) * reliso_Puppi_withoutlep;
1236  return reliso_Puppi_combined;
1237 }
1238 
1239 bool PATMuonProducer::isNeutralHadron(long pdgid) { return std::abs(pdgid) == 130; }
1240 
1241 bool PATMuonProducer::isChargedHadron(long pdgid) { return std::abs(pdgid) == 211; }
1242 
1243 bool PATMuonProducer::isPhoton(long pdgid) { return pdgid == 22; }
1244 
1245 // ParameterSet description for module
1248  iDesc.setComment("PAT muon producer module");
1249 
1250  // input source
1251  iDesc.add<edm::InputTag>("muonSource", edm::InputTag("no default"))->setComment("input collection");
1252 
1253  // embedding
1254  iDesc.add<bool>("embedMuonBestTrack", true)->setComment("embed muon best track (global pflow)");
1255  iDesc.add<bool>("embedTunePMuonBestTrack", true)->setComment("embed muon best track (muon only)");
1256  iDesc.add<bool>("forceBestTrackEmbedding", true)
1257  ->setComment(
1258  "force embedding separately the best tracks even if they're already embedded e.g. as tracker or global "
1259  "tracks");
1260  iDesc.add<bool>("embedTrack", true)->setComment("embed external track");
1261  iDesc.add<bool>("embedStandAloneMuon", true)->setComment("embed external stand-alone muon");
1262  iDesc.add<bool>("embedCombinedMuon", false)->setComment("embed external combined muon");
1263  iDesc.add<bool>("embedPickyMuon", false)->setComment("embed external picky track");
1264  iDesc.add<bool>("embedTpfmsMuon", false)->setComment("embed external tpfms track");
1265  iDesc.add<bool>("embedDytMuon", false)->setComment("embed external dyt track ");
1266 
1267  // embedding of MET muon corrections
1268  iDesc.add<bool>("embedCaloMETMuonCorrs", true)->setComment("whether to add MET muon correction for caloMET or not");
1269  iDesc.add<edm::InputTag>("caloMETMuonCorrs", edm::InputTag("muonMETValueMapProducer", "muCorrData"))
1270  ->setComment("source of MET muon corrections for caloMET");
1271  iDesc.add<bool>("embedTcMETMuonCorrs", true)->setComment("whether to add MET muon correction for tcMET or not");
1272  iDesc.add<edm::InputTag>("tcMETMuonCorrs", edm::InputTag("muonTCMETValueMapProducer", "muCorrData"))
1273  ->setComment("source of MET muon corrections for tcMET");
1274 
1275  // pf specific parameters
1276  iDesc.add<edm::InputTag>("pfMuonSource", edm::InputTag("pfMuons"))->setComment("particle flow input collection");
1277  iDesc.add<bool>("useParticleFlow", false)->setComment("whether to use particle flow or not");
1278  iDesc.add<bool>("embedPFCandidate", false)->setComment("embed external particle flow object");
1279  iDesc.add<bool>("embedPfEcalEnergy", true)->setComment("add ecal energy as reconstructed by PF");
1280 
1281  // inverse beta computation
1282  iDesc.add<bool>("addInverseBeta", true)->setComment("add combined inverse beta");
1283  iDesc.add<edm::InputTag>("sourceInverseBeta", edm::InputTag("muons", "combined"))
1284  ->setComment("source of inverse beta values");
1285 
1286  // MC matching configurables
1287  iDesc.add<bool>("addGenMatch", true)->setComment("add MC matching");
1288  iDesc.add<bool>("embedGenMatch", false)->setComment("embed MC matched MC information");
1289  std::vector<edm::InputTag> emptySourceVector;
1290  iDesc
1291  .addNode(edm::ParameterDescription<edm::InputTag>("genParticleMatch", edm::InputTag(), true) xor
1292  edm::ParameterDescription<std::vector<edm::InputTag>>("genParticleMatch", emptySourceVector, true))
1293  ->setComment("input with MC match information");
1294 
1295  // mini-iso
1296  iDesc.add<bool>("computeMiniIso", false)->setComment("whether or not to compute and store electron mini-isolation");
1297  iDesc.add<bool>("computePuppiCombinedIso", false)
1298  ->setComment("whether or not to compute and store puppi combined isolation");
1299 
1300  iDesc.add<edm::InputTag>("pfCandsForMiniIso", edm::InputTag("packedPFCandidates"))
1301  ->setComment("collection to use to compute mini-iso");
1302  iDesc.add<std::vector<double>>("miniIsoParams", std::vector<double>())
1303  ->setComment("mini-iso parameters to use for muons");
1304 
1305  iDesc.add<bool>("addTriggerMatching", false)->setComment("add L1 and HLT matching to offline muon");
1306 
1308 
1309  // IsoDeposit configurables
1310  edm::ParameterSetDescription isoDepositsPSet;
1311  isoDepositsPSet.addOptional<edm::InputTag>("tracker");
1312  isoDepositsPSet.addOptional<edm::InputTag>("ecal");
1313  isoDepositsPSet.addOptional<edm::InputTag>("hcal");
1314  isoDepositsPSet.addOptional<edm::InputTag>("particle");
1315  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedHadrons");
1316  isoDepositsPSet.addOptional<edm::InputTag>("pfChargedAll");
1317  isoDepositsPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
1318  isoDepositsPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1319  isoDepositsPSet.addOptional<edm::InputTag>("pfPhotons");
1320  isoDepositsPSet.addOptional<std::vector<edm::InputTag>>("user");
1321  iDesc.addOptional("isoDeposits", isoDepositsPSet);
1322 
1323  // isolation values configurables
1324  edm::ParameterSetDescription isolationValuesPSet;
1325  isolationValuesPSet.addOptional<edm::InputTag>("tracker");
1326  isolationValuesPSet.addOptional<edm::InputTag>("ecal");
1327  isolationValuesPSet.addOptional<edm::InputTag>("hcal");
1328  isolationValuesPSet.addOptional<edm::InputTag>("particle");
1329  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedHadrons");
1330  isolationValuesPSet.addOptional<edm::InputTag>("pfChargedAll");
1331  isolationValuesPSet.addOptional<edm::InputTag>("pfPUChargedHadrons");
1332  isolationValuesPSet.addOptional<edm::InputTag>("pfNeutralHadrons");
1333  isolationValuesPSet.addOptional<edm::InputTag>("pfPhotons");
1334  iDesc.addOptional("isolationValues", isolationValuesPSet);
1335 
1336  iDesc.ifValue(edm::ParameterDescription<bool>("addPuppiIsolation", false, true),
1338  "puppiIsolationChargedHadrons",
1339  edm::InputTag("muonPUPPIIsolation", "h+-DR030-ThresholdVeto000-ConeVeto000"),
1340  true) and
1342  "puppiIsolationNeutralHadrons",
1343  edm::InputTag("muonPUPPIIsolation", "h0-DR030-ThresholdVeto000-ConeVeto001"),
1344  true) and
1346  "puppiIsolationPhotons",
1347  edm::InputTag("muonPUPPIIsolation", "gamma-DR030-ThresholdVeto000-ConeVeto001"),
1348  true) and
1350  "puppiNoLeptonsIsolationChargedHadrons",
1351  edm::InputTag("muonPUPPINoLeptonsIsolation", "h+-DR030-ThresholdVeto000-ConeVeto000"),
1352  true) and
1354  "puppiNoLeptonsIsolationNeutralHadrons",
1355  edm::InputTag("muonPUPPINoLeptonsIsolation", "h0-DR030-ThresholdVeto000-ConeVeto001"),
1356  true) and
1358  "puppiNoLeptonsIsolationPhotons",
1359  edm::InputTag("muonPUPPINoLeptonsIsolation", "gamma-DR030-ThresholdVeto000-ConeVeto001"),
1360  true)) or
1361  false >> edm::EmptyGroupDescription());
1362 
1363  // Efficiency configurables
1364  edm::ParameterSetDescription efficienciesPSet;
1365  efficienciesPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
1366  iDesc.add("efficiencies", efficienciesPSet);
1367  iDesc.add<bool>("addEfficiencies", false);
1368 
1369  // Check to see if the user wants to add user data
1370  edm::ParameterSetDescription userDataPSet;
1372  iDesc.addOptional("userData", userDataPSet);
1373 
1374  edm::ParameterSetDescription isolationPSet;
1375  isolationPSet.setAllowAnything(); // TODO: the pat helper needs to implement a description.
1376  iDesc.add("userIsolation", isolationPSet);
1377 
1378  iDesc.add<bool>("embedHighLevelSelection", true)->setComment("embed high level selection");
1379  edm::ParameterSetDescription highLevelPSet;
1380  highLevelPSet.setAllowAnything();
1381  iDesc.addNode(edm::ParameterDescription<edm::InputTag>("beamLineSrc", edm::InputTag(), true))
1382  ->setComment("input with high level selection");
1384  ->setComment("input with high level selection");
1385 
1386  //descriptions.add("PATMuonProducer", iDesc);
1387 }
1388 
1389 // embed various impact parameters with errors
1390 // embed high level selection
1395  bool primaryVertexIsValid,
1397  bool beamspotIsValid) {
1398  // Correct to PV
1399 
1400  // PV2D
1401  aMuon.setDB(track->dxy(primaryVertex.position()),
1402  track->dxyError(primaryVertex.position(), primaryVertex.covariance()),
1403  pat::Muon::PV2D);
1404 
1405  // PV3D
1406  std::pair<bool, Measurement1D> result =
1407  IPTools::signedImpactParameter3D(tt, GlobalVector(track->px(), track->py(), track->pz()), primaryVertex);
1408  double d0_corr = result.second.value();
1409  double d0_err = primaryVertexIsValid ? result.second.error() : -1.0;
1410  aMuon.setDB(d0_corr, d0_err, pat::Muon::PV3D);
1411 
1412  // Correct to beam spot
1413 
1414  // BS2D
1415  aMuon.setDB(track->dxy(beamspot), track->dxyError(beamspot), pat::Muon::BS2D);
1416 
1417  // make a fake vertex out of beam spot
1418  reco::Vertex vBeamspot(beamspot.position(), beamspot.rotatedCovariance3D());
1419 
1420  // BS3D
1421  result = IPTools::signedImpactParameter3D(tt, GlobalVector(track->px(), track->py(), track->pz()), vBeamspot);
1422  d0_corr = result.second.value();
1423  d0_err = beamspotIsValid ? result.second.error() : -1.0;
1424  aMuon.setDB(d0_corr, d0_err, pat::Muon::BS3D);
1425 
1426  // PVDZ
1427  aMuon.setDB(
1428  track->dz(primaryVertex.position()), std::hypot(track->dzError(), primaryVertex.zError()), pat::Muon::PVDZ);
1429 }
1430 
1432 
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:329
#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:333
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:339
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:335
void setSimHeaviestMotherFlavour(int id)
Definition: Muon.h:330
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_]
pat::MuonMvaIDEstimator const & muonMvaIDEstimator() const
edm::EDGetTokenT< edm::ValueMap< float > > PUPPINoLeptonsIsolation_neutral_hadrons_
void setSimType(reco::MuonSimType type)
Definition: Muon.h:327
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:122
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:332
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:328
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:145
std::unique_ptr< const pat::MuonMvaIDEstimator > muonMvaIDEstimator_
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:336
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:41
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:331
const edm::EDPutTokenT< std::vector< Muon > > patMuonPutToken_
void setSimPt(float pt)
Definition: Muon.h:337
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:151
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:338
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:301
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:340
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:334
bool embedHighLevelSelection_
embed high level selection variables
double eta() const final
momentum pseudorapidity