1313#define O2_ITS3_ALIGNMENT_HIERARCHY_H
1414
1515#include < memory>
16- #include < compare>
17- #include < type_traits>
18- #include < map>
1916#include < utility>
2017#include < vector>
2118#include < ostream>
2219#include < string>
23- #include < format >
20+ #include < map >
2421#include < algorithm>
2522
2623#include < Eigen/Dense>
2724
2825#include < TGeoMatrix.h>
2926#include < TGeoPhysicalNode.h>
3027
28+ #include " ITS3Align/AlignmentLabel.h"
29+ #include " ITS3Align/AlignmentDOF.h"
30+
3131namespace o2 ::its3::align
3232{
3333using Matrix36 = Eigen::Matrix<double , 3 , 6 >;
3434using Matrix66 = Eigen::Matrix<double , 6 , 6 >;
3535
36- // indices for rigid body parameters in LOC frame
37- enum RigidBodyDOF : uint8_t {
38- TX = 0 ,
39- TY,
40- TZ,
41- RX,
42- RY,
43- RZ,
44- NDOF,
45- };
46- static constexpr const char * RigidBodyDOFNames[RigidBodyDOF::NDOF] = {" TX" , " TY" , " TZ" , " RX" , " RY" , " RZ" };
47-
4836// return the rigid body derivatives
4937// trk has be at in the measurment frame
5038auto getRigidBodyDerivatives (const auto & trk)
@@ -63,144 +51,6 @@ auto getRigidBodyDerivatives(const auto& trk)
6351 return der;
6452}
6553
66- class DOFSet
67- {
68- public:
69- enum class Type : uint8_t { RigidBody,
70- Legendre };
71- virtual ~DOFSet () = default ;
72- virtual Type type () const = 0;
73- int nDOFs () const { return static_cast <int >(mFree .size ()); }
74- virtual std::string dofName (int idx) const = 0;
75- bool isFree (int idx) const { return mFree [idx]; }
76- void setFree (int idx, bool f) { mFree [idx] = f; }
77- void setAllFree (bool f) { std::fill (mFree .begin (), mFree .end (), f); }
78- int nFreeDOFs () const
79- {
80- int n = 0 ;
81- for (bool f : mFree ) {
82- n += f;
83- }
84- return n;
85- }
86-
87- protected:
88- DOFSet (int n) : mFree (n, true ) {}
89- std::vector<bool > mFree ;
90- };
91-
92- class RigidBodyDOFSet final : public DOFSet
93- {
94- public:
95- static constexpr int NDOF = RigidBodyDOF::NDOF;
96- RigidBodyDOFSet () : DOFSet(NDOF) {}
97- // mask: bitmask of free DOFs (bit i = DOF i is free)
98- explicit RigidBodyDOFSet (uint8_t mask) : DOFSet(NDOF)
99- {
100- for (int i = 0 ; i < NDOF; ++i) {
101- mFree [i] = (mask >> i) & 1 ;
102- }
103- }
104- Type type () const override { return Type::RigidBody; }
105- std::string dofName (int idx) const override { return RigidBodyDOFNames[idx]; }
106- uint8_t mask () const
107- {
108- uint8_t m = 0 ;
109- for (int i = 0 ; i < NDOF; ++i) {
110- m |= (uint8_t (mFree [i]) << i);
111- }
112- return m;
113- }
114- };
115-
116- class LegendreDOFSet final : public DOFSet
117- {
118- public:
119- explicit LegendreDOFSet (int order) : DOFSet((order + 1 ) * (order + 2 ) / 2), mOrder(order) {}
120- Type type () const override { return Type::Legendre; }
121- int order () const { return mOrder ; }
122- std::string dofName (int idx) const override
123- {
124- int i = 0 ;
125- while ((i + 1 ) * (i + 2 ) / 2 <= idx) {
126- ++i;
127- }
128- int j = idx - (i * (i + 1 ) / 2 );
129- return std::format (" L({},{})" , i, j);
130- }
131-
132- private:
133- int mOrder ;
134- };
135-
136- class GlobalLabel
137- {
138- // Millepede label is any positive integer [1....)
139- // Layout: DOF(5) | CALIB(1) | ID(22) | SENS(1) | DET(2) = 31 usable bits (MSB reserved, GBL uses signed int)
140- public:
141- using T = uint32_t ;
142- static constexpr int DOF_BITS = 5 ; // bits 0-4
143- static constexpr int CALIB_BITS = 1 ; // bit 5: 0 = rigid body, 1 = calibration
144- static constexpr int ID_BITS = 22 ; // bits 6-27
145- static constexpr int SENS_BITS = 1 ; // bit 28
146- static constexpr int TOTAL_BITS = sizeof (T) * 8 ;
147- static constexpr int DET_BITS = TOTAL_BITS - (DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS) - 1 ; // one less bit since GBL uses int!
148- static constexpr T bitMask (int b) noexcept
149- {
150- return (T (1 ) << b) - T (1 );
151- }
152- static constexpr int DOF_SHIFT = 0 ;
153- static constexpr T DOF_MAX = (T(1 ) << DOF_BITS) - T(1 );
154- static constexpr T DOF_MASK = DOF_MAX << DOF_SHIFT;
155- static constexpr int CALIB_SHIFT = DOF_BITS;
156- static constexpr T CALIB_MAX = (T(1 ) << CALIB_BITS) - T(1 );
157- static constexpr T CALIB_MASK = CALIB_MAX << CALIB_SHIFT;
158- static constexpr int ID_SHIFT = DOF_BITS + CALIB_BITS;
159- static constexpr T ID_MAX = (T(1 ) << ID_BITS) - T(1 );
160- static constexpr T ID_MASK = ID_MAX << ID_SHIFT;
161- static constexpr int SENS_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS;
162- static constexpr T SENS_MAX = (T(1 ) << SENS_BITS) - T(1 );
163- static constexpr T SENS_MASK = SENS_MAX << SENS_SHIFT;
164- static constexpr int DET_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS;
165- static constexpr T DET_MAX = (T(1 ) << DET_BITS) - T(1 );
166- static constexpr T DET_MASK = DET_MAX << DET_SHIFT;
167-
168- GlobalLabel (T det, T id, bool sens, bool calib = false )
169- : mID ((((id + 1 ) & ID_MAX) << ID_SHIFT) |
170- ((det & DET_MAX) << DET_SHIFT) |
171- ((T(sens) & SENS_MAX) << SENS_SHIFT) |
172- ((T(calib) & CALIB_MAX) << CALIB_SHIFT))
173- {
174- }
175-
176- // / produce the raw Millepede label for a given DOF index (rigid body: calib=0 in label)
177- constexpr T raw (T dof) const noexcept { return (mID & ~DOF_MASK) | ((dof & DOF_MAX) << DOF_SHIFT); }
178- constexpr int rawGBL (T dof) const noexcept { return static_cast <int >(raw (dof)); }
179-
180- // / return a copy of this label with the CALIB bit set (for calibration DOFs on same volume)
181- GlobalLabel asCalib () const noexcept
182- {
183- GlobalLabel c{*this };
184- c.mID |= (T (1 ) << CALIB_SHIFT);
185- return c;
186- }
187-
188- constexpr T id () const noexcept { return ((mID >> ID_SHIFT) & ID_MAX) - 1 ; }
189- constexpr T det () const noexcept { return (mID & DET_MASK) >> DET_SHIFT; }
190- constexpr bool sens () const noexcept { return (mID & SENS_MASK) >> SENS_SHIFT; }
191- constexpr bool calib () const noexcept { return (mID & CALIB_MASK) >> CALIB_SHIFT; }
192-
193- std::string asString () const
194- {
195- return std::format (" Det:{} Id:{} Sens:{} Calib:{}" , det (), id (), sens (), calib ());
196- }
197-
198- constexpr auto operator <=>(const GlobalLabel&) const noexcept = default ;
199-
200- private:
201- T mID {0 };
202- };
203-
20454class HierarchyConstraint
20555{
20656 public:
@@ -220,8 +70,6 @@ class HierarchyConstraint
22070 std::vector<double > mCoeff ; // their coefficients
22171};
22272
223- // --- AlignableVolume ---
224-
22573class AlignableVolume
22674{
22775 public:
0 commit comments