CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
MuonToSimAssociatorByHits Class Reference

#include <MuonToSimAssociatorByHits.h>

Inheritance diagram for MuonToSimAssociatorByHits:
MuonToSimAssociatorBase

Public Member Functions

void associateMuons (MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::Handle< edm::View< reco::Muon >> &, MuonTrackType, const edm::Handle< TrackingParticleCollection > &, const edm::Event *event=nullptr, const edm::EventSetup *setup=nullptr) const override
 
void associateMuons (MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &, MuonTrackType, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=nullptr, const edm::EventSetup *setup=nullptr) const override
 
 MuonToSimAssociatorByHits (const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
 
 ~MuonToSimAssociatorByHits () override
 
- Public Member Functions inherited from MuonToSimAssociatorBase
 MuonToSimAssociatorBase ()
 
virtual ~MuonToSimAssociatorBase ()
 

Private Attributes

const edm::ParameterSet conf_
 
MuonAssociatorByHitsHelper helper_
 
TrackerHitAssociator::Config trackerHitAssociatorConfig_
 

Additional Inherited Members

- Public Types inherited from MuonToSimAssociatorBase
typedef std::map< edm::RefToBase< reco::Muon >, std::vector< std::pair< TrackingParticleRef, double > >, RefToBaseSortMuonToSimCollection
 
enum  MuonTrackType { InnerTk, OuterTk, GlobalTk, Segments }
 
typedef std::map< TrackingParticleRef, std::vector< std::pair< edm::RefToBase< reco::Muon >, double > > > SimToMuonCollection
 

Detailed Description

Definition at line 11 of file MuonToSimAssociatorByHits.h.

Constructor & Destructor Documentation

◆ MuonToSimAssociatorByHits()

MuonToSimAssociatorByHits::MuonToSimAssociatorByHits ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  iC 
)

Definition at line 19 of file MuonToSimAssociatorByHits.cc.

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 }

References conf_, and eostools::move().

◆ ~MuonToSimAssociatorByHits()

MuonToSimAssociatorByHits::~MuonToSimAssociatorByHits ( )
override

Definition at line 30 of file MuonToSimAssociatorByHits.cc.

30 {}

Member Function Documentation

◆ associateMuons() [1/2]

void MuonToSimAssociatorByHits::associateMuons ( MuonToSimCollection recoToSim,
SimToMuonCollection simToReco,
const edm::Handle< edm::View< reco::Muon >> &  tCH,
MuonTrackType  type,
const edm::Handle< TrackingParticleCollection > &  tPCH,
const edm::Event event = nullptr,
const edm::EventSetup setup = nullptr 
) const
overridevirtual

Implements MuonToSimAssociatorBase.

Definition at line 32 of file MuonToSimAssociatorByHits.cc.

38  {
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 }

References associateMuons(), mps_fire::i, edm::HandleBase::id(), dqmiolumiharvest::j, edm::RefToBaseVector< T >::push_back(), edm::RefVector< C, T, F >::push_back(), and singleTopDQM_cfi::setup.

◆ associateMuons() [2/2]

void MuonToSimAssociatorByHits::associateMuons ( MuonToSimCollection recoToSim,
SimToMuonCollection simToReco,
const edm::RefToBaseVector< reco::Muon > &  muons,
MuonTrackType  trackType,
const edm::RefVector< TrackingParticleCollection > &  tPC,
const edm::Event event = nullptr,
const edm::EventSetup setup = nullptr 
) const
overridevirtual

PART 1: Fill MuonToSimAssociatorByHits::TrackHitsCollection

PART 2: call the association routines

Implements MuonToSimAssociatorBase.

Definition at line 50 of file MuonToSimAssociatorByHits.cc.

56  {
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 
142  tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth, &gemtruth, {}};
143 
144  auto recSimColl = helper_.associateRecoToSimIndices(muonHitRefs, tPC, resources);
145  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
146  edm::RefToBase<reco::Muon> rec = muons[it->first];
147  std::vector<std::pair<TrackingParticleRef, double>> &tpAss = recToSim[rec];
148  for (auto const &a : it->second) {
149  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
150  }
151  }
152  auto simRecColl = helper_.associateSimToRecoIndices(muonHitRefs, tPC, resources);
153  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
154  TrackingParticleRef sim = tPC[it->first];
155  std::vector<std::pair<edm::RefToBase<reco::Muon>, double>> &recAss = simToRec[sim];
156  for (auto const &a : it->second) {
157  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
158  }
159  }
160 }

