CMS 3D CMS Logo

HLTScoutingMuonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HLTrigger/Muon
4 // Class: HLTScoutingMuonProducer
5 //
11 //
12 // Original Author: David G. Sheffield (Rutgers)
13 // Created: Fri, 31 Jul 2015
14 //
15 //
16 
19 #include "TMath.h"
20 
21 //
22 // constructors and destructor
23 //
25  : ChargedCandidateCollection_(
26  consumes<reco::RecoChargedCandidateCollection>(iConfig.getParameter<edm::InputTag>("ChargedCandidates"))),
27  displacedvertexCollection_(
28  consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("displacedvertexCollection"))),
29  MuonCollection_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("InputMuons"))),
30  linkToken_(consumes<reco::MuonTrackLinksCollection>(iConfig.getParameter<edm::InputTag>("InputLinks"))),
31  TrackCollection_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("Tracks"))),
32  EcalPFClusterIsoMap_(consumes<RecoChargedCandMap>(iConfig.getParameter<edm::InputTag>("EcalPFClusterIsoMap"))),
33  HcalPFClusterIsoMap_(consumes<RecoChargedCandMap>(iConfig.getParameter<edm::InputTag>("HcalPFClusterIsoMap"))),
34  TrackIsoMap_(consumes<edm::ValueMap<double>>(iConfig.getParameter<edm::InputTag>("TrackIsoMap"))),
35  muonPtCut(iConfig.getParameter<double>("muonPtCut")),
36  muonEtaCut(iConfig.getParameter<double>("muonEtaCut")),
37  minVtxProbCut(iConfig.getParameter<double>("minVtxProbCut")) {
38  //register products
39  produces<Run3ScoutingMuonCollection>();
40  produces<Run3ScoutingVertexCollection>("displacedVtx");
41 }
42 
44 
45 // ------------ method called to produce the data ------------
47  using namespace edm;
48 
49  std::unique_ptr<Run3ScoutingMuonCollection> outMuons(new Run3ScoutingMuonCollection());
50  std::unique_ptr<Run3ScoutingVertexCollection> dispVertices(new Run3ScoutingVertexCollection());
51 
52  // Get RecoChargedCandidate
53  Handle<reco::RecoChargedCandidateCollection> ChargedCandidateCollection;
54  if (!iEvent.getByToken(ChargedCandidateCollection_, ChargedCandidateCollection)) {
55  iEvent.put(std::move(outMuons));
56  iEvent.put(std::move(dispVertices), "displacedVtx");
57  return;
58  }
59 
60  std::pair<reco::RecoChargedCandidate, reco::RecoChargedCandidate> ivtxMuPair;
61  std::vector<std::pair<reco::RecoChargedCandidate, reco::RecoChargedCandidate>> vtxMuPair;
62 
63  //get displaced vertices
66  for (auto& dispvtx : *displacedvertexCollection) {
67  if (!dispvtx.isValid())
68  continue;
69  float vtxProb = 0.0;
70  if ((dispvtx.chi2() >= 0.0) && (dispvtx.ndof() > 0))
71  vtxProb = TMath::Prob(dispvtx.chi2(), dispvtx.ndof());
72  if (vtxProb < minVtxProbCut)
73  continue;
74 
75  // Get the 2 tracks associated to displaced vertex
76  auto trackIt = dispvtx.tracks_begin();
77  reco::TrackRef vertextkRef1 = (*trackIt).castTo<reco::TrackRef>();
78  trackIt++;
79  reco::TrackRef vertextkRef2 = (*trackIt).castTo<reco::TrackRef>();
80 
81  // Get the muons associated with the tracks
82  int iFoundRefs = 0;
83  for (auto const& cand : *ChargedCandidateCollection) {
84  reco::TrackRef tkRef = cand.get<reco::TrackRef>();
85  if (tkRef == vertextkRef1) {
86  ivtxMuPair.first = cand;
87  iFoundRefs++;
88  }
89  if (tkRef == vertextkRef2) {
90  ivtxMuPair.second = cand;
91  iFoundRefs++;
92  }
93  }
94  if (iFoundRefs < 2)
95  continue;
96  vtxMuPair.push_back(ivtxMuPair);
97 
98  dispVertices->emplace_back(dispvtx.x(),
99  dispvtx.y(),
100  dispvtx.z(),
101  dispvtx.zError(),
102  dispvtx.xError(),
103  dispvtx.yError(),
104  dispvtx.tracksSize(),
105  dispvtx.chi2(),
106  dispvtx.ndof(),
107  dispvtx.isValid(),
108  dispvtx.covariance(0, 1),
109  dispvtx.covariance(0, 2),
110  dispvtx.covariance(1, 2));
111  }
112  }
113 
114  // Get Muon collection
116  if (!iEvent.getByToken(MuonCollection_, MuonCollection)) {
117  iEvent.put(std::move(outMuons));
118  iEvent.put(std::move(dispVertices), "displacedVtx");
119  return;
120  }
121 
122  // Get Links collection
124  if (!iEvent.getByToken(linkToken_, links)) {
125  iEvent.put(std::move(outMuons));
126  iEvent.put(std::move(dispVertices), "displacedVtx");
127  return;
128  }
129 
130  // Get EcalPFClusterIsoMap
133 
134  // Get HcalPFClusterIsoMap
137 
138  // Get TrackIsoMap
140  iEvent.getByToken(TrackIsoMap_, TrackIsoMap);
141 
142  // Produce muons
143  std::vector<int> vtxInd;
144  float minDR2 = 1e-06;
145  int index = 0;
146 
147  for (auto& muon : *ChargedCandidateCollection) {
148  reco::RecoChargedCandidateRef muonRef = getRef(ChargedCandidateCollection, index);
149  ++index;
150  if (muonRef.isNull() || !muonRef.isAvailable())
151  continue;
152 
153  reco::TrackRef track = muon.track();
154  if (track.isNull() || !track.isAvailable())
155  continue;
156 
157  int validStandAloneMuonHits = 0;
158  int matchedStandAloneMuonStations = 0;
159  for (auto const& link : *links) {
160  const reco::Track& trackerTrack = *link.trackerTrack();
161  float dR2 = deltaR2(track->eta(), track->phi(), trackerTrack.eta(), trackerTrack.phi());
162  float dPt = std::abs(track->pt() - trackerTrack.pt());
163  if (track->pt() != 0)
164  dPt = dPt / track->pt();
165 
166  if (dR2 < 0.02 * 0.02 and dPt < 0.001) {
167  if (link.standAloneTrack().isNonnull()) {
168  validStandAloneMuonHits = link.standAloneTrack()->hitPattern().numberOfValidMuonHits();
169  matchedStandAloneMuonStations = link.standAloneTrack()->hitPattern().muonStationsWithValidHits();
170  }
171  }
172  }
173 
174  unsigned int recoMuonType = 2; // Global muon
175  float normalizedChi2 = 999.0;
176  int nRecoMuonValidMuonHits = 0;
177  int nRecoMuonChambers = 0;
178  int nRecoMuonChambersCSCorDT = 0;
179  int nRecoMuonMatches = 0;
180  int nRecoMuonMatchedStations = 0;
181  unsigned int nRecoMuonExpectedMatchedStations = 0;
182  unsigned int recoMuonStationMask = 0;
184  unsigned int recoMuonRPClayerMask = 0;
185  for (auto const& recoMu : *MuonCollection) {
186  float dR2 = deltaR2(muon.eta(), muon.phi(), recoMu.eta(), recoMu.phi());
187  float dPt = std::abs(muon.pt() - recoMu.pt());
188  if (muon.pt() != 0)
189  dPt = dPt / muon.pt();
190 
191  if (dR2 < 0.02 * 0.02 and dPt < 0.001) {
192  if (recoMu.globalTrack().isNonnull()) {
193  normalizedChi2 = recoMu.globalTrack()->normalizedChi2();
194  nRecoMuonValidMuonHits = recoMu.globalTrack()->hitPattern().numberOfValidMuonHits();
195  }
196  recoMuonType = recoMu.type();
197  nRecoMuonChambers = recoMu.numberOfChambers();
198  nRecoMuonChambersCSCorDT = recoMu.numberOfChambersCSCorDT();
199  nRecoMuonMatches = recoMu.numberOfMatches();
200  nRecoMuonMatchedStations = recoMu.numberOfMatchedStations();
201  nRecoMuonExpectedMatchedStations = recoMu.expectedNnumberOfMatchedStations();
202  recoMuonStationMask = recoMu.stationMask();
203  nRecoMuonMatchedRPCLayers = recoMu.numberOfMatchedRPCLayers();
204  recoMuonRPClayerMask = recoMu.RPClayerMask();
205  }
206  }
207 
208  if (muon.pt() < muonPtCut)
209  continue;
210  if (fabs(muon.eta()) > muonEtaCut)
211  continue;
212 
213  double ecalisopf = -1.0;
214  if (EcalPFClusterIsoMap.isValid()) {
215  ecalisopf = (*EcalPFClusterIsoMap)[muonRef];
216  }
217 
218  double hcalisopf = -1.0;
219  if (HcalPFClusterIsoMap.isValid()) {
220  hcalisopf = (*HcalPFClusterIsoMap)[muonRef];
221  }
222 
223  double trackiso = -1.0;
224  if (TrackIsoMap.isValid()) {
225  trackiso = (*TrackIsoMap)[muonRef];
226  }
227 
228  vtxInd.reserve(vtxMuPair.size());
229  for (unsigned int i = 0; i < vtxMuPair.size(); i++) {
230  float dr2_1 = reco::deltaR2(((vtxMuPair[i]).first), muon);
231  float dr2_2 = reco::deltaR2(((vtxMuPair[i]).second), muon);
232  if ((dr2_1 < minDR2) || (dr2_2 < minDR2))
233  vtxInd.push_back(i);
234  }
235 
236  outMuons->emplace_back(muon.pt(),
237  muon.eta(),
238  muon.phi(),
239  muon.mass(),
240  recoMuonType,
241  track->charge(),
243  ecalisopf,
244  hcalisopf,
245  trackiso,
246  validStandAloneMuonHits,
247  matchedStandAloneMuonStations,
248  nRecoMuonValidMuonHits,
257  track->hitPattern().numberOfValidPixelHits(),
258  track->hitPattern().numberOfValidStripHits(),
259  track->hitPattern().pixelLayersWithMeasurement(),
260  track->hitPattern().trackerLayersWithMeasurement(),
261  track->chi2(),
262  track->ndof(),
263  track->dxy(),
264  track->dz(),
265  track->qoverp(),
266  track->lambda(),
267  track->pt(),
268  track->phi(),
269  track->eta(),
270  track->dxyError(),
271  track->dzError(),
272  track->qoverpError(),
273  track->lambdaError(),
274  track->phiError(),
275  track->dsz(),
276  track->dszError(),
277  track->covariance(0, 1),
278  track->covariance(0, 2),
279  track->covariance(0, 3),
280  track->covariance(0, 4),
281  track->covariance(1, 2),
282  track->covariance(1, 3),
283  track->covariance(1, 4),
284  track->covariance(2, 3),
285  track->covariance(2, 4),
286  track->covariance(3, 4),
287  track->vx(),
288  track->vy(),
289  track->vz(),
290  vtxInd,
291  track->hitPattern().run3ScoutingHitPatternPOD());
292  vtxInd.clear();
293  }
294 
295  // Put output
296  iEvent.put(std::move(outMuons));
297  iEvent.put(std::move(dispVertices), "displacedVtx");
298 }
299 
300 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
303  desc.add<edm::InputTag>("ChargedCandidates", edm::InputTag("hltIterL3MuonCandidatesNoVtx"));
304  desc.add<edm::InputTag>("displacedvertexCollection", edm::InputTag("hltDisplacedmumuVtxProducer"));
305  desc.add<edm::InputTag>("InputMuons", edm::InputTag("hltIterL3MuonsNoVtx"));
306  desc.add<edm::InputTag>("InputLinks", edm::InputTag("hltL3MuonsIterL3LinksNoVtx"));
307  desc.add<edm::InputTag>("Tracks", edm::InputTag("hltPixelTracks"));
308  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltMuonEcalMFPFClusterIsoForMuonsNoVtx"));
309  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltMuonHcalPFClusterIsoForMuonsNoVtx"));
310  desc.add<edm::InputTag>("TrackIsoMap",
311  edm::InputTag("hltMuonTkRelIsolationCut0p09MapNoVtx:combinedRelativeIsoDeposits"));
312  desc.add<double>("muonPtCut", 3.0);
313  desc.add<double>("muonEtaCut", 2.4);
314  desc.add<double>("minVtxProbCut", 0.001);
315 
316  descriptions.add("hltScoutingMuonProducer", desc);
317 }
318 
319 // declare this class as a framework plugin
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
std::vector< Run3ScoutingVertex > Run3ScoutingVertexCollection
const edm::EDGetTokenT< reco::MuonCollection > MuonCollection_
void produce(edm::StreamID sid, edm::Event &iEvent, edm::EventSetup const &setup) const final
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const edm::EDGetTokenT< RecoChargedCandMap > EcalPFClusterIsoMap_
const edm::EDGetTokenT< RecoChargedCandMap > HcalPFClusterIsoMap_
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::vector< MuonTrackLinks > MuonTrackLinksCollection
collection of MuonTrackLinks
Definition: MuonFwd.h:22
U second(std::pair< T, U > const &p)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< edm::ValueMap< double > > TrackIsoMap_
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
bool isAvailable() const
Definition: Ref.h:541
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
~HLTScoutingMuonProducer() override
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< reco::VertexCollection > displacedvertexCollection_
bool isNull() const
Checks for null.
Definition: Ref.h:235
std::vector< RecoChargedCandidate > RecoChargedCandidateCollection
collectin of RecoChargedCandidate objects
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
const edm::EDGetTokenT< reco::RecoChargedCandidateCollection > ChargedCandidateCollection_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< Run3ScoutingMuon > Run3ScoutingMuonCollection
const edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkToken_
fixed size matrix
HLT enums.
HLTScoutingMuonProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511