CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  DTHitAssociator dttruth(conf,std::move(iC));
29  CSCHitAssociator muonTruth(conf,std::move(iC));
30 }
31 
32 
34 {
35 }
36 
37 
38 
42  const edm::Event * event, const edm::EventSetup * setup) const {
43 
45  for (unsigned int j=0; j<tPCH->size();j++)
47 
48  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
49  for (size_t i = 0; i < tCH->size(); ++i)
50  muonBaseRefVector.push_back(tCH->refAt(i));
51 
52  associateMuons(recToSim, simToRec, muonBaseRefVector,type,tpc,event,setup);
53 }
54 
58  const edm::Event * event, const edm::EventSetup * setup) const {
59 
62  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from segments
63  switch (trackType) {
64  case InnerTk:
65  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
67  if (mur->track().isNonnull()) {
68  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
69  } else {
70  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
71  }
72  }
73  break;
74  case OuterTk:
75  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
77  if (mur->outerTrack().isNonnull()) {
78  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
79  } else {
80  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
81  }
82  }
83  break;
84  case GlobalTk:
85  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
87  if (mur->globalTrack().isNonnull()) {
88  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
89  } else {
90  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
91  }
92  }
93  break;
94  case Segments: {
95  TrackerMuonHitExtractor hitExtractor(conf_);
96  hitExtractor.init(*event, *setup);
97  // puts hits in the vector, and record indices
98  std::vector<std::pair<size_t, size_t> > muonHitIndices;
99  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
100  edm::RefToBase<reco::Muon> mur = *it;
101  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
102  if (mur->isTrackerMuon()) {
103  std::vector<const TrackingRecHit *> hits = hitExtractor.getMuonHits(*mur);
104  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh; ++ith) {
105  allTMRecHits.push_back(**ith);
106  }
107  indices.second += hits.size();
108  }
109  muonHitIndices.push_back(indices);
110  }
111  // convert indices into pairs of iterators to references
112  typedef std::pair<size_t, size_t> index_pair;
113  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
114  for (std::vector<std::pair<size_t, size_t> >::const_iterator idxs = muonHitIndices.begin(), idxend = muonHitIndices.end(); idxs != idxend; ++idxs) {
115  muonHitRefs.push_back(std::make_pair(hitRefBegin+idxs->first,
116  hitRefBegin+idxs->second));
117  }
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 
130  // Tracker hit association
132  // CSC hit association
133  CSCHitAssociator csctruth(*event,*setup,conf_);
134  // DT hit association
135  bool printRtS = true;
136  DTHitAssociator dttruth(*event,*setup,conf_,printRtS);
137  // RPC hit association
138  RPCHitAssociator rpctruth(*event,*setup,conf_);
139 
140  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth};
141 
142  auto recSimColl = helper_.associateRecoToSimIndices(muonHitRefs,tPC,resources);
143  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
144  edm::RefToBase<reco::Muon> rec = muons[it->first];
145  std::vector<std::pair<TrackingParticleRef, double> > & tpAss = recToSim[rec];
146  for ( auto const & a : it->second) {
147  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
148  }
149  }
150  auto simRecColl = helper_.associateSimToRecoIndices(muonHitRefs,tPC,resources);
151  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
152  TrackingParticleRef sim = tPC[it->first];
153  std::vector<std::pair<edm::RefToBase<reco::Muon>, double> > & recAss = simToRec[sim];
154  for ( auto const & a: it->second ) {
155  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
156  }
157  }
158 
159 }
type
Definition: HCALResponse.h:21
std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSort > MuonToSimCollection
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
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
Definition: sim.h:19
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
void push_back(D *&d)
Definition: OwnVector.h:280
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
int j
Definition: DBlmapReader.cc:9
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
tuple conf
Definition: dbtoconf.py:185
void init(const edm::Event &, const edm::EventSetup &)
std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
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
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
MuonAssociatorByHitsHelper helper_
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:62
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
TrackerHitAssociator::Config trackerHitAssociatorConfig_
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
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