CMS 3D CMS Logo

MuonSpecialVariables.cc
Go to the documentation of this file.
6 
9 
13 
16 
22 
24 public:
25  explicit MuonSpecialVariables(const edm::ParameterSet &iConfig)
26  : muonSrc_(consumes<std::vector<pat::Muon>>(iConfig.getParameter<edm::InputTag>("muonSrc"))),
27  vertexSrc_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("vertexSrc"))),
28  trkSrc_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("trkSrc"))) {
29  produces<std::vector<pat::Muon>>();
30  }
31  ~MuonSpecialVariables() override {}
32 
33  void setArbitratedTracker(pat::Muon &mu) const;
34  void setInnerTrackDxyz(pat::Muon &mu, const reco::Vertex &vtx) const;
35  void setTrkiso04(pat::Muon &mu, const std::vector<reco::Track> tracks) const;
36  void setTrkiso03(pat::Muon &mu, const std::vector<reco::Track> tracks) const;
37  void setNSegements(pat::Muon &mu) const;
38 
39 private:
40  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
41 
45 };
46 
48  mu.addUserInt("isArbitratedTracker", muon::isGoodMuon(mu, muon::TrackerMuonArbitrated));
49 }
50 
52  float innerTrackDxy =
53  mu.innerTrack().isNonnull() ? mu.innerTrack()->dxy(reco::TrackBase::Point(vtx.x(), vtx.y(), vtx.z())) : -999.9;
54  float innerTrackDz =
55  mu.innerTrack().isNonnull() ? mu.innerTrack()->dz(reco::TrackBase::Point(vtx.x(), vtx.y(), vtx.z())) : -999.9;
56  mu.addUserFloat("innerTrackDxy", innerTrackDxy);
57  mu.addUserFloat("innerTrackDz", innerTrackDz);
58 }
59 
60 void MuonSpecialVariables::setTrkiso04(pat::Muon &mu, const std::vector<reco::Track> tracks) const {
61  float energy = 0;
62  for (const auto &trk : tracks) {
63  if (deltaR(mu.eta(), mu.phi(), trk.eta(), trk.phi()) > 0.4)
64  continue;
65  energy += trk.pt();
66  }
67  float Trkiso04 = (energy - mu.pt());
68  float absTrkiso04 = (Trkiso04 > 0) ? Trkiso04 : 0;
69  mu.addUserFloat("absTrkiso04", absTrkiso04);
70 }
71 
72 void MuonSpecialVariables::setTrkiso03(pat::Muon &mu, const std::vector<reco::Track> tracks) const {
73  float energy = 0;
74  for (const auto &trk : tracks) {
75  if (deltaR(mu.eta(), mu.phi(), trk.eta(), trk.phi()) > 0.3)
76  continue;
77  energy += trk.pt();
78  }
79  float Trkiso03 = (energy - mu.pt());
80  float absTrkiso03 = (Trkiso03 > 0) ? Trkiso03 : 0;
81  mu.addUserFloat("absTrkiso03", absTrkiso03);
82 }
83 
85  int nsegments = 0;
86  for (auto &chamber : mu.matches()) {
87  if (chamber.id.det() != DetId::Muon)
88  continue;
89  if (chamber.id.subdetId() != MuonSubdetId::DT && chamber.id.subdetId() != MuonSubdetId::CSC)
90  continue;
91  nsegments += chamber.segmentMatches.size();
92  }
93  mu.addUserInt("nsegments", nsegments);
94 }
95 
98  iEvent.getByToken(muonSrc_, muonSrc);
99 
101  iEvent.getByToken(vertexSrc_, vertices);
102 
104  iEvent.getByToken(trkSrc_, trkCollection);
105 
106  std::unique_ptr<std::vector<pat::Muon>> muonCollection(new std::vector<pat::Muon>(*muonSrc));
107 
108  std::unique_ptr<std::vector<pat::Muon>> out(new std::vector<pat::Muon>());
109 
110  out->reserve(muonCollection->size());
111 
112  for (unsigned int i = 0; i < muonCollection->size(); i++) {
113  pat::Muon &mu = (*muonCollection).at(i);
115  int good_vertex = 0;
116  for (auto &vtx : *vertices) {
117  if (vtx.isFake() || !vtx.isValid())
118  continue;
120  good_vertex = 1;
121  break;
122  }
123  mu.addUserInt("isGoodVertex", good_vertex);
124  setTrkiso04(mu, *trkCollection);
125  setTrkiso03(mu, *trkCollection);
126  setNSegements(mu);
127  out->push_back(mu);
128  }
129 
130  iEvent.put(std::move(out));
131 }
132 
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void setTrkiso03(pat::Muon &mu, const std::vector< reco::Track > tracks) const
Definition: HeavyIon.h:7
void setInnerTrackDxyz(pat::Muon &mu, const reco::Vertex &vtx) const
int iEvent
Definition: GenABIO.cc:224
Definition: Muon.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
math::XYZPoint Point
point in the space
Definition: TrackBase.h:80
void setNSegements(pat::Muon &mu) const
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
void setArbitratedTracker(pat::Muon &mu) const
fixed size matrix
HLT enums.
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12
Analysis-level muon class.
Definition: Muon.h:51
def move(src, dest)
Definition: eostools.py:511
MuonSpecialVariables(const edm::ParameterSet &iConfig)
void setTrkiso04(pat::Muon &mu, const std::vector< reco::Track > tracks) const