Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
ParameterTraits.hpp
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file ParameterTraits.hpp
1
// This file is part of the Acts project.
2
//
3
// Copyright (C) 2016-2020 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
#include "
Acts/Definitions/TrackParametrization.hpp
"
12
13
#include <algorithm>
14
#include <cmath>
15
#include <cstddef>
16
17
namespace
Acts {
18
namespace
detail {
19
21
struct
UnrestrictedParameterTraits
{
23
static
constexpr
bool
may_modify_value
=
false
;
24
26
template
<
typename
value_t>
27
static
constexpr
const
value_t
&
getValue
(
const
value_t
&
value
) {
28
return
value
;
29
}
31
template
<
typename
value_t>
32
static
constexpr
value_t
getDifference
(
const
value_t
&
lhs
,
33
const
value_t
&
rhs
) {
34
return
lhs -
rhs
;
35
}
36
};
37
44
template
<
typename
limits_t>
45
struct
RestrictedParameterTraits
{
47
static
constexpr
bool
may_modify_value
=
true
;
49
static
constexpr
double
min
= limits_t::lowest();
51
static
constexpr
double
max
= limits_t::max();
52
54
template
<
typename
value_t>
55
static
constexpr
value_t
getValue
(
const
value_t
&
value
) {
56
return
std::clamp(value, static_cast<value_t>(
min
),
57
static_cast<value_t>(
max
));
58
}
60
template
<
typename
value_t>
61
static
constexpr
value_t
getDifference
(
const
value_t
&
lhs
,
62
const
value_t
&
rhs
) {
63
return
getValue
(lhs) -
getValue
(rhs);
64
}
65
};
66
72
template
<
typename
limits_t>
73
struct
CyclicParameterTraits
{
75
static
constexpr
bool
may_modify_value
=
true
;
77
static
constexpr
double
min
= limits_t::lowest();
79
static
constexpr
double
max
= limits_t::max();
80
82
template
<
typename
value_t>
83
static
constexpr
value_t
getValue
(
const
value_t
&
value
) {
84
if
((
min
<= value) and (value <
max
)) {
85
return
value
;
86
}
else
{
87
return
value - (
max
-
min
) * std::floor((value -
min
) / (
max
-
min
));
88
}
89
}
91
template
<
typename
value_t>
92
static
constexpr
value_t
getDifference
(
const
value_t
&
lhs
,
93
const
value_t
&
rhs
) {
94
constexpr
value_t
range = (
max
-
min
);
95
value_t
delta
=
getValue
(lhs) -
getValue
(rhs);
96
if
((2 * delta) < -range) {
97
return
delta + range;
98
}
else
if
(range < (2 * delta)) {
99
return
delta - range;
100
}
else
{
101
return
delta
;
102
}
103
}
104
};
105
106
// Limit types for parameter traits.
107
//
108
// The functions names are chosen to be consistent w/ std::numeric_limits
109
struct
PhiBoundParameterLimits
{
110
static
constexpr
double
lowest
() {
return
-M_PI; }
111
static
constexpr
double
max
() {
return
M_PI; }
112
};
113
struct
ThetaBoundParameterLimits
{
114
static
constexpr
double
lowest
() {
return
0; }
115
static
constexpr
double
max
() {
return
M_PI; }
116
};
117
118
// Traits implementation structs for single parameters.
119
//
120
// Separate implementation structs are needed to generate a compile-time error
121
// in case of an unsupported enum type/ index combination.
122
template
<
typename
index_t, index_t kIndex>
123
struct
ParameterTraitsImpl
;
124
template
<>
125
struct
ParameterTraitsImpl
<
BoundIndices
,
BoundIndices
::
eBoundPhi
> {
126
using
Type
=
CyclicParameterTraits<PhiBoundParameterLimits>
;
127
};
128
template
<>
129
struct
ParameterTraitsImpl
<
BoundIndices
,
BoundIndices
::
eBoundTheta
> {
130
using
Type
=
RestrictedParameterTraits<ThetaBoundParameterLimits>
;
131
};
132
template
<BoundIndices kIndex>
133
struct
ParameterTraitsImpl
<
BoundIndices
, kIndex> {
134
// other bound parameters not explicitly specified above are unrestricted
135
using
Type
=
UnrestrictedParameterTraits
;
136
};
137
template
<FreeIndices kIndex>
138
struct
ParameterTraitsImpl
<
FreeIndices
, kIndex> {
139
// all free parameters components are unrestricted
140
using
Type
=
UnrestrictedParameterTraits
;
141
};
142
150
template
<
typename
index_t, index_t kIndex>
151
using
ParameterTraits
=
typename
ParameterTraitsImpl<index_t, kIndex>::Type
;
152
153
// Traits implementation structs for all parameters in an indices enum.
154
//
155
// Separate implementation structs are needed to generate a compile-time error
156
// in case of an unsupported indices enum. Also required since template
157
// variables can not have an undefined default case.
158
template
<
typename
indices_t>
159
struct
ParametersTraitsImpl
;
160
template
<>
161
struct
ParametersTraitsImpl
<
BoundIndices
> {
162
static
constexpr
size_t
kSize =
static_cast<
size_t
>
(
BoundIndices::eBoundSize
);
163
};
164
template
<>
165
struct
ParametersTraitsImpl
<
FreeIndices
> {
166
static
constexpr
size_t
kSize =
static_cast<
size_t
>
(
FreeIndices::eFreeSize
);
167
};
168
170
template
<
typename
indices_t>
171
constexpr
size_t
kParametersSize
=
ParametersTraitsImpl<indices_t>::kSize
;
172
173
}
// namespace detail
174
}
// namespace Acts
acts
blob
sPHENIX
Core
include
Acts
EventData
detail
ParameterTraits.hpp
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:17:32
using
1.8.2 with
sPHENIX GitHub integration