CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
MuonSimHitMatcher Class Reference

#include <MuonSimHitMatcher.h>

Inheritance diagram for MuonSimHitMatcher:
CSCSimHitMatcher DTSimHitMatcher GEMSimHitMatcher ME0SimHitMatcher RPCSimHitMatcher

Public Member Functions

std::set< unsigned int > chamberIds (int type=0) const
 
std::set< unsigned int > detIds (int type=0) const
 
const edm::PSimHitContainerhitsInChamber (unsigned int) const
 
const edm::PSimHitContainerhitsInDetId (unsigned int) const
 
void init (const edm::Event &e, const edm::EventSetup &eventSetup)
 initialize the event More...
 
void match (const SimTrack &t, const SimVertex &v)
 do the matching More...
 
 MuonSimHitMatcher (const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
 
const edm::PSimHitContainersimHits (int) const
 
GlobalVector simHitsMeanMomentum (const edm::PSimHitContainer &sim_hits) const
 
GlobalPoint simHitsMeanPosition (const edm::PSimHitContainer &sim_hits) const
 
GlobalPoint simHitsMeanPositionStation (int n) const
 
 ~MuonSimHitMatcher ()
 

Protected Member Functions

std::vector< unsigned int > getIdsOfSimTrackShower (unsigned trk_id, const edm::SimTrackContainer &simTracks, const edm::SimVertexContainer &simVertices)
 

Protected Attributes

std::map< unsigned int, edm::PSimHitContainerchamber_to_hits_
 
std::map< unsigned int, edm::PSimHitContainerdetid_to_hits_
 
bool discardEleHits_
 
const TrackingGeometrygeometry_
 
bool hasGeometry_
 
edm::PSimHitContainer hits_
 
edm::PSimHitContainer no_hits_
 
edm::EDGetTokenT< edm::PSimHitContainersimHitInput_
 
edm::ParameterSet simHitPSet_
 
edm::PSimHitContainer simHits_
 
edm::Handle< edm::PSimHitContainersimHitsH_
 
bool simMuOnly_
 
edm::EDGetTokenT< edm::SimTrackContainersimTrackInput_
 
edm::SimTrackContainer simTracks_
 
edm::Handle< edm::SimTrackContainersimTracksH_
 
edm::EDGetTokenT< edm::SimVertexContainersimVertexInput_
 
edm::SimVertexContainer simVertices_
 
edm::Handle< edm::SimVertexContainersimVerticesH_
 
std::vector< unsigned > track_ids_
 
std::map< unsigned int, unsigned int > trkid_to_index_
 
bool verbose_
 
bool verboseSimTrack_
 

Detailed Description

Description: Matching of muon SimHit to SimTrack

Author: Sven Dildick (TAMU), Tao Huang (TAMU)

Definition at line 33 of file MuonSimHitMatcher.h.

Constructor & Destructor Documentation

MuonSimHitMatcher::MuonSimHitMatcher ( const edm::ParameterSet iPS,
edm::ConsumesCollector &&  iC 
)

Definition at line 7 of file MuonSimHitMatcher.cc.

References edm::ParameterSet::getParameterSet(), muonSimHitMatcherPSet::simTrack, and ecalDetailedTimeRecHit_cfi::simVertex.

8  {
9  const auto& simVertex = ps.getParameterSet("simVertex");
10  const auto& simTrack = ps.getParameterSet("simTrack");
11  verboseSimTrack_ = simTrack.getParameter<int>("verbose");
12 
14  simVertex.getParameter<edm::InputTag>("inputTag"));
16  simTrack.getParameter<edm::InputTag>("inputTag"));
17 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< edm::SimVertexContainer > simVertexInput_
std::vector< SimVertex > SimVertexContainer
edm::EDGetTokenT< edm::SimTrackContainer > simTrackInput_
std::vector< SimTrack > SimTrackContainer
MuonSimHitMatcher::~MuonSimHitMatcher ( )
inline

Member Function Documentation

std::set<unsigned int> MuonSimHitMatcher::chamberIds ( int  type = 0) const

Referenced by ~MuonSimHitMatcher().

std::set<unsigned int> MuonSimHitMatcher::detIds ( int  type = 0) const

Referenced by ~MuonSimHitMatcher().

std::vector< unsigned int > MuonSimHitMatcher::getIdsOfSimTrackShower ( unsigned  trk_id,
const edm::SimTrackContainer simTracks,
const edm::SimVertexContainer simVertices 
)
protected

Definition at line 51 of file MuonSimHitMatcher.cc.

References TrackValidation_cff::association, SimTrack::noVertex(), mps_fire::result, protons_cff::t, and SimTrack::vertIndex().

Referenced by ~MuonSimHitMatcher().

