CMS 3D CMS Logo

CSCSimHitMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
7  : MuonSimHitMatcher(ps, std::move(iC)) {
8  simHitPSet_ = ps.getParameterSet("cscSimHit");
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(csc_geom_);
21  if (csc_geom_.isValid()) {
22  geometry_ = &*csc_geom_;
23  } else {
24  hasGeometry_ = false;
25  edm::LogWarning("CSCSimHitMatcher")
26  << "+++ Info: CSC geometry is unavailable. +++\n";
27  }
28  MuonSimHitMatcher::init(iEvent, iSetup);
29 }
30 
32 void CSCSimHitMatcher::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("CSCSimHitMatcher")
41  << "nTrackIds " << track_ids_.size() << " nSelectedCSCSimHits "
42  << hits_.size() << endl;
43  edm::LogInfo("CSCSimHitMatcher")
44  << "detids CSC " << detIds(0).size() << endl;
45 
46  for (const auto& id : detIds(0)) {
47  const auto& simhits = hitsInDetId(id);
48  const auto& simhits_gp = simHitsMeanPosition(simhits);
49  const auto& strips = hitStripsInDetId(id);
50  CSCDetId cscid(id);
51  if (cscid.station() == 1 and (cscid.ring() == 1 or cscid.ring() == 4)) {
52  edm::LogInfo("CSCSimHitMatcher")
53  << "cscdetid " << CSCDetId(id) << ": " << simhits.size() << " "
54  << simhits_gp.phi() << " " << detid_to_hits_[id].size() << endl;
55  edm::LogInfo("CSCSimHitMatcher")
56  << "nStrip " << strips.size() << endl;
57  edm::LogInfo("CSCSimHitMatcher") << "strips : ";
58  for (const auto& p : strips) {
59  edm::LogInfo("CSCSimHitMatcher") << p;
60  }
61  }
62  }
63  }
64  }
65 }
66 
68  for (const auto& track_id : track_ids_) {
69  for (const auto& h : simHits_) {
70  if (h.trackId() != track_id) continue;
71  int pdgid = h.particleType();
72  if (simMuOnly_ && std::abs(pdgid) != 13) continue;
73  // discard electron hits in the CSC chambers
74  if (discardEleHits_ && pdgid == 11) continue;
75 
76  const CSCDetId& layer_id(h.detUnitId());
77  hits_.push_back(h);
78  detid_to_hits_[h.detUnitId()].push_back(h);
79  chamber_to_hits_[layer_id.chamberId().rawId()].push_back(h);
80  }
81  }
82 }
83 
84 std::set<unsigned int> CSCSimHitMatcher::detIds(int csc_type) const {
85  std::set<unsigned int> result;
86  for (const auto& p : detid_to_hits_) {
87  const auto& id = p.first;
88  if (csc_type > 0) {
89  CSCDetId detId(id);
90  if (MuonHitHelper::toCSCType(detId.station(), detId.ring()) != csc_type)
91  continue;
92  }
93  result.insert(id);
94  }
95  return result;
96 }
97 
98 std::set<unsigned int> CSCSimHitMatcher::chamberIds(int csc_type) const {
99  std::set<unsigned int> result;
100  for (const auto& p : chamber_to_hits_) {
101  const auto& id = p.first;
102  if (csc_type > 0) {
103  CSCDetId detId(id);
104  if (MuonHitHelper::toCSCType(detId.station(), detId.ring()) != csc_type)
105  continue;
106  }
107  result.insert(id);
108  }
109  return result;
110 }
111 
112 int CSCSimHitMatcher::nLayersWithHitsInChamber(unsigned int detid) const {
113  set<int> layers_with_hits;
114  for (const auto& h : MuonSimHitMatcher::hitsInChamber(detid)) {
115  const CSCDetId& idd(h.detUnitId());
116  layers_with_hits.insert(idd.layer());
117  }
118  return layers_with_hits.size();
119 }
120 
121 bool CSCSimHitMatcher::hitStation(int st, int nlayers) const {
122  int nst = 0;
123  for (const auto& ddt : chamberIds()) {
124  const CSCDetId id(ddt);
125  int ri(id.ring());
126  if (id.station() != st) continue;
127 
128  // ME1/a case - check the ME1/b chamber
129  if (st == 1 and ri == 4) {
130  CSCDetId idME1b(id.endcap(), id.station(), 1, id.chamber(), 0);
131  const int nl1a(nLayersWithHitsInChamber(id.rawId()));
132  const int nl1b(nLayersWithHitsInChamber(idME1b.rawId()));
133  if (nl1a + nl1b < nlayers) continue;
134  ++nst;
135  }
136  // ME1/b case - check the ME1/a chamber
137  else if (st == 1 and ri == 1) {
138  CSCDetId idME1a(id.endcap(), id.station(), 4, id.chamber(), 0);
139  const int nl1a(nLayersWithHitsInChamber(idME1a.rawId()));
140  const int nl1b(nLayersWithHitsInChamber(id.rawId()));
141  if (nl1a + nl1b < nlayers) continue;
142  ++nst;
143  }
144  // default case
145  else {
146  const int nl(nLayersWithHitsInChamber(id.rawId()));
147  if (nl < nlayers) continue;
148  ++nst;
149  }
150  }
151  return nst;
152 }
153 
155  return (hitStation(1, nlayers) + hitStation(2, nlayers) +
156  hitStation(3, nlayers) + hitStation(4, nlayers));
157 }
158 
159 float CSCSimHitMatcher::LocalBendingInChamber(unsigned int detid) const {
160  const CSCDetId cscid(detid);
161  if (nLayersWithHitsInChamber(detid) < 6) return -100;
162  float phi_layer1 = -10;
163  float phi_layer6 = 10;
164 
165  if (cscid.station() == 1 and (cscid.ring() == 1 or cscid.ring() == 4)) {
166  // phi in layer 1
167  const CSCDetId cscid1a(cscid.endcap(), cscid.station(), 4, cscid.chamber(),
168  1);
169  const CSCDetId cscid1b(cscid.endcap(), cscid.station(), 1, cscid.chamber(),
170  1);
171  const edm::PSimHitContainer& hits1a =
172  MuonSimHitMatcher::hitsInDetId(cscid1a.rawId());
173  const edm::PSimHitContainer& hits1b =
174  MuonSimHitMatcher::hitsInDetId(cscid1b.rawId());
175  const GlobalPoint& gp1a =
177  const GlobalPoint& gp1b =
179  if (!hits1a.empty() and !hits1b.empty())
180  phi_layer1 = (gp1a.phi() + gp1b.phi()) / 2.0;
181  else if (!hits1a.empty())
182  phi_layer1 = gp1a.phi();
183  else if (!hits1b.empty())
184  phi_layer1 = gp1b.phi();
185 
186  // phi in layer 6
187  const CSCDetId cscid6a(cscid.endcap(), cscid.station(), 4, cscid.chamber(),
188  6);
189  const CSCDetId cscid6b(cscid.endcap(), cscid.station(), 1, cscid.chamber(),
190  6);
191  const edm::PSimHitContainer& hits6a =
192  MuonSimHitMatcher::hitsInDetId(cscid6a.rawId());
193  const edm::PSimHitContainer& hits6b =
194  MuonSimHitMatcher::hitsInDetId(cscid6b.rawId());
195  const GlobalPoint& gp6a =
197  const GlobalPoint& gp6b =
199  if (!hits6a.empty() and !hits6b.empty())
200  phi_layer6 = (gp6a.phi() + gp6b.phi()) / 2.0;
201  else if (!hits6a.empty())
202  phi_layer6 = gp6a.phi();
203  else if (!hits6b.empty())
204  phi_layer6 = gp6b.phi();
205 
206  } else {
207  // phi in layer 1
208  const CSCDetId cscid1(cscid.endcap(), cscid.station(), cscid.ring(),
209  cscid.chamber(), 1);
210  const GlobalPoint& gp1 =
212  phi_layer1 = gp1.phi();
213 
214  // phi in layer 6
215  const CSCDetId cscid6(cscid.endcap(), cscid.station(), cscid.ring(),
216  cscid.chamber(), 6);
217  const GlobalPoint& gp6 =
219  phi_layer6 = gp6.phi();
220  }
221  return deltaPhi(phi_layer6, phi_layer1);
222 }
223 
225  const edm::PSimHitContainer& sim_hits) const {
226  if (sim_hits.empty()) return -1.f;
227 
228  float sums = 0.f;
229  size_t n = 0;
230  for (const auto& h : sim_hits) {
231  const LocalPoint& lp = h.entryPoint();
232  float s;
233  const auto& d = h.detUnitId();
234  s = dynamic_cast<const CSCGeometry*>(geometry_)
235  ->layer(d)
236  ->geometry()
237  ->strip(lp);
238  // convert to half-strip:
239  s *= 2.;
240  sums += s;
241  ++n;
242  }
243  if (n == 0) return -1.f;
244  return sums / n;
245 }
246 
248  const edm::PSimHitContainer& sim_hits) const {
249  if (sim_hits.empty()) return -1.f;
250 
251  float sums = 0.f;
252  size_t n = 0;
253  for (const auto& h : sim_hits) {
254  const LocalPoint& lp = h.entryPoint();
255  float s;
256  const auto& d = h.detUnitId();
257  // find nearest wire
258  const auto& layerG(
259  dynamic_cast<const CSCGeometry*>(geometry_)->layer(d)->geometry());
260  int nearestWire(layerG->nearestWire(lp));
261  // then find the corresponding wire group
262  s = layerG->wireGroup(nearestWire);
263  sums += s;
264  ++n;
265  }
266  if (n == 0) return -1.f;
267  return sums / n;
268 }
269 
270 std::set<int> CSCSimHitMatcher::hitStripsInDetId(unsigned int detid,
271  int margin_n_strips) const {
272  set<int> result;
273  const auto& simhits = MuonSimHitMatcher::hitsInDetId(detid);
274  CSCDetId id(detid);
275  int max_nstrips = dynamic_cast<const CSCGeometry*>(geometry_)
276  ->layer(id)
277  ->geometry()
278  ->numberOfStrips();
279  for (const auto& h : simhits) {
280  const LocalPoint& lp = h.entryPoint();
281  int central_strip = dynamic_cast<const CSCGeometry*>(geometry_)
282  ->layer(id)
283  ->geometry()
284  ->nearestStrip(lp);
285  int smin = central_strip - margin_n_strips;
286  smin = (smin > 0) ? smin : 1;
287  int smax = central_strip + margin_n_strips;
288  smax = (smax <= max_nstrips) ? smax : max_nstrips;
289  for (int ss = smin; ss <= smax; ++ss) result.insert(ss);
290  }
291  return result;
292 }
293 
294 std::set<int> CSCSimHitMatcher::hitWiregroupsInDetId(unsigned int detid,
295  int margin_n_wg) const {
296  set<int> result;
297  const auto& simhits = MuonSimHitMatcher::hitsInDetId(detid);
298  CSCDetId id(detid);
299  int max_n_wg = dynamic_cast<const CSCGeometry*>(geometry_)
300  ->layer(id)
301  ->geometry()
302  ->numberOfWireGroups();
303  for (const auto& h : simhits) {
304  const LocalPoint& lp = h.entryPoint();
305  const auto& layer_geo =
306  dynamic_cast<const CSCGeometry*>(geometry_)->layer(id)->geometry();
307  int central_wg = layer_geo->wireGroup(layer_geo->nearestWire(lp));
308  int wg_min = central_wg - margin_n_wg;
309  wg_min = (wg_min > 0) ? wg_min : 1;
310  int wg_max = central_wg + margin_n_wg;
311  wg_max = (wg_max <= max_n_wg) ? wg_max : max_n_wg;
312  for (int wg = wg_min; wg <= wg_max; ++wg) result.insert(wg);
313  }
314  return result;
315 }
316 
317 int CSCSimHitMatcher::nCoincidenceChambers(int min_n_layers) const {
318  int result = 0;
319  const auto& chamber_ids = chamberIds(0);
320  for (const auto& id : chamber_ids) {
321  if (nLayersWithHitsInChamber(id) >= min_n_layers) result += 1;
322  }
323  return result;
324 }
325 
327  const std::set<unsigned int>& set) const {
328  for (const auto& p : set) {
329  CSCDetId detId(p);
330  edm::LogInfo("CSCSimHitMatcher") << " " << detId << "\n";
331  }
332 }
333 
334 std::set<unsigned int> CSCSimHitMatcher::chamberIdsStation(int station) const {
335  set<unsigned int> result;
336  switch (station) {
337  case 1: {
338  const auto& p1(chamberIds(MuonHitHelper::CSC_ME1a));
339  const auto& p2(chamberIds(MuonHitHelper::CSC_ME1b));
340  const auto& p3(chamberIds(MuonHitHelper::CSC_ME12));
341  const auto& p4(chamberIds(MuonHitHelper::CSC_ME13));
342  result.insert(p1.begin(), p1.end());
343  result.insert(p2.begin(), p2.end());
344  result.insert(p3.begin(), p3.end());
345  result.insert(p4.begin(), p4.end());
346  break;
347  }
348  case 2: {
349  const auto& p1(chamberIds(MuonHitHelper::CSC_ME21));
350  const auto& p2(chamberIds(MuonHitHelper::CSC_ME22));
351  result.insert(p1.begin(), p1.end());
352  result.insert(p2.begin(), p2.end());
353  break;
354  }
355  case 3: {
356  const auto& p1(chamberIds(MuonHitHelper::CSC_ME31));
357  const auto& p2(chamberIds(MuonHitHelper::CSC_ME32));
358  result.insert(p1.begin(), p1.end());
359  result.insert(p2.begin(), p2.end());
360  break;
361  }
362  case 4: {
363  const auto& p1(chamberIds(MuonHitHelper::CSC_ME41));
364  const auto& p2(chamberIds(MuonHitHelper::CSC_ME42));
365  result.insert(p1.begin(), p1.end());
366  result.insert(p2.begin(), p2.end());
367  break;
368  }
369  };
370  return result;
371 }
static int toCSCType(int st, int ri)
int chamber() const
Definition: CSCDetId.h:68
T getParameter(std::string const &) const
const TrackingGeometry * geometry_
edm::PSimHitContainer hits_
void match(const SimTrack &t, const SimVertex &v)
do the matching
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::map< unsigned int, edm::PSimHitContainer > detid_to_hits_
std::set< unsigned int > detIds(int type=MuonHitHelper::CSC_ALL) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
float LocalBendingInChamber(unsigned int detid) const
float simHitsMeanStrip(const edm::PSimHitContainer &sim_hits) const
CSCSimHitMatcher(const edm::ParameterSet &iPS, edm::ConsumesCollector &&iC)
int nStations(int nl=4) const
std::vector< unsigned > track_ids_
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
int endcap() const
Definition: CSCDetId.h:93
std::set< int > hitWiregroupsInDetId(unsigned int, int margin_n_wg=0) const
int iEvent
Definition: GenABIO.cc:224
GlobalPoint simHitsMeanPosition(const edm::PSimHitContainer &sim_hits) const
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
edm::PSimHitContainer simHits_
edm::ParameterSet simHitPSet_
double p4[4]
Definition: TauolaWrapper.h:92
float simHitsMeanWG(const edm::PSimHitContainer &sim_hits) 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
int nCoincidenceChambers(int min_n_layers=4) const
std::map< unsigned int, edm::PSimHitContainer > chamber_to_hits_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
std::set< unsigned int > chamberIds(int type=MuonHitHelper::CSC_ALL) const
double p2[4]
Definition: TauolaWrapper.h:90
edm::ESHandle< CSCGeometry > csc_geom_
int ring() const
Definition: CSCDetId.h:75
ParameterSet const & getParameterSet(std::string const &) const
const edm::PSimHitContainer & hitsInDetId(unsigned int) const
int nLayersWithHitsInChamber(unsigned int) const
void match(const SimTrack &t, const SimVertex &v)
do the matching
edm::EDGetTokenT< edm::PSimHitContainer > simHitInput_
ESHandle< TrackerGeometry > geometry
double p1[4]
Definition: TauolaWrapper.h:89
void chamberIdsToString(const std::set< unsigned int > &set) const
T get() const
Definition: EventSetup.h:71
int station() const
Definition: CSCDetId.h:86
std::vector< PSimHit > PSimHitContainer
std::set< unsigned int > chamberIdsStation(int station) const
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
bool hitStation(int, int) const
bool isValid() const
Definition: ESHandle.h:44
const edm::PSimHitContainer & hitsInChamber(unsigned int) const
def move(src, dest)
Definition: eostools.py:511
double p3[4]
Definition: TauolaWrapper.h:91