1 package org.lcsim.geometry.segmentation;
2
3 import hep.physics.vec.Hep3Vector;
4
5 import java.util.ArrayList;
6
7 import org.jdom.DataConversionException;
8 import org.jdom.Element;
9 import org.lcsim.detector.identifier.IExpandedIdentifier;
10 import org.lcsim.geometry.layer.Layer;
11 import org.lcsim.geometry.layer.Layering;
12 import org.lcsim.geometry.subdetector.BarrelEndcapFlag;
13 import org.lcsim.geometry.util.IDDescriptor;
14
15
16
17
18
19
20
21 public class GlobalGridXY extends AbstractCartesianGrid
22 {
23 private int xIndex = -1;
24 private int yIndex = -1;
25 private static final String[] fieldNames = {"x", "y"};
26
27 public GlobalGridXY(Element node) throws DataConversionException
28 {
29 super(node);
30
31 if (node.getAttribute("gridSizeX") != null)
32 {
33 gridSizeX = node.getAttribute("gridSizeX").getDoubleValue();
34 cellSizes.add(0, gridSizeX);
35 }
36 else
37 {
38 throw new RuntimeException("Missing gridSizeX parameter.");
39 }
40
41 if (node.getAttribute("gridSizeY") != null)
42 {
43 gridSizeY = node.getAttribute("gridSizeY").getDoubleValue();
44 cellSizes.add(1, gridSizeY);
45 }
46 else
47 {
48 throw new RuntimeException("Missing gridSizeY parameter.");
49 }
50 }
51
52 public String[] getSegmentationFieldNames() {
53 return fieldNames;
54 }
55
56 protected void computePosition()
57 {
58 computeGlobalX();
59 computeGlobalY();
60 computeGlobalZ();
61 }
62
63 private void computeGlobalX()
64 {
65 globalPosition[0] = (((double) getValue(xIndex)) + 0.5) * gridSizeX;
66 }
67
68 private void computeGlobalY()
69 {
70 globalPosition[1] = (((double) getValue(yIndex)) + 0.5) * gridSizeY;
71 }
72
73
74
75
76 private void computeGlobalZ()
77 {
78 Layering layers = getSubdetector().getLayering();
79 int sliceIdx = getValue("slice");
80 int layerIdx = getValue("layer");
81 Layer layer = layers.getLayer(layerIdx);
82
83 globalPosition[2] = layers.getDistanceToLayer(layerIdx) + layer.computeDistanceToSliceMid(sliceIdx);
84
85
86 if (getBarrelEndcapFlag() == BarrelEndcapFlag.ENDCAP_SOUTH)
87 {
88 globalPosition[2] = -globalPosition[2];
89 }
90 }
91
92 protected void setSegmentationValues(IExpandedIdentifier geomId, Hep3Vector positionVec)
93 {
94 geomId.setValue(xIndex, getXBin(positionVec.x()));
95 geomId.setValue(yIndex, getYBin(positionVec.y()));
96 }
97
98 protected void setupGeomFields(IDDescriptor id)
99 {
100 if (geomFields == null)
101 {
102 geomFields = new ArrayList<Integer>();
103
104 xIndex = id.indexOf("x");
105 yIndex = id.indexOf("y");
106 layerIndex = id.indexOf("layer");
107 try
108 {
109 sliceIndex = id.indexOf("slice");
110 }
111 catch (IllegalArgumentException x)
112 {
113 System.err.println("The slice field does not exist in this IDDecoder.");
114 sliceIndex = -1;
115 }
116
117
118 for (int i = 0; i < id.fieldCount(); i++)
119 {
120 String fname = id.fieldName(i);
121 if (!fname.equals("x") && !fname.equals("y"))
122 {
123 geomFields.add(i);
124 }
125 }
126 }
127 }
128
129 public long[] getNeighbourIDs(int layerRange, int xRange, int yRange)
130 {
131 return getNeighbourIDs(layerRange, xRange, yRange, xIndex, yIndex);
132 }
133
134 public int getXBin(double x)
135 {
136 return getBin(x, gridSizeX);
137 }
138
139 public int getYBin(double y)
140 {
141 return getBin(y, gridSizeY);
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 protected void computeLocalPosition()
168 {
169 }
170
171
172 public boolean boundsCheck(long rawId)
173 {
174 return false;
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239 }