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 TrackingGeometrygeometry ()
 
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

void clear ()
 
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 32 of file MuonSimHitMatcher.h.

Constructor & Destructor Documentation

◆ MuonSimHitMatcher()

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

Definition at line 7 of file MuonSimHitMatcher.cc.

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

7  {
8  const auto& simVertex = ps.getParameterSet("simVertex");
9  const auto& simTrack = ps.getParameterSet("simTrack");
10  verboseSimTrack_ = simTrack.getParameter<int>("verbose");
11 
13  simTrackInput_ = iC.consumes<edm::SimTrackContainer>(simTrack.getParameter<edm::InputTag>("inputTag"));
14 }
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::~MuonSimHitMatcher ( )
inline

Definition at line 38 of file MuonSimHitMatcher.h.

38 {}

Member Function Documentation

◆ chamberIds()

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

◆ clear()

void MuonSimHitMatcher::clear ( void  )
protected

Definition at line 139 of file MuonSimHitMatcher.cc.

Referenced by CSCSimHitMatcher::clear(), and GEMSimHitMatcher::clear().

139  {
140  track_ids_.clear();
141  trkid_to_index_.clear();
142  hits_.clear();
143  detid_to_hits_.clear();
144  chamber_to_hits_.clear();
145 }
edm::PSimHitContainer hits_
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
std::vector< unsigned > track_ids_
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
std::map< unsigned int, unsigned int > trkid_to_index_

◆ detIds()

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

◆ geometry()

const TrackingGeometry* MuonSimHitMatcher::geometry ( )
inline

Definition at line 69 of file MuonSimHitMatcher.h.

References geometry_.

Referenced by CSCSimHitMatcher::simHitsMeanWG().

69 { return geometry_; }
const TrackingGeometry * geometry_

◆ getIdsOfSimTrackShower()

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

Definition at line 47 of file MuonSimHitMatcher.cc.

References SimTrack::noVertex(), mps_fire::result, submitPVValidationJobs::t, and SimTrack::vertIndex().

