Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-08 03:36:30

0001 /** \class MuonLinksProducerForHLT
0002  *
0003  *  \author R. Bellan - UCSB <riccardo.bellan@cern.ch>
0004  */
0005 
0006 // system include files
0007 #include <memory>
0008 
0009 // user include files
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "DataFormats/Common/interface/Handle.h"
0015 #include "RecoMuon/MuonIdentification/plugins/MuonLinksProducerForHLT.h"
0016 
0017 MuonLinksProducerForHLT::MuonLinksProducerForHLT(const edm::ParameterSet& iConfig)
0018     : theLinkCollectionInInput_{iConfig.getParameter<edm::InputTag>("LinkCollection")},
0019       theInclusiveTrackCollectionInInput_{iConfig.getParameter<edm::InputTag>("InclusiveTrackerTrackCollection")},
0020       linkToken_{consumes<reco::MuonTrackLinksCollection>(theLinkCollectionInInput_)},
0021       trackToken_{consumes<reco::TrackCollection>(theInclusiveTrackCollectionInInput_)},
0022       ptMin_{iConfig.getParameter<double>("ptMin")},
0023       pMin_{iConfig.getParameter<double>("pMin")},
0024       shareHitFraction_{iConfig.getParameter<double>("shareHitFraction")} {
0025   produces<reco::MuonTrackLinksCollection>();
0026 }
0027 
0028 void MuonLinksProducerForHLT::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0029   auto output = std::make_unique<reco::MuonTrackLinksCollection>();
0030 
0031   edm::Handle<reco::MuonTrackLinksCollection> links;
0032   iEvent.getByToken(linkToken_, links);
0033 
0034   edm::Handle<reco::TrackCollection> incTracks;
0035   iEvent.getByToken(trackToken_, incTracks);
0036 
0037   for (reco::MuonTrackLinksCollection::const_iterator link = links->begin(); link != links->end(); ++link) {
0038     bool found = false;
0039     unsigned int trackIndex = 0;
0040     unsigned int muonTrackHits = link->trackerTrack()->extra()->recHitsSize();
0041     for (reco::TrackCollection::const_iterator track = incTracks->begin(); track != incTracks->end();
0042          ++track, ++trackIndex) {
0043       if (track->pt() < ptMin_)
0044         continue;
0045       if (track->p() < pMin_)
0046         continue;
0047       //std::cout << "pt (muon/track) " << link->trackerTrack()->pt() << " " << track->pt() << std::endl;
0048       unsigned trackHits = track->extra()->recHitsSize();
0049       //std::cout << "hits (muon/track) " << muonTrackHits  << " " << trackHits() << std::endl;
0050       unsigned int smallestNumberOfHits = trackHits < muonTrackHits ? trackHits : muonTrackHits;
0051       int numberOfCommonDetIds = 0;
0052       for (auto hit = track->extra()->recHitsBegin(); hit != track->extra()->recHitsEnd(); ++hit) {
0053         for (auto mit = link->trackerTrack()->extra()->recHitsBegin();
0054              mit != link->trackerTrack()->extra()->recHitsEnd();
0055              ++mit) {
0056           if ((*hit)->geographicalId() == (*mit)->geographicalId() &&
0057               (*hit)->sharesInput((*mit), TrackingRecHit::some)) {
0058             numberOfCommonDetIds++;
0059             break;
0060           }
0061         }
0062       }
0063       double fraction = (double)numberOfCommonDetIds / smallestNumberOfHits;
0064       // std::cout << "Overlap/Smallest/fraction = " << numberOfCommonDetIds << " " << smallestNumberOfHits << " " << fraction << std::endl;
0065       if (fraction > shareHitFraction_) {
0066         output->push_back(
0067             reco::MuonTrackLinks(reco::TrackRef(incTracks, trackIndex), link->standAloneTrack(), link->globalTrack()));
0068         found = true;
0069         break;
0070       }
0071     }
0072     if (!found)
0073       output->push_back(reco::MuonTrackLinks(link->trackerTrack(), link->standAloneTrack(), link->globalTrack()));
0074   }
0075   iEvent.put(std::move(output));
0076 }
0077 
0078 void MuonLinksProducerForHLT::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0079   edm::ParameterSetDescription desc;
0080   desc.add<edm::InputTag>("LinkCollection", edm::InputTag("hltPFMuonMerging"));
0081   desc.add<edm::InputTag>("InclusiveTrackerTrackCollection", edm::InputTag("hltL3MuonsLinksCombination"));
0082   desc.add<double>("ptMin", 2.5);
0083   desc.add<double>("pMin", 2.5);
0084   desc.add<double>("shareHitFraction", 0.80);
0085   descriptions.addWithDefaultLabel(desc);
0086 }