BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnVSPStationSet.cxx
Go to the documentation of this file.
1
#include "
BmnVSPStationSet.h
"
2
// STL
3
#include <fstream>
4
// Nlohmann
5
#include <
nlohmann/json.hpp
>
6
7
using
json =
nlohmann::json
;
8
9
BmnVSPStationSet::BmnVSPStationSet
()
10
:
NStations
(0)
11
,
XStationPositions
(NULL)
12
,
YStationPositions
(NULL)
13
,
ZStationPositions
(NULL)
14
,
VSPStations
(NULL)
15
,
fStatShifts
(NULL)
16
{}
17
18
BmnVSPStationSet::BmnVSPStationSet
(
TString
xml_config_file, map<Int_t, TVector3>* shifts)
19
:
NStations
(0)
20
,
XStationPositions
(NULL)
21
,
YStationPositions
(NULL)
22
,
ZStationPositions
(NULL)
23
,
VSPStations
(NULL)
24
,
fStatShifts
(shifts)
25
{
26
Bool_t
create_status =
CreateConfigurationFromXMLFile
(xml_config_file);
27
if
(!create_status) {
28
std::cerr <<
"Error: There are problems with creation of the configuration from XML (in BmnVSPStationSet)\n"
;
29
}
30
}
31
32
BmnVSPStationSet::~BmnVSPStationSet
()
33
{
34
if
(
XStationPositions
) {
35
delete
[]
XStationPositions
;
36
XStationPositions
= NULL;
37
}
38
if
(
YStationPositions
) {
39
delete
[]
YStationPositions
;
40
YStationPositions
= NULL;
41
}
42
if
(
ZStationPositions
) {
43
delete
[]
ZStationPositions
;
44
ZStationPositions
= NULL;
45
}
46
47
for
(
Int_t
i
= 0;
i
<
NStations
;
i
++) {
48
if
(
VSPStations
[
i
]) {
49
delete
VSPStations
[
i
];
50
VSPStations
[
i
] = NULL;
51
}
52
}
53
NStations
= 0;
54
55
if
(
VSPStations
) {
56
delete
[]
VSPStations
;
57
VSPStations
= NULL;
58
}
59
}
60
61
Double_t
BmnVSPStationSet::GetXStationPosition
(
Int_t
station_num)
62
{
63
if
(
XStationPositions
&& station_num >= 0 && station_num <
NStations
) {
64
return
XStationPositions
[station_num];
65
}
else
{
66
throw
(
StationSet_Exception
(
"Error in the function GetXStationPosition()"
));
67
}
68
}
69
70
Double_t
BmnVSPStationSet::GetYStationPosition
(
Int_t
station_num)
71
{
72
if
(
YStationPositions
&& station_num >= 0 && station_num <
NStations
) {
73
return
YStationPositions
[station_num];
74
}
else
{
75
throw
(
StationSet_Exception
(
"Error in the function GetYStationPosition()"
));
76
}
77
}
78
79
Double_t
BmnVSPStationSet::GetZStationPosition
(
Int_t
station_num)
80
{
81
if
(
ZStationPositions
&& station_num >= 0 && station_num <
NStations
) {
82
return
ZStationPositions
[station_num];
83
}
else
{
84
throw
(
StationSet_Exception
(
"Error in the function GetZStationPosition()"
));
85
}
86
}
87
88
BmnVSPStation
*
BmnVSPStationSet::GetVSPStation
(
Int_t
station_num)
89
{
90
if
(
VSPStations
&& station_num >= 0 && station_num <
NStations
) {
91
return
VSPStations
[station_num];
92
}
else
{
93
throw
(
StationSet_Exception
(
"Error in the function GetVSPStation()"
));
94
}
95
}
96
97
void
BmnVSPStationSet::Reset
()
98
{
99
for
(
Int_t
istation = 0; istation <
NStations
; ++istation) {
100
VSPStations
[istation]->Reset();
101
}
102
}
103
104
Bool_t
BmnVSPStationSet::AddPointToDetector
(
Double_t
xcoord,
105
Double_t
ycoord,
106
Double_t
zcoord,
107
Double_t
px,
108
Double_t
py,
109
Double_t
pz,
110
Double_t
dEloss,
111
Int_t
refID)
112
{
113
114
Int_t
station =
GetPointStationOwnership
(zcoord);
115
116
if
(station != -1) {
117
if
(
VSPStations
[station]->AddPointToStation(xcoord, ycoord, zcoord, px, py, pz, dEloss, refID) != -1)
118
return
true
;
119
else
120
return
false
;
121
}
122
return
false
;
123
}
124
125
Int_t
BmnVSPStationSet::CountNAddedToDetectorPoints
()
126
{
127
Int_t
points_sum = 0;
128
for
(
Int_t
iStation = 0; iStation <
NStations
; iStation++) {
129
points_sum +=
VSPStations
[iStation]->CountNAddedToStationPoints();
130
}
131
return
points_sum;
132
}
133
134
void
BmnVSPStationSet::ProcessPointsInDetector
()
135
{
136
for
(
Int_t
iStation = 0; iStation <
NStations
; iStation++) {
137
VSPStations
[iStation]->ProcessPointsInStation();
138
}
139
}
140
141
Int_t
BmnVSPStationSet::CountNProcessedPointsInDetector
()
142
{
143
Int_t
points_sum = 0;
144
for
(
Int_t
iStation = 0; iStation <
NStations
; iStation++) {
145
points_sum +=
VSPStations
[iStation]->CountNProcessedPointInStation();
146
}
147
return
points_sum;
148
}
149
150
Int_t
BmnVSPStationSet::GetPointStationOwnership
(
Double_t
zcoord)
151
{
152
// for z-positions and z-shifts of all modules in a station
153
for
(
Int_t
iStation = 0; iStation <
NStations
; iStation++) {
154
Int_t
NModules =
VSPStations
[iStation]->GetNModules();
155
for
(
Int_t
iModule = 0; iModule < NModules; ++iModule) {
156
if
(
VSPStations
[iStation]->GetModule(iModule)->IsPointInsideZThickness(zcoord)) {
157
return
iStation;
158
}
159
}
160
}
161
return
-1;
162
}
163
164
Int_t
BmnVSPStationSet::GetPointStationOwnership
(
Double_t
xcoord,
Double_t
ycoord,
Double_t
zcoord)
165
{
166
// for z-positions and z-shifts of all modules in a station
167
for
(
Int_t
iStation = 0; iStation <
NStations
; iStation++) {
168
Int_t
NModules =
VSPStations
[iStation]->GetNModules();
169
for
(
Int_t
iModule = 0; iModule < NModules; ++iModule) {
170
// if( VSPStations[iStation]->GetModule(iModule)->IsPointInsideZThickness(zcoord) ) {
171
if
(
VSPStations
[iStation]->GetModule(iModule)->IsPointInsideModule(xcoord, ycoord, zcoord)) {
172
return
iStation;
173
}
174
}
175
}
176
return
-1;
177
}
178
179
Bool_t
BmnVSPStationSet::CreateConfigurationFromXMLFile
(
TString
xml_config_file)
180
{
181
TDOMParser
* parser =
new
TDOMParser
();
182
parser->
SetValidate
(
false
);
183
184
Int_t
parse_status = parser->
ParseFile
(xml_config_file);
185
if
(parse_status != 0) {
186
std::cerr <<
"Error: An error occured when parsing the file! (in BmnVSPStationSet)\n"
;
187
return
false
;
188
}
189
190
TXMLNode
* node = parser->
GetXMLDocument
()->
GetRootNode
();
191
192
if
(strcmp(node->
GetNodeName
(),
"StationSet"
) != 0) {
193
std::cerr <<
"Error: Incorrect name of the root element! (in BmnVSPStationSet)\n"
;
194
return
false
;
195
}
196
197
NStations
=
CountNumberOfStations
(node);
198
199
VSPStations
=
new
BmnVSPStation
*[
NStations
];
200
XStationPositions
=
new
Double_t
[
NStations
];
201
YStationPositions
=
new
Double_t
[
NStations
];
202
ZStationPositions
=
new
Double_t
[
NStations
];
203
204
// default values
205
for
(
Int_t
i
= 0;
i
<
NStations
; ++
i
) {
206
VSPStations
[
i
] = 0;
// zero-pointer
207
XStationPositions
[
i
] = 0.0;
208
YStationPositions
[
i
] = 0.0;
209
ZStationPositions
[
i
] = 0.0;
210
}
211
212
node = node->
GetChildren
();
213
Int_t
currentStationNum = 0;
214
while
(node) {
215
if
(strcmp(node->
GetNodeName
(),
"Station"
) == 0) {
216
parse_status =
ParseStation
(node, currentStationNum);
217
if
(!parse_status)
218
return
false
;
219
currentStationNum++;
220
}
221
node = node->
GetNextNode
();
222
}
223
224
delete
parser;
225
226
return
true
;
227
}
228
229
Int_t
BmnVSPStationSet::CountNumberOfStations
(
TXMLNode
* node)
230
{
231
Int_t
station_cnt = 0;
232
node = node->
GetChildren
();
233
while
(node) {
234
if
(strcmp(node->
GetNodeName
(),
"Station"
) == 0) {
235
station_cnt++;
236
}
237
node = node->
GetNextNode
();
238
}
239
return
station_cnt;
240
}
241
242
Bool_t
BmnVSPStationSet::ParseStation
(
TXMLNode
* node,
Int_t
iStation)
243
{
244
245
if
(node->
HasAttributes
()) {
246
TList
* attrList = node->
GetAttributes
();
247
TXMLAttr
* attr = 0;
248
TIter
next(attrList);
249
250
while
((attr = (
TXMLAttr
*)next()) !=
nullptr
) {
251
if
(strcmp(attr->
GetName
(),
"xPosition"
) == 0) {
252
XStationPositions
[iStation] = -atof(attr->
GetValue
());
// inverted
253
}
254
if
(strcmp(attr->
GetName
(),
"yPosition"
) == 0) {
255
YStationPositions
[iStation] = atof(attr->
GetValue
());
256
}
257
if
(strcmp(attr->
GetName
(),
"zPosition"
) == 0) {
258
ZStationPositions
[iStation] = atof(attr->
GetValue
());
259
}
260
}
261
}
262
263
Double_t
dx = 0.;
264
Double_t
dy = 0.;
265
Double_t
dz = 0.;
266
267
if
(
fStatShifts
)
268
for
(
auto
it : *
fStatShifts
) {
269
Int_t
stat = it.first;
270
if
(iStation == stat) {
271
dx = it.second.X();
272
dy = it.second.Y();
273
dz = it.second.Z();
274
break
;
275
}
276
}
277
278
VSPStations
[iStation] =
new
BmnVSPStation
(node, iStation,
XStationPositions
[iStation] + dx,
279
YStationPositions
[iStation] + dy,
ZStationPositions
[iStation] + dz);
280
return
true
;
281
}
282
283
unique_ptr<BmnVSPStationSet>
BmnVSPStationSet::Create
(
Int_t
period,
Int_t
stp)
284
{
285
TString
gPathConfig = getenv(
"VMCWORKDIR"
);
286
std::ifstream f(gPathConfig +
"/config/bmnconf.json"
);
287
json data = json::parse(f);
288
json jss = data[
"Detectors"
][
"vsp"
][
"StationSet"
];
289
TString
conf_subdir = jss.value(
"Dir"
,
""
);
290
json xmlConfFileNameJ = jss[to_string(stp).c_str()];
291
TString
xmlConfFileName = jss[
"Setup"
][to_string(stp).c_str()][
"Period"
].value(to_string(period).c_str(),
""
);
292
TString
gPathCscConfig = gPathConfig +
"/"
+ conf_subdir +
"/"
;
293
return
std::make_unique<BmnVSPStationSet>(gPathCscConfig + xmlConfFileName);
294
}
i
int i
Definition
P4_F32vec4.h:22
Bool_t
bool Bool_t
Int_t
int Int_t
Double_t
double Double_t
BmnVSPStationSet::ZStationPositions
Double_t * ZStationPositions
Definition
BmnVSPStationSet.h:21
BmnVSPStationSet::fStatShifts
map< Int_t, TVector3 > * fStatShifts
Definition
BmnVSPStationSet.h:24
BmnVSPStationSet::CountNProcessedPointsInDetector
Int_t CountNProcessedPointsInDetector()
Definition
BmnVSPStationSet.cxx:141
BmnVSPStationSet::GetZStationPosition
Double_t GetZStationPosition(Int_t station_num)
Definition
BmnVSPStationSet.cxx:79
BmnVSPStationSet::XStationPositions
Double_t * XStationPositions
Definition
BmnVSPStationSet.h:19
BmnVSPStationSet::ParseStation
Bool_t ParseStation(TXMLNode *node, Int_t iStation)
Definition
BmnVSPStationSet.cxx:242
BmnVSPStationSet::Reset
void Reset()
Definition
BmnVSPStationSet.cxx:97
BmnVSPStationSet::AddPointToDetector
Bool_t AddPointToDetector(Double_t xcoord, Double_t ycoord, Double_t zcoord, Double_t px, Double_t py, Double_t pz, Double_t dEloss, Int_t refID)
Definition
BmnVSPStationSet.cxx:104
BmnVSPStationSet::NStations
Int_t NStations
Definition
BmnVSPStationSet.h:17
BmnVSPStationSet::BmnVSPStationSet
BmnVSPStationSet()
Definition
BmnVSPStationSet.cxx:9
BmnVSPStationSet::GetPointStationOwnership
Int_t GetPointStationOwnership(Double_t zcoord)
Definition
BmnVSPStationSet.cxx:150
BmnVSPStationSet::~BmnVSPStationSet
virtual ~BmnVSPStationSet()
Definition
BmnVSPStationSet.cxx:32
BmnVSPStationSet::GetXStationPosition
Double_t GetXStationPosition(Int_t station_num)
Definition
BmnVSPStationSet.cxx:61
BmnVSPStationSet::VSPStations
BmnVSPStation ** VSPStations
Definition
BmnVSPStationSet.h:23
BmnVSPStationSet::Create
static unique_ptr< BmnVSPStationSet > Create(Int_t period, Int_t stp=0)
Definition
BmnVSPStationSet.cxx:283
BmnVSPStationSet::CountNAddedToDetectorPoints
Int_t CountNAddedToDetectorPoints()
Definition
BmnVSPStationSet.cxx:125
BmnVSPStationSet::YStationPositions
Double_t * YStationPositions
Definition
BmnVSPStationSet.h:20
BmnVSPStationSet::CountNumberOfStations
Int_t CountNumberOfStations(TXMLNode *node)
Definition
BmnVSPStationSet.cxx:229
BmnVSPStationSet::ProcessPointsInDetector
void ProcessPointsInDetector()
Definition
BmnVSPStationSet.cxx:134
BmnVSPStationSet::CreateConfigurationFromXMLFile
Bool_t CreateConfigurationFromXMLFile(TString xml_config_file)
Definition
BmnVSPStationSet.cxx:179
BmnVSPStationSet::GetVSPStation
BmnVSPStation * GetVSPStation(Int_t station_num)
Definition
BmnVSPStationSet.cxx:88
BmnVSPStationSet::GetYStationPosition
Double_t GetYStationPosition(Int_t station_num)
Definition
BmnVSPStationSet.cxx:70
BmnVSPStation
Definition
BmnVSPStation.h:14
StationSet_Exception
Definition
BmnStripData.h:30
TDOMParser
TDOMParser::GetXMLDocument
virtual TXMLDocument * GetXMLDocument() const
TDOMParser::ParseFile
Int_t ParseFile(const char *filename) override
TIter
TList
TString
TXMLAttr
TXMLAttr::GetValue
const char * GetValue() const
TXMLAttr::GetName
const char * GetName() const override
TXMLDocument::GetRootNode
TXMLNode * GetRootNode() const
TXMLNode
TXMLNode::GetAttributes
TList * GetAttributes()
TXMLNode::GetNextNode
TXMLNode * GetNextNode()
TXMLNode::GetChildren
TXMLNode * GetChildren()
TXMLNode::GetNodeName
const char * GetNodeName() const
TXMLNode::HasAttributes
Bool_t HasAttributes() const
TXMLParser::SetValidate
void SetValidate(Bool_t val=kTRUE)
BmnVSPStationSet.h
json.hpp
nlohmann::json
basic_json<> json
default specialization
Definition
json.hpp:3365
detectors
vsp
BmnVSPStationSet.cxx
Generated on
for BmnRoot by
1.17.0