CMS 3D CMS Logo

MuonToTrackingParticleAssociatorByHitsImpl.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimMuon/MCTruth
4 // Class : MuonToTrackingParticleAssociatorByHitsImpl
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Christopher Jones
10 // Created: Wed, 07 Jan 2015 21:35:56 GMT
11 //
12 
13 // system include files
14 
15 // user include files
18 
19 //
20 // constants, enums and typedefs
21 //
22 
23 //
24 // static data member definitions
25 //
26 
27 //
28 // constructors and destructor
29 //
31  TrackerMuonHitExtractor const &iHitExtractor,
32  MuonAssociatorByHitsHelper::Resources const &iResources,
33  MuonAssociatorByHitsHelper const *iHelper)
34  : m_hitExtractor(&iHitExtractor), m_resources(iResources), m_helper(iHelper) {}
35 
36 //
37 // member functions
38 //
39 
40 //
41 // const member functions
42 //
44  reco::MuonToSimCollection &recToSim,
45  reco::SimToMuonCollection &simToRec,
51  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from
52  // segments
53 
54  std::vector<edm::OwnVector<TrackingRecHit>> TMRecHits; // used for case GlbOrTrk
56 
57  switch (type) {
58  case reco::InnerTk:
59  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
61  if (mur->track().isNonnull()) {
62  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
63  } else {
64  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
65  }
66  }
67  break;
68  case reco::OuterTk:
69  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
71  if (mur->outerTrack().isNonnull()) {
72  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
73  } else {
74  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
75  }
76  }
77  break;
78  case reco::GlobalTk:
79  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
81  if (mur->globalTrack().isNonnull()) {
82  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
83  } else {
84  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
85  }
86  }
87  break;
88  case reco::Segments: {
89  // puts hits in the vector, and record indices
90  std::vector<std::pair<size_t, size_t>> muonHitIndices;
91  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
93  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
94  if (mur->isTrackerMuon()) {
95  std::vector<const TrackingRecHit *> hits = m_hitExtractor->getMuonHits(*mur);
96  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh;
97  ++ith) {
98  allTMRecHits.push_back(**ith);
99  }
100  indices.second += hits.size();
101  }
102  muonHitIndices.push_back(indices);
103  }
104  // convert indices into pairs of iterators to references
105  typedef std::pair<size_t, size_t> index_pair;
106  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
107  for (std::vector<std::pair<size_t, size_t>>::const_iterator idxs = muonHitIndices.begin(),
108  idxend = muonHitIndices.end();
109  idxs != idxend;
110  ++idxs) {
111  muonHitRefs.push_back(std::make_pair(hitRefBegin + idxs->first, hitRefBegin + idxs->second));
112  }
113 
114  } break;
115  case reco::GlbOrTrk: {
116  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
117  << "\n"
118  << "There are " << muons.size() << " selected reco::Muons.";
119 
120  int isel = 0;
121  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
122  edm::RefToBase<reco::Muon> mur = *it;
123 
124  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
125  << " #" << isel << ", reco::Muon key = " << mur.key() << ", q*p = " << mur->charge() * mur->p()
126  << ", pT = " << mur->pt() << ", eta = " << mur->eta() << ", phi = " << mur->phi();
127 
128  // Global muon with valid muon hits
129  if (mur->isGlobalMuon() && mur->globalTrack()->hitPattern().numberOfValidMuonHits() > 0) {
130  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
131  << "\t this is a Global Muon with valid muon hits";
132  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
133  }
134 
135  // Tracker Muon
136  else if (mur->isTrackerMuon()) {
137  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl") << "\t this is a Tracker Muon";
139 
140  std::vector<const TrackingRecHit *> hits = m_hitExtractor->getMuonHits(*mur);
141  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh;
142  ++ith) {
143  TMvec.push_back(**ith);
144  }
145 
146  TMRecHits.push_back(TMvec);
147 
148  muonHitRefs.push_back(std::make_pair(TMRecHits.rbegin()->data().begin(), TMRecHits.rbegin()->data().end()));
149  }
150 
151  // Standalone muon or Global without valid muon hits
152  else if (mur->outerTrack().isNonnull()) {
153  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl") << "\t this is a Standalone muon";
154  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
155  }
156 
157  else {
158  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl") << "\t what muon is this ?";
159  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
160  << "isMuon : " << mur->isMuon() << ", isPFMuon : " << mur->isPFMuon()
161  << ", isTrackerMuon : " << mur->isTrackerMuon() << ", isStandAloneMuon : " << mur->isStandAloneMuon()
162  << ", isGlobalMuon : " << mur->isGlobalMuon() << ", isRPCMuon : " << mur->isRPCMuon()
163  << ", isGEMMuon : " << mur->isGEMMuon() << ", isME0Muon : " << mur->isME0Muon();
164  muonHitRefs.push_back(std::make_pair(noTM.data().end(), noTM.data().end()));
165  }
166 
167  isel++;
168  } // loop on muons
169 
170  } break;
171  }
172 
174  auto recSimColl = m_helper->associateRecoToSimIndices(muonHitRefs, tPC, m_resources);
175  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
176  edm::RefToBase<reco::Muon> rec = muons[it->first];
177  std::vector<std::pair<TrackingParticleRef, double>> &tpAss = recToSim[rec];
178  for (auto const &a : it->second) {
179  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
180  }
181  }
182  auto simRecColl = m_helper->associateSimToRecoIndices(muonHitRefs, tPC, m_resources);
183  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
184  TrackingParticleRef sim = tPC[it->first];
185  std::vector<std::pair<edm::RefToBase<reco::Muon>, double>> &recAss = simToRec[sim];
186  for (auto const &a : it->second) {
187  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
188  }
189  }
190 }
191 
193  reco::MuonToSimCollection &recToSim,
194  reco::SimToMuonCollection &simToRec,
197  const edm::Handle<TrackingParticleCollection> &tPCH) const {
199  for (unsigned int j = 0; j < tPCH->size(); j++)
201 
202  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
203  for (size_t i = 0; i < tCH->size(); ++i)
204  muonBaseRefVector.push_back(tCH->refAt(i));
205 
206  associateMuons(recToSim, simToRec, muonBaseRefVector, type, tpc);
207 }
208 
209 //
210 // static member functions
211 //
bTagCombinedSVVariables_cff.indices
indices
Definition: bTagCombinedSVVariables_cff.py:67
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
mps_fire.i
i
Definition: mps_fire.py:428
TrackerMuonHitExtractor.h
reco::Muon::isGEMMuon
bool isGEMMuon() const
Definition: Muon.h:305
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::RefToBase::key
size_t key() const
Definition: RefToBase.h:219
reco::Muon::isRPCMuon
bool isRPCMuon() const
Definition: Muon.h:304
reco::MuonToSimCollection
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
Definition: MuonTrackType.h:37
MuonToTrackingParticleAssociatorByHitsImpl::m_helper
const MuonAssociatorByHitsHelper * m_helper
Definition: MuonToTrackingParticleAssociatorByHitsImpl.h:65
reco::OuterTk
Definition: MuonTrackType.h:28
MuonToTrackingParticleAssociatorByHitsImpl::m_hitExtractor
const TrackerMuonHitExtractor * m_hitExtractor
Definition: MuonToTrackingParticleAssociatorByHitsImpl.h:63
reco::Muon::isME0Muon
bool isME0Muon() const
Definition: Muon.h:306
reco::InnerTk
Definition: MuonTrackType.h:28
edm::RefVector< TrackingParticleCollection >
MuonAssociatorByHitsHelper::TrackHitsCollection
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
Definition: MuonAssociatorByHitsHelper.h:34
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
reco::Muon::isMuon
bool isMuon() const override
Definition: Muon.h:298
edm::Handle
Definition: AssociativeIterator.h:50
TrackerMuonHitExtractor::getMuonHits
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
Definition: TrackerMuonHitExtractor.cc:100
edm::Ref< TrackingParticleCollection >
MuonToTrackingParticleAssociatorByHitsImpl::associateMuons
void associateMuons(reco::MuonToSimCollection &recoToSim, reco::SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &muons, reco::MuonTrackType type, const edm::RefVector< TrackingParticleCollection > &tpColl) const override
Definition: MuonToTrackingParticleAssociatorByHitsImpl.cc:43
edm::RefToBaseVector::push_back
void push_back(const RefToBase< T > &)
Definition: RefToBaseVector.h:217
MuonAssociatorByHitsHelper::associateSimToRecoIndices
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
Definition: MuonAssociatorByHitsHelper.cc:406
reco::Muon::outerTrack
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:48
reco::SimToMuonCollection
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
Definition: MuonTrackType.h:38
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
reco::GlbOrTrk
Definition: MuonTrackType.h:28
reco::GlobalTk
Definition: MuonTrackType.h:28
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
reco::Muon::isGlobalMuon
bool isGlobalMuon() const override
Definition: Muon.h:299
edm::View
Definition: CaloClusterFwd.h:14
particleFlowSimParticle_cfi.sim
sim
Definition: particleFlowSimParticle_cfi.py:21
MuonAssociatorByHitsHelper
Definition: MuonAssociatorByHitsHelper.h:28
a
double a
Definition: hdecay.h:119
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
reco::Muon::globalTrack
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:51
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
sim
Definition: GeometryProducer.h:20
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
reco::LeafCandidate::charge
int charge() const final
electric charge
Definition: LeafCandidate.h:106
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::RefToBaseVector
Definition: EDProductfwd.h:29
MuonAssociatorByHitsHelper::Resources
Definition: MuonAssociatorByHitsHelper.h:38
reco::Muon::isPFMuon
bool isPFMuon() const
Definition: Muon.h:303
MuonToTrackingParticleAssociatorByHitsImpl::m_resources
MuonAssociatorByHitsHelper::Resources m_resources
Definition: MuonToTrackingParticleAssociatorByHitsImpl.h:64
reco::Muon::track
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
reco::Muon::isTrackerMuon
bool isTrackerMuon() const override
Definition: Muon.h:300
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
edm::OwnVector::data
base const & data() const
Definition: OwnVector.h:476
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
MuonAssociatorByHitsHelper::associateRecoToSimIndices
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
Definition: MuonAssociatorByHitsHelper.cc:65
reco::LeafCandidate::p
double p() const final
magnitude of momentum vector
Definition: LeafCandidate.h:123
edm::RefToBase
Definition: AssociativeIterator.h:54
reco::Muon::isStandAloneMuon
bool isStandAloneMuon() const override
Definition: Muon.h:301
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
MuonToTrackingParticleAssociatorByHitsImpl.h
TrackerMuonHitExtractor
Definition: TrackerMuonHitExtractor.h:18
MuonToTrackingParticleAssociatorByHitsImpl::MuonToTrackingParticleAssociatorByHitsImpl
MuonToTrackingParticleAssociatorByHitsImpl(TrackerMuonHitExtractor const &iHitExtractor, MuonAssociatorByHitsHelper::Resources const &iResources, MuonAssociatorByHitsHelper const *iHelper)
Definition: MuonToTrackingParticleAssociatorByHitsImpl.cc:30
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:29
reco::Segments
Definition: MuonTrackType.h:28
reco::MuonTrackType
MuonTrackType
Definition: MuonTrackType.h:28
edm::OwnVector< TrackingRecHit >