ATLAS Offline Software
Loading...
Searching...
No Matches
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
6#include <stdexcept>
7#include <utility>
8
9using namespace NswAsBuilt;
10
11ElementModelSTGC::ElementModelSTGC(double lenX, double lenY, Amg::Vector3D defo0)
12 : m_lenY(lenY),m_lenX(lenX),
13 m_defo0(std::move(defo0))
14{
15}
16
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
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 */
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
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
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
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
99// Scale measured by CMM/Faro at construction sites
100 return d0.array() * Eigen::Array3d{0., scl/m_lenY, 0.};
101}
102
103
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
110void 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
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
static Amg::Vector3D stgcOffset(double off)
void applyDeformation2(const ParameterVector &parvec, VectorSetRef local) const
virtual ipar_t getParameterIndex(const std::string &parname) const override
virtual std::string getParameterName(ipar_t ipar) const override
void applyDeformation(const ParameterVector &parvec, Eigen::Ref< Amg::Vector3D > local) const
static Amg::Vector3D stgcRotation(double rot, const Amg::Vector3D &d0)
virtual void transform(const ParameterVector &parvec, VectorSetRef local) const override
Transform a set of vectors expressed in local frame, stored in a matrix.
Amg::Vector3D stgcNonPar(double npar, const Amg::Vector3D &d0) const
Amg::Vector3D stgcScale(double scl, const Amg::Vector3D &d0) const
virtual void cacheTransform(ParameterVector &parvec) const override
Cache the rigid component of this deformation model.
Eigen::Ref< VectorSet > VectorSetRef
Eigen::Matrix< double, 3, Eigen::Dynamic, Eigen::ColMajor|Eigen::AutoAlign, 3, 5 > VectorSet
STL class.
Eigen::Matrix< double, 3, 1 > Vector3D
STL namespace.