1 package org.lcsim.geometry.compact;
2
3 import java.net.URL;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8 import java.util.Set;
9
10 import org.jdom.Element;
11 import org.lcsim.detector.IDetectorElement;
12 import org.lcsim.detector.IPhysicalVolume;
13 import org.lcsim.detector.IPhysicalVolumeNavigator;
14 import org.lcsim.detector.PhysicalVolumeNavigator;
15 import org.lcsim.geometry.Calorimeter;
16 import org.lcsim.material.MaterialManager;
17 import org.lcsim.material.XMLMaterialManager;
18
19 import Jama.Matrix;
20
21
22
23
24
25
26
27 public class Detector {
28
29 private Header header;
30 private Map<String, Constant> constants = new HashMap<String, Constant>();
31 private Map<String, Subdetector> subdetectors = new HashMap<String, Subdetector>();
32 private Map<String, Readout> readouts = new HashMap<String, Readout>();
33 private Map<String, Field> fields = new HashMap<String, Field>();
34 private Map<String, LimitSet> limits = new HashMap<String, LimitSet>();
35 private Map<String, Region> regions = new HashMap<String, Region>();
36 private Map<String, VisAttributes> display = new HashMap<String, VisAttributes>();
37 private Map<String, Matrix> matrices = new HashMap<String, Matrix>();
38 private XMLMaterialManager materialMgr;
39 private List<URL> gdmlReferences = new ArrayList<URL>();
40
41 private SystemIDMap idmap = new SystemIDMap();
42
43 private IPhysicalVolume worldVolume;
44 private IPhysicalVolume trackingVolume;
45 private IPhysicalVolumeNavigator navigator;
46
47 private IDetectorElement de;
48
49 String name;
50
51
52
53
54
55
56 protected Detector(Element element) {
57 if (element != null) {
58 name = element.getChild("info").getAttributeValue("name");
59 }
60 }
61
62 protected void setXMLMaterialManager(XMLMaterialManager xmat) {
63 materialMgr = xmat;
64 }
65
66 public String getName() {
67 return name;
68 }
69
70 public IPhysicalVolume getWorldVolume() {
71 return worldVolume;
72 }
73
74 public void setWorldVolume(IPhysicalVolume worldVolume) {
75 this.worldVolume = worldVolume;
76 navigator = new PhysicalVolumeNavigator("world", worldVolume);
77 trackingVolume = navigator.getPath("/tracking_region").getLeafVolume();
78 }
79
80 public IPhysicalVolume getTrackingVolume() {
81 return trackingVolume;
82 }
83
84 public IPhysicalVolumeNavigator getNavigator() {
85 return navigator;
86 }
87
88
89
90
91
92
93 protected void setHeader(Header header) {
94 this.header = header;
95 }
96
97
98
99
100
101
102 public Header getHeader() {
103 return header;
104 }
105
106
107
108
109
110
111 public String getDetectorName() {
112 return getHeader().getDetectorName();
113 }
114
115
116
117
118
119
120 protected void addConstant(Constant c) {
121 constants.put(c.getName(), c);
122 }
123
124
125
126
127
128
129 public Map<String, Constant> getConstants() {
130 return constants;
131 }
132
133
134
135
136
137
138 public void addMatrix(String name, Matrix matrix) {
139 this.matrices.put(name, matrix);
140 }
141
142
143
144
145
146
147 public Matrix getMatrix(String name) {
148 return this.matrices.get(name);
149 }
150
151
152
153
154
155 public Map<String, Matrix> getMatrices() {
156 return this.matrices;
157 }
158
159
160
161
162
163
164 protected void addReadout(Readout r) {
165
166 readouts.put(r.getName(), r);
167 }
168
169
170
171
172
173
174 public Map<String, Readout> getReadouts() {
175 return readouts;
176 }
177
178
179
180
181 public Readout getReadout(String rn) {
182 return readouts.get(rn);
183 }
184
185
186
187
188
189
190 protected void addSubdetector(Subdetector sub) {
191
192 if (subdetectors.get(sub.getName()) != null) {
193 throw new RuntimeException("The subdetector " + sub.getName() + " in detector " + this.getDetectorName() + " has the same name as another subdetector, which is not allowed.");
194 }
195 subdetectors.put(sub.getName(), sub);
196
197
198 if (sub.getSystemID() != 0 && idmap.get(sub.getSystemID()) != null) {
199 throw new RuntimeException("The subdetector " + sub.getName() + " in detector " + this.getDetectorName() + " duplicates the system ID " + sub.getSystemID() + " of the existing subdetector " + idmap.get(sub.getSystemID()).getName());
200 }
201
202 idmap.add(sub.getSystemID(), sub);
203 }
204
205
206
207
208
209
210 public Subdetector getSubdetector(int sysid) {
211 return idmap.get(sysid);
212 }
213
214
215
216
217
218
219 public Subdetector getSubdetector(String name) {
220 return subdetectors.get(name);
221 }
222
223
224
225
226
227
228 public Set<String> getSubdetectorNames() {
229 return getSubdetectors().keySet();
230 }
231
232
233
234
235
236
237 public Map<String, Subdetector> getSubdetectors() {
238 return subdetectors;
239 }
240
241 protected void addField(Field field) {
242 fields.put(field.getName(), field);
243 }
244
245 public Map<String, Field> getFields() {
246 return fields;
247 }
248
249 public final XMLMaterialManager getXMLMaterialManager() {
250 return materialMgr;
251 }
252
253 public MaterialManager getMaterialManager() {
254 return MaterialManager.instance();
255 }
256
257 public void addLimitSet(LimitSet limitset) {
258 limits.put(limitset.getName(), limitset);
259 }
260
261 public LimitSet getLimitSet(String name) {
262 return limits.get(name);
263 }
264
265 public Map<String, LimitSet> getLimits() {
266 return limits;
267 }
268
269 public void addRegion(Region region) {
270 regions.put(region.getName(), region);
271 }
272
273 public Region getRegion(String name) {
274 return regions.get(name);
275 }
276
277 public Map<String, Region> getRegions() {
278 return regions;
279 }
280
281 public void addVisAttributes(VisAttributes vis) {
282 display.put(vis.getName(), vis);
283 }
284
285 public Map<String, VisAttributes> getVisAttributes() {
286 return display;
287 }
288
289 public IDetectorElement getDetectorElement() {
290 return de;
291 }
292
293 public void setDetectorElement(IDetectorElement de) {
294 this.de = de;
295 }
296
297 public void addGDMLReference(URL url) {
298 gdmlReferences.add(url);
299 }
300
301 public List<URL> getGDMLReferences() {
302 return gdmlReferences;
303 }
304
305 public Calorimeter getCalorimeterByType(Calorimeter.CalorimeterType calType) {
306 for (Subdetector subdet : this.subdetectors.values()) {
307 if (subdet.isCalorimeter()) {
308 Calorimeter cal = (Calorimeter) subdet;
309 if (cal.getCalorimeterType() == calType)
310 return (Calorimeter) subdet;
311 }
312 }
313 return null;
314 }
315
316 public List<Subdetector> getSubdetectorList() {
317 return new ArrayList<Subdetector>(getSubdetectors().values());
318 }
319 }