Project
Loading...
Searching...
No Matches
AlignmentHierarchy.h
Go to the documentation of this file.
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_HIERARCHY_H
13#define O2_ITS3_ALIGNMENT_HIERARCHY_H
14
15#include <memory>
16#include <utility>
17#include <vector>
18#include <ostream>
19#include <string>
20#include <map>
21#include <algorithm>
22
23#include <Eigen/Dense>
24
25#include <TGeoMatrix.h>
26#include <TGeoPhysicalNode.h>
27
30
32{
33using Matrix36 = Eigen::Matrix<double, 3, 6>;
34using Matrix66 = Eigen::Matrix<double, 6, 6>;
35
37{
38 public:
39 HierarchyConstraint(std::string name, double value) : mName(std::move(name)), mValue(value) {}
40 void add(uint32_t lab, double coeff)
41 {
42 mLabels.push_back(lab);
43 mCoeff.push_back(coeff);
44 }
45 void write(std::ostream& os) const;
46 auto getSize() const noexcept { return mLabels.size(); }
47
48 private:
49 std::string mName; // name of the constraint
50 double mValue{0.0}; // constraint value
51 std::vector<uint32_t> mLabels; // parameter labels
52 std::vector<double> mCoeff; // their coefficients
53};
54
56{
57 public:
58 using Ptr = std::unique_ptr<AlignableVolume>;
59 using SensorMapping = std::map<GlobalLabel, AlignableVolume*>;
60
65 AlignableVolume(const char* symName, uint32_t label, uint32_t det, bool sens);
66 AlignableVolume(const char* symName, GlobalLabel label);
67 virtual ~AlignableVolume() = default;
68
69 void finalise(uint8_t level = 0);
70
71 // steering file output
72 void writeRigidBodyConstraints(std::ostream& os) const;
73 void writeParameters(std::ostream& os) const;
74 void writeTree(std::ostream& os, int indent = 0) const;
75
76 // tree-like
77 auto getLevel() const noexcept { return mLevel; }
78 bool isRoot() const noexcept { return mParent == nullptr; }
79 bool isLeaf() const noexcept { return mChildren.empty(); }
80 template <class T = AlignableVolume>
81 requires std::derived_from<T, AlignableVolume>
82 AlignableVolume* addChild(const char* symName, uint32_t label, uint32_t det, bool sens)
83 {
84 auto c = std::make_unique<T>(symName, label, det, sens);
85 return setParent(std::move(c));
86 }
87 template <class T = AlignableVolume>
88 requires std::derived_from<T, AlignableVolume>
89 AlignableVolume* addChild(const char* symName, GlobalLabel lbl)
90 {
91 auto c = std::make_unique<T>(symName, lbl);
92 return setParent(std::move(c));
93 }
94
95 // bfs traversal
96 void traverse(const std::function<void(AlignableVolume*)>& visitor)
97 {
98 visitor(this);
99 for (auto& c : mChildren) {
100 c->traverse(visitor);
101 }
102 }
103
104 std::string getSymName() const noexcept { return mSymName; }
105 GlobalLabel getLabel() const noexcept { return mLabel; }
106 AlignableVolume* getParent() const { return mParent; }
107 size_t getNChildren() const noexcept { return mChildren.size(); }
108
109 // DOF management
110 void setRigidBody(std::unique_ptr<DOFSet> rb) { mRigidBody = std::move(rb); }
111 void setCalib(std::unique_ptr<DOFSet> cal) { mCalib = std::move(cal); }
112 DOFSet* getRigidBody() const { return mRigidBody.get(); }
113 DOFSet* getCalib() const { return mCalib.get(); }
114 void setPseudo(bool p) noexcept { mIsPseudo = p; }
115 bool isPseudo() const noexcept { return mIsPseudo; }
116 void setSensorId(int id) noexcept { mSensorId = id; }
117 int getSensorId() const noexcept { return mSensorId; }
118 // true if this volume participates in the hierarchy (has DOFs or is pseudo)
119 bool isActive() const noexcept { return mRigidBody != nullptr || mIsPseudo; }
120
121 // transformation matrices
122 virtual void defineMatrixL2G() {}
123 virtual void defineMatrixT2L() {}
124 virtual void computeJacobianL2T(const double* pos, Matrix66& jac) const {};
125 const TGeoHMatrix& getL2P() const { return mL2P; }
126 const TGeoHMatrix& getT2L() const { return mT2L; }
127 const Matrix66& getJL2P() const { return mJL2P; }
128 const Matrix66& getJP2L() const { return mJP2L; }
129
130 protected:
132 AlignableVolume* mParent{nullptr}; // parent
133 TGeoPNEntry* mPNE{nullptr}; // physical entry
134 TGeoPhysicalNode* mPN{nullptr}; // physical node
135 TGeoHMatrix mL2G; // (LOC) -> (GLO)
136 TGeoHMatrix mL2P; // (LOC) -> (PAR)
137 Matrix66 mJL2P; // jac (LOC) -> (PAR)
138 Matrix66 mJP2L; // jac (PAR) -> (LOC)
139 TGeoHMatrix mT2L; // (TRK) -> (LOC)
140
141 private:
142 std::string mSymName;
143 GlobalLabel mLabel;
144 uint8_t mLevel{0};
145 bool mIsPseudo{false};
146 int mSensorId{-1};
147 std::unique_ptr<DOFSet> mRigidBody;
148 std::unique_ptr<DOFSet> mCalib;
149
150 AlignableVolume* setParent(Ptr c)
151 {
152 c->mParent = this;
153 mChildren.push_back(std::move(c));
154 return mChildren.back().get();
155 }
156 std::vector<Ptr> mChildren; // children
157
158 void init();
159};
160
161// apply DOF configuration from a JSON file to the hierarchy
162void applyDOFConfig(AlignableVolume* root, const std::string& jsonPath);
163
164// parse millepede.res and write result.json with fitted parameters for ITS3 half barrels
165void writeMillepedeResults(AlignableVolume* root, const std::string& milleResPath, const std::string& outJsonPath, const std::string& injectedJsonPath = "");
166
167} // namespace o2::its3::align
168
169#endif
uint16_t pos
Definition RawData.h:3
uint32_t c
Definition RawData.h:2
AlignableVolume * addChild(const char *symName, GlobalLabel lbl)
virtual void computeJacobianL2T(const double *pos, Matrix66 &jac) const
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
std::unique_ptr< AlignableVolume > Ptr
void writeParameters(std::ostream &os) const
AlignableVolume & operator=(AlignableVolume &&)=delete
GlobalLabel getLabel() const noexcept
const TGeoHMatrix & getT2L() const
AlignableVolume(AlignableVolume &&)=delete
AlignableVolume * mParent
matrices
const TGeoHMatrix & getL2P() const
void setRigidBody(std::unique_ptr< DOFSet > rb)
AlignableVolume & operator=(const AlignableVolume &)=delete
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)
void add(uint32_t lab, double coeff)
HierarchyConstraint(std::string name, double value)
GLuint const GLchar * name
Definition glcorearb.h:781
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLuint GLsizei const GLchar * label
Definition glcorearb.h:2519
GLuint id
Definition glcorearb.h:650
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)