BmnRoot
Loading...
Searching...
No Matches
BmnATestDetectorPlane.h
Go to the documentation of this file.
1/*
2 BM@N alignment routine
3 BM@N experiment at NICA complex, JINR, 2025
4
5 Department: Math & Soft Group of HEP lab
6 Author: Igor Polev, polev@jinr.ru
7
8 BmnATestDetectorPlane class header-only implementation
9 Minimalistic representation of detector for alignment algorithm test only
10*/
11
12#ifndef BMNATESTDETECTORPLANE_H
13#define BMNATESTDETECTORPLANE_H
14
15#include "BmnAlignDefines.h"
16#include "Math/Functions.h"
17#include "TMath.h"
18#include "TPolyLine3D.h"
19
20#include <stdexcept>
21
22#define BMN_PLANE_SIZE 400.0
23#define BMN_PLANE_COLOR kBlue
24#define BMN_NORMAL_COLOR kRed
25
27{
28 public:
29 BmnATestDetectorPlane() = default; // required for BMN project to be compilable
30 BmnATestDetectorPlane(Double_t Zposition, const SVectGL& Misalignments, Int_t DetectorID);
31
32 Double_t GetPosition() const noexcept { return fZposition; };
33 Int_t GetDetectorID() const noexcept { return fDetectorID; };
34
35 Double_t GetConst() const noexcept { return fConst; };
36 const SVect3& GetNormal() const noexcept { return fNormal; };
37 const SMatr3x3& GetCrdRotation() const noexcept { return fCoordRotation; };
38 const SMatr3x3& GetCrdInvRotation() const noexcept { return fCoordInvRotation; };
39 const SVect3& GetCrdShift() const noexcept { return fCoordShift; };
40
41 const SVect3& GetAlignShift() const noexcept { return fAlignShift; };
42 const SVect3& GetAlignRot() const noexcept { return fAlignRot; };
43
44 void Draw(Bool_t showNormal = kFALSE) const; // for ROOT macro mode only
45 protected:
46 Double_t fZposition; // nominal position of detector plane
47 SVect3 fAlignShift, // detector position shift in x,y,z axis
48 fAlignRot; // detector position rotation around x,y,z axis
49 // attention: rotations are applied in reverse order (z, y, x)
50 // equation is defined in form ax + by + cz + d = 0
51 SVect3 fNormal; // (a,b,c)
52 Double_t fConst; // d
53 // transition to detector local coordinates
57};
58
59// it is up to compiler to keep this function inlined
60
61inline BmnATestDetectorPlane::BmnATestDetectorPlane(Double_t Zposition, const SVectGL& Misalignmets, Int_t DetectorID)
62 : fZposition(Zposition)
63 , fDetectorID(DetectorID)
64{
65 for (Int_t i = iX; i <= iZ; i++) {
67 break;
68 fAlignShift(i) = Misalignmets(i);
69 }
70 for (Int_t i = iX, j = iZ + 1; i <= iZ; i++, j++) {
71 if (j >= BMN_GLOBAL_PARAMS_PD)
72 break;
73 fAlignRot(i) = Misalignmets(j);
74 }
77
78 Double_t sinAlpha{TMath::Sin(fAlignRot(iX))}, // rotation over x
79 cosAlpha{TMath::Cos(fAlignRot(iX))}, sinBeta{TMath::Sin(fAlignRot(iY))}, // rotation over y
80 cosBeta{TMath::Cos(fAlignRot(iY))}, sinGamma{TMath::Sin(fAlignRot(iZ))}, // rotation over z
81 cosGamma{TMath::Cos(fAlignRot(iZ))};
82
83 // rotation matrix in the following order: over z, over y, over x
84 fCoordRotation(iX, iX) = cosBeta * cosGamma;
85 fCoordRotation(iX, iY) = -cosBeta * sinGamma;
86 fCoordRotation(iX, iZ) = sinBeta;
87 fCoordRotation(iY, iX) = sinAlpha * sinBeta * cosGamma + cosAlpha * sinGamma;
88 fCoordRotation(iY, iY) = -sinAlpha * sinBeta * sinGamma + cosAlpha * cosGamma;
89 fCoordRotation(iY, iZ) = -sinAlpha * cosBeta;
90 fCoordRotation(iZ, iX) = sinAlpha * sinGamma - cosAlpha * sinBeta * cosGamma;
91 fCoordRotation(iZ, iY) = sinAlpha * cosGamma + cosAlpha * sinBeta * sinGamma;
92 fCoordRotation(iZ, iZ) = cosAlpha * cosBeta;
93
94 // normal vector calculated by rotation of (0,0,1)
95 // on misalignment rotation angles:
96 // it is exactly the 3rd column of rotation matrix
98 // constant d of equation ax + by + cz + d = 0
99 // calculated from point on detector plane X
100 // to satisfy equation:
101 // d = - Normal dot X
102 fConst = -ROOT::Math::Dot(fNormal, fCoordShift);
103
104 Int_t inverse_failure;
105 fCoordInvRotation = fCoordRotation.Inverse(inverse_failure);
106 // here inverse can't fail normally
107 if (inverse_failure)
108 throw std::runtime_error("BmnATestDetectorPlane: rotation matrix inverse failed");
109}
110
111// visualization works in ROOT macro mode only
112inline void BmnATestDetectorPlane::Draw(Bool_t showNormal) const
113{
114 const Double_t halfSize{BMN_PLANE_SIZE / 2.0};
115
116 // square outline in local (detector) coordinates
117 SVect3 points[5];
118 points[0](iX) = -halfSize;
119 points[0](iY) = -halfSize;
120 points[1](iX) = -halfSize;
121 points[1](iY) = halfSize;
122 points[2](iX) = halfSize;
123 points[2](iY) = halfSize;
124 points[3](iX) = halfSize;
125 points[3](iY) = -halfSize;
126 points[4] = points[0];
127
128 // transformation into global (lab) coordinates
129 Double_t x[5], y[5], z[5];
130 for (int i = 0; i < 5; i++) {
131 points[i] = fCoordRotation * points[i] + fCoordShift;
132 x[i] = points[i](iX);
133 y[i] = points[i](iY);
134 z[i] = points[i](iZ);
135 }
136
137 // visualization using polyline
138 // note: x and z axis are swapped
139 auto* outline = new TPolyLine3D(5, z, y, x);
140 outline->SetLineColor(BMN_PLANE_COLOR);
141 outline->Draw();
142
143 if (!showNormal)
144 return;
145
146 // draw normal to the plane
147 SVect3 normal[2];
148 normal[1](iZ) = BMN_PLANE_SIZE;
149 for (int i = 0; i < 2; i++) {
150 normal[i] = fCoordRotation * normal[i] + fCoordShift;
151 x[i] = normal[i](iX);
152 y[i] = normal[i](iY);
153 z[i] = normal[i](iZ);
154 }
155 auto* normalLine = new TPolyLine3D(2, z, y, x);
156 normalLine->SetLineColor(BMN_NORMAL_COLOR);
157 normalLine->Draw();
158
159 // in macro mode we don't clean RAM, sorry
160}
161
162#endif // BMNATESTDETECTORPLANE_H
#define BMN_NORMAL_COLOR
#define BMN_PLANE_COLOR
#define BMN_PLANE_SIZE
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
ROOT::Math::SMatrix< Double_t, 3, 3 > SMatr3x3
ROOT::Math::SVector< Double_t, 3 > SVect3
@ iZ
@ iX
@ iY
#define BMN_GLOBAL_PARAMS_PD
int i
Definition P4_F32vec4.h:22
const SVect3 & GetNormal() const noexcept
BmnATestDetectorPlane()=default
const SVect3 & GetCrdShift() const noexcept
Double_t GetPosition() const noexcept
const SVect3 & GetAlignRot() const noexcept
const SMatr3x3 & GetCrdInvRotation() const noexcept
const SMatr3x3 & GetCrdRotation() const noexcept
const SVect3 & GetAlignShift() const noexcept
void Draw(Bool_t showNormal=kFALSE) const
Int_t GetDetectorID() const noexcept
Double_t GetConst() const noexcept