49  {
50  vector<unsigned int> result;
51  result.push_back(initial_trk_id);
52 
53  if (!simMuOnly_)
54  return result;
55 
56  for (const auto& t : simTracks_) {
57  SimTrack last_trk = t;
58  // if (std::abs(t.type()) != 13) continue;
59  bool is_child = false;
60  while (true) {
61  if (last_trk.noVertex())
62  break;
63  if (simVertices_[last_trk.vertIndex()].noParent())
64  break;
65 
66  unsigned parentId = simVertices_[last_trk.vertIndex()].parentIndex();
67  if (parentId == initial_trk_id) {
68  is_child = true;
69  break;
70  }
71 
72  const auto& association = trkid_to_index_.find(parentId);
73  if (association == trkid_to_index_.end())
74  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_
int vertIndex() const
index of the vertex in the Event container (-1 if no vertex)
Definition: SimTrack.h:33
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
edm::SimVertexContainer simVertices_
std::map< unsigned int, unsigned int > trkid_to_index_
bool noVertex() const
Definition: SimTrack.h:34

◆ hitsInChamber()

const edm::PSimHitContainer & MuonSimHitMatcher::hitsInChamber ( unsigned int  detid) const

Definition at line 93 of file MuonSimHitMatcher.cc.

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

93  {
94  if (chamber_to_hits_.find(detid) == chamber_to_hits_.end())
95  return no_hits_;
96  return chamber_to_hits_.at(detid);
97 }
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
edm::PSimHitContainer no_hits_

◆ hitsInDetId()

const edm::PSimHitContainer & MuonSimHitMatcher::hitsInDetId ( unsigned int  detid) const

◆ init()

void MuonSimHitMatcher::init ( const edm::Event e,
const edm::EventSetup eventSetup 
)

initialize the event

Definition at line 17 of file MuonSimHitMatcher.cc.

References iEvent.

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

17  {
18  hasGeometry_ = true;
19 
20  iEvent.getByToken(simTrackInput_, simTracksH_);
22  iEvent.getByToken(simHitInput_, simHitsH_);
23 }
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_

◆ match()

void MuonSimHitMatcher::match ( const SimTrack t,
const SimVertex v 
)

do the matching

Definition at line 26 of file MuonSimHitMatcher.cc.

References submitPVValidationJobs::t, and HLT_2022v12_cff::track.

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

26  {
30 
31  // fill trkId2Index association:
32  int no = 0;
33  trkid_to_index_.clear();
34  for (const auto& t : simTracks_) {
35  trkid_to_index_[t.trackId()] = no;
36  no++;
37  }
38 
40  if (verboseSimTrack_) {
41  edm::LogInfo("MuonSimHitMatcher") << "Printing track_ids" << std::endl;
42  for (const auto& id : track_ids_)
43  edm::LogInfo("MuonSimHitMatcher") << "id: " << id << std::endl;
44  }
45 }
edm::SimTrackContainer simTracks_
T const * product() const
Definition: Handle.h:70
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_
Log< level::Info, false > LogInfo
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)

◆ simHits()

const edm::PSimHitContainer & MuonSimHitMatcher::simHits ( int  sub) const

Definition at line 85 of file MuonSimHitMatcher.cc.

Referenced by ntupleDataFormat.TrackingParticle::bestMatchingTrack().

85 { return hits_; }
edm::PSimHitContainer hits_

◆ simHitsMeanMomentum()

GlobalVector MuonSimHitMatcher::simHitsMeanMomentum ( const edm::PSimHitContainer sim_hits) const

Definition at line 119 of file MuonSimHitMatcher.cc.

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

119  {
120  if (sim_hits.empty())
121  return GlobalVector(); // point "zero"
122 
123  float sumx, sumy, sumz;
124  sumx = sumy = sumz = 0.f;
125  size_t n = 0;
126  for (const auto& h : sim_hits) {
127  const LocalVector& lv = h.momentumAtEntry();
128  const GlobalVector& gv = geometry_->idToDet(h.detUnitId())->surface().toGlobal(lv);
129  sumx += gv.x();
130  sumy += gv.y();
131  sumz += gv.z();
132  ++n;
133  }
134  if (n == 0)
135  return GlobalVector();
136  return GlobalVector(sumx / n, sumy / n, sumz / n);
137 }
const TrackingGeometry * geometry_
T z() const
Definition: PV3DBase.h:61
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
virtual const GeomDet * idToDet(DetId) const =0
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Global3DVector GlobalVector
Definition: GlobalVector.h:10

◆ simHitsMeanPosition()

GlobalPoint MuonSimHitMatcher::simHitsMeanPosition ( const edm::PSimHitContainer sim_hits) const

Definition at line 99 of file MuonSimHitMatcher.cc.

References runTauDisplay::gp, h, and dqmiodumpmetadata::n.

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

99  {
100  if (sim_hits.empty())
101  return GlobalPoint(); // point "zero"
102 
103  float sumx, sumy, sumz;
104  sumx = sumy = sumz = 0.f;
105  size_t n = 0;
106  for (const auto& h : sim_hits) {
107  const LocalPoint& lp = h.entryPoint();
108  const GlobalPoint& gp = geometry_->idToDet(h.detUnitId())->surface().toGlobal(lp);
109  sumx += gp.x();
110  sumy += gp.y();
111  sumz += gp.z();
112  ++n;
113  }
114  if (n == 0)
115  return GlobalPoint();
116  return GlobalPoint(sumx / n, sumy / n, sumz / n);
117 }
const TrackingGeometry * geometry_
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
virtual const GeomDet * idToDet(DetId) const =0
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4

◆ simHitsMeanPositionStation()

GlobalPoint MuonSimHitMatcher::simHitsMeanPositionStation ( int  n) const

Member Data Documentation

◆ chamber_to_hits_

std::map<unsigned int, edm::PSimHitContainer> MuonSimHitMatcher::chamber_to_hits_
protected

◆ detid_to_hits_

std::map<unsigned int, edm::PSimHitContainer> MuonSimHitMatcher::detid_to_hits_
protected

◆ discardEleHits_

bool MuonSimHitMatcher::discardEleHits_
protected

◆ geometry_

const TrackingGeometry* MuonSimHitMatcher::geometry_
protected

◆ hasGeometry_

bool MuonSimHitMatcher::hasGeometry_
protected

Definition at line 82 of file MuonSimHitMatcher.h.

◆ hits_

edm::PSimHitContainer MuonSimHitMatcher::hits_
protected

◆ no_hits_

edm::PSimHitContainer MuonSimHitMatcher::no_hits_
protected

◆ simHitInput_

edm::EDGetTokenT<edm::PSimHitContainer> MuonSimHitMatcher::simHitInput_
protected

◆ simHitPSet_

edm::ParameterSet MuonSimHitMatcher::simHitPSet_
protected

◆ simHits_

edm::PSimHitContainer MuonSimHitMatcher::simHits_
protected

◆ simHitsH_

edm::Handle<edm::PSimHitContainer> MuonSimHitMatcher::simHitsH_
protected

Definition at line 92 of file MuonSimHitMatcher.h.

◆ simMuOnly_

bool MuonSimHitMatcher::simMuOnly_
protected

◆ simTrackInput_

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

Definition at line 87 of file MuonSimHitMatcher.h.

◆ simTracks_

edm::SimTrackContainer MuonSimHitMatcher::simTracks_
protected

Definition at line 94 of file MuonSimHitMatcher.h.

◆ simTracksH_

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

Definition at line 90 of file MuonSimHitMatcher.h.

◆ simVertexInput_

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

Definition at line 86 of file MuonSimHitMatcher.h.

◆ simVertices_

edm::SimVertexContainer MuonSimHitMatcher::simVertices_
protected

Definition at line 95 of file MuonSimHitMatcher.h.

◆ simVerticesH_

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

Definition at line 91 of file MuonSimHitMatcher.h.

◆ track_ids_

std::vector<unsigned> MuonSimHitMatcher::track_ids_
protected

◆ trkid_to_index_

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

Definition at line 100 of file MuonSimHitMatcher.h.

◆ verbose_

bool MuonSimHitMatcher::verbose_
protected

◆ verboseSimTrack_

bool MuonSimHitMatcher::verboseSimTrack_
protected

Definition at line 78 of file MuonSimHitMatcher.h.