CMS 3D CMS Logo

GEMSimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
7  : MuonSimHitMatcher(ps, std::move(iC)) {
8  simHitPSet_ = ps.getParameterSet("gemSimHit");
9  verbose_ = simHitPSet_.getParameter<int>("verbose");
10  simMuOnly_ = simHitPSet_.getParameter<bool>("simMuOnly");
11  discardEleHits_ = simHitPSet_.getParameter<bool>("discardEleHits");
12 
13  simHitInput_ = iC.consumes<edm::PSimHitContainer>(
15 }
16 
19  const edm::EventSetup& iSetup) {
20  iSetup.get<MuonGeometryRecord>().get(gem_geom_);
21  if (gem_geom_.isValid()) {
22  geometry_ = dynamic_cast<const GEMGeometry*>(&*gem_geom_);
23  } else {
24  hasGeometry_ = false;
25  edm::LogWarning("GEMSimHitMatcher")
26  << "+++ Info: GEM geometry is unavailable. +++\n";
27  }
28  MuonSimHitMatcher::init(iEvent, iSetup);
29 }
30 
32 void GEMSimHitMatcher::match(const SimTrack& track, const SimVertex& vertex) {
33  // instantiates the track ids and simhits
34  MuonSimHitMatcher::match(track, vertex);
35 
36  if (hasGeometry_) {
38 
39  if (verbose_) {
40  edm::LogInfo("GEMSimHitMatcher")
41  << "nTrackIds " << track_ids_.size() << " nSelectedGEMSimHits "
42  << hits_.size() << endl;
43  edm::LogInfo("GEMSimHitMatcher")
44  << "detids GEM " << detIds(0).size() << endl;
45 
46  const auto& gem_ch_ids = detIds();
47  for (const auto& id : gem_ch_ids) {
48  const auto& gem_simhits = MuonSimHitMatcher::hitsInDetId(id);
49  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
50  edm::LogInfo("GEMSimHitMatcher")
51  << "gemchid " << GEMDetId(id) << ": nHits " << gem_simhits.size()
52  << " phi " << gem_simhits_gp.phi() << " nCh "
53  << chamber_to_hits_[id].size() << endl;
54  const auto& strips = hitStripsInDetId(id);
55  edm::LogInfo("GEMSimHitMatcher") << "nStrip " << strips.size() << endl;
56  edm::LogInfo("GEMSimHitMatcher") << "strips : ";
57  for (const auto& p : strips) {
58  edm::LogInfo("GEMSimHitMatcher") << p;
59  }
60  }
61  const auto& gem_sch_ids = superChamberIds();
62  for (const auto& id : gem_sch_ids) {
63  const auto& gem_simhits = hitsInSuperChamber(id);
64  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
65  edm::LogInfo("GEMSimHitMatcher")
66  << "gemschid " << GEMDetId(id) << ": " << nCoincidencePadsWithHits()
67  << " | " << gem_simhits.size() << " " << gem_simhits_gp.phi() << " "
68  << superchamber_to_hits_[id].size() << endl;
69  }
70  }
71  }
72 }
73 
75  for (const auto& track_id : track_ids_) {
76  for (const auto& h : simHits_) {
77  if (h.trackId() != track_id) continue;
78  int pdgid = h.particleType();
79  if (simMuOnly_ && std::abs(pdgid) != 13) continue;
80  // discard electron hits in the GEM chambers
81  if (discardEleHits_ && pdgid == 11) continue;
82 
83  const GEMDetId& p_id(h.detUnitId());
84  detid_to_hits_[h.detUnitId()].push_back(h);
85  hits_.push_back(h);
86  chamber_to_hits_[p_id.chamberId().rawId()].push_back(h);
87  superchamber_to_hits_[p_id.superChamberId().rawId()].push_back(h);
88  }
89  }
90 
91  // find pads with hits
92  const auto& detids = detIds();
93  // find 2-layer coincidence pads with hits
94  for (const auto& d : detids) {
95  GEMDetId id(d);
96  const auto& hits = hitsInDetId(d);
97  const auto& roll =
98  dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id);
99  // int max_npads = roll->npads();
100  set<int> pads;
101  for (const auto& h : hits) {
102  const LocalPoint& lp = h.entryPoint();
103  pads.insert(1 + static_cast<int>(roll->padTopology().channel(lp)));
104  }
105  detids_to_pads_[d] = pads;
106  }
107 
108  // find 2-layer coincidence pads with hits
109  for (const auto& d : detids) {
110  GEMDetId id1(d);
111  if (id1.layer() != 1) continue;
112 
113  // find pads with hits in layer1
114  const auto& hits1 = hitsInDetId(d);
115  const auto& roll1 =
116  dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id1);
117  set<int> pads1;
118  set<int> pads2;
119  set<int> copads;
120 
121  for (const auto& h : hits1) {
122  const LocalPoint& lp = h.entryPoint();
123  pads1.insert(1 + static_cast<int>(roll1->padTopology().channel(lp)));
124  if (verbose_)
125  edm::LogInfo("GEMSimHitMatcher")
126  << "GEMHits detid1 " << id1 << " pad1 "
127  << 1 + static_cast<int>(roll1->padTopology().channel(lp))
128  << std::endl;
129  }
130 
131  // find pads with hits in layer2
132  for (const auto& d2 : detids) {
133  // staggered geometry???? improve here !!
134  GEMDetId id2(d2);
135  // does layer 2 has simhits?
136  if (id2.layer() != 2 or id2.region() != id1.region() or
137  id2.ring() != id1.ring() or id2.station() != id1.station() or
138  abs(id2.roll() - id1.roll()) > 1)
139  continue;
140  const auto& hits2 = hitsInDetId(id2());
141  const auto& roll2 =
142  dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id2);
143  for (const auto& h : hits2) {
144  const LocalPoint& lp = h.entryPoint();
145  pads2.insert(1 + static_cast<int>(roll2->padTopology().channel(lp)));
146  if (verbose_)
147  edm::LogInfo("GEMSimHitMatcher")
148  << "GEMHits detid2 " << id2 << " pad2 "
149  << 1 + static_cast<int>(roll2->padTopology().channel(lp))
150  << std::endl;
151  }
152  }
153 
154  for (const auto& pad1 : pads1) {
155  for (const auto& pad2 : pads2) {
156  if (abs(pad1 - pad2) <= 2) {
157  if (copads.find(pad1) == copads.end()) copads.insert(pad1);
158  if (copads.find(pad2) == copads.end()) copads.insert(pad2);
159  }
160  }
161  }
162 
163  if (copads.empty()) continue;
164 
165  // detids here is layer1 id
166  detids_to_copads_[d] = copads;
167  }
168 }
169 
170 std::set<unsigned int> GEMSimHitMatcher::detIds(int gem_type) const {
171  std::set<unsigned int> result;
172  for (const auto& p : detid_to_hits_) {
173  const auto& id = p.first;
174  if (gem_type > 0) {
175  GEMDetId detId(id);
176  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
177  continue;
178  }
179  result.insert(id);
180  }
181  return result;
182 }
183 
184 std::set<unsigned int> GEMSimHitMatcher::detIdsCoincidences() const {
185  std::set<unsigned int> result;
186  for (const auto& p : detids_to_copads_) result.insert(p.first);
187  return result;
188 }
189 
190 std::set<unsigned int> GEMSimHitMatcher::chamberIds(int gem_type) const {
191  std::set<unsigned int> result;
192  for (const auto& p : chamber_to_hits_) {
193  const auto& id = p.first;
194  if (gem_type > 0) {
195  GEMDetId detId(id);
196  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
197  continue;
198  }
199  result.insert(id);
200  }
201  return result;
202 }
203 
204 std::set<unsigned int> GEMSimHitMatcher::superChamberIds() const {
205  std::set<unsigned int> result;
206  for (const auto& p : superchamber_to_hits_) result.insert(p.first);
207  return result;
208 }
209 
210 std::set<unsigned int> GEMSimHitMatcher::superChamberIdsCoincidences() const {
211  std::set<unsigned int> result;
212  for (const auto& p : detids_to_copads_) {
213  const GEMDetId& p_id(p.first);
214  result.insert(p_id.superChamberId().rawId());
215  }
216  return result;
217 }
218 
220  unsigned int detid) const {
221  if (MuonHitHelper::isGEM(detid)) {
222  const GEMDetId id(detid);
223  if (superchamber_to_hits_.find(id.chamberId().rawId()) ==
224  superchamber_to_hits_.end())
225  return no_hits_;
226  return superchamber_to_hits_.at(id.chamberId().rawId());
227  }
228 
229  return no_hits_;
230 }
231 
232 int GEMSimHitMatcher::nLayersWithHitsInSuperChamber(unsigned int detid) const {
233  set<int> layers_with_hits;
234  const auto& hits = hitsInSuperChamber(detid);
235  for (const auto& h : hits) {
236  const GEMDetId& idd(h.detUnitId());
237  layers_with_hits.insert(idd.layer());
238  }
239  return layers_with_hits.size();
240 }
241 
242 bool GEMSimHitMatcher::hitStation(int st, int nlayers) const {
243  int nst = 0;
244  for (const auto& ddt : chamberIds()) {
245  const GEMDetId id(ddt);
246  if (id.station() != st) continue;
247 
248  const int nl(nLayersWithHitsInSuperChamber(id.rawId()));
249  if (nl < nlayers) continue;
250  ++nst;
251  }
252  return nst;
253 }
254 
256  return (hitStation(1, nlayers) + hitStation(2, nlayers));
257 }
258 
260  const edm::PSimHitContainer& sim_hits) const {
261  if (sim_hits.empty()) return -0.0; // point "zero"
262 
263  float central = -0.0;
264  size_t n = 0;
265  for (const auto& h : sim_hits) {
266  LocalPoint lp(0., 0., 0.); // local central
267  GlobalPoint gp;
268  if (MuonHitHelper::isGEM(h.detUnitId())) {
269  gp = geometry_->idToDet(h.detUnitId())->surface().toGlobal(lp);
270  }
271  central = gp.perp();
272  if (n >= 1)
273  edm::LogWarning("GEMSimHitMatcher")
274  << "warning! find more than one simhits in GEM chamber " << std::endl;
275  ++n;
276  }
277 
278  return central;
279 }
280 
282  const edm::PSimHitContainer& sim_hits) const {
283  if (sim_hits.empty()) return -1.f;
284 
285  float sums = 0.f;
286  size_t n = 0;
287  for (const auto& h : sim_hits) {
288  const LocalPoint& lp = h.entryPoint();
289  const auto& d = h.detUnitId();
290  sums +=
291  dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(d)->strip(lp);
292  ++n;
293  }
294  if (n == 0) return -1.f;
295  return sums / n;
296 }
297 
298 std::set<int> GEMSimHitMatcher::hitStripsInDetId(unsigned int detid,
299  int margin_n_strips) const {
300  set<int> result;
301  const auto& simhits = MuonSimHitMatcher::hitsInDetId(detid);
302  GEMDetId id(detid);
303  int max_nstrips =
304  dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->nstrips();
305  for (const auto& h : simhits) {
306  const LocalPoint& lp = h.entryPoint();
307  int central_strip =
308  static_cast<int>(dynamic_cast<const GEMGeometry*>(geometry_)
309  ->etaPartition(id)
310  ->topology()
311  .channel(lp));
312  int smin = central_strip - margin_n_strips;
313  smin = (smin > 0) ? smin : 1;
314  int smax = central_strip + margin_n_strips;
315  smax = (smax <= max_nstrips) ? smax : max_nstrips;
316  for (int ss = smin; ss <= smax; ++ss) result.insert(ss);
317  }
318  return result;
319 }
320 
321 std::set<int> GEMSimHitMatcher::hitPadsInDetId(unsigned int detid) const {
322  set<int> none;
323  if (detids_to_pads_.find(detid) == detids_to_pads_.end()) return none;
324  return detids_to_pads_.at(detid);
325 }
326 
327 std::set<int> GEMSimHitMatcher::hitCoPadsInDetId(unsigned int detid) const {
328  set<int> none;
329  if (detids_to_copads_.find(detid) == detids_to_copads_.end()) return none;
330  return detids_to_copads_.at(detid);
331 }
332 
333 std::set<int> GEMSimHitMatcher::hitPartitions() const {
334  std::set<int> result;
335 
336  const auto& detids = detIds();
337  for (const auto& id : detids) {
338  GEMDetId idd(id);
339  result.insert(idd.roll());
340  }
341  return result;
342 }
343 
345  int result = 0;
346  const auto& pad_ids = detIds();
347  for (const auto& id : pad_ids) {
348  result += hitPadsInDetId(id).size();
349  }
350  return result;
351 }
352 
354  int result = 0;
355  const auto& copad_ids = detIdsCoincidences();
356  for (const auto& id : copad_ids) {
357  result += hitCoPadsInDetId(id).size();
358  }
359  return result;
360 }
T getParameter(std::string const &) const
float simHitsGEMCentralPosition(const edm::PSimHitContainer &sim_hits) const
bool hitStation(int, int) const
const TrackingGeometry * geometry_
std::map< unsigned int, std::set< int > > detids_to_pads_
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
edm::PSimHitContainer hits_
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
T perp() const
Definition: PV3DBase.h:72
int nPadsWithHits() 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 gem_type=MuonHitHelper::GEM_ALL) const
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
int roll() const
Definition: GEMDetId.h:80
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
int ring() const
Definition: GEMDetId.h:59
virtual const GeomDet * idToDet(DetId) const =0
GEMSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
GEMDetId superChamberId() const
Return the corresponding superChamberId.
Definition: GEMDetId.h:90
static int toGEMType(int st, int ri)
std::vector< unsigned > track_ids_
std::set< unsigned int > superChamberIds() const
std::set< unsigned int > detIds(int gem_type=MuonHitHelper::GEM_ALL) const
int nCoincidencePadsWithHits() const
int iEvent
Definition: GenABIO.cc:224
GlobalPoint simHitsMeanPosition(const edm::PSimHitContainer &sim_hits) const
std::set< int > hitPadsInDetId(unsigned int) const
edm::PSimHitContainer simHits_
edm::ParameterSet simHitPSet_
int nStations(int nl=2) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::set< unsigned int > detIdsCoincidences() const
std::map< unsigned int, edm::PSimHitContainer > superchamber_to_hits_
int layer() const
Layer id: each station have two layers of chambers: layer 1 is the inner chamber and layer 2 is the o...
Definition: GEMDetId.h:69
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int region() const
Region id: 0 for Barrel Not in use, +/-1 For +/- Endcap.
Definition: GEMDetId.h:53
std::set< int > hitPartitions() const
edm::PSimHitContainer no_hits_
ParameterSet const & getParameterSet(std::string const &) const
const edm::PSimHitContainer & hitsInDetId(unsigned int) const
std::set< int > hitCoPadsInDetId(unsigned int) const
std::map< unsigned int, std::set< int > > detids_to_copads_
void match(const SimTrack &t, const SimVertex &v)
do the matching
static bool isGEM(unsigned int detId)
Definition: MuonHitHelper.cc:8
int nLayersWithHitsInSuperChamber(unsigned int) const
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
T get() const
Definition: EventSetup.h:71
void match(const SimTrack &t, const SimVertex &v)
do the matching
std::vector< PSimHit > PSimHitContainer
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
const edm::PSimHitContainer & hitsInSuperChamber(unsigned int) const
bool isValid() const
Definition: ESHandle.h:44
std::set< unsigned int > superChamberIdsCoincidences() const
def move(src, dest)
Definition: eostools.py:511
edm::ESHandle< GEMGeometry > gem_geom_