Commit in GeomConverter on MAIN
resources/org/lcsim/schemas/compact/1.0/compact.xsd+21-61.8 -> 1.9
src/org/lcsim/geometry/compact/CompactReader.java+45-131.48 -> 1.49
                              /Detector.java+30-11.33 -> 1.34
src/org/lcsim/geometry/compact/converter/lcdd/LCDDDetector.java+251.27 -> 1.28
                                             /Main.java+42-571.22 -> 1.23
src/org/lcsim/geometry/compact/converter/lcdd/util/Matrix.java+25added 1.1
                                                  /Define.java+19-161.3 -> 1.4
                                                  /LCDD.java+41.31 -> 1.32
testResources/org/lcsim/geometry/subdetector/OpticalCalorimeterTest.xml+96added 1.1
+307-93
2 added + 7 modified, total 9 files
add basic support for including optical properties matrix in compact description and generated LCDD files

GeomConverter/resources/org/lcsim/schemas/compact/1.0
compact.xsd 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- compact.xsd	11 Dec 2012 21:59:45 -0000	1.8
+++ compact.xsd	24 Apr 2013 02:00:35 -0000	1.9
@@ -31,12 +31,21 @@
     <xs:element name="define">
         <xs:complexType>
             <xs:sequence>
-                <xs:element name="constant" minOccurs="0" maxOccurs="unbounded">
-                    <xs:complexType>
-                        <xs:attribute name="name" type="xs:string" use="required"/>
-                        <xs:attribute name="value" type="xs:string" use="required"/>
-                    </xs:complexType>
-                </xs:element>
+                <xs:choice maxOccurs="unbounded">
+                    <xs:element name="constant" minOccurs="0" maxOccurs="unbounded">
+                        <xs:complexType>
+                            <xs:attribute name="name" type="xs:string" use="required"/>
+                            <xs:attribute name="value" type="xs:string" use="required"/>
+                        </xs:complexType>                    
+                    </xs:element>
+                    <xs:element name="matrix" minOccurs="0" maxOccurs="unbounded">
+                        <xs:complexType>
+                            <xs:attribute name="name" type="xs:string" use="required" />
+                            <xs:attribute name="coldim" type="xs:integer" use="required" />
+                            <xs:attribute name="values" type="xs:string" use="required" />
+                        </xs:complexType>
+                    </xs:element>
+                </xs:choice>
             </xs:sequence>
         </xs:complexType>
     </xs:element>
@@ -96,6 +105,12 @@
                 <xs:element name="material" minOccurs="0" maxOccurs="unbounded">
                     <xs:complexType>
                         <xs:sequence>
+                            <xs:element name="property" minOccurs="0" maxOccurs="1">
+                                <xs:complexType>
+                                    <xs:attribute name="name" type="xs:string" use="required" />
+                                    <xs:attribute name="ref" type="xs:string" use="required" />
+                                </xs:complexType>
+                            </xs:element>                            
                             <xs:element name="D" minOccurs="1" maxOccurs="1">
                                 <xs:complexType>
                                     <xs:attribute name="type" type="xs:string" default="density"/>

GeomConverter/src/org/lcsim/geometry/compact
CompactReader.java 1.48 -> 1.49
diff -u -r1.48 -r1.49
--- CompactReader.java	11 Dec 2012 21:59:45 -0000	1.48
+++ CompactReader.java	24 Apr 2013 02:00:35 -0000	1.49
@@ -5,10 +5,13 @@
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Scanner;
 
 import org.jdom.Document;
 import org.jdom.Element;
@@ -22,6 +25,8 @@
 import org.lcsim.util.xml.ElementFactory.ElementCreationException;
 import org.lcsim.util.xml.JDOMExpressionFactory;
 
