ECCE @ 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 
10 // GeometryObjectSorter.h, Acts project
12 
13 #pragma once
14 
15 // Workaround for building on clang+libstdc++
17 
18 #include <functional>
21 
22 namespace Acts {
23 
24 // @class ObjectSorterT
26 template <class T>
27 class ObjectSorterT : public std::binary_function<T, T, bool> {
28  public:
34 
41  bool operator()(T one, T two) const {
45  // switch the binning value
46  // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
47  switch (m_binningValue) {
48  // compare on x
49  case binX: {
50  return (one.x() < two.x());
51  }
52  // compare on y
53  case binY: {
54  return (one.y() < two.y());
55  }
56  // compare on z
57  case binZ: {
58  return (one.z() < two.z());
59  }
60  // compare on r
61  case binR: {
62  return (perp(one) < perp(two));
63  }
64  // compare on phi
65  case binPhi: {
66  return (phi(one) < phi(two));
67  }
68  // compare on eta
69  case binEta: {
70  return (eta(one) < eta(two));
71  }
72  // default for the moment
73  default: {
74  return (one.norm() < two.norm());
75  }
76  }
77  }
78 
80 
81  private:
83 };
84 
88 template <class T>
89 class DistanceSorterT : public std::binary_function<T, T, bool> {
90  public:
96  : m_binningValue(bValue),
97  m_reference(reference),
98  m_refR(VectorHelpers::perp(reference)),
99  m_refPhi(VectorHelpers::phi(reference)),
100  m_refEta(VectorHelpers::eta(reference)) {}
101 
108  bool operator()(T one, T two) const {
112  // switch the binning value
113  // - binX, binY, binZ, binR, binPhi, binRPhi, binH, binEta
114  switch (m_binningValue) {
115  // compare on diff x
116  case binX: {
117  double diffOneX = one.x() - m_reference.x();
118  double diffTwoX = two.x() - m_reference.x();
119  return (diffOneX * diffOneX < diffTwoX * diffTwoX);
120  }
121  // compare on diff y
122  case binY: {
123  double diffOneY = one.y() - m_reference.y();
124  double diffTwoY = two.y() - m_reference.y();
125  return (diffOneY * diffOneY < diffTwoY * diffTwoY);
126  }
127  // compare on diff z
128  case binZ: {
129  double diffOneZ = one.z() - m_reference.z();
130  double diffTwoZ = two.z() - m_reference.z();
131  return (diffOneZ * diffOneZ < diffTwoZ * diffTwoZ);
132  }
133  // compare on r
134  case binR: {
135  double diffOneR = perp(one) - m_refR;
136  double diffTwoR = perp(two) - m_refR;
137  return (diffOneR * diffOneR < diffTwoR * diffTwoR);
138  }
139  // compare on phi /// @todo add cyclic value
140  case binPhi: {
141  double diffOnePhi = phi(one) - m_refPhi;
142  double diffTwoPhi = phi(two) - m_refPhi;
143  return (diffOnePhi * diffOnePhi < diffTwoPhi * diffTwoPhi);
144  }
145  // compare on eta
146  case binEta: {
147  double diffOneEta = eta(one) - m_refEta;
148  double diffTwoEta = eta(two) - m_refEta;
149  return (diffOneEta * diffOneEta < diffTwoEta * diffTwoEta);
150  }
151  // default for the moment
152  default: {
153  T diffOne(one - m_reference);
154  T diffTwo(two - m_reference);
155  return (diffOne.mag2() < diffTwo.mag2());
156  }
157  }
158  }
159 
160  private:
163  double m_refR;
164  double m_refPhi;
165  double m_refEta;
166 };
167 
170 template <class T>
171 class GeometryObjectSorterT : public std::binary_function<T, T, bool> {
172  public:
178  std::shared_ptr<const Transform3D> transform = nullptr)
179  : m_context(gctx),
180  m_objectSorter(bValue),
181  m_transform(std::move(transform)) {}
182 
189  bool operator()(T one, T two) const {
190  // get the pos one / pos two
191  Vector3D posOne =
193  ? m_transform->inverse() *
194  one->binningPosition(m_context, m_objectSorter.binningValue())
195  : one->binningPosition(m_context, m_objectSorter.binningValue());
196  Vector3D posTwo =
198  ? m_transform->inverse() *
199  two->binningPosition(m_context, m_objectSorter.binningValue())
200  : two->binningPosition(m_context, m_objectSorter.binningValue());
201  // now call the distance sorter
202  return m_objectSorter.operator()(posOne, posTwo);
203  }
204 
205  protected:
206  std::reference_wrapper<const GeometryContext> m_context;
208  std::shared_ptr<const Transform3D> m_transform;
209 };
210 } // namespace Acts