1 package org.lcsim.geometry.compact;
2
3 import java.awt.Color;
4
5 import org.jdom.Attribute;
6 import org.jdom.Element;
7 import org.jdom.JDOMException;
8 import org.lcsim.detector.IDetectorElement;
9 import org.lcsim.geometry.IDDecoder;
10 import org.lcsim.geometry.layer.Layering;
11
12
13
14
15
16
17
18
19
20
21 public class Subdetector implements org.lcsim.geometry.Subdetector
22 {
23
24
25
26 private boolean reflect = true;
27
28 private Readout readout;
29 private String name;
30 private int systemID;
31
32 private VisAttributes vis;
33 private Element node;
34 private IDetectorElement de;
35 private boolean insideTrackingVolume = false;
36 String digiCollectionName = null;
37
38 protected Subdetector(Element element) throws JDOMException
39 {
40
41 node = element;
42
43
44 name = element.getAttributeValue("name");
45
46
47 Attribute r = element.getAttribute("reflect");
48 reflect = r != null && r.getBooleanValue();
49
50
51 systemID = element.getAttribute("id").getIntValue();
52
53
54 Attribute insideAttrib = node.getAttribute("insideTrackingVolume");
55 try
56 {
57 if (insideAttrib == null)
58 {
59 if (isTracker())
60 {
61 insideTrackingVolume = true;
62 }
63 else
64 {
65 insideTrackingVolume = false;
66 }
67 } else
68 {
69 insideTrackingVolume = insideAttrib.getBooleanValue();
70 }
71 }
72 catch (org.jdom.DataConversionException dce)
73 {
74 throw new RuntimeException("Error converting insideTrackingVolume attribute.", dce);
75 }
76
77
78 digiCollectionName = this.getName().replace("Hits","DigiHits");
79 }
80
81 protected void setReadout(Readout r)
82 {
83
84 if (systemID == 0)
85 throw new RuntimeException("The detector " + getName() + " cannot have a readout" + " because it does not have a valid system id.");
86 this.readout = r;
87 }
88
89
90
91
92
93
94 public Readout getReadout()
95 {
96 return readout;
97 }
98
99
100
101
102
103
104
105
106
107
108
109
110
111 public IDDecoder getIDDecoder()
112 {
113 return getReadout().getIDDecoder();
114 }
115
116 public String getName()
117 {
118 return name;
119 }
120
121 public int getSystemID()
122 {
123 return (systemID);
124 }
125
126 public boolean isBarrel()
127 {
128 return false;
129 }
130
131 public boolean isEndcap()
132 {
133 return false;
134 }
135
136 public boolean isCalorimeter()
137 {
138 return false;
139 }
140
141 public boolean isTracker()
142 {
143 return false;
144 }
145
146 public boolean isLayered()
147 {
148 return false;
149 }
150
151 public double[] transformLocalToGlobal(double[] locPos)
152 {
153 return locPos;
154 }
155
156 public boolean getReflect()
157 {
158 return reflect;
159 }
160
161 public Layering getLayering()
162 {
163 throw new RuntimeException("layers not implemented");
164 }
165
166 public void setVisAttributes(VisAttributes vis)
167 {
168 this.vis = vis;
169 }
170
171 public VisAttributes getVisAttributes()
172 {
173
174 if ( vis == null )
175 {
176 vis = new VisAttributes( getName() + "_vis" );
177
178
179 vis.setColor( Color.WHITE );
180 }
181 return vis;
182 }
183
184 public Element getNode()
185 {
186 return node;
187 }
188
189 public IDetectorElement getDetectorElement()
190 {
191 return de;
192 }
193
194 public void setDetectorElement(IDetectorElement de)
195 {
196 this.de = de;
197 }
198
199 public boolean isInsideTrackingVolume()
200 {
201 return insideTrackingVolume;
202 }
203
204 public String getHitsCollectionName()
205 {
206 return getReadout().getName();
207 }
208
209
210
211
212
213
214 public void setDigiHitsCollectionName(String digiCollectionName)
215 {
216 this.digiCollectionName = digiCollectionName;
217 }
218
219
220
221
222
223 public String getDigiHitsCollectionName()
224 {
225 return digiCollectionName;
226 }
227 }