+import Jama.Matrix;
+
 /**
  * A tool for reading xml files containing compact detector descriptions.
  * 
@@ -30,7 +35,7 @@
  * which extends this.
  * 
  * @author tonyj
- * @version $Id: CompactReader.java,v 1.48 2012/12/11 21:59:45 jeremy Exp $
+ * @version $Id: CompactReader.java,v 1.49 2013/04/24 02:00:35 jeremy Exp $
  * 
  */
 public class CompactReader {
@@ -83,19 +88,20 @@
 
         doc = builder.build(in);
 
-        Element lccdd = doc.getRootElement();
-        Detector det = factory.createElement(Detector.class, lccdd, null);
+        Element compact = doc.getRootElement();
+        Detector det = factory.createElement(Detector.class, compact, null);
 
-        readHeader(lccdd, det);
-        readConstants(lccdd, det);
-        readRegions(lccdd, det);
-        readLimits(lccdd, det);
-        readMaterials(lccdd, det);
-        Map<String, Readout> readoutMap = readReadouts(lccdd, det);
-        readVisAttributes(lccdd, det);
-        readSubdetectors(lccdd, det, readoutMap);
-        readFields(lccdd, det);
-        readIncludes(lccdd, det);
+        readHeader(compact, det);
+        readConstants(compact, det);
+        readMatrices(compact, det);
+        readRegions(compact, det);
+        readLimits(compact, det);
+        readMaterials(compact, det);
+        Map<String, Readout> readoutMap = readReadouts(compact, det);
+        readVisAttributes(compact, det);
+        readSubdetectors(compact, det, readoutMap);
+        readFields(compact, det);
+        readIncludes(compact, det);
 
         return det;
     }
@@ -109,6 +115,32 @@
             det.addConstant(c);
         }
     }
+    
+    private void readMatrices(Element compact, Detector det) {
+        Element define = compact.getChild("define");
+        for (Iterator iterator = define.getChildren("matrix").iterator(); iterator.hasNext();) {
+            Element element = (Element)iterator.next();
+            String name = element.getAttributeValue("name");
+            int coldim = Integer.parseInt(element.getAttributeValue("coldim"));
+            String rawValues = element.getAttributeValue("values");
+            Scanner scanner = new Scanner(rawValues);
+            List<double[]> rows = new ArrayList<double[]>();
+            while (scanner.hasNextDouble()) {
+                double[] row = new double[coldim];
+                for (int i=0; i<coldim; i++) {
+                    double value = scanner.nextDouble();
+                    row[i] = value;
+                }
+                rows.add(row);
+            }
+            double[][] array = new double[rows.size()][coldim];
+            for (int i=0, n=rows.size(); i<n; i++) {
+                array[i] = rows.get(i);
+            }
+            Matrix matrix = new Matrix(array);
+            det.addMatrix(name, matrix);            
+        }
+    }
 
     private void readHeader(Element lccdd, Detector det) throws JDOMException, ElementCreationException {
         Element info = lccdd.getChild("info");

GeomConverter/src/org/lcsim/geometry/compact
Detector.java 1.33 -> 1.34
diff -u -r1.33 -r1.34
--- Detector.java	24 Jan 2013 22:27:16 -0000	1.33
+++ Detector.java	24 Apr 2013 02:00:35 -0000	1.34
@@ -13,8 +13,10 @@
 import org.lcsim.detector.IPhysicalVolumeNavigator;
 import org.lcsim.detector.PhysicalVolumeNavigator;
 import org.lcsim.geometry.Calorimeter;
-import org.lcsim.material.XMLMaterialManager;
 import org.lcsim.material.MaterialManager;
+import org.lcsim.material.XMLMaterialManager;
+
+import Jama.Matrix;
 
 /**
  * Default class created to represent the parsed detector.
@@ -32,6 +34,7 @@
     private Map<String, LimitSet> limits = new HashMap<String, LimitSet>();
     private Map<String, Region> regions = new HashMap<String, Region>();
     private Map<String, VisAttributes> display = new HashMap<String, VisAttributes>();
+    private Map<String, Matrix> matrices = new HashMap<String, Matrix>();
     private XMLMaterialManager materialMgr; // Setup externally by CompactReader.
     private List<URL> gdmlReferences = new ArrayList<URL>();
 
@@ -126,6 +129,32 @@
     public Map<String, Constant> getConstants() {
         return constants;
     }
+    
+    /**
+     * Add a matrix associated with this Detector, e.g. for material properties.
+     * @param name The name of the matrix.
+     * @param matrix The matrix object.
+     */
+    public void addMatrix(String name, Matrix matrix) {
+        this.matrices.put(name, matrix);
+    }
+    
+    /**
+     * Get a matrix associated with this Detector.
+     * @param name The name of the matrix.
+     * @return The matrix or null if it does not exist.
+     */
+    public Matrix getMatrix(String name) {
+        return this.matrices.get(name);
+    }
+    
+    /**
+     * Get the map of named matrices.
+     * @return The map of matrices for this detector.
+     */
+    public Map<String, Matrix> getMatrices() {
+        return this.matrices;
+    }
 
     /**
      * Called by the reader to add a new Readout to this detector.

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
LCDDDetector.java 1.27 -> 1.28
diff -u -r1.27 -r1.28
--- LCDDDetector.java	24 Jan 2013 22:27:16 -0000	1.27
+++ LCDDDetector.java	24 Apr 2013 02:00:35 -0000	1.28
@@ -42,6 +42,8 @@
 import org.lcsim.geometry.util.IDDescriptor;
 import org.lcsim.util.cache.FileCache;
 
+import Jama.Matrix;
+
 /**
  * 
  * @author tonyj
@@ -93,6 +95,9 @@
         for (org.lcsim.geometry.compact.Constant c : getConstants().values()) {
             define.addConstant(new Constant(c.getName(), String.valueOf(c.getValue())));
         }
+        
+        /* Write out the matrices associated with this detector, e.g. for material properties. */
+        writeMatrices(lcdd);
 
         /* Setup materials. */
         setupMaterials(lcdd);
@@ -232,6 +237,26 @@
             lcdd.addRegion(lcddRegion);
         }
     }
