CMS 3D CMS Logo

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