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),
21  conf_(conf),
22  trackerHitAssociatorConfig_(conf,std::move(iC))
23 {
24  TrackerMuonHitExtractor hitExtractor(conf_,std::move(iC));
25 
26  //hack for consumes
27  RPCHitAssociator rpctruth(conf,std::move(iC));
28  GEMHitAssociator gemtruth(conf,std::move(iC));
29  DTHitAssociator dttruth(conf,std::move(iC));
30  CSCHitAssociator muonTruth(conf,std::move(iC));
31 }
32 
33 
35 {
36 }
37 
38 
39 
43  const edm::Event * event, const edm::EventSetup * setup) const {
44 
46  for (unsigned int j=0; j<tPCH->size();j++)
48 
49  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
50  for (size_t i = 0; i < tCH->size(); ++i)
51  muonBaseRefVector.push_back(tCH->refAt(i));
52 
53  associateMuons(recToSim, simToRec, muonBaseRefVector,type,tpc,event,setup);
54 }
55 
59  const edm::Event * event, const edm::EventSetup * setup) const {
60 
63  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from segments
64  switch (trackType) {
65  case InnerTk:
66  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
68  if (mur->track().isNonnull()) {
69  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
70  } else {
71  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
72  }
73  }
74  break;
75  case OuterTk:
76  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
78  if (mur->outerTrack().isNonnull()) {
79  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
80  } else {
81  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
82  }
83  }
84  break;
85  case GlobalTk:
86  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
88  if (mur->globalTrack().isNonnull()) {
89  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
90  } else {
91  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
92  }
93  }
94  break;
95  case Segments: {
96  TrackerMuonHitExtractor hitExtractor(conf_);
97  hitExtractor.init(*event, *setup);
98  // puts hits in the vector, and record indices
99  std::vector<std::pair<size_t, size_t> > muonHitIndices;
100  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
101  edm::RefToBase<reco::Muon> mur = *it;
102  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
103  if (mur->isTrackerMuon()) {
104  std::vector<const TrackingRecHit *> hits = hitExtractor.getMuonHits(*mur);
105  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh; ++ith) {
106  allTMRecHits.push_back(**ith);
107  }
108  indices.second += hits.size();
109  }
110  muonHitIndices.push_back(indices);
111  }
112  // convert indices into pairs of iterators to references
113  typedef std::pair<size_t, size_t> index_pair;
114  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
115  for (std::vector<std::pair<size_t, size_t> >::const_iterator idxs = muonHitIndices.begin(), idxend = muonHitIndices.end(); idxs != idxend; ++idxs) {
116  muonHitRefs.push_back(std::make_pair(hitRefBegin+idxs->first,
117  hitRefBegin+idxs->second));
118  }
119 
120  }
121  break;
122  }
123 
125  //Retrieve tracker topology from geometry
127  setup->get<TrackerTopologyRcd>().get(tTopoHand);
128  const TrackerTopology *tTopo=tTopoHand.product();
129 
130 
131  // Tracker hit association
133  // CSC hit association
134  CSCHitAssociator csctruth(*event,*setup,conf_);
135  // DT hit association
136  bool printRtS = true;
137  DTHitAssociator dttruth(*event,*setup,conf_,printRtS);
138  // RPC hit association
139  RPCHitAssociator rpctruth(*event,*setup,conf_);
140  // GEM hit association
141  GEMHitAssociator gemtruth(*event,*setup,conf_);
142 
143  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth};
144 
145  auto recSimColl = helper_.associateRecoToSimIndices(muonHitRefs,tPC,resources);
146  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
147  edm::RefToBase<reco::Muon> rec = muons[it->first];
148  std::vector<std::pair<TrackingParticleRef, double> > & tpAss = recToSim[rec];
149  for ( auto const & a : it->second) {
150  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
151  }
152  }
153  auto simRecColl = helper_.associateSimToRecoIndices(muonHitRefs,tPC,resources);
154  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
155  TrackingParticleRef sim = tPC[it->first];
156  std::vector<std::pair<edm::RefToBase<reco::Muon>, double> > & recAss = simToRec[sim];
157  for ( auto const & a: it->second ) {
158  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
159  }
160  }
161 
162 }
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:253
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:277
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
Definition: RunManager.h:28
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:62
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