CoaxialConesImplementation.h 8.13 KB
Newer Older
1
/// @file CoaxialConesImplementation.h
2
/// @author Raman Sehgal (raman.sehgal@cern.ch)
3
4
5
6
7
8

#ifndef VECGEOM_VOLUMES_KERNEL_COAXIALCONESIMPLEMENTATION_H_
#define VECGEOM_VOLUMES_KERNEL_COAXIALCONESIMPLEMENTATION_H_

#include "base/Vector3D.h"
#include "volumes/CoaxialConesStruct.h"
9
#include "volumes/kernel/ConeImplementation.h"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "volumes/kernel/GenericKernels.h"
#include <VecCore/VecCore>

#include <cstdio>

namespace vecgeom {

VECGEOM_DEVICE_FORWARD_DECLARE(struct CoaxialConesImplementation;);
VECGEOM_DEVICE_DECLARE_CONV(struct, CoaxialConesImplementation);

inline namespace VECGEOM_IMPL_NAMESPACE {

class PlacedCoaxialCones;
template <typename T>
struct CoaxialConesStruct;
class UnplacedCoaxialCones;

struct CoaxialConesImplementation {

  using PlacedShape_t    = PlacedCoaxialCones;
  using UnplacedStruct_t = CoaxialConesStruct<double>;
  using UnplacedVolume_t = UnplacedCoaxialCones;

  VECCORE_ATT_HOST_DEVICE
  static void PrintType()
  {
    //  printf("SpecializedCoaxialCones<%i, %i>", transCodeT, rotCodeT);
  }

  template <typename Stream>
  static void PrintType(Stream &st, int transCodeT = translation::kGeneric, int rotCodeT = rotation::kGeneric)
  {
    st << "SpecializedCoaxialCones<" << transCodeT << "," << rotCodeT << ">";
  }

  template <typename Stream>
  static void PrintImplementationType(Stream &st)
  {
    (void)st;
    // st << "CoaxialConesImplementation<" << transCodeT << "," << rotCodeT << ">";
  }

  template <typename Stream>
  static void PrintUnplacedType(Stream &st)
  {
    (void)st;
    // TODO: this is wrong
    // st << "UnplacedCoaxialCones";
  }

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  template <typename Real_v, bool ForLowerZ>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static typename vecCore::Mask_v<Real_v> IsOnRing(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point)
  {

    using Bool_v = typename vecCore::Mask_v<Real_v>;
    Bool_v onRing(false);
    for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
      onRing |= (ConeImplementation<ConeTypes::UniversalCone>::template IsOnRing<Real_v, true, ForLowerZ>(
                     *coaxialcones.fConeStructVector[i], point) ||
                 ConeImplementation<ConeTypes::UniversalCone>::template IsOnRing<Real_v, false, ForLowerZ>(
                     *coaxialcones.fConeStructVector[i], point));
    }

    return onRing;
  }

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  template <typename Real_v, typename Bool_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void Contains(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Bool_v &inside)
  {
    Bool_v unused, outside;
    GenericKernelForContainsAndInside<Real_v, Bool_v, false>(coaxialcones, point, unused, outside);
    inside = !outside;
  }

  // BIG QUESTION: DO WE WANT TO GIVE ALL 3 TEMPLATE PARAMETERS
  // -- OR -- DO WE WANT TO DEDUCE Bool_v, Index_t from Real_v???
  template <typename Real_v, typename Inside_t>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void Inside(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Inside_t &inside)
  {

    using Bool_v       = vecCore::Mask_v<Real_v>;
    using InsideBool_v = vecCore::Mask_v<Inside_t>;
    Bool_v completelyinside, completelyoutside;
    GenericKernelForContainsAndInside<Real_v, Bool_v, true>(coaxialcones, point, completelyinside, completelyoutside);
    inside = EInside::kSurface;
    vecCore::MaskedAssign(inside, (InsideBool_v)completelyoutside, Inside_t(EInside::kOutside));
    vecCore::MaskedAssign(inside, (InsideBool_v)completelyinside, Inside_t(EInside::kInside));
  }

  template <typename Real_v, typename Bool_v, bool ForInside>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void GenericKernelForContainsAndInside(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point,
                                                Bool_v &completelyinside, Bool_v &completelyoutside)
  {
    /* TODO : Logic to check where the point is inside or not.
    **
    ** if ForInside is false then it will only check if the point is outside,
    ** and is used by Contains function
    **
    ** if ForInside is true then it will check whether the point is inside or outside,
    ** and if neither inside nor outside then it is on the surface.
    ** and is used by Inside function
    */
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    completelyinside  = Bool_v(false);
    completelyoutside = Bool_v(true);
    Bool_v onSurf(false);

    for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
      Bool_v compIn(false);
      Bool_v compOut(false);

      ConeHelpers<Real_v, ConeTypes::UniversalCone>::template GenericKernelForContainsAndInside<ForInside>(
          *coaxialcones.fConeStructVector[i], point, compIn, compOut);
      if (ForInside) {
        completelyinside |= compIn;
        if (vecCore::MaskFull(completelyinside)) {
          completelyoutside = !completelyinside;
          return;
        }

        onSurf |= (!compIn && !compOut);
        if (vecCore::MaskFull(onSurf)) {
          completelyoutside = !onSurf;
          return;
        }
      } else {

        completelyoutside &= compOut;
      }
    }
147
148
149
150
151
152
  }

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void DistanceToIn(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point,
153
                           Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance)
154
155
  {
    /* TODO :  Logic to calculate Distance from outside point to the CoaxialCones surface */
156

157
158
159
160
161
    distance = kInfLength;
    for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
      Real_v dist(kInfLength);
      ConeImplementation<ConeTypes::UniversalCone>::template DistanceToIn<Real_v>(*coaxialcones.fConeStructVector[i],
                                                                                  point, direction, stepMax, dist);
162

163
164
      vecCore::MaskedAssign(distance, dist < distance, dist);
    }
165
166
167
168
169
170
  }

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void DistanceToOut(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point,
171
                            Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance)
