BmnRoot 26.10.0-18-g4e3414f9
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.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)
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);
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
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>();
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
87 return kTRUE;
88}
89
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
#define BMN_ALIGN_PARAM_TOLERENCE
#define BMN_TEST_MODULE_COUNT
static TRandom3 BMN_RND
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
@ iZ
@ iX
@ iY
SVectGL fMisalignments[BMN_TEST_MODULE_COUNT]
BmnATestDetector(Double_t detectorStep, const char *dumpPath=nullptr)
Double_t fNominalZ[BMN_TEST_MODULE_COUNT]
Bool_t Save(const char *path) const
BmnATestDetectorPlane fDetectors[BMN_TEST_MODULE_COUNT]
Bool_t Load(const char *path)
BmnSimpleDetModel()=delete
basic_json<> json
default specialization
Definition json.hpp:3365