References a, MuonAssociatorByHitsHelper::associateRecoToSimIndices(), MuonAssociatorByHitsHelper::associateSimToRecoIndices(), conf_, edm::OwnVector< T, P >::data(), get, TrackerMuonHitExtractor::getMuonHits(), MuonToSimAssociatorBase::GlobalTk, reco::Muon::globalTrack(), helper_, hfClusterShapes_cfi::hits, bTagCombinedSVVariables_cff::indices, TrackerMuonHitExtractor::init(), MuonToSimAssociatorBase::InnerTk, edm::Ref< C, T, F >::isNonnull(), reco::Muon::isTrackerMuon(), PDWG_BPHSkim_cff::muons, MuonToSimAssociatorBase::OuterTk, reco::Muon::outerTrack(), edm::ESHandle< T >::product(), edm::RefVector< C, T, F >::push_back(), edm::OwnVector< T, P >::push_back(), mps_fire::resources, MuonToSimAssociatorBase::Segments, singleTopDQM_cfi::setup, particleFlowSimParticle_cfi::sim, edm::OwnVector< T, P >::size(), reco::Muon::track(), trackerHitAssociatorConfig_, PbPb_ZMuSkimMuonDPG_cff::trackType, and trackerHitRTTI::vector.

Referenced by associateMuons().

Member Data Documentation

◆ conf_

const edm::ParameterSet MuonToSimAssociatorByHits::conf_
private

Definition at line 34 of file MuonToSimAssociatorByHits.h.

Referenced by associateMuons(), and MuonToSimAssociatorByHits().

◆ helper_

MuonAssociatorByHitsHelper MuonToSimAssociatorByHits::helper_
private

Definition at line 33 of file MuonToSimAssociatorByHits.h.

Referenced by associateMuons().

◆ trackerHitAssociatorConfig_

TrackerHitAssociator::Config MuonToSimAssociatorByHits::trackerHitAssociatorConfig_
private

Definition at line 35 of file MuonToSimAssociatorByHits.h.

Referenced by associateMuons().

bTagCombinedSVVariables_cff.indices
indices
Definition: bTagCombinedSVVariables_cff.py:67
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
mps_fire.i
i
Definition: mps_fire.py:428
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
MuonToSimAssociatorBase::GlobalTk
Definition: MuonToSimAssociatorBase.h:20
TrackerTopology
Definition: TrackerTopology.h:16
edm::RefVector< TrackingParticleCollection >
MuonAssociatorByHitsHelper::TrackHitsCollection
std::vector< std::pair< trackingRecHit_iterator, trackingRecHit_iterator > > TrackHitsCollection
Definition: MuonAssociatorByHitsHelper.h:34
MuonToSimAssociatorBase::Segments
Definition: MuonToSimAssociatorBase.h:20
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::Ref< TrackingParticleCollection >
DTHitAssociator
Definition: DTHitAssociator.h:22
edm::RefToBaseVector::push_back
void push_back(const RefToBase< T > &)
Definition: RefToBaseVector.h:217
MuonToSimAssociatorByHits::associateMuons
void associateMuons(MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::RefToBaseVector< reco::Muon > &, MuonTrackType, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=nullptr, const edm::EventSetup *setup=nullptr) const override
Definition: MuonToSimAssociatorByHits.cc:50
MuonAssociatorByHitsHelper::associateSimToRecoIndices
IndexAssociation associateSimToRecoIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
Definition: MuonAssociatorByHitsHelper.cc:406
MuonToSimAssociatorByHits::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: MuonToSimAssociatorByHits.h:35
reco::Muon::outerTrack
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:48
edm::ESHandle< TrackerTopology >
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
edm::OwnVector::const_iterator
Definition: OwnVector.h:41
MuonToSimAssociatorByHits::conf_
const edm::ParameterSet conf_
Definition: MuonToSimAssociatorByHits.h:34
particleFlowSimParticle_cfi.sim
sim
Definition: particleFlowSimParticle_cfi.py:21
a
double a
Definition: hdecay.h:119
reco::Muon::globalTrack
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:51
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
sim
Definition: GeometryProducer.h:20
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
get
#define get
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::RefToBaseVector
Definition: EDProductfwd.h:29
PbPb_ZMuSkimMuonDPG_cff.trackType
trackType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:36
MuonAssociatorByHitsHelper::Resources
Definition: MuonAssociatorByHitsHelper.h:38
reco::Muon::track
TrackRef track() const override
reference to a Track
Definition: Muon.h:46
TrackerHitAssociator
Definition: TrackerHitAssociator.h:55
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::Muon::isTrackerMuon
bool isTrackerMuon() const override
Definition: Muon.h:300
MuonToSimAssociatorByHits::helper_
MuonAssociatorByHitsHelper helper_
Definition: MuonToSimAssociatorByHits.h:33
edm::OwnVector::data
base const & data() const
Definition: OwnVector.h:476
RPCHitAssociator
Definition: RPCHitAssociator.h:32
MuonAssociatorByHitsHelper::associateRecoToSimIndices
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
Definition: MuonAssociatorByHitsHelper.cc:65
mps_fire.resources
resources
Definition: mps_fire.py:263
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
TrackerMuonHitExtractor
Definition: TrackerMuonHitExtractor.h:18
MuonToSimAssociatorBase::InnerTk
Definition: MuonToSimAssociatorBase.h:20
CSCHitAssociator
Definition: CSCHitAssociator.h:24
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
MuonToSimAssociatorBase::OuterTk
Definition: MuonToSimAssociatorBase.h:20
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
event
Definition: event.py:1
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:29
edm::OwnVector< TrackingRecHit >
GEMHitAssociator
Definition: GEMHitAssociator.h:33