12#ifndef O2_ITS3_ALIGNMENT_HIERARCHY_H
13#define O2_ITS3_ALIGNMENT_HIERARCHY_H
28#include <TGeoMatrix.h>
29#include <TGeoPhysicalNode.h>
46static constexpr const char* RigidBodyDOFNames[
RigidBodyDOF::NDOF] = {
"TX",
"TY",
"TZ",
"RX",
"RY",
"RZ"};
53 const double tgl = trk.getTgl(), snp = trk.getSnp();
54 const double csp = 1. / sqrt(1. + (tgl * tgl));
55 const double u = trk.getY(),
v = trk.getZ();
56 const double uP = snp * csp, vP = tgl * csp;
61 der << uP, -1., 0.,
v,
v * uP, -u * uP,
62 vP, 0., -1., -u,
v * vP, -u * vP;
73 int nDOFs()
const {
return static_cast<int>(
mFree.size()); }
74 virtual std::string
dofName(
int idx)
const = 0;
100 for (
int i = 0;
i <
NDOF; ++
i) {
105 std::string
dofName(
int idx)
const override {
return RigidBodyDOFNames[idx]; }
109 for (
int i = 0;
i <
NDOF; ++
i) {
121 int order()
const {
return mOrder; }
125 while ((
i + 1) * (
i + 2) / 2 <= idx) {
128 int j = idx - (
i * (
i + 1) / 2);
129 return std::format(
"L({},{})",
i,
j);
150 return (
T(1) <<
b) -
T(1);
178 constexpr int rawGBL(
T dof)
const noexcept {
return static_cast<int>(
raw(dof)); }
195 return std::format(
"Det:{} Id:{} Sens:{} Calib:{}",
det(),
id(),
sens(),
calib());
208 void add(uint32_t lab,
double coeff)
210 mLabels.push_back(lab);
211 mCoeff.push_back(coeff);
213 void write(std::ostream& os)
const;
214 auto getSize() const noexcept {
return mLabels.size(); }
219 std::vector<uint32_t> mLabels;
220 std::vector<double> mCoeff;
228 using Ptr = std::unique_ptr<AlignableVolume>;
244 void writeTree(std::ostream& os,
int indent = 0)
const;
249 bool isLeaf() const noexcept {
return mChildren.empty(); }
250 template <
class T = AlignableVolume>
251 requires std::derived_from<T, AlignableVolume>
254 auto c = std::make_unique<T>(symName,
label, det, sens);
255 return setParent(std::move(
c));
257 template <
class T = AlignableVolume>
258 requires std::derived_from<T, AlignableVolume>
261 auto c = std::make_unique<T>(symName, lbl);
262 return setParent(std::move(
c));
269 for (
auto&
c : mChildren) {
270 c->traverse(visitor);
280 void setRigidBody(std::unique_ptr<DOFSet> rb) { mRigidBody = std::move(rb); }
281 void setCalib(std::unique_ptr<DOFSet> cal) { mCalib = std::move(cal); }
285 bool isPseudo() const noexcept {
return mIsPseudo; }
289 bool isActive() const noexcept {
return mRigidBody !=
nullptr || mIsPseudo; }
304 TGeoPhysicalNode*
mPN{
nullptr};
312 std::string mSymName;
315 bool mIsPseudo{
false};
317 std::unique_ptr<DOFSet> mRigidBody;
318 std::unique_ptr<DOFSet> mCalib;
320 AlignableVolume* setParent(
Ptr c)
323 mChildren.push_back(std::move(
c));
324 return mChildren.back().get();
326 std::vector<Ptr> mChildren;
332void applyDOFConfig(AlignableVolume* root,
const std::string& jsonPath);
335void writeMillepedeResults(AlignableVolume* root,
const std::string& milleResPath,
const std::string& outJsonPath,
const std::string& injectedJsonPath =
"");
auto getLevel() const noexcept
AlignableVolume * addChild(const char *symName, GlobalLabel lbl)
bool isActive() const noexcept
bool isLeaf() const noexcept
virtual void computeJacobianL2T(const double *pos, Matrix66 &jac) const
void setSensorId(int id) noexcept
size_t getNChildren() const noexcept
AlignableVolume * addChild(const char *symName, uint32_t label, uint32_t det, bool sens)
AlignableVolume * getParent() const
void traverse(const std::function< void(AlignableVolume *)> &visitor)
virtual ~AlignableVolume()=default
DOFSet * getRigidBody() const
DOFSet * getCalib() const
std::unique_ptr< AlignableVolume > Ptr
void writeParameters(std::ostream &os) const
int getSensorId() const noexcept
virtual void defineMatrixT2L()
const Matrix66 & getJP2L() const
AlignableVolume & operator=(AlignableVolume &&)=delete
GlobalLabel getLabel() const noexcept
void finalise(uint8_t level=0)
const TGeoHMatrix & getT2L() const
AlignableVolume(AlignableVolume &&)=delete
const Matrix66 & getJL2P() const
void setPseudo(bool p) noexcept
bool isPseudo() const noexcept
bool isRoot() const noexcept
AlignableVolume * mParent
matrices
const TGeoHMatrix & getL2P() const
void setRigidBody(std::unique_ptr< DOFSet > rb)
AlignableVolume & operator=(const AlignableVolume &)=delete
virtual void defineMatrixL2G()
std::map< GlobalLabel, AlignableVolume * > SensorMapping
void writeTree(std::ostream &os, int indent=0) const
std::string getSymName() const noexcept
void writeRigidBodyConstraints(std::ostream &os) const
AlignableVolume(const AlignableVolume &)=delete
void setCalib(std::unique_ptr< DOFSet > cal)
virtual ~DOFSet()=default
std::vector< bool > mFree
virtual Type type() const =0
virtual std::string dofName(int idx) const =0
void setFree(int idx, bool f)
bool isFree(int idx) const
static constexpr T CALIB_MASK
GlobalLabel asCalib() const noexcept
return a copy of this label with the CALIB bit set (for calibration DOFs on same volume)
static constexpr int SENS_BITS
constexpr T raw(T dof) const noexcept
produce the raw Millepede label for a given DOF index (rigid body: calib=0 in label)
constexpr T id() const noexcept
static constexpr int ID_BITS
constexpr int rawGBL(T dof) const noexcept
static constexpr T SENS_MAX
static constexpr T DOF_MAX
static constexpr int DOF_BITS
constexpr auto operator<=>(const GlobalLabel &) const noexcept=default
constexpr bool calib() const noexcept
static constexpr T SENS_MASK
constexpr bool sens() const noexcept
static constexpr int TOTAL_BITS
static constexpr int DET_SHIFT
static constexpr int DOF_SHIFT
constexpr T det() const noexcept
static constexpr T bitMask(int b) noexcept
static constexpr int ID_SHIFT
static constexpr T DOF_MASK
std::string asString() const
GlobalLabel(T det, T id, bool sens, bool calib=false)
static constexpr int CALIB_SHIFT
static constexpr T ID_MAX
static constexpr T DET_MAX
static constexpr int DET_BITS
static constexpr int SENS_SHIFT
static constexpr T DET_MASK
static constexpr int CALIB_BITS
static constexpr T CALIB_MAX
static constexpr T ID_MASK
void add(uint32_t lab, double coeff)
auto getSize() const noexcept
HierarchyConstraint(std::string name, double value)
void write(std::ostream &os) const
Type type() const override
std::string dofName(int idx) const override
LegendreDOFSet(int order)
RigidBodyDOFSet(uint8_t mask)
static constexpr int NDOF
std::string dofName(int idx) const override
Type type() const override
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * value
GLuint GLsizei const GLchar * label
Eigen::Matrix< double, 3, 6 > Matrix36
Eigen::Matrix< double, 6, 6 > Matrix66
void writeMillepedeResults(AlignableVolume *root, const std::string &milleResPath, const std::string &outJsonPath, const std::string &injectedJsonPath="")
void applyDOFConfig(AlignableVolume *root, const std::string &jsonPath)
auto getRigidBodyDerivatives(const auto &trk)
Defining DataPointCompositeObject explicitly as copiable.