BmnRoot
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
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);
49 ~BmnAlignResult() = default;
50 // default constructor is required for ROOT serialization and not intended to be used
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;
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
78inline 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",
89 , fResidualsY(Form("residualsY_%lu", GetHistCounter()),
90 "Residuals by Y",
94 , fMSE{}
95 , fMSEtotal(0.0)
96 , fAlphaCount(TrackCount)
97{
99}
100
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
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
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
157inline 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
166{
167 fMSE.fill(0.0);
168 fMSEtotal = 0.0;
169}
170
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
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
184inline 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
#define BMN_RESIDUALS_BINS
ROOT::Math::SVector< Double_t, BMN_GLPARAMS_TOTAL > SVectGLT
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
#define BMN_RESIDUALS_RANGE_X
#define BMN_RESIDUALS_RANGE_Y
ROOT::Math::SVector< Double_t, BMN_LOCAL_PARAMS_PT > SVectLC
#define BMN_MODULE_COUNT
#define BMN_GLOBAL_PARAMS_PD
int i
Definition P4_F32vec4.h:22
IdxValuePair_t GetSortedMSE() const
VectorSVectLC_t & Alpha() noexcept
Double_t GetValueMSE(Int_t index) const noexcept
TVectorD & SVDSig() noexcept
SVectGL & A(Int_t index) noexcept
SVectLC & Alpha(Int_t index) noexcept
std::array< Double_t, BMN_MODULE_COUNT > ArrayDouble_t
SVectGLT & A() noexcept
std::array< std::pair< Int_t, Double_t >, BMN_MODULE_COUNT > IdxValuePair_t
TH1D & ResidualsX() noexcept
TVectorD & L() noexcept
~BmnAlignResult()=default
std::array< SVectLC, BMN_MODULE_COUNT > ArraySVectLC_t
TH1D & ResidualsY() noexcept
std::array< SVectGL, BMN_MODULE_COUNT > ArraySVectGL_t
BmnAlignResult & operator=(const BmnAlignResult &other)
Int_t GetAlphaCount() const noexcept
Double_t GetValueMSE() const noexcept
ULong_t GetHistCounter() const noexcept
std::vector< SVectLC > VectorSVectLC_t
void AddValueMSE(Int_t detectorIndex, Double_t val)