CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 //
21 // constants, enums and typedefs
22 //
23 
24 //
25 // static data member definitions
26 //
27 
28 //
29 // constructors and destructor
30 //
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  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; ++ith) {
97  allTMRecHits.push_back(**ith);
98  }
99  indices.second += hits.size();
100  }
101  muonHitIndices.push_back(indices);
102  }
103  // convert indices into pairs of iterators to references
104  typedef std::pair<size_t, size_t> index_pair;
105  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
106  for (std::vector<std::pair<size_t, size_t> >::const_iterator idxs = muonHitIndices.begin(), idxend = muonHitIndices.end(); idxs != idxend; ++idxs) {
107  muonHitRefs.push_back(std::make_pair(hitRefBegin+idxs->first,
108  hitRefBegin+idxs->second));
109  }
110 
111  }
112  break;
113  }
114 
116  auto recSimColl = m_helper->associateRecoToSimIndices(muonHitRefs,tPC, m_resources);
117  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
118  edm::RefToBase<reco::Muon> rec = muons[it->first];
119  std::vector<std::pair<TrackingParticleRef, double> > & tpAss = recToSim[rec];
120  for ( auto const & a : it->second) {
121  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
122  }
123  }
124  auto simRecColl = m_helper->associateSimToRecoIndices(muonHitRefs,tPC,m_resources);
125  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
126  TrackingParticleRef sim = tPC[it->first];
127  std::vector<std::pair<edm::RefToBase<reco::Muon>, double> > & recAss = simToRec[sim];
128  for ( auto const & a: it->second ) {
129  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
130  }
131  }
132 }
133 
134 void
136  reco::SimToMuonCollection & simToRec,
137  const edm::Handle<edm::View<reco::Muon> > & tCH,
139  const edm::Handle<TrackingParticleCollection>& tPCH) const {
140 
142  for (unsigned int j=0; j<tPCH->size();j++)
144 
145  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
146  for (size_t i = 0; i < tCH->size(); ++i)
147  muonBaseRefVector.push_back(tCH->refAt(i));
148 
149  associateMuons(recToSim, simToRec, muonBaseRefVector,type,tpc);
150 }
151 
152 //
153 // static member functions
154 //
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
Definition: MuonTrackType.h:34
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
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:15
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
bool isTrackerMuon() const
Definition: Muon.h:219
size_type size() const
Definition: OwnVector.h:254
const_iterator end() const
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:49
MuonToTrackingParticleAssociatorByHitsImpl(TrackerMuonHitExtractor const &iHitExtractor, MuonAssociatorByHitsHelper::Resources const &iResources, MuonAssociatorByHitsHelper const *iHelper)
Definition: sim.h:19
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
Definition: MuonTrackType.h:35
void push_back(D *&d)
Definition: OwnVector.h:280
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
int j
Definition: DBlmapReader.cc:9
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
base const & data() const
Definition: OwnVector.h:372
tuple muons
Definition: patZpeak.py:38
double a
Definition: hdecay.h:121
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:64
MuonTrackType
Definition: MuonTrackType.h:27
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54