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.SensitiveDetector;
11 import org.lcsim.geometry.compact.converter.lcdd.util.Solids;
12 import org.lcsim.geometry.compact.converter.lcdd.util.Structure;
13 import org.lcsim.geometry.compact.converter.lcdd.util.Tube;
14 import org.lcsim.geometry.compact.converter.lcdd.util.Volume;
15
16
17
18
19
20 class TPC extends LCDDSubdetector
21 {
22 TPC(Element node) throws JDOMException
23 {
24 super(node);
25 }
26
27 public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
28 {
29 sens.setAttribute("combine_hits","true");
30
31 String detectorName = node.getAttributeValue("name");
32 int id = node.getAttribute("id").getIntValue();
33
34 Material air = lcdd.getMaterial("Air");
35 Solids solids = lcdd.getSolids();
36 Structure structure = lcdd.getStructure();
37 Volume motherVolume = lcdd.pickMotherVolume(this);
38
39 Element dimensions = node.getChild("dimensions");
40 double z = dimensions.getAttribute("outer_z").getDoubleValue();
41 double rmin = dimensions.getAttribute("inner_r").getDoubleValue();
42 double r = rmin;
43
44
45 double zpos = 0;
46 Element position = node.getChild("position");
47 if (position != null)
48 {
49 if (position.getAttribute("z") != null)
50 {
51 zpos = position.getAttribute("z").getDoubleValue();
52 }
53 }
54
55 Tube envelope = new Tube(detectorName+"_envelope");
56 Volume envelopeVolume = new Volume(detectorName+"_envelope_volume");
57 envelopeVolume.setMaterial(air);
58 envelopeVolume.setSolid(envelope);
59
60 int n = 0;
61 for (Iterator i = node.getChildren("layer").iterator(); i.hasNext();)
62 {
63 int repeat = 1;
64 Element layer = (Element) i.next();
65 if (layer.getAttribute("repeat") != null) {
66 repeat = (int) Math.round(layer.getAttribute("repeat").getDoubleValue());
67 }
68 for (int ll=0; ll<repeat; ll++)
69 {
70 double rlayer = r;
71
72 String name1 = detectorName+"_layer"+n;
73 Tube tube1 = new Tube(name1);
74 Volume volume1 = new Volume(name1+"_volume");
75 volume1.setMaterial(air);
76 volume1.setSolid(tube1);
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(2 * z);
89 tube.setRMin(r);
90 r += w;
91 tube.setRMax(r);
92 tube.setDeltaPhi(2*Math.PI);
93 solids.addSolid(tube);
94
95 Volume volume = new Volume(name+"_volume");
96 volume.setMaterial(lcdd.getMaterial(slice.getAttributeValue("material")));
97 volume.setSolid(tube);
98 if (sensitive) volume.setSensitiveDetector(sens);
99
100
101 setLimitSet(lcdd, slice, volume);
102 setRegion(lcdd, slice, volume);
103
104 setVisAttributes(lcdd, node, volume);
105 structure.addVolume(volume);
106 volume1.addPhysVol(new PhysVol(volume));
107 }
108
109 tube1.setZ(2*z);
110 tube1.setRMin(rlayer);
111 tube1.setRMax(r);
112 tube1.setDeltaPhi(2*Math.PI);
113
114 PhysVol physvol = new PhysVol(volume1);
115 physvol.addPhysVolID("layer",n);
116 envelopeVolume.addPhysVol(physvol);
117 setVisAttributes(lcdd, node, volume1);
118 structure.addVolume(volume1);
119 solids.addSolid(tube1);
120 n++;
121 }
122 }
123
124 envelope.setZ(2*z);
125 envelope.setRMin(rmin);
126 envelope.setRMax(r);
127 envelope.setDeltaPhi(Math.PI*2);
128 PhysVol physvol = new PhysVol(envelopeVolume);
129 physvol.setZ(zpos);
130 physvol.addPhysVolID("system",id);
131 physvol.addPhysVolID("barrel",0);
132 motherVolume.addPhysVol(physvol);
133
134 solids.addSolid(envelope);
135 setVisAttributes(lcdd, node, envelopeVolume);
136 structure.addVolume(envelopeVolume);
137
138 setCombineHits(node, sens);
139 }
140
141 public boolean isTracker()
142 {
143 return true;
144 }
145 }