BmnRoot
26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
expandS.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.int
7
8
Solution expansion macro
9
Re-encodes an alignment solution from a coarse detector model into a finer one
10
that distinguishes more detector elements. Every fine element inherits the
11
correction of the coarse element it belongs to.
12
*/
13
14
// headers below are for IDE syntax to work and they will be
15
// turned off during execution in ROOT macro mode
16
#ifndef __CLING__
17
#include "
BmnAlignConfig.h
"
18
#include "
BmnAlignDefines.h
"
19
#include "
BmnAlignModels.h
"
// IWYU pragma: keep
20
#endif
21
22
#include "fairlogger/Logger.h"
23
24
#include <fstream>
25
#include <iomanip>
26
#include <nlohmann/json.hpp>
27
#include <vector>
28
29
// ---- expansion configuration ------------------------------------------------
30
using
inDetModel
=
BmnRun8cgDM
;
// source (coarse) model
31
using
outDetModel
=
BmnRun8DM
;
// output (fine) model
32
// -----------------------------------------------------------------------------
33
34
/**
35
* @brief Re-encode a solution from a coarse detector model into a finer one.
36
*
37
* Every element of the fine model inherits the correction of the coarse element
38
* it belongs to, so a solution obtained on half-stations can seed a run that
39
* aligns individual modules. The two models are named by the inDetModel and
40
* outDetModel aliases at the top of the file.
41
*
42
* @param inSolutionPath .json solution written for the coarse model
43
* @param outSolutionPath .json file to write the expanded solution into
44
*
45
* @return 0 on success, -1 if the solution could not be read or written
46
*/
47
int
expandS
(
const
char
* inSolutionPath =
"/home/igor/bmnroot/align_new/cfg/run8/slALL.e11.00.json"
,
48
const
char
* outSolutionPath =
"/home/igor/bmnroot/align_new/cfg/run8/slALL.e76.00.json"
)
49
{
50
fair::Logger::SetConsoleColor(
true
);
51
fair::Logger::SetConsoleSeverity(
"info"
);
52
LOG(state) <<
" > expandS.C : solution expansion started"
;
53
54
// Read the input solution through the file-format layer alone: expanding a
55
// solution needs neither the solver nor a reconstruction task. The flat
56
// parametrization is all that is required to address the file, since the
57
// per-element values it lists are the *effective* corrections - whatever
58
// hierarchy produced them, its levels are already summed into these.
59
inDetModel
inputModel;
60
inputModel.
Init
();
61
BmnAlignHierarchy
inputLayout;
62
if
(!inputLayout.
BuildFlat
(inputModel)) {
63
LOG(error) <<
" <!> failed to build the input model layout"
;
64
return
-1;
65
}
66
BmnAlignConfig::Solution
solution;
67
if
(!
BmnAlignConfig::ReadSolution
(inSolutionPath, inputLayout, solution)) {
68
LOG(error) <<
" <!> failed to load solution "
<< inSolutionPath;
69
return
-1;
70
}
71
// corrections by coarse element index, so the loop below can look one up
72
VecSVectGL_t
corrections(inputModel.
Alignables
());
73
for
(
const
BmnAlignConfig::NodeValues
& leaf : solution.
leaves
)
74
corrections[leaf.
node
] = leaf.
values
;
75
if
(solution.
leaves
.empty()) {
76
LOG(error) <<
" <!> "
<< inSolutionPath <<
" holds no detector elements"
;
77
return
-1;
78
}
79
80
outDetModel
outputModel;
81
outputModel.
Init
();
82
const
Int_t
outputCount{outputModel.
Alignables
()};
83
84
// --- build the expanded solution -----------------------------------------
85
using
nlohmann::json;
86
json js;
87
js[
"CorrectionValues"
] =
BmnParamLayout::ParamNames
();
88
js[
"DetectorElements"
] = outputCount;
89
js[
"CorrectionsPerDetector"
] = json::array();
90
91
Int_t
outputCnt{0};
92
for
(
Int_t
i
= 0;
i
< outputCount;
i
++) {
93
const
Int_t
outputID{outputModel.
EncodedID
(
i
)};
94
json element;
95
element[
"detector_id"
] = outputID;
96
element[
"values"
] = json::array();
97
element[
"errors"
] = json::array();
98
99
// coarse element this fine element belongs to (per the old model)
100
const
Int_t
hitID{inputModel.
IDfromHit
(outputID)};
101
if
(inputModel.
UnknownID
(hitID)) {
102
LOG(error) <<
" <!> element "
<< outputID <<
" maps to unknown id "
<< hitID <<
" in input model, aborting"
;
103
return
-1;
104
}
105
106
const
SVectGL
& A{corrections[inputModel.
Idx
(hitID)]};
107
for
(
Int_t
j = 0; j <
BMN_GLOBAL_PARAMS_PD
; j++) {
108
element[
"values"
].push_back(A(j));
109
element[
"errors"
].push_back(0.0);
// errors are discarded on load
110
}
111
js[
"CorrectionsPerDetector"
].push_back(element);
112
outputCnt++;
113
}
114
115
// --- write the expanded solution -----------------------------------------
116
std::ofstream ofs(outSolutionPath);
117
if
(!ofs.good()) {
118
LOG(error) <<
" <!> failed to open output file "
<< outSolutionPath;
119
return
-1;
120
}
121
try
{
122
ofs << std::setw(4) << js << std::endl;
123
}
catch
(std::exception& e) {
124
LOG(error) <<
" <!> failed to write JSON data\n"
<< e.what();
125
return
-1;
126
}
127
128
LOG(info) <<
" "
<< outputCnt <<
" elements written to "
<< outSolutionPath;
129
LOG(state) <<
" < expandS.C : solution expansion completed"
;
130
return
0;
131
}
BmnAlignConfig.h
BmnAlignDefines.h
VecSVectGL_t
std::vector< SVectGL > VecSVectGL_t
Definition
BmnAlignDefines.h:71
SVectGL
RM::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
Definition
BmnAlignDefines.h:61
BMN_GLOBAL_PARAMS_PD
#define BMN_GLOBAL_PARAMS_PD
Definition
BmnAlignDefines.h:20
BmnAlignModels.h
i
int i
Definition
P4_F32vec4.h:22
Int_t
int Int_t
BmnAlignConfig::ReadSolution
static Bool_t ReadSolution(const char *jsonPath, const BmnAlignHierarchy &hierarchy, Solution &solution)
Definition
BmnAlignConfig.cxx:95
BmnAlignHierarchy
Definition
BmnAlignHierarchy.h:89
BmnAlignHierarchy::BuildFlat
Bool_t BuildFlat(const BmnDetectorModel &detModel)
Definition
BmnAlignHierarchy.h:114
BmnDetectorModel::EncodedID
Int_t EncodedID(Int_t idx) const
Definition
BmnDetectorModel.h:96
BmnDetectorModel::Init
Bool_t Init(const char *targetGeoFile=nullptr)
Definition
BmnDetectorModel.h:120
BmnDetectorModel::UnknownID
Bool_t UnknownID(Int_t hitID) const
Definition
BmnDetectorModel.h:99
BmnDetectorModel::Idx
Int_t Idx(Int_t ID) const
Definition
BmnDetectorModel.h:97
BmnParamLayout::ParamNames
static const std::vector< std::string > & ParamNames()
Definition
BmnParamLayout.cxx:22
BmnRun8DM
Definition
BmnRun8DM.h:41
BmnRun8DM::Alignables
virtual Int_t Alignables() const noexcept override
Definition
BmnRun8DM.h:139
BmnRun8cgDM
Definition
BmnRun8cgDM.h:26
BmnRun8cgDM::IDfromHit
virtual Int_t IDfromHit(Int_t CbmDetectorID) const noexcept override
Definition
BmnRun8cgDM.h:72
outDetModel
BmnRun8DM outDetModel
Definition
expandS.C:31
inDetModel
BmnRun8cgDM inDetModel
Definition
expandS.C:30
expandS
int expandS(const char *inSolutionPath="/home/igor/bmnroot/align_new/cfg/run8/slALL.e11.00.json", const char *outSolutionPath="/home/igor/bmnroot/align_new/cfg/run8/slALL.e76.00.json")
Re-encode a solution from a coarse detector model into a finer one.
Definition
expandS.C:47
BmnAlignConfig::NodeValues
Definition
BmnAlignConfig.h:53
BmnAlignConfig::NodeValues::node
Int_t node
Definition
BmnAlignConfig.h:54
BmnAlignConfig::NodeValues::values
SVectGL values
Definition
BmnAlignConfig.h:55
BmnAlignConfig::Solution
Definition
BmnAlignConfig.h:59
BmnAlignConfig::Solution::leaves
std::vector< NodeValues > leaves
Definition
BmnAlignConfig.h:60
align_new
macro
expandS.C
Generated on
for BmnRoot by
1.17.0