BmnRoot
Loading...
Searching...
No Matches
BmnVSPStation.cxx
Go to the documentation of this file.
1#include "BmnVSPStation.h"
2
4: StationNumber(0), NModules(0),
5 XMinStation(0.0), XMaxStation(0.0),
6 YMinStation(0.0), YMaxStation(0.0),
7 ZMinStation(0.0), ZMaxStation(0.0),
8 XSize(0.0), YSize(0.0), ZSize(0.0),
9 XPosition(0.0), YPosition(0.0), ZPosition(0.0),
10 RotationAngleDeg(0.0), RotationCenterX(0.0), RotationCenterY(0.0),
11 XShiftOfModules(NULL), YShiftOfModules(NULL), ZShiftOfModules(NULL),
12 Modules(NULL)
13{}
14
15BmnVSPStation::BmnVSPStation(TXMLNode *stationNode, Int_t iStation,
16 Double_t xpos_station, Double_t ypos_station, Double_t zpos_station)
17
18: StationNumber(iStation), NModules(0),
19 XMinStation(0.0), XMaxStation(0.0),
20 YMinStation(0.0), YMaxStation(0.0),
21 ZMinStation(0.0), ZMaxStation(0.0),
22 XSize(0.0), YSize(0.0), ZSize(0.0),
23 XPosition(xpos_station), YPosition(ypos_station), ZPosition(zpos_station),
24 RotationAngleDeg(0.0), RotationCenterX(0.0), RotationCenterY(0.0),
25 XShiftOfModules(NULL), YShiftOfModules(NULL), ZShiftOfModules(NULL),
26 Modules(NULL)
27{
28 Bool_t create_status = CreateConfigurationFromXMLNode(stationNode);
29 if(!create_status) {
30 std::cerr << "Error: There are problems with creation of the configuration from XML node (in BmnVSPStation)\n";
31 }
32
33 //define station borders and sizes
35
39}
40
42 for (Int_t i = 0; i < NModules; ++i) {
43 if (Modules[i]) {
44 delete Modules[i];
45 Modules[i] = NULL;
46 }
47 }
48 NModules = 0;
49
50 if (Modules) {
51 delete [] Modules;
52 Modules = NULL;
53 }
54 if (XShiftOfModules) {
55 delete [] XShiftOfModules;
56 XShiftOfModules = NULL;
57 }
58 if (YShiftOfModules) {
59 delete [] YShiftOfModules;
60 YShiftOfModules = NULL;
61 }
62 if (ZShiftOfModules) {
63 delete [] ZShiftOfModules;
64 ZShiftOfModules = NULL;
65 }
66}
67
68Double_t BmnVSPStation::GetXShiftOfModule(Int_t module_num) {
69 if(XShiftOfModules && module_num >= 0 && module_num < NModules) {
70 return XShiftOfModules[module_num];
71 }
72 else {
73 throw(Station_Exception("Error in the function GetXShiftOfModule()"));
74 }
75}
76
77Double_t BmnVSPStation::GetYShiftOfModule(Int_t module_num) {
78 if(YShiftOfModules && module_num >= 0 && module_num < NModules) {
79 return YShiftOfModules[module_num];
80 }
81 else {
82 throw(Station_Exception("Error in the function GetYShiftOfModule()"));
83 }
84}
85
86Double_t BmnVSPStation::GetZShiftOfModule(Int_t module_num) {
87 if(ZShiftOfModules && module_num >= 0 && module_num < NModules) {
88 return ZShiftOfModules[module_num];
89 }
90 else {
91 throw(Station_Exception("Error in the function GetZShiftOfModule()"));
92 }
93}
94
96 if(Modules && module_num >= 0 && module_num < NModules) {
97 return Modules[module_num];
98 }
99 else {
100 //throw(Station_Exception("Error in the function GetReadoutModule()"));
101 return NULL;
102 }
103}
104
106 for(Int_t imodule = 0; imodule < NModules; ++imodule) {
107 Modules[imodule]->ResetModuleData();
108 }
109}
110
111Int_t BmnVSPStation::AddPointToStation(Double_t xcoord, Double_t ycoord, Double_t zcoord,
112 Double_t px, Double_t py, Double_t pz,
113 Double_t dEloss, Int_t refID) {
114
115 Int_t module = GetPointModuleOwnership(xcoord, ycoord, zcoord);
116
117 if(module >= 0) {
118 //if(Modules[module]->AddRealPointSimple(xcoord, ycoord, zcoord, px, py, pz, dEloss, refID)) {
119 //if(Modules[module]->AddRealPointFullOne(xcoord, ycoord, zcoord, px, py, pz, dEloss, refID)) {
120 //if(Modules[module]->AddRealPointFullOne_WithIncline(xcoord, ycoord, zcoord, px, py, pz, dEloss, refID)) {
121 if(Modules[module]->AddRealPointFull(xcoord, ycoord, zcoord, px, py, pz, dEloss, refID)) {
122 return module;
123 }
124 else {
125 return -1;
126 }
127 }
128 return -1;
129}
130
132 Int_t points_sum = 0;
133 for(Int_t iModule = 0; iModule < NModules; iModule++) {
134 points_sum += Modules[iModule]->GetNRealPoints();
135 }
136 return points_sum;
137}
138
140 for(Int_t iModule = 0; iModule < NModules; iModule++) {
142 }
143}
144
146 Int_t points_sum = 0;
147 for(Int_t iModule = 0; iModule < NModules; iModule++) {
148 points_sum += Modules[iModule]->GetNIntersectionPoints();
149 }
150 return points_sum;
151}
152
153Int_t BmnVSPStation::GetPointModuleOwnership(Double_t xcoord, Double_t ycoord, Double_t zcoord) {
154 for(Int_t imodule = 0; imodule < NModules; ++imodule) {
155 if( Modules[imodule]->IsPointInsideModule(xcoord, ycoord, zcoord, false) ) return imodule;
156 }
157 return -1;
158}
159
161 XMinStation = 1.0E+10;
162 XMaxStation = -1.0E+10;
163 YMinStation = 1.0E+10;
164 YMaxStation = -1.0E+10;
165 ZMinStation = 1.0E+10;
166 ZMaxStation = -1.0E+10;
167
168 for(Int_t i = 0; i < NModules; ++i) {
169 if( Modules[i]->GetXMinModule() < XMinStation ) XMinStation = Modules[i]->GetXMinModule();
170 if( Modules[i]->GetXMaxModule() > XMaxStation ) XMaxStation = Modules[i]->GetXMaxModule();
171 if( Modules[i]->GetYMinModule() < YMinStation ) YMinStation = Modules[i]->GetYMinModule();
172 if( Modules[i]->GetYMaxModule() > YMaxStation ) YMaxStation = Modules[i]->GetYMaxModule();
173
174 Double_t zstart = Modules[i]->GetZStartModulePosition();
176 if( zstart < ZMinStation ) ZMinStation = zstart;
177 if( zend > ZMaxStation ) ZMaxStation = zend;
178 }
179}
180
181Bool_t BmnVSPStation::CreateConfigurationFromXMLNode(TXMLNode *node) {
182 NModules = CountNumberOfModules(node);
183
185 XShiftOfModules = new Double_t[NModules];
186 YShiftOfModules = new Double_t[NModules];
187 ZShiftOfModules = new Double_t[NModules];
188
189 //default values
190 for(Int_t i = 0; i < NModules; ++i) {
191 Modules[i] = 0; //zero-pointer
192 XShiftOfModules[i] = 0.0;
193 YShiftOfModules[i] = 0.0;
194 ZShiftOfModules[i] = 0.0;
195 }
196
197 //for station rotation parameters
198 if( node->HasAttributes() ) {
199 TList *attrList = node->GetAttributes();
200 TXMLAttr *attr = 0;
201 TIter next(attrList);
202
203 while ((attr = (TXMLAttr*)next()) != nullptr) {
204 if( strcmp(attr->GetName(), "rotAngleDeg") == 0 ) {
205 RotationAngleDeg = atof(attr->GetValue()); //clockwise direction is plus, if we look at the module in the direction of the beam axis
206 }
207 if( strcmp(attr->GetName(), "rotCenterX") == 0 ) {
208 RotationCenterX = -atof(attr->GetValue()); //inverted (from global to local system)
209 }
210 if( strcmp(attr->GetName(), "rotCenterY") == 0 ) {
211 RotationCenterY = atof(attr->GetValue());
212 }
213 }
214 }
215
216 node = node->GetChildren();
217 Int_t currentModuleNum = 0;
218 while(node) {
219 if( strcmp(node->GetNodeName(), "Module") == 0 ) {
220 Bool_t parse_status = ParseModule(node, currentModuleNum);
221 if(!parse_status) return false;
222 currentModuleNum++;
223 }
224 node = node->GetNextNode();
225 }
226
227 return true;
228}
229
230Int_t BmnVSPStation::CountNumberOfModules(TXMLNode *node) {
231 Int_t module_cnt = 0;
232 node = node->GetChildren();
233 while(node) {
234 if( strcmp(node->GetNodeName(), "Module") == 0 ) {
235 module_cnt++;
236 }
237 node = node->GetNextNode();
238 }
239 return module_cnt;
240}
241
242Bool_t BmnVSPStation::ParseModule(TXMLNode *node, Int_t iModule) {
243
244 if( node->HasAttributes() ) {
245 TList *attrList = node->GetAttributes();
246 TXMLAttr *attr = 0;
247 TIter next(attrList);
248
249 while ((attr = (TXMLAttr*)next()) != nullptr) {
250 if( strcmp(attr->GetName(), "xShift") == 0 ) {
251 XShiftOfModules[iModule] = -atof(attr->GetValue()); //inverted (from global to local system)
252 }
253 if( strcmp(attr->GetName(), "yShift") == 0 ) {
254 YShiftOfModules[iModule] = atof(attr->GetValue());
255 }
256 if( strcmp(attr->GetName(), "zShift") == 0 ) {
257 ZShiftOfModules[iModule] = atof(attr->GetValue());
258 }
259 }
260 }
261
262 Modules[iModule] = new BmnVSPModule(ZPosition+ZShiftOfModules[iModule]);
264
265 //Layers
266 node = node->GetChildren();
267 Int_t currentLayerNum = 0;
268 while(node) {
269 if( strcmp(node->GetNodeName(), "Layer") == 0 ) {
270 Modules[iModule]->AddStripLayer(ParseLayer(node, currentLayerNum, iModule));
271 currentLayerNum++;
272 }
273 node = node->GetNextNode();
274 }
275
276 return true;
277}
278
279BmnVSPLayer BmnVSPStation::ParseLayer(TXMLNode *node, Int_t iLayer, Int_t iModule) {
280 Int_t zone_id; //id-number of a zone in the module (e.g. big or small)
281 StripLayerType layer_type; // lower or upper strips
282 Int_t first_strip_number; //a number that numbered strips start with
283 Double_t adeg; //strip angle (positive value in degrees is clockwise from vertical)
284 Double_t pitch;
285 Double_t xsize, ysize, xorig, yorig;
286 StripNumberingDirection strip_direction;
287 Double_t lx_border, ly_border; //left border
288 Double_t rx_border, ry_border; //right border
289
290 if( node->HasAttributes() ) {
291 TList *attrList = node->GetAttributes();
292 TXMLAttr *attr = 0;
293 TIter next(attrList);
294
295 while ((attr = (TXMLAttr*)next()) != nullptr) {
296 if( strcmp(attr->GetName(), "zoneID") == 0 ) {
297 zone_id = atoi(attr->GetValue());
298 }
299 if( strcmp(attr->GetName(), "type") == 0 ) {
300 if( strcmp(attr->GetValue(), "lower") == 0 ) {
301 layer_type = LowerStripLayer;
302 }
303 if( strcmp(attr->GetValue(), "upper") == 0 ) {
304 layer_type = UpperStripLayer;
305 }
306 }
307 if( strcmp(attr->GetName(), "firstStripNumber") == 0 ) {
308 first_strip_number = atoi(attr->GetValue());
309 }
310 if( strcmp(attr->GetName(), "stripAngle") == 0 ) {
311 adeg = atof(attr->GetValue());
312 }
313 if( strcmp(attr->GetName(), "pitch") == 0 ) {
314 pitch = atof(attr->GetValue());
315 }
316 if( strcmp(attr->GetName(), "xorig") == 0 ) {
317 xorig = -atof(attr->GetValue()); //inverted
318 }
319 if( strcmp(attr->GetName(), "yorig") == 0 ) {
320 yorig = atof(attr->GetValue());
321 }
322 if( strcmp(attr->GetName(), "xsize") == 0 ) {
323 xsize = atof(attr->GetValue());
324 }
325 if( strcmp(attr->GetName(), "ysize") == 0 ) {
326 ysize = atof(attr->GetValue());
327 }
328 if( strcmp(attr->GetName(), "stripDirection") == 0 ) {
329 if( strcmp(attr->GetValue(), "LeftToRight") == 0 ) {
330 strip_direction = LeftToRight;
331 }
332 if( strcmp(attr->GetValue(), "RightToLeft") == 0 ) {
333 strip_direction = RightToLeft;
334 }
335 }
336 if( strcmp(attr->GetName(), "lxborder") == 0 ) {
337 lx_border = -atof(attr->GetValue()); //inverted
338 }
339 if( strcmp(attr->GetName(), "lyborder") == 0 ) {
340 ly_border = atof(attr->GetValue());
341 }
342 if( strcmp(attr->GetName(), "rxborder") == 0 ) {
343 rx_border = -atof(attr->GetValue()); //inverted
344 }
345 if( strcmp(attr->GetName(), "ryborder") == 0 ) {
346 ry_border = atof(attr->GetValue());
347 }
348 }
349 }
350
351 BmnVSPLayer layer(zone_id, layer_type, first_strip_number,
352 xsize, ysize,
353 XShiftOfModules[iModule]+XPosition+xorig, YShiftOfModules[iModule]+YPosition+yorig,
354 pitch, adeg);
355
356 layer.SetStripNumberingOrder(strip_direction);
357
358 layer.SetStripNumberingBorders(XShiftOfModules[iModule]+XPosition+lx_border,
359 YShiftOfModules[iModule]+YPosition+ly_border,
360 XShiftOfModules[iModule]+XPosition+rx_border,
361 YShiftOfModules[iModule]+YPosition+ry_border);
362
363 //Dead zones
364 node = node->GetChildren();
365 Int_t currentDeadZoneNum = 0;
366 while(node) {
367 if( strcmp(node->GetNodeName(), "DeadZone") == 0 ) {
368 layer.AddDeadZone(ParseDeadZone(node, iModule));
369 currentDeadZoneNum++;
370 }
371 node = node->GetNextNode();
372 }
373
374 return layer;
375}
376
377DeadZoneOfStripLayer BmnVSPStation::ParseDeadZone(TXMLNode *node, Int_t iModule) {
378 DeadZoneOfStripLayer dead_zone;
379
380 Int_t n_dead_points = CountDeadZonePoints(node);
381 Double_t *xpoints = new Double_t[n_dead_points];
382 Double_t *ypoints = new Double_t[n_dead_points];
383
384 //Dead points
385 node = node->GetChildren();
386 Int_t currentDeadPointNum = 0;
387 while(node) {
388 if( strcmp(node->GetNodeName(), "DeadPoint") == 0 ) {
389
390 if( node->HasAttributes() ) {
391 TList *attrList = node->GetAttributes();
392 TXMLAttr *attr = 0;
393 TIter next(attrList);
394
395 while ((attr = (TXMLAttr*)next()) != nullptr)
396 {
397 if( strcmp(attr->GetName(), "x") == 0 ) {
398 xpoints[currentDeadPointNum] = -atof(attr->GetValue())+XShiftOfModules[iModule]+XPosition; //inverted
399 }
400 if( strcmp(attr->GetName(), "y") == 0 ) {
401 ypoints[currentDeadPointNum] = atof(attr->GetValue())+YShiftOfModules[iModule]+YPosition;
402 }
403 }
404 }
405
406 currentDeadPointNum++;
407 }
408 node = node->GetNextNode();
409 }
410
411 dead_zone.SetDeadZone(n_dead_points, xpoints, ypoints);
412
413 delete [] xpoints;
414 delete [] ypoints;
415
416 return dead_zone;
417}
418
419Int_t BmnVSPStation::CountDeadZonePoints(TXMLNode *node) {
420 Int_t dead_point_cnt = 0;
421 node = node->GetChildren();
422 while(node) {
423 if( strcmp(node->GetNodeName(), "DeadPoint") == 0 ) {
424 dead_point_cnt++;
425 }
426 node = node->GetNextNode();
427 }
428 return dead_point_cnt;
429}
int i
Definition P4_F32vec4.h:22
StripNumberingDirection
@ RightToLeft
@ LeftToRight
StripLayerType
@ UpperStripLayer
@ LowerStripLayer
Double_t GetYMinModule()
Bool_t SetModuleRotation(Double_t angleDeg, Double_t rot_center_x, Double_t rot_center_y)
Int_t GetNIntersectionPoints()
void CalculateStripHitIntersectionPoints()
void ResetModuleData()
Double_t GetXMinModule()
Double_t GetYMaxModule()
Double_t GetModuleThickness()
Double_t GetZStartModulePosition()
Double_t GetXMaxModule()
Int_t GetNRealPoints()
void AddStripLayer(BmnVSPLayer strip_layer)
Int_t AddPointToStation(Double_t xcoord, Double_t ycoord, Double_t zcoord, Double_t px, Double_t py, Double_t pz, Double_t dEloss, Int_t refID)
Double_t RotationAngleDeg
void DefineStationBorders()
Double_t XPosition
Double_t GetXShiftOfModule(Int_t module_num)
Double_t * ZShiftOfModules
BmnVSPModule ** Modules
Double_t * YShiftOfModules
Double_t ZMinStation
Double_t RotationCenterY
Double_t GetZShiftOfModule(Int_t module_num)
Double_t XMinStation
Int_t CountNAddedToStationPoints()
Double_t YMinStation
virtual ~BmnVSPStation()
BmnVSPModule * GetModule(Int_t module_num)
Double_t RotationCenterX
Double_t ZPosition
Double_t YPosition
Int_t CountNProcessedPointInStation()
Double_t GetYShiftOfModule(Int_t module_num)
Int_t GetPointModuleOwnership(Double_t xcoord, Double_t ycoord, Double_t zcoord)
Double_t ZMaxStation
Double_t XMaxStation
Double_t * XShiftOfModules
Double_t YMaxStation
void ProcessPointsInStation()
Bool_t SetDeadZone(Int_t n_points, Double_t *xpoints, Double_t *ypoints)