CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  TrackerHitAssociator::Config const &iTracker,
33  CSCHitAssociator::Config const &iCSC,
34  DTHitAssociator::Config const &iDT,
35  RPCHitAssociator::Config const &iRPC,
36  GEMHitAssociator::Config const &iGEM,
37  edm::Event const &iEvent,
38  edm::EventSetup const &iSetup,
39  const TrackerTopology *iTopo,
40  std::function<void(const TrackHitsCollection &, const TrackingParticleCollection &)> iDiagnostics,
41  MuonAssociatorByHitsHelper const *iHelper)
42  : m_hitExtractor(&iHitExtractor),
43  m_tracker(iEvent, iTracker),
44  m_csc(iEvent, iSetup, iCSC),
45  m_dt(iEvent, iSetup, iDT, true),
46  m_rpc(iEvent, iRPC),
47  m_gem(iEvent, iGEM),
48  m_resources(iTopo, &m_tracker, &m_csc, &m_dt, &m_rpc, &m_gem, iDiagnostics),
49  m_helper(iHelper) {}
50 
51 //
52 // member functions
53 //
54 
55 //
56 // const member functions
57 //
59  reco::MuonToSimCollection &recToSim,
60  reco::SimToMuonCollection &simToRec,
66  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from
67  // segments
68 
69  std::vector<edm::OwnVector<TrackingRecHit>> TMRecHits; // used for case GlbOrTrk
71 
72  switch (type) {
73  case reco::InnerTk:
74  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
76  if (mur->track().isNonnull()) {
77  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
78  } else {
79  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
80  }
81  }
82  break;
83  case reco::OuterTk:
84  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
86  if (mur->outerTrack().isNonnull()) {
87  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
88  } else {
89  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
90  }
91  }
92  break;
93  case reco::GlobalTk:
94  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
96  if (mur->globalTrack().isNonnull()) {
97  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
98  } else {
99  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
100  }
101  }
102  break;
103  case reco::Segments: {
104  // puts hits in the vector, and record indices
105  std::vector<std::pair<size_t, size_t>> muonHitIndices;
106  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
107  edm::RefToBase<reco::Muon> mur = *it;
108  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
109  if (mur->isTrackerMuon()) {
110  std::vector<const TrackingRecHit *> hits = m_hitExtractor->getMuonHits(*mur);
111  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh;
112  ++ith) {
113  allTMRecHits.push_back(**ith);
114  }
115  indices.second += hits.size();
116  }
117  muonHitIndices.push_back(indices);
118  }
119  // convert indices into pairs of iterators to references
120  typedef std::pair<size_t, size_t> index_pair;
121  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
122  for (std::vector<std::pair<size_t, size_t>>::const_iterator idxs = muonHitIndices.begin(),
123  idxend = muonHitIndices.end();
124  idxs != idxend;
125  ++idxs) {
126  muonHitRefs.push_back(std::make_pair(hitRefBegin + idxs->first, hitRefBegin + idxs->second));
127  }
128 
129  } break;
130  case reco::GlbOrTrk: {
131  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
132  << "\n"
133  << "There are " << muons.size() << " selected reco::Muons.";
134 
135  int isel = 0;
136  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
137  edm::RefToBase<reco::Muon> mur = *it;
138 
139  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
140  << " #" << isel << ", reco::Muon key = " << mur.key() << ", q*p = " << mur->charge() * mur->p()
141  << ", pT = " << mur->pt() << ", eta = " << mur->eta() << ", phi = " << mur->phi();
142 
143  // Global muon with valid muon hits
144  if (mur->isGlobalMuon() && mur->globalTrack()->hitPattern().numberOfValidMuonHits() > 0) {
145  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
146  << "\t this is a Global Muon with valid muon hits";
147  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
148  }
149 
150  // Tracker Muon
151  else if (mur->isTrackerMuon()) {
152  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl") << "\t this is a Tracker Muon";
154 
155  std::vector<const TrackingRecHit *> hits = m_hitExtractor->getMuonHits(*mur);
156  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh;
157  ++ith) {
158  TMvec.push_back(**ith);
159  }
160 
161  TMRecHits.push_back(TMvec);
162 
163  muonHitRefs.push_back(std::make_pair(TMRecHits.rbegin()->data().begin(), TMRecHits.rbegin()->data().end()));
164  }
165 
166  // Standalone muon or Global without valid muon hits
167  else if (mur->outerTrack().isNonnull()) {
168  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl") << "\t this is a Standalone muon";
169  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
170  }
171 
172  else {
173  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl") << "\t what muon is this ?";
174  edm::LogVerbatim("MuonToTrackingParticleAssociatorByHitsImpl")
175  << "isMuon : " << mur->isMuon() << ", isPFMuon : " << mur->isPFMuon()
176  << ", isTrackerMuon : " << mur->isTrackerMuon() << ", isStandAloneMuon : " << mur->isStandAloneMuon()
177  << ", isGlobalMuon : " << mur->isGlobalMuon() << ", isRPCMuon : " << mur->isRPCMuon()
178  << ", isGEMMuon : " << mur->isGEMMuon() << ", isME0Muon : " << mur->isME0Muon();
179  muonHitRefs.push_back(std::make_pair(noTM.data().end(), noTM.data().end()));
180  }
181 
182  isel++;
183  } // loop on muons
184 
185  } break;
186  }
187 
189  auto recSimColl = m_helper->associateRecoToSimIndices(muonHitRefs, tPC, m_resources);
190  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
191  edm::RefToBase<reco::Muon> rec = muons[it->first];
192  std::vector<std::pair<TrackingParticleRef, double>> &tpAss = recToSim[rec];
193  for (auto const &a : it->second) {
194  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
195  }
196  }
197  auto simRecColl = m_helper->associateSimToRecoIndices(muonHitRefs, tPC, m_resources);
198  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
199  TrackingParticleRef sim = tPC[it->first];
200  std::vector<std::pair<edm::RefToBase<reco::Muon>, double>> &recAss = simToRec[sim];
201  for (auto const &a : it->second) {
202  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
203  }
204  }
205 }
206 
208  reco::MuonToSimCollection &recToSim,
209  reco::SimToMuonCollection &simToRec,
212  const edm::Handle<TrackingParticleCollection> &tPCH) const {
214  for (unsigned int j = 0; j < tPCH->size(); j++)
216 
217  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
218  for (size_t i = 0; i < tCH->size(); ++i)
219  muonBaseRefVector.push_back(tCH->refAt(i));
220 
221  associateMuons(recToSim, simToRec, muonBaseRefVector, type, tpc);
222 }
223 
224 //
225 // static member functions
226 //
Log< level::Info, true > LogVerbatim
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
Definition: MuonTrackType.h:37
bool isMuon() const override
Definition: Muon.h:300
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
double pt() const final
transverse momentum
void associateMuons(reco::MuonToSimCollection &recoToSim, reco::SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &muons, reco::MuonTrackType type, const edm::RefVector< TrackingParticleCollection > &tpColl) const override
ProductID id() const
Definition: HandleBase.cc:29
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
size_type size() const
Definition: OwnVector.h:300
const_iterator end() const
MuonToTrackingParticleAssociatorByHitsImpl(TrackerMuonHitExtractor const &iHitExtractor, TrackerHitAssociator::Config const &iTracker, CSCHitAssociator::Config const &iCSC, DTHitAssociator::Config const &iDT, RPCHitAssociator::Config const &iRPC, GEMHitAssociator::Config const &iGEM, edm::Event const &iEvent, edm::EventSetup const &iSetup, const TrackerTopology *iTopo, std::function< void(const TrackHitsCollection &, const TrackingParticleCollection &)>, MuonAssociatorByHitsHelper const *iHelper)
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
Definition: sim.h:19
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
bool isME0Muon() const
Definition: Muon.h:308
bool isTrackerMuon() const override
Definition: Muon.h:302
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
Definition: MuonTrackType.h:38
bool isRPCMuon() const
Definition: Muon.h:306
void push_back(D *&d)
Definition: OwnVector.h:326
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
int iEvent
Definition: GenABIO.cc:224
double p() const final
magnitude of momentum vector
size_t key() const
Definition: RefToBase.h:219
string function
Definition: callgraph.py:50
size_type size() const
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:48
MuonAssociatorByHitsHelper::TrackHitsCollection TrackHitsCollection
bool isGEMMuon() const
Definition: Muon.h:307
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
base const & data() const
Definition: OwnVector.h:476
tuple muons
Definition: patZpeak.py:41
double a
Definition: hdecay.h:119
void push_back(const RefToBase< T > &)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:67
bool isPFMuon() const
Definition: Muon.h:305
std::vector< TrackingParticle > TrackingParticleCollection
MuonTrackType
Definition: MuonTrackType.h:28
list indices
Definition: dqmdumpme.py:50
double phi() const final
momentum azimuthal angle
bool isGlobalMuon() const override
Definition: Muon.h:301
int charge() const final
electric charge
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:51
bool isStandAloneMuon() const override
Definition: Muon.h:303
double eta() const final
momentum pseudorapidity