BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnAlignResult.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
BmnAlignResult class header-only implementation
9
Stores results of alignment iteration
10
*/
11
12
#ifndef BMNALIGNRESULT_H
13
#define BMNALIGNRESULT_H
14
15
#include "
BmnAlignDefines.h
"
16
#include "
TH1D.h
"
17
#include "
TVectorD.h
"
18
19
#include <algorithm>
20
#include <array>
21
#include <stdexcept>
22
#include <vector>
23
24
class
BmnAlignResult
25
{
26
public
:
27
typedef
std::array<std::pair<Int_t, Double_t>,
BMN_MODULE_COUNT
>
IdxValuePair_t
;
28
typedef
std::array<SVectGL, BMN_MODULE_COUNT>
ArraySVectGL_t
;
29
typedef
std::array<SVectLC, BMN_MODULE_COUNT>
ArraySVectLC_t
;
30
typedef
std::array<Double_t, BMN_MODULE_COUNT>
ArrayDouble_t
;
31
typedef
std::vector<SVectLC>
VectorSVectLC_t
;
32
33
private
:
34
VectorSVectLC_t
fAlpha
;
// array of local parameters for each track
35
SVectGLT
fAfull
;
// global parameters for all detectors in one vector
36
ArraySVectGL_t
fA
;
// array of global parameters for each detector
37
TVectorD
fL
,
// Lagrange multipliers for global parameters constrains
38
fSVDSig
;
// singular values vector from SVD decomposition
39
TH1D
fResidualsX
,
// histogram of residuals by X coordinate
40
fResidualsY
;
// histogram of residuals by Y coordinate
41
ArrayDouble_t
fMSE
;
// MSE values per detector plane
42
Double_t
fMSEtotal
;
// total value of target function at current solution
43
const
Int_t
fAlphaCount
;
// number of tracks (set in constructor)
44
45
public
:
46
explicit
BmnAlignResult
(
Int_t
TrackCount);
47
BmnAlignResult
(
const
BmnAlignResult
& other);
48
BmnAlignResult
&
operator=
(
const
BmnAlignResult
& other);
49
~BmnAlignResult
() =
default
;
50
// default constructor is required for ROOT serialization and not intended to be used
51
BmnAlignResult
()
52
:
fAlphaCount
(0) {};
53
54
VectorSVectLC_t
&
Alpha
() noexcept {
return
fAlpha
; };
55
SVectLC
&
Alpha
(
Int_t
index)
noexcept
{
return
fAlpha
[index]; };
56
SVectGL
&
A
(
Int_t
index)
noexcept
{
return
fA
[index]; };
57
SVectGLT
&
A
() noexcept {
return
fAfull
; };
58
TVectorD
&
L
() noexcept {
return
fL
; };
59
TVectorD
&
SVDSig
() noexcept {
return
fSVDSig
; };
60
TH1D
&
ResidualsX
() noexcept {
return
fResidualsX
; };
61
TH1D
&
ResidualsY
() noexcept {
return
fResidualsY
; };
62
63
Double_t
GetValueMSE
(
Int_t
index)
const
noexcept
{
return
fMSE
[index]; };
64
Double_t
GetValueMSE
() const noexcept {
return
fMSEtotal
; };
65
Int_t
GetAlphaCount
() const noexcept {
return
fAlphaCount
; };
66
ULong_t
GetHistCounter
() const noexcept;
67
IdxValuePair_t
GetSortedMSE
() const;
68
69
void
AddValueMSE
(
Int_t
detectorIndex,
Double_t
val);
70
void
ResetValueMSE
();
71
72
void
SeparateA
();
73
void
ConcatenateA
();
74
};
75
76
// Inline implementations
77
78
inline
BmnAlignResult
::
BmnAlignResult
(
Int_t
TrackCount)
79
:
fAlpha
(TrackCount)
80
,
fAfull
()
81
,
fA
()
82
,
fL
()
83
,
fSVDSig
()
84
,
fResidualsX
(
Form
(
"residualsX_%lu"
,
GetHistCounter
()),
85
"Residuals by X"
,
86
BMN_RESIDUALS_BINS
,
87
-
BMN_RESIDUALS_RANGE_X
,
88
BMN_RESIDUALS_RANGE_X
)
89
,
fResidualsY
(
Form
(
"residualsY_%lu"
,
GetHistCounter
()),
90
"Residuals by Y"
,
91
BMN_RESIDUALS_BINS
,
92
-
BMN_RESIDUALS_RANGE_Y
,
93
BMN_RESIDUALS_RANGE_Y
)
94
,
fMSE
{}
95
,
fMSEtotal
(0.0)
96
,
fAlphaCount
(TrackCount)
97
{
98
ResetValueMSE
();
99
}
100
101
inline
BmnAlignResult::BmnAlignResult
(
const
BmnAlignResult
& other)
102
:
fAlpha
(other.
fAlpha
)
103
,
fAfull
(other.
fAfull
)
104
,
fA
(other.
fA
)
105
,
fL
(other.
fL
)
106
,
fSVDSig
(other.
fSVDSig
)
107
,
fResidualsX
(other.
fResidualsX
)
108
,
fResidualsY
(other.
fResidualsY
)
109
,
fMSE
(other.
fMSE
)
110
,
fMSEtotal
(other.
fMSEtotal
)
111
,
fAlphaCount
(other.
fAlphaCount
)
112
{
113
// Update histogram names to be unique using common counter
114
fResidualsX
.SetName(
Form
(
"residualsX_%lu"
,
GetHistCounter
()));
115
fResidualsY
.SetName(
Form
(
"residualsY_%lu"
,
GetHistCounter
()));
116
}
117
118
inline
BmnAlignResult
&
BmnAlignResult::operator=
(
const
BmnAlignResult
& other)
119
{
120
if
(
this
== &other)
121
return
*
this
;
122
if
(
fAlphaCount
!= other.
fAlphaCount
)
123
throw
std::runtime_error(
"BmnAlignResult: assignment between objects with different alphaCount"
);
124
125
fL
.ResizeTo(other.
fL
);
126
fSVDSig
.ResizeTo(other.
fSVDSig
);
127
fAlpha
= other.
fAlpha
;
128
fAfull
= other.
fAfull
;
129
fA
= other.
fA
;
130
fL
= other.
fL
;
131
fSVDSig
= other.
fSVDSig
;
132
fResidualsX
= other.
fResidualsX
;
133
fResidualsY
= other.
fResidualsY
;
134
fMSE
= other.
fMSE
;
135
fMSEtotal
= other.
fMSEtotal
;
136
137
return
*
this
;
138
}
139
140
inline
BmnAlignResult::IdxValuePair_t
BmnAlignResult::GetSortedMSE
()
const
141
{
142
IdxValuePair_t
result;
143
for
(
Int_t
i
= 0;
i
<
BMN_MODULE_COUNT
;
i
++) {
144
result[
i
] = std::make_pair(
i
,
fMSE
[
i
]);
145
}
146
147
// Sort by MSE value in ascending order (best detectors first)
148
std::sort(result.begin(), result.end(),
149
[](
const
std::pair<Int_t, Double_t>& a,
const
std::pair<Int_t, Double_t>& b)
noexcept
{
150
return a.second < b.second;
151
}
// ascending order (best detectors first)
152
);
153
154
return
result;
155
}
156
157
inline
void
BmnAlignResult::AddValueMSE
(
Int_t
detectorIndex,
Double_t
val)
158
{
159
if
(detectorIndex < 0 || detectorIndex >=
BMN_MODULE_COUNT
)
160
throw
std::runtime_error(
"BmnAlignResult: detectorIndex out of range"
);
161
fMSE
[detectorIndex] += val;
162
fMSEtotal
+= val;
163
}
164
165
inline
void
BmnAlignResult::ResetValueMSE
()
166
{
167
fMSE
.fill(0.0);
168
fMSEtotal
= 0.0;
169
}
170
171
inline
void
BmnAlignResult::SeparateA
()
172
{
173
auto
itr{
fAfull
.begin()};
174
for
(
Int_t
i
= 0;
i
<
BMN_MODULE_COUNT
;
i
++, itr +=
BMN_GLOBAL_PARAMS_PD
)
175
fA
[
i
].SetElements(itr,
BMN_GLOBAL_PARAMS_PD
);
176
}
177
178
inline
void
BmnAlignResult::ConcatenateA
()
179
{
180
for
(
Int_t
i
= 0, j = 0;
i
<
BMN_MODULE_COUNT
;
i
++, j +=
BMN_GLOBAL_PARAMS_PD
)
181
fAfull
.Place_at(
fA
[
i
], j);
182
}
183
184
inline
ULong_t
BmnAlignResult::GetHistCounter
() const noexcept
185
{
186
// Common counter for all histograms in all BmnAlignResult instances
187
static
ULong_t
sHistCounter{0};
188
return
++sHistCounter;
189
};
190
191
#endif
// BMNALIGNRESULT_H
i
int i
Definition
P4_F32vec4.h:22
Int_t
int Int_t
ULong_t
unsigned long ULong_t
Double_t
double Double_t
TH1D.h
Form
char * Form(const char *fmt,...)
TVectorD.h
TVectorD
TVectorT< Double_t > TVectorD
BmnAlignDefines.h
BMN_RESIDUALS_BINS
#define BMN_RESIDUALS_BINS
Definition
BmnAlignDefines.h:63
SVectGLT
ROOT::Math::SVector< Double_t, BMN_GLPARAMS_TOTAL > SVectGLT
Definition
BmnAlignDefines.h:74
SVectGL
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
Definition
BmnAlignDefines.h:73
BMN_RESIDUALS_RANGE_X
#define BMN_RESIDUALS_RANGE_X
Definition
BmnAlignDefines.h:64
BMN_RESIDUALS_RANGE_Y
#define BMN_RESIDUALS_RANGE_Y
Definition
BmnAlignDefines.h:65
SVectLC
ROOT::Math::SVector< Double_t, BMN_LOCAL_PARAMS_PT > SVectLC
Definition
BmnAlignDefines.h:72
BMN_MODULE_COUNT
#define BMN_MODULE_COUNT
Definition
BmnAlignDefines.h:19
BMN_GLOBAL_PARAMS_PD
#define BMN_GLOBAL_PARAMS_PD
Definition
BmnAlignDefines.h:21
BmnAlignResult::GetSortedMSE
IdxValuePair_t GetSortedMSE() const
Definition
BmnAlignResult.h:140
BmnAlignResult::ResetValueMSE
void ResetValueMSE()
Definition
BmnAlignResult.h:165
BmnAlignResult::Alpha
VectorSVectLC_t & Alpha() noexcept
Definition
BmnAlignResult.h:54
BmnAlignResult::fA
ArraySVectGL_t fA
Definition
BmnAlignResult.h:36
BmnAlignResult::BmnAlignResult
BmnAlignResult(Int_t TrackCount)
Definition
BmnAlignResult.h:78
BmnAlignResult::fMSEtotal
Double_t fMSEtotal
Definition
BmnAlignResult.h:42
BmnAlignResult::GetValueMSE
Double_t GetValueMSE(Int_t index) const noexcept
Definition
BmnAlignResult.h:63
BmnAlignResult::ConcatenateA
void ConcatenateA()
Definition
BmnAlignResult.h:178
BmnAlignResult::SVDSig
TVectorD & SVDSig() noexcept
Definition
BmnAlignResult.h:59
BmnAlignResult::fResidualsX
TH1D fResidualsX
Definition
BmnAlignResult.h:39
BmnAlignResult::fMSE
ArrayDouble_t fMSE
Definition
BmnAlignResult.h:41
BmnAlignResult::fL
TVectorD fL
Definition
BmnAlignResult.h:37
BmnAlignResult::A
SVectGL & A(Int_t index) noexcept
Definition
BmnAlignResult.h:56
BmnAlignResult::Alpha
SVectLC & Alpha(Int_t index) noexcept
Definition
BmnAlignResult.h:55
BmnAlignResult::SeparateA
void SeparateA()
Definition
BmnAlignResult.h:171
BmnAlignResult::ArrayDouble_t
std::array< Double_t, BMN_MODULE_COUNT > ArrayDouble_t
Definition
BmnAlignResult.h:30
BmnAlignResult::A
SVectGLT & A() noexcept
Definition
BmnAlignResult.h:57
BmnAlignResult::IdxValuePair_t
std::array< std::pair< Int_t, Double_t >, BMN_MODULE_COUNT > IdxValuePair_t
Definition
BmnAlignResult.h:27
BmnAlignResult::ResidualsX
TH1D & ResidualsX() noexcept
Definition
BmnAlignResult.h:60
BmnAlignResult::L
TVectorD & L() noexcept
Definition
BmnAlignResult.h:58
BmnAlignResult::~BmnAlignResult
~BmnAlignResult()=default
BmnAlignResult::fAfull
SVectGLT fAfull
Definition
BmnAlignResult.h:35
BmnAlignResult::ArraySVectLC_t
std::array< SVectLC, BMN_MODULE_COUNT > ArraySVectLC_t
Definition
BmnAlignResult.h:29
BmnAlignResult::ResidualsY
TH1D & ResidualsY() noexcept
Definition
BmnAlignResult.h:61
BmnAlignResult::ArraySVectGL_t
std::array< SVectGL, BMN_MODULE_COUNT > ArraySVectGL_t
Definition
BmnAlignResult.h:28
BmnAlignResult::operator=
BmnAlignResult & operator=(const BmnAlignResult &other)
Definition
BmnAlignResult.h:118
BmnAlignResult::fAlpha
VectorSVectLC_t fAlpha
Definition
BmnAlignResult.h:34
BmnAlignResult::GetAlphaCount
Int_t GetAlphaCount() const noexcept
Definition
BmnAlignResult.h:65
BmnAlignResult::BmnAlignResult
BmnAlignResult()
Definition
BmnAlignResult.h:51
BmnAlignResult::GetValueMSE
Double_t GetValueMSE() const noexcept
Definition
BmnAlignResult.h:64
BmnAlignResult::fAlphaCount
const Int_t fAlphaCount
Definition
BmnAlignResult.h:43
BmnAlignResult::fResidualsY
TH1D fResidualsY
Definition
BmnAlignResult.h:40
BmnAlignResult::GetHistCounter
ULong_t GetHistCounter() const noexcept
Definition
BmnAlignResult.h:184
BmnAlignResult::fSVDSig
TVectorD fSVDSig
Definition
BmnAlignResult.h:38
BmnAlignResult::VectorSVectLC_t
std::vector< SVectLC > VectorSVectLC_t
Definition
BmnAlignResult.h:31
BmnAlignResult::AddValueMSE
void AddValueMSE(Int_t detectorIndex, Double_t val)
Definition
BmnAlignResult.h:157
TH1D
align_new
src
BmnAlignResult.h
Generated on
for BmnRoot by
1.17.0