BmnRoot
Loading...
Searching...
No Matches
BmnGemStripStationSet.cxx
Go to the documentation of this file.
2// STL
3#include <fstream>
4// Nlohmann
5#include <nlohmann/json.hpp>
6
8
10 : NStations(0)
11 , XStationPositions(nullptr)
12 , YStationPositions(nullptr)
13 , ZStationPositions(nullptr)
14 , BeamHoleRadiuses(nullptr)
15 , GemStations(nullptr)
16 , fStatShifts(nullptr)
17{}
18
19BmnGemStripStationSet::BmnGemStripStationSet(TString xml_config_file, map<Int_t, TVector3>* shifts)
20 : NStations(0)
21 , XStationPositions(nullptr)
22 , YStationPositions(nullptr)
23 , ZStationPositions(nullptr)
24 , BeamHoleRadiuses(nullptr)
25 , GemStations(nullptr)
26 , fStatShifts(shifts)
27{
28 Bool_t create_status = CreateConfigurationFromXMLFile(xml_config_file);
29 if (!create_status) {
30 std::cerr
31 << "Error: There are problems with creation of the configuration from XML (in BmnGemStripStationSet)\n";
32 throw(StationSet_Exception("Error in the constructor BmnGemStripStationSet()"));
33 }
34}
35
36BmnGemStripStationSet::BmnGemStripStationSet(Int_t period, BmnSetup stp, map<Int_t, TVector3>* shifts)
37 : NStations(0)
38 , XStationPositions(nullptr)
39 , YStationPositions(nullptr)
40 , ZStationPositions(nullptr)
41 , BeamHoleRadiuses(nullptr)
42 , GemStations(nullptr)
43 , fStatShifts(shifts)
44{
45 TString gPathConfig = getenv("VMCWORKDIR");
46 TString xml_config_file;
47 switch (period) {
48 case 8:
49 if (stp == kBMNSETUP) {
50 xml_config_file = "GemRun8.xml";
51 } else {
52 xml_config_file = "GemRunSRC2021.xml";
53 }
54 break;
55 case 7:
56 if (stp == kBMNSETUP) {
57 xml_config_file = "GemRunSpring2018.xml";
58 } else {
59 xml_config_file = "GemRunSRCSpring2018.xml";
60 }
61 break;
62 case 6:
63 xml_config_file = "GemRunSpring2017.xml";
64 break;
65 default:
66 printf("Error! Unknown config!\n");
67 xml_config_file = "";
68 break;
69 }
70 if (xml_config_file.Length()) {
71 xml_config_file = gPathConfig + "/parameters/gem/XMLConfigs/" + xml_config_file;
72 Bool_t create_status = CreateConfigurationFromXMLFile(xml_config_file);
73 if (!create_status) {
74 std::cerr
75 << "Error: There are problems with creation of the configuration from XML (in BmnGemStripStationSet)\n";
76 throw(StationSet_Exception("Error in the constructor BmnGemStripStationSet()"));
77 }
78 }
79}
80
82{
84 delete[] XStationPositions;
85 XStationPositions = nullptr;
86 }
88 delete[] YStationPositions;
89 YStationPositions = nullptr;
90 }
92 delete[] ZStationPositions;
93 ZStationPositions = nullptr;
94 }
95 if (BeamHoleRadiuses) {
96 delete[] BeamHoleRadiuses;
97 BeamHoleRadiuses = nullptr;
98 }
99
100 for (Int_t i = 0; i < NStations; i++) {
101 if (GemStations[i]) {
102 delete GemStations[i];
103 GemStations[i] = nullptr;
104 }
105 }
106 NStations = 0;
107
108 if (GemStations) {
109 delete[] GemStations;
110 GemStations = nullptr;
111 }
112}
113
115{
116 if (XStationPositions && station_num >= 0 && station_num < NStations) {
117 return XStationPositions[station_num];
118 } else {
119 throw(StationSet_Exception("Error in the function GetXStationPosition()"));
120 }
121}
122
124{
125 if (YStationPositions && station_num >= 0 && station_num < NStations) {
126 return YStationPositions[station_num];
127 } else {
128 throw(StationSet_Exception("Error in the function GetYStationPosition()"));
129 }
130}
131
133{
134 if (ZStationPositions && station_num >= 0 && station_num < NStations) {
135 return ZStationPositions[station_num];
136 } else {
137 throw(StationSet_Exception("Error in the function GetZStationPosition()"));
138 }
139}
140
142{
143 if (BeamHoleRadiuses && station_num >= 0 && station_num < NStations) {
144 return BeamHoleRadiuses[station_num];
145 } else {
146 throw(StationSet_Exception("Error in the function GetBeamHoleRadius()"));
147 }
148}
149
151{
152 if (GemStations && station_num >= 0 && station_num < NStations) {
153 return GemStations[station_num];
154 } else {
155 throw(StationSet_Exception("Error in the function GetGemStation()"));
156 }
157}
158
160{
161 for (Int_t istation = 0; istation < NStations; ++istation) {
162 GemStations[istation]->Reset();
163 }
164}
165
167 Double_t ycoord,
168 Double_t zcoord,
169 Double_t px,
170 Double_t py,
171 Double_t pz,
172 Double_t dEloss,
173 Int_t refID)
174{
175
176 Int_t station = GetPointStationOwnership(xcoord, ycoord, zcoord);
177
178 if (station != -1) {
179 if (GemStations[station]->AddPointToStation(xcoord, ycoord, zcoord, px, py, pz, dEloss, refID) != -1)
180 return true;
181 else
182 return false;
183 }
184 return false;
185}
186
188{
189 Int_t points_sum = 0;
190 for (Int_t iStation = 0; iStation < NStations; iStation++) {
191 points_sum += GemStations[iStation]->CountNAddedToStationPoints();
192 }
193 return points_sum;
194}
195
197{
198 for (Int_t iStation = 0; iStation < NStations; iStation++) {
200 }
201}
202
204{
205 Int_t points_sum = 0;
206 for (Int_t iStation = 0; iStation < NStations; iStation++) {
207 points_sum += GemStations[iStation]->CountNProcessedPointInStation();
208 }
209 return points_sum;
210}
211
213{
214 /*for(Int_t iStation = 0; iStation < NStations; iStation++) {
215 if( (zcoord >= ZStationPositions[iStation]) && (zcoord <=
216 (ZStationPositions[iStation]+GemStations[iStation]->GetZSize())) ) { return iStation;
217 }
218 }*/
219
220 // for z-positions and z-shifts of all modules in a station
221 for (Int_t iStation = 0; iStation < NStations; iStation++) {
222 Int_t NModules = GemStations[iStation]->GetNModules();
223 for (Int_t iModule = 0; iModule < NModules; ++iModule) {
224 if (GemStations[iStation]->GetModule(iModule)->IsPointInsideZThickness(zcoord)) {
225 return iStation;
226 }
227 }
228 }
229 return -1;
230}
231
232Int_t BmnGemStripStationSet::GetPointStationOwnership(Double_t xcoord, Double_t ycoord, Double_t zcoord)
233{
234 // for z-positions and z-shifts of all modules in a station
235 for (Int_t iStation = 0; iStation < NStations; iStation++) {
236 Int_t NModules = GemStations[iStation]->GetNModules();
237 for (Int_t iModule = 0; iModule < NModules; ++iModule) {
238 // if( GemStations[iStation]->GetModule(iModule)->IsPointInsideZThickness(zcoord) ) {
239 if (GemStations[iStation]->GetModule(iModule)->IsPointInsideModule(xcoord, ycoord, zcoord)) {
240 return iStation;
241 }
242 }
243 }
244 return -1;
245}
246
247Bool_t BmnGemStripStationSet::CreateConfigurationFromXMLFile(TString xml_config_file)
248{
249 TDOMParser* parser = new TDOMParser();
250 parser->SetValidate(false);
251
252 Int_t parse_status = parser->ParseFile(xml_config_file);
253 if (parse_status != 0) {
254 std::cerr << "Error: An error occured when parsing the file! (in BmnGemStripStationSet)\n";
255 delete parser;
256 return false;
257 }
258
259 TXMLNode* node = parser->GetXMLDocument()->GetRootNode();
260
261 if (strcmp(node->GetNodeName(), "StationSet") != 0) {
262 std::cerr << "Error: Incorrect name of the root element! (in BmnGemStripStationSet)\n";
263 delete parser;
264 return false;
265 }
266
267 NStations = CountNumberOfStations(node);
268
270 XStationPositions = new Double_t[NStations];
271 YStationPositions = new Double_t[NStations];
272 ZStationPositions = new Double_t[NStations];
273 BeamHoleRadiuses = new Double_t[NStations];
274
275 // default values
276 for (Int_t i = 0; i < NStations; ++i) {
277 GemStations[i] = 0; // zero-pointer
278 XStationPositions[i] = 0.0;
279 YStationPositions[i] = 0.0;
280 ZStationPositions[i] = 0.0;
281 BeamHoleRadiuses[i] = 0.0;
282 }
283
284 node = node->GetChildren();
285 Int_t currentStationNum = 0;
286 while (node) {
287 if (strcmp(node->GetNodeName(), "Station") == 0) {
288 Bool_t b_parse_status = ParseStation(node, currentStationNum);
289 if (!b_parse_status) {
290 delete parser;
291 return false;
292 }
293 currentStationNum++;
294 }
295 node = node->GetNextNode();
296 }
297
298 delete parser;
299
300 return true;
301}
302
303Int_t BmnGemStripStationSet::CountNumberOfStations(TXMLNode* node)
304{
305 Int_t station_cnt = 0;
306 node = node->GetChildren();
307 while (node) {
308 if (strcmp(node->GetNodeName(), "Station") == 0) {
309 station_cnt++;
310 }
311 node = node->GetNextNode();
312 }
313 return station_cnt;
314}
315
316Bool_t BmnGemStripStationSet::ParseStation(TXMLNode* node, Int_t iStation)
317{
318
319 if (node->HasAttributes()) {
320 TList* attrList = node->GetAttributes();
321 TXMLAttr* attr = 0;
322 TIter next(attrList);
323
324 while ((attr = (TXMLAttr*)next()) != nullptr) {
325 if (strcmp(attr->GetName(), "xPosition") == 0) {
326 XStationPositions[iStation] = -atof(attr->GetValue()); // inverted
327 }
328 if (strcmp(attr->GetName(), "yPosition") == 0) {
329 YStationPositions[iStation] = atof(attr->GetValue());
330 }
331 if (strcmp(attr->GetName(), "zPosition") == 0) {
332 ZStationPositions[iStation] = atof(attr->GetValue());
333 }
334 if (strcmp(attr->GetName(), "beamHole") == 0) {
335 BeamHoleRadiuses[iStation] = atof(attr->GetValue());
336 }
337 }
338 }
339
340 Double_t dx = 0.;
341 Double_t dy = 0.;
342 Double_t dz = 0.;
343
344 if (fStatShifts)
345 for (auto it : *fStatShifts) {
346 Int_t stat = it.first;
347 if (iStation == stat) {
348 dx = it.second.X();
349 dy = it.second.Y();
350 dz = it.second.Z();
351 break;
352 }
353 }
354
355 GemStations[iStation] =
356 new BmnGemStripStation(node, iStation, XStationPositions[iStation] + dx, YStationPositions[iStation] + dy,
357 ZStationPositions[iStation] + dz, BeamHoleRadiuses[iStation]);
358
359 return true;
360}
361
362unique_ptr<BmnGemStripStationSet> BmnGemStripStationSet::Create(Int_t period, Int_t stp)
363{
364 TString gPathConfig = getenv("VMCWORKDIR");
365 std::ifstream f(gPathConfig + "/config/bmnconf.json");
366 json data = json::parse(f);
367 json jss = data["Detectors"]["gem"]["StationSet"];
368 TString conf_subdir = jss.value("Dir", "");
369 json xmlConfFileNameJ = jss[to_string(stp).c_str()];
370 TString xmlConfFileName = jss["Setup"][to_string(stp).c_str()]["Period"].value(to_string(period).c_str(), "");
371 TString gPathCscConfig = gPathConfig + "/" + conf_subdir + "/";
372 return std::make_unique<BmnGemStripStationSet>(gPathCscConfig + xmlConfFileName);
373}
const int NStations
Definition L1AlgoPulls.h:9
int i
Definition P4_F32vec4.h:22
float f
Definition P4_F32vec4.h:21
BmnSetup
Definition BmnEnums.h:89
@ kBMNSETUP
Definition BmnEnums.h:90
BmnGemStripStation ** GemStations
map< Int_t, TVector3 > * fStatShifts
Double_t GetXStationPosition(Int_t station_num)
BmnGemStripStation * GetGemStation(Int_t station_num)
static unique_ptr< BmnGemStripStationSet > Create(Int_t period, Int_t stp=0)
Double_t GetZStationPosition(Int_t station_num)
Double_t GetYStationPosition(Int_t station_num)
Double_t GetBeamHoleRadius(Int_t station_num)
Int_t GetPointStationOwnership(Double_t zcoord)
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)
a class to store JSON values
Definition json.hpp:17282
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:19319
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
Definition json.hpp:20814
basic_json<> json
default specialization
Definition json.hpp:3337