CMS 3D CMS Logo

CSCStubMatcher.cc
Go to the documentation of this file.
3 #include <algorithm>
4 
5 using namespace std;
6 
8  useGEMs_ = pSet.getParameter<bool>("useGEMs");
9 
10  const auto& cscCLCT = pSet.getParameter<edm::ParameterSet>("cscCLCT");
11  minBXCLCT_ = cscCLCT.getParameter<int>("minBX");
12  maxBXCLCT_ = cscCLCT.getParameter<int>("maxBX");
13  verboseCLCT_ = cscCLCT.getParameter<int>("verbose");
14  minNHitsChamberCLCT_ = cscCLCT.getParameter<int>("minNHitsChamber");
15 
16  const auto& cscALCT = pSet.getParameter<edm::ParameterSet>("cscALCT");
17  minBXALCT_ = cscALCT.getParameter<int>("minBX");
18  maxBXALCT_ = cscALCT.getParameter<int>("maxBX");
19  verboseALCT_ = cscALCT.getParameter<int>("verbose");
20  minNHitsChamberALCT_ = cscALCT.getParameter<int>("minNHitsChamber");
21 
22  const auto& cscLCT = pSet.getParameter<edm::ParameterSet>("cscLCT");
23  minBXLCT_ = cscLCT.getParameter<int>("minBX");
24  maxBXLCT_ = cscLCT.getParameter<int>("maxBX");
25  matchTypeTightLCT_ = cscLCT.getParameter<bool>("matchTypeTight");
26  verboseLCT_ = cscLCT.getParameter<int>("verbose");
27  minNHitsChamberLCT_ = cscLCT.getParameter<int>("minNHitsChamber");
28  addGhostLCTs_ = cscLCT.getParameter<bool>("addGhosts");
29 
30  const auto& cscMPLCT = pSet.getParameter<edm::ParameterSet>("cscMPLCT");
31  minBXMPLCT_ = cscMPLCT.getParameter<int>("minBX");
32  maxBXMPLCT_ = cscMPLCT.getParameter<int>("maxBX");
33  verboseMPLCT_ = cscMPLCT.getParameter<int>("verbose");
34  minNHitsChamberMPLCT_ = cscMPLCT.getParameter<int>("minNHitsChamber");
35 
36  if (useGEMs_)
37  gemDigiMatcher_.reset(new GEMDigiMatcher(pSet, std::move(iC)));
38  cscDigiMatcher_.reset(new CSCDigiMatcher(pSet, std::move(iC)));
39 
40  clctInputTag_ = cscCLCT.getParameter<edm::InputTag>("inputTag");
41  alctInputTag_ = cscALCT.getParameter<edm::InputTag>("inputTag");
42  lctInputTag_ = cscLCT.getParameter<edm::InputTag>("inputTag");
43  mplctInputTag_ = cscMPLCT.getParameter<edm::InputTag>("inputTag");
44 
45  clctToken_ = iC.consumes<CSCCLCTDigiCollection>(clctInputTag_);
46  alctToken_ = iC.consumes<CSCALCTDigiCollection>(alctInputTag_);
47  lctToken_ = iC.consumes<CSCCorrelatedLCTDigiCollection>(lctInputTag_);
48  mplctToken_ = iC.consumes<CSCCorrelatedLCTDigiCollection>(mplctInputTag_);
49 
50  geomToken_ = iC.esConsumes<CSCGeometry, MuonGeometryRecord>();
51 }
52 
54  if (useGEMs_)
55  gemDigiMatcher_->init(iEvent, iSetup);
56  cscDigiMatcher_->init(iEvent, iSetup);
57 
58  iEvent.getByToken(clctToken_, clctsH_);
59  iEvent.getByToken(alctToken_, alctsH_);
60  iEvent.getByToken(lctToken_, lctsH_);
61  iEvent.getByToken(mplctToken_, mplctsH_);
62 
63  cscGeometry_ = &iSetup.getData(geomToken_);
64 }
65 
66 // do the matching
67 void CSCStubMatcher::match(const SimTrack& t, const SimVertex& v) {
68  // match simhits first
69  if (useGEMs_)
70  gemDigiMatcher_->match(t, v);
71  cscDigiMatcher_->match(t, v);
72 
73  const CSCCLCTDigiCollection& clcts = *clctsH_.product();
74  const CSCALCTDigiCollection& alcts = *alctsH_.product();
75  const CSCCorrelatedLCTDigiCollection& lcts = *lctsH_.product();
76  const CSCCorrelatedLCTDigiCollection& mplcts = *mplctsH_.product();
77 
78  // clear collections
79  clear();
80 
81  if (!alctsH_.isValid()) {
82  edm::LogError("CSCStubMatcher") << "Cannot get ALCTs with label " << alctInputTag_.encode();
83  } else {
84  matchALCTsToSimTrack(alcts);
85  }
86 
87  if (!clctsH_.isValid()) {
88  edm::LogError("CSCStubMatcher") << "Cannot get CLCTs with label " << clctInputTag_.encode();
89  } else {
90  matchCLCTsToSimTrack(clcts);
91  }
92 
93  if (!lctsH_.isValid()) {
94  edm::LogError("CSCStubMatcher") << "Cannot get LCTs with label " << lctInputTag_.encode();
95  } else {
96  matchLCTsToSimTrack(lcts);
97  }
98 
99  if (!mplctsH_.isValid()) {
100  edm::LogError("CSCStubMatcher") << "Cannot get MPLCTs with label " << mplctInputTag_.encode();
101  } else {
102  matchMPLCTsToSimTrack(mplcts);
103  }
104 }
105 
107  const auto& cathode_ids = cscDigiMatcher_->chamberIdsStrip(0);
108 
109  for (const auto& id : cathode_ids) {
110  CSCDetId ch_id(id);
111  if (verboseCLCT_) {
112  edm::LogInfo("CSCStubMatcher") << "To check CSC chamber " << ch_id;
113  }
114 
115  int ring = ch_id.ring();
116 
117  // do not consider CSCs with too few hits
118  if (cscDigiMatcher_->nLayersWithStripInChamber(ch_id) < minNHitsChamberCLCT_)
119  continue;
120 
121  // get the comparator digis in this chamber
122  std::vector<CSCComparatorDigiContainer> comps;
123  for (int ilayer = CSCDetId::minLayerId(); ilayer <= CSCDetId::maxLayerId(); ilayer++) {
124  CSCDetId layerid(ch_id.endcap(), ch_id.station(), ring, ch_id.chamber(), ilayer);
125  comps.push_back(cscDigiMatcher_->comparatorDigisInDetId(layerid));
126  }
127 
128  // print out the digis
129  if (verboseCLCT_) {
130  edm::LogInfo("CSCStubMatcher") << "clct: comparators " << ch_id;
131  int layer = 0;
132  for (const auto& p : comps) {
133  layer++;
134  for (const auto& q : p) {
135  edm::LogInfo("CSCStubMatcher") << "L" << layer << " " << q << " " << q.getHalfStrip() << " ";
136  }
137  }
138  }
139 
140  //use ME1b id to get CLCTs
141  const bool isME1a(ch_id.station() == 1 and ch_id.ring() == 4);
142  if (isME1a)
143  ring = 1;
144  CSCDetId ch_id2(ch_id.endcap(), ch_id.station(), ring, ch_id.chamber(), 0);
145  auto id2 = ch_id2.rawId(); // CLCTs should be sorted into the det of the CLCTs.
146 
147  const auto& clcts_in_det = clcts.get(ch_id2);
148 
149  for (auto c = clcts_in_det.first; c != clcts_in_det.second; ++c) {
150  if (verboseCLCT_)
151  edm::LogInfo("CSCStubMatcher") << "clct " << ch_id2 << " " << *c;
152 
153  if (!c->isValid())
154  continue;
155 
156  // check that the BX for this stub wasn't too early or too late
157  if (c->getBX() < minBXCLCT_ || c->getBX() > maxBXCLCT_)
158  continue;
159 
160  // store all CLCTs in this chamber
161  chamber_to_clcts_all_[id2].push_back(*c);
162 
163  // check that at least 3 comparator digis were matched!
164  int nMatches = 0;
165  int layer = 0;
166  for (const auto& p : comps) {
167  layer++;
168  for (const auto& q : p) {
169  if (verboseCLCT_)
170  edm::LogInfo("CSCStubMatcher") << "L" << layer << " " << q << " " << q.getHalfStrip() << " " << std::endl;
171  for (const auto& clctComp : (*c).getHits()[layer - 1]) {
172  if (clctComp == 65535)
173  continue;
174  if (verboseCLCT_) {
175  edm::LogInfo("CSCStubMatcher") << "\t" << clctComp << " ";
176  }
177  if (q.getHalfStrip() == clctComp or (isME1a and q.getHalfStrip() + 128 == clctComp)) {
178  nMatches++;
179  if (verboseCLCT_) {
180  edm::LogInfo("CSCStubMatcher") << "\t\tnMatches " << nMatches << std::endl;
181  }
182  }
183  }
184  }
185  }
186 
187  // require at least 3 good matches
188  if (nMatches < 3)
189  continue;
190 
191  if (verboseCLCT_)
192  edm::LogInfo("CSCStubMatcher") << "clctGOOD";
193 
194  // store matching CLCTs in this chamber
195  if (std::find(chamber_to_clcts_[id2].begin(), chamber_to_clcts_[id2].end(), *c) == chamber_to_clcts_[id2].end()) {
196  chamber_to_clcts_[id2].push_back(*c);
197  }
198  }
199  if (chamber_to_clcts_[id2].size() > 2) {
200  edm::LogInfo("CSCStubMatcher") << "WARNING!!! too many CLCTs " << chamber_to_clcts_[id2].size() << " in "
201  << ch_id2;
202  for (auto& c : chamber_to_clcts_[id2])
203  edm::LogInfo("CSCStubMatcher") << " " << c;
204  }
205  }
206 }
207 
209  const auto& anode_ids = cscDigiMatcher_->chamberIdsWire(0);
210  for (const auto& id : anode_ids) {
211  CSCDetId ch_id(id);
212 
213  // fill 1 WG wide gaps
214  const auto& digi_wgs = cscDigiMatcher_->wiregroupsInChamber(id, 1);
215  if (verboseALCT_) {
216  cout << "alct: digi_wgs " << ch_id << " ";
217  copy(digi_wgs.begin(), digi_wgs.end(), ostream_iterator<int>(cout, " "));
218  cout << endl;
219  }
220 
221  int ring = ch_id.ring();
222  if (ring == 4)
223  ring = 1; //use ME1b id to get ALCTs
224  CSCDetId ch_id2(ch_id.endcap(), ch_id.station(), ring, ch_id.chamber(), 0);
225  auto id2 = ch_id2.rawId(); // ALCTs should be sorted into the det of the ALCTs.
226 
227  const auto& alcts_in_det = alcts.get(ch_id2);
228  for (auto a = alcts_in_det.first; a != alcts_in_det.second; ++a) {
229  if (!a->isValid())
230  continue;
231 
232  if (verboseALCT_)
233  edm::LogInfo("CSCStubMatcher") << "alct " << ch_id << " " << *a;
234 
235  // check that the BX for stub wasn't too early or too late
236  if (a->getBX() < minBXALCT_ || a->getBX() > maxBXALCT_)
237  continue;
238 
239  int wg = a->getKeyWG() + 1; // as ALCT wiregroups numbers start from 0
240 
241  // store all ALCTs in this chamber
242  chamber_to_alcts_all_[id2].push_back(*a);
243 
244  // match by wiregroup with the digis
245  if (digi_wgs.find(wg) == digi_wgs.end()) {
246  continue;
247  }
248  if (verboseALCT_)
249  edm::LogInfo("CSCStubMatcher") << "alctGOOD";
250 
251  // store matching ALCTs in this chamber
252  if (std::find(chamber_to_alcts_[id2].begin(), chamber_to_alcts_[id2].end(), *a) == chamber_to_alcts_[id2].end()) {
253  chamber_to_alcts_[id2].push_back(*a);
254  }
255  }
256  if (chamber_to_alcts_[id2].size() > 2) {
257  edm::LogInfo("CSCStubMatcher") << "WARNING!!! too many ALCTs " << chamber_to_alcts_[id2].size() << " in "
258  << ch_id;
259  for (auto& a : chamber_to_alcts_[id2])
260  edm::LogInfo("CSCStubMatcher") << " " << a;
261  }
262  }
263 }
264 
266  // only look for stubs in chambers that already have CLCT and ALCT
267  const auto& cathode_ids = chamberIdsAllCLCT(0);
268  const auto& anode_ids = chamberIdsAllALCT(0);
269 
270  std::set<int> cathode_and_anode_ids;
271  std::set_union(cathode_ids.begin(),
272  cathode_ids.end(),
273  anode_ids.begin(),
274  anode_ids.end(),
275  std::inserter(cathode_and_anode_ids, cathode_and_anode_ids.end()));
276 
277  for (const auto& id : cathode_and_anode_ids) {
278  CSCDetId ch_id(id);
279 
280  //use ME1b id to get LCTs
281  int ring = ch_id.ring();
282  if (ring == 4)
283  ring = 1;
284  CSCDetId ch_id2(ch_id.endcap(), ch_id.station(), ring, ch_id.chamber(), 0);
285  auto id2 = ch_id2.rawId(); // LCTs should be sorted into the det of the LCTs.
286 
287  const auto& lcts_in_det = lcts.get(ch_id2);
288 
289  std::map<int, CSCCorrelatedLCTDigiContainer> bx_to_lcts;
290 
291  // collect all valid LCTs in a handy container
293  for (auto lct = lcts_in_det.first; lct != lcts_in_det.second; ++lct) {
294  if (!lct->isValid())
295  continue;
296  lcts_tmp.push_back(*lct);
297  int bx = lct->getBX();
298  bx_to_lcts[bx].push_back(*lct);
299 
300  // Add ghost LCTs when there are two in bx
301  // and the two don't share half-strip or wiregroup
302  if (bx_to_lcts[bx].size() == 2 and addGhostLCTs_) {
303  auto lct11 = bx_to_lcts[bx][0];
304  auto lct22 = bx_to_lcts[bx][1];
305  addGhostLCTs(lct11, lct22, lcts_tmp);
306  }
307  }
308 
309  for (const auto& lct : lcts_tmp) {
310  bool lct_clct_match(false);
311  bool lct_alct_match(false);
312  bool lct_gem1_match(false);
313  bool lct_gem2_match(false);
314 
315  if (verboseLCT_) {
316  edm::LogInfo("CSCStubMatcher") << ch_id << " " << ch_id2;
317  edm::LogInfo("CSCStubMatcher") << lct;
318  edm::LogInfo("CSCStubMatcher") << "getCLCT " << lct.getCLCT() << "\ngetALCT " << lct.getALCT() << "\ngetGEM1 "
319  << lct.getGEM1() << "\ngetGEM2 " << lct.getGEM2();
320  }
321  // Check if matched to an CLCT
322  for (const auto& p : clctsInChamber(id)) {
323  if (p == lct.getCLCT()) {
324  lct_clct_match = true;
325  if (verboseLCT_)
326  edm::LogInfo("CSCStubMatcher") << "\t...lct_clct_match";
327  break;
328  }
329  }
330 
331  // Check if matched to an ALCT
332  for (const auto& p : alctsInChamber(id)) {
333  if (p == lct.getALCT()) {
334  lct_alct_match = true;
335  if (verboseLCT_)
336  edm::LogInfo("CSCStubMatcher") << "\t...lct_alct_match";
337  break;
338  }
339  }
340 
341  if (useGEMs_) {
342  // fixME here: double check the timing of GEMPad
343  if (ch_id.ring() == 1 and (ch_id.station() == 1 or ch_id.station() == 2)) {
344  // Check if matched to an GEM pad L1
345  const GEMDetId gemDetIdL1(ch_id.zendcap(), 1, ch_id.station(), 1, ch_id.chamber(), 0);
346  for (const auto& p : gemDigiMatcher_->padsInChamber(gemDetIdL1.rawId())) {
347  if (p == lct.getGEM1()) {
348  lct_gem1_match = true;
349  if (verboseLCT_)
350  edm::LogInfo("CSCStubMatcher") << "\t...lct_gem1_match";
351  break;
352  }
353  }
354 
355  // Check if matched to an GEM pad L2
356  const GEMDetId gemDetIdL2(ch_id.zendcap(), 1, ch_id.station(), 2, ch_id.chamber(), 0);
357  for (const auto& p : gemDigiMatcher_->padsInChamber(gemDetIdL2.rawId())) {
358  if (p == lct.getGEM2()) {
359  lct_gem2_match = true;
360  if (verboseLCT_)
361  edm::LogInfo("CSCStubMatcher") << "\t...lct_gem2_match";
362  break;
363  }
364  }
365  }
366  }
367 
368  const bool alct_clct = lct_clct_match and lct_alct_match;
369  const bool alct_gem = lct_alct_match and lct_gem1_match and lct_gem2_match;
370  const bool clct_gem = lct_clct_match and lct_gem1_match and lct_gem2_match;
371 
372  bool lct_tight_matched = alct_clct or alct_gem or clct_gem;
373  bool lct_loose_matched = lct_clct_match or lct_alct_match;
374  bool lct_matched = matchTypeTightLCT_ ? lct_tight_matched : lct_loose_matched;
375 
376  if (lct_matched) {
377  if (verboseLCT_)
378  edm::LogInfo("CSCStubMatcher") << "...was matched";
379  if (std::find(chamber_to_lcts_[id2].begin(), chamber_to_lcts_[id2].end(), lct) == chamber_to_lcts_[id2].end()) {
380  chamber_to_lcts_[id2].emplace_back(lct);
381  }
382  }
383  } // lct loop over
384  }
385 }
386 
388  // match simtrack to MPC LCT by looking only in chambers
389  // that already have LCTs matched to this simtrack
390  const auto& lcts_ids = chamberIdsLCT(0);
391 
392  // loop on the detids
393  for (const auto& id : lcts_ids) {
394  const auto& mplcts_in_det = mplcts.get(id);
395 
396  // loop on the MPC LCTs in this detid
397  for (auto lct = mplcts_in_det.first; lct != mplcts_in_det.second; ++lct) {
398  if (!lct->isValid())
399  continue;
400 
401  chamber_to_mplcts_all_[id].emplace_back(*lct);
402 
403  // check if this stub corresponds with a previously matched stub
404  for (const auto& sim_stub : lctsInChamber(id)) {
405  if (sim_stub == *lct) {
406  if (std::find(chamber_to_mplcts_[id].begin(), chamber_to_mplcts_[id].end(), *lct) ==
407  chamber_to_mplcts_[id].end()) {
408  chamber_to_mplcts_[id].emplace_back(*lct);
409  }
410  }
411  }
412  }
413  }
414 }
415 
416 std::set<unsigned int> CSCStubMatcher::chamberIdsAllCLCT(int csc_type) const {
417  return selectDetIds(chamber_to_clcts_all_, csc_type);
418 }
419 
420 std::set<unsigned int> CSCStubMatcher::chamberIdsAllALCT(int csc_type) const {
421  return selectDetIds(chamber_to_alcts_all_, csc_type);
422 }
423 
424 std::set<unsigned int> CSCStubMatcher::chamberIdsAllLCT(int csc_type) const {
425  return selectDetIds(chamber_to_lcts_all_, csc_type);
426 }
427 
428 std::set<unsigned int> CSCStubMatcher::chamberIdsAllMPLCT(int csc_type) const {
429  return selectDetIds(chamber_to_mplcts_all_, csc_type);
430 }
431 
432 std::set<unsigned int> CSCStubMatcher::chamberIdsCLCT(int csc_type) const {
433  return selectDetIds(chamber_to_clcts_, csc_type);
434 }
435 
436 std::set<unsigned int> CSCStubMatcher::chamberIdsALCT(int csc_type) const {
437  return selectDetIds(chamber_to_alcts_, csc_type);
438 }
439 
440 std::set<unsigned int> CSCStubMatcher::chamberIdsLCT(int csc_type) const {
441  return selectDetIds(chamber_to_lcts_, csc_type);
442 }
443 
444 std::set<unsigned int> CSCStubMatcher::chamberIdsMPLCT(int csc_type) const {
445  return selectDetIds(chamber_to_mplcts_, csc_type);
446 }
447 
448 const CSCCLCTDigiContainer& CSCStubMatcher::allCLCTsInChamber(unsigned int detid) const {
449  if (chamber_to_clcts_all_.find(detid) == chamber_to_clcts_all_.end())
450  return no_clcts_;
451  return chamber_to_clcts_all_.at(detid);
452 }
453 
454 const CSCALCTDigiContainer& CSCStubMatcher::allALCTsInChamber(unsigned int detid) const {
455  if (chamber_to_alcts_all_.find(detid) == chamber_to_alcts_all_.end())
456  return no_alcts_;
457  return chamber_to_alcts_all_.at(detid);
458 }
459 
461  if (chamber_to_lcts_all_.find(detid) == chamber_to_lcts_all_.end())
462  return no_lcts_;
463  return chamber_to_lcts_all_.at(detid);
464 }
465 
467  if (chamber_to_mplcts_all_.find(detid) == chamber_to_mplcts_all_.end())
468  return no_mplcts_;
469  return chamber_to_mplcts_all_.at(detid);
470 }
471 
472 const CSCCLCTDigiContainer& CSCStubMatcher::clctsInChamber(unsigned int detid) const {
473  if (chamber_to_clcts_.find(detid) == chamber_to_clcts_.end())
474  return no_clcts_;
475  return chamber_to_clcts_.at(detid);
476 }
477 
478 const CSCALCTDigiContainer& CSCStubMatcher::alctsInChamber(unsigned int detid) const {
479  if (chamber_to_alcts_.find(detid) == chamber_to_alcts_.end())
480  return no_alcts_;
481  return chamber_to_alcts_.at(detid);
482 }
483 
485  if (chamber_to_lcts_.find(detid) == chamber_to_lcts_.end())
486  return no_lcts_;
487  return chamber_to_lcts_.at(detid);
488 }
489 
491  if (chamber_to_mplcts_.find(detid) == chamber_to_mplcts_.end())
492  return no_mplcts_;
493  return chamber_to_mplcts_.at(detid);
494 }
495 
497  //sort stubs based on quality
498  const auto& input(clctsInChamber(detid));
499  int bestQ = 0;
500  int index = -1;
501  for (unsigned int i = 0; i < input.size(); ++i) {
502  int quality = input[i].getQuality();
503  if (quality > bestQ) {
504  bestQ = quality;
505  index = i;
506  }
507  }
508  if (index != -1)
509  return input[index];
510  return CSCCLCTDigi();
511 }
512 
514  //sort stubs based on quality
515  const auto& input(alctsInChamber(detid));
516  int bestQ = 0;
517  int index = -1;
518  for (unsigned int i = 0; i < input.size(); ++i) {
519  int quality = input[i].getQuality();
520  if (quality > bestQ) {
521  bestQ = quality;
522  index = i;
523  }
524  }
525  if (index != -1)
526  return input[index];
527  return CSCALCTDigi();
528 }
529 
531  //sort stubs based on quality
532  const auto& input(lctsInChamber(detid));
533  int bestQ = 0;
534  int index = -1;
535  for (unsigned int i = 0; i < input.size(); ++i) {
536  int quality = input[i].getQuality();
537  if (quality > bestQ) {
538  bestQ = quality;
539  index = i;
540  }
541  }
542  if (index != -1)
543  return input[index];
544  return CSCCorrelatedLCTDigi();
545 }
546 
547 float CSCStubMatcher::zpositionOfLayer(unsigned int detid, int layer) const {
548  const auto& id = CSCDetId(detid);
549  const auto& chamber(cscGeometry_->chamber(id));
550  return fabs(chamber->layer(layer)->centerOfStrip(20).z());
551 }
552 
553 int CSCStubMatcher::nChambersWithCLCT(int min_quality) const {
554  int result = 0;
555  const auto& chamber_ids = chamberIdsCLCT();
556  for (const auto& id : chamber_ids) {
557  int nStubChamber = 0;
558  const auto& clcts = clctsInChamber(id);
559  for (const auto& clct : clcts) {
560  if (!clct.isValid())
561  continue;
562  if (clct.getQuality() >= min_quality) {
563  nStubChamber++;
564  }
565  }
566  if (nStubChamber > 0) {
567  ++result;
568  }
569  }
570  return result;
571 }
572 
573 int CSCStubMatcher::nChambersWithALCT(int min_quality) const {
574  int result = 0;
575  const auto& chamber_ids = chamberIdsALCT();
576  for (const auto& id : chamber_ids) {
577  int nStubChamber = 0;
578  const auto& alcts = alctsInChamber(id);
579  for (const auto& alct : alcts) {
580  if (!alct.isValid())
581  continue;
582  if (alct.getQuality() >= min_quality) {
583  nStubChamber++;
584  }
585  }
586  if (nStubChamber > 0) {
587  ++result;
588  }
589  }
590  return result;
591 }
592 
593 int CSCStubMatcher::nChambersWithLCT(int min_quality) const {
594  int result = 0;
595  const auto& chamber_ids = chamberIdsLCT();
596  for (const auto& id : chamber_ids) {
597  int nStubChamber = 0;
598  const auto& lcts = lctsInChamber(id);
599  for (const auto& lct : lcts) {
600  if (!lct.isValid())
601  continue;
602  if (lct.getQuality() >= min_quality) {
603  nStubChamber++;
604  }
605  }
606  if (nStubChamber > 0) {
607  ++result;
608  }
609  }
610  return result;
611 }
612 
613 int CSCStubMatcher::nChambersWithMPLCT(int min_quality) const {
614  int result = 0;
615  const auto& chamber_ids = chamberIdsMPLCT();
616  for (const auto& id : chamber_ids) {
617  int nStubChamber = 0;
618  const auto& mplcts = mplctsInChamber(id);
619  for (const auto& mplct : mplcts) {
620  if (!mplct.isValid())
621  continue;
622  if (mplct.getQuality() >= min_quality) {
623  nStubChamber++;
624  }
625  }
626  if (nStubChamber > 0) {
627  ++result;
628  }
629  }
630  return result;
631 }
632 
633 bool CSCStubMatcher::lctInChamber(const CSCDetId& id, const CSCCorrelatedLCTDigi& lct) const {
634  for (const auto& stub : lctsInChamber(id.rawId())) {
635  if (stub == lct)
636  return true;
637  }
638  return false;
639 }
640 
642  CSCDetId cscId(rawId);
643  CSCDetId keyId(cscId.endcap(), cscId.station(), cscId.ring(), cscId.chamber(), CSCConstants::KEY_CLCT_LAYER);
644  float fractional_strip = lct.getFractionalStrip();
645  // case ME1/1
646  if (cscId.station() == 1 and (cscId.ring() == 4 || cscId.ring() == 1)) {
647  int ring = 1; // Default to ME1/b
649  ring = 4; // Change to ME1/a if the HalfStrip Number exceeds the range of ME1/b
650  fractional_strip -= CSCConstants::NUM_STRIPS_ME1B;
651  }
652  CSCDetId cscId_(cscId.endcap(), cscId.station(), ring, cscId.chamber(), cscId.layer());
653  cscId = cscId_;
654  }
655  // regular cases
656  const auto& chamber = cscGeometry_->chamber(cscId);
657  const auto& layer_geo = chamber->layer(CSCConstants::KEY_CLCT_LAYER)->geometry();
658  // LCT::getKeyWG() also starts from 0
659  float wire = layer_geo->middleWireOfGroup(lct.getKeyWG() + 1);
660  const LocalPoint& csc_intersect = layer_geo->intersectionOfStripAndWire(fractional_strip, wire);
661  const GlobalPoint& csc_gp = cscGeometry_->idToDet(keyId)->surface().toGlobal(csc_intersect);
662  return csc_gp;
663 }
664 
666  chamber_to_clcts_all_.clear();
667  chamber_to_alcts_all_.clear();
668  chamber_to_lcts_all_.clear();
669  chamber_to_mplcts_all_.clear();
670 
671  chamber_to_clcts_.clear();
672  chamber_to_alcts_.clear();
673  chamber_to_lcts_.clear();
674  chamber_to_mplcts_.clear();
675 }
676 
678  const CSCCorrelatedLCTDigi& lct22,
679  CSCCorrelatedLCTDigiContainer& lcts_tmp) const {
680  int wg1 = lct11.getKeyWG();
681  int wg2 = lct22.getKeyWG();
682  int hs1 = lct11.getStrip();
683  int hs2 = lct22.getStrip();
684 
685  if (!(wg1 == wg2 || hs1 == hs2)) {
686  // flip the ALCTs
687  CSCCorrelatedLCTDigi lct12 = lct11;
688  lct12.setWireGroup(wg2);
689  lct12.setALCT(lct22.getALCT());
690  lct12.setCLCT(lct11.getCLCT());
691  lcts_tmp.push_back(lct12);
692 
693  CSCCorrelatedLCTDigi lct21 = lct22;
694  lct21.setWireGroup(wg1);
695  lct21.setALCT(lct11.getALCT());
696  lct21.setCLCT(lct22.getCLCT());
697  lcts_tmp.push_back(lct21);
698  }
699 }
size
Write out results.
std::set< unsigned int > chamberIdsAllALCT(int csc_type=MuonHitHelper::CSC_ALL) const
std::vector< CSCCLCTDigi > CSCCLCTDigiContainer
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void setALCT(const CSCALCTDigi &alct)
const CSCCLCTDigiContainer & allCLCTsInChamber(unsigned int) const
all stubs (not necessarily matching) from a particular crossed chamber
int nChambersWithALCT(int min_quality=0) const
short int zendcap() const
Definition: CSCDetId.h:91
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
bool lctInChamber(const CSCDetId &id, const CSCCorrelatedLCTDigi &lct) const
int nChambersWithLCT(int min_quality=0) const
std::set< unsigned int > chamberIdsMPLCT(int csc_type=MuonHitHelper::CSC_ALL) const
int nChambersWithCLCT(int min_quality=0) const
How many CSC chambers with matching stubs of some minimal quality did this SimTrack hit...
const CSCALCTDigiContainer & allALCTsInChamber(unsigned int) const
CSCStubMatcher(edm::ParameterSet const &iPS, edm::ConsumesCollector &&iC)
std::set< unsigned int > chamberIdsAllLCT(int csc_type=MuonHitHelper::CSC_ALL) const
std::set< unsigned int > chamberIdsALCT(int csc_type=MuonHitHelper::CSC_ALL) const
void matchMPLCTsToSimTrack(const CSCCorrelatedLCTDigiCollection &)
std::set< unsigned int > chamberIdsAllCLCT(int csc_type=MuonHitHelper::CSC_ALL) const
crossed chamber detIds with not necessarily matching stubs
GlobalPoint getGlobalPosition(unsigned int rawId, const CSCCorrelatedLCTDigi &lct) const
const CSCCorrelatedLCTDigiContainer & allMPLCTsInChamber(unsigned int) const
std::vector< CSCCorrelatedLCTDigi > CSCCorrelatedLCTDigiContainer
CSCCorrelatedLCTDigi bestLctInChamber(unsigned int) const
int layer() const
Definition: CSCDetId.h:56
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
float zpositionOfLayer(unsigned int detid, int layer) const
static std::string const input
Definition: EdmProvDump.cc:50
string quality
int nChambersWithMPLCT(int min_quality=0) const
std::vector< CSCALCTDigi > CSCALCTDigiContainer
int iEvent
Definition: GenABIO.cc:224
void setWireGroup(const uint16_t wiregroup)
set wiregroup number
CSCCLCTDigi bestClctInChamber(unsigned int) const
best matching from a particular crossed chamber
std::set< unsigned int > chamberIdsLCT(int csc_type=MuonHitHelper::CSC_ALL) const
const CSCCLCTDigiContainer & clctsInChamber(unsigned int) const
all matching from a particular crossed chamber
void matchLCTsToSimTrack(const CSCCorrelatedLCTDigiCollection &)
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
const CSCALCTDigiContainer & alctsInChamber(unsigned int) const
int chamber() const
Definition: CSCDetId.h:62
const CSCCorrelatedLCTDigiContainer & mplctsInChamber(unsigned int) const
Log< level::Info, false > LogInfo
void matchALCTsToSimTrack(const CSCALCTDigiCollection &)
uint16_t getStrip(uint16_t n=2) const
return the key halfstrip from 0,159
const CSCCLCTDigi & getCLCT() const
static int minLayerId()
Definition: CSCDetId.h:242
int station() const
Definition: CSCDetId.h:79
void matchCLCTsToSimTrack(const CSCCLCTDigiCollection &)
int endcap() const
Definition: CSCDetId.h:85
float getFractionalStrip(uint16_t n=2) const
return the fractional strip
const CSCCorrelatedLCTDigiContainer & lctsInChamber(unsigned int) const
uint16_t getKeyWG() const
return the key wire group. counts from 0.
CSCALCTDigi bestAlctInChamber(unsigned int) const
std::set< unsigned int > chamberIdsAllMPLCT(int csc_type=MuonHitHelper::CSC_ALL) const
double a
Definition: hdecay.h:121
std::set< unsigned int > chamberIdsCLCT(int csc_type=MuonHitHelper::CSC_ALL) const
chamber detIds with matching stubs
void match(const SimTrack &t, const SimVertex &v)
do the matching
void clear(EGIsoObj &c)
Definition: egamma.h:82
int ring() const
Definition: CSCDetId.h:68
void setCLCT(const CSCCLCTDigi &clct)
const CSCALCTDigi & getALCT() const
const CSCCorrelatedLCTDigiContainer & allLCTsInChamber(unsigned int) const
static int maxLayerId()
Definition: CSCDetId.h:243
def move(src, dest)
Definition: eostools.py:511
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
void addGhostLCTs(const CSCCorrelatedLCTDigi &lct11, const CSCCorrelatedLCTDigi &lct22, CSCCorrelatedLCTDigiContainer &lctcontainer) const