BmnRoot
26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
makett.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
Generation of alignment test tasks based on real data
9
*/
10
11
// headers below are for IDE syntax to work and they will be
12
// turned off during execution in ROOT macro mode
13
#ifndef __CLING__
14
#include "
BmnAlignModels.h
"
// IWYU pragma: keep
15
#include "
BmnAlignReport.h
"
16
#include "
BmnAlignTestTask.h
"
17
#include "
BmnAligner.h
"
18
#endif
19
20
#include "fairlogger/Logger.h"
21
22
#include <
TRandom3.h
>
23
#include <fstream>
24
#include <string>
25
26
#define DEF_THREADS_COUNT 16
27
28
/**
29
* @brief Build a synthetic alignment task with a known answer.
30
*
31
* Reads real tracks, fits straight lines to them, displaces the detector by a
32
* randomly drawn solution and writes out hits lying exactly on the displaced
33
* model, together with the solution that produced them. Feeding the result back
34
* into align.C tests the solver against a truth instead of against itself.
35
*
36
* The truth is drawn from the truth sigmas and obeys the constraints (see
37
* BmnAlignTestTask), so align.C must use the same constraints file on the task.
38
* The solver's own presigmas play no part here: both aligners below take the
39
* truth sigmas as their presigmas, the generator to draw the truth from them,
40
* the viewer only to display the task.
41
*
42
* @param fileListPath text file listing the source .root files, one per line
43
* @param testTaskPath .root file to write the synthetic hits into
44
* @param testSolPath .json file to write the truth solution into
45
* @param constraintsPath .json constraints, the same align.C will use on the task
46
* @param truthSigmaPath .json truth sigmas in the presigma format; every composite parameter not
47
* fixed by a constraint needs one, see BmnAlignPriors::Check()
48
* @param sigmaScale truth StdDev = truth sigma * sigmaScale, 0 for the nominal geometry
49
* @param showTask kTRUE to reload the generated task and draw it afterwards
50
* @param seed PRNG seed for the truth and the noise, 0 for a new one each run (it is logged)
51
*
52
* @return 0 on success, -1 if any stage failed
53
*/
54
int
makett
(
const
char
* fileListPath =
"/home/igor/bmnroot/align_new/cfg/run9/9555.noa_rlerr.list"
,
55
const
char
* testTaskPath =
"/home/igor/data.cache/tt9555.r9_lin3.00.root"
,
56
const
char
* testSolPath =
"/home/igor/data.cache/tt9555.r9_lin3.00.solution.json"
,
57
const
char
* constraintsPath =
"/home/igor/bmnroot/align_new/cfg/constraints/cnstr_r9_lin3.json"
,
58
const
char
* truthSigmaPath =
"/home/igor/bmnroot/align_new/cfg/presigmas/psg_r9_lin3-testTruth.json"
,
59
Double_t
sigmaScale = 0.25,
60
Bool_t
showTask =
kTRUE
,
61
UInt_t
seed = 137)
62
{
63
// the collision target installed in the run, as a FairRoot ASCII geometry file
64
constexpr
const
char
* TARGET_GEO{
"/home/igor/bmnroot/align_new/cfg/target_Sn.geo"
};
65
66
fair::Logger::SetConsoleColor(
true
);
67
fair::Logger::SetConsoleSeverity(
"info"
);
68
69
LOG(state) <<
" > makett : test task generation script started"
;
70
if
(!truthSigmaPath) {
71
LOG(error) <<
" <!> makett: truthSigmaPath is required, the truth is drawn from it"
;
72
return
-1;
73
}
74
75
// SetSeed(0) fills the whole TRandom3 state from a TUUID, and no single
76
// number reproduces that state. So a fresh seed is drawn here and set
77
// explicitly: the logged value rebuilds the same task.
78
if
(!seed)
79
seed =
TRandom3
(0).
Integer
(
kMaxUInt
) + 1;
80
gRandom
->SetSeed(seed);
81
LOG(info) <<
" random seed "
<< seed;
82
83
BmnMeasureLin3
measureModel;
84
BmnRun9DM
detModel(
kTRUE
);
85
if
(!detModel.
Init
(TARGET_GEO))
86
return
-1;
87
88
std::string outListPath;
89
{
90
// Scoped on purpose: this aligner holds the source data in RAM, and it
91
// is released here, before the one below loads the generated task.
92
BmnAligner
aligner(&measureModel, &detModel, fileListPath, constraintsPath, truthSigmaPath,
DEF_THREADS_COUNT
);
93
if
(!aligner.
Initialized
())
94
return
-1;
95
if
(!aligner.
PrepareData
())
96
return
-1;
97
if
(!
BmnAlignTestTask::Make
(aligner, testTaskPath, testSolPath, sigmaScale,
BmnAlignTestTask::kHitErrors
))
98
return
-1;
99
100
// make .list file for the task
101
std::string taskPath(testTaskPath);
102
auto
dot = taskPath.find_last_of(
'.'
);
103
auto
slash = taskPath.find_last_of(
'/'
);
104
Bool_t
dotInName = (dot != std::string::npos) && (slash == std::string::npos || dot > slash);
105
outListPath = (dotInName ? taskPath.substr(0, dot) : taskPath) +
".list"
;
106
107
std::ofstream listOut(outListPath);
108
if
(!listOut) {
109
LOG(error) <<
"Failed to write list file: "
<< outListPath;
110
return
-1;
111
}
112
listOut << testTaskPath <<
'\n'
;
113
}
114
LOG(state) <<
" < makett : test task generation completed"
;
115
116
if
(!showTask)
117
return
0;
118
119
LOG(state) <<
" > makett : test task visual representation"
;
120
BmnAligner
viewer(&measureModel, &detModel, outListPath.c_str(), constraintsPath, truthSigmaPath,
121
DEF_THREADS_COUNT
);
122
if
(!viewer.
Initialized
())
123
return
-1;
124
if
(!viewer.
PrepareData
())
125
return
-1;
126
if
(!viewer.
LoadSolution
(
""
))
127
return
-1;
128
if
(!viewer.
LoadSolution
(testSolPath))
129
return
-1;
130
BmnAlignReport::Results
(viewer);
131
BmnAlignReport::Draw
(viewer);
132
LOG(state) <<
" > makett : test task visual representation completed"
;
133
134
return
0;
135
}
BmnAlignModels.h
BmnAlignReport.h
BmnAlignTestTask.h
BmnAligner.h
Bool_t
bool Bool_t
UInt_t
unsigned int UInt_t
kMaxUInt
constexpr UInt_t kMaxUInt
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
TRandom3.h
gRandom
R__EXTERN TRandom * gRandom
BmnAlignReport::Draw
static void Draw(const BmnAligner &aligner, Int_t number=-1)
Definition
BmnAlignReport.cxx:614
BmnAlignReport::Results
static void Results(const BmnAligner &aligner)
Definition
BmnAlignReport.cxx:50
BmnAlignTestTask::Make
static Bool_t Make(BmnAligner &aligner, const char *dataPath, const char *solutionPath, Double_t sigmaScale=1.0, ENoise noise=kHitErrors, const TVector2 &stdDevXY=TVector2())
Definition
BmnAlignTestTask.cxx:109
BmnAlignTestTask::kHitErrors
@ kHitErrors
Definition
BmnAlignTestTask.h:50
BmnAligner
Definition
BmnAligner.h:36
BmnAligner::Initialized
Bool_t Initialized() const noexcept
Definition
BmnAligner.h:66
BmnAligner::LoadSolution
Bool_t LoadSolution(const char *jsonPath)
Definition
BmnAligner.cxx:480
BmnAligner::PrepareData
Bool_t PrepareData(const char *dumpPath=nullptr, Bool_t fitTargetZ=kTRUE)
Definition
BmnAligner.cxx:218
BmnDetectorModel::Init
Bool_t Init(const char *targetGeoFile=nullptr)
Definition
BmnDetectorModel.h:120
BmnMeasureLin3
Definition
BmnMeasureLin3.h:34
BmnRun9DM
Definition
BmnRun9DM.h:53
TRandom3
TRandom::Integer
virtual UInt_t Integer(UInt_t imax)
DEF_THREADS_COUNT
#define DEF_THREADS_COUNT
Definition
makett.C:26
makett
int makett(const char *fileListPath="/home/igor/bmnroot/align_new/cfg/run9/9555.noa_rlerr.list", const char *testTaskPath="/home/igor/data.cache/tt9555.r9_lin3.00.root", const char *testSolPath="/home/igor/data.cache/tt9555.r9_lin3.00.solution.json", const char *constraintsPath="/home/igor/bmnroot/align_new/cfg/constraints/cnstr_r9_lin3.json", const char *truthSigmaPath="/home/igor/bmnroot/align_new/cfg/presigmas/psg_r9_lin3-testTruth.json", Double_t sigmaScale=0.25, Bool_t showTask=kTRUE, UInt_t seed=137)
Build a synthetic alignment task with a known answer.
Definition
makett.C:54
align_new
macro
makett.C
Generated on
for BmnRoot by
1.17.0