CMS 3D CMS Logo

MuonToSimAssociatorByHits.cc
Go to the documentation of this file.
14 #include <sstream>
15 
16 using namespace reco;
17 using namespace std;
18 
20  : helper_(conf), conf_(conf), trackerHitAssociatorConfig_(conf, std::move(iC)) {
21  TrackerMuonHitExtractor hitExtractor(conf_, std::move(iC));
22 
23  // hack for consumes
24  RPCHitAssociator rpctruth(conf, std::move(iC));
25  GEMHitAssociator gemtruth(conf, std::move(iC));
26  DTHitAssociator dttruth(conf, std::move(iC));
27  CSCHitAssociator muonTruth(conf, std::move(iC));
28 }
29 
31 
33  SimToMuonCollection &simToRec,
37  const edm::Event *event,
38  const edm::EventSetup *setup) const {
40  for (unsigned int j = 0; j < tPCH->size(); j++)
42 
43  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
44  for (size_t i = 0; i < tCH->size(); ++i)
45  muonBaseRefVector.push_back(tCH->refAt(i));
46 
47  associateMuons(recToSim, simToRec, muonBaseRefVector, type, tpc, event, setup);
48 }
49 
51  SimToMuonCollection &simToRec,
55  const edm::Event *event,
56  const edm::EventSetup *setup) const {
59  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from
60  // segments
61  switch (trackType) {
62  case InnerTk:
63  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
65  if (mur->track().isNonnull()) {
66  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
67  } else {
68  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
69  }
70  }
71  break;
72  case OuterTk:
73  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
75  if (mur->outerTrack().isNonnull()) {
76  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
77  } else {
78  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
79  }
80  }
81  break;
82  case GlobalTk:
83  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
85  if (mur->globalTrack().isNonnull()) {
86  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
87  } else {
88  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
89  }
90  }
91  break;
92  case Segments: {
93  TrackerMuonHitExtractor hitExtractor(conf_);
94  hitExtractor.init(*event, *setup);
95  // puts hits in the vector, and record indices
96  std::vector<std::pair<size_t, size_t>> muonHitIndices;
97  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
99  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
100  if (mur->isTrackerMuon()) {
101  std::vector<const TrackingRecHit *> hits = hitExtractor.getMuonHits(*mur);
102  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh;
103  ++ith) {
104  allTMRecHits.push_back(**ith);
105  }
106  indices.second += hits.size();
107  }
108  muonHitIndices.push_back(indices);
109  }
110  // convert indices into pairs of iterators to references
111  typedef std::pair<size_t, size_t> index_pair;
112  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
113  for (std::vector<std::pair<size_t, size_t>>::const_iterator idxs = muonHitIndices.begin(),
114  idxend = muonHitIndices.end();
115  idxs != idxend;
116  ++idxs) {
117  muonHitRefs.push_back(std::make_pair(hitRefBegin + idxs->first, hitRefBegin + idxs->second));
118  }
119 
120  } break;
121  }
122 
124  // Retrieve tracker topology from geometry
126  setup->get<TrackerTopologyRcd>().get(tTopoHand);
127  const TrackerTopology *tTopo = tTopoHand.product();
128 
129  // Tracker hit association
131  // CSC hit association
132  CSCHitAssociator csctruth(*event, *setup, conf_);
133  // DT hit association
134  bool printRtS = true;
135  DTHitAssociator dttruth(*event, *setup, conf_, printRtS);
136  // RPC hit association
137  RPCHitAssociator rpctruth(*event, *setup, conf_);
138  // GEM hit association
139  GEMHitAssociator gemtruth(*event, *setup, conf_);
140 
141  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth};
142 
143  auto recSimColl = helper_.associateRecoToSimIndices(muonHitRefs, tPC, resources);
144  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
145  edm::RefToBase<reco::Muon> rec = muons[it->first];
146  std::vector<std::pair<TrackingParticleRef, double>> &tpAss = recToSim[rec];
147  for (auto const &a : it->second) {
148  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
149  }
150  }
151  auto simRecColl = helper_.associateSimToRecoIndices(muonHitRefs, tPC, resources);
152  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
153  TrackingParticleRef sim = tPC[it->first];
154  std::vector<std::pair<edm::RefToBase<reco::Muon>, double>> &recAss = simToRec[sim];
155  for (auto const &a : it->second) {
156  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
157  }
158  }
159 }
type
Definition: HCALResponse.h:21
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
ProductID id() const
Definition: HandleBase.cc:15
std::vector< const TrackingRecHit * > getMuonHits(const reco::Muon &mu) const
size_type size() const
Definition: OwnVector.h:264
const_iterator end() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
void associateMuons(MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &, MuonTrackType, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const override
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
bool isTrackerMuon() const override
Definition: Muon.h:292
void push_back(D *&d)
Definition: OwnVector.h:290
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
void init(const edm::Event &, const edm::EventSetup &)
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
fixed size matrix
base const & data() const
Definition: OwnVector.h:440
double a
Definition: hdecay.h:121
T get() const
Definition: EventSetup.h:71
MuonAssociatorByHitsHelper helper_
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
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:511
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: event.py:1
MuonToSimAssociatorByHits(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54