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