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