BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
align.C
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 ROOT alignment macro
9*/
10
11// ==============================================================
12// COMMON HEADER SECTION BEGIN : INSERT FROM COMPILE VERSION HERE
13
14#undef BMN_TEST_ALGORITHM // task type selection
15
16// headers below are for IDE syntax to work and they will be
17// turned off during execution in ROOT macro mode
18#ifndef __CLING__
19#include "BmnMeasureModel.h"
20#include "BmnRun8cgDetModel.h"
21#ifdef BMN_TEST_ALGORITHM
22#include "BmnATestDetector.h"
23#include "BmnATestHit.h"
24#include "BmnAlignerTest.h"
25
26#include <filesystem>
27#else // non-test mode
28#include "BmnAligner.h"
29#endif
30#endif
31
32#include "fairlogger/Logger.h"
33
34#ifdef BMN_TEST_ALGORITHM
35#define TEST_DETECTOR_STEP 20.0
36#define TEST_TRACK_COUNT 30000
37#define TEST_DETECTORS_FILE "cfg/test_detectors.json"
38#define TEST_TRACKS_FILE "cfg/test_tracks.json"
39#endif
40#define FILE_LIST_PATH "cfg/dst7466noa.txt"
41#define SOLUTION_PATH "cfg/new_solution.json"
42
43constexpr const char *START_APPROX_PATH{nullptr}, // "cfg/fix_last.json"
44 *CONSTRAINTS_PATH{nullptr}; // "cfg/test_constraints.json"
45
46// COMMON HEADER SECTION END : INSERT FROM COMPILE VERSION UTIL HERE
47// =================================================================
48
49int align(int argc = 0, char** argv = nullptr)
50{
51 // =======================================================
52 // COMMON SECTION BEGIN : INSERT FROM COMPILE VERSION HERE
53
54 fair::Logger::SetConsoleColor(true);
55 fair::Logger::SetConsoleSeverity("info");
56 // fair::Logger::InitFileSink("debug", "bmn-align.log");
57
58 BmnMeasureModel measureModel;
59
60#ifdef BMN_TEST_ALGORITHM
61 // TEST MODE ===============================================================================
62
63 // generate or load test detectors
64 BmnATestDetector detModel{std::filesystem::exists(TEST_DETECTORS_FILE)
65 ? BmnATestDetector(TEST_DETECTORS_FILE)
66 : BmnATestDetector(TEST_DETECTOR_STEP //,
67 // TEST_DETECTORS_FILE
68 )};
69
70 // init aligner: dynamic object is mandatory for ROOT macro mode compatibility
71 BmnAlignerTest pAligner = new BmnAlignerTest(&measureModel, &detModel, TEST_TRACK_COUNT, constraintsPath, 16);
72
73#else // not BMN_TEST_ALGORITHM
74 // REAL DATA MODE ==========================================================================
75
76 BmnRun8cgDetModel detModel;
77 detModel.Init();
78
79 // init aligner: dynamic object is mandatory for ROOT macro mode compatibility
80 BmnAligner<>* pAligner = new BmnAligner<>(&measureModel, &detModel, FILE_LIST_PATH, CONSTRAINTS_PATH, 16);
81
82#endif // BMN_TEST_ALGORITHM
83 // =========================================================================================
84
85 Bool_t success;
86 success = pAligner->Initialized();
87 if (!success) {
88 LOG(error) << " <!> final failure: initialization unsuccessful";
89 return -1;
90 }
91 success = pAligner->PrepareData();
92 if (!success) {
93 LOG(error) << " <!> final failure: data preparation unsuccessful";
94 return -1;
95 }
97 success = pAligner->LoadSolution(START_APPROX_PATH);
98 if (!success) {
99 LOG(error) << " <!> final failure: calibration solution loading unsuccessful";
100 return -1;
101 }
102 }
103 success = pAligner->Align();
104 if (!success) {
105 LOG(error) << " <!> final failure: alignment unsuccessful";
106 return -1;
107 }
108
109 success = pAligner->SaveSolution(SOLUTION_PATH);
110 if (!success) {
111 LOG(error) << " <!> final failure: solution saving unsuccessful";
112 return -1;
113 }
114
115 // COMMON SECTION END : INSERT FROM COMPILE VERSION UTIL HERE
116 // ==========================================================
117
118 pAligner->Draw(); // works in ROOT macro mode only
119
120 // failed to implement object cleanup in ROOT macro mode
121 // delete pAligner;
122 return 0;
123}
bool Bool_t
#define FILE_LIST_PATH
Definition align.C:40
#define SOLUTION_PATH
Definition align.C:41
constexpr const char * START_APPROX_PATH
Definition align.C:43
constexpr const char * CONSTRAINTS_PATH
Definition align.C:44
int align(int argc=0, char **argv=nullptr)
Definition align.C:49
virtual Bool_t PrepareData(const char *tracksPath=nullptr) override
virtual void Draw() override
Bool_t Initialized() const noexcept
Definition BmnAligner.h:59
Bool_t SaveSolution(const char *jsonPath, Bool_t withAlpha=kFALSE)
Bool_t LoadSolution(const char *jsonPath, Bool_t withAlpha=kTRUE, Bool_t withMSE=kTRUE)
Bool_t Align(Bool_t fixEvery=kFALSE)