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 
19 
21  public:
22  explicit MuonIDTableProducer(const edm::ParameterSet &iConfig) :
23  name_(iConfig.getParameter<std::string>("name")),
24  src_(consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muons"))),
25  srcVtx_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertices")))
26  {
27  produces<nanoaod::FlatTable>();
28  }
29 
30  ~MuonIDTableProducer() override {};
31 
32  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
34  desc.add<edm::InputTag>("muons")->setComment("input muon collection");
35  desc.add<edm::InputTag>("vertices", edm::InputTag("offlineSlimmedPrimaryVertices"))->setComment("input vertex collection, for dxy/dz");
36  desc.add<std::string>("name")->setComment("name of the muon nanoaod::FlatTable we are extending with IDs");
37  descriptions.add("muonIDTable", desc);
38  }
39 
40  private:
41  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override ;
42 
46 
47  static bool isMediumMuonHIP(const pat::Muon& muon) ;
48  static bool isSoftMuonHIP(const pat::Muon& muon, const reco::Vertex& vtx) ;
49  static bool isTrackerHighPt(const pat::Muon & mu, const reco::Vertex & primaryVertex) ;
50 };
51 
52 // ------------ method called to produce the data ------------
53 void
55 {
56 
58  iEvent.getByToken(src_, muons);
60  iEvent.getByToken(srcVtx_, vertices);
61 
62  unsigned int ncand = muons->size();
63 
64  const reco::Vertex & pv = vertices->front(); // consistent with IP information in slimmedLeptons.
65 
66  bool isRun2016BCDEF = (272007 <= iEvent.run() && iEvent.run() <= 278808);
67  std::vector<uint8_t> tight(ncand, 0), highPt(ncand, 0), soft(ncand, 0), medium(ncand, 0);
68  for (unsigned int i = 0; i < ncand; ++i) {
69  const pat::Muon & mu = (*muons)[i];
70  tight[i] = muon::isTightMuon(mu, pv);
71  highPt[i] = muon::isHighPtMuon(mu, pv) ? 2 : isTrackerHighPt(mu,pv);
72  soft[i] = isRun2016BCDEF ? isSoftMuonHIP(mu,pv) : muon::isSoftMuon(mu, pv);
73  medium[i] = isRun2016BCDEF ? isMediumMuonHIP(mu) : muon::isMediumMuon(mu);
74  }
75 
76  auto tab = std::make_unique<nanoaod::FlatTable>(ncand, name_, false, true);
77  tab->addColumn<uint8_t>("tightId", tight, "POG Tight muon ID", nanoaod::FlatTable::BoolColumn);
78  tab->addColumn<uint8_t>("highPtId", highPt, "POG highPt muon ID (1 = tracker high pT, 2 = global high pT, which includes tracker high pT)", nanoaod::FlatTable::UInt8Column);
79  tab->addColumn<uint8_t>("softId", soft, "POG Soft muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", nanoaod::FlatTable::BoolColumn);
80  tab->addColumn<uint8_t>("mediumId", medium, "POG Medium muon ID (using the relaxed cuts in the data Run 2016 B-F periods, and standard cuts elsewhere)", nanoaod::FlatTable::BoolColumn);
81 
82  iEvent.put(std::move(tab));
83 }
84 
86  bool goodGlob = mu.isGlobalMuon() &&
87  mu.globalTrack()->normalizedChi2() < 3 &&
89  mu.combinedQuality().trkKink < 20;
90  bool isMedium = muon::isLooseMuon(mu) &&
91  mu.innerTrack()->validFraction() > 0.49 &&
92  muon::segmentCompatibility(mu) > (goodGlob ? 0.303 : 0.451);
93  return isMedium;
94 }
95 
98  mu.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 &&
99  mu.innerTrack()->hitPattern().pixelLayersWithMeasurement() > 0 &&
100  std::abs(mu.innerTrack()->dxy(vtx.position())) < 0.3 &&
101  std::abs(mu.innerTrack()->dz(vtx.position())) < 20.;
102 }
103 
105  return ( mu.numberOfMatchedStations() > 1
106  && (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
float chi2LocalPosition
chi2 value for the STA-TK matching of local position
Definition: MuonQuality.h:19
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isMediumMuon(const reco::Muon &, bool run2016_hip_mitigation=false)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
float trkKink
value of the kink algorithm applied to the inner track stub
Definition: MuonQuality.h:11
edm::EDGetTokenT< std::vector< pat::Muon > > src_
const Point & position() const
position
Definition: Vertex.h:109
bool isLooseMuon(const reco::Muon &)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
Definition: Muon.py:1
bool isGlobalMuon() const override
Definition: Muon.h:276
MuonQuality combinedQuality() const
get energy deposition information
Definition: Muon.h:121
RunNumber_t run() const
Definition: Event.h:109
def pv(vc)
Definition: MetAnalyzer.py:7
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
const int mu
Definition: Constants.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isSoftMuon(const reco::Muon &, const reco::Vertex &, bool run2016_hip_mitigation=false)
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
int numberOfMatchedStations(ArbitrationType type=SegmentAndTrackArbitration) const
static bool isSoftMuonHIP(const pat::Muon &muon, const reco::Vertex &vtx)
MuonIDTableProducer(const edm::ParameterSet &iConfig)
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:81
static bool isMediumMuonHIP(const pat::Muon &muon)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
reco::TrackRef muonBestTrack() const override
Track selected to be the best measurement of the muon parameters (including PFlow global information)...
static bool isTrackerHighPt(const pat::Muon &mu, const reco::Vertex &primaryVertex)
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
Analysis-level muon class.
Definition: Muon.h:50
def move(src, dest)
Definition: eostools.py:511