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