Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:25:55

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 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 
0017 #include "DataFormats/Common/interface/Handle.h"
0018 #include "RecoMuon/MuonIdentification/plugins/MuonLinksProducerForHLT.h"
0019 
0020 //#include <algorithm>
0021 
0022 MuonLinksProducerForHLT::MuonLinksProducerForHLT(const edm::ParameterSet& iConfig) {
0023   produces<reco::MuonTrackLinksCollection>();
0024   theLinkCollectionInInput = iConfig.getParameter<edm::InputTag>("LinkCollection");
0025   theInclusiveTrackCollectionInInput = iConfig.getParameter<edm::InputTag>("InclusiveTrackerTrackCollection");
0026   ptMin = iConfig.getParameter<double>("ptMin");
0027   pMin = iConfig.getParameter<double>("pMin");
0028   shareHitFraction = iConfig.getParameter<double>("shareHitFraction");
0029 
0030   linkToken_ = consumes<reco::MuonTrackLinksCollection>(theLinkCollectionInInput);
0031   trackToken_ = consumes<reco::TrackCollection>(theInclusiveTrackCollectionInInput);
0032 }
0033 
0034 MuonLinksProducerForHLT::~MuonLinksProducerForHLT() {}
0035 
0036 void MuonLinksProducerForHLT::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0037   auto output = std::make_unique<reco::MuonTrackLinksCollection>();
0038 
0039   edm::Handle<reco::MuonTrackLinksCollection> links;
0040   iEvent.getByToken(linkToken_, links);
0041 
0042   edm::Handle<reco::TrackCollection> incTracks;
0043   iEvent.getByToken(trackToken_, incTracks);
0044 
0045   for (reco::MuonTrackLinksCollection::const_iterator link = links->begin(); link != links->end(); ++link) {
0046     bool found = false;
0047     unsigned int trackIndex = 0;
0048     unsigned int muonTrackHits = link->trackerTrack()->extra()->recHitsSize();
0049     for (reco::TrackCollection::const_iterator track = incTracks->begin(); track != incTracks->end();
0050          ++track, ++trackIndex) {
0051       if (track->pt() < ptMin)
0052         continue;
0053       if (track->p() < pMin)
0054         continue;
0055       //std::cout << "pt (muon/track) " << link->trackerTrack()->pt() << " " << track->pt() << std::endl;
0056       unsigned trackHits = track->extra()->recHitsSize();
0057       //std::cout << "hits (muon/track) " << muonTrackHits  << " " << trackHits() << std::endl;
0058       unsigned int smallestNumberOfHits = trackHits < muonTrackHits ? trackHits : muonTrackHits;
0059       int numberOfCommonDetIds = 0;
0060       for (auto hit = track->extra()->recHitsBegin(); hit != track->extra()->recHitsEnd(); ++hit) {
0061         for (auto mit = link->trackerTrack()->extra()->recHitsBegin();
0062              mit != link->trackerTrack()->extra()->recHitsEnd();
0063              ++mit) {
0064           if ((*hit)->geographicalId() == (*mit)->geographicalId() &&
0065               (*hit)->sharesInput((*mit), TrackingRecHit::some)) {
0066             numberOfCommonDetIds++;
0067             break;
0068           }
0069         }
0070       }
0071       double fraction = (double)numberOfCommonDetIds / smallestNumberOfHits;
0072       // std::cout << "Overlap/Smallest/fraction = " << numberOfCommonDetIds << " " << smallestNumberOfHits << " " << fraction << std::endl;
0073       if (fraction > shareHitFraction) {
0074         output->push_back(
0075             reco::MuonTrackLinks(reco::TrackRef(incTracks, trackIndex), link->standAloneTrack(), link->globalTrack()));
0076         found = true;
0077         break;
0078       }
0079     }
0080     if (!found)
0081       output->push_back(reco::MuonTrackLinks(link->trackerTrack(), link->standAloneTrack(), link->globalTrack()));
0082   }
0083   iEvent.put(std::move(output));
0084 }