CMS 3D CMS Logo

MuonLinksProducerForHLT.cc
Go to the documentation of this file.
1 
7 // system include files
8 #include <memory>
9 
10 // user include files
12 
15 
17 
20 
21 //#include <algorithm>
22 
24 {
25  produces<reco::MuonTrackLinksCollection>();
26  theLinkCollectionInInput = iConfig.getParameter<edm::InputTag>("LinkCollection");
27  theInclusiveTrackCollectionInInput = iConfig.getParameter<edm::InputTag>("InclusiveTrackerTrackCollection");
28  ptMin = iConfig.getParameter<double>("ptMin");
29  pMin = iConfig.getParameter<double>("pMin");
30  shareHitFraction = iConfig.getParameter<double>("shareHitFraction");
31 
32  linkToken_ = consumes<reco::MuonTrackLinksCollection>(theLinkCollectionInInput);
33  trackToken_ = consumes<reco::TrackCollection>(theInclusiveTrackCollectionInInput);
34 
35 }
36 
38 {
39 }
40 
42 {
43  auto output = std::make_unique<reco::MuonTrackLinksCollection>();
44 
46  iEvent.getByToken(linkToken_, links);
47 
49  iEvent.getByToken(trackToken_, incTracks);
50 
51  for(reco::MuonTrackLinksCollection::const_iterator link = links->begin();
52  link != links->end(); ++link){
53  bool found = false;
54  unsigned int trackIndex = 0;
55  unsigned int muonTrackHits = link->trackerTrack()->extra()->recHitsSize();
56  for(reco::TrackCollection::const_iterator track = incTracks->begin();
57  track != incTracks->end(); ++track, ++trackIndex){
58  if ( track->pt() < ptMin ) continue;
59  if ( track->p() < pMin ) continue;
60  //std::cout << "pt (muon/track) " << link->trackerTrack()->pt() << " " << track->pt() << std::endl;
61  unsigned trackHits = track->extra()->recHitsSize();
62  //std::cout << "hits (muon/track) " << muonTrackHits << " " << trackHits() << std::endl;
63  unsigned int smallestNumberOfHits = trackHits < muonTrackHits ? trackHits : muonTrackHits;
64  int numberOfCommonDetIds = 0;
65  for ( auto hit = track->extra()->recHitsBegin();
66  hit != track->extra()->recHitsEnd(); ++hit ) {
67  for ( auto mit = link->trackerTrack()->extra()->recHitsBegin();
68  mit != link->trackerTrack()->extra()->recHitsEnd(); ++mit ) {
69  if ( (*hit)->geographicalId() == (*mit)->geographicalId() &&
70  (*hit)->sharesInput((*mit),TrackingRecHit::some) ) {
71  numberOfCommonDetIds++;
72  break;
73  }
74  }
75  }
76  double fraction = (double)numberOfCommonDetIds/smallestNumberOfHits;
77  // std::cout << "Overlap/Smallest/fraction = " << numberOfCommonDetIds << " " << smallestNumberOfHits << " " << fraction << std::endl;
78  if( fraction > shareHitFraction ) {
79  output->push_back(reco::MuonTrackLinks(reco::TrackRef(incTracks,trackIndex),
80  link->standAloneTrack(),
81  link->globalTrack() ) );
82  found = true;
83  break;
84  }
85  }
86  if (!found)
87  output->push_back(reco::MuonTrackLinks(link->trackerTrack(),
88  link->standAloneTrack(),
89  link->globalTrack() ) );
90  }
91  iEvent.put(std::move(output));
92 }
T getParameter(std::string const &) const
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< reco::TrackCollection > trackToken_
edm::EDGetTokenT< reco::MuonTrackLinksCollection > linkToken_
MuonLinksProducerForHLT(const edm::ParameterSet &)
edm::InputTag theInclusiveTrackCollectionInInput
def move(src, dest)
Definition: eostools.py:511