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 
HLTObjectMonitor_cfi.muonPt
muonPt
Definition: HLTObjectMonitor_cfi.py:82
edm::StreamID
Definition: StreamID.h:30
electrons_cff.bool
bool
Definition: electrons_cff.py:366
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
Muon.h
TrackCollectionCloner::Producer
Definition: TrackCollectionCloner.h:52
HLTMuonTrackSelector::token_muon
const edm::EDGetTokenT< std::vector< reco::Muon > > token_muon
Definition: HLTMuonTrackSelector.h:45
HLTObjectMonitor_cfi.muonEta
muonEta
Definition: HLTObjectMonitor_cfi.py:92
muon
Definition: MuonCocktails.h:17
HLTMuonTrackSelector
Definition: HLTMuonTrackSelector.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
RawToDigi_Repacked_cff.producer
producer
Definition: RawToDigi_Repacked_cff.py:6
cms::cuda::assert
assert(be >=bs)
reco::btau::trackEta
Definition: TaggingVariable.h:42
HLTMuonTrackSelector::token_originalMVAVals
const edm::EDGetTokenT< MVACollection > token_originalMVAVals
Definition: HLTMuonTrackSelector.h:46
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
HLTMuonTrackSelector::collectionCloner
TrackCollectionCloner collectionCloner
Definition: HLTMuonTrackSelector.h:42
edm::Handle
Definition: AssociativeIterator.h:50
Muon
Definition: Muon.py:1
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
MakerMacros.h
HLTMuonTrackSelector::HLTMuonTrackSelector
HLTMuonTrackSelector(const edm::ParameterSet &)
Definition: HLTMuonTrackSelector.cc:21
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11725
MuonFwd.h
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
TrackCollectionCloner::fill
static void fill(edm::ParameterSetDescription &desc)
Definition: TrackCollectionCloner.cc:3
HLTMuonTrackSelector::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: HLTMuonTrackSelector.cc:32
funct::true
true
Definition: Factorize.h:173
edm::ParameterSet
Definition: ParameterSet.h:47
deltaR.h
TrackCollectionTokens::tracks
reco::TrackCollection const & tracks(edm::Event &evt) const
Definition: TrackCollectionTokens.h:26
reco::btau::trackPhi
Definition: TaggingVariable.h:43
HLTObjectMonitor_cfi.muonPhi
muonPhi
Definition: HLTObjectMonitor_cfi.py:102
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
HLTMuonTrackSelector::collectionClonerTokens
const TrackCollectionCloner::Tokens collectionClonerTokens
Definition: HLTMuonTrackSelector.h:43
packedPFCandidates_cfi.originalTracks
originalTracks
Definition: packedPFCandidates_cfi.py:7
HLTMuonTrackSelector::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: HLTMuonTrackSelector.cc:42
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HLTMuonTrackSelector.h
HLTMuonTrackSelector::MVACollection
std::vector< float > MVACollection
Definition: HLTMuonTrackSelector.h:35
HLTMuonTrackSelector::~HLTMuonTrackSelector
~HLTMuonTrackSelector() override
Definition: HLTMuonTrackSelector.cc:30
edm::Event
Definition: Event.h:73
listHistos.trackPt
trackPt
Definition: listHistos.py:120
edm::InputTag
Definition: InputTag.h:15
HLTMuonTrackSelector::flag_copyMVA
const bool flag_copyMVA
Definition: HLTMuonTrackSelector.h:47