1 package org.lcsim.geometry;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6
7 import org.lcsim.geometry.compact.Header;
8 import org.lcsim.geometry.compact.Segmentation;
9 import org.lcsim.geometry.layer.Layer;
10 import org.lcsim.geometry.layer.LayerSlice;
11 import org.lcsim.geometry.layer.Layering;
12 import org.lcsim.util.test.OneTimeDetectorSetup;
13
14
15
16
17
18
19
20
21 public class GeometryReaderTest extends TestCase
22 {
23 static final String detName = "GeometryReaderTest";
24 static final String detLoc = detName + ".xml";
25
26
27 Detector detector;
28
29 static final int nDetectors = 10;
30 static final int nConstants = 10;
31
32 static final int nTrackerLayers = 5;
33 static final int nTrackerEndcapLayers = 10;
34 static final int nFields = 1;
35
36 static final int nEMLayers = 30;
37 static final double EMThick = 150.0;
38 static final int nEMSlices = 5;
39
40 static final double EMBarrelir = 1270.0;
41 static final double EMBarreloz = 1840.0;
42 static final double EMBarrelor = EMBarrelir + EMThick;
43
44 static final double EMEndcapir = 200.0;
45 static final double EMEndcapiz = 1680.0;
46 static final double EMEndcapor = 1250.0;
47 static final double EMEndcapoz = EMEndcapiz + EMThick;
48
49 int nHADLayers = 34;
50 int nMuonLayers = 32;
51
52 double tol = 0.0001;
53
54 public static Test suite()
55 {
56 TestSuite ts = new TestSuite();
57 ts.addTestSuite(GeometryReaderTest.class);
58 return new OneTimeDetectorSetup(ts, detLoc);
59 }
60
61 public GeometryReaderTest(String testName)
62 {
63 super(testName);
64 }
65
66 protected void setUp()
67 {
68 if (detector == null)
69 detector = OneTimeDetectorSetup.getDetector();
70 }
71
72 public void testHeader()
73 {
74 Header hdr = detector.getHeader();
75 assertTrue (hdr.getDetectorName().equals("GeometryReaderTest"));
76
77 assertTrue (hdr.getComment().equals("Test of org.lcsim.geometry.GeometryReader"));
78
79
80 }
81
82 public void testCollSizes()
83 {
84 assertEquals(nDetectors, detector.getSubdetectors().size());
85 assertEquals(nDetectors, detector.getReadouts().size());
86 assertEquals(nConstants, detector.getConstants().size());
87 assertEquals(nFields, detector.getFields().size());
88 }
89
90 public void testLayers()
91 {
92 assertEquals(detName, detector.getName());
93
94 org.lcsim.geometry.Subdetector subdetector = null;
95
96 for (String sn : detector.getSubdetectorNames())
97 {
98 subdetector = detector.getSubdetector(sn);
99 assertTrue (sn != null);
100
101 Layering layers = ((Layered) subdetector).getLayering();
102 assertTrue (layers != null);
103
104
105
106 int nLayers = -1;
107 int nSlices = -1;
108
109 if (sn.equals("BarrelVertex") || sn.equals("BarrelTracker") || sn.equals("EndcapVertex"))
110 {
111 nLayers = nTrackerLayers;
112 }
113
114 if (sn.equals("EndcapTracker"))
115 {
116 nLayers = nTrackerEndcapLayers;
117 }
118
119 if (sn.equals("EMBarrel") || sn.equals("EMEndcap"))
120 {
121 nLayers = nEMLayers;
122 nSlices = nEMSlices;
123 }
124
125 if (sn.equals("HADBarrel") || sn.equals("HADEndcap"))
126 {
127 nLayers = nHADLayers;
128 }
129
130 if (sn.equals("MuonBarrel") || sn.equals("MuonEndcap"))
131 {
132 nLayers = nMuonLayers;
133 }
134
135
136 if (nLayers != -1)
137 {
138 boolean sensitive=false;
139
140
141 assertEquals(layers.getLayerCount(), nLayers);
142
143 for (int i = 0; i < nLayers; i++)
144 {
145
146 assert (layers.getLayerStack().getLayer(i) != null);
147
148
149 if (nSlices != -1)
150 {
151 assert (layers.getLayerStack().getLayer(i).getSlices().size() == nSlices);
152 }
153
154
155 boolean gotLayers = false;
156
157 for (LayerSlice slice : layers.getLayerStack().getLayer(i).getSlices())
158 {
159 assertTrue (slice != null);
160 assertTrue (slice.getMaterial() != null);
161 assertTrue (slice.getThickness() >= 0);
162 gotLayers = true;
163 if ( slice.isSensitive() )
164 {
165 sensitive=true;
166 }
167 }
168
169
170 assertTrue( gotLayers );
171 }
172
173
174
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 if (subdetector.isCalorimeter())
200 {
201
202
203
204
205 Segmentation seg = (Segmentation) subdetector.getIDDecoder();
206
207 assertTrue (seg != null);
208 }
209 }
210 }
211 }
212
213 public void testAttributes()
214 {
215 for (String sn : detector.getSubdetectorNames())
216 {
217 Subdetector subdetector = detector.getSubdetector(sn);
218
219 if (sn.equals("EMBarrel") || sn.equals("EMEndcap"))
220 {
221 double totThick = ((Layered) subdetector).getLayering().getLayerStack().getTotalThickness();
222
223
224 assertEquals(totThick, EMThick, tol);
225
226 CylindricalSubdetector cyl = (CylindricalSubdetector) subdetector;
227 assertTrue (cyl != null);
228
229
230 if (sn.equals("EMBarrel"))
231 {
232 assertEquals(cyl.getInnerRadius(), EMBarrelir, tol);
233 assertEquals(cyl.getZMax(), EMBarreloz, tol);
234 assertEquals(cyl.getZMin(), -EMBarreloz, tol);
235 assertEquals(cyl.getOuterRadius(), EMBarrelor, tol);
236 }
237
238 else if (sn.equals("EMEndcap"))
239 {
240 assertEquals(cyl.getInnerRadius(), EMEndcapir, tol);
241 assertEquals(cyl.getZMin(), EMEndcapiz, tol);
242 assertEquals(cyl.getOuterRadius(), EMEndcapor, tol);
243 assertEquals(cyl.getZMax(), EMEndcapoz, tol);
244 }
245
246
247
248
249
250 double compThick = 0;
251 int lnum = 0;
252 int nlay = ((Layered) subdetector).getLayering().getLayerStack().getNumberOfLayers();
253 for (int i = 0; i < nlay; i++)
254 {
255 Layer l = ((Layered) subdetector).getLayering().getLayerStack().getLayer(i);
256
257 assertTrue (l != null);
258
259 for (LayerSlice sl : l.getSlices())
260 {
261 compThick += sl.getThickness();
262 }
263 }
264
265 assertTrue (compThick == totThick);
266 }
267 }
268 }
269 }