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 setNSegements(pat::Muon &mu) const;
37 
38 private:
39  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
40 
44 };
45 
47  mu.addUserInt("isArbitratedTracker", muon::isGoodMuon(mu, muon::TrackerMuonArbitrated));
48 }
49 
51  float innerTrackDxy =
52  mu.innerTrack().isNonnull() ? mu.innerTrack()->dxy(reco::TrackBase::Point(vtx.x(), vtx.y(), vtx.z())) : -999.9;
53  float innerTrackDz =
54  mu.innerTrack().isNonnull() ? mu.innerTrack()->dz(reco::TrackBase::Point(vtx.x(), vtx.y(), vtx.z())) : -999.9;
55  mu.addUserFloat("innerTrackDxy", innerTrackDxy);
56  mu.addUserFloat("innerTrackDz", innerTrackDz);
57 }
58 
59 void MuonSpecialVariables::setTrkiso04(pat::Muon &mu, const std::vector<reco::Track> tracks) const {
60  float energy = 0;
61  for (const auto &trk : tracks) {
62  if (deltaR(mu.eta(), mu.phi(), trk.eta(), trk.phi()) > 0.4)
63  continue;
64  energy += trk.pt();
65  }
66  float Trkiso04 = (energy - mu.pt()) / mu.pt();
67  float relTrkiso4 = (Trkiso04 > 0) ? Trkiso04 : 0;
68  mu.addUserFloat("relTrkiso4", relTrkiso4);
69 }
70 
72  int nsegments = 0;
73  for (auto &chamber : mu.matches()) {
74  if (chamber.id.det() != DetId::Muon)
75  continue;
76  if (chamber.id.subdetId() != MuonSubdetId::DT && chamber.id.subdetId() != MuonSubdetId::CSC)
77  continue;
78  nsegments += chamber.segmentMatches.size();
79  }
80  mu.addUserInt("nsegments", nsegments);
81 }
82 
85  iEvent.getByToken(muonSrc_, muonSrc);
86 
88  iEvent.getByToken(vertexSrc_, vertices);
89 
91  iEvent.getByToken(trkSrc_, trkCollection);
92 
93  std::unique_ptr<std::vector<pat::Muon>> muonCollection(new std::vector<pat::Muon>(*muonSrc));
94 
95  std::unique_ptr<std::vector<pat::Muon>> out(new std::vector<pat::Muon>());
96 
97  out->reserve(muonCollection->size());
98 
99  for (unsigned int i = 0; i < muonCollection->size(); i++) {
100  pat::Muon &mu = (*muonCollection).at(i);
102  int good_vertex = 0;
103  for (auto &vtx : *vertices) {
104  if (vtx.isFake() || !vtx.isValid())
105  continue;
107  good_vertex = 1;
108  break;
109  }
110  mu.addUserInt("isGoodVertex", good_vertex);
111  setTrkiso04(mu, *trkCollection);
112  setNSegements(mu);
113  out->push_back(mu);
114  }
115 
116  iEvent.put(std::move(out));
117 }
118 
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
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