172
173
  {
    /* TODO :  Logic to calculate Distance from inside point to the CoaxialCones surface */
174
175
176
177
178
179
180
181
    distance = -1.;
    for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
      Real_v dist(kInfLength);
      ConeImplementation<ConeTypes::UniversalCone>::template DistanceToOut<Real_v>(*coaxialcones.fConeStructVector[i],
                                                                                   point, direction, stepMax, dist);

      vecCore::MaskedAssign(distance, dist > distance, dist);
    }
182
183
184
185
186
187
188
  }

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void SafetyToIn(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Real_v &safety)
  {
189
190
191
192
193
194
195
196
197
    /* TODO :  Logic to calculate Safety from outside point to the CoaxialCones surface */
    safety = kInfLength;
    for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
      Real_v safeDist(kInfLength);
      ConeImplementation<ConeTypes::UniversalCone>::template SafetyToIn<Real_v>(*coaxialcones.fConeStructVector[i],
                                                                                point, safeDist);

      vecCore::MaskedAssign(safety, safeDist < safety, safeDist);
    }
198
199
200
201
202
203
204
205
  }

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  static void SafetyToOut(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Real_v &safety)
  {
    /* TODO :  Logic to calculate Safety from inside point to the CoaxialCones surface */
206
207
208
209
210
211
212
213
    safety = Real_v(-1.);
    for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
      Real_v safeDist(kInfLength);
      ConeImplementation<ConeTypes::UniversalCone>::template SafetyToOut<Real_v>(*coaxialcones.fConeStructVector[i],
                                                                                 point, safeDist);

      vecCore::MaskedAssign(safety, safeDist > safety, safeDist);
    }
214
215
216
217
218
219
  }
};
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom

#endif // VECGEOM_VOLUMES_KERNEL_COAXIALCONESIMPLEMENTATION_H_