39#pragma cling add_include_path("/home/igor/bmnroot/services")
40#pragma cling add_include_path("/usr/include")
42#include <nlohmann/json.hpp>
47 "phi",
"theta",
"psi"};
49 "phi rotation, rad",
"theta rotation, rad",
"psi rotation, rad"};
60 std::vector<Int_t>
ids;
61 std::vector<std::vector<Double_t>>
values;
62 std::vector<std::vector<Double_t>>
errors;
67 std::ifstream ifs(path);
69 std::cerr <<
" <!> compareSolutions: failed to open " << path << std::endl;
75 }
catch (
const std::exception& e) {
76 std::cerr <<
" <!> compareSolutions: failed to parse JSON " << path <<
":\n " << e.what() << std::endl;
79 if (!js.contains(
"CorrectionsPerDetector") || !js[
"CorrectionsPerDetector"].is_array()) {
80 std::cerr <<
" <!> compareSolutions: 'CorrectionsPerDetector' missing or"
85 const auto& arr = js[
"CorrectionsPerDetector"];
89 sol.
ids.reserve(arr.size());
90 sol.
values.reserve(arr.size());
91 sol.
errors.reserve(arr.size());
92 for (
const auto& el : arr) {
93 if (!el.contains(
"detector_id") || !el.contains(
"values") || !el[
"values"].is_array()
96 std::cerr <<
" <!> compareSolutions: malformed entry in " << path << std::endl;
99 std::vector<Double_t>
v;
101 for (
const auto& x : el[
"values"])
105 if (el.contains(
"errors") && el[
"errors"].is_array() && el[
"errors"].size() ==
PARAM_CNT) {
107 e[k] = el[
"errors"][k].get<Double_t>();
109 sol.
ids.push_back(el[
"detector_id"].get<Int_t>());
110 sol.
values.push_back(std::move(
v));
111 sol.
errors.push_back(std::move(e));
130 const char* obtainedPath =
"/home/igor/bmnroot/align_new/cfg/solutions/sl9555.112e_lin3.04.json",
131 const char* precisePath =
132 "/home/igor/data.cache/tt9555.112e_lin3.04.solution.json",
133 const char* pdfPath =
nullptr)
141 if (sObt.
ids.size() != sTru.
ids.size()) {
142 std::cerr <<
" <!> compareSolutions: detector counts differ (" << sObt.
ids.size() <<
" obtained vs "
143 << sTru.
ids.size() <<
" precise)" << std::endl;
149 std::map<Int_t, Int_t> truIdxByID;
151 truIdxByID[sTru.
ids[
i]] =
i;
153 std::vector<Int_t> ids(nDet);
154 std::vector<std::vector<Double_t>> tVal(nDet, std::vector<Double_t>(
PARAM_CNT, 0.0)),
155 oVal(nDet, std::vector<Double_t>(
PARAM_CNT, 0.0)), oErr(nDet, std::vector<Double_t>(
PARAM_CNT, 0.0));
158 auto it = truIdxByID.find(
id);
159 if (it == truIdxByID.end()) {
160 std::cerr <<
" <!> compareSolutions: detector_id " <<
id <<
" not found in precise solution" << std::endl;
167 tVal[
i][p] = sTru.
values[it->second][p];
173 cout <<
"Per-parameter summary of (obtained - precise):\n";
174 cout <<
" " << left << setw(8) <<
"param"
179 << setw(15) <<
"RMS diff" << setw(19) <<
"mean|diff/true|" << setw(18) <<
"max|diff/true|" << setw(10)
180 <<
"det_idx" << setw(12) <<
"det_id"
184 Double_t s{0.0}, s2{0.0}, t{0.0}, o{0.0}, sRel{0.0}, maxRel{-1.0};
192 if (
fabs(tVal[
i][p]) < TRUTH_EPS)
201 cout <<
" " << left << setw(8) <<
PARAM_NAMES[p] << right << fixed
206 << setw(15) <<
sqrt(s2 / nDet) << setw(19) << sRel / nDet;
208 cout << fixed << setprecision(1) << setw(18) << maxRel << setw(10) << maxIdx << setw(12) << ids[maxIdx];
210 cout << setw(18) <<
"n/a" << setw(10) <<
"-" << setw(12) <<
"-";
216 "canvas",
"BM@N alignment solutions comparison : BAR = true value, DOT = obtained (1-sigma conf), LINE = diff",
223 pPads[
i][j] =
new TPad(
Form(
"pad%u%u",
i, j),
Form(
"pad%u%u",
i, j), padW * j, padH *
i, padW * (j + 1),
235 std::vector<Double_t> x(nDet), xE(nDet, 0.0), yT(nDet), yO(nDet), yE(nDet), yD(nDet);
242 yD[
i] = oVal[
i][p] - tVal[
i][p];
245 if (yO[
i] - yE[
i] < yMin)
246 yMin = yO[
i] - yE[
i];
251 if (yO[
i] + yE[
i] > yMax)
252 yMax = yO[
i] + yE[
i];
256 Double_t pad{0.1 * std::max(yMax - yMin, 1e-6)};
295 TLine* zero =
new TLine(-0.5, 0.0, nDet - 0.5, 0.0);
312 if (pdfPath && pdfPath[0])
friend F32vec4 fabs(const F32vec4 &a)
char * Form(const char *fmt,...)
virtual void SetNdivisions(Int_t n1, Int_t n2, Int_t n3, Bool_t optim=kTRUE)
virtual void SetFillColor(Color_t fcolor)
virtual void SetLineStyle(Style_t lstyle)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
virtual void SetMarkerColor(Color_t mcolor=1)
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetLimits(Double_t xmin, Double_t xmax)
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
void SetCanvasSize(UInt_t ww, UInt_t wh) override
virtual void Add(TGraph *graph, Option_t *chopt="")
void Draw(Option_t *chopt="") override
virtual void SetTitle(const char *title="")
virtual void SetName(const char *name)
virtual void Draw(Option_t *option="")
void SaveAs(const char *filename="", Option_t *option="") const override
TVirtualPad * cd(Int_t subpadnumber=0) override
void Draw(Option_t *option="") override
static constexpr const char * PARAM_TITLES[PARAM_CNT]
static constexpr const Double_t PARAM_RANGES[PARAM_CNT]
static Bool_t LoadCmpSolution(const char *path, CmpSolution &sol)
int compareS(const char *obtainedPath="/home/igor/bmnroot/align_new/cfg/solutions/sl9555.112e_lin3.04.json", const char *precisePath="/home/igor/data.cache/tt9555.112e_lin3.04.solution.json", const char *pdfPath=nullptr)
Visual comparison of two alignment solutions.
static constexpr const char * PARAM_NAMES[PARAM_CNT]
RVec< PromoteType< T > > sqrt(const RVec< T > &v)
std::vector< std::vector< Double_t > > values
std::vector< std::vector< Double_t > > errors