14#include "Math/Functions.h"
16#include "TStopwatch.h"
17#include "fairlogger/Logger.h"
20#include <nlohmann/json.hpp>
25 const char* constraintsPath,
27 :
BmnAligner(measureModel, modelDetector, constraintsPath, nThreads)
28 , fpDetectors(modelDetector)
30 LOG(state) <<
" > BmnAlignerTest : initialization started";
39 LOG(info) <<
" RAM required: " << ram_size / 1073741824.0 <<
" GB, ";
41 LOG(error) <<
"<!> required RAM size is too large for test:" << std::endl
42 <<
"<!> decrease number of tracks or detector planes" << std::endl
58 LOG(state) <<
" < BmnAlignerTest : initialization completed";
64 delete[] fpTestTracksData;
70 LOG(state) <<
" > BmnAlignerTest : data preparation started";
72 LOG(error) <<
" <!> BmnAlignerTest is not initialized";
76 Bool_t loadTracks{tracksPath && std::filesystem::exists(tracksPath)};
81 LOG(error) <<
" <!> failed to load tracks from file " << tracksPath;
85 LOG(info) <<
" Generating random tracks";
87 fpTestTracks =
reinterpret_cast<BmnATestTrack*
>(fpTestTracksData);
89 new (fpTestTracks + iTrack)
94 LOG(warning) <<
" failed to save tracks to file " << tracksPath;
98 SVect3 HitPoint, HitPointLocal;
100 Int_t iTrack, iHit{0};
109 HitPoint = {Track.
X(Z), Track.
Y(Z), Z};
113 <<
" <!> non-zero local z coordinate of test hit: " << HitPointLocal(2);
115 auto pHit =
new (
fpHits + iHit)
130 Double_t dX{lastHit.
GetX() - firstHit.
GetX()}, dY{lastHit.GetY() - firstHit.
GetY()},
131 dZ{lastHit.GetZ() - firstHit.
GetZ()}, AlphaX1{dX / dZ}, AlphaY1{dY / dZ};
132 arrAlpha[iTrack] =
SVectLC(firstHit.
GetX() - AlphaX1 * firstHit.
GetZ(), AlphaX1,
133 firstHit.
GetY() - AlphaY1 * firstHit.
GetZ(), AlphaY1);
152 LOG(info) <<
" " <<
fTotalTracks <<
" tracks ready, total hits: " << iHit <<
", time spent: " << Timer.CpuTime()
154 LOG(state) <<
" < BmnAlignerTest : data preparation completed";
171 LOG(info) <<
" === average local parameters convergence:";
180 LOG(info) <<
" Saving tracks data to " << path;
183 std::ofstream ofs(path);
185 LOG(error) <<
" <!> failed to open JSON file " << path;
191 j[
"alphas"] = nlohmann::json::array();
193 const auto& tr = fpTestTracks[
i];
204 LOG(info) <<
" Loading tracks data from " << path;
205 std::ifstream ifs(path);
207 LOG(error) <<
" <!> failed to open JSON file " << path;
216 if (fpTestTracksData)
217 delete[] fpTestTracksData;
219 fpTestTracks =
reinterpret_cast<BmnATestTrack*
>(fpTestTracksData);
221 const auto& arr = j[
"alphas"];
223 const auto& a = arr[
i];
224 SVectLC Alpha(a[
iX0].get<double>(), a[
iX1].get<double>(), a[
iY0].get<double>(), a[
iY1].get<double>());
237 fpPad3D->SetTitle(
"Some random tracks");
238 const Double_t zMax = fpDetectors->
GetMaxZ() * 1.1;
245 if (drawn_tracks.end() == std::find(drawn_tracks.begin(), drawn_tracks.end(), j) &&
fpTrackUsable->at(
i)) {
248 trk.
Draw(kFALSE, zMax);
254 double xValues[BMN_GLPARAMS_TOTAL];
255 for (
auto i = 0;
i < BMN_GLPARAMS_TOTAL;
i++)
256 xValues[
i] =
static_cast<double>(
i + 1);
259 Double_t A[BMN_GLPARAMS_TOTAL];
265 TGraph* graphSolution =
new TGraph(BMN_GLPARAMS_TOTAL, xValues, A);
266 graphSolution->SetTitle(
"Alignment values");
267 graphSolution->SetFillColor(kRed);
268 graphSolution->SetMinimum(-0.25);
269 graphSolution->SetMaximum(0.35);
270 graphSolution->GetXaxis()->SetRangeUser(xValues[0], xValues[BMN_GLPARAMS_TOTAL - 1]);
271 graphSolution->Draw(
"AB");
272 Double_t T[BMN_GLPARAMS_TOTAL];
276 TGraph* graphTest =
new TGraph(BMN_GLPARAMS_TOTAL, xValues, T);
277 graphTest->SetLineColor(kBlack);
278 graphTest->Draw(
"*SAME");
319 Double_t beforeValue{0.0}, afterValue{0.0};
321 beforeValue += ROOT::Math::Mag2(Atest[
i] - pBeforeResult->A(
i));
322 afterValue += ROOT::Math::Mag2(Atest[
i] - pAfterResult->A(
i));
324 LOG(info) <<
" === distance to test A before/after alignment: " << std::sqrt(beforeValue) <<
" / "
325 << std::sqrt(afterValue);
335 for (Int_t iTrack = 0; iTrack <
fTotalTracks; iTrack++) {
338 fpTestTracks[iTrack].
AddMSE(
this, withResiduals);
#define BMN_DRAW_TRACKS_CNT
#define BMN_CLOSE_TO_ZERO
#define BMN_TEST_AVERAGE_DY
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
#define BMN_TEST_ALPHA2_MAX
#define BMN_TEST_AVERAGE_DX
#define BMN_TEST_ALPHA1_SIGMA
#define BMN_TEST_ALPHA2_MIN
ROOT::Math::SVector< Double_t, 3 > SVect3
ROOT::Math::SVector< Double_t, BMN_LOCAL_PARAMS_PT > SVectLC
#define BMN_MAX_HIT_RAM_SIZE
#define BMN_GLOBAL_PARAMS_PD
const Float_t delta
Distance between GEM-stations.
const SVect3 & GetNormal() const noexcept
const SVect3 & GetCrdShift() const noexcept
Double_t GetPosition() const noexcept
const SMatr3x3 & GetCrdInvRotation() const noexcept
void Draw(Bool_t showNormal=kFALSE) const
Double_t GetConst() const noexcept
const SVectGL * GetTestA() const
const BmnATestDetectorPlane * GetDetectors() const
const SVect3 & GetVertex() const noexcept
const SVectLC & GetAlpha() const noexcept
void AddMSE(BmnAlignerClass *pAligner, Bool_t withResiduals=kFALSE) const
Double_t Y(Double_t z) const noexcept
Double_t X(Double_t z) const noexcept
void Draw(Bool_t solid=kTRUE, Double_t maxZ=BMN_TEST_TRACK_DEF_MAX_Z) const
const SVect3 & GetDirection() const noexcept
void AddHit(BmnATestHit &hit)
VectorSVectLC_t & Alpha() noexcept
Double_t GetValueMSE(Int_t index) const noexcept
SVectGL & A(Int_t index) noexcept
TH1D & ResidualsX() noexcept
TH1D & ResidualsY() noexcept
virtual void ReportResults() const override
virtual Double_t CalculateMSE(Bool_t withResiduals) override
virtual Bool_t PrepareData(const char *tracksPath=nullptr) override
virtual Bool_t IterateAlignment() override
virtual ~BmnAlignerTest()
virtual void Draw() override
Bool_t LoadTracks(const char *path)
Bool_t SaveTracks(const char *path) const
const BmnATestTrack & GetTestTrack(Int_t trackID) const noexcept
BmnAlignResult * fpResultCurrent
void StoreZeroSolution(const std::vector< SVectLC > &AlphaZero)
BmnDataIterator * fpIteratorMain
virtual Bool_t IterateAlignment()
std::vector< Bool_t > * fpTrackUsable
BmnRamIterator< BmnATestHit > * fpRamIterator
Double_t fOmegaScaleFactor
Int_t TotalTracks() const noexcept
virtual void ReportResults() const
BmnAlignResult * GetResult(Bool_t last=kTRUE) const noexcept
Double_t GetY() const noexcept
Double_t GetX() const noexcept
Double_t GetZ() const noexcept
a class to store JSON values
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
void push_back(basic_json &&val)
add an object to an array