View Javadoc

1   package org.lcsim.detector.converter.compact;
2   
3   import java.util.ArrayList;
4   import java.util.Iterator;
5   import java.util.List;
6   
7   import org.jdom.DataConversionException;
8   import org.jdom.Element;
9   import org.lcsim.detector.DetectorElement;
10  import org.lcsim.detector.DetectorFactory;
11  import org.lcsim.detector.ILogicalVolume;
12  import org.lcsim.detector.IPhysicalVolume;
13  import org.lcsim.detector.LogicalVolume;
14  import org.lcsim.detector.DetectorIdentifierHelper.SystemMap;
15  import org.lcsim.detector.identifier.IIdentifierHelper;
16  import org.lcsim.detector.material.IMaterial;
17  import org.lcsim.detector.material.MaterialStore;
18  import org.lcsim.detector.solids.Polycone;
19  import org.lcsim.detector.solids.Polycone.ZPlane;
20  import org.lcsim.geometry.compact.Detector;
21  import org.lcsim.geometry.compact.Subdetector;
22  import org.lcsim.geometry.subdetector.PolyconeSupport;
23  
24  /**
25   * Convert a {@link org.lcsim.geometry.subdetector.PolyconeSupport} to the
26   * {@link org.lcsim.detector} detailed detector representation.
27   * 
28   * @author Jeremy McCormick <jeremym@slac.stanford.edu>
29   * @version $Id: PolyconeSupportConverter.java,v 1.4 2011/02/09 01:28:15 jeremy Exp $
30   */
31  
32  public class PolyconeSupportConverter extends AbstractSubdetectorConverter implements ISubdetectorConverter
33  {
34      /**
35       * This type is only used for dead material and has no IdentifierHelper.
36       */
37      public IIdentifierHelper makeIdentifierHelper( Subdetector subdetector, SystemMap systemMap )
38      {
39          return null;
40      }
41  
42      public void convert( Subdetector subdet, Detector detector )
43      {        
44          List< ZPlane > zplanes = new ArrayList< ZPlane >();
45          Element node = subdet.getNode();
46          for ( Iterator i = node.getChildren( "zplane" ).iterator(); i.hasNext(); )
47          {
48              try
49              {
50                  Element zplane = ( Element ) i.next();
51                  zplanes.add( new ZPlane( zplane.getAttribute( "rmin" ).getDoubleValue(), zplane.getAttribute( "rmax" )
52                          .getDoubleValue(), zplane.getAttribute( "z" ).getDoubleValue() ) );
53              }
54              catch ( DataConversionException dce )
55              {
56                  throw new RuntimeException( "bad values for zplane from the xml file", dce );
57              }
58          }
59  
60          Polycone polycone = new Polycone( subdet.getName(), zplanes );
61  
62          IMaterial material = MaterialStore.getInstance().get( node.getChild( "material" ).getAttributeValue( "name" ) );
63  
64          ILogicalVolume lvPolycone = new LogicalVolume( subdet.getName(), polycone, material );
65  
66          IPhysicalVolume mom = null;
67          String path = "/";
68          if ( subdet.isInsideTrackingVolume() )
69          {
70              mom = detector.getTrackingVolume();
71              path = mom.getName() + "/";
72          }
73          else
74          {
75              mom = detector.getWorldVolume();
76          } 
77  
78          IPhysicalVolume pv = DetectorFactory.getInstance().createPhysicalVolume(
79                  null,
80                  subdet.getName(),
81                  lvPolycone,
82                  mom.getLogicalVolume(),
83                  0 );
84          
85          path += pv.getName();
86          
87          //System.out.println("making PolyconeSupport DE with path: " + path);
88                                 
89          new DetectorElement(subdet.getName() + "_placement", subdet.getDetectorElement(), path);
90      }
91  
92      public Class getSubdetectorType()
93      {
94          return PolyconeSupport.class;
95      }
96  }