CMS 3D CMS Logo

GEMSimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
6  : MuonSimHitMatcher(ps, std::move(iC)) {
7  simHitPSet_ = ps.getParameterSet("gemSimHit");
8  verbose_ = simHitPSet_.getParameter<int>("verbose");
9  simMuOnly_ = simHitPSet_.getParameter<bool>("simMuOnly");
10  discardEleHits_ = simHitPSet_.getParameter<bool>("discardEleHits");
11 
13 }
14 
17  iSetup.get<MuonGeometryRecord>().get(gem_geom_);
18  if (gem_geom_.isValid()) {
19  geometry_ = dynamic_cast<const GEMGeometry*>(&*gem_geom_);
20  } else {
21  hasGeometry_ = false;
22  edm::LogWarning("GEMSimHitMatcher") << "+++ Info: GEM geometry is unavailable. +++\n";
23  }
24  MuonSimHitMatcher::init(iEvent, iSetup);
25 }
26 
29  // instantiates the track ids and simhits
30  MuonSimHitMatcher::match(track, vertex);
31 
32  if (hasGeometry_) {
34 
35  if (verbose_) {
36  edm::LogInfo("GEMSimHitMatcher") << "nTrackIds " << track_ids_.size() << " nSelectedGEMSimHits " << hits_.size()
37  << endl;
38  edm::LogInfo("GEMSimHitMatcher") << "detids GEM " << detIds(0).size() << endl;
39 
40  const auto& gem_ch_ids = detIds();
41  for (const auto& id : gem_ch_ids) {
42  const auto& gem_simhits = MuonSimHitMatcher::hitsInDetId(id);
43  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
44  edm::LogInfo("GEMSimHitMatcher") << "gemchid " << GEMDetId(id) << ": nHits " << gem_simhits.size() << " phi "
45  << gem_simhits_gp.phi() << " nCh " << chamber_to_hits_[id].size() << endl;
46  const auto& strips = hitStripsInDetId(id);
47  edm::LogInfo("GEMSimHitMatcher") << "nStrip " << strips.size() << endl;
48  edm::LogInfo("GEMSimHitMatcher") << "strips : ";
49  for (const auto& p : strips) {
50  edm::LogInfo("GEMSimHitMatcher") << p;
51  }
52  }
53  const auto& gem_sch_ids = superChamberIds();
54  for (const auto& id : gem_sch_ids) {
55  const auto& gem_simhits = hitsInSuperChamber(id);
56  const auto& gem_simhits_gp = simHitsMeanPosition(gem_simhits);
57  edm::LogInfo("GEMSimHitMatcher") << "gemschid " << GEMDetId(id) << ": " << nCoincidencePadsWithHits() << " | "
58  << gem_simhits.size() << " " << gem_simhits_gp.phi() << " "
59  << superchamber_to_hits_[id].size() << endl;
60  }
61  }
62  }
63 }
64 
66  for (const auto& track_id : track_ids_) {
67  for (const auto& h : simHits_) {
68  if (h.trackId() != track_id)
69  continue;
70  int pdgid = h.particleType();
71  if (simMuOnly_ && std::abs(pdgid) != 13)
72  continue;
73  // discard electron hits in the GEM chambers
74  if (discardEleHits_ && pdgid == 11)
75  continue;
76 
77  const GEMDetId& p_id(h.detUnitId());
78  detid_to_hits_[h.detUnitId()].push_back(h);
79  hits_.push_back(h);
80  chamber_to_hits_[p_id.chamberId().rawId()].push_back(h);
81  superchamber_to_hits_[p_id.superChamberId().rawId()].push_back(h);
82  }
83  }
84 
85  // find pads with hits
86  const auto& detids = detIds();
87  // find 2-layer coincidence pads with hits
88  for (const auto& d : detids) {
89  GEMDetId id(d);
90  const auto& hits = hitsInDetId(d);
91  const auto& roll = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id);
92  // int max_npads = roll->npads();
93  set<int> pads;
94  for (const auto& h : hits) {
95  const LocalPoint& lp = h.entryPoint();
96  pads.insert(1 + static_cast<int>(roll->padTopology().channel(lp)));
97  }
98  detids_to_pads_[d] = pads;
99  }
100 
101  // find 2-layer coincidence pads with hits
102  for (const auto& d : detids) {
103  GEMDetId id1(d);
104  if (id1.layer() != 1)
105  continue;
106 
107  // find pads with hits in layer1
108  const auto& hits1 = hitsInDetId(d);
109  const auto& roll1 = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id1);
110  set<int> pads1;
111  set<int> pads2;
112  set<int> copads;
113 
114  for (const auto& h : hits1) {
115  const LocalPoint& lp = h.entryPoint();
116  pads1.insert(1 + static_cast<int>(roll1->padTopology().channel(lp)));
117  if (verbose_)
118  edm::LogInfo("GEMSimHitMatcher") << "GEMHits detid1 " << id1 << " pad1 "
119  << 1 + static_cast<int>(roll1->padTopology().channel(lp)) << std::endl;
120  }
121 
122  // find pads with hits in layer2
123  for (const auto& d2 : detids) {
124  // staggered geometry???? improve here !!
125  GEMDetId id2(d2);
126  // does layer 2 has simhits?
127  if (id2.layer() != 2 or id2.region() != id1.region() or id2.ring() != id1.ring() or
128  id2.station() != id1.station() or abs(id2.roll() - id1.roll()) > 1)
129  continue;
130  const auto& hits2 = hitsInDetId(id2());
131  const auto& roll2 = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id2);
132  for (const auto& h : hits2) {
133  const LocalPoint& lp = h.entryPoint();
134  pads2.insert(1 + static_cast<int>(roll2->padTopology().channel(lp)));
135  if (verbose_)
136  edm::LogInfo("GEMSimHitMatcher") << "GEMHits detid2 " << id2 << " pad2 "
137  << 1 + static_cast<int>(roll2->padTopology().channel(lp)) << std::endl;
138  }
139  }
140 
141  for (const auto& pad1 : pads1) {
142  for (const auto& pad2 : pads2) {
143  if (abs(pad1 - pad2) <= 2) {
144  if (copads.find(pad1) == copads.end())
145  copads.insert(pad1);
146  if (copads.find(pad2) == copads.end())
147  copads.insert(pad2);
148  }
149  }
150  }
151 
152  if (copads.empty())
153  continue;
154 
155  // detids here is layer1 id
156  detids_to_copads_[d] = copads;
157  }
158 }
159 
160 std::set<unsigned int> GEMSimHitMatcher::detIds(int gem_type) const {
161  std::set<unsigned int> result;
162  for (const auto& p : detid_to_hits_) {
163  const auto& id = p.first;
164  if (gem_type > 0) {
165  GEMDetId detId(id);
166  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
167  continue;
168  }
169  result.insert(id);
170  }
171  return result;
172 }
173 
174 std::set<unsigned int> GEMSimHitMatcher::detIdsCoincidences() const {
175  std::set<unsigned int> result;
176  for (const auto& p : detids_to_copads_)
177  result.insert(p.first);
178  return result;
179 }
180 
181 std::set<unsigned int> GEMSimHitMatcher::chamberIds(int gem_type) const {
182  std::set<unsigned int> result;
183  for (const auto& p : chamber_to_hits_) {
184  const auto& id = p.first;
185  if (gem_type > 0) {
186  GEMDetId detId(id);
187  if (MuonHitHelper::toGEMType(detId.station(), detId.ring()) != gem_type)
188  continue;
189  }
190  result.insert(id);
191  }
192  return result;
193 }
194 
195 std::set<unsigned int> GEMSimHitMatcher::superChamberIds() const {
196  std::set<unsigned int> result;
197  for (const auto& p : superchamber_to_hits_)
198  result.insert(p.first);
199  return result;
200 }
201 
202 std::set<unsigned int> GEMSimHitMatcher::superChamberIdsCoincidences() const {
203  std::set<unsigned int> result;
204  for (const auto& p : detids_to_copads_) {
205  const GEMDetId& p_id(p.first);
206  result.insert(p_id.superChamberId().rawId());
207  }
208  return result;
209 }
210 
212  if (MuonHitHelper::isGEM(detid)) {
213  const GEMDetId id(detid);
214  if (superchamber_to_hits_.find(id.chamberId().rawId()) == superchamber_to_hits_.end())
215  return no_hits_;
216  return superchamber_to_hits_.at(id.chamberId().rawId());
217  }
218 
219  return no_hits_;
220 }
221 
222 int GEMSimHitMatcher::nLayersWithHitsInSuperChamber(unsigned int detid) const {
223  set<int> layers_with_hits;
224  const auto& hits = hitsInSuperChamber(detid);
225  for (const auto& h : hits) {
226  const GEMDetId& idd(h.detUnitId());
227  layers_with_hits.insert(idd.layer());
228  }
229  return layers_with_hits.size();
230 }
231 
232 bool GEMSimHitMatcher::hitStation(int st, int nlayers) const {
233  int nst = 0;
234  for (const auto& ddt : chamberIds()) {
235  const GEMDetId id(ddt);
236  if (id.station() != st)
237  continue;
238 
239  const int nl(nLayersWithHitsInSuperChamber(id.rawId()));
240  if (nl < nlayers)
241  continue;
242  ++nst;
243  }
244  return nst;
245 }
246 
247 int GEMSimHitMatcher::nStations(int nlayers) const { return (hitStation(1, nlayers) + hitStation(2, nlayers)); }
248 
250  if (sim_hits.empty())
251  return -0.0; // point "zero"
252 
253  float central = -0.0;
254  size_t n = 0;
255  for (const auto& h : sim_hits) {
256  LocalPoint lp(0., 0., 0.); // local central
257  GlobalPoint gp;
258  if (MuonHitHelper::isGEM(h.detUnitId())) {
259  gp = geometry_->idToDet(h.detUnitId())->surface().toGlobal(lp);
260  }
261  central = gp.perp();
262  if (n >= 1)
263  edm::LogWarning("GEMSimHitMatcher") << "warning! find more than one simhits in GEM chamber " << std::endl;
264  ++n;
265  }
266 
267  return central;
268 }
269 
271  if (sim_hits.empty())
272  return -1.f;
273 
274  float sums = 0.f;
275  size_t n = 0;
276  for (const auto& h : sim_hits) {
277  const LocalPoint& lp = h.entryPoint();
278  const auto& d = h.detUnitId();
279  sums += dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(d)->strip(lp);
280  ++n;
281  }
282  if (n == 0)
283  return -1.f;
284  return sums / n;
285 }
286 
287 std::set<int> GEMSimHitMatcher::hitStripsInDetId(unsigned int detid, int margin_n_strips) const {
288  set<int> result;
289  const auto& simhits = MuonSimHitMatcher::hitsInDetId(detid);
290  GEMDetId id(detid);
291  int max_nstrips = dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->nstrips();
292  for (const auto& h : simhits) {
293  const LocalPoint& lp = h.entryPoint();
294  int central_strip =
295  static_cast<int>(dynamic_cast<const GEMGeometry*>(geometry_)->etaPartition(id)->topology().channel(lp));
296  int smin = central_strip - margin_n_strips;
297  smin = (smin > 0) ? smin : 1;
298  int smax = central_strip + margin_n_strips;
299  smax = (smax <= max_nstrips) ? smax : max_nstrips;
300  for (int ss = smin; ss <= smax; ++ss)
301  result.insert(ss);
302  }
303  return result;
304 }
305 
306 std::set<int> GEMSimHitMatcher::hitPadsInDetId(unsigned int detid) const {
307  set<int> none;
308  if (detids_to_pads_.find(detid) == detids_to_pads_.end())
309  return none;
310  return detids_to_pads_.at(detid);
311 }
312 
313 std::set<int> GEMSimHitMatcher::hitCoPadsInDetId(unsigned int detid) const {
314  set<int> none;
315  if (detids_to_copads_.find(detid) == detids_to_copads_.end())
316  return none;
317  return detids_to_copads_.at(detid);
318 }
319 
320 std::set<int> GEMSimHitMatcher::hitPartitions() const {
321  std::set<int> result;
322 
323  const auto& detids = detIds();
324  for (const auto& id : detids) {
325  GEMDetId idd(id);
326  result.insert(idd.roll());
327  }
328  return result;
329 }
330 
332  int result = 0;
333  const auto& pad_ids = detIds();
334  for (const auto& id : pad_ids) {
335  result += hitPadsInDetId(id).size();
336  }
337  return result;
338 }
339 
341  int result = 0;
342  const auto& copad_ids = detIdsCoincidences();
343  for (const auto& id : copad_ids) {
344  result += hitCoPadsInDetId(id).size();
345  }
346  return result;
347 }
T getParameter(std::string const &) const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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:69
int nPadsWithHits() const
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:49
int roll() const
Definition: GEMDetId.h:188
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int ring() const
Definition: GEMDetId.h:170
virtual const GeomDet * idToDet(DetId) const =0
GEMSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
GEMDetId superChamberId() const
Definition: GEMDetId.h:196
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
Definition: GEMDetId.h:184
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
int station() const
Definition: GEMDetId.h:173
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
int region() const
Definition: GEMDetId.h:165
d
Definition: ztail.py:151
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:7
int nLayersWithHitsInSuperChamber(unsigned int) const
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
T get() const
Definition: EventSetup.h:73
void match(const SimTrack &t, const SimVertex &v)
do the matching
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
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_