ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SeedFilter.ipp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SeedFilter.ipp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <utility>
10 
11 namespace Acts {
12 // constructor
13 template <typename external_spacepoint_t>
17  : m_cfg(config), m_experimentCuts(expCuts) {}
18 
19 // function to filter seeds based on all seeds with same bottom- and
20 // middle-spacepoint.
21 // return vector must contain weight of each seed
22 template <typename external_spacepoint_t>
23 std::vector<std::pair<
24  float, std::unique_ptr<const InternalSeed<external_spacepoint_t>>>>
28  std::vector<const InternalSpacePoint<external_spacepoint_t>*>& topSpVec,
29  std::vector<float>& invHelixDiameterVec,
30  std::vector<float>& impactParametersVec, float zOrigin) const {
31  std::vector<std::pair<
32  float, std::unique_ptr<const InternalSeed<external_spacepoint_t>>>>
33  selectedSeeds;
34 
35  for (size_t i = 0; i < topSpVec.size(); i++) {
36  // if two compatible seeds with high distance in r are found, compatible
37  // seeds span 5 layers
38  // -> very good seed
39  std::vector<float> compatibleSeedR;
40 
41  float invHelixDiameter = invHelixDiameterVec[i];
42  float lowerLimitCurv = invHelixDiameter - m_cfg.deltaInvHelixDiameter;
43  float upperLimitCurv = invHelixDiameter + m_cfg.deltaInvHelixDiameter;
44  float currentTop_r = topSpVec[i]->radius();
45  float impact = impactParametersVec[i];
46 
47  float weight = -(impact * m_cfg.impactWeightFactor);
48  for (size_t j = 0; j < topSpVec.size(); j++) {
49  if (i == j) {
50  continue;
51  }
52  // compared top SP should have at least deltaRMin distance
53  float otherTop_r = topSpVec[j]->radius();
54  float deltaR = currentTop_r - otherTop_r;
55  if (std::abs(deltaR) < m_cfg.deltaRMin) {
56  continue;
57  }
58  // curvature difference within limits?
59  // TODO: how much slower than sorting all vectors by curvature
60  // and breaking out of loop? i.e. is vector size large (e.g. in jets?)
61  if (invHelixDiameterVec[j] < lowerLimitCurv) {
62  continue;
63  }
64  if (invHelixDiameterVec[j] > upperLimitCurv) {
65  continue;
66  }
67  bool newCompSeed = true;
68  for (float previousDiameter : compatibleSeedR) {
69  // original ATLAS code uses higher min distance for 2nd found compatible
70  // seed (20mm instead of 5mm)
71  // add new compatible seed only if distance larger than rmin to all
72  // other compatible seeds
73  if (std::abs(previousDiameter - otherTop_r) < m_cfg.deltaRMin) {
74  newCompSeed = false;
75  break;
76  }
77  }
78  if (newCompSeed) {
79  compatibleSeedR.push_back(otherTop_r);
80  weight += m_cfg.compatSeedWeight;
81  }
82  if (compatibleSeedR.size() >= m_cfg.compatSeedLimit) {
83  break;
84  }
85  }
86  if (m_experimentCuts != nullptr) {
87  // add detector specific considerations on the seed weight
88  weight += m_experimentCuts->seedWeight(bottomSP, middleSP, *topSpVec[i]);
89  // discard seeds according to detector specific cuts (e.g.: weight)
90  if (!m_experimentCuts->singleSeedCut(weight, bottomSP, middleSP,
91  *topSpVec[i])) {
92  continue;
93  }
94  }
95  selectedSeeds.push_back(std::make_pair(
97  bottomSP, middleSP, *topSpVec[i], zOrigin)));
98  }
99  return selectedSeeds;
100 }
101 
102 // after creating all seeds with a common middle space point, filter again
103 template <typename external_spacepoint_t>
105  std::vector<std::pair<
106  float, std::unique_ptr<const InternalSeed<external_spacepoint_t>>>>&
107  seedsPerSpM,
108  std::vector<Seed<external_spacepoint_t>>& outVec) const {
109  // sort by weight and iterate only up to configured max number of seeds per
110  // middle SP
111  std::sort((seedsPerSpM.begin()), (seedsPerSpM.end()),
112  [](const std::pair<float, std::unique_ptr<const Acts::InternalSeed<
113  external_spacepoint_t>>>& i1,
114  const std::pair<float, std::unique_ptr<const Acts::InternalSeed<
115  external_spacepoint_t>>>& i2) {
116  return i1.first > i2.first;
117  });
118  if (m_experimentCuts != nullptr) {
119  seedsPerSpM = m_experimentCuts->cutPerMiddleSP(std::move(seedsPerSpM));
120  }
121  unsigned int maxSeeds = seedsPerSpM.size();
122  if (maxSeeds > m_cfg.maxSeedsPerSpM) {
123  maxSeeds = m_cfg.maxSeedsPerSpM + 1;
124  }
125  auto itBegin = seedsPerSpM.begin();
126  auto it = seedsPerSpM.begin();
127  // default filter removes the last seeds if maximum amount exceeded
128  // ordering by weight by filterSeeds_2SpFixed means these are the lowest
129  // weight seeds
130  for (; it < itBegin + maxSeeds; ++it) {
131  outVec.push_back(Seed<external_spacepoint_t>(
132  (*it).second->sp[0]->sp(), (*it).second->sp[1]->sp(),
133  (*it).second->sp[2]->sp(), (*it).second->z()));
134  }
135 }
136 
137 } // namespace Acts