BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnATestDetector.cxx
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 BmnATestDetector implementation
9*/
10
11/*
12 === DEPRECATION NOTICE =========================================
13 Due to complex changes in BmnAligner, this class requires rework
14 ================================================================
15*/
16
17#include "BmnATestDetector.h"
18
19#include "fairlogger/Logger.h"
20
21#include <fstream>
22#include <nlohmann/json.hpp>
23
24BmnATestDetector::BmnATestDetector(Double_t detectorStep, const char* dumpPath)
25 : BmnSimpleDM(BMN_TEST_MODULE_COUNT)
26{
27 LOG(info) << " > Generating " << BMN_TEST_MODULE_COUNT << " test detectors planes";
28
29 Double_t nominalZ = detectorStep;
30 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++) { // first detector is fixed
31 for (Int_t j = iX; j <= iZ; j++) {
32 if (i > 0)
33 fMisalignments[i](j) = BMN_RND.Gaus(0.0, BMN_ALIGN_PARAM_TOLERENCE);
34 // if (i == 2 && j == iX)
35 // fMisalignments[i](j) = 0.1;
36 }
37 fNominalZ[i] = nominalZ;
38 nominalZ += detectorStep;
39 }
40
41 if (dumpPath)
42 Save(dumpPath);
44}
45
46Bool_t BmnATestDetector::Save(const char* path) const
47{
48 LOG(info) << " Saving test detectors planes to " << path;
49 std::ofstream ofs(path);
50 if (!ofs.good()) {
51 LOG(error) << " <!> failed to open JSON file " << path;
52 return kFALSE;
53 }
54
55 nlohmann::json j;
56 j["nominal_z"] = fNominalZ;
57 j["misalignments"] = nlohmann::json::array();
58 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++) {
59 j["misalignments"].push_back({fMisalignments[i](iX), fMisalignments[i](iY), fMisalignments[i](iZ)});
60 }
61
62 ofs << j.dump(2);
63 return kTRUE;
64}
65
67{
68 LOG(info) << " > Loading test detectors planes from " << path;
69 std::ifstream ifs(path);
70 if (!ifs.good()) {
71 LOG(error) << " <!> failed to open JSON file " << path;
72 return kFALSE;
73 }
74 nlohmann::json j;
75 ifs >> j;
76
77 const auto& jz = j["nominal_z"];
78 const auto& jm = j["misalignments"];
79
80 if (jz.size() != jm.size()) {
81 LOG(error) << " <!> inconsistent number of detector planes in JSON file " << path;
82 return kFALSE;
83 }
84
85 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++) {
86 fNominalZ[i] = jz[i].get<double>();
88 SVectGL(jm[i][static_cast<Int_t>(iX)].get<double>(), jm[i][static_cast<Int_t>(iY)].get<double>(),
89 jm[i][static_cast<Int_t>(iZ)].get<double>());
90 }
91
93 return kTRUE;
94}
95
97{
98 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++)
100}
RM::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
@ iZ
@ iX
@ iY
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
SVectGL fMisalignments[BMN_TEST_MODULE_COUNT]
BmnATestDetectorPlane fDetectors[BMN_TEST_MODULE_COUNT]
BmnATestDetector(Double_t detectorStep, const char *dumpPath=nullptr)
Bool_t Save(const char *path) const
Bool_t Load(const char *path)
Double_t fNominalZ[BMN_TEST_MODULE_COUNT]
BmnSimpleDM()=delete