CMS 3D CMS Logo

ZtoMMMuonTrackProducer.cc
Go to the documentation of this file.
4 
8 #include "TLorentzVector.h"
9 
11 
12 using namespace std;
13 using namespace edm;
14 
16  : muonTag_(ps.getUntrackedParameter<edm::InputTag>("muonInputTag", edm::InputTag("muons"))),
17  bsTag_(ps.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
18  muonToken_(consumes<reco::MuonCollection>(muonTag_)),
19  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
20  maxEta_(ps.getUntrackedParameter<double>("maxEta", 2.4)),
21  minPt_(ps.getUntrackedParameter<double>("minPt", 5)),
22  maxNormChi2_(ps.getUntrackedParameter<double>("maxNormChi2", 1000)),
23  maxD0_(ps.getUntrackedParameter<double>("maxD0", 0.02)),
24  maxDz_(ps.getUntrackedParameter<double>("maxDz", 20.)),
25  minPixelHits_(ps.getUntrackedParameter<uint32_t>("minPixelHits", 1)),
26  minStripHits_(ps.getUntrackedParameter<uint32_t>("minStripHits", 8)),
27  minChambers_(ps.getUntrackedParameter<uint32_t>("minChambers", 2)),
28  minMatches_(ps.getUntrackedParameter<uint32_t>("minMatches", 2)),
29  minMatchedStations_(ps.getUntrackedParameter<double>("minMatchedStations", 2)),
30  maxIso_(ps.getUntrackedParameter<double>("maxIso", 0.3)),
31  minPtHighest_(ps.getUntrackedParameter<double>("minPtHighest", 24)),
32  minInvMass_(ps.getUntrackedParameter<double>("minInvMass", 60)),
33  maxInvMass_(ps.getUntrackedParameter<double>("maxInvMass", 120)) {
34  produces<reco::TrackCollection>("");
35 }
36 
38 
40  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection());
41 
42  // Read Muon Collection
44  iEvent.getByToken(muonToken_, muonColl);
45 
46  // and the beamspot
48  iEvent.getByToken(bsToken_, beamSpot);
49 
50  std::vector<TLorentzVector> list;
51  if (muonColl.isValid()) {
52  for (auto const& mu : *muonColl) {
53  if (!mu.isGlobalMuon())
54  continue;
55  if (!mu.isPFMuon())
56  continue;
57  if (std::fabs(mu.eta()) >= maxEta_)
58  continue;
59  if (mu.pt() < minPt_)
60  continue;
61 
62  reco::TrackRef gtk = mu.globalTrack();
63  double chi2 = gtk->chi2();
64  double ndof = gtk->ndof();
65  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
66  if (chbyndof >= maxNormChi2_)
67  continue;
68 
69  reco::TrackRef tk = mu.innerTrack();
70  if (beamSpot.isValid()) {
71  double trkd0 = -(tk->dxy(beamSpot->position()));
72  if (std::fabs(trkd0) >= maxD0_)
73  continue;
74  double trkdz = tk->dz(beamSpot->position());
75  if (std::fabs(trkdz) >= maxDz_)
76  continue;
77  } else {
78  edm::LogError("ZtoMMMuonTrackProducer") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
79  }
80  const reco::HitPattern& hitp = gtk->hitPattern();
82  continue;
84  continue;
85  // Hits/section in the muon chamber
86  if (mu.numberOfChambers() < minChambers_)
87  continue;
88  if (mu.numberOfMatches() < minMatches_)
89  continue;
90  if (mu.numberOfMatchedStations() < minMatchedStations_)
91  continue;
93  continue;
94 
95  //if (!muon::isMediumMuon(mu)) continue;
96 
97  // PF Isolation
98  const reco::MuonPFIsolation& pfIso04 = mu.pfIsolationR04();
99  double absiso = pfIso04.sumChargedHadronPt +
100  std::max(0.0, pfIso04.sumNeutralHadronEt + pfIso04.sumPhotonEt - 0.5 * pfIso04.sumPUPt);
101  if (absiso / mu.pt() > maxIso_)
102  continue;
103 
104  TLorentzVector lv;
105  lv.SetPtEtaPhiE(mu.pt(), mu.eta(), mu.phi(), mu.energy());
106  list.push_back(lv);
107 
108  outputTColl->push_back(*tk);
109  }
110  } else {
111  edm::LogError("ZtoMMMuonTrackProducer") << "Error >> Failed to get MuonCollection for label: " << muonTag_;
112  }
113 
114  iEvent.put(std::move(outputTColl));
115 }
116 
117 // Define this as a plug-in
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
const edm::InputTag bsTag_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const float maxD0_
Definition: Constants.h:82
const edm::EDGetTokenT< reco::MuonCollection > muonToken_
Log< level::Error, false > LogError
const edm::EDGetTokenT< reco::BeamSpot > bsToken_
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int numberOfValidStripHits() const
Definition: HitPattern.h:843
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::StreamID streamID, edm::Event &iEvent, edm::EventSetup const &iSetup) const override
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
bool isValid() const
Definition: HandleBase.h:70
ZtoMMMuonTrackProducer(const edm::ParameterSet &)
fixed size matrix
HLT enums.
const edm::InputTag muonTag_
def move(src, dest)
Definition: eostools.py:511