CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/RecoMuon/MuonIdentification/plugins/MuonLinksProducerForHLT.cc

Go to the documentation of this file.
00001 
00009 // system include files
00010 #include <memory>
00011 
00012 // user include files
00013 #include "FWCore/Framework/interface/Frameworkfwd.h"
00014 #include "FWCore/Framework/interface/EDProducer.h"
00015 
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/EventSetup.h"
00018 
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 
00021 #include "DataFormats/Common/interface/Handle.h"
00022 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00023 #include "DataFormats/TrackReco/interface/Track.h"
00024 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00025 //#include "DataFormats/MuonReco/interface/Muon.h"
00026 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00027 #include "RecoMuon/MuonIdentification/plugins/MuonLinksProducerForHLT.h"
00028 
00029 //#include <algorithm>
00030 
00031 MuonLinksProducerForHLT::MuonLinksProducerForHLT(const edm::ParameterSet& iConfig)
00032 {
00033    produces<reco::MuonTrackLinksCollection>();
00034    theLinkCollectionInInput = iConfig.getParameter<edm::InputTag>("LinkCollection");
00035    theInclusiveTrackCollectionInInput = iConfig.getParameter<edm::InputTag>("InclusiveTrackerTrackCollection");
00036    ptMin = iConfig.getParameter<double>("ptMin");
00037    pMin = iConfig.getParameter<double>("pMin");
00038    shareHitFraction = iConfig.getParameter<double>("shareHitFraction");
00039 }
00040 
00041 MuonLinksProducerForHLT::~MuonLinksProducerForHLT()
00042 {
00043 }
00044 
00045 void MuonLinksProducerForHLT::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00046 {
00047    std::auto_ptr<reco::MuonTrackLinksCollection> output(new reco::MuonTrackLinksCollection());
00048 
00049    edm::Handle<reco::MuonTrackLinksCollection> links; 
00050    iEvent.getByLabel(theLinkCollectionInInput, links);
00051 
00052    edm::Handle<reco::TrackCollection> incTracks; 
00053    iEvent.getByLabel(theInclusiveTrackCollectionInInput, incTracks);
00054 
00055    for(reco::MuonTrackLinksCollection::const_iterator link = links->begin(); 
00056        link != links->end(); ++link){
00057      bool found = false;
00058      unsigned int trackIndex = 0;
00059      unsigned int muonTrackHits = link->trackerTrack()->extra()->recHits().size();
00060      for(reco::TrackCollection::const_iterator track = incTracks->begin();
00061          track != incTracks->end(); ++track, ++trackIndex){      
00062        if ( track->pt() < ptMin ) continue;
00063        if ( track->p() < pMin ) continue;
00064        //std::cout << "pt (muon/track) " << link->trackerTrack()->pt() << " " << track->pt() << std::endl;
00065        unsigned trackHits = track->extra()->recHits().size();
00066        //std::cout << "hits (muon/track) " << muonTrackHits  << " " << trackHits() << std::endl;
00067        unsigned int smallestNumberOfHits = trackHits < muonTrackHits ? trackHits : muonTrackHits;
00068        int numberOfCommonDetIds = 0;
00069        for ( TrackingRecHitRefVector::const_iterator hit = track->extra()->recHitsBegin();
00070              hit != track->extra()->recHitsEnd(); ++hit ) {
00071          for ( TrackingRecHitRefVector::const_iterator mit = link->trackerTrack()->extra()->recHitsBegin();
00072              mit != link->trackerTrack()->extra()->recHitsEnd(); ++mit ) {
00073            if ( hit->get()->geographicalId() == mit->get()->geographicalId() && 
00074                 hit->get()->sharesInput(mit->get(),TrackingRecHit::some) ) { 
00075              numberOfCommonDetIds++;
00076              break;
00077            }
00078          }
00079        }
00080        double fraction = (double)numberOfCommonDetIds/smallestNumberOfHits;
00081        // std::cout << "Overlap/Smallest/fraction = " << numberOfCommonDetIds << " " << smallestNumberOfHits << " " << fraction << std::endl;
00082        if( fraction > shareHitFraction ) { 
00083          output->push_back(reco::MuonTrackLinks(reco::TrackRef(incTracks,trackIndex), 
00084                                                 link->standAloneTrack(), 
00085                                                 link->globalTrack() ) );
00086          found = true;
00087          break;
00088        }
00089      }
00090      if (!found) 
00091        output->push_back(reco::MuonTrackLinks(link->trackerTrack(), 
00092                                               link->standAloneTrack(), 
00093                                               link->globalTrack() ) );
00094    }  
00095    iEvent.put( output );
00096 }