BmnRoot
26.10.0-233-gb9bbe585
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.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
32
class
BmnATestDetectorPlane
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)
58
Double_t
fConst
;
// d
59
// transition to detector local coordinates
60
SMatr3x3
fCoordRotation
,
fCoordInvRotation
;
61
SVect3
fCoordShift
;
62
Int_t
fDetectorID
;
63
};
64
65
// it is up to compiler to keep this function inlined
66
67
inline
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
++) {
72
if
(
i
>=
BMN_GLOBAL_PARAMS_PD
)
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
}
81
fCoordShift
=
fAlignShift
;
82
fCoordShift
(
iZ
) +=
fZposition
;
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
103
fNormal
=
fCoordRotation
.Col(
iZ
);
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
108
fConst
= -
ROOT::Math::Dot
(
fNormal
,
fCoordShift
);
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
118
inline
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
BMN_NORMAL_COLOR
#define BMN_NORMAL_COLOR
Definition
BmnATestDetectorPlane.h:30
BMN_PLANE_COLOR
#define BMN_PLANE_COLOR
Definition
BmnATestDetectorPlane.h:29
BMN_PLANE_SIZE
#define BMN_PLANE_SIZE
Definition
BmnATestDetectorPlane.h:28
BmnAlignDefines.h
SVect3
RM::SVector< Double_t, 3 > SVect3
Definition
BmnAlignDefines.h:59
SVectGL
RM::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
Definition
BmnAlignDefines.h:61
SMatr3x3
RM::SMatrix< Double_t, 3, 3 > SMatr3x3
Definition
BmnAlignDefines.h:63
iZ
@ iZ
Definition
BmnAlignDefines.h:27
iX
@ iX
Definition
BmnAlignDefines.h:25
iY
@ iY
Definition
BmnAlignDefines.h:26
BMN_GLOBAL_PARAMS_PD
#define BMN_GLOBAL_PARAMS_PD
Definition
BmnAlignDefines.h:20
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
BmnATestDetectorPlane::fCoordInvRotation
SMatr3x3 fCoordInvRotation
Definition
BmnATestDetectorPlane.h:60
BmnATestDetectorPlane::GetNormal
const SVect3 & GetNormal() const noexcept
Definition
BmnATestDetectorPlane.h:42
BmnATestDetectorPlane::fAlignRot
SVect3 fAlignRot
Definition
BmnATestDetectorPlane.h:54
BmnATestDetectorPlane::BmnATestDetectorPlane
BmnATestDetectorPlane()=default
BmnATestDetectorPlane::fAlignShift
SVect3 fAlignShift
Definition
BmnATestDetectorPlane.h:53
BmnATestDetectorPlane::GetCrdShift
const SVect3 & GetCrdShift() const noexcept
Definition
BmnATestDetectorPlane.h:45
BmnATestDetectorPlane::GetPosition
Double_t GetPosition() const noexcept
Definition
BmnATestDetectorPlane.h:38
BmnATestDetectorPlane::fDetectorID
Int_t fDetectorID
Definition
BmnATestDetectorPlane.h:62
BmnATestDetectorPlane::GetAlignRot
const SVect3 & GetAlignRot() const noexcept
Definition
BmnATestDetectorPlane.h:48
BmnATestDetectorPlane::fConst
Double_t fConst
Definition
BmnATestDetectorPlane.h:58
BmnATestDetectorPlane::fCoordShift
SVect3 fCoordShift
Definition
BmnATestDetectorPlane.h:61
BmnATestDetectorPlane::GetCrdInvRotation
const SMatr3x3 & GetCrdInvRotation() const noexcept
Definition
BmnATestDetectorPlane.h:44
BmnATestDetectorPlane::fNormal
SVect3 fNormal
Definition
BmnATestDetectorPlane.h:57
BmnATestDetectorPlane::GetCrdRotation
const SMatr3x3 & GetCrdRotation() const noexcept
Definition
BmnATestDetectorPlane.h:43
BmnATestDetectorPlane::GetAlignShift
const SVect3 & GetAlignShift() const noexcept
Definition
BmnATestDetectorPlane.h:47
BmnATestDetectorPlane::Draw
void Draw(Bool_t showNormal=kFALSE) const
Definition
BmnATestDetectorPlane.h:118
BmnATestDetectorPlane::fZposition
Double_t fZposition
Definition
BmnATestDetectorPlane.h:52
BmnATestDetectorPlane::GetDetectorID
Int_t GetDetectorID() const noexcept
Definition
BmnATestDetectorPlane.h:39
BmnATestDetectorPlane::GetConst
Double_t GetConst() const noexcept
Definition
BmnATestDetectorPlane.h:41
BmnATestDetectorPlane::fCoordRotation
SMatr3x3 fCoordRotation
Definition
BmnATestDetectorPlane.h:60
TPolyLine3D
ROOT::Math::Dot
T Dot(const SVector< T, D > &lhs, const SVector< T, D > &rhs)
Functions.h
TMath::Cos
Double_t Cos(Double_t)
TMath::Sin
Double_t Sin(Double_t)
align_new
deprecated
BmnATestDetectorPlane.h
Generated on
for BmnRoot by
1.17.0