CMS 3D CMS Logo

StubAssociation.cc
Go to the documentation of this file.
2 
3 #include <map>
4 #include <vector>
5 #include <utility>
6 #include <numeric>
7 
8 using namespace std;
9 
10 namespace tt {
11 
12  // insert a TPPtr and its associated collection of TTstubRefs into the underlayering maps
13  void StubAssociation::insert(const TPPtr& tpPtr, const vector<TTStubRef>& ttSTubRefs) {
14  mapTPPtrsTTStubRefs_.insert({tpPtr, ttSTubRefs});
15  for (const TTStubRef& ttSTubRef : ttSTubRefs)
16  mapTTStubRefsTPPtrs_[ttSTubRef].push_back(tpPtr);
17  }
18 
19  // returns collection of TPPtrs associated to given TTstubRef
20  vector<TPPtr> StubAssociation::findTrackingParticlePtrs(const TTStubRef& ttStubRef) const {
21  const auto it = mapTTStubRefsTPPtrs_.find(ttStubRef);
22  const vector<TPPtr> res = it != mapTTStubRefsTPPtrs_.end() ? it->second : emptyTPPtrs_;
23  return res;
24  }
25 
26  // returns collection of TTStubRefs associated to given TPPtr
27  vector<TTStubRef> StubAssociation::findTTStubRefs(const TPPtr& tpPtr) const {
28  const auto it = mapTPPtrsTTStubRefs_.find(tpPtr);
29  return it != mapTPPtrsTTStubRefs_.end() ? it->second : emptyTTStubRefs_;
30  }
31 
32  // Get all TPs that are matched to these stubs in at least 'tpMinLayers' layers and 'tpMinLayersPS' ps layers
33  vector<TPPtr> StubAssociation::associate(const vector<TTStubRef>& ttStubRefs) const {
34  // count associated layer for each TP
35  map<TPPtr, set<int>> m;
36  map<TPPtr, set<int>> mPS;
37  for (const TTStubRef& ttStubRef : ttStubRefs) {
38  for (const TPPtr& tpPtr : findTrackingParticlePtrs(ttStubRef)) {
39  const int layerId = setup_->layerId(ttStubRef);
40  m[tpPtr].insert(layerId);
41  if (setup_->psModule(ttStubRef))
42  mPS[tpPtr].insert(layerId);
43  }
44  }
45  // count matched TPs
46  auto acc = [this](int sum, const pair<TPPtr, set<int>>& p) {
47  return sum + ((int)p.second.size() < setup_->tpMinLayers() ? 0 : 1);
48  };
49  const int nTPs = accumulate(m.begin(), m.end(), 0, acc);
50  vector<TPPtr> tpPtrs;
51  tpPtrs.reserve(nTPs);
52  // fill and return matched TPs
53  for (const auto& p : m)
54  if ((int)p.second.size() >= setup_->tpMinLayers() && (int)mPS[p.first].size() >= setup_->tpMinLayersPS())
55  tpPtrs.push_back(p.first);
56  return tpPtrs;
57  }
58 
59  // Get all TPs that are matched to these stubs in at least 'tpMinLayers' layers and 'tpMinLayersPS' ps layers with not more then 'tpMaxBadStubs2S' not associated 2S stubs and not more then 'tpMaxBadStubsPS' associated PS stubs
60  std::vector<TPPtr> StubAssociation::associateFinal(const std::vector<TTStubRef>& ttStubRefs) const {
61  // Get all TPs that are matched to these stubs in at least 'tpMinLayers' layers and 'tpMinLayersPS' ps layers
62  vector<TPPtr> tpPtrs = associate(ttStubRefs);
63  // remove TPs with more then 'tpMaxBadStubs2S' not associated 2S stubs and more then 'tpMaxBadStubsPS' not associated PS stubs
64  auto check = [this, &ttStubRefs](const TPPtr& tpPtr) {
65  int bad2S(0);
66  int badPS(0);
67  for (const TTStubRef& ttStubRef : ttStubRefs) {
68  const vector<TPPtr>& tpPtrs = findTrackingParticlePtrs(ttStubRef);
69  if (find(tpPtrs.begin(), tpPtrs.end(), tpPtr) == tpPtrs.end())
70  setup_->psModule(ttStubRef) ? badPS++ : bad2S++;
71  }
72  if (badPS > setup_->tpMaxBadStubsPS() || bad2S > setup_->tpMaxBadStubs2S())
73  return true;
74  return false;
75  };
76  tpPtrs.erase(remove_if(tpPtrs.begin(), tpPtrs.end(), check), tpPtrs.end());
77  return tpPtrs;
78  }
79 
80 } // namespace tt
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
Definition: Electron.h:6
Definition: TTTypes.h:54
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50