CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::RefToBaseVector< reco::Muon > &, MuonTrackType, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const override
 
void associateMuons (MuonToSimCollection &recoToSim, SimToMuonCollection &simToReco, const edm::Handle< edm::View< reco::Muon > > &, MuonTrackType, const edm::Handle< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const override
 
 MuonToSimAssociatorByHits (const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
 
 MuonToSimAssociatorByHits (const edm::ParameterSet &conf)
 
 ~MuonToSimAssociatorByHits ()
 
- Public Member Functions inherited from MuonToSimAssociatorBase
 MuonToSimAssociatorBase ()
 
virtual ~MuonToSimAssociatorBase ()
 

Private Attributes

edm::ParameterSet const conf_
 
MuonAssociatorByHitsHelper helper_
 

Additional Inherited Members

- Public Types inherited from MuonToSimAssociatorBase
typedef std::map
< edm::RefToBase< reco::Muon >
, std::vector< std::pair
< TrackingParticleRef, double >
>, RefToBaseSort
MuonToSimCollection
 
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 10 of file MuonToSimAssociatorByHits.h.

Constructor & Destructor Documentation

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

Definition at line 19 of file MuonToSimAssociatorByHits.cc.

References conf_.

19  :
20  helper_(conf),
21  conf_(conf)
22 {
23  TrackerMuonHitExtractor hitExtractor(conf_,std::move(iC));
24 
25  //hack for consumes
26  RPCHitAssociator rpctruth(conf,std::move(iC));
27  DTHitAssociator dttruth(conf,std::move(iC));
28  CSCHitAssociator muonTruth(conf,std::move(iC));
29  TrackerHitAssociator trackertruth(conf,std::move(iC));
30 }
MuonAssociatorByHitsHelper helper_
MuonToSimAssociatorByHits::MuonToSimAssociatorByHits ( const edm::ParameterSet conf)

Definition at line 33 of file MuonToSimAssociatorByHits.cc.

33  :
34  helper_(conf),
35  conf_(conf)
36 {}
MuonAssociatorByHitsHelper helper_
MuonToSimAssociatorByHits::~MuonToSimAssociatorByHits ( )

Definition at line 38 of file MuonToSimAssociatorByHits.cc.

39 {
40 }

Member Function Documentation

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

PART 1: Fill MuonToSimAssociatorByHits::TrackHitsCollection

PART 2: call the association routines

Implements MuonToSimAssociatorBase.

Definition at line 60 of file MuonToSimAssociatorByHits.cc.

References a, MuonAssociatorByHitsHelper::associateRecoToSimIndices(), MuonAssociatorByHitsHelper::associateSimToRecoIndices(), edm::RefToBaseVector< T >::begin(), conf_, edm::OwnVector< T, P >::data(), edm::RefToBaseVector< T >::end(), edm::EventSetup::get(), TrackerMuonHitExtractor::getMuonHits(), MuonToSimAssociatorBase::GlobalTk, reco::Muon::globalTrack(), helper_, TrackerMuonHitExtractor::init(), MuonToSimAssociatorBase::InnerTk, edm::Ref< C, T, F >::isNonnull(), reco::Muon::isTrackerMuon(), MuonToSimAssociatorBase::OuterTk, reco::Muon::outerTrack(), edm::ESHandle< class >::product(), edm::RefToBaseVector< T >::push_back(), edm::RefVector< C, T, F >::push_back(), edm::OwnVector< T, P >::push_back(), MuonToSimAssociatorBase::Segments, edm::OwnVector< T, P >::size(), and reco::Muon::track().

Referenced by associateMuons().

63  {
64 
67  edm::OwnVector<TrackingRecHit> allTMRecHits; // this I will fill in only for tracker muon hits from segments
68  switch (trackType) {
69  case InnerTk:
70  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
72  if (mur->track().isNonnull()) {
73  muonHitRefs.push_back(std::make_pair(mur->track()->recHitsBegin(), mur->track()->recHitsEnd()));
74  } else {
75  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
76  }
77  }
78  break;
79  case OuterTk:
80  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
82  if (mur->outerTrack().isNonnull()) {
83  muonHitRefs.push_back(std::make_pair(mur->outerTrack()->recHitsBegin(), mur->outerTrack()->recHitsEnd()));
84  } else {
85  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
86  }
87  }
88  break;
89  case GlobalTk:
90  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
92  if (mur->globalTrack().isNonnull()) {
93  muonHitRefs.push_back(std::make_pair(mur->globalTrack()->recHitsBegin(), mur->globalTrack()->recHitsEnd()));
94  } else {
95  muonHitRefs.push_back(std::make_pair(allTMRecHits.data().end(), allTMRecHits.data().end()));
96  }
97  }
98  break;
99  case Segments: {
100  TrackerMuonHitExtractor hitExtractor(conf_);
101  hitExtractor.init(*event, *setup);
102  // puts hits in the vector, and record indices
103  std::vector<std::pair<size_t, size_t> > muonHitIndices;
104  for (edm::RefToBaseVector<reco::Muon>::const_iterator it = muons.begin(), ed = muons.end(); it != ed; ++it) {
105  edm::RefToBase<reco::Muon> mur = *it;
106  std::pair<size_t, size_t> indices(allTMRecHits.size(), allTMRecHits.size());
107  if (mur->isTrackerMuon()) {
108  std::vector<const TrackingRecHit *> hits = hitExtractor.getMuonHits(*mur);
109  for (std::vector<const TrackingRecHit *>::const_iterator ith = hits.begin(), edh = hits.end(); ith != edh; ++ith) {
110  allTMRecHits.push_back(**ith);
111  }
112  indices.second += hits.size();
113  }
114  muonHitIndices.push_back(indices);
115  }
116  // convert indices into pairs of iterators to references
117  typedef std::pair<size_t, size_t> index_pair;
118  trackingRecHit_iterator hitRefBegin = allTMRecHits.data().begin();
119  for (std::vector<std::pair<size_t, size_t> >::const_iterator idxs = muonHitIndices.begin(), idxend = muonHitIndices.end(); idxs != idxend; ++idxs) {
120  muonHitRefs.push_back(std::make_pair(hitRefBegin+idxs->first,
121  hitRefBegin+idxs->second));
122  }
123 
124  }
125  break;
126  }
127 
129  //Retrieve tracker topology from geometry
131  setup->get<IdealGeometryRecord>().get(tTopoHand);
132  const TrackerTopology *tTopo=tTopoHand.product();
133 
134 
135  // Tracker hit association
136  TrackerHitAssociator trackertruth(*event, conf_);
137  // CSC hit association
138  CSCHitAssociator csctruth(*event,*setup,conf_);
139  // DT hit association
140  bool printRtS = true;
141  DTHitAssociator dttruth(*event,*setup,conf_,printRtS);
142  // RPC hit association
143  RPCHitAssociator rpctruth(*event,*setup,conf_);
144 
145  MuonAssociatorByHitsHelper::Resources resources = {tTopo, &trackertruth, &csctruth, &dttruth, &rpctruth};
146 
147  auto recSimColl = helper_.associateRecoToSimIndices(muonHitRefs,tPC,resources);
148  for (auto it = recSimColl.begin(), ed = recSimColl.end(); it != ed; ++it) {
149  edm::RefToBase<reco::Muon> rec = muons[it->first];
150  std::vector<std::pair<TrackingParticleRef, double> > & tpAss = recToSim[rec];
151  for ( auto const & a : it->second) {
152  tpAss.push_back(std::make_pair(tPC[a.idx], a.quality));
153  }
154  }
155  auto simRecColl = helper_.associateSimToRecoIndices(muonHitRefs,tPC,resources);
156  for (auto it = simRecColl.begin(), ed = simRecColl.end(); it != ed; ++it) {
157  TrackingParticleRef sim = tPC[it->first];
158  std::vector<std::pair<edm::RefToBase<reco::Muon>, double> > & recAss = simToRec[sim];
159  for ( auto const & a: it->second ) {
160  recAss.push_back(std::make_pair(muons[a.idx], a.quality));
161  }
162  }
163 
164 }
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
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
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
const_iterator begin() const
IndexAssociation associateRecoToSimIndices(const TrackHitsCollection &, const edm::RefVector< TrackingParticleCollection > &, Resources const &) const
base const & data() const
Definition: OwnVector.h:372
double a
Definition: hdecay.h:121
void push_back(const RefToBase< T > &)
MuonAssociatorByHitsHelper helper_
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
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
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 = 0,
const edm::EventSetup setup = 0 
) const
overridevirtual

Implements MuonToSimAssociatorBase.

Definition at line 44 of file MuonToSimAssociatorByHits.cc.

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

47  {
48 
50  for (unsigned int j=0; j<tPCH->size();j++)
52 
53  edm::RefToBaseVector<reco::Muon> muonBaseRefVector;
54  for (size_t i = 0; i < tCH->size(); ++i)
55  muonBaseRefVector.push_back(tCH->refAt(i));
56 
57  associateMuons(recToSim, simToRec, muonBaseRefVector,type,tpc,event,setup);
58 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
ProductID id() const
Definition: HandleBase.cc:15
int j
Definition: DBlmapReader.cc:9
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
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

Member Data Documentation

edm::ParameterSet const MuonToSimAssociatorByHits::conf_
private

Definition at line 33 of file MuonToSimAssociatorByHits.h.

Referenced by associateMuons(), and MuonToSimAssociatorByHits().

MuonAssociatorByHitsHelper MuonToSimAssociatorByHits::helper_
private

Definition at line 32 of file MuonToSimAssociatorByHits.h.

Referenced by associateMuons().