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 //
21 // constants, enums and typedefs
22 //
23 
24 //
25 // static data member definitions
26 //
27 
28 //
29 // constructors and destructor
30 //
32  MuonAssociatorByHitsHelper::Resources const& iResources,
33  MuonAssociatorByHitsHelper const* iHelper):
34  m_hitExtractor(&iHitExtractor),
35  m_resources(iResources),
36  m_helper(iHelper)
37 {
38 }
39 
40 
41 //
42 // member functions
43 //
44 
45 //
46 // const member functions
47 //
48 void
50  reco::SimToMuonCollection & simToRec,
56  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from segments
57 
58  std::vector<edm::OwnVector<TrackingRecHit> > TMRecHits; // used for case GlbOrTrk
60 
61  switch (type) {
62 
63  case reco::InnerTk:
64  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
66  if (mur->track().isNonnull()) {
67  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
68  } else {
69  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
70  }
71  }
72  break;
73  case reco::OuterTk:
74  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
76  if (mur->outerTrack().isNonnull()) {
77  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
78  } else {
79  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
80  }
81  }
82  break;
83  case reco::GlobalTk:
84  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
86  if (mur->globalTrack().isNonnull()) {
87  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
88  } else {
89  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
90  }
91  }
92  break;
93  case reco::Segments: {
94  // puts hits in the vector, and record indices
95  std::vector<std::pair<size_t, size_t> > muonHitIndices;
96  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
98  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
99  if (mur->isTrackerMuon()) {
100  std::vector<const TrackingRecHit *> hits = m_hitExtractor->getMuonHits(*mur);
101  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh; ++ith) {
102  allTMRecHits.push_back(**ith);
103  }
104  indices.second += hits.size();
105  }
106  muonHitIndices.push_back(indices);
107  }
108  // convert indices into pairs of iterators to references
109  typedef std::pair<size_t, size_t> index_pair;
110  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
111  for (std::vector<std::pair<size_t, size_t> >::const_iterator idxs = muonHitIndices.begin(), idxend = muonHitIndices.end(); idxs != idxend; ++idxs) {
112  muonHitRefs.push_back(std::make_pair(hitRefBegin+idxs->first,
113  hitRefBegin+idxs->second));
114  }
115 
116  }
117  break;
118  case reco::GlbOrTrk: {
119  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
120  <<"\n"<<"There are "<<muons.size()<<" selected reco::Muons.";
121 
122  int isel = 0;
123  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
124  edm::RefToBase<reco::Muon> mur = *it;
125 
126  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
127  <<" #"<<isel<<", reco::Muon key = " <<mur.key()
128  <<", q*p = "<<mur->charge()*mur->p()<<", pT = "<<mur->pt()<<", eta = "<<mur->eta()<<", phi = "<<mur->phi();
129 
130  // Global muon with valid muon hits
131  if (mur->isGlobalMuon() && mur->globalTrack()->hitPattern().numberOfValidMuonHits()>0) {
132  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
133  <<"\t this is a Global Muon with valid muon hits";
134  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
135  }
136 
137  // Tracker Muon
138  else if (mur->isTrackerMuon()) {
139  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
140  <<"\t this is a Tracker Muon";
142 
143  std::vector<const TrackingRecHit *> hits = m_hitExtractor->getMuonHits(*mur);
144  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh; ++ith) {
145  TMvec.push_back(**ith);
146  }
147 
148  TMRecHits.push_back(TMvec);
149 
150  muonHitRefs.push_back(std::make_pair(TMRecHits.rbegin()->data().begin(), TMRecHits.rbegin()->data().end()));
151  }
152 
153  // Standalone muon or Global without valid muon hits
154  else if (mur->outerTrack().isNonnull()) {
155  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
156  <<"\t this is a Standalone muon";
157  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
158  }
159 
160  else {
161  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
162  <<"\t what muon is this ?";
163  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
164  <<"isMuon : "<<mur->isMuon()<<", isPFMuon : "<<mur->isPFMuon()<<", isTrackerMuon : "<<mur->isTrackerMuon()
165  <<", isStandAloneMuon : "<<mur->isStandAloneMuon()<<", isGlobalMuon : "<<mur->isGlobalMuon()
166  <<", isRPCMuon : "<<mur->isRPCMuon()<<", isGEMMuon : "<<mur->isGEMMuon()<<", isME0Muon : "<<mur->isME0Muon();
167  muonHitRefs.push_back(std::make_pair(noTM.data().end(), noTM.data().end()));
168  }
169 
170  isel++;
171  } // loop on muons
172 
173  }
174  break;
175  }
176 
178  auto recSimColl = m_helper->associateRecoToSimIndices(muonHitRefs,tPC, m_resources);
179  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
180  edm::RefToBase<reco::Muon> rec = muons[it->first];
181  std::vector<std::pair<TrackingParticleRef, double> > & tpAss = recToSim[rec];
182  for ( auto const & a : it->second) {
183  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
184  }
185  }
186  auto simRecColl = m_helper->associateSimToRecoIndices(muonHitRefs,tPC,m_resources);
187  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
188  TrackingParticleRef sim = tPC[it->first];
189  std::vector<std::pair<edm::RefToBase<reco::Muon>, double> > & recAss = simToRec[sim];
190  for ( auto const & a: it->second ) {
191  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
192  }
193  }
194 }
195 
196 void
198  reco::SimToMuonCollection & simToRec,
199  const edm::Handle<edm::View<reco::Muon> > & tCH,
201  const edm::Handle<TrackingParticleCollection>& tPCH) const {
202 
204  for (unsigned int j=0; j<tPCH->size();j++)
206 
207  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
208  for (size_t i = 0; i < tCH->size(); ++i)
209  muonBaseRefVector.push_back(tCH->refAt(i));
210 
211  associateMuons(recToSim, simToRec, muonBaseRefVector,type,tpc);
212 }
213 
214 //
215 // static member functions
216 //
type
Definition: HCALResponse.h:21
bool isMuon() const override
Definition: Muon.h:267
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
Definition: MuonTrackType.h:34
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
double eta() const final
momentum pseudorapidity
bool isStandAloneMuon() const override
Definition: Muon.h:270
ProductID id() const
Definition: HandleBase.cc:15
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
void associateMuons(reco::MuonToSimCollection &recoToSim, reco::SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &muons, reco::MuonTrackType type, const edm::RefVector< TrackingParticleCollection > &tpColl) const override
size_type size() const
Definition: OwnVector.h:264
const_iterator end() const
double pt() const final
transverse momentum
int charge() const final
electric charge
Definition: LeafCandidate.h:91
MuonToTrackingParticleAssociatorByHitsImpl(TrackerMuonHitExtractor const &iHitExtractor, MuonAssociatorByHitsHelper::Resources const &iResources, MuonAssociatorByHitsHelper const *iHelper)
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
bool isME0Muon() const
Definition: Muon.h:275
bool isTrackerMuon() const override
Definition: Muon.h:269
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
Definition: MuonTrackType.h:35
bool isRPCMuon() const
Definition: Muon.h:273
void push_back(D *&d)
Definition: OwnVector.h:290
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
bool isGlobalMuon() const override
Definition: Muon.h:268
size_t key() const
Definition: RefToBase.h:250
size_type size() const
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
Definition: RunManager.h:28
double p() const final
magnitude of momentum vector
bool isGEMMuon() const
Definition: Muon.h:274
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
base const & data() const
Definition: OwnVector.h:440
double a
Definition: hdecay.h:121
void push_back(const RefToBase< T > &)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:69
bool isPFMuon() const
Definition: Muon.h:272
MuonTrackType
Definition: MuonTrackType.h:27
double phi() const final
momentum azimuthal angle
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54