View Javadoc

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   * Class for converting a compact detector element of type
19   * CylindricalBarrelCalorimeter to the LCDD format.
20   *
21   * @author tonyj
22   * @version $id: $
23   */
24  class CylindricalBarrelCalorimeter extends LCDDSubdetector
25  {
26      CylindricalBarrelCalorimeter(Element node) throws JDOMException
27      {
28          super(node);
29      }
30      
31      public void addToLCDD(LCDD lcdd, SensitiveDetector sens) throws JDOMException
32      {
33          String detectorName = node.getAttributeValue("name");
34          int id = node.getAttribute("id").getIntValue();
35          
36          Material air = lcdd.getMaterial("Air");
37          Solids solids = lcdd.getSolids();
38          Structure structure = lcdd.getStructure();
39          Volume motherVolume = lcdd.pickMotherVolume(this);
40          
41          Element dimensions = node.getChild("dimensions");
42          double z = dimensions.getAttribute("outer_z").getDoubleValue();
43          double rmin = dimensions.getAttribute("inner_r").getDoubleValue();
44          double r = rmin;
45          
46          Tube envelope = new Tube(detectorName+"_envelope");
47          Volume envelopeVolume = new Volume(detectorName+"_envelope_volume");
48          envelopeVolume.setMaterial(air);
49          envelopeVolume.setSolid(envelope);
50                  
51          int n = 0;
52          for (Iterator i = node.getChildren("layer").iterator(); i.hasNext();)
53          {
54              Element layer = (Element) i.next();
55              int repeat = (int)layer.getAttribute("repeat").getDoubleValue();
56              for (int ll=0; ll<repeat; ll++)
57              {
58                  double rlayer = r;
59                  
60                  String name1 = detectorName+"_layer"+n;
61                  Tube tube1 = new Tube(name1);
62                  Volume volume1 = new Volume(name1+"_volume");
63                  volume1.setMaterial(air);
64                  volume1.setSolid(tube1);                               
65                  
66                  int m = 0;
67                  for (Iterator j = layer.getChildren("slice").iterator(); j.hasNext(); m++)
68                  {
69                      Element slice = (Element) j.next();
70                      double w = slice.getAttribute("thickness").getDoubleValue();
71                      Attribute s = slice.getAttribute("sensitive");
72                      boolean sensitive = s != null && s.getBooleanValue();
73                      
74                      String name = detectorName+"_layer"+n+"_slice"+m;
75                      Tube tube = new Tube(name);
76                      tube.setZ(2 * z);
77                      tube.setRMin(r);
78                      r += w;
79                      tube.setRMax(r);
80                      tube.setDeltaPhi(2*Math.PI);
81                      solids.addSolid(tube);
82                      
83                      Volume volume = new Volume(name+"_volume");
84                      volume.setMaterial(lcdd.getMaterial(slice.getAttributeValue("material")));
85                      volume.setSolid(tube);
86                      if (sensitive) volume.setSensitiveDetector(sens);                    
87                      
88                      setAttributes(lcdd, slice, volume);
89                      
90                      structure.addVolume(volume);
91                      volume1.addPhysVol(new PhysVol(volume));                    
92                  }
93                  
94                  setVisAttributes(lcdd, node, volume1);
95                  
96                  tube1.setZ(2*z);
97                  tube1.setRMin(rlayer);
98                  tube1.setRMax(r);
99                  tube1.setDeltaPhi(2*Math.PI);
100                 
101                 PhysVol physvol = new PhysVol(volume1);
102                 physvol.addPhysVolID("layer",n);
103                 envelopeVolume.addPhysVol(physvol);
104                 structure.addVolume(volume1);
105                 solids.addSolid(tube1);
106                 n++;                                
107             }
108         }
109         
110         envelope.setZ(2*z);
111         envelope.setRMin(rmin);
112         envelope.setRMax(r);
113         envelope.setDeltaPhi(Math.PI*2);
114         PhysVol physvol = new PhysVol(envelopeVolume);
115         physvol.addPhysVolID("system",id);
116         physvol.addPhysVolID("barrel",0);
117         motherVolume.addPhysVol(physvol);
118         
119         solids.addSolid(envelope);
120         
121         // Set envelope volume attributes.
122         setAttributes(lcdd, node, envelopeVolume);
123         
124         structure.addVolume(envelopeVolume);                       
125     }
126     
127     public boolean isCalorimeter()
128     {
129         return true;
130     }
131 }