File: ParaboloidStruct.h

package info (click to toggle)
vecgeom 1.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,928 kB
  • sloc: cpp: 88,717; ansic: 6,894; python: 1,035; sh: 582; sql: 538; makefile: 29
file content (120 lines) | stat: -rw-r--r-- 3,687 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
120
// This file is part of VecGeom and is distributed under the
// conditions in the file LICENSE.txt in the top directory.
// For the full list of authors see CONTRIBUTORS.txt and `git log`.

/// Declaration of a struct with data members for the UnplacedParaboloid class
/// @file volumes/ParaboloidStruct.h
/// @author Raman Sehgal

#ifndef VECGEOM_VOLUMES_PARABOLOIDSTRUCT_H_
#define VECGEOM_VOLUMES_PARABOLOIDSTRUCT_H_
#include "VecGeom/base/Global.h"

namespace vecgeom {

inline namespace VECGEOM_IMPL_NAMESPACE {

/// Struct encapsulating data members of the unplaced paraboloid
template <typename T = double>
struct ParaboloidStruct {
  T fRlo; ///< Radius of the circle at z = -dz
  T fRhi; ///< Radius of the circle at z = +dz
  T fDz;  ///< Half size in z

  // Values computed from parameters, to be cached
  T fDx;   ///< Half size of the bounding box in x
  T fDy;   ///< Half size of the bounding box in y
  T fA;    ///< Parameter a in the equation of paraboloid: z = a * (x^2 + y^2) + b
  T fInvA; ///< Inverted value of a
  T fA2;   ///< Parameter a squared
  T fB;    ///< Parameter b in the equation of paraboloid: z = a * (x^2 + y^2) + b
  T fB2;   ///< Parameter b squared
  T fInvB; ///< Inverted value of b
  T fK1;   ///< Cached value: 0.5 * (Rhi^2 - Rlo^2) / Dz
  T fK2;   ///< Cached value: 0.5 * (Rhi^2 + Rlo^2)
  T fRlo2; ///< Radius of the circle at z = -dz squared
  T fRhi2; ///< Radius of the circle at z = +dz squared

  /// Default constructor
  VECCORE_ATT_HOST_DEVICE
  ParaboloidStruct()
      : fRlo(0.), fRhi(0.), fDz(0.), fA(0.), fInvA(0.), fB(0.), fInvB(0.), fK1(0.), fK2(0.), fRlo2(0.), fRhi2(0.)
  {
    CalculateCached();
  }

  /// Constructor
  /// @param rlo Radius of the circle at z = -dz
  /// @param rhi Radius of the circle at z = +dz
  /// @param dz Half size in z
  VECCORE_ATT_HOST_DEVICE
  ParaboloidStruct(const T rlo, const T rhi, const T dz)
      : fRlo(rlo), fRhi(rhi), fDz(dz), fA(0.), fInvA(0.), fB(0.), fInvB(0.), fK1(0.), fK2(0.), fRlo2(0.), fRhi2(0.)
  {
    CalculateCached();
  }

  /// Sets data members
  VECCORE_ATT_HOST_DEVICE
  void CalculateCached()
  {
    fRlo2 = fRlo * fRlo;
    fRhi2 = fRhi * fRhi;
    T dd  = 1. / (fRhi2 - fRlo2);
    fA    = 2. * fDz * dd;
    fB    = -fDz * (fRlo2 + fRhi2) * dd;
    fK1   = (fRhi2 - fRlo2) * 0.5 / fDz;
    fK2   = (fRhi2 + fRlo2) * 0.5;
    fInvA = 1 / fA;
    fInvB = 1 / fB;
    fA2   = fA * fA;
    fB2   = fB * fB;
    ComputeBoundingBox();
  }

  /// Sets fDx and fDy
  VECCORE_ATT_HOST_DEVICE
  void ComputeBoundingBox()
  {
    fDx = Max(fRhi, fRlo);
    fDy = fDx;
  }

  /// Sets parameters of the paraboloid
  /// @param rlo Radius of the circle at z = -dz
  /// @param rhi Radius of the circle at z = +dz
  /// @param dz Half size in z
  VECCORE_ATT_HOST_DEVICE
  void SetRloAndRhiAndDz(const T rlo, const T rhi, const T dz)
  {

    if ((rlo < 0) || (rhi < 0) || (dz <= 0)) {

      printf("Error SetRloAndRhiAndDz: invalid dimensions. Check (rlo>=0) (rhi>=0) (dz>0)\n");
      return;
    }
    fRlo = rlo;
    fRhi = rhi;
    fDz  = dz;
    CalculateCached();
  }

  /// Sets the raduis of the circle at z = -dz
  /// @param val Value of the radius
  VECCORE_ATT_HOST_DEVICE
  void SetRlo(const T rlo) { SetRloAndRhiAndDz(rlo, fRhi, fDz); }

  /// Sets the raduis of the circle at z = +dz
  /// @param val Value of the radius
  VECCORE_ATT_HOST_DEVICE
  void SetRhi(const T rhi) { SetRloAndRhiAndDz(fRlo, rhi, fDz); }

  /// Sets the half size in z
  /// @param val Value of the half size in z
  VECCORE_ATT_HOST_DEVICE
  void SetDz(const T dz) { SetRloAndRhiAndDz(fRlo, fRhi, dz); }
};
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom

#endif