CMS 3D CMS Logo

RPCSimHitMatcher.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 
8  : MuonSimHitMatcher(ps, std::move(iC)) {
9  simHitPSet_ = ps.getParameterSet("rpcSimHit");
10  verbose_ = simHitPSet_.getParameter<int>("verbose");
11  simMuOnly_ = simHitPSet_.getParameter<bool>("simMuOnly");
12  discardEleHits_ = simHitPSet_.getParameter<bool>("discardEleHits");
13 
14  simHitInput_ = iC.consumes<edm::PSimHitContainer>(
16 }
17 
20  const edm::EventSetup& iSetup) {
21  iSetup.get<MuonGeometryRecord>().get(rpc_geom_);
22  if (rpc_geom_.isValid()) {
23  geometry_ = &*rpc_geom_;
24  } else {
25  hasGeometry_ = false;
26  edm::LogWarning("RPCSimHitMatcher")
27  << "+++ Info: RPC geometry is unavailable. +++\n";
28  }
29  MuonSimHitMatcher::init(iEvent, iSetup);
30 }
31 
33 void RPCSimHitMatcher::match(const SimTrack& track, const SimVertex& vertex) {
34  // instantiates the track ids and simhits
35  MuonSimHitMatcher::match(track, vertex);
36 
37  if (hasGeometry_) {
39 
40  if (verbose_) {
41  edm::LogInfo("RPCSimHitMatcher")
42  << "nSimHits " << simHits_.size() << " nTrackIds "
43  << track_ids_.size() << endl;
44  edm::LogInfo("RPCSimHitMatcher")
45  << "detids RPC " << detIds().size() << endl;
46 
47  const auto& ch_ids = chamberIds();
48  for (const auto& id : ch_ids) {
49  const auto& simhits = MuonSimHitMatcher::hitsInChamber(id);
50  const auto& simhits_gp = simHitsMeanPosition(simhits);
51  edm::LogInfo("RPCSimHitMatcher")
52  << "RPCDetId " << RPCDetId(id) << ": nHits " << simhits.size()
53  << " eta " << simhits_gp.eta() << " phi " << simhits_gp.phi()
54  << " nCh " << chamber_to_hits_[id].size() << endl;
55  const auto& strips = hitStripsInDetId(id);
56  edm::LogInfo("RPCSimHitMatcher") << "nStrips " << strips.size() << endl;
57  edm::LogInfo("RPCSimHitMatcher") << "strips : ";
58  for (const auto& p : strips) {
59  edm::LogInfo("RPCSimHitMatcher") << p;
60  }
61  }
62  }
63  }
64 }
65 
67  for (const auto& track_id : track_ids_) {
68  for (const auto& h : simHits_) {
69  if (h.trackId() != track_id) continue;
70  int pdgid = h.particleType();
71  if (simMuOnly_ && std::abs(pdgid) != 13) continue;
72  // discard electron hits in the RPC chambers
73  if (discardEleHits_ && pdgid == 11) continue;
74 
75  const RPCDetId& layer_id(h.detUnitId());
76  detid_to_hits_[h.detUnitId()].push_back(h);
77  hits_.push_back(h);
78  chamber_to_hits_[layer_id.chamberId().rawId()].push_back(h);
79  }
80  }
81 }
82 
83 std::set<unsigned int> RPCSimHitMatcher::detIds(int type) const {
84  std::set<unsigned int> result;
85  for (const auto& p : detid_to_hits_) {
86  const auto& id = p.first;
87  if (type > 0) {
88  RPCDetId detId(id);
89  if (MuonHitHelper::toRPCType(detId.region(), detId.station(),
90  detId.ring()) != type)
91  continue;
92  }
93  result.insert(id);
94  }
95  return result;
96 }
97 
98 std::set<unsigned int> RPCSimHitMatcher::chamberIds(int type) const {
99  std::set<unsigned int> result;
100  for (const auto& p : chamber_to_hits_) {
101  const auto& id = p.first;
102  if (type > 0) {
103  RPCDetId detId(id);
104  if (MuonHitHelper::toRPCType(detId.region(), detId.station(),
105  detId.ring()) != type)
106  continue;
107  }
108  result.insert(id);
109  }
110  return result;
111 }
112 
113 bool RPCSimHitMatcher::hitStation(int st) const {
114  int nst = 0;
115  for (const auto& ddt : chamberIds(0)) {
116  const RPCDetId id(ddt);
117  if (id.station() != st) continue;
118  ++nst;
119  }
120  return nst;
121 }
122 
124  return (hitStation(1) + hitStation(2) + hitStation(3) + hitStation(4));
125 }
126 
128  const edm::PSimHitContainer& sim_hits) const {
129  if (sim_hits.empty()) return -1.f;
130 
131  float sums = 0.f;
132  size_t n = 0;
133  for (const auto& h : sim_hits) {
134  const LocalPoint& lp = h.entryPoint();
135  const auto& d = h.detUnitId();
136  sums += dynamic_cast<const RPCGeometry*>(geometry_)->roll(d)->strip(lp);
137  ++n;
138  }
139  if (n == 0) return -1.f;
140  return sums / n;
141 }
142 
143 std::set<int> RPCSimHitMatcher::hitStripsInDetId(unsigned int detid,
144  int margin_n_strips) const {
145  set<int> result;
146  RPCDetId id(detid);
147  for (const auto& roll :
148  dynamic_cast<const RPCGeometry*>(geometry_)->chamber(id)->rolls()) {
149  int max_nstrips = roll->nstrips();
150  for (const auto& h : MuonSimHitMatcher::hitsInDetId(roll->id().rawId())) {
151  const LocalPoint& lp = h.entryPoint();
152  int central_strip = static_cast<int>(roll->topology().channel(lp));
153  int smin = central_strip - margin_n_strips;
154  smin = (smin > 0) ? smin : 1;
155  int smax = central_strip + margin_n_strips;
156  smax = (smax <= max_nstrips) ? smax : max_nstrips;
157  for (int ss = smin; ss <= smax; ++ss) result.insert(ss);
158  }
159  }
160  return result;
161 }
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
const TrackingGeometry * geometry_
edm::PSimHitContainer hits_
std::set< unsigned int > detIds(int type=MuonHitHelper::RPC_ALL) const
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
std::set< unsigned int > chamberIds(int type=MuonHitHelper::RPC_ALL) const
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
RPCSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
std::vector< unsigned > track_ids_
int iEvent
Definition: GenABIO.cc:224
GlobalPoint simHitsMeanPosition(const edm::PSimHitContainer &sim_hits) const
edm::PSimHitContainer simHits_
int ring() const
Definition: RPCDetId.h:72
edm::ParameterSet simHitPSet_
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int nStations() const
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
ParameterSet const & getParameterSet(std::string const &) const
const edm::PSimHitContainer & hitsInDetId(unsigned int) const
void match(const SimTrack &t, const SimVertex &v)
do the matching
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
T get() const
Definition: EventSetup.h:71
edm::ESHandle< RPCGeometry > rpc_geom_
std::vector< PSimHit > PSimHitContainer
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
bool hitStation(int st) const
static int toRPCType(int re, int st, int ri)
bool isValid() const
Definition: ESHandle.h:44
const edm::PSimHitContainer & hitsInChamber(unsigned int) const
def move(src, dest)
Definition: eostools.py:511
void match(const SimTrack &t, const SimVertex &v)
do the matching
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96