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  }
109  }
110 
111  // Get Muon collection
113  if (!iEvent.getByToken(MuonCollection_, MuonCollection)) {
114  iEvent.put(std::move(outMuons));
115  iEvent.put(std::move(dispVertices), "displacedVtx");
116  return;
117  }
118 
119  // Get Links collection
121  if (!iEvent.getByToken(linkToken_, links)) {
122  iEvent.put(std::move(outMuons));
123  iEvent.put(std::move(dispVertices), "displacedVtx");
124  return;
125  }
126 
127  // Get EcalPFClusterIsoMap
130 
131  // Get HcalPFClusterIsoMap
134 
135  // Get TrackIsoMap
137  iEvent.getByToken(TrackIsoMap_, TrackIsoMap);
138 
139  // Produce muons
140  std::vector<int> vtxInd;
141  float minDR2 = 1e-06;
142  int index = 0;
143 
144  for (auto& muon : *ChargedCandidateCollection) {
145  reco::RecoChargedCandidateRef muonRef = getRef(ChargedCandidateCollection, index);
146  ++index;
147  if (muonRef.isNull() || !muonRef.isAvailable())
148  continue;
149 
150  reco::TrackRef track = muon.track();
151  if (track.isNull() || !track.isAvailable())
152  continue;
153 
154  int validStandAloneMuonHits = 0;
155  int matchedStandAloneMuonStations = 0;
156  for (auto const& link : *links) {
157  const reco::Track& trackerTrack = *link.trackerTrack();
158  float dR2 = deltaR2(track->eta(), track->phi(), trackerTrack.eta(), trackerTrack.phi());
159  float dPt = std::abs(track->pt() - trackerTrack.pt());
160  if (track->pt() != 0)
161  dPt = dPt / track->pt();
162 
163  if (dR2 < 0.02 * 0.02 and dPt < 0.001) {
164  if (link.standAloneTrack().isNonnull()) {
165  validStandAloneMuonHits = link.standAloneTrack()->hitPattern().numberOfValidMuonHits();
166  matchedStandAloneMuonStations = link.standAloneTrack()->hitPattern().muonStationsWithValidHits();
167  }
168  }
169  }
170 
171  unsigned int recoMuonType = 2; // Global muon
172  float normalizedChi2 = 999.0;
173  int nRecoMuonValidMuonHits = 0;
174  int nRecoMuonChambers = 0;
175  int nRecoMuonChambersCSCorDT = 0;
176  int nRecoMuonMatches = 0;
177  int nRecoMuonMatchedStations = 0;
178  unsigned int nRecoMuonExpectedMatchedStations = 0;
179  unsigned int recoMuonStationMask = 0;
180  int nRecoMuonMatchedRPCLayers = 0;
181  unsigned int recoMuonRPClayerMask = 0;
182  for (auto const& recoMu : *MuonCollection) {
183  float dR2 = deltaR2(muon.eta(), muon.phi(), recoMu.eta(), recoMu.phi());
184  float dPt = std::abs(muon.pt() - recoMu.pt());
185  if (muon.pt() != 0)
186  dPt = dPt / muon.pt();
187 
188  if (dR2 < 0.02 * 0.02 and dPt < 0.001) {
189  if (recoMu.globalTrack().isNonnull()) {
190  normalizedChi2 = recoMu.globalTrack()->normalizedChi2();
191  nRecoMuonValidMuonHits = recoMu.globalTrack()->hitPattern().numberOfValidMuonHits();
192  }
193  recoMuonType = recoMu.type();
194  nRecoMuonChambers = recoMu.numberOfChambers();
195  nRecoMuonChambersCSCorDT = recoMu.numberOfChambersCSCorDT();
196  nRecoMuonMatches = recoMu.numberOfMatches();
197  nRecoMuonMatchedStations = recoMu.numberOfMatchedStations();
198  nRecoMuonExpectedMatchedStations = recoMu.expectedNnumberOfMatchedStations();
199  recoMuonStationMask = recoMu.stationMask();
200  nRecoMuonMatchedRPCLayers = recoMu.numberOfMatchedRPCLayers();
201  recoMuonRPClayerMask = recoMu.RPClayerMask();
202  }
203  }
204 
205  if (muon.pt() < muonPtCut)
206  continue;
207  if (fabs(muon.eta()) > muonEtaCut)
208  continue;
209 
210  double ecalisopf = -1.0;
211  if (EcalPFClusterIsoMap.isValid()) {
212  ecalisopf = (*EcalPFClusterIsoMap)[muonRef];
213  }
214 
215  double hcalisopf = -1.0;
216  if (HcalPFClusterIsoMap.isValid()) {
217  hcalisopf = (*HcalPFClusterIsoMap)[muonRef];
218  }
219 
220  double trackiso = -1.0;
221  if (TrackIsoMap.isValid()) {
222  trackiso = (*TrackIsoMap)[muonRef];
223  }
224 
225  vtxInd.reserve(vtxMuPair.size());
226  for (unsigned int i = 0; i < vtxMuPair.size(); i++) {
227  float dr2_1 = reco::deltaR2(((vtxMuPair[i]).first), muon);
228  float dr2_2 = reco::deltaR2(((vtxMuPair[i]).second), muon);
229  if ((dr2_1 < minDR2) || (dr2_2 < minDR2))
230  vtxInd.push_back(i);
231  }
232 
233  outMuons->emplace_back(muon.pt(),
234  muon.eta(),
235  muon.phi(),
236  muon.mass(),
237  recoMuonType,
238  track->charge(),
240  ecalisopf,
241  hcalisopf,
242  trackiso,
243  validStandAloneMuonHits,
244  matchedStandAloneMuonStations,
245  nRecoMuonValidMuonHits,
246  nRecoMuonChambers,
247  nRecoMuonChambersCSCorDT,
248  nRecoMuonMatches,
249  nRecoMuonMatchedStations,
250  nRecoMuonExpectedMatchedStations,
251  recoMuonStationMask,
252  nRecoMuonMatchedRPCLayers,
253  recoMuonRPClayerMask,
254  track->hitPattern().numberOfValidPixelHits(),
255  track->hitPattern().numberOfValidStripHits(),
256  track->hitPattern().pixelLayersWithMeasurement(),
257  track->hitPattern().trackerLayersWithMeasurement(),
258  track->chi2(),
259  track->ndof(),
260  track->dxy(),
261  track->dz(),
262  track->qoverp(),
263  track->lambda(),
264  track->pt(),
265  track->phi(),
266  track->eta(),
267  track->dxyError(),
268  track->dzError(),
269  track->qoverpError(),
270  track->lambdaError(),
271  track->phiError(),
272  track->dsz(),
273  track->dszError(),
274  track->covariance(0, 1),
275  track->covariance(0, 2),
276  track->covariance(0, 3),
277  track->covariance(0, 4),
278  track->covariance(1, 2),
279  track->covariance(1, 3),
280  track->covariance(1, 4),
281  track->covariance(2, 3),
282  track->covariance(2, 4),
283  track->covariance(3, 4),
284  track->vx(),
285  track->vy(),
286  track->vz(),
287  vtxInd,
288  track->hitPattern().run3ScoutingHitPatternPOD());
289  vtxInd.clear();
290  }
291 
292  // Put output
293  iEvent.put(std::move(outMuons));
294  iEvent.put(std::move(dispVertices), "displacedVtx");
295 }
296 
297 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
300  desc.add<edm::InputTag>("ChargedCandidates", edm::InputTag("hltIterL3MuonCandidatesNoVtx"));
301  desc.add<edm::InputTag>("displacedvertexCollection", edm::InputTag("hltDisplacedmumuVtxProducer"));
302  desc.add<edm::InputTag>("InputMuons", edm::InputTag("hltIterL3MuonsNoVtx"));
303  desc.add<edm::InputTag>("InputLinks", edm::InputTag("hltL3MuonsIterL3LinksNoVtx"));
304  desc.add<edm::InputTag>("Tracks", edm::InputTag("hltPixelTracks"));
305  desc.add<edm::InputTag>("EcalPFClusterIsoMap", edm::InputTag("hltMuonEcalMFPFClusterIsoForMuonsNoVtx"));
306  desc.add<edm::InputTag>("HcalPFClusterIsoMap", edm::InputTag("hltMuonHcalPFClusterIsoForMuonsNoVtx"));
307  desc.add<edm::InputTag>("TrackIsoMap",
308  edm::InputTag("hltMuonTkRelIsolationCut0p09MapNoVtx:combinedRelativeIsoDeposits"));
309  desc.add<double>("muonPtCut", 3.0);
310  desc.add<double>("muonEtaCut", 2.4);
311  desc.add<double>("minVtxProbCut", 0.001);
312 
313  descriptions.add("hltScoutingMuonProducer", desc);
314 }
315 
316 // 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_
bool isAvailable() const
Definition: Ref.h:537
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