BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
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
26
class
BmnATestDetectorPlane
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
54
SMatr3x3
fCoordRotation
,
fCoordInvRotation
;
55
SVect3
fCoordShift
;
56
Int_t
fDetectorID
;
57
};
58
59
// it is up to compiler to keep this function inlined
60
61
inline
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
++) {
66
if
(
i
>=
BMN_GLOBAL_PARAMS_PD
)
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
}
75
fCoordShift
=
fAlignShift
;
76
fCoordShift
(
iZ
) +=
fZposition
;
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
97
fNormal
=
fCoordRotation
.Col(
iZ
);
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
112
inline
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
i
int i
Definition
P4_F32vec4.h:22
Bool_t
bool Bool_t
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
TMath.h
TPolyLine3D.h
BmnAlignDefines.h
SVectGL
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
Definition
BmnAlignDefines.h:73
SMatr3x3
ROOT::Math::SMatrix< Double_t, 3, 3 > SMatr3x3
Definition
BmnAlignDefines.h:76
SVect3
ROOT::Math::SVector< Double_t, 3 > SVect3
Definition
BmnAlignDefines.h:71
iZ
@ iZ
Definition
BmnAlignDefines.h:87
iX
@ iX
Definition
BmnAlignDefines.h:85
iY
@ iY
Definition
BmnAlignDefines.h:86
BMN_GLOBAL_PARAMS_PD
#define BMN_GLOBAL_PARAMS_PD
Definition
BmnAlignDefines.h:21
BmnATestDetectorPlane::fCoordInvRotation
SMatr3x3 fCoordInvRotation
Definition
BmnATestDetectorPlane.h:54
BmnATestDetectorPlane::GetNormal
const SVect3 & GetNormal() const noexcept
Definition
BmnATestDetectorPlane.h:36
BmnATestDetectorPlane::fAlignRot
SVect3 fAlignRot
Definition
BmnATestDetectorPlane.h:48
BmnATestDetectorPlane::BmnATestDetectorPlane
BmnATestDetectorPlane()=default
BmnATestDetectorPlane::fAlignShift
SVect3 fAlignShift
Definition
BmnATestDetectorPlane.h:47
BmnATestDetectorPlane::GetCrdShift
const SVect3 & GetCrdShift() const noexcept
Definition
BmnATestDetectorPlane.h:39
BmnATestDetectorPlane::GetPosition
Double_t GetPosition() const noexcept
Definition
BmnATestDetectorPlane.h:32
BmnATestDetectorPlane::fDetectorID
Int_t fDetectorID
Definition
BmnATestDetectorPlane.h:56
BmnATestDetectorPlane::GetAlignRot
const SVect3 & GetAlignRot() const noexcept
Definition
BmnATestDetectorPlane.h:42
BmnATestDetectorPlane::fConst
Double_t fConst
Definition
BmnATestDetectorPlane.h:52
BmnATestDetectorPlane::fCoordShift
SVect3 fCoordShift
Definition
BmnATestDetectorPlane.h:55
BmnATestDetectorPlane::GetCrdInvRotation
const SMatr3x3 & GetCrdInvRotation() const noexcept
Definition
BmnATestDetectorPlane.h:38
BmnATestDetectorPlane::fNormal
SVect3 fNormal
Definition
BmnATestDetectorPlane.h:51
BmnATestDetectorPlane::GetCrdRotation
const SMatr3x3 & GetCrdRotation() const noexcept
Definition
BmnATestDetectorPlane.h:37
BmnATestDetectorPlane::GetAlignShift
const SVect3 & GetAlignShift() const noexcept
Definition
BmnATestDetectorPlane.h:41
BmnATestDetectorPlane::Draw
void Draw(Bool_t showNormal=kFALSE) const
Definition
BmnATestDetectorPlane.h:112
BmnATestDetectorPlane::fZposition
Double_t fZposition
Definition
BmnATestDetectorPlane.h:46
BmnATestDetectorPlane::GetDetectorID
Int_t GetDetectorID() const noexcept
Definition
BmnATestDetectorPlane.h:33
BmnATestDetectorPlane::GetConst
Double_t GetConst() const noexcept
Definition
BmnATestDetectorPlane.h:35
BmnATestDetectorPlane::fCoordRotation
SMatr3x3 fCoordRotation
Definition
BmnATestDetectorPlane.h:54
TPolyLine3D
ROOT::Math::Dot
T Dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
BMN_NORMAL_COLOR
#define BMN_NORMAL_COLOR
Definition
BmnATestDetectorPlane.h:24
BMN_PLANE_COLOR
#define BMN_PLANE_COLOR
Definition
BmnATestDetectorPlane.h:23
BMN_PLANE_SIZE
#define BMN_PLANE_SIZE
Definition
BmnATestDetectorPlane.h:22
Functions.h
TMath::Cos
Double_t Cos(Double_t)
TMath::Sin
Double_t Sin(Double_t)
align_new
src
BmnATestDetectorPlane.h
Generated on
for BmnRoot by
1.17.0