+    
+    private void writeMatrices(LCDD lcdd) {
+        for (String name : this.getMatrices().keySet()) {
+             Matrix matrix = this.getMatrix(name);
+             int coldim = matrix.getColumnDimension();             
+             org.lcsim.geometry.compact.converter.lcdd.util.Matrix lcddMatrix = 
+                     new org.lcsim.geometry.compact.converter.lcdd.util.Matrix(name, coldim);                         
+             String values = "";
+             for (int i=0, n=matrix.getRowDimension(); i<n; i++) {
+                 String row = "";
+                 for (int j=0; j<coldim; j++) {
+                     row += matrix.get(i, j) + " ";
+                 }
+                 values += row.trim() + '\n';
+             }
+             values = values.trim();
+             lcddMatrix.setValues(values);
+             lcdd.add(lcddMatrix);
+        }
+    }
 
     private Map<Readout, IDSpec> writeReadouts(LCDD lcdd) {
         // Loop over the readouts

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd
Main.java 1.22 -> 1.23
diff -u -r1.22 -r1.23
--- Main.java	7 Dec 2010 20:16:46 -0000	1.22
+++ Main.java	24 Apr 2013 02:00:35 -0000	1.23
@@ -23,102 +23,87 @@
 import org.lcsim.util.xml.ElementFactory;
 
 /**
- * This class is the front end for generating LCDD output from the compact description.
+ * This class is the front end for generating LCDD output from the compact
+ * description.
  * 
  * @author tonyj
  * @author jeremym
  */
-public class Main implements Converter
-{
-    private boolean validate = true;
+public class Main implements Converter {
 
+    private boolean validate = true;
+    
     /**
      * @param args the command line arguments
      */
-    public static void main( String[] args ) throws Exception
-    {
-        if ( args.length < 1 || args.length > 2 )
+    public static void main(String[] args) throws Exception {
+        if (args.length < 1 || args.length > 2)
             usage();
-        InputStream in = new BufferedInputStream( new FileInputStream( args[ 0 ] ) );
-        OutputStream out = args.length == 1 ? System.out : new BufferedOutputStream( new FileOutputStream( args[ 1 ] ) );        
-        new Main().convert( args[ 0 ], in, out );
-    } 
-    
-    public Main() throws Exception
-    {
+        InputStream in = new BufferedInputStream(new FileInputStream(args[0]));
+        OutputStream out = args.length == 1 ? System.out : new BufferedOutputStream(new FileOutputStream(args[1]));
+        new Main().convert(args[0], in, out);
+    }
+
+    public Main() throws Exception {
         setValidationFromSystemProperty();
     }
-    
-    private void setValidationFromSystemProperty()
-    {     
-        boolean validateProp = Boolean.parseBoolean( System.getProperty(
-                "org.lcsim.geometry.compact.converter.lcdd.validate",
-                "true" ) );
+
+    private void setValidationFromSystemProperty() {
+        boolean validateProp = Boolean.parseBoolean(System.getProperty("org.lcsim.geometry.compact.converter.lcdd.validate", "true"));
         this.validate = validateProp;
-        if ( validateProp == false )
-        {            
-            Logger.getLogger( Main.class.getName() ).warning( "XML output validation is turned OFF." );
+        if (validateProp == false) {
+            Logger.getLogger(Main.class.getName()).warning("XML output validation is turned OFF.");
         }
     }
 
-    public void convert( String inputFileName, InputStream in, OutputStream out ) throws Exception
-    {                      
+    public void convert(String inputFileName, InputStream in, OutputStream out) throws Exception {
         ElementFactory factory = new LCDDElementFactory();
-        CompactReader reader = new CompactReader( factory );
-        Detector det = reader.read( in );
-        Document doc = ( ( LCDDDetector ) det ).writeLCDD( inputFileName );
+        CompactReader reader = new CompactReader(factory);
+        Detector det = reader.read(in);
+        Document doc = ((LCDDDetector) det).writeLCDD(inputFileName);
 
         XMLOutputter outputter = new XMLOutputter();
-
-        if ( validate )
-        {
+                
+        if (validate) {
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
-            outputter.output( doc, stream );
+            outputter.output(doc, stream);
             stream.close();
 
             SAXBuilder builder = new SAXBuilder();
+            builder.setEntityResolver(new ClasspathEntityResolver());
+            builder.setValidation(true);
+            builder.setFeature("http://apache.org/xml/features/validation/schema", true);
 
-            builder.setEntityResolver( new ClasspathEntityResolver() );
-
-            builder.setValidation( true );
-            builder.setFeature( "http://apache.org/xml/features/validation/schema", true );
-
-            builder.build( new ByteArrayInputStream( stream.toByteArray() ) );
+            builder.build(new ByteArrayInputStream(stream.toByteArray()));
         }
 
-        if ( out != null )
-        {
-            outputter.setFormat( Format.getPrettyFormat() );
-            outputter.output( doc, out );
+        if (out != null) {
+            outputter.setFormat(Format.getPrettyFormat());
+            outputter.output(doc, out);            
             out.close();
         }
     }
 
-    private static void usage()
-    {
-        System.out.println( "java " + Main.class.getName() + " <compact> [<lcdd>]" );
-        System.exit( 0 );
+    private static void usage() {
+        System.out.println("java " + Main.class.getName() + " <compact> [<lcdd>]");
+        System.exit(0);
     }
 
-    public String getOutputFormat()
-    {
+    public String getOutputFormat() {
         return "lcdd";
     }
 
-    public FileFilter getFileFilter()
-    {
+    public FileFilter getFileFilter() {
         return new LCDDFileFilter();
     }
 
-    private static class LCDDFileFilter extends FileFilter
-    {
-        public boolean accept( java.io.File file )
-        {
-            return file.isDirectory() || file.getName().endsWith( ".lcdd" );
+    private static class LCDDFileFilter extends FileFilter {
+
+        public boolean accept(java.io.File file) {
+            return file.isDirectory() || file.getName().endsWith(".lcdd");
         }
 
-        public String getDescription()
-        {
+        public String getDescription() {
             return "LCDD file (*.lcdd)";
         }
     }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Matrix.java added at 1.1
diff -N Matrix.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Matrix.java	24 Apr 2013 02:00:35 -0000	1.1
@@ -0,0 +1,25 @@
+package org.lcsim.geometry.compact.converter.lcdd.util;
+
+
+/**
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: Matrix.java,v 1.1 2013/04/24 02:00:35 jeremy Exp $
+ */
+public class Matrix extends RefElement {
+    
+    int coldim = 0;
+    
+    public Matrix(String name, int coldim) {
+        super("matrix", name);
+        if (name == null)
+            throw new IllegalArgumentException("name is null");
+        if (coldim <= 0) {
+            throw new IllegalArgumentException("invalid coldim value: " + coldim);
+        }
+        setAttribute("coldim", String.valueOf(coldim));        
+    }
+    
+    public void setValues(String values) {
+        setAttribute("values", values);
+    }
+}

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
Define.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- Define.java	13 Apr 2011 00:09:52 -0000	1.3
+++ Define.java	24 Apr 2013 02:00:35 -0000	1.4
@@ -8,47 +8,50 @@
  * 
  * @author tonyj
  */
-public class Define extends Element
-{
+public class Define extends Element {
+
     private Map rotations = new HashMap();
     private Map constants = new HashMap();
     private Map positions = new HashMap();
+    private Map matrices = new HashMap();
 
-    public Define()
-    {
+    public Define() {
         super("define");
     }
 
-    public void addConstant(Constant constant)
-    {
+    public void addConstant(Constant constant) {
         addContent(constant);
         constants.put(constant.getRefName(), constant);
     }
 
-    public void addPosition(Position position)
-    {
+    public void addPosition(Position position) {
         addContent(position);
         positions.put(position.getRefName(), position);
     }
 
-    public void addRotation(Rotation rotation)
-    {
+    public void addRotation(Rotation rotation) {
         addContent(rotation);
         rotations.put(rotation.getRefName(), rotation);
     }
 
-    public Rotation getRotation(String name)
-    {
+    public Rotation getRotation(String name) {
         return (Rotation) rotations.get(name);
     }
 
-    public Position getPosition(String name)
-    {
+    public Position getPosition(String name) {
         return (Position) positions.get(name);
     }
 
-    public Constant getConstant(String name)
-    {
+    public Constant getConstant(String name) {
         return (Constant) constants.get(name);
     }
+    
+    public void addMatrix(Matrix matrix) {
+        addContent(matrix);
+        this.matrices.put(matrix.getRefName(), matrix);
+    }
+    
+    public Matrix getMatrix(String name) {
+        return (Matrix) matrices.get(name);
+    }
 }

GeomConverter/src/org/lcsim/geometry/compact/converter/lcdd/util
LCDD.java 1.31 -> 1.32
diff -u -r1.31 -r1.32
--- LCDD.java	24 Jan 2013 22:26:54 -0000	1.31
+++ LCDD.java	24 Apr 2013 02:00:35 -0000	1.32
@@ -201,6 +201,10 @@
     public void add(Constant constant) {
         getDefine().addConstant(constant);
     }
+    
+    public void add(Matrix matrix) {
+        getDefine().addMatrix(matrix);
+    }
 
     public void add(Position position) {
         getDefine().addPosition(position);

GeomConverter/testResources/org/lcsim/geometry/subdetector
OpticalCalorimeterTest.xml added at 1.1
diff -N OpticalCalorimeterTest.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ OpticalCalorimeterTest.xml	24 Apr 2013 02:00:36 -0000	1.1
@@ -0,0 +1,96 @@
+
+<lccdd xmlns:compact="http://www.lcsim.org/schemas/compact/1.0"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
+    xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/compact/1.0/compact.xsd">
+
+    <info name="OpticalCalorimeterTest"/>
+
+    <define>
+        <constant name="world_side" value="30000" />
+        <constant name="world_x" value="world_side" />
+        <constant name="world_y" value="world_side" />
+        <constant name="world_z" value="world_side" />
+        <constant name="tracking_region_radius" value="125.0*cm"/>
+        <constant name="tracking_region_zmax" value="200.0*cm"/>
+        <matrix name="prop1" coldim="2"  values="0.000002034 1.65
+                                                0.000002068 1.65
+                                                0.000002103 1.65 
+                                                0.000002139 1.65
+                                                0.000002177 1.65
+                                                0.000002216 1.65
+                                                0.000002256 1.65
+                                                0.000002298 1.65
+                                                0.000002341 1.65
+                                                0.000002386 1.65 
+                                                0.000002433 1.65
+                                                0.000002481 1.65
+                                                0.000002532 1.65
+                                                0.000002585 1.65
+                                                0.000002640 1.65
+                                                0.000002697 1.65
+                                                0.000002757 1.65
+                                                0.000002820 1.65
+                                                0.000002885 1.65
+                                                0.000002954 1.65
+                                                0.000003026 1.65
+                                                0.000003102 1.65
+                                                0.000003181 1.65
+                                                0.000003265 1.65
+                                                0.000003353 1.65
+                                                0.000003446 1.65
+                                                0.000003545 1.65
+                                                0.000003649 1.65
+                                                0.000003760 1.65
+                                                0.000003877 1.65 
+                                                0.000004002 1.65
+                                                0.000004136 1.65"/>
+    </define>
+    <materials>
+        <material name="BGO">
+            <property name="RINDEX" ref="prop1" />
+            <D value="7.13" unit="g/cm3"/>
+            <composite n="4" ref="Bi"/>
+            <composite n="3" ref="Ge"/>
+            <composite n="12" ref="O"/>
+        </material>
+    </materials>
+    <limits>
+        <limitset name="cal_limits">
+            <limit name="step_length_max" particles="*" value="5.0" unit="mm" />
+        </limitset>
+    </limits>
+    <detectors>
+        <detector id="7" name="HcalBarrel" type="PolyhedraBarrelCalorimeter2" readout="HcalBarrelHits" calorimeterType="HAD_BARREL" gap="0.*cm" material="BGO">
+            <comment>Hadron Calorimeter Barrel</comment>
+            <dimensions numsides="12" rmin="146*cm" z="370.2*cm * 2"/>
+            <staves />
+            <layer repeat="30">
+                <slice material="BGO" thickness="5.0*cm" sensitive="yes" />
+            </layer>
+        </detector>
+        <detector id="8" name="HcalEndcap" type="PolyhedraEndcapCalorimeter3" readout="HcalEndcapHits" reflect="true" calorimeterType="HAD_ENDCAP">
+            <comment>Hadron Calorimeter Endcaps</comment>
+            <dimensions numsides="12" zmin="220.2*cm" rmin="39.0*cm" rmax="146.0*cm" angle="6.*deg" />
+            <layer repeat="30">
+                <slice material="BGO" thickness="5.0*cm" sensitive="yes" />
+            </layer>
+        </detector>
+    </detectors>
+    <readouts>
+        <readout name="HcalBarrelHits">
+            <segmentation type="CartesianGridXY" gridSizeX="2.0*cm" gridSizeY="2.0*cm" />
+            <id>system:6,barrel:3,module:4,layer:6,slice:5,x:32:-16,y:-16</id>
+        </readout>
+        <readout name="HcalEndcapHits">
+            <segmentation type="GlobalGridXY" gridSizeX="2.0*cm" gridSizeY="2.0*cm" />
+            <id>system:6,barrel:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id>
+        </readout>
+    </readouts>
+    <fields>
+        <field type="Solenoid" name="GlobalSolenoid"
+        inner_field="5.0"
+        outer_field="-0.6"
+        zmax="1000*cm"
+        outer_radius="300*cm"/>
+    </fields>
+</lccdd>
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1