BmnRoot
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.ru
7
8 BmnATestDetector implementation
9*/
10
11#include "BmnATestDetector.h"
12
13#include "fairlogger/Logger.h"
14
15#include <fstream>
16#include <nlohmann/json.hpp>
17
18BmnATestDetector::BmnATestDetector(Double_t detectorStep, const char* dumpPath)
20{
21 LOG(info) << " > Generating " << BMN_TEST_MODULE_COUNT << " test detectors planes";
22
23 Double_t nominalZ = detectorStep;
24 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++) { // first detector is fixed
25 for (Int_t j = iX; j <= iZ; j++) {
26 if (i > 0)
27 fMisalignments[i](j) = BMN_RND.Gaus(0.0, BMN_ALIGN_PARAM_TOLERENCE);
28 // if (i == 2 && j == iX)
29 // fMisalignments[i](j) = 0.1;
30 }
31 fNominalZ[i] = nominalZ;
32 nominalZ += detectorStep;
33 }
34
35 if (dumpPath)
36 Save(dumpPath);
37 RebuildDetectors();
38}
39
40Bool_t BmnATestDetector::Save(const char* path) const
41{
42 LOG(info) << " Saving test detectors planes to " << path;
43 std::ofstream ofs(path);
44 if (!ofs.good()) {
45 LOG(error) << " <!> failed to open JSON file " << path;
46 return kFALSE;
47 }
48
50 j["nominal_z"] = fNominalZ;
51 j["misalignments"] = nlohmann::json::array();
52 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++) {
53 j["misalignments"].push_back({fMisalignments[i](iX), fMisalignments[i](iY), fMisalignments[i](iZ)});
54 }
55
56 ofs << j.dump(2);
57 return kTRUE;
58}
59
60Bool_t BmnATestDetector::Load(const char* path)
61{
62 LOG(info) << " > Loading test detectors planes from " << path;
63 std::ifstream ifs(path);
64 if (!ifs.good()) {
65 LOG(error) << " <!> failed to open JSON file " << path;
66 return kFALSE;
67 }
69 ifs >> j;
70
71 const auto& jz = j["nominal_z"];
72 const auto& jm = j["misalignments"];
73
74 if (jz.size() != jm.size()) {
75 LOG(error) << " <!> inconsistent number of detector planes in JSON file " << path;
76 return kFALSE;
77 }
78
79 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++) {
80 fNominalZ[i] = jz[i].get<double>();
81 fMisalignments[i] =
82 SVectGL(jm[i][static_cast<Int_t>(iX)].get<double>(), jm[i][static_cast<Int_t>(iY)].get<double>(),
83 jm[i][static_cast<Int_t>(iZ)].get<double>());
84 }
85
86 RebuildDetectors();
87 return kTRUE;
88}
89
90void BmnATestDetector::RebuildDetectors()
91{
92 for (Int_t i = 0; i < BMN_TEST_MODULE_COUNT; i++)
93 fDetectors[i] = BmnATestDetectorPlane(fNominalZ[i], fMisalignments[i], i);
94}
#define BMN_ALIGN_PARAM_TOLERENCE
#define BMN_TEST_MODULE_COUNT
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
@ iZ
@ iX
@ iY
int i
Definition P4_F32vec4.h:22
BmnATestDetector(Double_t detectorStep, const char *dumpPath=nullptr)
Bool_t Save(const char *path) const
Bool_t Load(const char *path)
a class to store JSON values
Definition json.hpp:17282
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
Definition json.hpp:18426
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:19986