14#include <TGeoManager.h>
15#include <TGeoMatrix.h>
17#include <TGeoPhysicalNode.h>
19#include <TGeoVolume.h>
26 constexpr bool kEulerAngles =
false;
40 TGeoRotation rot(
"", rotX, rotY, rotZ);
41 fGlobal.SetRotation(rot.GetRotationMatrix());
72 LOG(fatal) <<
"TGeoManager is not initialized!";
77 LOG(fatal) <<
"Alignment node path is empty!";
82 LOG(fatal) <<
"Alignment node path is not global. It must start with \"/\" "
87 if (!gGeoManager->cd(
fNodePath.c_str())) {
88 LOG(fatal) <<
"Failed to cd to path " <<
fNodePath;
91 LOG(debug) <<
"Found alignment body: " <<
fNodePath;
94 const TGeoNode* node = gGeoManager->GetCurrentNode();
96 LOG(fatal) <<
"Failed to find TGeoNode at path " <<
fNodePath;
102 ->GetCurrentMatrix());
108 TGeoHMatrix GlobalMother =
110 ->GetCurrentMatrix());
116 TObjArray* pNodes = gGeoManager->GetListOfPhysicalNodes();
117 for (
int i = 0; i < pNodes->GetEntriesFast(); i++) {
118 const TGeoPhysicalNode* pnode =
dynamic_cast<const TGeoPhysicalNode*
>(pNodes->At(i));
120 LOG(fatal) <<
"Failed to cast TGeoPhysicalNode at index " << i;
123 if (pnode->GetNode() == node) {
125 LOG(warn) <<
"Found pre-existing alignment for node " <<
fNodePath
126 <<
". Pre-existing alignment will be ignored and replaced by new alignment.";
127 TGeoHMatrix localNoniminal = *(pnode->GetOriginalMatrix());
131 TGeoHMatrix A0 = localNoniminal.Inverse() * (GlobalMother.Inverse() *
fGlobal);
164 fAlignment.SetRotation(rot.GetRotationMatrix());
179 std::array<double, 3> alignedHit;
188 std::array<double, 3> alignedHit;
Alignment body class for the BBA alignment.
void ActivateParameters(const std::array< bool, NofParameters > &isParActive)
TGeoHMatrix fGlobal
global transformation matrix of the alignment body
TGeoHMatrix fGlobalNominal
nominal global transformation matrix, without (pre-)alignment
std::string fNodePath
full path to the node in the root geometry
bool fIsValid
flag indicating if the alignment body is valid
std::array< double, 3 > ApplyAlignmentToHit(const std::array< double, 3 > hit) const
Apply the alignment to hit: return = fHitTransform * hit.
const std::array< double, NofParameters > & GetParameters() const
Get the alignment parameters.
AlignmentBody()=default
Default constructor.
std::array< double, NofParameters > fPar
alignment parameters: shiftX, shiftY, shiftZ, rotX, rotY, rotZ
std::array< bool, NofParameters > fIsParActive
flags for the parameters to be aligned
static constexpr int NofParameters
number of alignment parameters
TGeoHMatrix fHitTransform
TGeoHMatrix fAlignment
transformation matrix of the alignment body. Corresponds to the fPar values.
bool CreateFromGeoNode(const std::string nodePath)
void SetParameters(double shiftX=0., double shiftY=0., double shiftZ=0., double rotX=0., double rotY=0., double rotZ=0.)
TGeoHMatrix fGlobalInv
inverse of the global transformation matrix
std::array< double, 3 > ApplyInverseAlignmentToHit(const std::array< double, 3 > hit) const
Apply the inverse alignment to hit: return = fHitTransform^{-1} * hit.