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