EIC 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 
18 
19 #include <functional>
20 
21 namespace Acts {
22 
23 template <class T>
24 class ObjectSorterT : public std::binary_function<T, T, bool> {
25  public:
31 
38  bool operator()(T one, T two) const {
42  // switch the binning value
43  // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
44  switch (m_binningValue) {
45  // compare on x
46  case binX: {
47  return (one.x() < two.x());
48  }
49  // compare on y
50  case binY: {
51  return (one.y() < two.y());
52  }
53  // compare on z
54  case binZ: {
55  return (one.z() < two.z());
56  }
57  // compare on r
58  case binR: {
59  return (perp(one) < perp(two));
60  }
61  // compare on phi
62  case binPhi: {
63  return (phi(one) < phi(two));
64  }
65  // compare on eta
66  case binEta: {
67  return (eta(one) < eta(two));
68  }
69  // default for the moment
70  default: {
71  return (one.norm() < two.norm());
72  }
73  }
74  }
75 
77 
78  private:
80 };
81 
83 template <class T>
84 class DistanceSorterT : public std::binary_function<T, T, bool> {
85  public:
91  : m_binningValue(bValue),
92  m_reference(reference),
93  m_refR(VectorHelpers::perp(reference)),
94  m_refPhi(VectorHelpers::phi(reference)),
95  m_refEta(VectorHelpers::eta(reference)) {}
96 
103  bool operator()(T one, T two) const {
107  // switch the binning value
108  // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
109  switch (m_binningValue) {
110  // compare on diff x
111  case binX: {
112  double diffOneX = one.x() - m_reference.x();
113  double diffTwoX = two.x() - m_reference.x();
114  return (diffOneX * diffOneX < diffTwoX * diffTwoX);
115  }
116  // compare on diff y
117  case binY: {
118  double diffOneY = one.y() - m_reference.y();
119  double diffTwoY = two.y() - m_reference.y();
120  return (diffOneY * diffOneY < diffTwoY * diffTwoY);
121  }
122  // compare on diff z
123  case binZ: {
124  double diffOneZ = one.z() - m_reference.z();
125  double diffTwoZ = two.z() - m_reference.z();
126  return (diffOneZ * diffOneZ < diffTwoZ * diffTwoZ);
127  }
128  // compare on r
129  case binR: {
130  double diffOneR = perp(one) - m_refR;
131  double diffTwoR = perp(two) - m_refR;
132  return (diffOneR * diffOneR < diffTwoR * diffTwoR);
133  }
134  // compare on phi /// @todo add cyclic value
135  case binPhi: {
136  double diffOnePhi = phi(one) - m_refPhi;
137  double diffTwoPhi = phi(two) - m_refPhi;
138  return (diffOnePhi * diffOnePhi < diffTwoPhi * diffTwoPhi);
139  }
140  // compare on eta
141  case binEta: {
142  double diffOneEta = eta(one) - m_refEta;
143  double diffTwoEta = eta(two) - m_refEta;
144  return (diffOneEta * diffOneEta < diffTwoEta * diffTwoEta);
145  }
146  // default for the moment
147  default: {
148  T diffOne(one - m_reference);
149  T diffTwo(two - m_reference);
150  return (diffOne.mag2() < diffTwo.mag2());
151  }
152  }
153  }
154 
155  private:
158  double m_refR;
159  double m_refPhi;
160  double m_refEta;
161 };
162 
163 template <class T>
164 class GeometryObjectSorterT : public std::binary_function<T, T, bool> {
165  public:
171  std::shared_ptr<const Transform3D> transform = nullptr)
172  : m_context(gctx),
173  m_objectSorter(bValue),
174  m_transform(std::move(transform)) {}
175 
182  bool operator()(T one, T two) const {
183  // get the pos one / pos two
184  Vector3D posOne =
186  ? m_transform->inverse() *
187  one->binningPosition(m_context, m_objectSorter.binningValue())
188  : one->binningPosition(m_context, m_objectSorter.binningValue());
189  Vector3D posTwo =
191  ? m_transform->inverse() *
192  two->binningPosition(m_context, m_objectSorter.binningValue())
193  : two->binningPosition(m_context, m_objectSorter.binningValue());
194  // now call the distance sorter
195  return m_objectSorter.operator()(posOne, posTwo);
196  }
197 
198  protected:
199  std::reference_wrapper<const GeometryContext> m_context;
201  std::shared_ptr<const Transform3D> m_transform;
202 };
203 } // namespace Acts