CMS 3D CMS Logo

ZtoMMMuonTrackProducer.cc
Go to the documentation of this file.
1 // system includes
2 #include <memory>
3 
4 // user includes
23 
24 // ROOT includes
25 #include "TLorentzVector.h"
26 
28 public:
30  ~ZtoMMMuonTrackProducer() override = default;
31  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
32 
33  void produce(edm::StreamID streamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
34 
35 private:
36  // ----------member data ---------------------------
41 
42  const double maxEta_;
43  const double minPt_;
44  const double maxNormChi2_;
45  const double maxD0_;
46  const double maxDz_;
47  const int minPixelHits_;
48  const int minStripHits_;
49  const int minChambers_;
50  const int minMatches_;
52  const double maxIso_;
53  const double minPtHighest_;
54  const double minInvMass_;
55  const double maxInvMass_;
56 };
57 
58 using namespace std;
59 using namespace edm;
60 
63  desc.addUntracked<edm::InputTag>("muonInputTag", edm::InputTag("muons"));
64  desc.addUntracked<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"));
65  desc.addUntracked<double>("maxEta", 2.4);
66  desc.addUntracked<double>("minPt", 5);
67  desc.addUntracked<double>("maxNormChi2", 1000);
68  desc.addUntracked<double>("maxD0", 0.02);
69  desc.addUntracked<double>("maxDz", 20.);
70  desc.addUntracked<uint32_t>("minPixelHits", 1);
71  desc.addUntracked<uint32_t>("minStripHits", 8);
72  desc.addUntracked<uint32_t>("minChambers", 2);
73  desc.addUntracked<uint32_t>("minMatches", 2);
74  desc.addUntracked<double>("minMatchedStations", 2);
75  desc.addUntracked<double>("maxIso", 0.3);
76  desc.addUntracked<double>("minPtHighest", 24);
77  desc.addUntracked<double>("minInvMass", 75);
78  desc.addUntracked<double>("maxInvMass", 105);
79  descriptions.addWithDefaultLabel(desc);
80 }
81 
83  : muonTag_(ps.getUntrackedParameter<edm::InputTag>("muonInputTag", edm::InputTag("muons"))),
84  bsTag_(ps.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
85  muonToken_(consumes<reco::MuonCollection>(muonTag_)),
86  bsToken_(consumes<reco::BeamSpot>(bsTag_)),
87  maxEta_(ps.getUntrackedParameter<double>("maxEta", 2.4)),
88  minPt_(ps.getUntrackedParameter<double>("minPt", 5)),
89  maxNormChi2_(ps.getUntrackedParameter<double>("maxNormChi2", 1000)),
90  maxD0_(ps.getUntrackedParameter<double>("maxD0", 0.02)),
91  maxDz_(ps.getUntrackedParameter<double>("maxDz", 20.)),
92  minPixelHits_(ps.getUntrackedParameter<uint32_t>("minPixelHits", 1)),
93  minStripHits_(ps.getUntrackedParameter<uint32_t>("minStripHits", 8)),
94  minChambers_(ps.getUntrackedParameter<uint32_t>("minChambers", 2)),
95  minMatches_(ps.getUntrackedParameter<uint32_t>("minMatches", 2)),
96  minMatchedStations_(ps.getUntrackedParameter<double>("minMatchedStations", 2)),
97  maxIso_(ps.getUntrackedParameter<double>("maxIso", 0.3)),
98  minPtHighest_(ps.getUntrackedParameter<double>("minPtHighest", 24)),
99  minInvMass_(ps.getUntrackedParameter<double>("minInvMass", 75)),
100  maxInvMass_(ps.getUntrackedParameter<double>("maxInvMass", 105)) {
101  produces<reco::TrackCollection>("");
102 }
103 
105  std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection());
106 
107  // Read Muon Collection
109  iEvent.getByToken(muonToken_, muonColl);
110 
111  // and the beamspot
113  iEvent.getByToken(bsToken_, beamSpot);
114 
115  std::vector<TLorentzVector> list;
116  if (muonColl.isValid()) {
117  for (auto const& mu : *muonColl) {
118  if (!mu.isGlobalMuon())
119  continue;
120  if (!mu.isPFMuon())
121  continue;
122  if (std::abs(mu.eta()) >= maxEta_)
123  continue;
124  if (mu.pt() < minPt_)
125  continue;
126 
127  reco::TrackRef gtk = mu.globalTrack();
128  double chi2 = gtk->chi2();
129  double ndof = gtk->ndof();
130  double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
131  if (chbyndof >= maxNormChi2_)
132  continue;
133 
134  reco::TrackRef tk = mu.innerTrack();
135  if (beamSpot.isValid()) {
136  double trkd0 = -(tk->dxy(beamSpot->position()));
137  if (std::abs(trkd0) >= maxD0_)
138  continue;
139  double trkdz = tk->dz(beamSpot->position());
140  if (std::abs(trkdz) >= maxDz_)
141  continue;
142  } else {
143  edm::LogError("ZtoMMMuonTrackProducer") << "Error >> Failed to get BeamSpot for label: " << bsTag_;
144  }
145  const reco::HitPattern& hitp = gtk->hitPattern();
147  continue;
149  continue;
150  // Hits/section in the muon chamber
151  if (mu.numberOfChambers() < minChambers_)
152  continue;
153  if (mu.numberOfMatches() < minMatches_)
154  continue;
155  if (mu.numberOfMatchedStations() < minMatchedStations_)
156  continue;
158  continue;
159 
160  //if (!muon::isMediumMuon(mu)) continue;
161 
162  // PF Isolation
163  const reco::MuonPFIsolation& pfIso04 = mu.pfIsolationR04();
164  double absiso = pfIso04.sumChargedHadronPt +
165  std::max(0.0, pfIso04.sumNeutralHadronEt + pfIso04.sumPhotonEt - 0.5 * pfIso04.sumPUPt);
166  if (absiso / mu.pt() > maxIso_)
167  continue;
168 
169  TLorentzVector lv;
170  lv.SetPtEtaPhiE(mu.pt(), mu.eta(), mu.phi(), mu.energy());
171  list.push_back(lv);
172 
173  outputTColl->push_back(*tk);
174  }
175  } else {
176  edm::LogError("ZtoMMMuonTrackProducer") << "Error >> Failed to get MuonCollection for label: " << muonTag_;
177  }
178 
179  iEvent.put(std::move(outputTColl));
180 }
181 
182 // Define this as a plug-in
int numberOfValidPixelHits() const
Definition: HitPattern.h:831
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const float maxD0_
Definition: Constants.h:83
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
~ZtoMMMuonTrackProducer() override=default
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#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
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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