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