Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryObjectSorter.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryObjectSorter.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-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 #pragma once
10 
11 // clang-format off
12 // Workaround for building on clang+libstdc++. Must always be first
14 // clang-format on
15 
19 
20 #include <functional>
21 #include <memory>
22 
23 namespace Acts {
24 
25 template <class T>
27  public:
32 
39  bool operator()(T one, T two) const {
43  // switch the binning value
44  // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
45  switch (m_binningValue) {
46  // compare on x
47  case binX: {
48  return one.x() < two.x();
49  }
50  // compare on y
51  case binY: {
52  return one.y() < two.y();
53  }
54  // compare on z
55  case binZ: {
56  return one.z() < two.z();
57  }
58  // compare on r
59  case binR: {
60  return perp(one) < perp(two);
61  }
62  // compare on phi
63  case binPhi: {
64  return phi(one) < phi(two);
65  }
66  // compare on eta
67  case binEta: {
68  return eta(one) < eta(two);
69  }
70  // default for the moment
71  default: {
72  return one.norm() < two.norm();
73  }
74  }
75  }
76 
78 
79  private:
81 };
82 
84 template <class T>
86  public:
92  : m_binningValue(bValue),
93  m_reference(reference),
94  m_refR(VectorHelpers::perp(reference)),
95  m_refPhi(VectorHelpers::phi(reference)),
96  m_refEta(VectorHelpers::eta(reference)) {}
97 
104  bool operator()(T one, T two) const {
108  // switch the binning value
109  // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
110  switch (m_binningValue) {
111  // compare on diff x
112  case binX: {
113  double diffOneX = one.x() - m_reference.x();
114  double diffTwoX = two.x() - m_reference.x();
115  return std::abs(diffOneX) < std::abs(diffTwoX);
116  }
117  // compare on diff y
118  case binY: {
119  double diffOneY = one.y() - m_reference.y();
120  double diffTwoY = two.y() - m_reference.y();
121  return std::abs(diffOneY) < std::abs(diffTwoY);
122  }
123  // compare on diff z
124  case binZ: {
125  double diffOneZ = one.z() - m_reference.z();
126  double diffTwoZ = two.z() - m_reference.z();
127  return std::abs(diffOneZ) < std::abs(diffTwoZ);
128  }
129  // compare on r
130  case binR: {
131  double diffOneR = perp(one) - m_refR;
132  double diffTwoR = perp(two) - m_refR;
133  return std::abs(diffOneR) < std::abs(diffTwoR);
134  }
135  // compare on phi /// @todo add cyclic value
136  case binPhi: {
137  double diffOnePhi = phi(one) - m_refPhi;
138  double diffTwoPhi = phi(two) - m_refPhi;
139  return std::abs(diffOnePhi) < std::abs(diffTwoPhi);
140  }
141  // compare on eta
142  case binEta: {
143  double diffOneEta = eta(one) - m_refEta;
144  double diffTwoEta = eta(two) - m_refEta;
145  return std::abs(diffOneEta) < std::abs(diffTwoEta);
146  }
147  // default for the moment
148  default: {
149  T diffOne(one - m_reference);
150  T diffTwo(two - m_reference);
151  return diffOne.mag2() < diffTwo.mag2();
152  }
153  }
154  }
155 
156  private:
159  double m_refR;
160  double m_refPhi;
161  double m_refEta;
162 };
163 
164 template <class T>
166  public:
173  std::shared_ptr<const Transform3> transform = nullptr)
174  : m_context(gctx),
175  m_objectSorter(bValue),
176  m_transform(std::move(transform)) {}
177 
184  bool operator()(T one, T two) const {
185  // get the pos one / pos two
186  Vector3 posOne =
188  ? m_transform->inverse() *
189  one->binningPosition(m_context, m_objectSorter.binningValue())
190  : one->binningPosition(m_context, m_objectSorter.binningValue());
191  Vector3 posTwo =
193  ? m_transform->inverse() *
194  two->binningPosition(m_context, m_objectSorter.binningValue())
195  : two->binningPosition(m_context, m_objectSorter.binningValue());
196  // now call the distance sorter
197  return m_objectSorter.operator()(posOne, posTwo);
198  }
199 
200  protected:
201  std::reference_wrapper<const GeometryContext> m_context;
203  std::shared_ptr<const Transform3> m_transform;
204 };
205 } // namespace Acts