EIC Software
Reference for
EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
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/Utilities/ParameterDefinitions.hpp
"
12
13
#include <algorithm>
14
#include <cmath>
15
16
namespace
Acts {
17
namespace
detail {
18
20
struct
UnrestrictedParameterTraits
{
22
static
constexpr
bool
may_modify_value
=
false
;
23
25
template
<
typename
value_t>
26
static
constexpr
const
value_t
&
getValue
(
const
value_t
&
value
) {
27
return
value
;
28
}
30
template
<
typename
value_t>
31
static
constexpr
value_t
getDifference
(
const
value_t
& lhs,
32
const
value_t
& rhs) {
33
return
lhs - rhs;
34
}
35
};
36
43
template
<
typename
limits_t>
44
struct
RestrictedParameterTraits
{
46
static
constexpr
bool
may_modify_value
=
true
;
48
static
constexpr
double
min
= limits_t::lowest();
50
static
constexpr
double
max
=
limits_t::max
();
51
53
template
<
typename
value_t>
54
static
constexpr
value_t
getValue
(
const
value_t
&
value
) {
55
return
std::clamp(value, static_cast<value_t>(
min
),
56
static_cast<value_t>(
max
));
57
}
59
template
<
typename
value_t>
60
static
constexpr
value_t
getDifference
(
const
value_t
& lhs,
61
const
value_t
& rhs) {
62
return
getValue
(lhs) -
getValue
(rhs);
63
}
64
};
65
71
template
<
typename
limits_t>
72
struct
CyclicParameterTraits
{
74
static
constexpr
bool
may_modify_value
=
true
;
76
static
constexpr
double
min
= limits_t::lowest();
78
static
constexpr
double
max
=
limits_t::max
();
79
81
template
<
typename
value_t>
82
static
constexpr
value_t
getValue
(
const
value_t
&
value
) {
83
if
((
min
<= value) and (value <
max
)) {
84
return
value
;
85
}
else
{
86
return
value - (
max
-
min
) * std::floor((value -
min
) / (
max
-
min
));
87
}
88
}
90
template
<
typename
value_t>
91
static
constexpr
value_t
getDifference
(
const
value_t
& lhs,
92
const
value_t
& rhs) {
93
constexpr
value_t
range = (
max
-
min
);
94
value_t
delta
=
getValue
(lhs) -
getValue
(rhs);
95
if
((2 * delta) < -range) {
96
return
delta + range;
97
}
else
if
(range < (2 * delta)) {
98
return
delta - range;
99
}
else
{
100
return
delta
;
101
}
102
}
103
};
104
105
// Limit types for parameter traits.
106
//
107
// The functions names are chosen to be consisten w/ std::numeric_limits
108
struct
PhiBoundParameterLimits
{
109
static
constexpr
double
lowest
() {
return
-
M_PI
; }
110
static
constexpr
double
max
() {
return
M_PI
; }
111
};
112
struct
ThetaBoundParameterLimits
{
113
static
constexpr
double
lowest
() {
return
0; }
114
static
constexpr
double
max
() {
return
M_PI
; }
115
};
116
117
// Traits implementation structs for single parameters.
118
//
119
// Separate implementation structs are needed to generate a compile-time error
120
// in case of an unsupported enum type/ index combination.
121
template
<
typename
index_t, index_t kIndex>
122
struct
ParameterTraitsImpl
;
123
template
<>
124
struct
ParameterTraitsImpl
<
BoundIndices
,
BoundIndices
::
eBoundPhi
> {
125
using
Type
=
CyclicParameterTraits<PhiBoundParameterLimits>
;
126
};
127
template
<>
128
struct
ParameterTraitsImpl
<
BoundIndices
,
BoundIndices
::
eBoundTheta
> {
129
using
Type
=
RestrictedParameterTraits<ThetaBoundParameterLimits>
;
130
};
131
template
<BoundIndices kIndex>
132
struct
ParameterTraitsImpl
<
BoundIndices
, kIndex> {
133
// other bound parameters not explicitely specified above are unrestricted
134
using
Type
=
UnrestrictedParameterTraits
;
135
};
136
template
<FreeIndices kIndex>
137
struct
ParameterTraitsImpl
<
FreeIndices
, kIndex> {
138
// all free parameters components are unrestricted
139
using
Type
=
UnrestrictedParameterTraits
;
140
};
141
149
template
<
typename
index_t, index_t kIndex>
150
using
ParameterTraits
=
typename
ParameterTraitsImpl<index_t, kIndex>::Type
;
151
152
// Traits implementation structs for all parameters in an indices enum.
153
//
154
// Separate implementation structs are needed to generate a compile-time error
155
// in case of an unsupported indices enum. Also required since template
156
// variables can not have an undefined default case.
157
template
<
typename
indices_t>
158
struct
ParametersTraitsImpl
;
159
template
<>
160
struct
ParametersTraitsImpl
<
BoundIndices
> {
161
using
Scalar
=
BoundScalar
;
162
static
constexpr
unsigned
int
kSize =
163
static_cast<
unsigned
int
>
(
BoundIndices::eBoundSize
);
164
};
165
template
<>
166
struct
ParametersTraitsImpl
<
FreeIndices
> {
167
using
Scalar
=
FreeScalar
;
168
static
constexpr
unsigned
int
kSize =
169
static_cast<
unsigned
int
>
(
FreeIndices::eFreeSize
);
170
};
171
173
template
<
typename
indices_t>
174
using
ParametersScalar
=
typename
ParametersTraitsImpl<indices_t>::Scalar
;
175
177
template
<
typename
indices_t>
178
constexpr
unsigned
int
kParametersSize
=
ParametersTraitsImpl<indices_t>::kSize
;
179
180
}
// namespace detail
181
}
// namespace Acts
acts
blob
sPHENIX
Core
include
Acts
EventData
detail
ParameterTraits.hpp
Built by
Jin Huang
. updated:
Mon Jan 22 2024 12:43:22
using
1.8.2 with
EIC GitHub integration