CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonLinksProducerForHLT.cc
Go to the documentation of this file.
1 
9 // system include files
10 #include <memory>
11 
12 // user include files
15 
18 
20 
25 //#include "DataFormats/MuonReco/interface/Muon.h"
28 
29 //#include <algorithm>
30 
32 {
33  produces<reco::MuonTrackLinksCollection>();
34  theLinkCollectionInInput = iConfig.getParameter<edm::InputTag>("LinkCollection");
35  theInclusiveTrackCollectionInInput = iConfig.getParameter<edm::InputTag>("InclusiveTrackerTrackCollection");
36  ptMin = iConfig.getParameter<double>("ptMin");
37  pMin = iConfig.getParameter<double>("pMin");
38  shareHitFraction = iConfig.getParameter<double>("shareHitFraction");
39 }
40 
42 {
43 }
44 
46 {
47  std::auto_ptr<reco::MuonTrackLinksCollection> output(new reco::MuonTrackLinksCollection());
48 
50  iEvent.getByLabel(theLinkCollectionInInput, links);
51 
54 
55  for(reco::MuonTrackLinksCollection::const_iterator link = links->begin();
56  link != links->end(); ++link){
57  bool found = false;
58  unsigned int trackIndex = 0;
59  unsigned int muonTrackHits = link->trackerTrack()->extra()->recHits().size();
60  for(reco::TrackCollection::const_iterator track = incTracks->begin();
61  track != incTracks->end(); ++track, ++trackIndex){
62  if ( track->pt() < ptMin ) continue;
63  if ( track->p() < pMin ) continue;
64  //std::cout << "pt (muon/track) " << link->trackerTrack()->pt() << " " << track->pt() << std::endl;
65  unsigned trackHits = track->extra()->recHits().size();
66  //std::cout << "hits (muon/track) " << muonTrackHits << " " << trackHits() << std::endl;
67  unsigned int smallestNumberOfHits = trackHits < muonTrackHits ? trackHits : muonTrackHits;
68  int numberOfCommonDetIds = 0;
69  for ( TrackingRecHitRefVector::const_iterator hit = track->extra()->recHitsBegin();
70  hit != track->extra()->recHitsEnd(); ++hit ) {
71  for ( TrackingRecHitRefVector::const_iterator mit = link->trackerTrack()->extra()->recHitsBegin();
72  mit != link->trackerTrack()->extra()->recHitsEnd(); ++mit ) {
73  if ( hit->get()->geographicalId() == mit->get()->geographicalId() &&
74  hit->get()->sharesInput(mit->get(),TrackingRecHit::some) ) {
75  numberOfCommonDetIds++;
76  break;
77  }
78  }
79  }
80  double fraction = (double)numberOfCommonDetIds/smallestNumberOfHits;
81  // std::cout << "Overlap/Smallest/fraction = " << numberOfCommonDetIds << " " << smallestNumberOfHits << " " << fraction << std::endl;
82  if( fraction > shareHitFraction ) {
83  output->push_back(reco::MuonTrackLinks(reco::TrackRef(incTracks,trackIndex),
84  link->standAloneTrack(),
85  link->globalTrack() ) );
86  found = true;
87  break;
88  }
89  }
90  if (!found)
91  output->push_back(reco::MuonTrackLinks(link->trackerTrack(),
92  link->standAloneTrack(),
93  link->globalTrack() ) );
94  }
95  iEvent.put( output );
96 }
T getParameter(std::string const &) const
std::vector< MuonTrackLinks > MuonTrackLinksCollection
collection of MuonTrackLinks
Definition: MuonFwd.h:22
std::string link(std::string &nm, std::string &ns)
Definition: hierarchy.cc:47
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
MuonLinksProducerForHLT(const edm::ParameterSet &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag theInclusiveTrackCollectionInInput
virtual void produce(edm::Event &, const edm::EventSetup &)