CMS 3D CMS Logo

MuonIDTableProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
9 
13 
18 
20 public:
21  explicit MuonIDTableProducer(const edm::ParameterSet& iConfig)
22  : name_(iConfig.getParameter<std::string>("name")),
23  src_(consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muons"))),
24  srcVtx_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices"))) {
25  produces<nanoaod::FlatTable>();
26  }
27 
28  ~MuonIDTableProducer() override{};
29 
30  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
32  desc.add<edm::InputTag>("muons")->setComment("input muon collection");
33  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"))
34  ->setComment("input vertex collection, for dxy/dz");
35  desc.add<std::string>("name")->setComment("name of the muon nanoaod::FlatTable we are extending with IDs");
36  descriptions.add("muonIDTable", desc);
37  }
38 
39 private:
40  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
41 
45 
46  static bool isMediumMuonHIP(const pat::Muon& muon);
47  static bool isSoftMuonHIP(const pat::Muon& muon, const reco::Vertex& vtx);
48  static bool isTrackerHighPt(const pat::Muon& mu, const reco::Vertex& primaryVertex);
49 };
50 
51 // ------------ method called to produce the data ------------
54  iEvent.getByToken(src_, muons);
56  iEvent.getByToken(srcVtx_, vertices);
57 
58  unsigned int ncand = muons->size();
59 
60  const reco::Vertex& pv = vertices->front(); // consistent with IP information in slimmedLeptons.
61 
62  bool isRun2016BCDEF = (272007 <= iEvent.run() && iEvent.run() <= 278808);
63  std::vector<uint8_t> tight(ncand, 0), highPt(ncand, 0), soft(ncand, 0), medium(ncand, 0);
64  for (unsigned int i = 0; i < ncand; ++i) {
65  const pat::Muon& mu = (*muons)[i];
66  tight[i] = muon::isTightMuon(mu, pv);
67  highPt[i] = muon::isHighPtMuon(mu, pv) ? 2 : isTrackerHighPt(mu, pv);
68  soft[i] = isRun2016BCDEF ? isSoftMuonHIP(mu, pv) : muon::isSoftMuon(mu, pv);
69  medium[i] = isRun2016BCDEF ? isMediumMuonHIP(mu) : muon::isMediumMuon(mu);
70  }
71 
72  auto tab = std::make_unique<nanoaod::FlatTable>(ncand, name_, false, true);
73  tab->addColumn<bool>("tightId", tight, "POG Tight muon ID");
74  tab->addColumn<uint8_t>(
75  "highPtId",
76  highPt,
77  "POG highPt muon ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)");
78  tab->addColumn<bool>(
79  "softId",
80  soft,
81  "POG Soft muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)");
82  tab->addColumn<bool>(
83  "mediumId",
84  medium,
85  "POG Medium muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)");
86 
87  iEvent.put(std::move(tab));
88 }
89 
91  bool goodGlob = mu.isGlobalMuon() && mu.globalTrack()->normalizedChi2() < 3 &&
92  mu.combinedQuality().chi2LocalPosition < 12 && mu.combinedQuality().trkKink < 20;
93  bool isMedium = muon::isLooseMuon(mu) && mu.innerTrack()->validFraction() > 0.49 &&
94  muon::segmentCompatibility(mu) > (goodGlob ? 0.303 : 0.451);
95  return isMedium;
96 }
97 
100  mu.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 &&
101  mu.innerTrack()->hitPattern().pixelLayersWithMeasurement() > 0 &&
102  std::abs(mu.innerTrack()->dxy(vtx.position())) < 0.3 && std::abs(mu.innerTrack()->dz(vtx.position())) < 20.;
103 }
104 
106  return (mu.numberOfMatchedStations() > 1 && (mu.muonBestTrack()->ptError() / mu.muonBestTrack()->pt()) < 0.3 &&
107  std::abs(mu.muonBestTrack()->dxy(primaryVertex.position())) < 0.2 &&
108  std::abs(mu.muonBestTrack()->dz(primaryVertex.position())) < 0.5 &&
109  mu.innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
110  mu.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5);
111 }
112 
114 //define this as a plug-in
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuonIDTableProducer::~MuonIDTableProducer
~MuonIDTableProducer() override
Definition: MuonIDTableProducer.cc:28
mps_fire.i
i
Definition: mps_fire.py:428
muon::isSoftMuon
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
Definition: MuonSelectors.cc:916
muon
Definition: MuonCocktails.h:17
muon::segmentCompatibility
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
Definition: MuonSelectors.cc:61
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
MuonIDTableProducer::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: MuonIDTableProducer.cc:52
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
edm::Handle
Definition: AssociativeIterator.h:50
AlignmentTracksFromVertexSelector_cfi.vertices
vertices
Definition: AlignmentTracksFromVertexSelector_cfi.py:5
Muon
Definition: Muon.py:1
MuonIDTableProducer::srcVtx_
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
Definition: MuonIDTableProducer.cc:44
BeamMonitor_cff.primaryVertex
primaryVertex
hltOfflineBeamSpot for HLTMON
Definition: BeamMonitor_cff.py:7
MakerMacros.h
muon::isGoodMuon
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
Definition: MuonSelectors.cc:649
muon::isLooseMuon
bool isLooseMuon(const reco::Muon &)
Definition: MuonSelectors.cc:895
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
MuonSelectors.h
ParameterSetDescription.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
muon::isHighPtMuon
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
Definition: MuonSelectors.cc:933
muon::TMOneStationTight
Definition: MuonSelectors.h:31
edm::ParameterSet
Definition: ParameterSet.h:47
MuonIDTableProducer::MuonIDTableProducer
MuonIDTableProducer(const edm::ParameterSet &iConfig)
Definition: MuonIDTableProducer.cc:21
Event.h
muon::isTightMuon
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
Definition: MuonSelectors.cc:880
MuonIDTableProducer::isMediumMuonHIP
static bool isMediumMuonHIP(const pat::Muon &muon)
Definition: MuonIDTableProducer.cc:90
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
muon::isMediumMuon
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
Definition: MuonSelectors.cc:899
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FlatTable.h
MuonIDTableProducer::isSoftMuonHIP
static bool isSoftMuonHIP(const pat::Muon &muon, const reco::Vertex &vtx)
Definition: MuonIDTableProducer.cc:98
MuonIDTableProducer::isTrackerHighPt
static bool isTrackerHighPt(const pat::Muon &mu, const reco::Vertex &primaryVertex)
Definition: MuonIDTableProducer.cc:105
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
MuonIDTableProducer
Definition: MuonIDTableProducer.cc:19
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:19
MuonIDTableProducer::src_
edm::EDGetTokenT< std::vector< pat::Muon > > src_
Definition: MuonIDTableProducer.cc:43
MuonIDTableProducer::name_
std::string name_
Definition: MuonIDTableProducer.cc:42
Vertex.h
Frameworkfwd.h
MuonIDTableProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonIDTableProducer.cc:30
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:159
EDProducer.h
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35