CMS 3D CMS Logo

MuonIdProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonIdentification
4 // Class: MuonIdProducer
5 //
6 //
7 // Original Author: Dmytro Kovalskyi
8 //
9 //
10 
11 // user include files
13 
27 
30 
33 
35  : geomTokenRun_(esConsumes<edm::Transition::BeginRun>()),
36  propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) {
37  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: Constructor called";
38 
39  produces<reco::MuonCollection>();
40  produces<reco::CaloMuonCollection>();
41  produces<reco::MuonTimeExtraMap>("combined");
42  produces<reco::MuonTimeExtraMap>("dt");
43  produces<reco::MuonTimeExtraMap>("csc");
44 
45  minPt_ = iConfig.getParameter<double>("minPt");
46  minP_ = iConfig.getParameter<double>("minP");
47  minPCaloMuon_ = iConfig.getParameter<double>("minPCaloMuon");
48  minNumberOfMatches_ = iConfig.getParameter<int>("minNumberOfMatches");
49  addExtraSoftMuons_ = iConfig.getParameter<bool>("addExtraSoftMuons");
50  maxAbsEta_ = iConfig.getParameter<double>("maxAbsEta");
51  maxAbsDx_ = iConfig.getParameter<double>("maxAbsDx");
52  maxAbsPullX2_ = iConfig.getParameter<double>("maxAbsPullX");
54  maxAbsDy_ = iConfig.getParameter<double>("maxAbsDy");
55  maxAbsPullY2_ = iConfig.getParameter<double>("maxAbsPullY");
57  fillCaloCompatibility_ = iConfig.getParameter<bool>("fillCaloCompatibility");
58  fillEnergy_ = iConfig.getParameter<bool>("fillEnergy");
59  storeCrossedHcalRecHits_ = iConfig.getParameter<bool>("storeCrossedHcalRecHits");
60  fillMatching_ = iConfig.getParameter<bool>("fillMatching");
61  fillIsolation_ = iConfig.getParameter<bool>("fillIsolation");
62  fillShowerDigis_ = iConfig.getParameter<bool>("fillShowerDigis");
63  writeIsoDeposits_ = iConfig.getParameter<bool>("writeIsoDeposits");
64  fillGlobalTrackQuality_ = iConfig.getParameter<bool>("fillGlobalTrackQuality");
65  fillGlobalTrackRefits_ = iConfig.getParameter<bool>("fillGlobalTrackRefits");
66  arbitrateTrackerMuons_ = iConfig.getParameter<bool>("arbitrateTrackerMuons");
67  selectHighPurity_ = iConfig.getParameter<bool>("selectHighPurity");
68  //SK: (maybe temporary) run it only if the global is also run
69  fillTrackerKink_ = false;
71  fillTrackerKink_ = iConfig.getParameter<bool>("fillTrackerKink");
72 
74  iConfig.getParameter<double>("ptThresholdToFillCandidateP4WithGlobalFit");
76  iConfig.getParameter<double>("sigmaThresholdToFillCandidateP4WithGlobalFit");
77  caloCut_ = iConfig.getParameter<double>("minCaloCompatibility"); //CaloMuons
78  arbClean_ = iConfig.getParameter<bool>("runArbitrationCleaner"); // muon mesh
79 
80  // Load TrackDetectorAssociator parameters
81  const edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
82  edm::ConsumesCollector iC = consumesCollector();
84 
85  // Load parameters for the TimingFiller
86  edm::ParameterSet timingParameters = iConfig.getParameter<edm::ParameterSet>("TimingFillerParameters");
87  theTimingFiller_ = std::make_unique<MuonTimingFiller>(timingParameters, consumesCollector());
88 
89  // Load parameters for the ShowerDigiFiller
91  edm::ParameterSet showerDigiParameters = iConfig.getParameter<edm::ParameterSet>("ShowerDigiFillerParameters");
92  theShowerDigiFiller_ = std::make_unique<MuonShowerDigiFiller>(showerDigiParameters, consumesCollector());
93  } else {
94  theShowerDigiFiller_ = std::make_unique<MuonShowerDigiFiller>(); // to be used to call fillDefault only
95  }
96 
98  // Load MuonCaloCompatibility parameters
99  const auto caloParams = iConfig.getParameter<edm::ParameterSet>("MuonCaloCompatibility");
101  }
102 
103  if (fillIsolation_) {
104  // Load MuIsoExtractor parameters
105  edm::ParameterSet caloExtractorPSet = iConfig.getParameter<edm::ParameterSet>("CaloExtractorPSet");
106  std::string caloExtractorName = caloExtractorPSet.getParameter<std::string>("ComponentName");
108  IsoDepositExtractorFactory::get()->create(caloExtractorName, caloExtractorPSet, consumesCollector());
109 
110  edm::ParameterSet trackExtractorPSet = iConfig.getParameter<edm::ParameterSet>("TrackExtractorPSet");
111  std::string trackExtractorName = trackExtractorPSet.getParameter<std::string>("ComponentName");
113  IsoDepositExtractorFactory::get()->create(trackExtractorName, trackExtractorPSet, consumesCollector());
114 
115  edm::ParameterSet jetExtractorPSet = iConfig.getParameter<edm::ParameterSet>("JetExtractorPSet");
116  std::string jetExtractorName = jetExtractorPSet.getParameter<std::string>("ComponentName");
118  IsoDepositExtractorFactory::get()->create(jetExtractorName, jetExtractorPSet, consumesCollector());
119  }
121  trackDepositName_ = iConfig.getParameter<std::string>("trackDepositName");
122  produces<reco::IsoDepositMap>(trackDepositName_);
123  ecalDepositName_ = iConfig.getParameter<std::string>("ecalDepositName");
124  produces<reco::IsoDepositMap>(ecalDepositName_);
125  hcalDepositName_ = iConfig.getParameter<std::string>("hcalDepositName");
126  produces<reco::IsoDepositMap>(hcalDepositName_);
127  hoDepositName_ = iConfig.getParameter<std::string>("hoDepositName");
128  produces<reco::IsoDepositMap>(hoDepositName_);
129  jetDepositName_ = iConfig.getParameter<std::string>("jetDepositName");
130  produces<reco::IsoDepositMap>(jetDepositName_);
131  }
132 
133  inputCollectionLabels_ = iConfig.getParameter<std::vector<edm::InputTag> >("inputCollectionLabels");
134  const auto inputCollectionTypes = iConfig.getParameter<std::vector<std::string> >("inputCollectionTypes");
135  if (inputCollectionLabels_.size() != inputCollectionTypes.size())
136  throw cms::Exception("ConfigurationError")
137  << "Number of input collection labels is different from number of types. "
138  << "For each collection label there should be exactly one collection type specified.";
139  if (inputCollectionLabels_.size() > 8 || inputCollectionLabels_.empty())
140  throw cms::Exception("ConfigurationError") << "Number of input collections should be from 1 to 8.";
141 
142  debugWithTruthMatching_ = iConfig.getParameter<bool>("debugWithTruthMatching");
144  edm::LogWarning("MuonIdentification")
145  << "========================================================================\n"
146  << "Debugging mode with truth matching is turned on!!! Make sure you understand what you are doing!\n"
147  << "========================================================================\n";
148 
150  }
152  const auto& glbQualTag = iConfig.getParameter<edm::InputTag>("globalTrackQualityInputTag");
153  glbQualToken_ = consumes<edm::ValueMap<reco::MuonQuality> >(glbQualTag);
154  }
155 
156  if (fillTrackerKink_) {
158  std::make_unique<MuonKinkFinder>(iConfig.getParameter<edm::ParameterSet>("TrackerKinkFinderParameters"), iC);
159  }
160 
161  if (selectHighPurity_) {
162  const auto& pvTag = iConfig.getParameter<edm::InputTag>("pvInputTag");
163  pvToken_ = mayConsume<reco::VertexCollection>(pvTag);
164  }
165 
166  //create mesh holder
167  meshAlgo_ = std::make_unique<MuonMesh>(iConfig.getParameter<edm::ParameterSet>("arbitrationCleanerOptions"));
168 
169  edm::InputTag rpcHitTag("rpcRecHits");
170  rpcHitToken_ = consumes<RPCRecHitCollection>(rpcHitTag);
171 
172  edm::InputTag gemHitTag("gemRecHits");
173  gemHitToken_ = consumes<GEMRecHitCollection>(gemHitTag);
174 
175  //Consumes... UGH
177  for (unsigned int i = 0; i < inputCollectionLabels_.size(); ++i) {
178  const auto inputLabel = inputCollectionLabels_[i];
179  const auto inputType = ICTypes::toKey(inputCollectionTypes[i]); // Note: thorws exception if type is undefined.
180 
181  if (inputType == ICTypes::INNER_TRACKS) {
182  innerTrackCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
184  outerTrackCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
185  } else if (inputType == ICTypes::OUTER_TRACKS) {
186  outerTrackSecondaryCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
187  } else if (inputType == ICTypes::LINKS) {
188  linkCollectionToken_ = consumes<reco::MuonTrackLinksCollection>(inputLabel);
189  } else if (inputType == ICTypes::MUONS) {
190  muonCollectionToken_ = consumes<reco::MuonCollection>(inputLabel);
191  } else if (inputType == ICTypes::TEV_FIRSTHIT) {
192  tpfmsCollectionToken_ = consumes<reco::TrackToTrackMap>(inputLabel);
193  } else if (fillGlobalTrackRefits_ && inputType == ICTypes::TEV_PICKY) {
194  pickyCollectionToken_ = consumes<reco::TrackToTrackMap>(inputLabel);
195  } else if (fillGlobalTrackRefits_ && inputType == ICTypes::TEV_DYT) {
196  dytCollectionToken_ = consumes<reco::TrackToTrackMap>(inputCollectionLabels_.at(i));
197  }
198 
199  inputCollectionTypes_[i] = inputType;
200  }
201 }
202 
204  // TimingReport::current()->dump(std::cout);
205 }
206 
213 
214  tpfmsCollectionHandle_.clear();
215  pickyCollectionHandle_.clear();
216  dytCollectionHandle_.clear();
217 
219 
220  if (fillTrackerKink_)
221  trackerKinkFinder_->init(iSetup);
222 
223  for (unsigned int i = 0; i < inputCollectionLabels_.size(); ++i) {
224  const auto& inputLabel = inputCollectionLabels_[i];
225  const auto inputType = inputCollectionTypes_[i];
226  if (inputType == ICTypes::INNER_TRACKS) {
229  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputLabel;
230  LogTrace("MuonIdentification") << "Number of input inner tracks: " << innerTrackCollectionHandle_->size();
231  } else if (inputType == ICTypes::OUTER_TRACKS && !outerTrackCollectionHandle_.isValid()) {
234  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputLabel;
235  LogTrace("MuonIdentification") << "Number of input outer tracks: " << outerTrackCollectionHandle_->size();
236  } else if (inputType == ICTypes::OUTER_TRACKS) {
239  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputLabel;
240  LogTrace("MuonIdentification") << "Number of input outer secondary tracks: "
242  } else if (inputType == ICTypes::LINKS) {
245  throw cms::Exception("FatalError") << "Failed to get input link collection with label: " << inputLabel;
246  LogTrace("MuonIdentification") << "Number of input links: " << linkCollectionHandle_->size();
247  } else if (inputType == ICTypes::MUONS) {
250  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
251  LogTrace("MuonIdentification") << "Number of input muons: " << muonCollectionHandle_->size();
252  } else if (fillGlobalTrackRefits_ && inputType == ICTypes::TEV_FIRSTHIT) {
254  if (!tpfmsCollectionHandle_.isValid())
255  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
256  LogTrace("MuonIdentification") << "Number of input muons: " << tpfmsCollectionHandle_->size();
257  } else if (fillGlobalTrackRefits_ && inputType == ICTypes::TEV_PICKY) {
259  if (!pickyCollectionHandle_.isValid())
260  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
261  LogTrace("MuonIdentification") << "Number of input muons: " << pickyCollectionHandle_->size();
262  } else if (fillGlobalTrackRefits_ && inputType == ICTypes::TEV_DYT) {
264  if (!dytCollectionHandle_.isValid())
265  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
266  LogTrace("MuonIdentification") << "Number of input muons: " << dytCollectionHandle_->size();
267  } else
268  throw cms::Exception("FatalError") << "Unknown input collection type: #" << ICTypes::toStr(inputType);
269  }
270 
271  iEvent.getByToken(rpcHitToken_, rpcHitHandle_);
272  iEvent.getByToken(gemHitToken_, gemHitHandle_);
274  iEvent.getByToken(glbQualToken_, glbQualHandle_);
275  if (selectHighPurity_)
276  iEvent.getByToken(pvToken_, pvHandle_);
277 }
278 
280  const edm::EventSetup& iSetup,
281  const reco::TrackRef& track,
283  LogTrace("MuonIdentification") << "Creating a muon from a track " << track.get()->pt()
284  << " Pt (GeV), eta: " << track.get()->eta();
285  reco::Muon aMuon(makeMuon(*(track.get())));
286 
287  LogTrace("MuonIdentification") << "Muon created from a track ";
288 
289  aMuon.setMuonTrack(type, track);
290  aMuon.setBestTrack(type);
291  aMuon.setTunePBestTrack(type);
292 
293  LogTrace("MuonIdentification")
294  << "Muon created from a track and setMuonBestTrack, setBestTrack and setTunePBestTrack called";
295 
296  return aMuon;
297 }
298 
300  LogTrace("MuonIdentification") << "Creating a CaloMuon from a Muon";
301 
302  reco::CaloMuon aMuon;
303  aMuon.setInnerTrack(muon.innerTrack());
304 
305  if (muon.isEnergyValid())
306  aMuon.setCalEnergy(muon.calEnergy());
307  // get calo compatibility
310  return aMuon;
311 }
312 
314  LogTrace("MuonIdentification") << "Creating a muon from a link to tracks object";
315 
316  reco::Muon aMuon;
317  reco::Muon::MuonTrackTypePair chosenTrack;
318  reco::TrackRef tpfmsRef;
319  reco::TrackRef pickyRef;
320  reco::TrackRef dytRef;
321  bool useSigmaSwitch = false;
322 
323  if (tpfmsCollectionHandle_.isValid() && !tpfmsCollectionHandle_.failedToGet() && pickyCollectionHandle_.isValid() &&
324  !pickyCollectionHandle_.failedToGet()) {
325  tpfmsRef = muon::getTevRefitTrack(links.globalTrack(), *tpfmsCollectionHandle_);
326  pickyRef = muon::getTevRefitTrack(links.globalTrack(), *pickyCollectionHandle_);
327  dytRef = muon::getTevRefitTrack(links.globalTrack(), *dytCollectionHandle_);
328 
329  if (tpfmsRef.isNull() && pickyRef.isNull() && dytRef.isNull()) {
330  edm::LogWarning("MakeMuonWithTEV") << "Failed to get TEV refits, fall back to sigma switch.";
331  useSigmaSwitch = true;
332  }
333  } else {
334  useSigmaSwitch = true;
335  }
336 
337  if (useSigmaSwitch) {
338  chosenTrack = muon::sigmaSwitch(links.globalTrack(),
339  links.trackerTrack(),
342  } else {
343  chosenTrack = muon::tevOptimized(links.globalTrack(),
344  links.trackerTrack(),
345  tpfmsRef,
346  pickyRef,
347  dytRef,
349  }
350  aMuon = makeMuon(*chosenTrack.first);
351  aMuon.setInnerTrack(links.trackerTrack());
352  aMuon.setOuterTrack(links.standAloneTrack());
353  aMuon.setGlobalTrack(links.globalTrack());
354  aMuon.setBestTrack(chosenTrack.second);
355  aMuon.setTunePBestTrack(chosenTrack.second);
356 
358  if (tpfmsCollectionHandle_.isValid() && !tpfmsCollectionHandle_.failedToGet()) {
360  if (it != tpfmsCollectionHandle_->end())
361  aMuon.setMuonTrack(reco::Muon::TPFMS, (it->val));
362  }
363  if (pickyCollectionHandle_.isValid() && !pickyCollectionHandle_.failedToGet()) {
365  if (it != pickyCollectionHandle_->end())
366  aMuon.setMuonTrack(reco::Muon::Picky, (it->val));
367  }
368  if (dytCollectionHandle_.isValid() && !dytCollectionHandle_.failedToGet()) {
370  if (it != dytCollectionHandle_->end())
371  aMuon.setMuonTrack(reco::Muon::DYT, (it->val));
372  }
373  }
374  return aMuon;
375 }
376 
378  // Pt and absolute momentum requirement
379  const double p = track.p();
380  const double pt = track.pt();
381  if (pt < minPt_ || (p < minP_ && p < minPCaloMuon_)) {
382  LogTrace("MuonIdentification") << "Skipped low momentum track (Pt,P): " << pt << ", " << track.p() << " GeV";
383  return false;
384  }
385 
386  // Eta requirement
387  const double eta = track.eta();
388  const double absEta = std::abs(eta);
389  if (absEta > maxAbsEta_) {
390  LogTrace("MuonIdentification") << "Skipped track with large pseudo rapidity (Eta: " << track.eta() << " )";
391  return false;
392  }
393 
394  return true;
395 }
396 
397 unsigned int MuonIdProducer::chamberId(const DetId& id) {
398  if (id.det() != DetId::Muon)
399  return 0;
400 
401  const auto subdetId = id.subdetId();
402  if (subdetId == MuonSubdetId::DT) {
403  return DTChamberId(id.rawId()).rawId();
404  } else if (subdetId == MuonSubdetId::CSC) {
405  return CSCDetId(id.rawId()).chamberId().rawId();
406  }
407 
408  return 0;
409 }
410 
412  if (!muon.isMatchesValid() || track.extra().isNull() || track.extra()->recHitsSize() == 0)
413  return 0;
414 
415  int numberOfCommonDetIds = 0;
416  const std::vector<reco::MuonChamberMatch>& matches(muon.matches());
417  for (const auto& match : matches) {
418  if (match.segmentMatches.empty())
419  continue;
420 
421  bool foundCommonDetId = false;
422  for (auto hit = track.extra()->recHitsBegin(); hit != track.extra()->recHitsEnd(); ++hit) {
423  // LogTrace("MuonIdentification") << "hit DetId: " << std::hex << hit->get()->geographicalId().rawId() <<
424  // "\t hit chamber DetId: " << getChamberId(hit->get()->geographicalId()) <<
425  // "\t segment DetId: " << match->id.rawId() << std::dec;
426 
427  if (chamberId((*hit)->geographicalId()) == match.id.rawId()) {
428  foundCommonDetId = true;
429  break;
430  }
431  }
432  if (foundCommonDetId) {
433  ++numberOfCommonDetIds;
434  break;
435  }
436  }
437  return numberOfCommonDetIds;
438 }
439 
440 void MuonIdProducer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
441  meshAlgo_->setCSCGeometry(&iSetup.getData(geomTokenRun_));
442 
444  theShowerDigiFiller_->getES(iSetup);
445 }
446 
447 bool validateGlobalMuonPair(const reco::MuonTrackLinks& goodMuon, const reco::MuonTrackLinks& badMuon) {
448  const int nHitsGood = goodMuon.globalTrack()->hitPattern().numberOfValidMuonHits();
449  const int nHitsBad = badMuon.globalTrack()->hitPattern().numberOfValidMuonHits();
450  if (std::min(nHitsGood, nHitsBad) > 10) {
451  const double chi2Good = goodMuon.globalTrack()->normalizedChi2();
452  const double chi2Bad = badMuon.globalTrack()->normalizedChi2();
453  return (chi2Good <= chi2Bad);
454  }
455 
456  return (nHitsGood >= nHitsBad);
457 }
458 
460  auto outputMuons = std::make_unique<reco::MuonCollection>();
461  auto caloMuons = std::make_unique<reco::CaloMuonCollection>();
462 
463  init(iEvent, iSetup);
464 
466  theShowerDigiFiller_->getDigis(iEvent);
467 
468  // loop over input collections
469 
470  // muons first - no cleaning, take as is.
472  for (const auto& muon : *muonCollectionHandle_) {
473  outputMuons->push_back(muon);
474  }
475  }
476 
477  // links second ( assume global muon type )
479  const auto nLink = linkCollectionHandle_->size();
480  std::vector<bool> goodmuons(nLink, true);
481  if (nLink > 1) {
482  // check for shared tracker tracks
483  for (unsigned int i = 0; i < nLink - 1; ++i) {
484  const auto& iLink = linkCollectionHandle_->at(i);
485  if (iLink.trackerTrack().isNull() || !checkLinks(&iLink))
486  continue;
487  for (unsigned int j = i + 1; j < nLink; ++j) {
488  const auto& jLink = linkCollectionHandle_->at(j);
489  if (!checkLinks(&jLink))
490  continue;
491  if (iLink.trackerTrack() == jLink.trackerTrack()) {
492  // Tracker track is the essential part that dominates muon resolution
493  // so taking either muon is fine. All that is important is to preserve
494  // the muon identification information. If number of hits is small,
495  // keep the one with large number of hits, otherwise take the smalest chi2/ndof
496  if (validateGlobalMuonPair(iLink, jLink))
497  goodmuons[j] = false;
498  else
499  goodmuons[i] = false;
500  }
501  }
502  }
503  // check for shared stand-alone muons.
504  for (unsigned int i = 0; i < nLink - 1; ++i) {
505  if (!goodmuons[i])
506  continue;
507  const auto& iLink = linkCollectionHandle_->at(i);
508  if (iLink.standAloneTrack().isNull() || !checkLinks(&iLink))
509  continue;
510  for (unsigned int j = i + 1; j < nLink; ++j) {
511  if (!goodmuons[j])
512  continue;
513  const auto& jLink = linkCollectionHandle_->at(j);
514  if (!checkLinks(&jLink))
515  continue;
516  if (iLink.standAloneTrack() == jLink.standAloneTrack()) {
517  if (validateGlobalMuonPair(iLink, jLink))
518  goodmuons[j] = false;
519  else
520  goodmuons[i] = false;
521  }
522  }
523  }
524  }
525  for (unsigned int i = 0; i < nLink; ++i) {
526  if (!goodmuons[i])
527  continue;
528  const auto& iLink = linkCollectionHandle_->at(i);
529  if (!checkLinks(&iLink))
530  continue;
531  // check if this muon is already in the list
532  bool newMuon = true;
533  for (const auto& muon : *outputMuons) {
534  if (muon.track() == iLink.trackerTrack() && muon.standAloneMuon() == iLink.standAloneTrack() &&
535  muon.combinedMuon() == iLink.globalTrack()) {
536  newMuon = false;
537  break;
538  }
539  }
540  if (newMuon) {
541  outputMuons->push_back(makeMuon(iLink));
542  outputMuons->back().setType(reco::Muon::GlobalMuon | reco::Muon::StandAloneMuon);
543  }
544  }
545  }
546 
547  // tracker and calo muons are next
549  LogTrace("MuonIdentification") << "Creating tracker muons";
550  std::vector<TrackDetectorAssociator::Direction> directions1, directions2;
551  directions1.push_back(TrackDetectorAssociator::InsideOut);
552  directions1.push_back(TrackDetectorAssociator::OutsideIn);
553  directions2.push_back(TrackDetectorAssociator::Any);
554 
555  const GlobalTrackingGeometry* geometry = nullptr;
557  geometry = &iSetup.getData(globalGeomToken_);
558  }
559 
560  for (unsigned int i = 0; i < innerTrackCollectionHandle_->size(); ++i) {
562  if (!isGoodTrack(track))
563  continue;
565  const reco::VertexCollection* recoVertices = pvHandle_.product();
566  if (!(*recoVertices)[0].isFake())
567  continue;
568  }
569  const auto& trackRef = reco::TrackRef(innerTrackCollectionHandle_, i);
570  bool splitTrack = false;
571  if (track.extra().isAvailable() && TrackDetectorAssociator::crossedIP(track))
572  splitTrack = true;
573  const auto& directions = splitTrack ? directions1 : directions2;
574  for (const auto direction : directions) {
575  // make muon
577  fillMuonId(iEvent, iSetup, trackerMuon, direction);
578 
580  // add MC hits to a list of matched segments.
581  // Since it's debugging mode - code is slow
583  }
584 
585  // check if this muon is already in the list
586  // have to check where muon hits are really located
587  // to match properly
588  bool newMuon = true;
589  const bool goodTrackerMuon = isGoodTrackerMuon(trackerMuon);
590  const bool goodRPCMuon = isGoodRPCMuon(trackerMuon);
591  const bool goodGEMMuon = isGoodGEMMuon(trackerMuon);
592  const bool goodME0Muon = isGoodME0Muon(trackerMuon);
593  if (goodTrackerMuon)
595  if (goodRPCMuon)
596  trackerMuon.setType(trackerMuon.type() | reco::Muon::RPCMuon);
597  if (goodGEMMuon)
598  trackerMuon.setType(trackerMuon.type() | reco::Muon::GEMMuon);
599  if (goodME0Muon)
600  trackerMuon.setType(trackerMuon.type() | reco::Muon::ME0Muon);
601 
602  for (auto& muon : *outputMuons) {
603  if (muon.innerTrack().get() == trackerMuon.innerTrack().get() &&
605  M_PI_2) {
606  newMuon = false;
607  muon.setMatches(trackerMuon.matches());
608  if (trackerMuon.isTimeValid())
609  muon.setTime(trackerMuon.time());
610  if (trackerMuon.isEnergyValid())
611  muon.setCalEnergy(trackerMuon.calEnergy());
612  if (goodTrackerMuon)
613  muon.setType(muon.type() | reco::Muon::TrackerMuon);
614  if (goodRPCMuon)
615  muon.setType(muon.type() | reco::Muon::RPCMuon);
616  if (goodGEMMuon)
617  muon.setType(muon.type() | reco::Muon::GEMMuon);
618  if (goodME0Muon)
619  muon.setType(muon.type() | reco::Muon::ME0Muon);
620  LogTrace("MuonIdentification") << "Found a corresponding global muon. Set energy, matches and move on";
621  break;
622  }
623  }
624  if (newMuon) {
625  if (goodTrackerMuon || goodRPCMuon || goodGEMMuon || goodME0Muon) {
626  outputMuons->push_back(trackerMuon);
627  } else {
628  LogTrace("MuonIdentification") << "track failed minimal number of muon matches requirement";
629  const reco::CaloMuon& caloMuon = makeCaloMuon(trackerMuon);
630  if (isGoodCaloMuon(caloMuon))
631  caloMuons->push_back(caloMuon);
632  }
633  }
634  }
635  }
636  }
637 
638  // and at last the stand alone muons
640  LogTrace("MuonIdentification") << "Looking for new muons among stand alone muon tracks";
641  const unsigned int nouter = outerTrackCollectionHandle_->size();
642  const unsigned int nsecond =
644  for (unsigned int i = 0; i < nouter + nsecond; ++i) {
645  const auto& outerTrack =
646  (i < nouter) ? outerTrackCollectionHandle_->at(i) : outerTrackSecondaryCollectionHandle_->at(i - nouter);
647  reco::TrackRef refToTrack = (i < nouter) ? reco::TrackRef(outerTrackCollectionHandle_, i)
649 
650  // check if this muon is already in the list of global muons
651  bool newMuon = true;
652  for (auto& muon : *outputMuons) {
653  if (!muon.standAloneMuon().isNull()) {
654  // global muon
655  if (muon.standAloneMuon().get() == &outerTrack ||
656  (muon.standAloneMuon()->extra().isNonnull() &&
657  muon.standAloneMuon()->extra().get() == outerTrack.extra().get())) {
658  newMuon = false;
659  break;
660  }
661  } else {
662  // tracker muon - no direct links to the standalone muon
663  // since we have only a few real muons in an event, matching
664  // the stand alone muon to the tracker muon by DetIds should
665  // be good enough for association. At the end it's up to a
666  // user to redefine the association and what it means. Here
667  // we would like to avoid obvious double counting and we
668  // tolerate a potential miss association
669  if (overlap(muon, outerTrack) > 0) {
670  LogTrace("MuonIdentification") << "Found associated tracker muon. Set a reference and move on";
671  newMuon = false;
672  muon.setOuterTrack(refToTrack);
673  muon.setType(muon.type() | reco::Muon::StandAloneMuon);
674  break;
675  }
676  }
677  }
678  if (newMuon) {
679  LogTrace("MuonIdentification") << "No associated stand alone track is found. Making a muon";
680  outputMuons->push_back(makeMuon(iEvent, iSetup, refToTrack, reco::Muon::OuterTrack));
681  outputMuons->back().setType(reco::Muon::StandAloneMuon);
682  }
683  }
684  }
685 
687  fillArbitrationInfo(outputMuons.get(), reco::Muon::TrackerMuon);
688  fillArbitrationInfo(outputMuons.get(), reco::Muon::GEMMuon);
689  fillArbitrationInfo(outputMuons.get(), reco::Muon::ME0Muon);
690  arbitrateMuons(outputMuons.get(), caloMuons.get());
691  }
692 
693  LogTrace("MuonIdentification") << "Dress up muons if it's necessary";
694 
695  const int nMuons = outputMuons->size();
696 
697  std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
698  std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
699  std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
700  std::vector<reco::IsoDeposit> trackDepColl(nMuons);
701  std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
702  std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
703  std::vector<reco::IsoDeposit> hoDepColl(nMuons);
704  std::vector<reco::IsoDeposit> jetDepColl(nMuons);
705 
706  // Fill various information
707  for (unsigned int i = 0; i < outputMuons->size(); ++i) {
708  auto& muon = outputMuons->at(i);
709 
710  // Fill muonID
711  if ((fillMatching_ && !muon.isMatchesValid()) || (fillEnergy_ && !muon.isEnergyValid())) {
712  // predict direction based on the muon interaction region location
713  // if it's available
714  if (muon.isStandAloneMuon()) {
717  } else {
719  }
720  } else {
721  LogTrace("MuonIdentification") << "THIS SHOULD NEVER HAPPEN";
722  fillMuonId(iEvent, iSetup, muon);
723  }
724  }
725 
727  // Fill global quality information
728  fillGlbQuality(iEvent, iSetup, muon);
729  }
730  LogDebug("MuonIdentification") << "";
731 
732  if (fillTrackerKink_) {
734  }
735 
737  muon.setCaloCompatibility(muonCaloCompatibility_.evaluate(muon));
738 
739  if (fillIsolation_) {
741  iEvent, iSetup, muon, trackDepColl[i], ecalDepColl[i], hcalDepColl[i], hoDepColl[i], jetDepColl[i]);
742  }
743 
744  // fill timing information
745  reco::MuonTime muonTime;
746  reco::MuonTimeExtra dtTime;
747  reco::MuonTimeExtra cscTime;
748  reco::MuonTime rpcTime;
749  reco::MuonTimeExtra combinedTime;
750 
751  theTimingFiller_->fillTiming(muon, dtTime, cscTime, rpcTime, combinedTime, iEvent, iSetup);
752 
753  muonTime.nDof = combinedTime.nDof();
754  muonTime.timeAtIpInOut = combinedTime.timeAtIpInOut();
755  muonTime.timeAtIpInOutErr = combinedTime.timeAtIpInOutErr();
756  muonTime.timeAtIpOutIn = combinedTime.timeAtIpOutIn();
757  muonTime.timeAtIpOutInErr = combinedTime.timeAtIpOutInErr();
758 
759  muon.setTime(muonTime);
760  muon.setRPCTime(rpcTime);
761  dtTimeColl[i] = dtTime;
762  cscTimeColl[i] = cscTime;
763  combinedTimeColl[i] = combinedTime;
764  }
765 
766  LogTrace("MuonIdentification") << "number of muons produced: " << outputMuons->size();
767  if (fillMatching_) {
768  fillArbitrationInfo(outputMuons.get(), reco::Muon::TrackerMuon);
769  fillArbitrationInfo(outputMuons.get(), reco::Muon::ME0Muon);
770  fillArbitrationInfo(outputMuons.get(), reco::Muon::GEMMuon);
771  }
772  edm::OrphanHandle<reco::MuonCollection> muonHandle = iEvent.put(std::move(outputMuons));
773 
774  auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = "") {
776  auto oMap = std::make_unique<MapType>();
777  {
778  typename MapType::Filler filler(*oMap);
779  filler.insert(refH, vec.begin(), vec.end());
780  vec.clear();
781  filler.fill();
782  }
783  ev.put(std::move(oMap), cAl);
784  };
785  fillMap(muonHandle, combinedTimeColl, iEvent, "combined");
786  fillMap(muonHandle, dtTimeColl, iEvent, "dt");
787  fillMap(muonHandle, cscTimeColl, iEvent, "csc");
788 
790  fillMap(muonHandle, trackDepColl, iEvent, trackDepositName_);
791  fillMap(muonHandle, ecalDepColl, iEvent, ecalDepositName_);
792  fillMap(muonHandle, hcalDepColl, iEvent, hcalDepositName_);
793  fillMap(muonHandle, hoDepColl, iEvent, hoDepositName_);
794  fillMap(muonHandle, jetDepColl, iEvent, jetDepositName_);
795  }
796 
797  iEvent.put(std::move(caloMuons));
798 }
799 
801  if (muon.track()->pt() < minPt_ || muon.track()->p() < minP_)
802  return false;
803  // NoArbitration checks for CSC/DT segments only, also use ME0 segments
804  int numMatches = muon.numberOfMatches(reco::Muon::NoArbitration);
805  if (addExtraSoftMuons_ && muon.pt() < 5 && std::abs(muon.eta()) < 1.5 && numMatches >= 1)
806  return true;
807  return (numMatches >= minNumberOfMatches_);
808 }
809 
811  if (!caloMuon.isCaloCompatibilityValid() || caloMuon.caloCompatibility() < caloCut_ || caloMuon.p() < minPCaloMuon_)
812  return false;
813  return true;
814 }
815 
817  if (muon.track()->pt() < minPt_ || muon.track()->p() < minP_)
818  return false;
819  if (addExtraSoftMuons_ && muon.pt() < 5 && std::abs(muon.eta()) < 1.5 &&
820  muon.numberOfMatchedRPCLayers(reco::Muon::RPCHitAndTrackArbitration) > 1)
821  return true;
822  return (muon.numberOfMatchedRPCLayers(reco::Muon::RPCHitAndTrackArbitration) > minNumberOfMatches_);
823 }
824 
826  // require GEMMuon to be a TrackerMuon
827  if (!isGoodTrackerMuon(muon))
828  return false;
829  if (muon.track()->pt() < minPt_ || muon.track()->p() < minP_)
830  return false;
831  //
832  int numMatches = 0;
833  for (auto& chamberMatch : muon.matches()) {
834  if (chamberMatch.gemMatches.empty())
835  continue;
836  numMatches += chamberMatch.gemMatches.size();
837  }
838  return (numMatches + muon.numberOfMatches(reco::Muon::GEMHitAndTrackArbitration)) >= 1;
839 }
840 
842  // need to update min cuts on pt
843  if (muon.track()->p() < minP_)
844  return false;
845  return (muon.numberOfMatches(reco::Muon::ME0SegmentAndTrackArbitration) >= 1);
846 }
847 
849  const edm::EventSetup& iSetup,
850  reco::Muon& aMuon,
852  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId";
853 
854  // perform track - detector association
855  const reco::Track* track = nullptr;
856  if (aMuon.track().isNonnull())
857  track = aMuon.track().get();
858  else if (aMuon.standAloneMuon().isNonnull())
859  track = aMuon.standAloneMuon().get();
860  else
861  throw cms::Exception("FatalError")
862  << "Failed to fill muon id information for a muon with undefined references to tracks";
863 
865 
866  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fillEnergy = " << fillEnergy_;
867 
868  if (fillEnergy_) {
870  muonEnergy.em = info.crossedEnergy(TrackDetMatchInfo::EcalRecHits);
871  muonEnergy.had = info.crossedEnergy(TrackDetMatchInfo::HcalRecHits);
872  muonEnergy.ho = info.crossedEnergy(TrackDetMatchInfo::HORecHits);
873  muonEnergy.tower = info.crossedEnergy(TrackDetMatchInfo::TowerTotal);
874  muonEnergy.emS9 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 1); // 3x3 energy
875  muonEnergy.emS25 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits, 2); // 5x5 energy
876  muonEnergy.hadS9 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits, 1); // 3x3 energy
877  muonEnergy.hoS9 = info.nXnEnergy(TrackDetMatchInfo::HORecHits, 1); // 3x3 energy
878  muonEnergy.towerS9 = info.nXnEnergy(TrackDetMatchInfo::TowerTotal, 1); // 3x3 energy
880  muonEnergy.crossedHadRecHits.clear();
881  for (auto hit : info.crossedHcalRecHits) {
883  mhit.energy = hit->energy();
884  mhit.chi2 = hit->chi2();
885  mhit.time = hit->time();
886  mhit.detId = hit->id();
887  muonEnergy.crossedHadRecHits.push_back(mhit);
888  }
889  }
890  muonEnergy.ecal_position = info.trkGlobPosAtEcal;
891  muonEnergy.hcal_position = info.trkGlobPosAtHcal;
892  if (!info.crossedEcalIds.empty())
893  muonEnergy.ecal_id = info.crossedEcalIds.front();
894  if (!info.crossedHcalIds.empty())
895  muonEnergy.hcal_id = info.crossedHcalIds.front();
896  // find maximal energy depositions and their time
897  DetId emMaxId = info.findMaxDeposition(TrackDetMatchInfo::EcalRecHits, 2); // max energy deposit in 5x5 shape
898  for (const auto& hit : info.ecalRecHits) {
899  if (hit->id() != emMaxId)
900  continue;
901  muonEnergy.emMax = hit->energy();
902  muonEnergy.ecal_time = hit->time();
903  }
904  DetId hadMaxId = info.findMaxDeposition(TrackDetMatchInfo::HcalRecHits, 1); // max energy deposit in 3x3 shape
905  for (const auto& hit : info.hcalRecHits) {
906  if (hit->id() != hadMaxId)
907  continue;
908  muonEnergy.hadMax = hit->energy();
909  muonEnergy.hcal_time = hit->time();
910  }
911  aMuon.setCalEnergy(muonEnergy);
912  }
913  if (!fillMatching_ && !aMuon.isTrackerMuon() && !aMuon.isRPCMuon() && !aMuon.isGEMMuon())
914  return;
915 
916  // fill muon match info
917  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fill muon match info ";
918  std::vector<reco::MuonChamberMatch> muonChamberMatches;
919  unsigned int nubmerOfMatchesAccordingToTrackAssociator = 0;
920  for (const auto& chamber : info.chambers) {
921  if (chamber.id.subdetId() == MuonSubdetId::RPC && rpcHitHandle_.isValid())
922  continue; // Skip RPC chambers, they are taken care of below)
923  if (chamber.id.subdetId() == MuonSubdetId::GEM && gemHitHandle_.isValid() &&
924  GEMDetId(chamber.id.rawId()).station() != 0)
925  continue; // Skip GE1/1 and 2/1 chambers, they are taken care of below)
926  reco::MuonChamberMatch matchedChamber;
927 
928  const auto& lErr = chamber.tState.localError();
929  const auto& lPos = chamber.tState.localPosition();
930  const auto& lDir = chamber.tState.localDirection();
931 
932  const auto& localError = lErr.positionError();
933  matchedChamber.x = lPos.x();
934  matchedChamber.y = lPos.y();
935  matchedChamber.xErr = sqrt(localError.xx());
936  matchedChamber.yErr = sqrt(localError.yy());
937 
938  matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999;
939  matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999;
940  // DANGEROUS - compiler cannot guaranty parameters ordering
941  AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix();
942  matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0;
943  matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0;
944 
945  matchedChamber.edgeX = chamber.localDistanceX;
946  matchedChamber.edgeY = chamber.localDistanceY;
947 
948  matchedChamber.id = chamber.id;
949 
951  theShowerDigiFiller_->fill(matchedChamber);
952  } else {
953  theShowerDigiFiller_->fillDefault(matchedChamber);
954  }
955 
956  if (!chamber.segments.empty())
957  ++nubmerOfMatchesAccordingToTrackAssociator;
958 
959  // fill segments
960  for (const auto& segment : chamber.segments) {
961  reco::MuonSegmentMatch matchedSegment;
962  matchedSegment.x = segment.segmentLocalPosition.x();
963  matchedSegment.y = segment.segmentLocalPosition.y();
964  matchedSegment.dXdZ =
965  segment.segmentLocalDirection.z() ? segment.segmentLocalDirection.x() / segment.segmentLocalDirection.z() : 0;
966  matchedSegment.dYdZ =
967  segment.segmentLocalDirection.z() ? segment.segmentLocalDirection.y() / segment.segmentLocalDirection.z() : 0;
968  matchedSegment.xErr = segment.segmentLocalErrorXX > 0 ? sqrt(segment.segmentLocalErrorXX) : 0;
969  matchedSegment.yErr = segment.segmentLocalErrorYY > 0 ? sqrt(segment.segmentLocalErrorYY) : 0;
970  matchedSegment.dXdZErr = segment.segmentLocalErrorDxDz > 0 ? sqrt(segment.segmentLocalErrorDxDz) : 0;
971  matchedSegment.dYdZErr = segment.segmentLocalErrorDyDz > 0 ? sqrt(segment.segmentLocalErrorDyDz) : 0;
972  matchedSegment.t0 = segment.t0;
973  matchedSegment.mask = 0;
974  matchedSegment.dtSegmentRef = segment.dtSegmentRef;
975  matchedSegment.cscSegmentRef = segment.cscSegmentRef;
976  matchedSegment.gemSegmentRef = segment.gemSegmentRef;
977  matchedSegment.me0SegmentRef = segment.me0SegmentRef;
978  matchedSegment.hasZed_ = segment.hasZed;
979  matchedSegment.hasPhi_ = segment.hasPhi;
980  // test segment
981  bool matchedX = false;
982  bool matchedY = false;
983  LogTrace("MuonIdentification") << " matching local x, segment x: " << matchedSegment.x
984  << ", chamber x: " << matchedChamber.x << ", max: " << maxAbsDx_;
985  LogTrace("MuonIdentification") << " matching local y, segment y: " << matchedSegment.y
986  << ", chamber y: " << matchedChamber.y << ", max: " << maxAbsDy_;
987  const double matchedSegChDx = std::abs(matchedSegment.x - matchedChamber.x);
988  const double matchedSegChDy = std::abs(matchedSegment.y - matchedChamber.y);
989  if (matchedSegment.xErr > 0 && matchedChamber.xErr > 0)
990  LogTrace("MuonIdentification") << " xpull: "
991  << matchedSegChDx / std::sqrt(std::pow(matchedSegment.xErr, 2) +
992  std::pow(matchedChamber.xErr, 2));
993  if (matchedSegment.yErr > 0 && matchedChamber.yErr > 0)
994  LogTrace("MuonIdentification") << " ypull: "
995  << matchedSegChDy / std::sqrt(std::pow(matchedSegment.yErr, 2) +
996  std::pow(matchedChamber.yErr, 2));
997 
998  if (matchedSegChDx < maxAbsDx_)
999  matchedX = true;
1000  else if (matchedSegment.xErr > 0 && matchedChamber.xErr > 0) {
1001  const double invMatchedSegChPullX2 = std::pow(matchedSegment.xErr, 2) + std::pow(matchedChamber.xErr, 2);
1002  if (matchedSegChDx * matchedSegChDx < maxAbsPullX2_ * invMatchedSegChPullX2)
1003  matchedX = true;
1004  }
1005  if (matchedSegChDy < maxAbsDy_)
1006  matchedY = true;
1007  else if (matchedSegment.yErr > 0 && matchedChamber.yErr > 0) {
1008  const double invMatchedSegChPullY2 = std::pow(matchedSegment.yErr, 2) + std::pow(matchedChamber.yErr, 2);
1009  if (matchedSegChDy * matchedSegChDy < maxAbsPullY2_ * invMatchedSegChPullY2)
1010  matchedY = true;
1011  }
1012  if (matchedX && matchedY) {
1013  if (matchedChamber.id.subdetId() == MuonSubdetId::ME0)
1014  matchedChamber.me0Matches.push_back(matchedSegment);
1015  else if (matchedChamber.id.subdetId() == MuonSubdetId::GEM)
1016  matchedChamber.gemMatches.push_back(matchedSegment);
1017  else
1018  matchedChamber.segmentMatches.push_back(matchedSegment);
1019  }
1020  }
1021  muonChamberMatches.push_back(matchedChamber);
1022  }
1023 
1024  // Fill RPC info
1025  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fill RPC info";
1026  if (rpcHitHandle_.isValid()) {
1027  for (const auto& chamber : info.chambers) {
1028  if (chamber.id.subdetId() != MuonSubdetId::RPC)
1029  continue; // Consider RPC chambers only
1030  const auto& lErr = chamber.tState.localError();
1031  const auto& lPos = chamber.tState.localPosition();
1032  const auto& lDir = chamber.tState.localDirection();
1033 
1034  reco::MuonChamberMatch matchedChamber;
1035 
1036  LocalError localError = lErr.positionError();
1037  matchedChamber.x = lPos.x();
1038  matchedChamber.y = lPos.y();
1039  matchedChamber.xErr = sqrt(localError.xx());
1040  matchedChamber.yErr = sqrt(localError.yy());
1041 
1042  matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999;
1043  matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999;
1044  // DANGEROUS - compiler cannot guaranty parameters ordering
1045  AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix();
1046  matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0;
1047  matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0;
1048 
1049  matchedChamber.edgeX = chamber.localDistanceX;
1050  matchedChamber.edgeY = chamber.localDistanceY;
1051 
1052  theShowerDigiFiller_->fillDefault(matchedChamber);
1053 
1054  matchedChamber.id = chamber.id;
1055 
1056  for (const auto& rpcRecHit : *rpcHitHandle_) {
1057  reco::MuonRPCHitMatch rpcHitMatch;
1058 
1059  if (rpcRecHit.rawId() != chamber.id.rawId())
1060  continue;
1061 
1062  rpcHitMatch.x = rpcRecHit.localPosition().x();
1063  rpcHitMatch.mask = 0;
1064  rpcHitMatch.bx = rpcRecHit.BunchX();
1065 
1066  const double absDx = std::abs(rpcRecHit.localPosition().x() - chamber.tState.localPosition().x());
1067  if (absDx <= 20 or absDx * absDx <= 16 * localError.xx())
1068  matchedChamber.rpcMatches.push_back(rpcHitMatch);
1069  }
1070 
1071  muonChamberMatches.push_back(matchedChamber);
1072  }
1073  }
1074 
1075  // Fill GEM info
1076  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fill GEM info";
1077  if (gemHitHandle_.isValid()) {
1078  for (const auto& chamber : info.chambers) {
1079  // only GE1/1 and 2/1 are for rechits, reject station 0 and segments (layer==0 for GEMSegment)
1080  if (chamber.id.subdetId() != MuonSubdetId::GEM || GEMDetId(chamber.id.rawId()).station() == 0 ||
1081  GEMDetId(chamber.id.rawId()).layer() == 0)
1082  continue; // Consider GEM chambers only
1083  const auto& lErr = chamber.tState.localError();
1084  const auto& lPos = chamber.tState.localPosition();
1085  const auto& lDir = chamber.tState.localDirection();
1086 
1087  reco::MuonChamberMatch matchedChamber;
1088 
1089  LocalError localError = lErr.positionError();
1090  matchedChamber.x = lPos.x();
1091  matchedChamber.y = lPos.y();
1092  matchedChamber.xErr = sqrt(localError.xx());
1093  matchedChamber.yErr = sqrt(localError.yy());
1094 
1095  matchedChamber.dXdZ = lDir.z() != 0 ? lDir.x() / lDir.z() : 9999;
1096  matchedChamber.dYdZ = lDir.z() != 0 ? lDir.y() / lDir.z() : 9999;
1097  // DANGEROUS - compiler cannot guaranty parameters ordering
1098  AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix();
1099  matchedChamber.dXdZErr = trajectoryCovMatrix(1, 1) > 0 ? sqrt(trajectoryCovMatrix(1, 1)) : 0;
1100  matchedChamber.dYdZErr = trajectoryCovMatrix(2, 2) > 0 ? sqrt(trajectoryCovMatrix(2, 2)) : 0;
1101 
1102  matchedChamber.edgeX = chamber.localDistanceX;
1103  matchedChamber.edgeY = chamber.localDistanceY;
1104 
1105  theShowerDigiFiller_->fillDefault(matchedChamber);
1106 
1107  matchedChamber.id = chamber.id;
1108 
1109  for (const auto& gemRecHit : *gemHitHandle_) {
1110  reco::MuonGEMHitMatch gemHitMatch;
1111 
1112  if (GEMDetId(gemRecHit.gemId().region(),
1113  gemRecHit.gemId().ring(),
1114  gemRecHit.gemId().station(),
1115  gemRecHit.gemId().layer(),
1116  gemRecHit.gemId().chamber(),
1117  0)
1118  .rawId() != chamber.id.rawId())
1119  continue;
1120 
1121  gemHitMatch.x = gemRecHit.localPosition().x();
1122  gemHitMatch.mask = 0;
1123  gemHitMatch.bx = gemRecHit.BunchX();
1124 
1125  const double absDx = std::abs(gemRecHit.localPosition().x() - chamber.tState.localPosition().x());
1126  if (absDx <= 5 or absDx * absDx <= 16 * localError.xx())
1127  matchedChamber.gemHitMatches.push_back(gemHitMatch);
1128  }
1129 
1130  muonChamberMatches.push_back(matchedChamber);
1131  }
1132  }
1133 
1134  aMuon.setMatches(muonChamberMatches);
1135 
1136  LogTrace("MuonIdentification") << "number of muon chambers: " << aMuon.matches().size() << "\n"
1137  << "number of chambers with segments according to the associator requirements: "
1138  << nubmerOfMatchesAccordingToTrackAssociator;
1139  LogTrace("MuonIdentification") << "number of segment matches with the producer requirements: "
1141 
1142  // fillTime( iEvent, iSetup, aMuon );
1143 }
1144 
1147  // arbitrate TrackerMuons
1148  // if a muon was exclusively TrackerMuon check if it can be a calo muon
1149  for (reco::MuonCollection::iterator muon = muons->begin(); muon != muons->end();) {
1150  if (muon->isTrackerMuon()) {
1151  int numMatches =
1152  muon->numberOfMatches(reco::Muon::GEMSegmentAndTrackArbitration) + muon->numberOfMatches(arbitration);
1153  if (numMatches < minNumberOfMatches_) {
1154  // TrackerMuon failed arbitration
1155  // If not any other base type - erase the element
1156  // (PFMuon is not a base type)
1157  // GEMMuon should be a subset of TrackerMuon, so don't count it either
1159  if ((muon->type() & (~mask)) == 0) {
1160  const reco::CaloMuon& caloMuon = makeCaloMuon(*muon);
1161  if (isGoodCaloMuon(caloMuon))
1162  caloMuons->push_back(caloMuon);
1163  muon = muons->erase(muon);
1164  continue;
1165  } else {
1166  muon->setType(muon->type() & (~(reco::Muon::TrackerMuon | reco::Muon::GEMMuon)));
1167  }
1168  }
1169  }
1170  muon++;
1171  }
1172 }
1173 
1174 void MuonIdProducer::fillArbitrationInfo(reco::MuonCollection* pOutputMuons, unsigned int muonType) {
1175  //
1176  // apply segment flags
1177  //
1178  std::vector<std::pair<reco::MuonChamberMatch*, reco::MuonSegmentMatch*> > chamberPairs; // for chamber segment sorting
1179  std::vector<std::pair<reco::MuonChamberMatch*, reco::MuonSegmentMatch*> > stationPairs; // for station segment sorting
1180  std::vector<std::pair<reco::MuonChamberMatch*, reco::MuonSegmentMatch*> >
1181  arbitrationPairs; // for muon segment arbitration
1182 
1183  // muonIndex1
1184  for (unsigned int muonIndex1 = 0; muonIndex1 < pOutputMuons->size(); ++muonIndex1) {
1185  auto& muon1 = pOutputMuons->at(muonIndex1);
1186  // chamberIter1
1187  for (auto& chamber1 : muon1.matches()) {
1188  // segmentIter1
1189  std::vector<reco::MuonSegmentMatch>* segmentMatches1 = getSegmentMatches(chamber1, muonType);
1190 
1191  if (segmentMatches1->empty())
1192  continue;
1193  chamberPairs.clear();
1194 
1195  for (auto& segment1 : *segmentMatches1) {
1196  chamberPairs.push_back(std::make_pair(&chamber1, &segment1));
1197  if (!segment1.isMask()) // has not yet been arbitrated
1198  {
1199  arbitrationPairs.clear();
1200  arbitrationPairs.push_back(std::make_pair(&chamber1, &segment1));
1201 
1202  // find identical segments with which to arbitrate
1203  // tracker muons only
1204  if (muon1.type() & muonType) {
1205  // muonIndex2
1206  for (unsigned int muonIndex2 = muonIndex1 + 1; muonIndex2 < pOutputMuons->size(); ++muonIndex2) {
1207  auto& muon2 = pOutputMuons->at(muonIndex2);
1208  // tracker muons only
1209  if (!(muon2.type() & muonType))
1210  continue;
1211  // chamberIter2
1212  for (auto& chamber2 : muon2.matches()) {
1213  // segmentIter2
1214  std::vector<reco::MuonSegmentMatch>* segmentMatches2 = getSegmentMatches(chamber2, muonType);
1215  for (auto& segment2 : *segmentMatches2) {
1216  if (segment2.isMask())
1217  continue; // has already been arbitrated
1218  if (approxEqual(segment2.x, segment1.x) && approxEqual(segment2.y, segment1.y) &&
1219  approxEqual(segment2.dXdZ, segment1.dXdZ) && approxEqual(segment2.dYdZ, segment1.dYdZ) &&
1220  approxEqual(segment2.xErr, segment1.xErr) && approxEqual(segment2.yErr, segment1.yErr) &&
1221  approxEqual(segment2.dXdZErr, segment1.dXdZErr) &&
1222  approxEqual(segment2.dYdZErr, segment1.dYdZErr)) {
1223  arbitrationPairs.push_back(std::make_pair(&chamber2, &segment2));
1224  }
1225  } // segmentIter2
1226  } // chamberIter2
1227  } // muonIndex2
1228  }
1229 
1230  // arbitration segment sort
1231  if (arbitrationPairs.empty())
1232  continue; // this should never happen
1233  if (arbitrationPairs.size() == 1) {
1234  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDRSlope);
1235  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDXSlope);
1236  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDR);
1237  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDX);
1238  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::Arbitrated);
1239  } else {
1240  sort(arbitrationPairs.begin(),
1241  arbitrationPairs.end(),
1243  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDRSlope);
1244  sort(arbitrationPairs.begin(),
1245  arbitrationPairs.end(),
1247  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDXSlope);
1248  sort(arbitrationPairs.begin(),
1249  arbitrationPairs.end(),
1251  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDR);
1252  sort(arbitrationPairs.begin(),
1253  arbitrationPairs.end(),
1255  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDX);
1256  for (auto& ap : arbitrationPairs) {
1257  ap.second->setMask(reco::MuonSegmentMatch::Arbitrated);
1258  }
1259  }
1260  }
1261 
1262  // setup me1a cleaning for later
1263  if (muonType == reco::Muon::TrackerMuon && chamber1.id.subdetId() == MuonSubdetId::CSC && arbClean_ &&
1264  CSCDetId(chamber1.id).ring() == 4) {
1265  for (auto& segment2 : chamber1.segmentMatches) {
1266  if (segment1.cscSegmentRef.isNull() || segment2.cscSegmentRef.isNull())
1267  continue;
1268  if (meshAlgo_->isDuplicateOf(segment1.cscSegmentRef, segment2.cscSegmentRef) &&
1269  (segment2.mask & 0x1e0000) && (segment1.mask & 0x1e0000)) {
1271  //if the track has lost the segment already through normal arbitration no need to do it again.
1272  }
1273  }
1274  } // mark all ME1/a duplicates that this track owns
1275 
1276  } // segmentIter1
1277 
1278  // chamber segment sort
1279  if (chamberPairs.empty())
1280  continue; // this should never happen
1281  if (chamberPairs.size() == 1) {
1282  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDRSlope);
1283  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDXSlope);
1284  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDR);
1285  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDX);
1286  } else {
1287  sort(chamberPairs.begin(),
1288  chamberPairs.end(),
1290  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDRSlope);
1291  sort(chamberPairs.begin(),
1292  chamberPairs.end(),
1294  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDXSlope);
1295  sort(chamberPairs.begin(),
1296  chamberPairs.end(),
1298  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDR);
1299  sort(chamberPairs.begin(),
1300  chamberPairs.end(),
1302  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDX);
1303  }
1304  } // chamberIter1
1305 
1306  // station segment sort
1307  for (int stationIndex = 1; stationIndex < 5; ++stationIndex) {
1308  for (int detectorIndex = 1; detectorIndex <= 5;
1309  ++detectorIndex) // 1-5, as in DataFormats/MuonDetId/interface/MuonSubdetId.h
1310  {
1311  stationPairs.clear();
1312 
1313  // chamberIter
1314  for (auto& chamber : muon1.matches()) {
1315  if (!(chamber.station() == stationIndex && chamber.detector() == detectorIndex))
1316  continue;
1317  std::vector<reco::MuonSegmentMatch>* segmentMatches = getSegmentMatches(chamber, muonType);
1318  if (segmentMatches->empty())
1319  continue;
1320 
1321  for (auto& segment : *segmentMatches) {
1322  stationPairs.push_back(std::make_pair(&chamber, &segment));
1323  }
1324  } // chamberIter
1325 
1326  if (stationPairs.empty())
1327  continue; // this may very well happen
1328  if (stationPairs.size() == 1) {
1329  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDRSlope);
1330  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDXSlope);
1331  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDR);
1332  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDX);
1333  } else {
1334  sort(stationPairs.begin(),
1335  stationPairs.end(),
1337  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDRSlope);
1338  sort(stationPairs.begin(),
1339  stationPairs.end(),
1341  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDXSlope);
1342  sort(stationPairs.begin(),
1343  stationPairs.end(),
1345  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDR);
1346  sort(stationPairs.begin(),
1347  stationPairs.end(),
1349  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDX);
1350  }
1351  }
1352  }
1353 
1354  } // muonIndex1
1355 
1356  if (arbClean_) {
1357  // clear old mesh, create and prune new mesh!
1358  meshAlgo_->clearMesh();
1359  meshAlgo_->runMesh(pOutputMuons);
1360  }
1361 }
1362 
1364  const edm::EventSetup& iSetup,
1365  reco::Muon& aMuon,
1366  reco::IsoDeposit& trackDep,
1367  reco::IsoDeposit& ecalDep,
1368  reco::IsoDeposit& hcalDep,
1369  reco::IsoDeposit& hoDep,
1370  reco::IsoDeposit& jetDep) {
1371  const reco::Track* track = nullptr;
1372  if (aMuon.track().isNonnull())
1373  track = aMuon.track().get();
1374  else if (aMuon.standAloneMuon().isNonnull())
1375  track = aMuon.standAloneMuon().get();
1376  else
1377  throw cms::Exception("FatalError")
1378  << "Failed to compute muon isolation information for a muon with undefined references to tracks";
1379 
1380  reco::MuonIsolation isoR03, isoR05;
1381 
1382  // get deposits
1383  reco::IsoDeposit depTrk = muIsoExtractorTrack_->deposit(iEvent, iSetup, *track);
1384  std::vector<reco::IsoDeposit> caloDeps = muIsoExtractorCalo_->deposits(iEvent, iSetup, *track);
1385  reco::IsoDeposit depJet = muIsoExtractorJet_->deposit(iEvent, iSetup, *track);
1386 
1387  if (caloDeps.size() != 3) {
1388  LogTrace("MuonIdentification") << "Failed to fill vector of calorimeter isolation deposits!";
1389  return;
1390  }
1391 
1392  reco::IsoDeposit depEcal = caloDeps.at(0);
1393  reco::IsoDeposit depHcal = caloDeps.at(1);
1394  reco::IsoDeposit depHo = caloDeps.at(2);
1395 
1396  //no need to copy outside if we don't write them
1397  if (writeIsoDeposits_) {
1398  trackDep = depTrk;
1399  ecalDep = depEcal;
1400  hcalDep = depHcal;
1401  hoDep = depHo;
1402  jetDep = depJet;
1403  }
1404 
1405  isoR03.sumPt = depTrk.depositWithin(0.3);
1406  isoR03.emEt = depEcal.depositWithin(0.3);
1407  isoR03.hadEt = depHcal.depositWithin(0.3);
1408  isoR03.hoEt = depHo.depositWithin(0.3);
1409  isoR03.nTracks = depTrk.depositAndCountWithin(0.3).second;
1410  isoR03.nJets = depJet.depositAndCountWithin(0.3).second;
1411  isoR03.trackerVetoPt = depTrk.candEnergy();
1412  isoR03.emVetoEt = depEcal.candEnergy();
1413  isoR03.hadVetoEt = depHcal.candEnergy();
1414  isoR03.hoVetoEt = depHo.candEnergy();
1415 
1416  isoR05.sumPt = depTrk.depositWithin(0.5);
1417  isoR05.emEt = depEcal.depositWithin(0.5);
1418  isoR05.hadEt = depHcal.depositWithin(0.5);
1419  isoR05.hoEt = depHo.depositWithin(0.5);
1420  isoR05.nTracks = depTrk.depositAndCountWithin(0.5).second;
1421  isoR05.nJets = depJet.depositAndCountWithin(0.5).second;
1422  isoR05.trackerVetoPt = depTrk.candEnergy();
1423  isoR05.emVetoEt = depEcal.candEnergy();
1424  isoR05.hadVetoEt = depHcal.candEnergy();
1425  isoR05.hoVetoEt = depHo.candEnergy();
1426 
1427  aMuon.setIsolation(isoR03, isoR05);
1428 }
1429 
1431  const double energy = std::sqrt(track.p() * track.p() + 0.105658369 * 0.105658369);
1432  const math::XYZTLorentzVector p4(track.px(), track.py(), track.pz(), energy);
1433  return reco::Muon(track.charge(), p4, track.vertex());
1434 }
1435 
1437  double phi = 0;
1438  if (id.subdetId() == MuonSubdetId::DT) { // DT
1439  DTChamberId muonId(id.rawId());
1440  if (muonId.sector() <= 12)
1441  phi = (muonId.sector() - 1) / 6. * M_PI;
1442  if (muonId.sector() == 13)
1443  phi = 3 / 6. * M_PI;
1444  if (muonId.sector() == 14)
1445  phi = 9 / 6. * M_PI;
1446  }
1447  if (id.subdetId() == MuonSubdetId::CSC) { // CSC
1448  CSCDetId muonId(id.rawId());
1449  phi = M_PI / 4 + (muonId.triggerSector() - 1) / 3. * M_PI;
1450  }
1451  if (phi > M_PI)
1452  phi -= 2 * M_PI;
1453  return phi;
1454 }
1455 
1457  if (muon.isStandAloneMuon())
1458  return muon.standAloneMuon()->innerPosition().phi();
1459  // the rest is tracker muon only
1460  if (muon.matches().empty()) {
1461  if (muon.innerTrack().isAvailable() && muon.innerTrack()->extra().isAvailable())
1462  return muon.innerTrack()->outerPosition().phi();
1463  else
1464  return muon.phi(); // makes little sense, but what else can I use
1465  }
1466  return sectorPhi(muon.matches().at(0).id);
1467 }
1468 
1471  aMuon.setCombinedQuality((*glbQualHandle_)[aMuon.combinedMuon()]);
1472  }
1473 
1474  LogDebug("MuonIdentification") << "tkChiVal " << aMuon.combinedQuality().trkRelChi2;
1475 }
1476 
1478  // skip muons with no tracks
1479  if (aMuon.innerTrack().isNull())
1480  return;
1481  // get quality from muon if already there, otherwise make empty one
1483  // fill it
1484  const bool filled = trackerKinkFinder_->fillTrkKink(quality, *aMuon.innerTrack());
1485  // if quality was there, or if we filled it, commit to the muon
1486  if (filled || aMuon.isQualityValid())
1487  aMuon.setCombinedQuality(quality);
1488 }
1489 
1491  const bool trackBAD = links->trackerTrack().isNull();
1492  const bool staBAD = links->standAloneTrack().isNull();
1493  const bool glbBAD = links->globalTrack().isNull();
1494  if (trackBAD || staBAD || glbBAD) {
1495  edm::LogWarning("muonIDbadLinks") << "Global muon links to constituent tracks are invalid: trkBad " << trackBAD
1496  << " standaloneBad " << staBAD << " globalBad " << glbBAD
1497  << ". There should be no such object. Muon is skipped.";
1498  return false;
1499  }
1500  return true;
1501 }
1502 
1505  desc.setAllowAnything();
1506 
1507  desc.add<bool>("arbitrateTrackerMuons", false);
1508  desc.add<bool>("storeCrossedHcalRecHits", false);
1509  desc.add<bool>("fillShowerDigis", false);
1510  desc.ifValue(
1511  edm::ParameterDescription<bool>("selectHighPurity", false, true),
1512  true >> (edm::ParameterDescription<edm::InputTag>("pvInputTag", edm::InputTag("offlinePrimaryVertices"), true)) or
1513  false >> (edm::ParameterDescription<edm::InputTag>("pvInputTag", edm::InputTag(""), true)));
1514 
1515  edm::ParameterSetDescription descTrkAsoPar;
1516  descTrkAsoPar.add<edm::InputTag>("GEMSegmentCollectionLabel", edm::InputTag("gemSegments"));
1517  descTrkAsoPar.add<edm::InputTag>("ME0SegmentCollectionLabel", edm::InputTag("me0Segments"));
1518  descTrkAsoPar.add<bool>("useGEM", false);
1519  descTrkAsoPar.add<bool>("useME0", false);
1520  descTrkAsoPar.add<bool>("preselectMuonTracks", false);
1521  descTrkAsoPar.add<edm::InputTag>("RPCHitCollectionLabel", edm::InputTag("rpcRecHits"));
1522  descTrkAsoPar.add<edm::InputTag>("GEMHitCollectionLabel", edm::InputTag("gemRecHits"));
1523  descTrkAsoPar.add<edm::InputTag>("ME0HitCollectionLabel", edm::InputTag("me0RecHits"));
1524  descTrkAsoPar.setAllowAnything();
1525  desc.add<edm::ParameterSetDescription>("TrackAssociatorParameters", descTrkAsoPar);
1526 
1528  descJet.setAllowAnything();
1529  descJet.add<edm::ParameterSetDescription>("TrackAssociatorParameters", descTrkAsoPar);
1530  desc.add<edm::ParameterSetDescription>("JetExtractorPSet", descJet);
1531 
1533  descCalo.setAllowAnything();
1534  descCalo.add<edm::ParameterSetDescription>("TrackAssociatorParameters", descTrkAsoPar);
1535  descCalo.add<bool>("UseEcalRecHitsFlag", false);
1536  descCalo.add<bool>("UseHcalRecHitsFlag", false);
1537  descCalo.add<bool>("UseHORecHitsFlag", false);
1538  descCalo.add<bool>("EcalRecHitThresh", false);
1539  descCalo.add<bool>("HcalCutsFromDB", false);
1540  descCalo.add<int>("MaxSeverityHB", 9);
1541  descCalo.add<int>("MaxSeverityHE", 9);
1542  desc.add<edm::ParameterSetDescription>("CaloExtractorPSet", descCalo);
1543 
1544  descriptions.addDefault(desc);
1545 }
std::string hoDepositName_
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:8
MuonQuality combinedQuality() const
get energy deposition information
Definition: Muon.h:119
static const unsigned int BelongsToTrackByME1aClean
std::string jetDepositName_
bool isGoodRPCMuon(const reco::Muon &muon)
bool approxEqual(const double a, const double b, const double tol=1E-3) const
edm::EDGetTokenT< reco::TrackCollection > innerTrackCollectionToken_
reco::Muon makeMuon(edm::Event &iEvent, const edm::EventSetup &iSetup, const reco::TrackRef &track, TrackType type)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
GEMSegmentRef gemSegmentRef
static const unsigned int GlobalMuon
Definition: Muon.h:289
void fillMuonIsolation(edm::Event &, const edm::EventSetup &, reco::Muon &aMuon, reco::IsoDeposit &trackDep, reco::IsoDeposit &ecalDep, reco::IsoDeposit &hcalDep, reco::IsoDeposit &hoDep, reco::IsoDeposit &jetDep)
edm::EDGetTokenT< edm::ValueMap< reco::MuonQuality > > glbQualToken_
DTRecSegment4DRef dtSegmentRef
static const TGPicture * info(bool iBackgroundIsBlack)
TrackRef combinedMuon() const override
reference to a stand-alone muon Track
Definition: Muon.h:52
static constexpr int GEM
Definition: MuonSubdetId.h:14
std::vector< reco::MuonSegmentMatch > gemMatches
static bool crossedIP(const reco::Track &track)
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:6
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
static void truthMatchMuon(const edm::Event &iEvent, const GlobalTrackingGeometry &iGeometry, reco::Muon &aMuon)
TrackDetectorAssociator trackAssociator_
CSCSegmentRef cscSegmentRef
std::unique_ptr< MuonKinkFinder > trackerKinkFinder_
static const unsigned int Arbitrated
segment mask flags
void fillMuonId(edm::Event &, const edm::EventSetup &, reco::Muon &, TrackDetectorAssociator::Direction direction=TrackDetectorAssociator::InsideOut)
void setAllowAnything()
allow any parameter label/value pairs
edm::Handle< reco::MuonTrackLinksCollection > linkCollectionHandle_
edm::EDGetTokenT< RPCRecHitCollection > rpcHitToken_
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
bool isGoodGEMMuon(const reco::Muon &muon)
int overlap(const reco::Muon &muon, const reco::Track &track)
bool fillCaloCompatibility_
std::string trackDepositName_
void fillArbitrationInfo(reco::MuonCollection *, unsigned int muonType=reco::Muon::TrackerMuon)
T const * product() const
Definition: Handle.h:70
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:98
std::vector< reco::MuonGEMHitMatch > gemHitMatches
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
const edm::ESGetToken< CSCGeometry, MuonGeometryRecord > geomTokenRun_
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
void produce(edm::Event &, const edm::EventSetup &) override
float hadVetoEt
hcal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:14
double p() const
momentum vector magnitude
Definition: CaloMuon.h:54
double evaluate(const reco::Muon &)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:232
#define M_PI_2
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
MuonCaloCompatibility muonCaloCompatibility_
static const unsigned int BestInStationByDRSlope
float timeAtIpOutInErr() const
Definition: MuonTimeExtra.h:49
edm::EDGetTokenT< reco::TrackToTrackMap > pickyCollectionToken_
static std::string toStr(const ICTypeKey k)
bool arbitrateTrackerMuons_
static const unsigned int BelongsToTrackByDXSlope
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:108
void fillGlbQuality(edm::Event &, const edm::EventSetup &, reco::Muon &aMuon)
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
float timeAtIpOutInErr
Definition: MuonTime.h:17
float trkRelChi2
chi2 value for the inner track stub with respect to the global track
Definition: MuonQuality.h:15
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > muIsoExtractorTrack_
static const unsigned int BestInStationByDR
float timeAtIpInOutErr() const
Definition: MuonTimeExtra.h:44
float timeAtIpInOut() const
Definition: MuonTimeExtra.h:43
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
bool isTrackerMuon() const override
Definition: Muon.h:304
std::unique_ptr< MuonTimingFiller > theTimingFiller_
#define LogTrace(id)
virtual void setTunePBestTrack(MuonTrackType muonType)
Definition: Muon.h:88
double phiOfMuonInteractionRegion(const reco::Muon &muon) const
edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > globalGeomToken_
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > muIsoExtractorCalo_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
void init(edm::Event &, const edm::EventSetup &)
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
bool failedToGet() const
Definition: HandleBase.h:72
float caloCompatibility() const
Definition: CaloMuon.h:45
string quality
float yy() const
Definition: LocalError.h:24
edm::EDGetTokenT< reco::TrackToTrackMap > tpfmsCollectionToken_
std::vector< reco::MuonSegmentMatch > me0Matches
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< MuonShowerDigiFiller > theShowerDigiFiller_
edm::Handle< reco::VertexCollection > pvHandle_
double ptThresholdToFillCandidateP4WithGlobalFit_
void addDefault(ParameterSetDescription const &psetDescription)
reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const double nSigma=2., const double ptThreshold=200.)
TrackAssociatorParameters parameters_
bool isGoodME0Muon(const reco::Muon &muon)
reco::Muon::MuonTrackTypePair tevOptimized(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const reco::TrackRef &tpfmsTrack, const reco::TrackRef &pickyTrack, const reco::TrackRef &dytTrack, const double ptThreshold=200., const double tune1=17., const double tune2=40., const double dptcut=0.25)
Definition: MuonCocktails.cc:9
void fillTrackerKink(reco::Muon &aMuon)
void setPropagator(const Propagator *)
use a user configured propagator
static const unsigned int ME0Muon
Definition: Muon.h:296
ArbitrationType
define arbitration schemes
Definition: Muon.h:187
T sqrt(T t)
Definition: SSEVec.h:23
bool isGoodTrackerMuon(const reco::Muon &muon)
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:129
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
float emEt
ecal sum-Et
Definition: MuonIsolation.h:7
float timeAtIpInOutErr
Definition: MuonTime.h:14
int nJets
number of jets in the cone
Definition: MuonIsolation.h:11
static const unsigned int BestInChamberByDX
std::string ecalDepositName_
bool checkLinks(const reco::MuonTrackLinks *) const
float timeAtIpOutIn
b) particle is moving from outside in
Definition: MuonTime.h:16
int nDof
number of muon stations used
Definition: MuonTime.h:9
bool isCaloCompatibilityValid() const
Definition: CaloMuon.h:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::MuonCollection > muonCollectionToken_
Transition
Definition: Transition.h:12
float hoEt
ho sum-Et
Definition: MuonIsolation.h:9
int nDof() const
number of measurements used in timing calculation
Definition: MuonTimeExtra.h:22
edm::EDGetTokenT< reco::TrackCollection > outerTrackCollectionToken_
def stationIndex(name)
Definition: plotscripts.py:355
edm::Handle< RPCRecHitCollection > rpcHitHandle_
std::vector< reco::MuonRPCHitMatch > rpcMatches
static constexpr int ME0
Definition: MuonSubdetId.h:15
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static const unsigned int BestInChamberByDR
TrackRef standAloneMuon() const override
reference to a stand-alone muon Track
Definition: Muon.h:49
ME0SegmentRef me0SegmentRef
virtual TrackRef innerTrack() const
Definition: Muon.h:45
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::Handle< reco::TrackToTrackMap > dytCollectionHandle_
bool isNull() const
Checks for null.
Definition: Ref.h:229
edm::Handle< reco::TrackCollection > outerTrackCollectionHandle_
edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkCollectionToken_
static const unsigned int BestInStationByDXSlope
bool isRPCMuon() const
Definition: Muon.h:308
bool fillGlobalTrackRefits_
static double sectorPhi(const DetId &id)
void setMuonTrack(const MuonTrackType &, const TrackRef &)
float hoVetoEt
ho sum-et in the veto region in r-phi
Definition: MuonIsolation.h:15
double depositWithin(double coneSize, const Vetos &vetos=Vetos(), bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:29
#define M_PI
edm::EDGetTokenT< GEMRecHitCollection > gemHitToken_
reco::CaloMuon makeCaloMuon(const reco::Muon &)
unsigned int id
int nTracks
number of tracks in the cone (excluding veto region)
Definition: MuonIsolation.h:10
static const unsigned int BestInChamberByDXSlope
void setCaloCompatibility(float input)
Definition: CaloMuon.h:46
Definition: DetId.h:17
static const unsigned int RPCMuon
Definition: Muon.h:294
bool isGEMMuon() const
Definition: Muon.h:309
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
static ICTypeKey toKey(const std::string &s)
std::vector< reco::MuonSegmentMatch > * getSegmentMatches(reco::MuonChamberMatch &chamber, unsigned int muonType) const
get the segment matches of the appropriate type
static const unsigned int TrackerMuon
Definition: Muon.h:290
float emVetoEt
ecal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:13
void configure(const edm::ParameterSet &)
bool isQualityValid() const
Definition: Muon.h:117
std::vector< ICTypes::ICTypeKey > inputCollectionTypes_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CSCDetId chamberId() const
Definition: CSCDetId.h:47
static const unsigned int BelongsToTrackByDRSlope
edm::Handle< GEMRecHitCollection > gemHitHandle_
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
Definition: CaloMuon.h:30
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
static constexpr int RPC
Definition: MuonSubdetId.h:13
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void setCombinedQuality(const MuonQuality &combinedQuality)
set energy deposition information
Definition: Muon.h:121
std::vector< edm::InputTag > inputCollectionLabels_
static const unsigned int PFMuon
Definition: Muon.h:293
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:145
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > muIsoExtractorJet_
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: CaloMuon.h:37
MuonIdProducer(const edm::ParameterSet &)
void arbitrateMuons(reco::MuonCollection *, reco::CaloMuonCollection *)
std::vector< reco::MuonSegmentMatch > segmentMatches
bool fillGlobalTrackQuality_
bool isValid() const
Definition: HandleBase.h:70
float timeAtIpOutIn() const
b) particle is moving from outside in
Definition: MuonTimeExtra.h:48
virtual void setOuterTrack(const TrackRef &t)
set reference to Track
static const unsigned int BelongsToTrackByDR
std::string hcalDepositName_
~MuonIdProducer() override
unsigned int chamberId(const DetId &)
reco::TrackRef getTevRefitTrack(const reco::TrackRef &combinedTrack, const reco::TrackToTrackMap &map)
static const unsigned int BelongsToTrackByDX
void setIsolation(const MuonIsolation &isoR03, const MuonIsolation &isoR05)
virtual void setBestTrack(MuonTrackType muonType)
Definition: Muon.h:86
HLT enums.
int sector() const
Definition: DTChamberId.h:52
functor predicate for standard library sort algorithm
static const unsigned int GEMMuon
Definition: Muon.h:295
edm::EDGetTokenT< reco::TrackCollection > outerTrackSecondaryCollectionToken_
edm::Handle< reco::TrackToTrackMap > tpfmsCollectionHandle_
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:226
static const unsigned int BestInStationByDX
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
bool storeCrossedHcalRecHits_
edm::Handle< reco::TrackCollection > innerTrackCollectionHandle_
bool isGoodTrack(const reco::Track &track)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
edm::EDGetTokenT< reco::VertexCollection > pvToken_
int triggerSector() const
Definition: CSCDetId.cc:3
MuonTrackType
map for Global Muon refitters
Definition: Muon.h:36
double sigmaThresholdToFillCandidateP4WithGlobalFit_
#define get
static const unsigned int StandAloneMuon
Definition: Muon.h:291
edm::Handle< reco::TrackCollection > outerTrackSecondaryCollectionHandle_
static constexpr int DT
Definition: MuonSubdetId.h:11
int ring() const
Definition: CSCDetId.h:68
Log< level::Warning, false > LogWarning
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:38
void setMatches(const std::vector< MuonChamberMatch > &matches)
set muon matching information
Definition: Muon.h:148
static constexpr int CSC
Definition: MuonSubdetId.h:12
static const unsigned int BestInChamberByDRSlope
bool validateGlobalMuonPair(const reco::MuonTrackLinks &goodMuon, const reco::MuonTrackLinks &badMuon)
bool debugWithTruthMatching_
float timeAtIpInOut
Definition: MuonTime.h:13
bool isGoodCaloMuon(const reco::CaloMuon &muon)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool isGlobalMuon() const override
Definition: Muon.h:303
virtual void setGlobalTrack(const TrackRef &t)
set reference to Track
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float trackerVetoPt
(sum-)pt inside the veto region in r-phi
Definition: MuonIsolation.h:12
float xx() const
Definition: LocalError.h:22
def move(src, dest)
Definition: eostools.py:511
edm::Handle< reco::MuonCollection > muonCollectionHandle_
Definition: Run.h:45
std::pair< double, int > depositAndCountWithin(double coneSize, const Vetos &vetos=Vetos(), double threshold=-1e+36, bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:37
edm::Handle< edm::ValueMap< reco::MuonQuality > > glbQualHandle_
void beginRun(const edm::Run &, const edm::EventSetup &) override
edm::Handle< reco::TrackToTrackMap > pickyCollectionHandle_
std::unique_ptr< MuonMesh > meshAlgo_
#define LogDebug(id)
edm::EDGetTokenT< reco::TrackToTrackMap > dytCollectionToken_