Skip to content

Commit 02943e3

Browse files
committed
ITS3: cleanup code
Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 2dbf448 commit 02943e3

File tree

3 files changed

+196
-156
lines changed

3 files changed

+196
-156
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_ITS3_ALIGNMENT_DOF_H
13+
#define O2_ITS3_ALIGNMENT_DOF_H
14+
15+
#include <cstdint>
16+
#include <format>
17+
#include <algorithm>
18+
#include <vector>
19+
20+
// Generic set of DOF
21+
class DOFSet
22+
{
23+
public:
24+
enum class Type : uint8_t { RigidBody,
25+
Legendre };
26+
virtual ~DOFSet() = default;
27+
virtual Type type() const = 0;
28+
int nDOFs() const { return static_cast<int>(mFree.size()); }
29+
virtual std::string dofName(int idx) const = 0;
30+
bool isFree(int idx) const { return mFree[idx]; }
31+
void setFree(int idx, bool f) { mFree[idx] = f; }
32+
void setAllFree(bool f) { std::fill(mFree.begin(), mFree.end(), f); }
33+
int nFreeDOFs() const
34+
{
35+
int n = 0;
36+
for (bool f : mFree) {
37+
n += f;
38+
}
39+
return n;
40+
}
41+
42+
protected:
43+
DOFSet(int n) : mFree(n, true) {}
44+
std::vector<bool> mFree;
45+
};
46+
47+
// Rigid body set
48+
class RigidBodyDOFSet final : public DOFSet
49+
{
50+
public:
51+
// indices for rigid body parameters in LOC frame
52+
enum RigidBodyDOF : uint8_t {
53+
TX = 0,
54+
TY,
55+
TZ,
56+
RX,
57+
RY,
58+
RZ,
59+
NDOF,
60+
};
61+
static constexpr const char* RigidBodyDOFNames[RigidBodyDOF::NDOF] = {"TX", "TY", "TZ", "RX", "RY", "RZ"};
62+
63+
RigidBodyDOFSet() : DOFSet(NDOF) {}
64+
// mask: bitmask of free DOFs (bit i = DOF i is free)
65+
explicit RigidBodyDOFSet(uint8_t mask) : DOFSet(NDOF)
66+
{
67+
for (int i = 0; i < NDOF; ++i) {
68+
mFree[i] = (mask >> i) & 1;
69+
}
70+
}
71+
Type type() const override { return Type::RigidBody; }
72+
std::string dofName(int idx) const override { return RigidBodyDOFNames[idx]; }
73+
uint8_t mask() const
74+
{
75+
uint8_t m = 0;
76+
for (int i = 0; i < NDOF; ++i) {
77+
m |= (uint8_t(mFree[i]) << i);
78+
}
79+
return m;
80+
}
81+
};
82+
83+
// Legendre DOFs
84+
// Describing radial misplacement
85+
class LegendreDOFSet final : public DOFSet
86+
{
87+
public:
88+
explicit LegendreDOFSet(int order) : DOFSet((order + 1) * (order + 2) / 2), mOrder(order) {}
89+
Type type() const override { return Type::Legendre; }
90+
int order() const { return mOrder; }
91+
std::string dofName(int idx) const override
92+
{
93+
int i = 0;
94+
while ((i + 1) * (i + 2) / 2 <= idx) {
95+
++i;
96+
}
97+
int j = idx - (i * (i + 1) / 2);
98+
return std::format("L({},{})", i, j);
99+
}
100+
101+
private:
102+
int mOrder;
103+
};
104+
105+
#endif

Detectors/Upgrades/ITS3/alignment/include/ITS3Align/AlignmentHierarchy.h

