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 
12 // user include files
14 
21 
24 
31 
33 
35 
37 {
38 
39  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: Constructor called";
40 
41  produces<reco::MuonCollection>();
42  produces<reco::CaloMuonCollection>();
43  produces<reco::MuonTimeExtraMap>("combined");
44  produces<reco::MuonTimeExtraMap>("dt");
45  produces<reco::MuonTimeExtraMap>("csc");
46 
47  minPt_ = iConfig.getParameter<double>("minPt");
48  minP_ = iConfig.getParameter<double>("minP");
49  minPCaloMuon_ = iConfig.getParameter<double>("minPCaloMuon");
50  minNumberOfMatches_ = iConfig.getParameter<int>("minNumberOfMatches");
51  addExtraSoftMuons_ = iConfig.getParameter<bool>("addExtraSoftMuons");
52  maxAbsEta_ = iConfig.getParameter<double>("maxAbsEta");
53  maxAbsDx_ = iConfig.getParameter<double>("maxAbsDx");
54  maxAbsPullX_ = iConfig.getParameter<double>("maxAbsPullX");
55  maxAbsDy_ = iConfig.getParameter<double>("maxAbsDy");
56  maxAbsPullY_ = 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  //SK: (maybe temporary) run it only if the global is also run
68  fillTrackerKink_ = false;
69  if (fillGlobalTrackQuality_) fillTrackerKink_ = iConfig.getParameter<bool>("fillTrackerKink");
70 
71  ptThresholdToFillCandidateP4WithGlobalFit_ = iConfig.getParameter<double>("ptThresholdToFillCandidateP4WithGlobalFit");
72  sigmaThresholdToFillCandidateP4WithGlobalFit_ = iConfig.getParameter<double>("sigmaThresholdToFillCandidateP4WithGlobalFit");
73  caloCut_ = iConfig.getParameter<double>("minCaloCompatibility"); //CaloMuons
74  arbClean_ = iConfig.getParameter<bool>("runArbitrationCleaner"); // muon mesh
75 
76  // Load TrackDetectorAssociator parameters
77  const edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
78  edm::ConsumesCollector iC = consumesCollector();
79  parameters_.loadParameters( parameters, iC );
80 
81  // Load parameters for the TimingFiller
82  edm::ParameterSet timingParameters = iConfig.getParameter<edm::ParameterSet>("TimingFillerParameters");
83  theTimingFiller_ = std::make_unique<MuonTimingFiller>(timingParameters,consumesCollector());
84 
85  // Load parameters for the ShowerDigiFiller
86  if (fillShowerDigis_ && fillMatching_)
87  {
88  edm::ParameterSet showerDigiParameters = iConfig.getParameter<edm::ParameterSet>("ShowerDigiFillerParameters");
89  theShowerDigiFiller_ = std::make_unique<MuonShowerDigiFiller>(showerDigiParameters,consumesCollector());
90  }
91 
92  if (fillCaloCompatibility_){
93  // Load MuonCaloCompatibility parameters
94  const auto caloParams = iConfig.getParameter<edm::ParameterSet>("MuonCaloCompatibility");
95  muonCaloCompatibility_.configure( caloParams );
96  }
97 
98  if (fillIsolation_){
99  // Load MuIsoExtractor parameters
100  edm::ParameterSet caloExtractorPSet = iConfig.getParameter<edm::ParameterSet>("CaloExtractorPSet");
101  std::string caloExtractorName = caloExtractorPSet.getParameter<std::string>("ComponentName");
102  muIsoExtractorCalo_ = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{IsoDepositExtractorFactory::get()->create( caloExtractorName, caloExtractorPSet,consumesCollector())};
103 
104  edm::ParameterSet trackExtractorPSet = iConfig.getParameter<edm::ParameterSet>("TrackExtractorPSet");
105  std::string trackExtractorName = trackExtractorPSet.getParameter<std::string>("ComponentName");
106  muIsoExtractorTrack_ = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{IsoDepositExtractorFactory::get()->create( trackExtractorName, trackExtractorPSet,consumesCollector())};
107 
108  edm::ParameterSet jetExtractorPSet = iConfig.getParameter<edm::ParameterSet>("JetExtractorPSet");
109  std::string jetExtractorName = jetExtractorPSet.getParameter<std::string>("ComponentName");
110  muIsoExtractorJet_ = std::unique_ptr<reco::isodeposit::IsoDepositExtractor>{IsoDepositExtractorFactory::get()->create( jetExtractorName, jetExtractorPSet,consumesCollector())};
111  }
112  if (fillIsolation_ && writeIsoDeposits_){
113  trackDepositName_ = iConfig.getParameter<std::string>("trackDepositName");
114  produces<reco::IsoDepositMap>(trackDepositName_);
115  ecalDepositName_ = iConfig.getParameter<std::string>("ecalDepositName");
116  produces<reco::IsoDepositMap>(ecalDepositName_);
117  hcalDepositName_ = iConfig.getParameter<std::string>("hcalDepositName");
118  produces<reco::IsoDepositMap>(hcalDepositName_);
119  hoDepositName_ = iConfig.getParameter<std::string>("hoDepositName");
120  produces<reco::IsoDepositMap>(hoDepositName_);
121  jetDepositName_ = iConfig.getParameter<std::string>("jetDepositName");
122  produces<reco::IsoDepositMap>(jetDepositName_);
123  }
124 
125  inputCollectionLabels_ = iConfig.getParameter<std::vector<edm::InputTag> >("inputCollectionLabels");
126  const auto inputCollectionTypes = iConfig.getParameter<std::vector<std::string> >("inputCollectionTypes");
127  if (inputCollectionLabels_.size() != inputCollectionTypes.size())
128  throw cms::Exception("ConfigurationError") << "Number of input collection labels is different from number of types. " <<
129  "For each collection label there should be exactly one collection type specified.";
130  if (inputCollectionLabels_.size()>7 ||inputCollectionLabels_.empty())
131  throw cms::Exception("ConfigurationError") << "Number of input collections should be from 1 to 7.";
132 
133  debugWithTruthMatching_ = iConfig.getParameter<bool>("debugWithTruthMatching");
134  if (debugWithTruthMatching_) edm::LogWarning("MuonIdentification")
135  << "========================================================================\n"
136  << "Debugging mode with truth matching is turned on!!! Make sure you understand what you are doing!\n"
137  << "========================================================================\n";
138  if (fillGlobalTrackQuality_){
139  const auto& glbQualTag = iConfig.getParameter<edm::InputTag>("globalTrackQualityInputTag");
140  glbQualToken_ = consumes<edm::ValueMap<reco::MuonQuality> >(glbQualTag);
141  }
142 
143  if (fillTrackerKink_) {
144  trackerKinkFinder_ = std::make_unique<MuonKinkFinder>(iConfig.getParameter<edm::ParameterSet>("TrackerKinkFinderParameters"));
145  }
146 
147  //create mesh holder
148  meshAlgo_ = std::make_unique<MuonMesh>(iConfig.getParameter<edm::ParameterSet>("arbitrationCleanerOptions"));
149 
150 
151  edm::InputTag rpcHitTag("rpcRecHits");
152  rpcHitToken_ = consumes<RPCRecHitCollection>(rpcHitTag);
153 
154 
155  //Consumes... UGH
156  inputCollectionTypes_.resize(inputCollectionLabels_.size());
157  for ( unsigned int i = 0; i < inputCollectionLabels_.size(); ++i ) {
158  const auto inputLabel = inputCollectionLabels_[i];
159  const auto inputType = ICTypes::toKey(inputCollectionTypes[i]); // Note: thorws exception if type is undefined.
160 
161  if ( inputType == ICTypes::INNER_TRACKS ) {
162  innerTrackCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
163  }
164  else if ( inputType == ICTypes::OUTER_TRACKS ) {
165  outerTrackCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
166  }
167  else if ( inputType == ICTypes::LINKS ) {
168  linkCollectionToken_ = consumes<reco::MuonTrackLinksCollection>(inputLabel);
169  }
170  else if ( inputType == ICTypes::MUONS ) {
171  muonCollectionToken_ = consumes<reco::MuonCollection>(inputLabel);
172  }
173  else if ( inputType == ICTypes::TEV_FIRSTHIT ) {
174  tpfmsCollectionToken_ = consumes<reco::TrackToTrackMap>(inputLabel);
175  }
176  else if ( fillGlobalTrackRefits_ && inputType == ICTypes::TEV_PICKY ) {
177  pickyCollectionToken_ = consumes<reco::TrackToTrackMap>(inputLabel);
178  }
179  else if ( fillGlobalTrackRefits_ && inputType == ICTypes::TEV_DYT ) {
180  dytCollectionToken_ = consumes<reco::TrackToTrackMap>(inputCollectionLabels_.at(i));
181  }
182 
183  inputCollectionTypes_[i] = inputType;
184  }
185 }
186 
187 
188 
190 {
191  // TimingReport::current()->dump(std::cout);
192 }
193 
195 {
200 
204 
205 
207  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
208  trackAssociator_.setPropagator(propagator.product());
209 
210  if (fillTrackerKink_) trackerKinkFinder_->init(iSetup);
211 
212  for ( unsigned int i = 0; i < inputCollectionLabels_.size(); ++i ) {
213  const auto& inputLabel = inputCollectionLabels_[i];
214  const auto inputType = inputCollectionTypes_[i];
215  if ( inputType == ICTypes::INNER_TRACKS ) {
218  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputLabel;
219  LogTrace("MuonIdentification") << "Number of input inner tracks: " << innerTrackCollectionHandle_->size();
220  }
221  else if ( inputType == ICTypes::OUTER_TRACKS ) {
224  throw cms::Exception("FatalError") << "Failed to get input track collection with label: " << inputLabel;
225  LogTrace("MuonIdentification") << "Number of input outer tracks: " << outerTrackCollectionHandle_->size();
226  }
227  else if ( inputType == ICTypes::LINKS ) {
230  throw cms::Exception("FatalError") << "Failed to get input link collection with label: " << inputLabel;
231  LogTrace("MuonIdentification") << "Number of input links: " << linkCollectionHandle_->size();
232  }
233  else if ( inputType == ICTypes::MUONS ) {
236  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
237  LogTrace("MuonIdentification") << "Number of input muons: " << muonCollectionHandle_->size();
238  }
239  else if ( fillGlobalTrackRefits_ && inputType == ICTypes::TEV_FIRSTHIT ) {
242  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
243  LogTrace("MuonIdentification") << "Number of input muons: " << tpfmsCollectionHandle_->size();
244  }
245  else if ( fillGlobalTrackRefits_ && inputType == ICTypes::TEV_PICKY ) {
248  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
249  LogTrace("MuonIdentification") << "Number of input muons: " << pickyCollectionHandle_->size();
250  }
251  else if ( fillGlobalTrackRefits_ && inputType == ICTypes::TEV_DYT ) {
253  if (! dytCollectionHandle_.isValid())
254  throw cms::Exception("FatalError") << "Failed to get input muon collection with label: " << inputLabel;
255  LogTrace("MuonIdentification") << "Number of input muons: " << dytCollectionHandle_->size();
256  }
257  else throw cms::Exception("FatalError") << "Unknown input collection type: #" << ICTypes::toStr(inputType);
258  }
259 
262 
263 }
264 
267 {
268  LogTrace("MuonIdentification") << "Creating a muon from a track " << track.get()->pt() <<
269  " Pt (GeV), eta: " << track.get()->eta();
270  reco::Muon aMuon( makeMuon( *(track.get()) ) );
271 
272  LogTrace("MuonIdentification") << "Muon created from a track ";
273 
274  aMuon.setMuonTrack(type,track);
275  aMuon.setBestTrack(type);
276  aMuon.setTunePBestTrack(type);
277 
278  LogTrace("MuonIdentification") << "Muon created from a track and setMuonBestTrack, setBestTrack and setTunePBestTrack called";
279 
280  return aMuon;
281 }
282 
284 {
285 
286  LogTrace("MuonIdentification") << "Creating a CaloMuon from a Muon";
287 
288  reco::CaloMuon aMuon;
289  aMuon.setInnerTrack( muon.innerTrack() );
290 
291  if (muon.isEnergyValid()) aMuon.setCalEnergy( muon.calEnergy() );
292  // get calo compatibility
294  return aMuon;
295 }
296 
297 
299 {
300  LogTrace("MuonIdentification") << "Creating a muon from a link to tracks object";
301 
302  reco::Muon aMuon;
303  reco::Muon::MuonTrackTypePair chosenTrack;
304  reco::TrackRef tpfmsRef;
305  reco::TrackRef pickyRef;
306  reco::TrackRef dytRef;
307  bool useSigmaSwitch = false;
308 
311 
315 
316  if (tpfmsRef.isNull() && pickyRef.isNull() && dytRef.isNull()){
317  edm::LogWarning("MakeMuonWithTEV")<<"Failed to get TEV refits, fall back to sigma switch.";
318  useSigmaSwitch = true;
319  }
320  } else {
321  useSigmaSwitch = true;
322  }
323 
324  if (useSigmaSwitch){
325  chosenTrack = muon::sigmaSwitch( links.globalTrack(), links.trackerTrack(),
328  } else {
329  chosenTrack = muon::tevOptimized( links.globalTrack(), links.trackerTrack(),
330  tpfmsRef, pickyRef, dytRef,
332  }
333  aMuon = makeMuon(*chosenTrack.first);
334  aMuon.setInnerTrack( links.trackerTrack() );
335  aMuon.setOuterTrack( links.standAloneTrack() );
336  aMuon.setGlobalTrack( links.globalTrack() );
337  aMuon.setBestTrack(chosenTrack.second);
338  aMuon.setTunePBestTrack(chosenTrack.second);
339 
343  if (it != tpfmsCollectionHandle_->end()) aMuon.setMuonTrack(reco::Muon::TPFMS, (it->val));
344  }
347  if (it != pickyCollectionHandle_->end()) aMuon.setMuonTrack(reco::Muon::Picky, (it->val));
348  }
351  if (it != dytCollectionHandle_->end()) aMuon.setMuonTrack(reco::Muon::DYT, (it->val));
352  }
353  }
354  return aMuon;
355 }
356 
357 
359 {
360  // Pt and absolute momentum requirement
361  const double p = track.p();
362  const double pt = track.pt();
363  if (pt < minPt_ || (p < minP_ && p < minPCaloMuon_)){
364  LogTrace("MuonIdentification") << "Skipped low momentum track (Pt,P): " << pt
365  << ", " << track.p() << " GeV";
366  return false;
367  }
368 
369  // Eta requirement
370  const double eta = track.eta();
371  const double absEta = std::abs(eta);
372  if ( absEta > maxAbsEta_ ){
373  LogTrace("MuonIdentification") << "Skipped track with large pseudo rapidity (Eta: " << track.eta() << " )";
374  return false;
375  }
376 
377  return true;
378 }
379 
380 unsigned int MuonIdProducer::chamberId( const DetId& id )
381 {
382  if ( id.det() != DetId::Muon ) return 0;
383 
384  const auto subdetId = id.subdetId();
385  if ( subdetId == MuonSubdetId::DT ) {
386  return DTChamberId(id.rawId()).rawId();
387  }
388  else if ( subdetId == MuonSubdetId::CSC ) {
389  return CSCDetId(id.rawId()).chamberId().rawId();
390  }
391 
392  return 0;
393 }
394 
395 
397 {
398  if ( ! muon.isMatchesValid() ||
399  track.extra().isNull() ||
400  track.extra()->recHitsSize()==0 ) return 0;
401 
402  int numberOfCommonDetIds = 0;
403  const std::vector<reco::MuonChamberMatch>& matches( muon.matches() );
404  for ( const auto& match : matches )
405  {
406  if ( match.segmentMatches.empty() ) continue;
407 
408  bool foundCommonDetId = false;
409  for ( auto hit = track.extra()->recHitsBegin();
410  hit != track.extra()->recHitsEnd(); ++hit )
411  {
412  // LogTrace("MuonIdentification") << "hit DetId: " << std::hex << hit->get()->geographicalId().rawId() <<
413  // "\t hit chamber DetId: " << getChamberId(hit->get()->geographicalId()) <<
414  // "\t segment DetId: " << match->id.rawId() << std::dec;
415 
416  if ( chamberId((*hit)->geographicalId()) == match.id.rawId() ) {
417  foundCommonDetId = true;
418  break;
419  }
420  }
421  if ( foundCommonDetId ) {
422  ++numberOfCommonDetIds;
423  break;
424  }
425  }
426  return numberOfCommonDetIds;
427 }
428 
429 void MuonIdProducer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
430 {
431  edm::ESHandle<CSCGeometry> geomHandle;
432  iSetup.get<MuonGeometryRecord>().get(geomHandle);
433 
434  meshAlgo_->setCSCGeometry(geomHandle.product());
435 
437  theShowerDigiFiller_->getES(iSetup);
438 }
439 
441  const reco::MuonTrackLinks& badMuon )
442 {
443  const int nHitsGood = goodMuon.globalTrack()->hitPattern().numberOfValidMuonHits();
444  const int nHitsBad = badMuon.globalTrack()->hitPattern().numberOfValidMuonHits();
445  if ( std::min(nHitsGood, nHitsBad) > 10 ) {
446  const double chi2Good = goodMuon.globalTrack()->normalizedChi2();
447  const double chi2Bad = badMuon.globalTrack()->normalizedChi2();
448  return ( chi2Good <= chi2Bad );
449  }
450 
451  return (nHitsGood >= nHitsBad);
452 }
453 
455 {
456 
457  auto outputMuons = std::make_unique<reco::MuonCollection>();
458  auto caloMuons = std::make_unique<reco::CaloMuonCollection>();
459 
460  init(iEvent, iSetup);
461 
463  theShowerDigiFiller_->getDigis(iEvent);
464 
465  // loop over input collections
466 
467  // muons first - no cleaning, take as is.
468  if ( muonCollectionHandle_.isValid() ) {
469  for ( const auto muon : *muonCollectionHandle_ ) {
470  outputMuons->push_back(muon);
471  }
472  }
473 
474  // links second ( assume global muon type )
475  if ( linkCollectionHandle_.isValid() ) {
476  const auto nLink = linkCollectionHandle_->size();
477  std::vector<bool> goodmuons(nLink, true);
478  if ( nLink > 1 ) {
479  // check for shared tracker tracks
480  for ( unsigned int i=0; i<nLink-1; ++i ) {
481  const auto& iLink = linkCollectionHandle_->at(i);
482  if ( iLink.trackerTrack().isNull() || !checkLinks(&iLink) ) continue;
483  for ( unsigned int j=i+1; j<nLink; ++j ){
484  const auto& jLink = linkCollectionHandle_->at(j);
485  if (!checkLinks(&jLink)) continue;
486  if ( iLink.trackerTrack() == jLink.trackerTrack() ) {
487  // Tracker track is the essential part that dominates muon resolution
488  // so taking either muon is fine. All that is important is to preserve
489  // the muon identification information. If number of hits is small,
490  // keep the one with large number of hits, otherwise take the smalest chi2/ndof
491  if ( validateGlobalMuonPair(iLink, jLink) ) goodmuons[j] = false;
492  else goodmuons[i] = false;
493  }
494  }
495  }
496  // check for shared stand-alone muons.
497  for ( unsigned int i=0; i<nLink-1; ++i ) {
498  if ( !goodmuons[i] ) continue;
499  const auto& iLink = linkCollectionHandle_->at(i);
500  if ( iLink.standAloneTrack().isNull() || !checkLinks(&iLink)) continue;
501  for ( unsigned int j=i+1; j<nLink; ++j ) {
502  if ( !goodmuons[j] ) continue;
503  const auto& jLink = linkCollectionHandle_->at(j);
504  if (!checkLinks(&jLink)) continue;
505  if ( iLink.standAloneTrack() == jLink.standAloneTrack() ) {
506  if ( validateGlobalMuonPair(iLink, jLink) ) goodmuons[j] = false;
507  else goodmuons[i] = false;
508  }
509  }
510  }
511  }
512  for ( unsigned int i=0; i<nLink; ++i ) {
513  if ( !goodmuons[i] ) continue;
514  const auto& iLink = linkCollectionHandle_->at(i);
515  if ( ! checkLinks(&iLink) ) continue;
516  // check if this muon is already in the list
517  bool newMuon = true;
518  for ( auto muon : *outputMuons ) {
519  if ( muon.track() == iLink.trackerTrack() &&
520  muon.standAloneMuon() == iLink.standAloneTrack() &&
521  muon.combinedMuon() == iLink.globalTrack() ) {
522  newMuon = false;
523  break;
524  }
525  }
526  if ( newMuon ) {
527  outputMuons->push_back( makeMuon(iLink) );
528  outputMuons->back().setType(reco::Muon::GlobalMuon | reco::Muon::StandAloneMuon);
529  }
530  }
531  }
532 
533  // tracker and calo muons are next
535  LogTrace("MuonIdentification") << "Creating tracker muons";
536  std::vector<TrackDetectorAssociator::Direction> directions1, directions2;
537  directions1.push_back(TrackDetectorAssociator::InsideOut);
538  directions1.push_back(TrackDetectorAssociator::OutsideIn);
539  directions2.push_back(TrackDetectorAssociator::Any);
540 
541  for ( unsigned int i = 0; i < innerTrackCollectionHandle_->size(); ++i )
542  {
544  if ( ! isGoodTrack( track ) ) continue;
545  const auto& trackRef = reco::TrackRef(innerTrackCollectionHandle_, i);
546  bool splitTrack = false;
547  if ( track.extra().isAvailable() &&
548  TrackDetectorAssociator::crossedIP( track ) ) splitTrack = true;
549  const auto& directions = splitTrack ? directions1 : directions2;
550  for ( const auto direction : directions ) {
551  // make muon
552  reco::Muon trackerMuon( makeMuon(iEvent, iSetup, trackRef, reco::Muon::InnerTrack) );
553  fillMuonId(iEvent, iSetup, trackerMuon, direction);
554 
555  if ( debugWithTruthMatching_ ) {
556  // add MC hits to a list of matched segments.
557  // Since it's debugging mode - code is slow
558  MuonIdTruthInfo::truthMatchMuon(iEvent, iSetup, trackerMuon);
559  }
560 
561  // check if this muon is already in the list
562  // have to check where muon hits are really located
563  // to match properly
564  bool newMuon = true;
565  const bool goodTrackerMuon = isGoodTrackerMuon( trackerMuon );
566  const bool goodRPCMuon = isGoodRPCMuon( trackerMuon );
567  const bool goodGEMMuon = isGoodGEMMuon( trackerMuon );
568  const bool goodME0Muon = isGoodME0Muon( trackerMuon );
569  if ( goodTrackerMuon ) trackerMuon.setType( trackerMuon.type() | reco::Muon::TrackerMuon );
570  if ( goodRPCMuon ) trackerMuon.setType( trackerMuon.type() | reco::Muon::RPCMuon );
571  if ( goodGEMMuon ) trackerMuon.setType( trackerMuon.type() | reco::Muon::GEMMuon );
572  if ( goodME0Muon ) trackerMuon.setType( trackerMuon.type() | reco::Muon::ME0Muon );
573 
574  for ( auto& muon : *outputMuons )
575  {
576  if ( muon.innerTrack().get() == trackerMuon.innerTrack().get() &&
578  {
579  newMuon = false;
580  muon.setMatches( trackerMuon.matches() );
581  if (trackerMuon.isTimeValid()) muon.setTime( trackerMuon.time() );
582  if (trackerMuon.isEnergyValid()) muon.setCalEnergy( trackerMuon.calEnergy() );
583  if (goodTrackerMuon) muon.setType( muon.type() | reco::Muon::TrackerMuon );
584  if (goodRPCMuon) muon.setType( muon.type() | reco::Muon::RPCMuon );
585  if (goodGEMMuon) muon.setType( muon.type() | reco::Muon::GEMMuon );
586  if (goodME0Muon) muon.setType( muon.type() | reco::Muon::ME0Muon );
587  LogTrace("MuonIdentification") << "Found a corresponding global muon. Set energy, matches and move on";
588  break;
589  }
590  }
591  if ( newMuon ) {
592  if ( goodTrackerMuon || goodRPCMuon || goodGEMMuon || goodME0Muon){
593  outputMuons->push_back( trackerMuon );
594  } else {
595  LogTrace("MuonIdentification") << "track failed minimal number of muon matches requirement";
596  const reco::CaloMuon& caloMuon = makeCaloMuon(trackerMuon);
597  if (isGoodCaloMuon(caloMuon)) caloMuons->push_back( caloMuon );
598  }
599  }
600  }
601  }
602  }
603 
604  // and at last the stand alone muons
606  LogTrace("MuonIdentification") << "Looking for new muons among stand alone muon tracks";
607  for ( unsigned int i = 0; i < outerTrackCollectionHandle_->size(); ++i )
608  {
609  const auto& outerTrack = outerTrackCollectionHandle_->at(i);
610 
611  // check if this muon is already in the list of global muons
612  bool newMuon = true;
613  for ( auto& muon : *outputMuons )
614  {
615  if ( ! muon.standAloneMuon().isNull() ) {
616  // global muon
617  if ( muon.standAloneMuon().get() == &outerTrack ) {
618  newMuon = false;
619  break;
620  }
621  } else {
622  // tracker muon - no direct links to the standalone muon
623  // since we have only a few real muons in an event, matching
624  // the stand alone muon to the tracker muon by DetIds should
625  // be good enough for association. At the end it's up to a
626  // user to redefine the association and what it means. Here
627  // we would like to avoid obvious double counting and we
628  // tolerate a potential miss association
629  if ( overlap(muon, outerTrack) > 0 ) {
630  LogTrace("MuonIdentification") << "Found associated tracker muon. Set a reference and move on";
631  newMuon = false;
632  muon.setOuterTrack( reco::TrackRef( outerTrackCollectionHandle_, i ) );
633  muon.setType( muon.type() | reco::Muon::StandAloneMuon );
634  break;
635  }
636  }
637  }
638  if ( newMuon ) {
639  LogTrace("MuonIdentification") << "No associated stand alone track is found. Making a muon";
640  outputMuons->push_back( makeMuon(iEvent, iSetup,
642  outputMuons->back().setType( reco::Muon::StandAloneMuon );
643  }
644  }
645  }
646 
648  fillArbitrationInfo( outputMuons.get() );
649  arbitrateMuons( outputMuons.get(), caloMuons.get() );
650  }
651 
652  LogTrace("MuonIdentification") << "Dress up muons if it's necessary";
653 
654  const int nMuons=outputMuons->size();
655 
656  std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
657  std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
658  std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
659  std::vector<reco::IsoDeposit> trackDepColl(nMuons);
660  std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
661  std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
662  std::vector<reco::IsoDeposit> hoDepColl(nMuons);
663  std::vector<reco::IsoDeposit> jetDepColl(nMuons);
664 
665  // Fill various information
666  for ( unsigned int i=0; i<outputMuons->size(); ++i )
667  {
668  auto& muon = outputMuons->at(i);
669 
670  // Fill muonID
671  if ( ( fillMatching_ && ! muon.isMatchesValid() ) ||
672  ( fillEnergy_ && !muon.isEnergyValid() ) )
673  {
674  // predict direction based on the muon interaction region location
675  // if it's available
676  if ( muon.isStandAloneMuon() ) {
677  if ( cos(phiOfMuonIneteractionRegion(muon) - muon.phi()) > 0 ) {
679  } else {
681  }
682  } else {
683  LogTrace("MuonIdentification") << "THIS SHOULD NEVER HAPPEN";
684  fillMuonId(iEvent, iSetup, muon);
685  }
686  }
687 
689  // Fill global quality information
690  fillGlbQuality(iEvent, iSetup, muon);
691  }
692  LogDebug("MuonIdentification");
693 
694  if (fillTrackerKink_) {
696  }
697 
698  if ( fillCaloCompatibility_ ) muon.setCaloCompatibility( muonCaloCompatibility_.evaluate(muon) );
699 
700  if ( fillIsolation_ ) {
701  fillMuonIsolation(iEvent, iSetup, muon,
702  trackDepColl[i], ecalDepColl[i], hcalDepColl[i], hoDepColl[i], jetDepColl[i]);
703  }
704 
705  // fill timing information
706  reco::MuonTime muonTime;
707  reco::MuonTimeExtra dtTime;
708  reco::MuonTimeExtra cscTime;
709  reco::MuonTime rpcTime;
710  reco::MuonTimeExtra combinedTime;
711 
712  theTimingFiller_->fillTiming(muon, dtTime, cscTime, rpcTime, combinedTime, iEvent, iSetup);
713 
714  muonTime.nDof=combinedTime.nDof();
715  muonTime.timeAtIpInOut=combinedTime.timeAtIpInOut();
716  muonTime.timeAtIpInOutErr=combinedTime.timeAtIpInOutErr();
717  muonTime.timeAtIpOutIn=combinedTime.timeAtIpOutIn();
718  muonTime.timeAtIpOutInErr=combinedTime.timeAtIpOutInErr();
719 
720  muon.setTime(muonTime);
721  muon.setRPCTime(rpcTime);
722  dtTimeColl[i] = dtTime;
723  cscTimeColl[i] = cscTime;
724  combinedTimeColl[i] = combinedTime;
725  }
726 
727  LogTrace("MuonIdentification") << "number of muons produced: " << outputMuons->size();
728  if ( fillMatching_ ) {
729  fillArbitrationInfo( outputMuons.get(), reco::Muon::TrackerMuon );
730  fillArbitrationInfo( outputMuons.get(), reco::Muon::ME0Muon );
731  fillArbitrationInfo( outputMuons.get(), reco::Muon::GEMMuon );
732  }
733  edm::OrphanHandle<reco::MuonCollection> muonHandle = iEvent.put(std::move(outputMuons));
734 
735  auto fillMap = [](auto refH, auto& vec, edm::Event& ev, const std::string& cAl = ""){
737  auto oMap = std::make_unique<MapType>();
738  {
739  typename MapType::Filler filler(*oMap);
740  filler.insert(refH, vec.begin(), vec.end());
741  vec.clear();
742  filler.fill();
743  }
744  ev.put(std::move(oMap), cAl);
745  };
746  fillMap(muonHandle, combinedTimeColl, iEvent, "combined");
747  fillMap(muonHandle, dtTimeColl, iEvent, "dt");
748  fillMap(muonHandle, cscTimeColl, iEvent, "csc");
749 
751  fillMap(muonHandle, trackDepColl, iEvent, trackDepositName_);
752  fillMap(muonHandle, ecalDepColl, iEvent, ecalDepositName_);
753  fillMap(muonHandle, hcalDepColl, iEvent, hcalDepositName_);
754  fillMap(muonHandle, hoDepColl, iEvent, hoDepositName_);
755  fillMap(muonHandle, jetDepColl, iEvent, jetDepositName_);
756  }
757 
758  iEvent.put(std::move(caloMuons));
759 }
760 
761 
763 {
764  if(muon.track()->pt() < minPt_ || muon.track()->p() < minP_) return false;
765  if ( addExtraSoftMuons_ &&
766  muon.pt()<5 && std::abs(muon.eta())<1.5 &&
767  muon.numberOfMatches( reco::Muon::NoArbitration ) >= 1 ) return true;
769 }
770 
772 {
773  if ( ! caloMuon.isCaloCompatibilityValid() || caloMuon.caloCompatibility() < caloCut_ || caloMuon.p() < minPCaloMuon_) return false;
774  return true;
775 }
776 
778 {
779  if(muon.track()->pt() < minPt_ || muon.track()->p() < minP_) return false;
780  if ( addExtraSoftMuons_ &&
781  muon.pt()<5 && std::abs(muon.eta())<1.5 &&
784 }
785 
787 {
788  if(muon.track()->pt() < minPt_ || muon.track()->p() < minP_) return false;
790 }
791 
793 {
794  // need to update min cuts on pt
795  if(muon.track()->p() < minP_) return false;
797 }
798 
800  reco::Muon& aMuon,
802 {
803 
804  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId";
805 
806  // perform track - detector association
807  const reco::Track* track = nullptr;
808  if ( aMuon.track().isNonnull() ) track = aMuon.track().get();
809  else if ( aMuon.standAloneMuon().isNonnull() ) track = aMuon.standAloneMuon().get();
810  else throw cms::Exception("FatalError") << "Failed to fill muon id information for a muon with undefined references to tracks";
811 
812 
813  TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup, *track, parameters_, direction);
814 
815  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fillEnergy = "<<fillEnergy_;
816 
817  if ( fillEnergy_ ) {
818 
819  reco::MuonEnergy muonEnergy;
822  muonEnergy.ho = info.crossedEnergy(TrackDetMatchInfo::HORecHits);
824  muonEnergy.emS9 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits,1); // 3x3 energy
825  muonEnergy.emS25 = info.nXnEnergy(TrackDetMatchInfo::EcalRecHits,2); // 5x5 energy
826  muonEnergy.hadS9 = info.nXnEnergy(TrackDetMatchInfo::HcalRecHits,1); // 3x3 energy
827  muonEnergy.hoS9 = info.nXnEnergy(TrackDetMatchInfo::HORecHits,1); // 3x3 energy
828  muonEnergy.towerS9 = info.nXnEnergy(TrackDetMatchInfo::TowerTotal,1); // 3x3 energy
830  muonEnergy.crossedHadRecHits.clear();
831  for (auto hit: info.crossedHcalRecHits){
833  mhit.energy = hit->energy();
834  mhit.chi2 = hit->chi2();
835  mhit.time = hit->time();
836  mhit.detId = hit->id();
837  muonEnergy.crossedHadRecHits.push_back(mhit);
838  }
839  }
840  muonEnergy.ecal_position = info.trkGlobPosAtEcal;
841  muonEnergy.hcal_position = info.trkGlobPosAtHcal;
842  if (! info.crossedEcalIds.empty() ) muonEnergy.ecal_id = info.crossedEcalIds.front();
843  if (! info.crossedHcalIds.empty() ) muonEnergy.hcal_id = info.crossedHcalIds.front();
844  // find maximal energy depositions and their time
845  DetId emMaxId = info.findMaxDeposition(TrackDetMatchInfo::EcalRecHits,2); // max energy deposit in 5x5 shape
846  for ( const auto& hit : info.ecalRecHits ) {
847  if (hit->id() != emMaxId) continue;
848  muonEnergy.emMax = hit->energy();
849  muonEnergy.ecal_time = hit->time();
850  }
851  DetId hadMaxId = info.findMaxDeposition(TrackDetMatchInfo::HcalRecHits,1); // max energy deposit in 3x3 shape
852  for ( const auto& hit : info.hcalRecHits ) {
853  if (hit->id() != hadMaxId) continue;
854  muonEnergy.hadMax = hit->energy();
855  muonEnergy.hcal_time = hit->time();
856  }
857  aMuon.setCalEnergy( muonEnergy );
858  }
859  if ( ! fillMatching_ && ! aMuon.isTrackerMuon() && ! aMuon.isRPCMuon() ) return;
860 
861  // fill muon match info
862  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fill muon match info ";
863  std::vector<reco::MuonChamberMatch> muonChamberMatches;
864  unsigned int nubmerOfMatchesAccordingToTrackAssociator = 0;
865  for ( const auto& chamber : info.chambers )
866  {
867  if (chamber.id.subdetId() == 3 && rpcHitHandle_.isValid() ) continue; // Skip RPC chambers, they are taken care of below)
868  reco::MuonChamberMatch matchedChamber;
869 
870  const auto& lErr = chamber.tState.localError();
871  const auto& lPos = chamber.tState.localPosition();
872  const auto& lDir = chamber.tState.localDirection();
873 
874  const auto& localError = lErr.positionError();
875  matchedChamber.x = lPos.x();
876  matchedChamber.y = lPos.y();
877  matchedChamber.xErr = sqrt( localError.xx() );
878  matchedChamber.yErr = sqrt( localError.yy() );
879 
880  matchedChamber.dXdZ = lDir.z()!=0?lDir.x()/lDir.z():9999;
881  matchedChamber.dYdZ = lDir.z()!=0?lDir.y()/lDir.z():9999;
882  // DANGEROUS - compiler cannot guaranty parameters ordering
883  AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix();
884  matchedChamber.dXdZErr = trajectoryCovMatrix(1,1)>0?sqrt(trajectoryCovMatrix(1,1)):0;
885  matchedChamber.dYdZErr = trajectoryCovMatrix(2,2)>0?sqrt(trajectoryCovMatrix(2,2)):0;
886 
887  matchedChamber.edgeX = chamber.localDistanceX;
888  matchedChamber.edgeY = chamber.localDistanceY;
889 
890  matchedChamber.id = chamber.id;
891 
892  if (fillShowerDigis_) {
893  theShowerDigiFiller_->fill(matchedChamber);
894  }
895  else {
896  theShowerDigiFiller_->fillDefault(matchedChamber);
897  }
898 
899  if ( ! chamber.segments.empty() ) ++nubmerOfMatchesAccordingToTrackAssociator;
900 
901  // fill segments
902  for ( const auto& segment : chamber.segments )
903  {
904  reco::MuonSegmentMatch matchedSegment;
905  matchedSegment.x = segment.segmentLocalPosition.x();
906  matchedSegment.y = segment.segmentLocalPosition.y();
907  matchedSegment.dXdZ = segment.segmentLocalDirection.z()?segment.segmentLocalDirection.x()/segment.segmentLocalDirection.z():0;
908  matchedSegment.dYdZ = segment.segmentLocalDirection.z()?segment.segmentLocalDirection.y()/segment.segmentLocalDirection.z():0;
909  matchedSegment.xErr = segment.segmentLocalErrorXX>0?sqrt(segment.segmentLocalErrorXX):0;
910  matchedSegment.yErr = segment.segmentLocalErrorYY>0?sqrt(segment.segmentLocalErrorYY):0;
911  matchedSegment.dXdZErr = segment.segmentLocalErrorDxDz>0?sqrt(segment.segmentLocalErrorDxDz):0;
912  matchedSegment.dYdZErr = segment.segmentLocalErrorDyDz>0?sqrt(segment.segmentLocalErrorDyDz):0;
913  matchedSegment.t0 = segment.t0;
914  matchedSegment.mask = 0;
915  matchedSegment.dtSegmentRef = segment.dtSegmentRef;
916  matchedSegment.cscSegmentRef = segment.cscSegmentRef;
917  matchedSegment.gemSegmentRef = segment.gemSegmentRef;
918  matchedSegment.me0SegmentRef = segment.me0SegmentRef;
919  matchedSegment.hasZed_ = segment.hasZed;
920  matchedSegment.hasPhi_ = segment.hasPhi;
921  // test segment
922  bool matchedX = false;
923  bool matchedY = false;
924  LogTrace("MuonIdentification") << " matching local x, segment x: " << matchedSegment.x <<
925  ", chamber x: " << matchedChamber.x << ", max: " << maxAbsDx_;
926  LogTrace("MuonIdentification") << " matching local y, segment y: " << matchedSegment.y <<
927  ", chamber y: " << matchedChamber.y << ", max: " << maxAbsDy_;
928  const double matchedSegChDx = std::abs(matchedSegment.x - matchedChamber.x);
929  const double matchedSegChDy = std::abs(matchedSegment.y - matchedChamber.y);
930  const double matchedSegChPullX = matchedSegChDx/std::hypot(matchedSegment.xErr, matchedChamber.xErr);
931  const double matchedSegChPullY = matchedSegChDy/std::hypot(matchedSegment.yErr, matchedChamber.yErr);
932  if (matchedSegment.xErr>0 && matchedChamber.xErr>0 )
933  LogTrace("MuonIdentification") << " xpull: " << matchedSegChPullX;
934  if (matchedSegment.yErr>0 && matchedChamber.yErr>0 )
935  LogTrace("MuonIdentification") << " ypull: " << matchedSegChPullY;
936 
937  if (matchedSegChDx < maxAbsDx_) matchedX = true;
938  if (matchedSegChDy < maxAbsDy_) matchedY = true;
939  if (matchedSegment.xErr>0 && matchedChamber.xErr>0 && matchedSegChPullX < maxAbsPullX_) matchedX = true;
940  if (matchedSegment.yErr>0 && matchedChamber.yErr>0 && matchedSegChPullY < maxAbsPullY_) matchedY = true;
941  if (matchedX && matchedY){
942  if (matchedChamber.id.subdetId() == MuonSubdetId::ME0)
943  matchedChamber.me0Matches.push_back(matchedSegment);
944  else if (matchedChamber.id.subdetId() == MuonSubdetId::GEM)
945  matchedChamber.gemMatches.push_back(matchedSegment);
946  else matchedChamber.segmentMatches.push_back(matchedSegment);
947  }
948  }
949  muonChamberMatches.push_back(matchedChamber);
950  }
951 
952  // Fill RPC info
953  LogTrace("MuonIdentification") << "RecoMuon/MuonIdProducer :: fillMuonId :: fill RPC info";
954  if ( rpcHitHandle_.isValid() )
955  {
956  for ( const auto& chamber : info.chambers )
957  {
958  if ( chamber.id.subdetId() != 3 ) continue; // Consider RPC chambers only
959  const auto& lErr = chamber.tState.localError();
960  const auto& lPos = chamber.tState.localPosition();
961  const auto& lDir = chamber.tState.localDirection();
962 
963  reco::MuonChamberMatch matchedChamber;
964 
965  LocalError localError = lErr.positionError();
966  matchedChamber.x = lPos.x();
967  matchedChamber.y = lPos.y();
968  matchedChamber.xErr = sqrt( localError.xx() );
969  matchedChamber.yErr = sqrt( localError.yy() );
970 
971  matchedChamber.dXdZ = lDir.z()!=0?lDir.x()/lDir.z():9999;
972  matchedChamber.dYdZ = lDir.z()!=0?lDir.y()/lDir.z():9999;
973  // DANGEROUS - compiler cannot guaranty parameters ordering
974  AlgebraicSymMatrix55 trajectoryCovMatrix = lErr.matrix();
975  matchedChamber.dXdZErr = trajectoryCovMatrix(1,1)>0?sqrt(trajectoryCovMatrix(1,1)):0;
976  matchedChamber.dYdZErr = trajectoryCovMatrix(2,2)>0?sqrt(trajectoryCovMatrix(2,2)):0;
977 
978  matchedChamber.edgeX = chamber.localDistanceX;
979  matchedChamber.edgeY = chamber.localDistanceY;
980 
981  theShowerDigiFiller_->fillDefault(matchedChamber);
982 
983  matchedChamber.id = chamber.id;
984 
985  for ( const auto& rpcRecHit : *rpcHitHandle_ )
986  {
987  reco::MuonRPCHitMatch rpcHitMatch;
988 
989  if ( rpcRecHit.rawId() != chamber.id.rawId() ) continue;
990 
991  rpcHitMatch.x = rpcRecHit.localPosition().x();
992  rpcHitMatch.mask = 0;
993  rpcHitMatch.bx = rpcRecHit.BunchX();
994 
995  const double absDx = std::abs(rpcRecHit.localPosition().x()-chamber.tState.localPosition().x());
996  if( absDx <= 20 or absDx/sqrt(localError.xx()) <= 4 ) matchedChamber.rpcMatches.push_back(rpcHitMatch);
997  }
998 
999  muonChamberMatches.push_back(matchedChamber);
1000  }
1001  }
1002 
1003  aMuon.setMatches(muonChamberMatches);
1004 
1005  LogTrace("MuonIdentification") << "number of muon chambers: " << aMuon.matches().size() << "\n"
1006  << "number of chambers with segments according to the associator requirements: " <<
1007  nubmerOfMatchesAccordingToTrackAssociator;
1008  LogTrace("MuonIdentification") << "number of segment matches with the producer requirements: " <<
1010 
1011  // fillTime( iEvent, iSetup, aMuon );
1012 }
1013 
1015 {
1017  // arbitrate TrackerMuons
1018  // if a muon was exclusively TrackerMuon check if it can be a calo muon
1019  for (reco::MuonCollection::iterator muon=muons->begin(); muon!=muons->end();){
1020  if (muon->isTrackerMuon()){
1021  if (muon->numberOfMatches(arbitration)<minNumberOfMatches_){
1022  // TrackerMuon failed arbitration
1023  // If not any other base type - erase the element
1024  // (PFMuon is not a base type)
1026  if ((muon->type() & (~mask))==0){
1027  const reco::CaloMuon& caloMuon = makeCaloMuon(*muon);
1028  if (isGoodCaloMuon(caloMuon)) caloMuons->push_back( caloMuon );
1029  muon = muons->erase(muon);
1030  continue;
1031  } else {
1032  muon->setType(muon->type()&(~reco::Muon::TrackerMuon));
1033  }
1034  }
1035  }
1036  muon++;
1037  }
1038 }
1039 
1040 void MuonIdProducer::fillArbitrationInfo( reco::MuonCollection* pOutputMuons, unsigned int muonType )
1041 {
1042  //
1043  // apply segment flags
1044  //
1045  std::vector<std::pair<reco::MuonChamberMatch*,reco::MuonSegmentMatch*> > chamberPairs; // for chamber segment sorting
1046  std::vector<std::pair<reco::MuonChamberMatch*,reco::MuonSegmentMatch*> > stationPairs; // for station segment sorting
1047  std::vector<std::pair<reco::MuonChamberMatch*,reco::MuonSegmentMatch*> > arbitrationPairs; // for muon segment arbitration
1048 
1049  // muonIndex1
1050  for( unsigned int muonIndex1 = 0; muonIndex1 < pOutputMuons->size(); ++muonIndex1 )
1051  {
1052  auto& muon1 = pOutputMuons->at(muonIndex1);
1053  // chamberIter1
1054  for ( auto& chamber1 : muon1.matches() )
1055  {
1056  // segmentIter1
1057  std::vector<reco::MuonSegmentMatch> * segmentMatches1 = getSegmentMatches(chamber1, muonType);
1058 
1059  if(segmentMatches1->empty()) continue;
1060  chamberPairs.clear();
1061 
1062  for ( auto& segment1 : *segmentMatches1 )
1063  {
1064  chamberPairs.push_back(std::make_pair(&chamber1, &segment1));
1065  if(!segment1.isMask()) // has not yet been arbitrated
1066  {
1067  arbitrationPairs.clear();
1068  arbitrationPairs.push_back(std::make_pair(&chamber1, &segment1));
1069 
1070  // find identical segments with which to arbitrate
1071  // tracker muons only
1072  if (muon1.type() & muonType) {
1073  // muonIndex2
1074  for( unsigned int muonIndex2 = muonIndex1+1; muonIndex2 < pOutputMuons->size(); ++muonIndex2 )
1075  {
1076  auto& muon2 = pOutputMuons->at(muonIndex2);
1077  // tracker muons only
1078  if ( !(muon2.type() & muonType) ) continue;
1079  // chamberIter2
1080  for ( auto& chamber2 : muon2.matches() )
1081  {
1082  // segmentIter2
1083  std::vector<reco::MuonSegmentMatch> * segmentMatches2 = getSegmentMatches(chamber2, muonType);
1084  for ( auto& segment2 : *segmentMatches2 )
1085  {
1086  if(segment2.isMask()) continue; // has already been arbitrated
1087  if(approxEqual(segment2.x , segment1.x ) &&
1088  approxEqual(segment2.y , segment1.y ) &&
1089  approxEqual(segment2.dXdZ , segment1.dXdZ ) &&
1090  approxEqual(segment2.dYdZ , segment1.dYdZ ) &&
1091  approxEqual(segment2.xErr , segment1.xErr ) &&
1092  approxEqual(segment2.yErr , segment1.yErr ) &&
1093  approxEqual(segment2.dXdZErr, segment1.dXdZErr) &&
1094  approxEqual(segment2.dYdZErr, segment1.dYdZErr))
1095  {
1096  arbitrationPairs.push_back(std::make_pair(&chamber2, &segment2));
1097  }
1098  } // segmentIter2
1099  } // chamberIter2
1100  } // muonIndex2
1101  }
1102 
1103  // arbitration segment sort
1104  if(arbitrationPairs.empty()) continue; // this should never happen
1105  if(arbitrationPairs.size()==1) {
1106  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDRSlope);
1107  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDXSlope);
1108  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDR);
1109  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDX);
1110  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::Arbitrated);
1111  } else {
1112  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDRSlope));
1113  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDRSlope);
1114  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDXSlope));
1115  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDXSlope);
1116  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDR));
1117  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDR);
1118  sort(arbitrationPairs.begin(), arbitrationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BelongsToTrackByDX));
1119  arbitrationPairs.front().second->setMask(reco::MuonSegmentMatch::BelongsToTrackByDX);
1120  for ( auto& ap : arbitrationPairs ) {
1121  ap.second->setMask(reco::MuonSegmentMatch::Arbitrated);
1122  }
1123  }
1124  }
1125 
1126  // setup me1a cleaning for later
1127  if( muonType == reco::Muon::TrackerMuon && chamber1.id.subdetId() == MuonSubdetId::CSC && arbClean_ &&
1128  CSCDetId(chamber1.id).ring() == 4) {
1129  for ( auto& segment2 : chamber1.segmentMatches ) {
1130  if( segment1.cscSegmentRef.isNull() || segment2.cscSegmentRef.isNull() ) continue;
1131  if( meshAlgo_->isDuplicateOf(segment1.cscSegmentRef,segment2.cscSegmentRef) &&
1132  (segment2.mask & 0x1e0000) &&
1133  (segment1.mask & 0x1e0000) ) {
1135  //if the track has lost the segment already through normal arbitration no need to do it again.
1136  }
1137  }
1138  }// mark all ME1/a duplicates that this track owns
1139 
1140  } // segmentIter1
1141 
1142  // chamber segment sort
1143  if(chamberPairs.empty()) continue; // this should never happen
1144  if(chamberPairs.size()==1) {
1145  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDRSlope);
1146  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDXSlope);
1147  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDR);
1148  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDX);
1149  } else {
1150  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDRSlope));
1151  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDRSlope);
1152  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDXSlope));
1153  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDXSlope);
1154  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDR));
1155  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDR);
1156  sort(chamberPairs.begin(), chamberPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInChamberByDX));
1157  chamberPairs.front().second->setMask(reco::MuonSegmentMatch::BestInChamberByDX);
1158  }
1159  } // chamberIter1
1160 
1161  // station segment sort
1162  for( int stationIndex = 1; stationIndex < 5; ++stationIndex )
1163  {
1164  for( int detectorIndex = 1; detectorIndex <= 5; ++detectorIndex ) // 1-5, as in DataFormats/MuonDetId/interface/MuonSubdetId.h
1165  {
1166  stationPairs.clear();
1167 
1168  // chamberIter
1169  for ( auto& chamber : muon1.matches() )
1170  {
1171  if(!(chamber.station()==stationIndex && chamber.detector()==detectorIndex)) continue;
1172  std::vector<reco::MuonSegmentMatch> * segmentMatches = getSegmentMatches(chamber, muonType);
1173  if (segmentMatches->empty()) continue;
1174 
1175  for ( auto& segment : *segmentMatches ) {
1176  stationPairs.push_back(std::make_pair(&chamber, &segment));
1177  }
1178  } // chamberIter
1179 
1180  if(stationPairs.empty()) continue; // this may very well happen
1181  if(stationPairs.size()==1) {
1182  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDRSlope);
1183  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDXSlope);
1184  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDR);
1185  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDX);
1186  } else {
1187  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDRSlope));
1188  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDRSlope);
1189  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDXSlope));
1190  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDXSlope);
1191  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDR));
1192  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDR);
1193  sort(stationPairs.begin(), stationPairs.end(), SortMuonSegmentMatches(reco::MuonSegmentMatch::BestInStationByDX));
1194  stationPairs.front().second->setMask(reco::MuonSegmentMatch::BestInStationByDX);
1195  }
1196  }
1197  }
1198 
1199  } // muonIndex1
1200 
1201  if(arbClean_) {
1202  // clear old mesh, create and prune new mesh!
1203  meshAlgo_->clearMesh();
1204  meshAlgo_->runMesh(pOutputMuons);
1205  }
1206 }
1207 
1209  reco::IsoDeposit& trackDep, reco::IsoDeposit& ecalDep, reco::IsoDeposit& hcalDep, reco::IsoDeposit& hoDep,
1210  reco::IsoDeposit& jetDep)
1211 {
1212  const reco::Track* track = nullptr;
1213  if ( aMuon.track().isNonnull() ) track = aMuon.track().get();
1214  else if ( aMuon.standAloneMuon().isNonnull() ) track = aMuon.standAloneMuon().get();
1215  else throw cms::Exception("FatalError") << "Failed to compute muon isolation information for a muon with undefined references to tracks";
1216 
1217  reco::MuonIsolation isoR03, isoR05;
1218 
1219  // get deposits
1220  reco::IsoDeposit depTrk = muIsoExtractorTrack_->deposit(iEvent, iSetup, *track );
1221  std::vector<reco::IsoDeposit> caloDeps = muIsoExtractorCalo_->deposits(iEvent, iSetup, *track);
1222  reco::IsoDeposit depJet = muIsoExtractorJet_->deposit(iEvent, iSetup, *track );
1223 
1224  if(caloDeps.size()!=3) {
1225  LogTrace("MuonIdentification") << "Failed to fill vector of calorimeter isolation deposits!";
1226  return;
1227  }
1228 
1229  reco::IsoDeposit depEcal = caloDeps.at(0);
1230  reco::IsoDeposit depHcal = caloDeps.at(1);
1231  reco::IsoDeposit depHo = caloDeps.at(2);
1232 
1233  //no need to copy outside if we don't write them
1234  if (writeIsoDeposits_){
1235  trackDep = depTrk;
1236  ecalDep = depEcal;
1237  hcalDep = depHcal;
1238  hoDep = depHo;
1239  jetDep = depJet;
1240  }
1241 
1242  isoR03.sumPt = depTrk.depositWithin(0.3);
1243  isoR03.emEt = depEcal.depositWithin(0.3);
1244  isoR03.hadEt = depHcal.depositWithin(0.3);
1245  isoR03.hoEt = depHo.depositWithin(0.3);
1246  isoR03.nTracks = depTrk.depositAndCountWithin(0.3).second;
1247  isoR03.nJets = depJet.depositAndCountWithin(0.3).second;
1248  isoR03.trackerVetoPt = depTrk.candEnergy();
1249  isoR03.emVetoEt = depEcal.candEnergy();
1250  isoR03.hadVetoEt = depHcal.candEnergy();
1251  isoR03.hoVetoEt = depHo.candEnergy();
1252 
1253  isoR05.sumPt = depTrk.depositWithin(0.5);
1254  isoR05.emEt = depEcal.depositWithin(0.5);
1255  isoR05.hadEt = depHcal.depositWithin(0.5);
1256  isoR05.hoEt = depHo.depositWithin(0.5);
1257  isoR05.nTracks = depTrk.depositAndCountWithin(0.5).second;
1258  isoR05.nJets = depJet.depositAndCountWithin(0.5).second;
1259  isoR05.trackerVetoPt = depTrk.candEnergy();
1260  isoR05.emVetoEt = depEcal.candEnergy();
1261  isoR05.hadVetoEt = depHcal.candEnergy();
1262  isoR05.hoVetoEt = depHo.candEnergy();
1263 
1264 
1265  aMuon.setIsolation(isoR03, isoR05);
1266 
1267 }
1268 
1270 {
1271  const double energy = hypot(track.p(), 0.105658369);
1272  const math::XYZTLorentzVector p4(track.px(), track.py(), track.pz(), energy);
1273  return reco::Muon( track.charge(), p4, track.vertex() );
1274 }
1275 
1277 {
1278  double phi = 0;
1279  if( id.subdetId() == MuonSubdetId::DT ) { // DT
1280  DTChamberId muonId(id.rawId());
1281  if ( muonId.sector() <= 12 )
1282  phi = (muonId.sector()-1)/6.*M_PI;
1283  if ( muonId.sector() == 13 ) phi = 3/6.*M_PI;
1284  if ( muonId.sector() == 14 ) phi = 9/6.*M_PI;
1285  }
1286  if( id.subdetId() == MuonSubdetId::CSC ) { // CSC
1287  CSCDetId muonId(id.rawId());
1288  phi = M_PI/4+(muonId.triggerSector()-1)/3.*M_PI;
1289  }
1290  if ( phi > M_PI ) phi -= 2*M_PI;
1291  return phi;
1292 }
1293 
1295 {
1296  if ( muon.isStandAloneMuon() ) return muon.standAloneMuon()->innerPosition().phi();
1297  // the rest is tracker muon only
1298  if ( muon.matches().empty() ) {
1299  if ( muon.innerTrack().isAvailable() &&
1300  muon.innerTrack()->extra().isAvailable() )
1301  return muon.innerTrack()->outerPosition().phi();
1302  else
1303  return muon.phi(); // makes little sense, but what else can I use
1304  }
1305  return sectorPhi(muon.matches().at(0).id);
1306 }
1307 
1309 {
1311  aMuon.setCombinedQuality((*glbQualHandle_)[aMuon.combinedMuon()]);
1312  }
1313 
1314  LogDebug("MuonIdentification") << "tkChiVal " << aMuon.combinedQuality().trkRelChi2;
1315 
1316 }
1317 
1319  // skip muons with no tracks
1320  if (aMuon.innerTrack().isNull()) return;
1321  // get quality from muon if already there, otherwise make empty one
1323  // fill it
1324  const bool filled = trackerKinkFinder_->fillTrkKink(quality, *aMuon.innerTrack());
1325  // if quality was there, or if we filled it, commit to the muon
1326  if (filled || aMuon.isQualityValid()) aMuon.setCombinedQuality(quality);
1327 }
1328 
1330  const bool trackBAD = links->trackerTrack().isNull();
1331  const bool staBAD = links->standAloneTrack().isNull();
1332  const bool glbBAD = links->globalTrack().isNull();
1333  if (trackBAD || staBAD || glbBAD )
1334  {
1335  edm::LogWarning("muonIDbadLinks") << "Global muon links to constituent tracks are invalid: trkBad "
1336  <<trackBAD <<" standaloneBad "<<staBAD<<" globalBad "<<glbBAD
1337  <<". There should be no such object. Muon is skipped.";
1338  return false;
1339  }
1340  return true;
1341 }
1342 
1345  desc.setAllowAnything();
1346 
1347  desc.add<bool>("arbitrateTrackerMuons",false);
1348  desc.add<bool>("storeCrossedHcalRecHits",false);
1349  desc.add<bool>("fillShowerDigis",false);
1350 
1351  edm::ParameterSetDescription descTrkAsoPar;
1352  descTrkAsoPar.add<edm::InputTag>("GEMSegmentCollectionLabel",edm::InputTag("gemSegments"));
1353  descTrkAsoPar.add<edm::InputTag>("ME0SegmentCollectionLabel",edm::InputTag("me0Segments"));
1354  descTrkAsoPar.add<bool>("useGEM", false);
1355  descTrkAsoPar.add<bool>("useME0", false);
1356  descTrkAsoPar.setAllowAnything();
1357  desc.add<edm::ParameterSetDescription>("TrackAssociatorParameters", descTrkAsoPar);
1358 
1360  descJet.setAllowAnything();
1361  descJet.add<edm::ParameterSetDescription>("TrackAssociatorParameters", descTrkAsoPar);
1362  desc.add<edm::ParameterSetDescription>("JetExtractorPSet", descJet);
1363 
1365  descCalo.setAllowAnything();
1366  descCalo.add<edm::ParameterSetDescription>("TrackAssociatorParameters", descTrkAsoPar);
1367  desc.add<edm::ParameterSetDescription>("CaloExtractorPSet", descCalo);
1368 
1369  descriptions.addDefault(desc);
1370 }
#define LogDebug(id)
std::string hoDepositName_
double p() const
momentum vector magnitude
Definition: TrackBase.h:648
bool isAvailable() const
Definition: Ref.h:575
type
Definition: HCALResponse.h:21
float hadEt
hcal sum-Et
Definition: MuonIsolation.h:9
T getParameter(std::string const &) const
static const unsigned int BelongsToTrackByME1aClean
std::string jetDepositName_
double candEnergy() const
Get energy or pT attached to cand trajectory.
Definition: IsoDeposit.h:136
bool isGoodRPCMuon(const reco::Muon &muon)
int numberOfMatchedRPCLayers(ArbitrationType type=RPCHitAndTrackArbitration) const
float xx() const
Definition: LocalError.h:24
edm::EDGetTokenT< reco::TrackCollection > innerTrackCollectionToken_
reco::Muon makeMuon(edm::Event &iEvent, const edm::EventSetup &iSetup, const reco::TrackRef &track, TrackType type)
GEMSegmentRef gemSegmentRef
static const unsigned int GlobalMuon
Definition: Muon.h:276
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_
static void truthMatchMuon(const edm::Event &iEvent, const edm::EventSetup &iSetup, reco::Muon &aMuon)
DTRecSegment4DRef dtSegmentRef
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
double eta() const final
momentum pseudorapidity
static constexpr int GEM
Definition: MuonSubdetId.h:15
bool isStandAloneMuon() const override
Definition: Muon.h:293
std::vector< reco::MuonSegmentMatch > gemMatches
static bool crossedIP(const reco::Track &track)
float sumPt
sum-pt of tracks
Definition: MuonIsolation.h:7
void setType(unsigned int type)
Definition: Muon.h:285
TrackDetectorAssociator trackAssociator_
CSCSegmentRef cscSegmentRef
std::unique_ptr< MuonKinkFinder > trackerKinkFinder_
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:194
static const unsigned int Arbitrated
segment mask flags
void fillMuonId(edm::Event &, const edm::EventSetup &, reco::Muon &, TrackDetectorAssociator::Direction direction=TrackDetectorAssociator::InsideOut)
std::vector< const HBHERecHit * > crossedHcalRecHits
const_iterator end() const
last iterator over the map (read only)
virtual TrackRef innerTrack() const
Definition: Muon.h:48
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
void setAllowAnything()
allow any parameter label/value pairs
edm::Handle< reco::MuonTrackLinksCollection > linkCollectionHandle_
edm::EDGetTokenT< RPCRecHitCollection > rpcHitToken_
bool isGoodGEMMuon(const reco::Muon &muon)
int overlap(const reco::Muon &muon, const reco::Track &track)
bool fillCaloCompatibility_
std::vector< const EcalRecHit * > ecalRecHits
hits in the cone
std::vector< DetId > crossedEcalIds
std::string trackDepositName_
void fillArbitrationInfo(reco::MuonCollection *, unsigned int muonType=reco::Muon::TrackerMuon)
const_iterator find(const key_type &k) const
find element with specified reference key
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
double phiOfMuonIneteractionRegion(const reco::Muon &muon) const
std::vector< CaloMuon > CaloMuonCollection
collection of Muon objects
Definition: MuonFwd.h:27
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
std::vector< reco::MuonSegmentMatch > * getSegmentMatches(reco::MuonChamberMatch &chamber, unsigned int muonType) const
get the segment matches of the appropriate type
DetId findMaxDeposition(EnergyType)
Find detector elements with highest energy deposition.
void produce(edm::Event &, const edm::EventSetup &) override
float hadVetoEt
hcal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:15
float emS9
energy deposited in 3x3 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:29
double evaluate(const reco::Muon &)
double pt() const final
transverse momentum
MuonCaloCompatibility muonCaloCompatibility_
static const unsigned int BestInStationByDRSlope
float timeAtIpOutInErr() const
Definition: MuonTimeExtra.h:49
bool isMatchesValid() const
Definition: Muon.h:142
bool ev
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
edm::EDGetTokenT< reco::TrackToTrackMap > pickyCollectionToken_
static std::string toStr(const ICTypeKey k)
double px() const
x coordinate of momentum vector
Definition: TrackBase.h:660
bool arbitrateTrackerMuons_
static const unsigned int BelongsToTrackByDXSlope
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:113
void fillGlbQuality(edm::Event &, const edm::EventSetup &, reco::Muon &aMuon)
int nDof() const
number of measurements used in timing calculation
Definition: MuonTimeExtra.h:22
float timeAtIpOutInErr
Definition: MuonTime.h:18
std::vector< DetId > crossedHcalIds
float trkRelChi2
chi2 value for the inner track stub with respect to the global track
Definition: MuonQuality.h:15
double nXnEnergy(const DetId &, EnergyType, int gridSize=1)
get energy of the NxN shape (N = 2*gridSize + 1) around given detector element
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > muIsoExtractorTrack_
float towerS9
total energy in 3x3 tower shape
Definition: MuonEnergy.h:23
static const unsigned int BestInStationByDR
MuonTime time() const
get DT/CSC combined timing information
Definition: Muon.h:131
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::unique_ptr< MuonTimingFiller > theTimingFiller_
math::XYZPoint trkGlobPosAtHcal
float ecal_time
Calorimeter timing.
Definition: MuonEnergy.h:48
float ho
energy deposited in crossed HO towers
Definition: MuonEnergy.h:43
bool isTrackerMuon() const override
Definition: Muon.h:292
double depositWithin(double coneSize, const Vetos &vetos=Vetos(), bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:34
bool approxEqual(const double a, const double b, const double tol=1E-3) const
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 &)
bool isRPCMuon() const
Definition: Muon.h:296
DetId hcal_id
DetId of the central HCAL tower with smallest depth.
Definition: MuonEnergy.h:61
edm::EDGetTokenT< reco::TrackToTrackMap > tpfmsCollectionToken_
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:732
std::vector< reco::MuonSegmentMatch > me0Matches
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< MuonShowerDigiFiller > theShowerDigiFiller_
double ptThresholdToFillCandidateP4WithGlobalFit_
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:684
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 isCaloCompatibilityValid() const
Definition: CaloMuon.h:44
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
float yy() const
Definition: LocalError.h:26
float emS25
energy deposited in 5x5 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:31
double p() const
momentum vector magnitude
Definition: CaloMuon.h:51
bool isGlobalMuon() const override
Definition: Muon.h:291
static const unsigned int ME0Muon
Definition: Muon.h:283
ArbitrationType
define arbitration schemes
Definition: Muon.h:186
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
bool isGoodTrackerMuon(const reco::Muon &muon)
double pt() const
track transverse momentum
Definition: TrackBase.h:654
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:8
bool checkLinks(const reco::MuonTrackLinks *) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
float timeAtIpInOutErr
Definition: MuonTime.h:15
std::vector< TAMuonChamberMatch > chambers
int nJets
number of jets in the cone
Definition: MuonIsolation.h:12
std::vector< const HBHERecHit * > hcalRecHits
static const unsigned int BestInChamberByDX
std::string ecalDepositName_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
MuonQuality combinedQuality() const
get energy deposition information
Definition: Muon.h:121
float timeAtIpOutIn
b) particle is moving from outside in
Definition: MuonTime.h:17
int nDof
number of muon stations used
Definition: MuonTime.h:10
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float timeAtIpInOutErr() const
Definition: MuonTimeExtra.h:44
CSCDetId chamberId() const
Definition: CSCDetId.h:53
edm::EDGetTokenT< reco::MuonCollection > muonCollectionToken_
float hoEt
ho sum-Et
Definition: MuonIsolation.h:10
edm::EDGetTokenT< reco::TrackCollection > outerTrackCollectionToken_
def stationIndex(name)
Definition: plotscripts.py:355
edm::Handle< RPCRecHitCollection > rpcHitHandle_
float hoS9
energy deposited in 3x3 HO tower shape around central tower
Definition: MuonEnergy.h:45
std::vector< reco::MuonRPCHitMatch > rpcMatches
static constexpr int ME0
Definition: MuonSubdetId.h:16
static const unsigned int BestInChamberByDR
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
T min(T a, T b)
Definition: MathUtil.h:58
ME0SegmentRef me0SegmentRef
bool isQualityValid() const
Definition: Muon.h:119
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::Handle< reco::TrackToTrackMap > dytCollectionHandle_
bool isValid() const
Definition: HandleBase.h:74
edm::Handle< reco::TrackCollection > outerTrackCollectionHandle_
edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkCollectionToken_
double crossedEnergy(EnergyType)
energy in detector elements crossed by the track by types
bool isNull() const
Checks for null.
Definition: Ref.h:248
#define LogTrace(id)
static const unsigned int BestInStationByDXSlope
math::XYZPointF hcal_position
Definition: MuonEnergy.h:55
bool fillGlobalTrackRefits_
static double sectorPhi(const DetId &id)
bool isEnergyValid() const
Definition: Muon.h:109
TrackRef standAloneMuon() const override
reference to a stand-alone muon Track
Definition: Muon.h:52
float hoVetoEt
ho sum-et in the veto region in r-phi
Definition: MuonIsolation.h:16
#define M_PI
double pz() const
z coordinate of momentum vector
Definition: TrackBase.h:672
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:111
reco::CaloMuon makeCaloMuon(const reco::Muon &)
unsigned int id
int nTracks
number of tracks in the cone (excluding veto region)
Definition: MuonIsolation.h:11
static const unsigned int BestInChamberByDXSlope
float emMax
maximal energy of ECAL crystal in the 5x5 shape
Definition: MuonEnergy.h:33
int ring() const
Definition: CSCDetId.h:75
bool failedToGet() const
Definition: HandleBase.h:78
void setCaloCompatibility(float input)
Definition: CaloMuon.h:43
Definition: DetId.h:18
static const unsigned int RPCMuon
Definition: Muon.h:281
static ICTypeKey toKey(const std::string &s)
bool isTimeValid() const
Definition: Muon.h:129
static const unsigned int TrackerMuon
Definition: Muon.h:277
float emVetoEt
ecal sum-et in the veto region in r-phi
Definition: MuonIsolation.h:14
void configure(const edm::ParameterSet &)
size_type size() const
map size
std::vector< ICTypes::ICTypeKey > inputCollectionTypes_
float timeAtIpInOut() const
Definition: MuonTimeExtra.h:43
float hadMax
maximal energy of HCAL tower in the 3x3 shape
Definition: MuonEnergy.h:41
static const unsigned int BelongsToTrackByDRSlope
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:21
TrackRef combinedMuon() const override
reference to a stand-alone muon Track
Definition: Muon.h:55
void setCombinedQuality(const MuonQuality &combinedQuality)
set energy deposition information
Definition: Muon.h:123
std::vector< edm::InputTag > inputCollectionLabels_
static const unsigned int PFMuon
Definition: Muon.h:280
std::vector< MuonChamberMatch > & matches()
get muon matching information
Definition: Muon.h:144
std::unique_ptr< reco::isodeposit::IsoDepositExtractor > muIsoExtractorJet_
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: CaloMuon.h:37
int triggerSector() const
Definition: CSCDetId.cc:3
MuonIdProducer(const edm::ParameterSet &)
void arbitrateMuons(reco::MuonCollection *, reco::CaloMuonCollection *)
std::vector< reco::MuonSegmentMatch > segmentMatches
bool fillGlobalTrackQuality_
int numberOfMatches(ArbitrationType type=SegmentAndTrackArbitration) const
get number of chambers with matched segments
DetId ecal_id
DetId of the central ECAL crystal.
Definition: MuonEnergy.h:58
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)
fixed size matrix
functor predicate for standard library sort algorithm
static const unsigned int GEMMuon
Definition: Muon.h:282
int sector() const
Definition: DTChamberId.h:61
std::pair< double, int > depositAndCountWithin(double coneSize, const Vetos &vetos=Vetos(), double threshold=-1e+36, bool skipDepositVeto=false) const
Get deposit.
Definition: IsoDeposit.cc:44
T get() const
Definition: EventSetup.h:71
edm::Handle< reco::TrackToTrackMap > tpfmsCollectionHandle_
static const unsigned int BestInStationByDX
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
bool storeCrossedHcalRecHits_
edm::Handle< reco::TrackCollection > innerTrackCollectionHandle_
unsigned int type() const
Definition: Muon.h:286
math::XYZPoint trkGlobPosAtEcal
Track position at different parts of the calorimeter.
int charge() const
track electric charge
Definition: TrackBase.h:600
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
MuonTrackType
map for Global Muon refitters
Definition: Muon.h:38
double sigmaThresholdToFillCandidateP4WithGlobalFit_
static const unsigned int StandAloneMuon
Definition: Muon.h:278
std::vector< HcalMuonRecHit > crossedHadRecHits
Definition: MuonEnergy.h:67
static constexpr int DT
Definition: MuonSubdetId.h:12
float timeAtIpOutIn() const
b) particle is moving from outside in
Definition: MuonTimeExtra.h:48
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
void setMatches(const std::vector< MuonChamberMatch > &matches)
set muon matching information
Definition: Muon.h:147
math::XYZPointF ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:54
static constexpr int CSC
Definition: MuonSubdetId.h:13
static const unsigned int BestInChamberByDRSlope
double phi() const final
momentum azimuthal angle
float caloCompatibility() const
Definition: CaloMuon.h:42
bool validateGlobalMuonPair(const reco::MuonTrackLinks &goodMuon, const reco::MuonTrackLinks &badMuon)
T const * product() const
Definition: ESHandle.h:86
bool debugWithTruthMatching_
float timeAtIpInOut
Definition: MuonTime.h:14
bool isGoodCaloMuon(const reco::CaloMuon &muon)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
float trackerVetoPt
(sum-)pt inside the veto region in r-phi
Definition: MuonIsolation.h:13
float hadS9
energy deposited in 3x3 HCAL tower shape around central tower
Definition: MuonEnergy.h:39
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
edm::Handle< reco::MuonCollection > muonCollectionHandle_
double py() const
y coordinate of momentum vector
Definition: TrackBase.h:666
Definition: Run.h:45
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_
edm::EDGetTokenT< reco::TrackToTrackMap > dytCollectionToken_