53  {
54  vector<unsigned int> result;
55  result.push_back(initial_trk_id);
56 
57  if (!simMuOnly_) return result;
58 
59  for (const auto& t : simTracks_) {
60  SimTrack last_trk = t;
61  // if (std::abs(t.type()) != 13) continue;
62  bool is_child = false;
63  while (true) {
64  if (last_trk.noVertex()) break;
65  if (simVertices_[last_trk.vertIndex()].noParent()) break;
66 
67  unsigned parentId = simVertices_[last_trk.vertIndex()].parentIndex();
68  if (parentId == initial_trk_id) {
69  is_child = true;
70  break;
71  }
72 
73  const auto& association = trkid_to_index_.find(parentId);
74  if (association == trkid_to_index_.end()) break;
75 
76  last_trk = simTracks_[association->second];
77  }
78  if (is_child) {
79  result.push_back(t.trackId());
80  }
81  }
82  return result;
83 }
edm::SimTrackContainer simTracks_
edm::SimVertexContainer simVertices_
bool noVertex() const
Definition: SimTrack.h:31
std::map< unsigned int, unsigned int > trkid_to_index_
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:30
const edm::PSimHitContainer & MuonSimHitMatcher::hitsInChamber ( unsigned int  detid) const

Definition at line 95 of file MuonSimHitMatcher.cc.

Referenced by ME0SimHitMatcher::match(), RPCSimHitMatcher::match(), CSCSimHitMatcher::nLayersWithHitsInChamber(), DTSimHitMatcher::nSuperLayersWithHitsInChamber(), and ~MuonSimHitMatcher().

96  {
97  if (chamber_to_hits_.find(detid) == chamber_to_hits_.end()) return no_hits_;
98  return chamber_to_hits_.at(detid);
99 }
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
edm::PSimHitContainer no_hits_
const edm::PSimHitContainer & MuonSimHitMatcher::hitsInDetId ( unsigned int  detid) const
void MuonSimHitMatcher::init ( const edm::Event e,
const edm::EventSetup eventSetup 
)

initialize the event

Definition at line 20 of file MuonSimHitMatcher.cc.

References edm::Event::getByToken().

Referenced by CSCSimHitMatcher::init(), RPCSimHitMatcher::init(), ME0SimHitMatcher::init(), GEMSimHitMatcher::init(), DTSimHitMatcher::init(), and ~MuonSimHitMatcher().

21  {
22  hasGeometry_ = true;
23 
24  iEvent.getByToken(simTrackInput_, simTracksH_);
26  iEvent.getByToken(simHitInput_, simHitsH_);
27 }
edm::Handle< edm::SimVertexContainer > simVerticesH_
edm::EDGetTokenT< edm::SimVertexContainer > simVertexInput_
int iEvent
Definition: GenABIO.cc:224
edm::Handle< edm::PSimHitContainer > simHitsH_
edm::Handle< edm::SimTrackContainer > simTracksH_
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
edm::EDGetTokenT< edm::SimTrackContainer > simTrackInput_
void MuonSimHitMatcher::match ( const SimTrack t,
const SimVertex v 
)

do the matching

Definition at line 30 of file MuonSimHitMatcher.cc.

References protons_cff::t, and CoreSimTrack::trackId().

Referenced by CSCSimHitMatcher::match(), RPCSimHitMatcher::match(), ME0SimHitMatcher::match(), GEMSimHitMatcher::match(), DTSimHitMatcher::match(), and ~MuonSimHitMatcher().

30  {
34 
35  // fill trkId2Index association:
36  int no = 0;
37  trkid_to_index_.clear();
38  for (const auto& t : simTracks_) {
39  trkid_to_index_[t.trackId()] = no;
40  no++;
41  }
42 
43  track_ids_ =
45  if (verboseSimTrack_) {
46  edm::LogInfo("MuonSimHitMatcher") << "Printing track_ids" << std::endl;
47  for (const auto& id : track_ids_) edm::LogInfo("MuonSimHitMatcher") << "id: " << id << std::endl;
48  }
49 }
edm::SimTrackContainer simTracks_
edm::Handle< edm::SimVertexContainer > simVerticesH_
std::vector< unsigned > track_ids_
edm::PSimHitContainer simHits_
edm::SimVertexContainer simVertices_
std::map< unsigned int, unsigned int > trkid_to_index_
unsigned int trackId() const
Definition: CoreSimTrack.h:31
T const * product() const
Definition: Handle.h:74
edm::Handle< edm::PSimHitContainer > simHitsH_
edm::Handle< edm::SimTrackContainer > simTracksH_
std::vector< unsigned int > getIdsOfSimTrackShower(unsigned trk_id, const edm::SimTrackContainer &simTracks, const edm::SimVertexContainer &simVertices)
const edm::PSimHitContainer & MuonSimHitMatcher::simHits ( int  sub) const

Definition at line 85 of file MuonSimHitMatcher.cc.

Referenced by ntupleDataFormat.TrackingParticle::bestMatchingTrack(), and ~MuonSimHitMatcher().

85  {
86  return hits_;
87 }
edm::PSimHitContainer hits_
GlobalVector MuonSimHitMatcher::simHitsMeanMomentum ( const edm::PSimHitContainer sim_hits) const

Definition at line 121 of file MuonSimHitMatcher.cc.

References h, gen::n, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by ~MuonSimHitMatcher().

