1 package org.lcsim.geometry.compact.converter.lcdd;
2
3 import java.util.Iterator;
4 import org.jdom.Attribute;
5 import org.jdom.Element;
6 import org.jdom.JDOMException;
7 import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
8 import org.lcsim.geometry.compact.converter.lcdd.util.Material;
9 import org.lcsim.geometry.compact.converter.lcdd.util.PhysVol;
10 import org.lcsim.geometry.compact.converter.lcdd.util.Rotation;
11 import org.lcsim.geometry.compact.converter.lcdd.util.SensitiveDetector;
12 import org.lcsim.geometry.compact.converter.lcdd.util.Solids;
13 import org.lcsim.geometry.compact.converter.lcdd.util.Structure;
14 import org.lcsim.geometry.compact.converter.lcdd.util.Tube;
15 import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
16
17
18
19
20
21 class CylindricalEndcapCalorimeter extends LCDDSubdetector
22 {
23 CylindricalEndcapCalorimeter(Element node) throws JDOMException
24 {
25 super(node);
26 }
27
28 public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
29 {
30 int id = node.getAttribute("id").getIntValue();
31 String detectorName = node.getAttributeValue("name");
32 boolean reflect = node.getAttribute("reflect").getBooleanValue();
33
34 Material air = lcdd.getMaterial("Air");
35 Rotation reflection = lcdd.getDefine().getRotation("reflect_rot");
36 Solids solids = lcdd.getSolids();
37 Structure structure = lcdd.getStructure();
38 Volume motherVolume = lcdd.pickMotherVolume(this);
39
40 Element dimensions = node.getChild("dimensions");
41 double zmin = dimensions.getAttribute("inner_z").getDoubleValue();
42 double rmin = dimensions.getAttribute("inner_r").getDoubleValue();
43 double rmax = dimensions.getAttribute("outer_r").getDoubleValue();
44
45 double totWidth = layers.getLayerStack().getTotalThickness();
46
47 double z = zmin;
48
49 Tube envelope = new Tube(detectorName+"_envelope");
50 solids.addSolid(envelope);
51 Volume envelopeVolume = new Volume(detectorName+"_envelope_volume");
52 envelopeVolume.setMaterial(air);
53 envelopeVolume.setSolid(envelope);
54
55 int n = 0;
56 for (Iterator i = node.getChildren("layer").iterator(); i.hasNext();)
57 {
58 Element layer = (Element) i.next();
59 int repeat = (int)layer.getAttribute("repeat").getDoubleValue();
60
61 double layerWidth = 0;
62 for (Iterator j = layer.getChildren("slice").iterator(); j.hasNext();)
63 {
64 Element slice = (Element) j.next();
65 double w = slice.getAttribute("thickness").getDoubleValue();
66 layerWidth += w;
67 }
68
69 for (int ll=0; ll<repeat; ll++)
70 {
71 double zlayer = z;
72 String layerName = detectorName+"_layer"+n;
73 Tube layerTube = new Tube(layerName);
74 Volume layerVolume = new Volume(layerName+"_volume");
75 layerVolume.setMaterial(air);
76 layerVolume.setSolid(layerTube);
77
78 int m = 0;
79 for (Iterator j = layer.getChildren("slice").iterator(); j.hasNext(); m++)
80 {
81 Element slice = (Element) j.next();
82 double w = slice.getAttribute("thickness").getDoubleValue();
83 Attribute s = slice.getAttribute("sensitive");
84 boolean sensitive = s != null && s.getBooleanValue();
85
86 String name = detectorName+"_layer"+n+"_slice"+m;
87 Tube tube = new Tube(name);
88 tube.setZ(w);
89 tube.setRMin(rmin);
90 tube.setRMax(rmax);
91 tube.setDeltaPhi(Math.PI*2);
92 solids.addSolid(tube);
93
94 Volume sliceVolume = new Volume(name+"_volume");
95 sliceVolume.setMaterial(lcdd.getMaterial(slice.getAttributeValue("material")));
96 sliceVolume.setSolid(tube);
97 if (sensitive) sliceVolume.setSensitiveDetector(sens);
98
99 setRegion(lcdd, slice, sliceVolume);
100 setLimitSet(lcdd, slice, sliceVolume);
101 setVisAttributes(lcdd, slice, sliceVolume);
102
103 structure.addVolume(sliceVolume);
104
105 PhysVol physvol = new PhysVol(sliceVolume);
106 physvol.setZ(z - zlayer - layerWidth/2 + w/2);
107 layerVolume.addPhysVol(physvol);
108
109 z += w;
110 }
111
112 setVisAttributes(lcdd, layer, layerVolume);
113
114 layerTube.setZ(layerWidth);
115 layerTube.setRMin(rmin);
116 layerTube.setRMax(rmax);
117 layerTube.setDeltaPhi(Math.PI*2);
118
119 PhysVol physvol = new PhysVol(layerVolume);
120 physvol.setZ(zlayer - zmin - totWidth/2 + layerWidth/2);
121 physvol.addPhysVolID("layer",n);
122 envelopeVolume.addPhysVol(physvol);
123 structure.addVolume(layerVolume);
124 solids.addSolid(layerTube);
125 n++;
126 }
127 }
128
129 envelope.setZ(totWidth);
130 envelope.setRMin(rmin);
131 envelope.setRMax(rmax);
132 envelope.setDeltaPhi(Math.PI*2);
133
134 PhysVol physvol = new PhysVol(envelopeVolume);
135 physvol.setZ(zmin+totWidth/2);
136 physvol.addPhysVolID("system",id);
137 physvol.addPhysVolID("barrel",1);
138 motherVolume.addPhysVol(physvol);
139
140 if (reflect)
141 {
142 PhysVol physvol2 = new PhysVol(envelopeVolume);
143 physvol2.setZ(-zmin-totWidth/2);
144 physvol2.setRotation(reflection);
145 physvol2.addPhysVolID("system",id);
146 physvol2.addPhysVolID("barrel",2);
147 motherVolume.addPhysVol(physvol2);
148 }
149
150
151 setAttributes(lcdd, node, envelopeVolume);
152
153 structure.addVolume(envelopeVolume);
154 }
155
156 public boolean isCalorimeter()
157 {
158 return true;
159 }
160 }