CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 " << ch_id2;
200  for (auto& c : chamber_to_clcts_[id2])
201  edm::LogInfo("CSCStubMatcher") << " " << c;
202  }
203  }
204 }
205 
207  const auto& anode_ids = cscDigiMatcher_->chamberIdsWire(0);
208  int n_minLayers = 0;
209  for (const auto& id : anode_ids) {
210  if (cscDigiMatcher_->nLayersWithWireInChamber(id) >= minNHitsChamberALCT_)
211  ++n_minLayers;
212  CSCDetId ch_id(id);
213 
214  // fill 1 WG wide gaps
215  const auto& digi_wgs = cscDigiMatcher_->wiregroupsInChamber(id, 1);
216  if (verboseALCT_) {
217  cout << "alct: digi_wgs " << ch_id << " ";
218  copy(digi_wgs.begin(), digi_wgs.end(), ostream_iterator<int>(cout, " "));
219  cout << endl;
220  }
221 
222  int ring = ch_id.ring();
223  if (ring == 4)
224  ring = 1; //use ME1b id to get ALCTs
225  CSCDetId ch_id2(ch_id.endcap(), ch_id.station(), ring, ch_id.chamber(), 0);
226  auto id2 = ch_id2.rawId(); // ALCTs should be sorted into the det of the ALCTs.
227 
228  const auto& alcts_in_det = alcts.get(ch_id2);
229  for (auto a = alcts_in_det.first; a != alcts_in_det.second; ++a) {
230  if (!a->isValid())
231  continue;
232 
233  if (verboseALCT_)
234  edm::LogInfo("CSCStubMatcher") << "alct " << ch_id << " " << *a;
235 
236  // check that the BX for stub wasn't too early or too late
237  if (a->getBX() < minBXALCT_ || a->getBX() > maxBXALCT_)
238  continue;
239 
240  int wg = a->getKeyWG() + 1; // as ALCT wiregroups numbers start from 0
241 
242  // store all ALCTs in this chamber
243  chamber_to_alcts_all_[id2].push_back(*a);
244 
245  // match by wiregroup with the digis
246  if (digi_wgs.find(wg) == digi_wgs.end()) {
247  continue;
248  }
249  if (verboseALCT_)
250  edm::LogInfo("CSCStubMatcher") << "alctGOOD";
251 
252  // store matching ALCTs in this chamber
253  if (std::find(chamber_to_alcts_[id2].begin(), chamber_to_alcts_[id2].end(), *a) == chamber_to_alcts_[id2].end()) {
254  chamber_to_alcts_[id2].push_back(*a);
255  }
256  }
257  if (chamber_to_alcts_[id2].size() > 2) {
258  edm::LogInfo("CSCStubMatcher") << "WARNING!!! too many ALCTs " << chamber_to_alcts_[id2].size() << " in " << 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  int iLct = -1;
279 
280  CSCDetId ch_id(id);
281 
282  //use ME1b id to get LCTs
283  int ring = ch_id.ring();
284  if (ring == 4)
285  ring = 1;
286  CSCDetId ch_id2(ch_id.endcap(), ch_id.station(), ring, ch_id.chamber(), 0);
287  auto id2 = ch_id2.rawId(); // LCTs should be sorted into the det of the LCTs.
288 
289  const auto& lcts_in_det = lcts.get(ch_id2);
290 
291  std::map<int, CSCCorrelatedLCTDigiContainer> bx_to_lcts;
292 
293  // collect all valid LCTs in a handy container
295  for (auto lct = lcts_in_det.first; lct != lcts_in_det.second; ++lct) {
296  if (!lct->isValid())
297  continue;
298  lcts_tmp.push_back(*lct);
299  int bx = lct->getBX();
300  bx_to_lcts[bx].push_back(*lct);
301 
302  // Add ghost LCTs when there are two in bx
303  // and the two don't share half-strip or wiregroup
304  if (bx_to_lcts[bx].size() == 2 and addGhostLCTs_) {
305  auto lct11 = bx_to_lcts[bx][0];
306  auto lct22 = bx_to_lcts[bx][1];
307  addGhostLCTs(lct11, lct22, lcts_tmp);
308  }
309  }
310 
311  for (const auto& lct : lcts_tmp) {
312  iLct++;
313 
314  bool lct_clct_match(false);
315  bool lct_alct_match(false);
316  bool lct_gem1_match(false);
317  bool lct_gem2_match(false);
318 
319  if (verboseLCT_) {
320  edm::LogInfo("CSCStubMatcher") << ch_id << " " << ch_id2;
321  edm::LogInfo("CSCStubMatcher") << lct;
322  edm::LogInfo("CSCStubMatcher") << "getCLCT " << lct.getCLCT() << "\ngetALCT " << lct.getALCT() << "\ngetGEM1 "
323  << lct.getGEM1() << "\ngetGEM2 " << lct.getGEM2();
324  }
325  // Check if matched to an CLCT
326  for (const auto& p : clctsInChamber(id)) {
327  if (p == lct.getCLCT()) {
328  lct_clct_match = true;
329  if (verboseLCT_)
330  edm::LogInfo("CSCStubMatcher") << "\t...lct_clct_match";
331  break;
332  }
333  }
334 
335  // Check if matched to an ALCT
336  for (const auto& p : alctsInChamber(id)) {
337  if (p == lct.getALCT()) {
338  lct_alct_match = true;
339  if (verboseLCT_)
340  edm::LogInfo("CSCStubMatcher") << "\t...lct_alct_match";
341  break;
342  }
343  }
344 
345  if (useGEMs_) {
346  // fixME here: double check the timing of GEMPad
347  if (ch_id.ring() == 1 and (ch_id.station() == 1 or ch_id.station() == 2)) {
348  // Check if matched to an GEM pad L1
349  const GEMDetId gemDetIdL1(ch_id.zendcap(), 1, ch_id.station(), 1, ch_id.chamber(), 0);
350  for (const auto& p : gemDigiMatcher_->padsInChamber(gemDetIdL1.rawId())) {
351  if (p == lct.getGEM1()) {
352  lct_gem1_match = true;
353  if (verboseLCT_)
354  edm::LogInfo("CSCStubMatcher") << "\t...lct_gem1_match";
355  break;
356  }
357  }
358 
359  // Check if matched to an GEM pad L2
360  const GEMDetId gemDetIdL2(ch_id.zendcap(), 1, ch_id.station(), 2, ch_id.chamber(), 0);
361  for (const auto& p : gemDigiMatcher_->padsInChamber(gemDetIdL2.rawId())) {
362  if (p == lct.getGEM2()) {
363  lct_gem2_match = true;
364  if (verboseLCT_)
365  edm::LogInfo("CSCStubMatcher") << "\t...lct_gem2_match";
366  break;
367  }
368  }
369  }
370  }
371 
372  const bool alct_clct = lct_clct_match and lct_alct_match;
373  const bool alct_gem = lct_alct_match and lct_gem1_match and lct_gem2_match;
374  const bool clct_gem = lct_clct_match and lct_gem1_match and lct_gem2_match;
375 
376  bool lct_tight_matched = alct_clct or alct_gem or clct_gem;
377  bool lct_loose_matched = lct_clct_match or lct_alct_match;
378  bool lct_matched = lct_loose_matched or lct_tight_matched;
379 
380  if (lct_matched) {
381  if (verboseLCT_)
382  edm::LogInfo("CSCStubMatcher") << "...was matched";
383  if (std::find(chamber_to_lcts_[id2].begin(), chamber_to_lcts_[id2].end(), lct) == chamber_to_lcts_[id2].end()) {
384  chamber_to_lcts_[id2].emplace_back(lct);
385  }
386  }
387  } // lct loop over
388  }
389 }
390 
392  // match simtrack to MPC LCT by looking only in chambers
393  // that already have LCTs matched to this simtrack
394  const auto& lcts_ids = chamberIdsLCT(0);
395 
396  // loop on the detids
397  for (const auto& id : lcts_ids) {
398  const auto& mplcts_in_det = mplcts.get(id);
399 
400  // loop on the MPC LCTs in this detid
401  for (auto lct = mplcts_in_det.first; lct != mplcts_in_det.second; ++lct) {
402  if (!lct->isValid())
403  continue;
404 
405  chamber_to_mplcts_all_[id].emplace_back(*lct);
406 
407  // check if this stub corresponds with a previously matched stub
408  for (const auto& sim_stub : lctsInChamber(id)) {
409  if (sim_stub == *lct) {
410  if (std::find(chamber_to_mplcts_[id].begin(), chamber_to_mplcts_[id].end(), *lct) ==
411  chamber_to_mplcts_[id].end()) {
412  chamber_to_mplcts_[id].emplace_back(*lct);
413  }
414  }
415  }
416  }
417  }
418 }
419 
420 std::set<unsigned int> CSCStubMatcher::chamberIdsAllCLCT(int csc_type) const {
421  return selectDetIds(chamber_to_clcts_all_, csc_type);
422 }
423 
424 std::set<unsigned int> CSCStubMatcher::chamberIdsAllALCT(int csc_type) const {
425  return selectDetIds(chamber_to_alcts_all_, csc_type);
426 }
427 
428 std::set<unsigned int> CSCStubMatcher::chamberIdsAllLCT(int csc_type) const {
429  return selectDetIds(chamber_to_lcts_all_, csc_type);
430 }
431 
432 std::set<unsigned int> CSCStubMatcher::chamberIdsAllMPLCT(int csc_type) const {
433  return selectDetIds(chamber_to_mplcts_all_, csc_type);
434 }
435 
436 std::set<unsigned int> CSCStubMatcher::chamberIdsCLCT(int csc_type) const {
437  return selectDetIds(chamber_to_clcts_, csc_type);
438 }
439 
440 std::set<unsigned int> CSCStubMatcher::chamberIdsALCT(int csc_type) const {
441  return selectDetIds(chamber_to_alcts_, csc_type);
442 }
443 
444 std::set<unsigned int> CSCStubMatcher::chamberIdsLCT(int csc_type) const {
445  return selectDetIds(chamber_to_lcts_, csc_type);
446 }
447 
448 std::set<unsigned int> CSCStubMatcher::chamberIdsMPLCT(int csc_type) const {
449  return selectDetIds(chamber_to_mplcts_, csc_type);
450 }
451 
452 const CSCCLCTDigiContainer& CSCStubMatcher::allCLCTsInChamber(unsigned int detid) const {
453  if (chamber_to_clcts_all_.find(detid) == chamber_to_clcts_all_.end())
454  return no_clcts_;
455  return chamber_to_clcts_all_.at(detid);
456 }
457 
458 const CSCALCTDigiContainer& CSCStubMatcher::allALCTsInChamber(unsigned int detid) const {
459  if (chamber_to_alcts_all_.find(detid) == chamber_to_alcts_all_.end())
460  return no_alcts_;
461  return chamber_to_alcts_all_.at(detid);
462 }
463 
465  if (chamber_to_lcts_all_.find(detid) == chamber_to_lcts_all_.end())
466  return no_lcts_;
467  return chamber_to_lcts_all_.at(detid);
468 }
469 
471  if (chamber_to_mplcts_all_.find(detid) == chamber_to_mplcts_all_.end())
472  return no_mplcts_;
473  return chamber_to_mplcts_all_.at(detid);
474 }
475 
476 const CSCCLCTDigiContainer& CSCStubMatcher::clctsInChamber(unsigned int detid) const {
477  if (chamber_to_clcts_.find(detid) == chamber_to_clcts_.end())
478  return no_clcts_;
479  return chamber_to_clcts_.at(detid);
480 }
481 
482 const CSCALCTDigiContainer& CSCStubMatcher::alctsInChamber(unsigned int detid) const {
483  if (chamber_to_alcts_.find(detid) == chamber_to_alcts_.end())
484  return no_alcts_;
485  return chamber_to_alcts_.at(detid);
486 }
487 
489  if (chamber_to_lcts_.find(detid) == chamber_to_lcts_.end())
490  return no_lcts_;
491  return chamber_to_lcts_.at(detid);
492 }
493 
495  if (chamber_to_mplcts_.find(detid) == chamber_to_mplcts_.end())
496  return no_mplcts_;
497  return chamber_to_mplcts_.at(detid);
498 }
499 
501  //sort stubs based on quality
502  const auto& input(clctsInChamber(detid));
503  int bestQ = 0;
504  int index = -1;
505  for (unsigned int i = 0; i < input.size(); ++i) {
506  int quality = input[i].getQuality();
507  if (quality > bestQ) {
508  bestQ = quality;
509  index = i;
510  }
511  }
512  if (index != -1)
513  return input[index];
514  return CSCCLCTDigi();
515 }
516 
518  //sort stubs based on quality
519  const auto& input(alctsInChamber(detid));
520  int bestQ = 0;
521  int index = -1;
522  for (unsigned int i = 0; i < input.size(); ++i) {
523  int quality = input[i].getQuality();
524  if (quality > bestQ) {
525  bestQ = quality;
526  index = i;
527  }
528  }
529  if (index != -1)
530  return input[index];
531  return CSCALCTDigi();
532 }
533 
535  //sort stubs based on quality
536  const auto& input(lctsInChamber(detid));
537  int bestQ = 0;
538  int index = -1;
539  for (unsigned int i = 0; i < input.size(); ++i) {
540  int quality = input[i].getQuality();
541  if (quality > bestQ) {
542  bestQ = quality;
543  index = i;
544  }
545  }
546  if (index != -1)
547  return input[index];
548  return CSCCorrelatedLCTDigi();
549 }
550 
551 float CSCStubMatcher::zpositionOfLayer(unsigned int detid, int layer) const {
552  const auto& id = CSCDetId(detid);
553  const auto& chamber(cscGeometry_->chamber(id));
554  return fabs(chamber->layer(layer)->centerOfStrip(20).z());
555 }
556 
557 int CSCStubMatcher::nChambersWithCLCT(int min_quality) const {
558  int result = 0;
559  const auto& chamber_ids = chamberIdsCLCT();
560  for (const auto& id : chamber_ids) {
561  int nStubChamber = 0;
562  const auto& clcts = clctsInChamber(id);
563  for (const auto& clct : clcts) {
564  if (!clct.isValid())
565  continue;
566  if (clct.getQuality() >= min_quality) {
567  nStubChamber++;
568  }
569  }
570  if (nStubChamber > 0) {
571  ++result;
572  }
573  }
574  return result;
575 }
576 
577 int CSCStubMatcher::nChambersWithALCT(int min_quality) const {
578  int result = 0;
579  const auto& chamber_ids = chamberIdsALCT();
580  for (const auto& id : chamber_ids) {
581  int nStubChamber = 0;
582  const auto& alcts = alctsInChamber(id);
583  for (const auto& alct : alcts) {
584  if (!alct.isValid())
585  continue;
586  if (alct.getQuality() >= min_quality) {
587  nStubChamber++;
588  }
589  }
590  if (nStubChamber > 0) {
591  ++result;
592  }
593  }
594  return result;
595 }
596 
597 int CSCStubMatcher::nChambersWithLCT(int min_quality) const {
598  int result = 0;
599  const auto& chamber_ids = chamberIdsLCT();
600  for (const auto& id : chamber_ids) {
601  int nStubChamber = 0;
602  const auto& lcts = lctsInChamber(id);
603  for (const auto& lct : lcts) {
604  if (!lct.isValid())
605  continue;
606  if (lct.getQuality() >= min_quality) {
607  nStubChamber++;
608  }
609  }
610  if (nStubChamber > 0) {
611  ++result;
612  }
613  }
614  return result;
615 }
616 
617 int CSCStubMatcher::nChambersWithMPLCT(int min_quality) const {
618  int result = 0;
619  const auto& chamber_ids = chamberIdsMPLCT();
620  for (const auto& id : chamber_ids) {
621  int nStubChamber = 0;
622  const auto& mplcts = mplctsInChamber(id);
623  for (const auto& mplct : mplcts) {
624  if (!mplct.isValid())
625  continue;
626  if (mplct.getQuality() >= min_quality) {
627  nStubChamber++;
628  }
629  }
630  if (nStubChamber > 0) {
631  ++result;
632  }
633  }
634  return result;
635 }
636 
637 bool CSCStubMatcher::lctInChamber(const CSCDetId& id, const CSCCorrelatedLCTDigi& lct) const {
638  for (const auto& stub : lctsInChamber(id.rawId())) {
639  if (stub == lct)
640  return true;
641  }
642  return false;
643 }
644 
646  CSCDetId cscId(rawId);
647  CSCDetId keyId(cscId.endcap(), cscId.station(), cscId.ring(), cscId.chamber(), CSCConstants::KEY_CLCT_LAYER);
648  float fractional_strip = lct.getFractionalStrip();
649  // case ME1/1
650  if (cscId.station() == 1 and (cscId.ring() == 4 || cscId.ring() == 1)) {
651  int ring = 1; // Default to ME1/b
653  ring = 4; // Change to ME1/a if the HalfStrip Number exceeds the range of ME1/b
654  fractional_strip -= CSCConstants::NUM_STRIPS_ME1B;
655  }
656  CSCDetId cscId_(cscId.endcap(), cscId.station(), ring, cscId.chamber(), cscId.layer());
657  cscId = cscId_;
658  }
659  // regular cases
660  const auto& chamber = cscGeometry_->chamber(cscId);
661  const auto& layer_geo = chamber->layer(CSCConstants::KEY_CLCT_LAYER)->geometry();
662  // LCT::getKeyWG() also starts from 0
663  float wire = layer_geo->middleWireOfGroup(lct.getKeyWG() + 1);
664  const LocalPoint& csc_intersect = layer_geo->intersectionOfStripAndWire(fractional_strip, wire);
665  const GlobalPoint& csc_gp = cscGeometry_->idToDet(keyId)->surface().toGlobal(csc_intersect);
666  return csc_gp;
667 }
668 
670  chamber_to_clcts_all_.clear();
671  chamber_to_alcts_all_.clear();
672  chamber_to_lcts_all_.clear();
673  chamber_to_mplcts_all_.clear();
674 
675  chamber_to_clcts_.clear();
676  chamber_to_alcts_.clear();
677  chamber_to_lcts_.clear();
678  chamber_to_mplcts_.clear();
679 }
680 
682  const CSCCorrelatedLCTDigi& lct22,
683  CSCCorrelatedLCTDigiContainer& lcts_tmp) const {
684  int wg1 = lct11.getKeyWG();
685  int wg2 = lct22.getKeyWG();
686  int hs1 = lct11.getStrip();
687  int hs2 = lct22.getStrip();
688 
689  if (!(wg1 == wg2 || hs1 == hs2)) {
690  // flip the ALCTs
691  CSCCorrelatedLCTDigi lct12 = lct11;
692  lct12.setWireGroup(wg2);
693  lct12.setALCT(lct22.getALCT());
694  lct12.setCLCT(lct11.getCLCT());
695  lcts_tmp.push_back(lct12);
696 
697  CSCCorrelatedLCTDigi lct21 = lct22;
698  lct21.setWireGroup(wg1);
699  lct21.setALCT(lct11.getALCT());
700  lct21.setCLCT(lct22.getCLCT());
701  lcts_tmp.push_back(lct21);
702  }
703 }
const CSCALCTDigi & getALCT() const
int chamber() const
Definition: CSCDetId.h:62
std::set< unsigned int > chamberIdsAllMPLCT(int csc_type=MuonHitHelper::CSC_ALL) const
std::set< unsigned int > chamberIdsLCT(int csc_type=MuonHitHelper::CSC_ALL) const
std::vector< CSCCLCTDigi > CSCCLCTDigiContainer
int nChambersWithMPLCT(int min_quality=0) const
const edm::EventSetup & c
void setALCT(const CSCALCTDigi &alct)
void addGhostLCTs(const CSCCorrelatedLCTDigi &lct11, const CSCCorrelatedLCTDigi &lct22, CSCCorrelatedLCTDigiContainer &lctcontainer) const
float getFractionalStrip(uint16_t n=2) const
return the fractional strip
float zpositionOfLayer(unsigned int detid, int layer) const
uint16_t *__restrict__ id
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
CSCALCTDigi bestAlctInChamber(unsigned int) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
CSCStubMatcher(edm::ParameterSet const &iPS, edm::ConsumesCollector &&iC)
uint32_t const *__restrict__ Quality * quality
activeDets clear()
void matchMPLCTsToSimTrack(const CSCCorrelatedLCTDigiCollection &)
const CSCCLCTDigiContainer & clctsInChamber(unsigned int) const
all matching from a particular crossed chamber
int nChambersWithALCT(int min_quality=0) const
GlobalPoint getGlobalPosition(unsigned int rawId, const CSCCorrelatedLCTDigi &lct) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< CSCCorrelatedLCTDigi > CSCCorrelatedLCTDigiContainer
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
const CSCALCTDigiContainer & allALCTsInChamber(unsigned int) const
int layer() const
Definition: CSCDetId.h:56
const CSCCorrelatedLCTDigiContainer & mplctsInChamber(unsigned int) const
int nChambersWithCLCT(int min_quality=0) const
How many CSC chambers with matching stubs of some minimal quality did this SimTrack hit...
const CSCCLCTDigi & getCLCT() const
constexpr std::array< uint8_t, layerIndexSize > layer
static std::string const input
Definition: EdmProvDump.cc:47
tuple result
Definition: mps_fire.py:311
int endcap() const
Definition: CSCDetId.h:85
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::vector< CSCALCTDigi > CSCALCTDigiContainer
bool lctInChamber(const CSCDetId &id, const CSCCorrelatedLCTDigi &lct) const
int iEvent
Definition: GenABIO.cc:224
void setWireGroup(const uint16_t wiregroup)
set wiregroup number
uint16_t getKeyWG() const
return the key wire group. counts from 0.
std::set< unsigned int > chamberIdsMPLCT(int csc_type=MuonHitHelper::CSC_ALL) const
const CSCALCTDigiContainer & alctsInChamber(unsigned int) const
std::set< unsigned int > chamberIdsALCT(int csc_type=MuonHitHelper::CSC_ALL) const
const CSCCorrelatedLCTDigiContainer & allLCTsInChamber(unsigned int) const
void matchLCTsToSimTrack(const CSCCorrelatedLCTDigiCollection &)
def move
Definition: eostools.py:511
const CSCCorrelatedLCTDigiContainer & allMPLCTsInChamber(unsigned int) const
std::set< unsigned int > chamberIdsCLCT(int csc_type=MuonHitHelper::CSC_ALL) const
chamber detIds with matching stubs
std::set< unsigned int > chamberIdsAllCLCT(int csc_type=MuonHitHelper::CSC_ALL) const
crossed chamber detIds with not necessarily matching stubs
uint16_t getStrip(uint16_t n=2) const
return the key halfstrip from 0,159
Log< level::Info, false > LogInfo
int ring() const
Definition: CSCDetId.h:68
short int zendcap() const
Definition: CSCDetId.h:91
void matchALCTsToSimTrack(const CSCALCTDigiCollection &)
static int minLayerId()
Definition: CSCDetId.h:242
void matchCLCTsToSimTrack(const CSCCLCTDigiCollection &)
std::set< unsigned int > chamberIdsAllLCT(int csc_type=MuonHitHelper::CSC_ALL) const
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int nChambersWithLCT(int min_quality=0) const
CSCCLCTDigi bestClctInChamber(unsigned int) const
best matching from a particular crossed chamber
double a
Definition: hdecay.h:119
string end
Definition: dataset.py:937
CSCCorrelatedLCTDigi bestLctInChamber(unsigned int) const
int station() const
Definition: CSCDetId.h:79
tuple cout
Definition: gather_cfg.py:144
void match(const SimTrack &t, const SimVertex &v)
do the matching
const CSCCLCTDigiContainer & allCLCTsInChamber(unsigned int) const
all stubs (not necessarily matching) from a particular crossed chamber
void setCLCT(const CSCCLCTDigi &clct)
static int maxLayerId()
Definition: CSCDetId.h:243
tuple size
Write out results.
const CSCCorrelatedLCTDigiContainer & lctsInChamber(unsigned int) const
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
initialize the event
std::set< unsigned int > chamberIdsAllALCT(int csc_type=MuonHitHelper::CSC_ALL) const