122  {
123  if (sim_hits.empty()) return GlobalVector(); // point "zero"
124 
125  float sumx, sumy, sumz;
126  sumx = sumy = sumz = 0.f;
127  size_t n = 0;
128  for (const auto& h : sim_hits) {
129  const LocalVector& lv = h.momentumAtEntry();
130  const GlobalVector& gv =
131  geometry_->idToDet(h.detUnitId())->surface().toGlobal(lv);
132  sumx += gv.x();
133  sumy += gv.y();
134  sumz += gv.z();
135  ++n;
136  }
137  if (n == 0) return GlobalVector();
138  return GlobalVector(sumx / n, sumy / n, sumz / n);
139 }
const TrackingGeometry * geometry_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
T y() const
Definition: PV3DBase.h:63
virtual const GeomDet * idToDet(DetId) const =0
T z() const
Definition: PV3DBase.h:64
T x() const
Definition: PV3DBase.h:62
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalPoint MuonSimHitMatcher::simHitsMeanPosition ( const edm::PSimHitContainer sim_hits) const

Definition at line 101 of file MuonSimHitMatcher.cc.

References runTauDisplay::gp, h, gen::n, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by CSCSimHitMatcher::LocalBendingInChamber(), RPCSimHitMatcher::match(), ME0SimHitMatcher::match(), GEMSimHitMatcher::match(), DTSimHitMatcher::match(), CSCSimHitMatcher::match(), and ~MuonSimHitMatcher().

102  {
103  if (sim_hits.empty()) return GlobalPoint(); // point "zero"
104 
105  float sumx, sumy, sumz;
106  sumx = sumy = sumz = 0.f;
107  size_t n = 0;
108  for (const auto& h : sim_hits) {
109  const LocalPoint& lp = h.entryPoint();
110  const GlobalPoint& gp =
111  geometry_->idToDet(h.detUnitId())->surface().toGlobal(lp);
112  sumx += gp.x();
113  sumy += gp.y();
114  sumz += gp.z();
115  ++n;
116  }
117  if (n == 0) return GlobalPoint();
118  return GlobalPoint(sumx / n, sumy / n, sumz / n);
119 }
const TrackingGeometry * geometry_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
virtual const GeomDet * idToDet(DetId) const =0
T z() const
Definition: PV3DBase.h:64
T x() const
Definition: PV3DBase.h:62
GlobalPoint MuonSimHitMatcher::simHitsMeanPositionStation ( int  n) const

Referenced by ~MuonSimHitMatcher().

Member Data Documentation

std::map<unsigned int, edm::PSimHitContainer> MuonSimHitMatcher::chamber_to_hits_
protected
std::map<unsigned int, edm::PSimHitContainer> MuonSimHitMatcher::detid_to_hits_
protected
bool MuonSimHitMatcher::discardEleHits_
protected
const TrackingGeometry* MuonSimHitMatcher::geometry_
protected
bool MuonSimHitMatcher::hasGeometry_
protected
edm::PSimHitContainer MuonSimHitMatcher::hits_
protected
edm::PSimHitContainer MuonSimHitMatcher::no_hits_
protected
edm::EDGetTokenT<edm::PSimHitContainer> MuonSimHitMatcher::simHitInput_
protected
edm::ParameterSet MuonSimHitMatcher::simHitPSet_
protected
edm::PSimHitContainer MuonSimHitMatcher::simHits_
protected
edm::Handle<edm::PSimHitContainer> MuonSimHitMatcher::simHitsH_
protected

Definition at line 89 of file MuonSimHitMatcher.h.

bool MuonSimHitMatcher::simMuOnly_
protected
edm::EDGetTokenT<edm::SimTrackContainer> MuonSimHitMatcher::simTrackInput_
protected

Definition at line 84 of file MuonSimHitMatcher.h.

edm::SimTrackContainer MuonSimHitMatcher::simTracks_
protected

Definition at line 91 of file MuonSimHitMatcher.h.

edm::Handle<edm::SimTrackContainer> MuonSimHitMatcher::simTracksH_
protected

Definition at line 87 of file MuonSimHitMatcher.h.

edm::EDGetTokenT<edm::SimVertexContainer> MuonSimHitMatcher::simVertexInput_
protected

Definition at line 83 of file MuonSimHitMatcher.h.

edm::SimVertexContainer MuonSimHitMatcher::simVertices_
protected

Definition at line 92 of file MuonSimHitMatcher.h.

edm::Handle<edm::SimVertexContainer> MuonSimHitMatcher::simVerticesH_
protected

Definition at line 88 of file MuonSimHitMatcher.h.

std::vector<unsigned> MuonSimHitMatcher::track_ids_
protected
std::map<unsigned int, unsigned int> MuonSimHitMatcher::trkid_to_index_
protected

Definition at line 97 of file MuonSimHitMatcher.h.

bool MuonSimHitMatcher::verbose_
protected
bool MuonSimHitMatcher::verboseSimTrack_
protected

Definition at line 75 of file MuonSimHitMatcher.h.