CMS 3D CMS Logo

HLTMuonTrackSelector.cc
Go to the documentation of this file.
1 /*
2 * class HLTMuonTrackSelector
3 *
4 * See header file for documentation
5 *
6 * Author: Kyeongpil Lee (kplee@cern.ch)
7 *
8 */
9 
10 #include "HLTMuonTrackSelector.h"
11 
17 
19 collectionCloner ( *this, iConfig, true ),
20 collectionClonerTokens ( iConfig.getParameter<edm::InputTag>("track"), consumesCollector() ),
21 token_muon ( consumes< vector<reco::Muon> > ( iConfig.getParameter<edm::InputTag>("muon" )) ),
22 token_originalMVAVals ( consumes< MVACollection > ( iConfig.getParameter<edm::InputTag>("originalMVAVals" )) ),
23 flag_copyMVA ( iConfig.getParameter<bool>("copyMVA") )
24 {
25  produces<MVACollection>("MVAValues");
26 }
27 
29 
32  desc.add<edm::InputTag>("track", edm::InputTag() );
33  desc.add<edm::InputTag>("muon", edm::InputTag() );
34  desc.add<edm::InputTag>("originalMVAVals", edm::InputTag() );
35  desc.add<bool>("copyMVA", false);
36  TrackCollectionCloner::fill(desc); // -- add copyExtras and copyTrajectories
37  descriptions.add("HLTMuonTrackSelector", desc);
38 }
39 
40 
43 
44  // -- load tracks
45  auto const & originalTracks = collectionClonerTokens.tracks(iEvent);
46  auto nTrack = originalTracks.size();
47 
48  // -- load muons
49  edm::Handle< vector<reco::Muon> > handle_muon;
50  iEvent.getByToken(token_muon, handle_muon);
51  auto nMuon = handle_muon->size();
52 
53  // -- load MVA values if necessary
54  edm::Handle<MVACollection> handle_originalMVAVals;
55  if( flag_copyMVA ) {
56  iEvent.getByToken(token_originalMVAVals, handle_originalMVAVals);
57  assert( (*handle_originalMVAVals).size() == nTrack );
58  }
59 
60  // -- containers for selected track informations
61  std::vector<unsigned int> selectedIter;
62  auto selectedMVAVals = std::make_unique<MVACollection>();
63 
64  auto nSelected = 0U;
65 
66 
68  // -- matching -- //
70 
71  // -- iteration over muons
72  for(auto i_mu=0U; i_mu<nMuon; ++i_mu) {
73  // -- avoids crashing in case the muon is SA only.
74  const reco::Muon& muon(handle_muon->at(i_mu));
75  TrackRef muonTrackRef = (muon.innerTrack().isNonnull())? muon.innerTrack() : muon.muonBestTrack();
76 
77  double muonPt = muonTrackRef->pt();
78  double muonEta = muonTrackRef->eta();
79  double muonPhi = muonTrackRef->phi();
80 
81  double smallestDPt = 1e30;
82  unsigned int smallestDPtIter = 9999U;
83 
84  // -- iteration over tracks
85  for(auto i_trk=0U; i_trk<nTrack; ++i_trk) {
86  auto const & track = originalTracks[i_trk];
87 
88  double trackPt = track.pt();
89  double trackEta = track.eta();
90  double trackPhi = track.phi();
91 
92  if( deltaR(trackEta, trackPhi, muonEta, muonPhi) < 0.1 ) {
93  double dPt = fabs( trackPt - muonPt );
94 
95  if( dPt < smallestDPt ) {
96  smallestDPt = dPt;
97  smallestDPtIter = i_trk;
98  }
99  }
100  } // -- end of track iteration
101 
102  // -- if at least one track is matched
103  if( smallestDPtIter != 9999U ) {
104  selectedIter.push_back(smallestDPtIter);
105  if( flag_copyMVA ) selectedMVAVals->push_back( (*handle_originalMVAVals)[smallestDPtIter] );
106  ++nSelected;
107  }
108 
109  } // -- end of muon iteration
110 
111  assert( producer.selTracks_->empty() );
112 
113  // -- produces tracks and associated informations
114  producer( collectionClonerTokens, selectedIter );
115  assert( producer.selTracks_->size() == nSelected );
116 
117  if( flag_copyMVA )
118  iEvent.put(std::move(selectedMVAVals),"MVAValues");
119 }
120 
122 
const TrackCollectionCloner::Tokens collectionClonerTokens
const edm::EDGetTokenT< MVACollection > token_originalMVAVals
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
static void fill(edm::ParameterSetDescription &desc)
std::unique_ptr< reco::TrackCollection > selTracks_
static void fillDescriptions(edm::ConfigurationDescriptions &)
int iEvent
Definition: GenABIO.cc:230
Definition: Muon.py:1
ParameterDescriptionBase * add(U const &iLabel, T const &value)
HLTMuonTrackSelector(const edm::ParameterSet &)
reco::TrackCollection const & tracks(edm::Event &evt) const
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
const edm::EDGetTokenT< vector< reco::Muon > > token_muon
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
def move(src, dest)
Definition: eostools.py:510
TrackCollectionCloner collectionCloner
std::vector< float > MVACollection