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 
18 using namespace std;
19 using namespace reco;
20 
22  : collectionCloner(producesCollector(), iConfig, true),
23  collectionClonerTokens(iConfig.getParameter<edm::InputTag>("track"), consumesCollector()),
24  token_muon(consumes<vector<reco::Muon> >(iConfig.getParameter<edm::InputTag>("muon"))),
25  token_originalMVAVals(consumes<MVACollection>(iConfig.getParameter<edm::InputTag>("originalMVAVals"))),
26  flag_copyMVA(iConfig.getParameter<bool>("copyMVA")) {
27  produces<MVACollection>("MVAValues");
28 }
29 
31 
34  desc.add<edm::InputTag>("track", edm::InputTag());
35  desc.add<edm::InputTag>("muon", edm::InputTag());
36  desc.add<edm::InputTag>("originalMVAVals", edm::InputTag());
37  desc.add<bool>("copyMVA", false);
38  TrackCollectionCloner::fill(desc); // -- add copyExtras and copyTrajectories
39  descriptions.add("HLTMuonTrackSelector", desc);
40 }
41 
44 
45  // -- load tracks
47  auto nTrack = originalTracks.size();
48 
49  // -- load muons
50  edm::Handle<vector<reco::Muon> > handle_muon;
51  iEvent.getByToken(token_muon, handle_muon);
52  auto nMuon = handle_muon->size();
53 
54  // -- load MVA values if necessary
55  edm::Handle<MVACollection> handle_originalMVAVals;
56  if (flag_copyMVA) {
57  iEvent.getByToken(token_originalMVAVals, handle_originalMVAVals);
58  assert((*handle_originalMVAVals).size() == nTrack);
59  }
60 
61  // -- containers for selected track informations
62  std::vector<unsigned int> selectedIter;
63  auto selectedMVAVals = std::make_unique<MVACollection>();
64 
65  auto nSelected = 0U;
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)
106  selectedMVAVals->push_back((*handle_originalMVAVals)[smallestDPtIter]);
107  ++nSelected;
108  }
109 
110  } // -- end of muon iteration
111 
112  assert(producer.selTracks_->empty());
113 
114  // -- produces tracks and associated informations
115  producer(collectionClonerTokens, selectedIter);
116  assert(producer.selTracks_->size() == nSelected);
117 
118  if (flag_copyMVA)
119  iEvent.put(std::move(selectedMVAVals), "MVAValues");
120 }
121 
123 
const TrackCollectionCloner::Tokens collectionClonerTokens
const edm::EDGetTokenT< std::vector< reco::Muon > > token_muon
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fill(edm::ParameterSetDescription &desc)
assert(be >=bs)
static void fillDescriptions(edm::ConfigurationDescriptions &)
int iEvent
Definition: GenABIO.cc:224
const edm::EDGetTokenT< MVACollection > token_originalMVAVals
Definition: Muon.py:1
HLTMuonTrackSelector(const edm::ParameterSet &)
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.
reco::TrackCollection const & tracks(edm::Event &evt) const
def move(src, dest)
Definition: eostools.py:511
TrackCollectionCloner collectionCloner
std::vector< float > MVACollection