Lines changed: 4 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,26 @@
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+
3131
namespace o2::its3::align
3232
{
3333
using Matrix36 = Eigen::Matrix<double, 3, 6>;
3434
using 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
5038
auto 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-
20454
class HierarchyConstraint
20555
{
20656
public:
@@ -220,8 +70,6 @@ class HierarchyConstraint
22070
std::vector<double> mCoeff; // their coefficients
22171
};
22272

223-
// --- AlignableVolume ---
224-
22573
class AlignableVolume
22674
{
22775
public:
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2019-2026 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
#ifndef O2_ITS3_ALIGNMENT_LABEL_H
13+
#define O2_ITS3_ALIGNMENT_LABEL_H
14+
15+
#include <cstdint>
16+
#include <string>
17+
#include <format>
18+
19+
class GlobalLabel
20+
{
21+
// Millepede label is any positive integer [1....)
22+
// Layout: DOF(5) | CALIB(1) | ID(22) | SENS(1) | DET(2) = 31 usable bits (MSB reserved, GBL uses signed int)
23+
public:
24+
using T = uint32_t;
25+
static constexpr int DOF_BITS = 5; // bits 0-4
26+
static constexpr int CALIB_BITS = 1; // bit 5: 0 = rigid body, 1 = calibration (only allow for one calibration, could be extended if needed)
27+
static constexpr int ID_BITS = 22; // bits 6-27
28+
static constexpr int SENS_BITS = 1; // bit 28
29+
static constexpr int TOTAL_BITS = sizeof(T) * 8;
30+
static constexpr int DET_BITS = TOTAL_BITS - (DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS) - 1; // one less bit since GBL uses int!
31+
static constexpr T bitMask(int b) noexcept
32+
{
33+
return (T(1) << b) - T(1);
34+
}
35+
static constexpr int DOF_SHIFT = 0;
36+
static constexpr T DOF_MAX = (T(1) << DOF_BITS) - T(1);
37+
static constexpr T DOF_MASK = DOF_MAX << DOF_SHIFT;
38+
static constexpr int CALIB_SHIFT = DOF_BITS;
39+
static constexpr T CALIB_MAX = (T(1) << CALIB_BITS) - T(1);
40+
static constexpr T CALIB_MASK = CALIB_MAX << CALIB_SHIFT;
41+
static constexpr int ID_SHIFT = DOF_BITS + CALIB_BITS;
42+
static constexpr T ID_MAX = (T(1) << ID_BITS) - T(1);
43+
static constexpr T ID_MASK = ID_MAX << ID_SHIFT;
44+
static constexpr int SENS_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS;
45+
static constexpr T SENS_MAX = (T(1) << SENS_BITS) - T(1);
46+
static constexpr T SENS_MASK = SENS_MAX << SENS_SHIFT;
47+
static constexpr int DET_SHIFT = DOF_BITS + CALIB_BITS + ID_BITS + SENS_BITS;
48+
static constexpr T DET_MAX = (T(1) << DET_BITS) - T(1);
49+
static constexpr T DET_MASK = DET_MAX << DET_SHIFT;
50+
51+
GlobalLabel(T det, T id, bool sens, bool calib = false)
52+
: mID((((id + 1) & ID_MAX) << ID_SHIFT) |
53+
((det & DET_MAX) << DET_SHIFT) |
54+
((T(sens) & SENS_MAX) << SENS_SHIFT) |
55+
((T(calib) & CALIB_MAX) << CALIB_SHIFT))
56+
{
57+
}
58+
59+
/// produce the raw Millepede label for a given DOF index (rigid body: calib=0 in label)
60+
constexpr T raw(T dof) const noexcept { return (mID & ~DOF_MASK) | ((dof & DOF_MAX) << DOF_SHIFT); }
61+
constexpr int rawGBL(T dof) const noexcept { return static_cast<int>(raw(dof)); }
62+
63+
/// return a copy of this label with the CALIB bit set (for calibration DOFs on same volume)
64+
GlobalLabel asCalib() const noexcept
65+
{
66+
GlobalLabel c{*this};
67+
c.mID |= (T(1) << CALIB_SHIFT);
68+
return c;
69+
}
70+
71+
constexpr T id() const noexcept { return ((mID >> ID_SHIFT) & ID_MAX) - 1; }
72+
constexpr T det() const noexcept { return (mID & DET_MASK) >> DET_SHIFT; }
73+
constexpr bool sens() const noexcept { return (mID & SENS_MASK) >> SENS_SHIFT; }
74+
constexpr bool calib() const noexcept { return (mID & CALIB_MASK) >> CALIB_SHIFT; }
75+
76+
std::string asString() const
77+
{
78+
return std::format("Det:{} Id:{} Sens:{} Calib:{}", det(), id(), sens(), calib());
79+
}
80+
81+
constexpr auto operator<=>(const GlobalLabel&) const noexcept = default;
82+
83+
private:
84+
T mID{0};
85+
};
86+
87+
#endif

0 commit comments

Comments
 (0)