ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonDetDescr
MuonNSWAsBuilt
src
ElementModelSTGC.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
MuonNSWAsBuilt/ElementModelSTGC.h
"
6
#include <stdexcept>
7
#include <utility>
8
9
using namespace
NswAsBuilt
;
10
11
ElementModelSTGC::ElementModelSTGC
(
double
lenX,
double
lenY,
Amg::Vector3D
defo0)
12
:
m_lenY
(lenY),
m_lenX
(lenX),
13
m_defo0
(
std
::move(defo0))
14
{
15
}
16
20
void
ElementModelSTGC::transform
(
const
ParameterVector
& parvec,
VectorSetRef
local)
const
{
21
22
if
(!parvec.
transformCacheValid
) {
23
throw
std::runtime_error(
"Should call Element::cacheTransforms() first"
);
24
}
25
26
// Apply the deformation component
27
28
// old-style (reference) implementation: not optimized, provided for comparison purposes
29
// for (int i=0; i< local.cols(); ++i) {
30
// applyDeformation(parvec, local.col(i));
31
// }
32
33
34
// Eigen-style implementation: optimized
35
applyDeformation2
(parvec, local);
36
37
// Apply the rigid component
38
local = (parvec.
transformCache
* local).eval();
// Needs eval to avoid aliasing (?)
39
}
40
45
void
ElementModelSTGC::cacheTransform
(
ParameterVector
& parvec)
const
{
46
const
auto
& pars = parvec.
parameters
;
47
parvec.
transformCache
48
= Eigen::Translation3d(pars[
X
], pars[
Y
], pars[
Z
])
49
* Eigen::AngleAxisd(pars[
THZ
], Eigen::Vector3d::UnitZ())
50
* Eigen::AngleAxisd(pars[
THY
], Eigen::Vector3d::UnitY())
51
* Eigen::AngleAxisd(pars[
THX
], Eigen::Vector3d::UnitX());
52
parvec.
transformCacheValid
=
true
;
53
}
54
55
/*
56
* Helper methods to convert parameter index to string representation
57
*/
58
ElementModelSTGC::ipar_t
ElementModelSTGC::getParameterIndex
(
const
std::string& parname)
const
{
59
if
(parname ==
"x"
)
return
parameter_t::X
;
60
if
(parname ==
"y"
)
return
parameter_t::Y
;
61
if
(parname ==
"z"
)
return
parameter_t::Z
;
62
if
(parname ==
"thx"
)
return
parameter_t::THX
;
63
if
(parname ==
"thy"
)
return
parameter_t::THY
;
64
if
(parname ==
"thz"
)
return
parameter_t::THZ
;
65
if
(parname ==
"rot"
)
return
parameter_t::ROT
;
66
if
(parname ==
"off"
)
return
parameter_t::OFF
;
67
if
(parname ==
"scl"
)
return
parameter_t::SCL
;
68
if
(parname ==
"npar"
)
return
parameter_t::NPAR
;
69
throw
std::runtime_error(
"Invalid parameter name "
+parname);
70
}
71
72
std::string
ElementModelSTGC::getParameterName
(
ipar_t
ipar)
const
{
73
switch
(ipar) {
74
case
X
:
return
"x"
;
75
case
Y
:
return
"y"
;
76
case
Z
:
return
"z"
;
77
case
THX
:
return
"thx"
;
78
case
THY
:
return
"thy"
;
79
case
THZ
:
return
"thz"
;
80
case
ROT
:
return
"rot"
;
81
case
OFF
:
return
"off"
;
82
case
SCL
:
return
"scl"
;
83
case
NPAR
:
return
"npar"
;
84
default
:
throw
std::runtime_error(
"Invalid parameter"
);
85
}
86
}
87
88
Amg::Vector3D
ElementModelSTGC::stgcOffset
(
double
off) {
89
// Offset extracted from combined fit of X-ray data and by CMM/Faro measurement at construction sites
90
return
off * Amg::Vector3D::UnitY();
91
}
92
93
Amg::Vector3D
ElementModelSTGC::stgcRotation
(
double
rot,
const
Amg::Vector3D
& d0) {
94
// Rotation extracted from combined fit of X-ray data and by CMM/Faro measurement at construction sites
95
return
-rot * d0.cross(Amg::Vector3D::UnitZ());
96
}
97
98
Amg::Vector3D
ElementModelSTGC::stgcScale
(
double
scl,
const
Amg::Vector3D
& d0)
const
{
99
// Scale measured by CMM/Faro at construction sites
100
return
d0.array() * Eigen::Array3d{0., scl/
m_lenY
, 0.};
101
}
102
103
104
Amg::Vector3D
ElementModelSTGC::stgcNonPar
(
double
npar,
const
Amg::Vector3D
& d0)
const
{
105
// Non-parallelism measured by CMM/Faro at construction sites
106
double
delta = npar*d0[0]*d0[1]/(
m_lenX
*
m_lenY
);
107
return
Amg::Vector3D
(0., delta, 0.);
108
}
109
110
void
ElementModelSTGC::applyDeformation
(
const
ParameterVector
& parvec, Eigen::Ref<Amg::Vector3D> local)
const
{
111
// Applies the deformation to the set of local vectors given as argument
112
// This old-style implementation is the reference implementation
113
Amg::Vector3D
d0 = local -
m_defo0
;
114
local = local
115
+
stgcOffset
(parvec[
OFF
])
116
+
stgcRotation
(parvec[
ROT
], d0)
117
+
stgcScale
(parvec[
SCL
], d0)
118
+
stgcNonPar
(parvec[
NPAR
], d0)
119
;
120
}
121
122
void
ElementModelSTGC::applyDeformation2
(
const
ParameterVector
& parvec,
VectorSetRef
local)
const
{
123
// Applies the deformation to the set of local vectors given as argument
124
// This implementation uses Eigen-style algebra (does the same as the method applyDeformation above, but benefits from Eigen's optimizations)
125
126
// Temporaries allocated on the stack
127
// d0 = local - defo0
128
VectorSet
d0 = local.colwise() -
m_defo0
;
129
130
double
off = parvec[
OFF
];
131
double
rot = parvec[
ROT
];
132
double
scl = parvec[
SCL
]/
m_lenY
;
133
double
npar = parvec[
NPAR
]/(
m_lenX
*
m_lenY
);
134
135
// OFF:
136
local.array().colwise() += Eigen::Array3d{0. ,off, 0.};
137
138
// ROT
139
local.topRows<2>().
array
() += d0.topRows<2>().
array
().colwise().reverse().colwise() * Eigen::Array2d{0., rot};
140
141
// SCL:
142
local.array() += d0.array().colwise() * Eigen::Array3d{0., scl, 0.};
143
144
// NPAR:
145
local.topRows<2>().
array
() += (d0.topRows<2>().array().colwise().reverse() * d0.topRows<2>().array()).colwise() * Eigen::Array2d{0., npar};
146
}
147
ElementModelSTGC.h
NswAsBuilt::ElementModelSTGC::stgcOffset
static Amg::Vector3D stgcOffset(double off)
Definition
ElementModelSTGC.cxx:88
NswAsBuilt::ElementModelSTGC::THZ
@ THZ
Definition
ElementModelSTGC.h:34
NswAsBuilt::ElementModelSTGC::THX
@ THX
Definition
ElementModelSTGC.h:32
NswAsBuilt::ElementModelSTGC::SCL
@ SCL
Definition
ElementModelSTGC.h:37
NswAsBuilt::ElementModelSTGC::X
@ X
Definition
ElementModelSTGC.h:29
NswAsBuilt::ElementModelSTGC::ROT
@ ROT
Definition
ElementModelSTGC.h:35
NswAsBuilt::ElementModelSTGC::Z
@ Z
Definition
ElementModelSTGC.h:31
NswAsBuilt::ElementModelSTGC::Y
@ Y
Definition
ElementModelSTGC.h:30
NswAsBuilt::ElementModelSTGC::OFF
@ OFF
Definition
ElementModelSTGC.h:36
NswAsBuilt::ElementModelSTGC::NPAR
@ NPAR
Definition
ElementModelSTGC.h:38
NswAsBuilt::ElementModelSTGC::THY
@ THY
Definition
ElementModelSTGC.h:33
NswAsBuilt::ElementModelSTGC::applyDeformation2
void applyDeformation2(const ParameterVector &parvec, VectorSetRef local) const
Definition
ElementModelSTGC.cxx:122
NswAsBuilt::ElementModelSTGC::ElementModelSTGC
ElementModelSTGC()=delete
NswAsBuilt::ElementModelSTGC::getParameterIndex
virtual ipar_t getParameterIndex(const std::string &parname) const override
Definition
ElementModelSTGC.cxx:58
NswAsBuilt::ElementModelSTGC::getParameterName
virtual std::string getParameterName(ipar_t ipar) const override
Definition
ElementModelSTGC.cxx:72
NswAsBuilt::ElementModelSTGC::m_defo0
Amg::Vector3D m_defo0
Definition
ElementModelSTGC.h:83
NswAsBuilt::ElementModelSTGC::applyDeformation
void applyDeformation(const ParameterVector &parvec, Eigen::Ref< Amg::Vector3D > local) const
Definition
ElementModelSTGC.cxx:110
NswAsBuilt::ElementModelSTGC::m_lenY
double m_lenY
Definition
ElementModelSTGC.h:81
NswAsBuilt::ElementModelSTGC::stgcRotation
static Amg::Vector3D stgcRotation(double rot, const Amg::Vector3D &d0)
Definition
ElementModelSTGC.cxx:93
NswAsBuilt::ElementModelSTGC::transform
virtual void transform(const ParameterVector &parvec, VectorSetRef local) const override
Transform a set of vectors expressed in local frame, stored in a matrix.
Definition
ElementModelSTGC.cxx:20
NswAsBuilt::ElementModelSTGC::stgcNonPar
Amg::Vector3D stgcNonPar(double npar, const Amg::Vector3D &d0) const
Definition
ElementModelSTGC.cxx:104
NswAsBuilt::ElementModelSTGC::m_lenX
double m_lenX
Definition
ElementModelSTGC.h:82
NswAsBuilt::ElementModelSTGC::stgcScale
Amg::Vector3D stgcScale(double scl, const Amg::Vector3D &d0) const
Definition
ElementModelSTGC.cxx:98
NswAsBuilt::ElementModelSTGC::cacheTransform
virtual void cacheTransform(ParameterVector &parvec) const override
Cache the rigid component of this deformation model.
Definition
ElementModelSTGC.cxx:45
NswAsBuilt::ElementModel::VectorSetRef
Eigen::Ref< VectorSet > VectorSetRef
Definition
ElementModel.h:37
NswAsBuilt::ElementModel::VectorSet
Eigen::Matrix< double, 3, Eigen::Dynamic, Eigen::ColMajor|Eigen::AutoAlign, 3, 5 > VectorSet
Definition
ElementModel.h:36
NswAsBuilt::ElementModel::ipar_t
unsigned int ipar_t
Definition
ElementModel.h:35
array
STL class.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:47
NswAsBuilt
Definition
CathodeBoardElement.h:12
std
STL namespace.
NswAsBuilt::ElementModel::ParameterVector
Definition
ElementModel.h:44
NswAsBuilt::ElementModel::ParameterVector::parameters
std::vector< double > parameters
Definition
ElementModel.h:45
NswAsBuilt::ElementModel::ParameterVector::transformCacheValid
bool transformCacheValid
Definition
ElementModel.h:47
NswAsBuilt::ElementModel::ParameterVector::transformCache
Eigen::Affine3d transformCache
Definition
ElementModel.h:46
Generated on
for ATLAS Offline Software by
1.17.0