Commit in GeomConverter on MAIN
src/org/lcsim/material/MaterialDefinitionType.java+79added 1.1
                      /MaterialElement.java+102added 1.1
                      /MaterialElementData.java+125added 1.1
                      /MaterialElementDataToGDMLCnv.java+118added 1.1
                      /MaterialFromGDMLCnv.java+256added 1.1
                      /MaterialManager.java+94added 1.1
                      /Material.java+219-7541.1 -> 1.2
                      /MaterialState.java+41-101.1 -> 1.2
test/org/lcsim/material/MaterialFromGDMLCnvTest.java+50added 1.1
                       /MaterialFromGDMLCnvTest.xml+30added 1.1
                       /ElementDataToGDMLTest.java+1-11.1 -> 1.2
+1115-765
8 added + 3 modified, total 11 files
First commit of org.lcsim.material package.  Still a WIP.  Needs more test cases and still needs to be used in compact -> reco obj code.

GeomConverter/src/org/lcsim/material
MaterialDefinitionType.java added at 1.1
diff -N MaterialDefinitionType.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialDefinitionType.java	30 Jun 2005 00:37:50 -0000	1.1
@@ -0,0 +1,79 @@
+/*
+ * MaterialDefinitionType.java
+ *
+ * Created on June 29, 2005, 12:40 PM
+ */
+
+package org.lcsim.material;
+
+import org.jdom.JDOMException;
+
+/**
+ *
+ * @author jeremym
+ */
+public class MaterialDefinitionType
+{
+    String _tagname;
+    
+    public static final MaterialDefinitionType COMPOSITE = new MaterialDefinitionType("composite");
+    public static final MaterialDefinitionType FRACTION = new MaterialDefinitionType("fraction");
+    public static final MaterialDefinitionType ATOM = new MaterialDefinitionType("atom");
+    public static final MaterialDefinitionType INVALID = new MaterialDefinitionType("");
+    
+    /** Creates a new instance of MaterialDefinitionType */
+    public MaterialDefinitionType(String tagname)
+    {
+        _tagname = tagname;
+    }
+    
+    public String getTagName()
+    {
+        return _tagname;
+    }
+    
+    static MaterialDefinitionType getMaterialDefinitionType(org.jdom.Element materialElement) throws JDOMException
+    {
+        boolean gotOne = false;
+        MaterialDefinitionType mdt = MaterialDefinitionType.INVALID;
+        
+        if ( materialElement.getChild("atom") != null )
+        {
+            mdt = MaterialDefinitionType.ATOM;
+            gotOne = true;
+        }
+        
+        if ( materialElement.getChild("composite") != null )
+        {
+            if ( gotOne )
+            {
+                throw new JDOMException("Already got atom tag for material: " + materialElement.getAttributeValue("name"));
+            }
+            else
+            {
+                gotOne = true;
+                mdt = MaterialDefinitionType.COMPOSITE;
+            }
+        }
+        
+        if ( materialElement.getChild("fraction") != null )
+        {
+            if ( gotOne )
+            {
+                throw new JDOMException("Already got atom or composite tag for material: " + materialElement.getAttributeValue("name"));
+            }
+            else
+            {
+                mdt = MaterialDefinitionType.FRACTION;
+                gotOne = true;
+            }
+        }
+        
+        if ( !gotOne )
+        {
+            throw new JDOMException("One of atom, composite or fraction was not found for material: " + materialElement.getAttributeValue("name"));
+        }
+        
+        return mdt;
+    }
+}

GeomConverter/src/org/lcsim/material
MaterialElement.java added at 1.1
diff -N MaterialElement.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialElement.java	30 Jun 2005 00:37:50 -0000	1.1
@@ -0,0 +1,102 @@
+package org.lcsim.material;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class MaterialElement
+{
+    private String _name;                 // Element 1 or 2 letter name
+    private String _fullName;             // Element full name
+    private int _Z;                    // Element Z
+    private double _A;                    // Atomic weight in mol/cc
+    private double _density;                  // Density in g/cm^3 at 25 degrees C or at boiling point for liquids
+    private double _meltingPoint;         // Melting point (K)
+    private double _boilingPoint;         // Boiling point (K)
+    private double _ionizationPotential;  // Ionization potential (eV)
+    
+    private static Map<String, MaterialElement> _elements = new TreeMap<String, MaterialElement>();
+    
+    /*
+    private static String[] ElementNotes = {
+        "Density measured at 15 degrees C",
+                "Density measured at 20 degrees C",
+                "Density measured at 26 degrees C",
+                "Melting point represents critical temperature",
+                "Boiling point represents sublimation temperature",
+                "Density is calculated",
+                "Density is estimated",
+                "Melting point is estimated",
+    };
+     */
+        
+    MaterialElement(String name,
+            String fullName,
+            int Z,
+            double A,
+            double density,
+            double mp,
+            double bp,
+            double ip)
+    {
+        System.out.println("MaterialElement ctor: " + name);
+        
+        _name = name;
+        _fullName =  fullName;
+        _Z = Z;
+        _A = A;
+        _density = density;
+        _meltingPoint = mp;
+        _boilingPoint = bp;
+        _ionizationPotential = ip;
+        _elements.put(name, this);
+    }    
+    
+    public static Map elements()
+    {
+        return _elements;
+    }
+    
+    public String name()
+    {
+        return _name;
+    }
+    public String fullName()
+    {
+        return _fullName;
+    }
+    public int getZ()
+    {
+        return _Z;
+    }
+    public double getA()
+    {
+        return _A;
+    }
+    public double getDensity()
+    {
+        return _density;
+    }
+    public double meltingPoint()
+    {
+        return _meltingPoint;
+    }
+    public double boilingPoint()
+    {
+        return _boilingPoint;
+    }
+    public double ionizationPotential()
+    {
+        return _ionizationPotential;
+    }
+    
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer("ElementData: \n");
+        sb.append(_fullName+" : "+_name+" Z= "+_Z+" A= "+_A+" density= "+_density+" MP= "+_meltingPoint+" BP= "+_boilingPoint+" IP= "+ _ionizationPotential+"\n");
+        return sb.toString();
+    }        
+    
+    public String getName()
+    {
+        return _name;
+    }
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/material
MaterialElementData.java added at 1.1
diff -N MaterialElementData.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialElementData.java	30 Jun 2005 00:37:50 -0000	1.1
@@ -0,0 +1,125 @@
+package org.lcsim.material;
+import java.util.Map;
+import java.util.TreeMap;
+/**
+ * Ported from lelaps.
+ *
+ */
+public class MaterialElementData
+{           
+    //
+    //                                                         name    fullName          Z    A           density         melts at    boils at    ion. pot.
+    //
+    public final static MaterialElement vacuum = new MaterialElement( "vacuum", "vacuum"    ,   0, 0.0       , 0.0       , 0.0       , 0.0       , 0.0       );
+    public final static MaterialElement Hydrogen = new MaterialElement( "H" , "Hydrogen"      ,   1, 1.00794   , 0.0708    , 13.81     , 20.28     , 13.598 );
+    public final static MaterialElement Deuterium = new MaterialElement( "D" , "Deuterium"     ,   1, 2.0140    , 0.16      , 15.0      , 23.4      , -1       );
+    public final static MaterialElement Helium = new MaterialElement( "He", "Helium"        ,   2, 4.002602  , 0.124901  , 0.94999999, 4.22      , 24.587      );
+    public final static MaterialElement Lithium = new MaterialElement( "Li", "Lithium"       ,   3, 6.941     , 0.534     , 453.65    , 1615.15   , 5.392      );
+    public final static MaterialElement Beryllium = new MaterialElement( "Be", "Beryllium"     ,   4, 9.012182  , 1.85      , 1560.15   , 2744.15   , 9.323      );
+    public final static MaterialElement Boron = new MaterialElement( "B" , "Boron"         ,   5, 10.811    , 2.37      , 2348.15   , 4273.15   , 8.298       );
+    public final static MaterialElement Carbon = new MaterialElement( "C" , "Carbon"        ,   6, 12.0107   , 2.2670    , 4765.15   , 4115.15   , 11.260     );
+    public final static MaterialElement Nitrogen = new MaterialElement( "N" , "Nitrogen"      ,   7, 14.00674  , 0.807     , 63.15     , 77.36     , 14.534   );
+    public final static MaterialElement Oxygen = new MaterialElement( "O" , "Oxygen"        ,   8, 15.9994   , 1.141     , 54.36     , 90.2      , 13.618     );
+    public final static MaterialElement Fluorine = new MaterialElement( "F" , "Fluorine"      ,   9, 18.9984032, 1.50      , 53.53     , 85.03     , 17.423   );
+    public final static MaterialElement Neon = new MaterialElement( "Ne", "Neon"          ,  10, 20.1797   , 1.204     , 24.56     , 27.07     , 21.565     );
+    public final static MaterialElement Sodium = new MaterialElement( "Na", "Sodium"        ,  11, 22.989770 , 0.97      , 370.95    , 1156.15   , 5.139      );
+    public final static MaterialElement Magnesium = new MaterialElement( "Mg", "Magnesium"     ,  12, 24.3050   , 1.74      , 923.15    , 1363.15   , 7.646   );
+    public final static MaterialElement Aluminum = new MaterialElement( "Al", "Aluminum"      ,  13, 26.981538 , 2.70      , 933.47    , 2792.15   , 5.986    );
+    public final static MaterialElement Silicon = new MaterialElement( "Si", "Silicon"       ,  14, 28.0855   , 2.3296    , 1687.15   , 3538.15   , 8.152       );
+    public final static MaterialElement Phosphorus = new MaterialElement( "P" , "Phosphorus"    ,  15, 30.973761 , 1.82      , 317.3     , 553.65    , 10.487      );
+    public final static MaterialElement Sulfur = new MaterialElement( "S" , "Sulfur"        ,  16, 32.066    , 2.067     , 388.36    , 717.75    , 10.360      );
+    public final static MaterialElement Chlorine = new MaterialElement( "Cl", "Chlorine"      ,  17, 35.4527   , 1.56      , 171.65    , 239.11    , 12.968      );
+    public final static MaterialElement Argon = new MaterialElement( "Ar", "Argon"         ,  18, 39.948    , 1.396     , 83.8      , 87.3      , 15.760      );
+    public final static MaterialElement Potassium = new MaterialElement( "K" , "Potassium"     ,  19, 39.0983   , 0.89      , 336.53    , 1032.15   , 4.341       );
+    public final static MaterialElement Calcium = new MaterialElement( "Ca", "Calcium"       ,  20, 40.078    , 1.54      , 1115.15   , 1757.15   , 6.113       );
+    public final static MaterialElement Scandium = new MaterialElement( "Sc", "Scandium"      ,  21, 44.955910 , 2.99      , 1814.15   , 3109.15   , 6.561       );
+    public final static MaterialElement Titanium = new MaterialElement( "Ti", "Titanium"      ,  22, 47.867    , 4.5       , 1941.15   , 3560.15   , 6.828       );
+    public final static MaterialElement Vanadium = new MaterialElement( "V" , "Vanadium"      ,  23, 50.9415   , 6.0       , 2183.15   , 3680.15   , 6.746       );
+    public final static MaterialElement Chromium = new MaterialElement( "Cr", "Chromium"      ,  24, 51.9961   , 7.15      , 2180.15   , 2944.15   , 6.767       );
+    public final static MaterialElement Manganese = new MaterialElement( "Mn", "Manganese"     ,  25, 54.938049 , 7.3       , 1519.15   , 2334.15   , 7.434       );
+    public final static MaterialElement Iron = new MaterialElement( "Fe", "Iron"          ,  26, 55.845    , 7.875     , 1811.15   , 3134.15   , 7.902       );
+    public final static MaterialElement Cobalt = new MaterialElement( "Co", "Cobalt"        ,  27, 58.933200 , 8.86      , 1768.15   , 3200.15   , 7.881       );
+    public final static MaterialElement Nickel = new MaterialElement( "Ni", "Nickel"        ,  28, 58.6934   , 8.912     , 1728.15   , 3186.15   , 7.640       );
+    public final static MaterialElement Copper = new MaterialElement( "Cu", "Copper"        ,  29, 63.546    , 8.933     , 1357.77   , 2835.15   , 7.726       );
+    public final static MaterialElement Zinc = new MaterialElement( "Zn", "Zinc"          ,  30, 65.39     , 7.134     , 692.68    , 1180.15   , 9.394       );
+    public final static MaterialElement Gallium = new MaterialElement( "Ga", "Gallium"       ,  31, 69.723    , 5.91      , 302.91    , 2477.15   , 5.999       );
+    public final static MaterialElement Germanium = new MaterialElement( "Ge", "Germanium"     ,  32, 72.61     , 5.323     , 1211.4    , 3106.15   , 7.900       );
+    public final static MaterialElement Arsenic = new MaterialElement( "As", "Arsenic"       ,  33, 74.92160  , 5.776     , 1090.15   , 887.15    , 9.815       );
+    public final static MaterialElement Selenium = new MaterialElement( "Se", "Selenium"      ,  34, 78.96     , 4.809     , 494.15    , 958.15    , 9.752         );
+    public final static MaterialElement Bromine = new MaterialElement( "Br", "Bromine"       ,  35, 79.904    , 3.11      , 265.95    , 331.95    , 11.814      );
+    public final static MaterialElement Krypton = new MaterialElement( "Kr", "Krypton"       ,  36, 83.80     , 2.418     , 115.79    , 119.93    , 14.000      );
+    public final static MaterialElement Rubidium = new MaterialElement( "Rb", "Rubidium"      ,  37, 85.4678   , 1.53      , 312.46    , 961.15    , 4.177       );
+    public final static MaterialElement Strontium = new MaterialElement( "Sr", "Strontium"     ,  38, 87.62     , 2.64      , 1050.15   , 1655.15   , 5.695       );
+    public final static MaterialElement Yttrium = new MaterialElement( "Y" , "Yttrium"       ,  39, 88.90585  , 4.47      , 1795.15   , 3618.15   , 6.217       );
+    public final static MaterialElement Zirconium = new MaterialElement( "Zr", "Zirconium"     ,  40, 91.224    , 6.52      , 2128.15   , 4682.15   , 6.634       );
+    public final static MaterialElement Niobium = new MaterialElement( "Nb", "Niobium"       ,  41, 92.90638  , 8.57      , 2750.15   , 5017.15   , 6.759       );
+    public final static MaterialElement Molybdenum = new MaterialElement( "Mo", "Molybdenum"    ,  42, 95.94     , 10.2      , 2896.15   , 4912.15   , 7.092      );
+    public final static MaterialElement Technetium = new MaterialElement( "Tc", "Technetium"    ,  43, 98        , 11        , 2430.15   , 4538.15   , 7.28       );
+    public final static MaterialElement Ruthenium = new MaterialElement( "Ru", "Ruthenium"     ,  44, 101.07    , 12.1      , 2607.15   , 4423.15   , 7.361      );
+    public final static MaterialElement densitydium = new MaterialElement( "Rh", "densitydium"       ,  45, 102.90550 , 12.4      , 2237.15   , 3968.15   , 7.459      );
+    public final static MaterialElement Palladium = new MaterialElement( "Pd", "Palladium"     ,  46, 106.42    , 12.0      , 1828.05   , 3236.15   , 8.337      );
+    public final static MaterialElement Silver = new MaterialElement( "Ag", "Silver"        ,  47, 107.8682  , 10.501    , 1234.93   , 2435.15   , 7.576      );
+    public final static MaterialElement Cadmium = new MaterialElement( "Cd", "Cadmium"       ,  48, 112.411   , 8.69      , 594.22    , 1040.15   , 8.994      );
+    public final static MaterialElement Indium = new MaterialElement( "In", "Indium"        ,  49, 114.818   , 7.31      , 429.75    , 2345.15   , 5.786      );
+    public final static MaterialElement Tin = new MaterialElement( "Sn", "Tin"           ,  50, 118.710   , 7.287     , 505.08    , 2875.15   , 7.344          );
+    public final static MaterialElement Antimony = new MaterialElement( "Sb", "Antimony"      ,  51, 121.760   , 6.685     , 903.78    , 1860.15   , 8.64          );
+    public final static MaterialElement Tellurium = new MaterialElement( "Te", "Tellurium"     ,  52, 127.60    , 6.232     , 722.66    , 1261.15   , 9.010      );
+    public final static MaterialElement Iodine = new MaterialElement( "I" , "Iodine"        ,  53, 126.90447 , 4.93      , 386.85    , 457.55    , 10.451         );
+    public final static MaterialElement Xenon = new MaterialElement( "Xe", "Xenon"         ,  54, 131.29    , 2.953     , 161.4     , 165.11    , 12.130     );
+    public final static MaterialElement Cesium = new MaterialElement( "Cs", "Cesium"        ,  55, 132.90545 , 1.93      , 301.59    , 944.15    , 3.894      );
+    public final static MaterialElement Barium = new MaterialElement( "Ba", "Barium"        ,  56, 137.327   , 3.62      , 1000.15   , 2170.15   , 5.212      );
+    public final static MaterialElement Lanthanum = new MaterialElement( "La", "Lanthanum"     ,  57, 138.9055  , 6.15      , 1191.15   , 3737.15   , 5.577      );
+    public final static MaterialElement Cerium = new MaterialElement( "Ce", "Cerium"        ,  58, 140.116   , 8.16      , 1071.15   , 3716.15   , 5.539      );
+    public final static MaterialElement Praseodymium = new MaterialElement( "Pr", "Praseodymium"  ,  59, 140.90765 , 6.77      , 1204.15   , 3793.15   , 5.464      );
+    public final static MaterialElement Neodymium = new MaterialElement( "Nd", "Neodymium"     ,  60, 144.24    , 7.01      , 1294.15   , 3347.15   , 5.525      );
+    public final static MaterialElement Promethium = new MaterialElement( "Pm", "Promethium"    ,  61, 145       , 7.26      , 1315.15   , 3273.15   , 5.55       );
+    public final static MaterialElement Samarium = new MaterialElement( "Sm", "Samarium"      ,  62, 150.36    , 7.52      , 1347.15   , 2067.15   , 5.644      );
+    public final static MaterialElement Europium = new MaterialElement( "Eu", "Europium"      ,  63, 151.964   , 5.24      , 1095.15   , 1869.15   , 5.670      );
+    public final static MaterialElement Gadolinium = new MaterialElement( "Gd", "Gadolinium"    ,  64, 157.25    , 7.90      , 1586.15   , 3546.15   , 6.150      );
+    public final static MaterialElement Terbium = new MaterialElement( "Tb", "Terbium"       ,  65, 158.92534 , 8.23      , 1629.15   , 3503.15   , 5.864      );
+    public final static MaterialElement Dysprosium = new MaterialElement( "Dy", "Dysprosium"    ,  66, 162.50    , 8.55      , 1685.15   , 2840.15   , 5.939      );
+    public final static MaterialElement Holmium = new MaterialElement( "Ho", "Holmium"       ,  67, 164.93032 , 8.80      , 1747.15   , 2973.15   , 6.022      );
+    public final static MaterialElement Erbium = new MaterialElement( "Er", "Erbium"        ,  68, 167.26    , 9.07      , 1802.15   , 3141.15   , 6.108      );
+    public final static MaterialElement Thulium = new MaterialElement( "Tm", "Thulium"       ,  69, 168.93421 , 9.32      , 1818.15   , 2223.15   , 6.184      );
+    public final static MaterialElement Ytterbium = new MaterialElement( "Yb", "Ytterbium"     ,  70, 173.04    , 6.90      , 1092.15   , 1469.15   , 6.254      );
+    public final static MaterialElement Lutetium = new MaterialElement( "Lu", "Lutetium"      ,  71, 174.967   , 9.84      , 1936.15   , 3675.15   , 5.426      );
+    public final static MaterialElement Hafnium = new MaterialElement( "Hf", "Hafnium"       ,  72, 178.49    , 13.3      , 2506.15   , 4876.15   , 6.825      );
+    public final static MaterialElement Tantalum = new MaterialElement( "Ta", "Tantalum"      ,  73, 180.9479  , 16.4      , 3290.15   , 5731.15   , 7.89       );
+    public final static MaterialElement Tungsten = new MaterialElement( "W" , "Tungsten"      ,  74, 183.84    , 19.3      , 3695.15   , 5828.15   , 7.98       );
+    public final static MaterialElement Rhenium = new MaterialElement( "Re", "Rhenium"       ,  75, 186.207   , 20.8      , 3459.15   , 5869.15   , 7.88       );
+    public final static MaterialElement Osmium = new MaterialElement( "Os", "Osmium"        ,  76, 190.23    , 22.5      , 3306.15   , 5285.15   , 8.7        );
+    public final static MaterialElement Iridium = new MaterialElement( "Ir", "Iridium"       ,  77, 192.217   , 22.5      , 2719.15   , 4701.15   , 9.1        );
+    public final static MaterialElement Platinum = new MaterialElement( "Pt", "Platinum"      ,  78, 195.078   , 21.46     , 2041.55   , 4098.15   , 9.0        );
+    public final static MaterialElement Gold = new MaterialElement( "Au", "Gold"          ,  79, 196.96655 , 19.282    , 1337.33   , 3129.15   , 9.226      );
+    public final static MaterialElement Mercury = new MaterialElement( "Hg", "Mercury"       ,  80, 200.59    , 13.5336   , 234.32    , 629.88    , 10.438     );
+    public final static MaterialElement Thallium = new MaterialElement( "Tl", "Thallium"      ,  81, 204.3833  , 11.8      , 577.15    , 1746.15   , 6.108      );
+    public final static MaterialElement Lead = new MaterialElement( "Pb", "Lead"          ,  82, 207.2     , 11.342    , 600.61    , 2022.15   , 7.417      );
+    public final static MaterialElement Bismuth = new MaterialElement( "Bi", "Bismuth"       ,  83, 208.98038 , 9.807     , 544.55    , 1837.15   , 7.289      );
+    public final static MaterialElement Polonium = new MaterialElement( "Po", "Polonium"      ,  84, 209       , 9.32      , 527.15    , 1235.15   , 8.417      );
+    public final static MaterialElement Astatine = new MaterialElement( "At", "Astatine"      ,  85, 210       , -1        , 575.15    , -1        , -1         );
+    public final static MaterialElement Radon = new MaterialElement( "Rn", "Radon"         ,  86, 222       , 4.4       , 202.15    , 211.45    , 10.749     );
+    public final static MaterialElement Francium = new MaterialElement( "Fr", "Francium"      ,  87, 223       , -1        , 300.15    , -1        , -1         );
+    public final static MaterialElement Radium = new MaterialElement( "Ra", "Radium"        ,  88, 226       , 5         , 973.15    , -1        , 5.279      );
+    public final static MaterialElement Actinium = new MaterialElement( "Ac", "Actinium"      ,  89, 227       , 10.07     , 1324.15   , 3471.15   , 5.17           );
+    public final static MaterialElement Thorium = new MaterialElement( "Th", "Thorium"       ,  90, 232.0381  , 11.72     , 2023.15   , 5061.15   , 6.08       );
+    public final static MaterialElement Protactinium = new MaterialElement( "Pa", "Protactinium"  ,  91, 231.03588 , 15.37     , 1845.15   , -1        , 5.89           );
+    public final static MaterialElement Uranium = new MaterialElement( "U" , "Uranium"       ,  92, 238.0289  , 18.95     , 1408.15   , 4404.15   , 6.194      );
+    public final static MaterialElement Neptunium = new MaterialElement( "Np", "Neptunium"     ,  93, 237       , 20.25     , 917.15    , -1        , 6.266          );
+    public final static MaterialElement Plutonium = new MaterialElement( "Pu", "Plutonium"     ,  94, 244       , 19.84     , 913.15    , 3501.15   , 6.06       );
+    public final static MaterialElement Americium = new MaterialElement( "Am", "Americium"     ,  95, 243       , 13.69     , 1449.15   , 2284.15   , 5.993         );
+    public final static MaterialElement Curium = new MaterialElement( "Cm", "Curium"        ,  96, 247       , 13.51     , 1618.15   , -1        , 6.02           );
+    public final static MaterialElement Berkelium = new MaterialElement( "Bk", "Berkelium"     ,  97, 247       , 14        , 1323.15   , -1        , 6.23          );
+    public final static MaterialElement Californium = new MaterialElement( "Cf", "Californium"   ,  98, 251       , -1        , 1173.15   , -1        , 6.30       );
+    public final static MaterialElement Einsteinium = new MaterialElement( "Es", "Einsteinium"   ,  99, 252       , -1        , 1133.15   , -1        , 6.42       );
+    public final static MaterialElement Fermium = new MaterialElement( "Fm", "Fermium"       , 100, 257       , -1        , 1800.15   , -1        , 6.50       );
+    public final static MaterialElement Mendelevium = new MaterialElement( "Md", "Mendelevium"   , 101, 258       , -1        , 1100.15   , -1        , 6.58       );
+    public final static MaterialElement Nobelium = new MaterialElement( "No", "Nobelium"      , 102, 259       , -1        , 1100.15   , -1        , 6.65       );
+    public final static MaterialElement Lawrencium = new MaterialElement( "Lr", "Lawrencium"    , 103, 262       , -1        , 1900.15   , -1        , -1         );
+    public final static MaterialElement Rutherfordium = new MaterialElement( "Rf", "Rutherfordium" , 104, 261       , -1        , -1        , -1        , -1         );
+    public final static MaterialElement Hahnium = new MaterialElement( "Ha", "Hahnium"       , 105, 262       , -1        , -1        , -1        , -1         );
+    public final static MaterialElement Seaborgium = new MaterialElement( "Sg", "Seaborgium"    , 106, 266       , -1        , -1        , -1        , -1         );
+    public final static MaterialElement Nielsbohrium = new MaterialElement( "Ns", "Nielsbohrium"  , 107, 264       , -1        , -1        , -1        , -1         );
+    public final static MaterialElement Hassium = new MaterialElement( "Hs", "Hassium"       , 108, 269       , -1        , -1        , -1        , -1         );
+    public final static MaterialElement Meitnerium = new MaterialElement( "Mt", "Meitnerium"    , 109, 268       , -1        , -1        , -1        , -1         );
+    // Last element:    
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/material
MaterialElementDataToGDMLCnv.java added at 1.1
diff -N MaterialElementDataToGDMLCnv.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialElementDataToGDMLCnv.java	30 Jun 2005 00:37:50 -0000	1.1
@@ -0,0 +1,118 @@
+/*
+ * ElementDataToXMLCnv.java
+ *
+ * Created on June 7, 2005, 3:28 PM
+ */
+
+package org.lcsim.material;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.output.XMLOutputter;
+import org.jdom.output.Format;
+
+/**
+ *
+ * @author jeremym
+ *
+ * Converts org.lcsim.material.ElementData to valid GDML materials block.
+ *
+ */
+public class MaterialElementDataToGDMLCnv
+{
+    static final String elementFileName = "elements.xml";
+    
+    /** Creates a new instance of ElementDataToXMLCnv */
+    public MaterialElementDataToGDMLCnv()
+    {}
+    
+    /** Get an XML document containing elements. */
+    public static Document convertElementData()
+    {
+        Element root = createMaterialsRoot();
+        
+        for ( Object o : MaterialElement.elements().values() )
+        {
+            MaterialElement d = (MaterialElement) o;
+            
+            Element e = createElement(d);
+            Element m = createMaterial(d);
+            
+            root.addContent(e);
+            root.addContent(m);
+        }
+        
+        Document d = new Document();
+        d.setRootElement(root);
+        return d;
+    }
+    
+    /** Write GDML materials block to given file and path. */
+    public static void write(String path, String nm) throws FileNotFoundException, IOException
+    {
+        Document d = convertElementData();        
+        File f = new File(path + File.separator + nm);
+        OutputStream out = new BufferedOutputStream(new FileOutputStream(f.getAbsolutePath()));
+        XMLOutputter outputter = new XMLOutputter();
+        outputter.setFormat(Format.getPrettyFormat());
+        outputter.output(d, out);
+        out.close();
+    }
+    
+    /** Default write converted elements to ./elements.xml . */
+    public static void write() throws FileNotFoundException, IOException
+    {
+        write(".", elementFileName);
+    }
+    
+    /** Create the "materials" root node. */
+    public static Element createMaterialsRoot()
+    {
+        return new Element("materials");
+    }
+    
+    /** 
+     * Create a chemical element node.      
+     */
+    public static Element createElement(MaterialElement d)
+    {
+        Element e = new Element("element");
+        e.setAttribute("name", d.fullName()+"_e" );
+        e.setAttribute("formula", d.name() );
+        e.setAttribute("Z", String.valueOf( d.getZ() ));
+        
+        Element a = new Element("atom");
+        a.setAttribute("type", "A");
+        a.setAttribute("unit", "g/mol");
+        a.setAttribute("value", String.valueOf( d.getA() ));
+        e.addContent(a);
+        
+        return e;
+    }
+    
+    /** Create a material node for the chemical element. */
+    public static Element createMaterial(MaterialElement d)
+    {
+        Element m = new Element("material");
+        m.setAttribute("name", d.fullName());
+        
+        Element dens = new Element("D");
+        dens.setAttribute("type", "density");
+        dens.setAttribute("unit", "g/cm3");
+        dens.setAttribute("value", String.valueOf(d.getDensity() ));
+        m.addContent(dens);
+        
+        Element comp = new Element("composite");
+        comp.setAttribute("n","1");
+        comp.setAttribute("ref",d.fullName()+"_e");
+        m.addContent(comp);
+        
+        return m;
+    }
+}

GeomConverter/src/org/lcsim/material
MaterialFromGDMLCnv.java added at 1.1
diff -N MaterialFromGDMLCnv.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialFromGDMLCnv.java	30 Jun 2005 00:37:50 -0000	1.1
@@ -0,0 +1,256 @@
+/*
+ * MaterialCnv.java
+ *
+ * Created on June 28, 2005, 3:44 PM
+ */
+
+package org.lcsim.material;
+
+import org.jdom.DataConversionException;
+import org.jdom.JDOMException;
+import org.lcsim.geometry.compact.converter.lcdd.util.LCDD;
+import org.lcsim.geometry.compact.converter.lcdd.util.Constant;
+
+/**
+ *
+ * @author jeremym
+ *
+ * Convert a GDML material to org.lcsim.Material implementation class.
+ *
+ */
+public class MaterialFromGDMLCnv
+{
+    LCDD _lcdd;
+    
+    /** Default temperature in kelvin = 1.0 */
+    public static final double defaultTemperature = 273.15;
+    
+    /** Default pressure in atmospheres = 1.0 */
+    public static final double defaultPressure = 1.0;        
+    
+    /** Creates a new instance of MaterialCnv */
+    public MaterialFromGDMLCnv(LCDD lcdd)
+    {
+        _lcdd = lcdd;
+    }
+    
+    public MaterialFromGDMLCnv()
+    {
+        _lcdd = null;
+    }
+    
+    public void setLCDD(LCDD lcdd)
+    {
+        _lcdd = lcdd;
+    }
+    
+    /** Make an org.lcsim.material.Material object from a material tag. */
+    public Material makeMaterial(org.jdom.Element materialElement, LCDD lcdd) throws JDOMException
+    {
+        _lcdd = lcdd;
+        
+        Material material = null;
+        String name = materialElement.getAttributeValue("name");
+        String formula = materialElement.getAttributeValue("formula");
+        MaterialState state = MaterialState.getMaterialState(materialElement);
+        
+        double density;
+        double pressure;
+        double temperature;
+        density = pressure = temperature = 0;
+        
+        /* Allow this function to throw, because D or Dref is a required tag. */
+        density = getDensity(materialElement);
+        
+        /* Get pressure or use default. */
+        try
+        {
+            pressure = getPressure(materialElement);
+        }
+        catch (JDOMException jde)
+        {
+            pressure = defaultPressure;
+        }
+        
+        /* Get temperature or use default. */
+        try
+        {
+            temperature = getTemperature(materialElement);
+        }
+        catch (JDOMException jde)
+        {
+            temperature = defaultTemperature;
+        }
+        
+        MaterialDefinitionType mdt = MaterialDefinitionType.getMaterialDefinitionType(materialElement);
+        
+        if ( mdt == MaterialDefinitionType.INVALID)
+        {
+            throw new RuntimeException("Material definition type was not valid.");
+        }
+        
+        String tagname = mdt.getTagName();
+        
+        if ( mdt == MaterialDefinitionType.ATOM )
+        {
+            double A = materialElement.getChild( tagname ).getAttribute("value").getDoubleValue();            
+            double Z = 0;
+            if ( materialElement.getAttribute("Z") != null )
+            {
+                Z = materialElement.getAttribute("Z").getDoubleValue();
+            }
+            else
+            {
+                throw new JDOMException("Required Z value missing for atom definition of material.");
+            }
+            
+            material = new Material(name,
+                    Z,
+                    A,
+                    density,
+                    state,
+                    pressure,
+                    temperature);
+        }
+        else
+        {
+            int nComponents = 0;
+            
+            nComponents = materialElement.getChildren(tagname).size();            
+            
+            material = new Material(name,
+                    nComponents,
+                    density,
+                    state,
+                    temperature,
+                    pressure);
+            
+            /* Fill in composite. */
+            if ( mdt == MaterialDefinitionType.COMPOSITE )
+            {
+                for ( Object o : materialElement.getChildren( tagname ) )
+                {
+                    org.jdom.Element compositeElement = (org.jdom.Element) o;
+                    int n = compositeElement.getAttribute("n").getIntValue();
+                    String elementName = compositeElement.getAttributeValue("ref");
+                    
+                    MaterialElement me = MaterialManager.getElement(elementName);
+                    
+                    if ( me != null )
+                    {
+                        material.addElement(me, n);
+                    }
+                    else
+                    {
+                        throw new RuntimeException("MaterialElement was not defined in MaterialManager: " + elementName);
+                    }
+                }
+            }
+            /* Fill in mass fraction. */
+            else
+            {
+                for ( Object o : materialElement.getChildren(tagname) )
+                {
+                    org.jdom.Element fractionElement = (org.jdom.Element) o;
+                    String refName = fractionElement.getAttributeValue("ref");
+                    double f = fractionElement.getAttribute("n").getDoubleValue();
+                    
+                    MaterialElement me = MaterialManager.getElement( refName );
+                    
+                    if ( me != null )
+                    {
+                        material.addElement(me, f);
+                    }
+                    else
+                    {
+                        Material m = MaterialManager.getMaterial(refName);
+                        
+                        if ( m != null )
+                        {
+                            material.addMaterial(m, f);
+                        }
+                        else
+                        {
+                            throw new JDOMException("fraction ref is undefined: " + refName);
+                        }
+                    }
+                }
+            }
+        }
+        
+        material.setFormula(formula);
+        
+        return material;
+    }    
+    
+    /** Get density from D or Dref tag. */
+    public double getDensity(org.jdom.Element materialElement) throws JDOMException
+    {
+        return getValueFromAttributeOrRef(materialElement, "D", _lcdd);
+    }
+    
+    /** Get pressure from P of Pref tag. */
+    public double getPressure(org.jdom.Element materialElement) throws JDOMException
+    {
+        return getValueFromAttributeOrRef(materialElement, "P", _lcdd);
+    }
+    
+    /** Get temperature from T or Tref tag. */
+    public double getTemperature(org.jdom.Element materialElement) throws JDOMException
+    {
+        return getValueFromAttributeOrRef(materialElement, "T", _lcdd);
+    }
+    
+    public double getValueFromAttributeOrRef(org.jdom.Element materialElement, String tagname, LCDD lcdd) throws DataConversionException, JDOMException
+    {
+        boolean haveLCDD = (lcdd == null);        
+        
+        org.jdom.Element tag = materialElement.getChild(tagname);
+        
+        double value = 0;
+        
+        /* FIXME: Use the unit attribute. */
+        if ( tag != null )
+        {
+            if ( tag.getAttribute("value") != null )
+            {
+                value = tag.getAttribute("value").getDoubleValue();
+            }
+            else
+            {
+                throw new JDOMException("Missing value attribute for " + tagname + " in material " + materialElement.getAttributeValue("name"));
+            }
+        }
+        else if ( haveLCDD )
+        {
+            org.jdom.Element tagref = materialElement.getChild(tagname);
+            
+            if ( tagref != null )
+            {
+                String ref = tagref.getAttributeValue("ref");
+                
+                Constant constant = lcdd.getDefine().getConstant(ref);
+                
+                if ( constant != null )
+                {
+                    value = constant.getConstantValue();
+                }
+                else
+                {
+                    throw new JDOMException(tagname + "ref's ref attribute does not refer to a defined constant: " + ref);
+                }
+            }
+            else
+            {
+                throw new JDOMException(tagname + " or " + tagname + "ref was not provided by the material: " + materialElement.getAttributeValue("name"));
+            }
+        }
+        else 
+        {
+            throw new JDOMException("No LCDD object to resolve the " + tagname + "ref.");
+        }
+        
+        return value;
+    }    
+   
+}
\ No newline at end of file

GeomConverter/src/org/lcsim/material
MaterialManager.java added at 1.1
diff -N MaterialManager.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialManager.java	30 Jun 2005 00:37:50 -0000	1.1
@@ -0,0 +1,94 @@
+/*
+ * MaterialManager.java
+ *
+ * Created on June 27, 2005, 5:14 PM
+ */
+
+package org.lcsim.material;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ * @author jeremym
+ */
+public class MaterialManager
+{
+    private static Map<String, Material> _materials = new HashMap<String, Material>();
+    
+    /** Creates a new instance of MaterialManager */
+    private MaterialManager()
+    {}
+    
+    static Map<String, Material> materials()
+    {
+        return _materials;
+    }
+    
+    static Map<String, MaterialElement> elements()
+    {
+        return MaterialElement.elements();
+    }
+    
+    static void addMaterial(Material material)
+    {
+        System.out.println("add material: " + material.getName() );
+        
+        if ( material == null ) 
+        {
+            throw new IllegalArgumentException("Material argument is null.");
+        }
+        
+        /* Only add the material if doesn't exist already. */
+        if ( getMaterial(material.getName()) == null )
+        {        
+            _materials.put(material.getName(), material);
+        }
+    }
+
+    static Material getMaterial(String materialName)
+    {
+        for ( Material m : materials().values())
+        {
+            System.out.println("defined material: " + m.getName());
+        }
+        
+        return _materials.get(materialName);
+    }    
+    
+    static MaterialElement getElement(String elementName)
+    {
+        //String realName = getElementNameFromRef(elementName);
+        
+        //System.out.println("Looking up element: " + realName);
+        
+        MaterialElement me = (MaterialElement) MaterialElement.elements().get(elementName);
+        
+        if ( me == null )
+        {
+            System.err.println("element not found: " + elementName);
+        }
+        
+        Object o;        
+        return me;
+    }        
+       
+    /*
+    public static String getElementNameFromRef(String ref) 
+    {       
+        String elemName;
+        if ( ref.contains("_e") )
+        {
+            elemName = ref.replace("_e","");
+            System.out.println("normalized ref: " + ref + " -> " + elemName);
+        }
+        else 
+        {
+            elemName = ref;        
+        }
+
+        return elemName;
+    }
+    */
+}

GeomConverter/src/org/lcsim/material
Material.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- Material.java	9 Jun 2005 03:30:22 -0000	1.1
+++ Material.java	30 Jun 2005 00:37:49 -0000	1.2
@@ -1,821 +1,286 @@
 package org.lcsim.material;
-import java.util.Random;
 
 import static java.lang.Math.sqrt;
+import static java.lang.Math.abs;
+import java.util.List;
+import java.util.ArrayList;
 
 /**
+ * @author jeremym
  *
+ * Material implementation, mostly based on G4Material.
  *
  */
 public class Material
 {
+    double _temp;
+    double _pressure;
+    double _density;
+    boolean _isElement;
+    public double _Zeff;
+    public double _Aeff;
+    public double _Neff;
+    MaterialState _state;
+    String _name;
+    String _formula;
+    
+    private List<MaterialElement> _elements = new ArrayList<MaterialElement>();
+    private List<Double> _massFractions = new ArrayList<Double>();
+    private List<Integer> _atoms = new ArrayList<Integer>();
+    
+    int _nComponents;
+    int _nComponentsMax;
+    int _nElements;
     
-    //
-    // Constructors. Only use these for creating vacuum.
-    // Use derived classes CEElement, CECompound and CEMixture for
-    // other materials.
-    //
     public Material()
     {
-        _Z=0;
+        _Zeff=0;
         _state = MaterialState.UNKNOWN;
         _isElement = false;
         _name = "Vacuum";
-    }
-    public Material(String name)
+    }        
+    
+    /* Construct base material with all info. */
+    public Material(String name,
+                    double z,
+                    double a,
+                    double density,
+                    MaterialState state,
+                    double temp,
+                    double pressure)
     {
-        _Z=0;
-        _state = MaterialState.UNKNOWN;
-        _isElement = false;
         _name = name;
-    }
-    public Material(Material mat)
-    {
-        _name             = mat._name;
-        
-        _Z                = mat._Z;
-        _A                = mat._A;
-        _ZoverA           = mat._ZoverA;
-        _rho              = mat._rho;
-        
-        _a                = mat._a;
-        _m                = mat._m;
-        _X0               = mat._X0;
-        _X1               = mat._X1;
-        _Cbar             = mat._Cbar;
-        _I                = mat._I;
-        _molecularWeight  = mat._molecularWeight;
-        _plen             = mat._plen;
-        _Cbar             = mat._Cbar;
-        _Xa               = mat._Xa;
-        _rho_STP          = mat._rho_STP;
-        _P                = mat._P;
-        _T                = mat._T;
-        _ASP              = mat._ASP;
-        _BSP              = mat._BSP;
-        _state            = mat._state;
-        _isElement       = mat._isElement;
-        
-        _radLength        = mat._radLength;
-        _intLength        = mat._intLength;
-        _Ec               = mat._Ec;
-        _rMoliere         = mat._rMoliere;
-        
-        _radLength_m      = mat._radLength_m;
-        _intLength_m      = mat._intLength_m;
-        _Ec_GeV           = mat._Ec_GeV;
-        _rMoliere_m       = mat._rMoliere_m;
-        
-        _F1               = mat._F1;
-        _F2               = mat._F2;
-        _F3               = mat._F3;
-        _F4               = mat._F4;
-        _F5               = mat._F5;
-        
-        _chi_c_sq_over_pl = mat._chi_c_sq_over_pl;
-        _chi_alpha_sq     = mat._chi_alpha_sq;
-        
-        _v_over_pl        = mat._v_over_pl;
-        
-        _cached_momentum  = mat._cached_momentum;
-        _cached_beta      = mat._cached_beta;
-        _cached_charge    = mat._cached_charge;
-        
-    }
-    //
-    // methods
-    //
-    
-    //
-    // Scatter vector q by a random amount based on calculated sigma of
-    // gaussian distribution in azimuth and using a flat distribution in phi.
-    // returns 1 if a scatter did occur.
-    //
-    // Scatter vector q by a random amount based on sigma, gaussian-distributed
-    // in azimuth and flat in phi. The algorithm is the one from Lynch and
-    // Dahl, NIMPR B58 (1991), 6-10, with a 2% accuracy.
-    //
-    // Need to make some variables static, or not give all wafers a new
-    // material, for a small speed increase
-    //
-    public boolean scatter(double[]  q,
-            double momentum,            // Momentum in GeV/c
-            double beta,                // v/c
-            double pathlength,          // Pathlength in m
-            double charge)              // Charge in elementary charge units
-    {
-        //   if ((physics & (CEM_MULTIPLE_SCATTERING | CEM_ENERGY_LOSS)) == 0) return(0);
-        
-        if ((charge == 0.0) || (pathlength == 0.0) || (momentum == 0.0)
-        || (_Z <= 0.0)) return false;
-        
-        
-        if (charge < 0.0) charge = - charge;
-        //
-        // recalculate stuff if needed
-        //
-        if ((Math.abs(momentum - _cached_momentum) > CEM_EPSILON) ||
-                (Math.abs(beta     - _cached_beta)     > CEM_EPSILON) ||
-                (Math.abs(charge   - _cached_charge)   > CEM_EPSILON))
-        {
-            _cached_momentum = momentum;
-            _cached_beta     = beta;
-            _cached_charge   = charge;
-            //
-            // Convert momentum to MeV
-            //
-            
-            momentum *= 1000.0;
-            
-            double f = charge / (momentum * beta);
-            _chi_c_sq_over_pl = _F1 * f * f;
-            
-            f = _F3 * charge * charge / (beta * beta);
-            _chi_alpha_sq = _F2 * (1.0 + f) / (momentum * momentum);
-            
-            _v_over_pl = _F4 * _chi_c_sq_over_pl / _chi_alpha_sq;
+        _density = density;
+        _state = state;
+        _temp = temp;
+        _pressure = pressure;
+        _formula = " ";
+                       
+        if ( z <= 0 )
+        {
+            throw new IllegalArgumentException("Z must be >= 0.");
         }
         
-        double v = _v_over_pl * pathlength;
-        //
-        // No scattering unless we have accumulated enough material
-        //
-        if (v < 1000.0) return false;
-        
-        double sigma_sq = _F5 * _chi_c_sq_over_pl * pathlength;
-        
-        if (v > 1.0e6) sigma_sq *= Math.log(v) - 1.0;
-        else           sigma_sq *= ((1.0 + v) / v) * Math.log(1.0 + v) - 1.0;
-        
-        double sigma = Math.sqrt(sigma_sq);
-        double theta = sigma * _ran.nextGaussian();
-        
-        double sintheta = Math.sin(theta);
-        double costheta = Math.cos(theta);
-        //
-        // Since theta comes back either positive or negative, we only need
-        // to generate phi in PI rather than two PI.
-        //
-        double phi = Math.PI * _ran.nextDouble();
-        double sinphi = Math.sin(phi);
-        double cosphi = Math.cos(phi);
-        
-        double qx = sintheta * cosphi;
-        double qy = sintheta * sinphi;
-        double qz = costheta;
-        //
-        // The following algorithm is also used in EGS4 (routine UPHI).
-        //
-        double z        = q[2];
-        double cosalpha = z;
-        double sinalpha = Math.sqrt(1.0 - cosalpha * cosalpha);
-        
-        //   if (physics & CEM_MULTIPLE_SCATTERING) {
-        if (sinalpha < 1.0e-10)
-        {
-            q[0] = qx;
-            q[1] = qy;
-            q[2] = qz;
-        }
-        else
-        {
-            //
-            // transform back to q
-            //
-            double x = q[0];
-            double y = q[1];
-            
-            double cosbeta = x / sinalpha;
-            double sinbeta = y / sinalpha;
-            double qxz = qx * z;
-            
-            q[0] = qxz * cosbeta  + qz * x - qy * sinbeta;
-            q[1] = qxz * sinbeta  + qz * y + qy * cosbeta;
-            q[2] = -qx * sinalpha + qz * z;
-        }
-        //   }
-        
-        return true;
-    }
-    //
-    // Return the energy loss. Uses Sternheimer/Peierls
-    //
-    public double energyLoss(double beta,          // v/c
-            double restE,         // Rest energy in GeV
-            double pathlength,    // Pathlength in m
-            double charge )  // Charge in elementary charge units
-    {
-        //   if (((physics & CEM_ENERGY_LOSS) == 0) || (Z <= 0.0) || (charge == 0.0) ||
-        //       (beta <= 0.0) || (restE <= 0.0)) return(0.0);
-        if((_Z <= 0.0) || (charge == 0.0) ||  (beta <= 0.0) || (restE <= 0.0)) return 0.;
-        double QsQ = charge * charge;
-        
-        double betasq = beta * beta;
-        double bgsq   = betasq / (1.0 - betasq);
-        //
-        //                                                      2
-        // X = log10(beta * gamma) = 0.5 * log10( (beta * gamma) )
-        // (saves a sqrt)
-        //
-        double X = 0.5 * Math.log(bgsq)/2.3026;
-        //
-        // Eq. 1-2: delta
-        //
-        double delta;
-        if (X < _X0)
+        _Zeff = z;
+        
+        if ( a <= 0 )
         {
-            delta = 0.0;
+            throw new IllegalArgumentException("A must be >= 0.");        
         }
-        else
+        
+        _Aeff = a;
+        
+        _nComponents = _nComponentsMax = _nElements = 1;
+        _isElement = true;
+        
+        MaterialElement element = MaterialManager.getElement(name);
+        
+        if ( element == null )
         {
-            delta = 4.6052 * X - _Cbar;
-            if (X < _X1)
-            {
-                double x1minusx = _X1 - X;
-                delta += _a * Math.pow(x1minusx, _m);
-            }
+            throw new RuntimeException("Corresponding element not found for material by name: " + name);
         }
-        //
-        // In the following, remember that 2log(p/m0 c) = 4.6052 * X
-        //
-        double dE = 0.0;
-        //
-        // Use average energy loss, because we don't do delta rays.
-        // The pathlength (in g/cm^2) is computed using the material's
-        // actual rho so the Sternheimer "eta" correction is implicit.
-        //
-        double s = 0.000511 / restE;
-        double Wmax = 1.022 * bgsq / (1.0 + s * (2.0 * Math.sqrt(1.0 + bgsq) + s));
-        //
-        // Eq. 55: Average energy loss in MeV:
-        //
-        dE = QsQ * _ASP * pathlength / betasq * (_BSP + 0.693 + 4.6052 * X + Math.log(Wmax) -
-                2.0 * betasq - delta);
-        //
-        // Just in case we need these sometime, here are the other equations:
-        //
-        //   double W0 = 1.0; // MeV
-        //
-        // Eq. 60: Restricted energy loss in MeV:
-        //
-        //   dE = QsQ * ASP * pathlength / betasq * (BSP + 0.693 + 4.6052 * X + log(W0) -
-        //                                           betasq - delta);
-        //
-        // Eq. 63: Most probable energy loss (Landau) in MeV for thin material is:
-        //
-        //   dE = QsQ * ASP * pathlength / betasq * (BSP + 0.891 + 4.6052 * X + log(ASP * t / betasq) -
-        //                                           betasq - delta);
-        //
-        dE *= 0.001;   // in GeV
-        if (dE < 0.0) dE = 0.0;
-        return dE;
-    }
-    
-    public boolean isMaterial()
-    { return(_Z > 0.0); }
-    //
-    // Set material name
-    //
-    public void setName(String name )
+        
+        _elements.add(element);
+        _massFractions.add(1.0);                
+    }
+    
+    public Material(String name,
+                    int nComponents,
+                    double density,                    
+                    MaterialState state,
+                    double temp,
+                    double pressure
+                    )
     {
         _name = name;
+        _density = density;
+        _state = state;
+        _temp = temp;
+        _pressure = pressure;
+        _formula = " ";
+        
+        if ( nComponents <= 0 )
+        {
+            throw new IllegalArgumentException("nComponents must be >= 0.");
+        }
+        
+        _nComponentsMax = nComponents;
+        _nComponents = _nElements = 0;
+        _isElement = false;                
     }
-    public void addName(String name)
+    
+    int getNumberOfElements()
     {
+        return _nElements;
     }
-    //
-    // Get information about this material
-    //
-    public String name( )
-    { return(_name); }
-    
-    public int               getNumberOfParts()
-    {
-        return 1;
-    }
-    public Material          partialMaterial(int index)
-    {
-        return this;
-    }
-    public double            getPartialVolume(int index)
-    {
-        return 0.;
-    }
-    public double            getPartialWeight(int index)
-    {
-        return 0.;
-    }
-    
-    
     
+    List<MaterialElement> getElements()
+    {
+        return _elements;
+    }
     
+    List<Double> getMassFractions()
+    {
+        return _massFractions;
+    }
     
-    double rho( )
-    { return _rho;             };  // density (g/cc)
-    double Z()
-    { return _Z;               };  // "Z"
-    double A()
-    { return _A;               };  // "A"
-    double ZoverA()
-    { return _ZoverA;          };  // Z/A
-    double I()
-    { return _I;               };  // excitation potential (eV)
-    double P()
-    { return _P;               };  // pressure (atm)
-    double T()
-    { return _T;               };  // temperature (K)
-    double MolWeight()
-    { return _molecularWeight; };  // mol. weight (g/mol)
-    MaterialState   state()
-    { return _state;           };  // gas or solid/liquid
-    double RadLength()
-    { return _radLength;       };  // rad. length (g/cmsq)
-    double RadLength_m()
-    { return _radLength_m;     };  // rad. length (m)
-    double IntLength()
-    { return _intLength;       };  // int. length (g/cmsq)
-    double IntLength_m()
-    { return _intLength_m;     };  // int. length (m)
-    double Ec()
-    { return _Ec;              };  // crit. energy (MeV)
-    double Ec_GeV()
-    { return _Ec_GeV;          };  // crit. energy (GeV)
-    double MoliereRadius()
-    { return _rMoliere;      };  // Moliere radius (g/cmsq)
-    double MoliereRadius_m()
-    { return _rMoliere_m;  };  // Moliere radius (m)
-    //
-    // Turn multiple scattering/energy loss on/off
-    //
-    public static void setInteracting(int p)
-    { _physics = p; };
-    public static int  interacting()
-    { return _physics; };
-    
-    
-    
-    protected String _name;                    // optional name of the material
-    //
-    // Commonly needed quantities
-    //
-    // Z is only used for multiple scattering.
-    // Z is the atomic number in units of e.
-    // In compounds, it is calculated as an effective Z using
-    //
-    //    Z (Z + 1) n = Sum Zi (Zi + 1) ni
-    //
-    // where Zi are the effective Z's and ni the partial number densities
-    // of the constituent materials: ni = (Ni/NA)/V (mol/cc), and n is the
-    // overal number density of compound n = (N/NA)/V = (Sum Ni / NA) / V
-    // = Sum ni.
-    //
-    protected double _Z;
-    //
-    // A is inly used for multiple scattering.
-    // A is the atomic weight of the material in g/mol.
-    // For compounds it is calculated as
-    //
-    //     A = rho / n = rho / Sum ni
-    //
-    protected double _A;
-    //
-    // ZoverA is only used for energy loss.
-    // For elements, it is simply Z / A, but for compounds it is
-    // computed as
-    //
-    //     <Z / A> = Sum ni Zi  /  Sum ni Ai
-    //
-    // where the ni are as defined above.
-    //
-    protected double _ZoverA;
-    //
-    // rho is the material density in g/cc. For compounds it is
-    // calculated as:
-    //
-    //     rho = Sum rho_i Vi / V
-    //
-    protected double _rho;
-    //
-    // molecularWeight is the molecular weight of the material in g/mol
-    // and is equal to A for simple elements (but for e.g. O2 it is
-    // 2 * A).
-    //
-    protected double _molecularWeight;
-    //
-    // state is the state of the material: unknown, solid or gas.
-    //
-    //cng  should be enum
-    //
-    protected MaterialState _state;
-    //
-    // Is this an element?
-    //
-    protected boolean   _isElement;
-    //
-    // Set constants in this material for multiple scattering
-    //
-    ////
-    //
-    // Derived classes must set Z, A, rho, state, is_element, P, T and I.
-    // They must then call setMultipleScattering() and setSternheimerPeierls()
-    // to set the rest.
-    //
-    ////
-    protected void setMultipleScattering()
-    {
-        _F1 = 0.157 * _Z * (_Z + 1) / _A;
-        _F2 = 2.007e-5 * Math.pow(_Z, 2.0/3.0);
-        _F3 = 3.34 * _Z * _Z * CEM_ALPHA_FINE_SQ;
-        
-        double F = 0.98;
-        _F4 = 0.5 / (1.0 - F);
-        _F5 = 1.0 / (1.0 + F * F);
-        
-        _cached_momentum = -1.0;
-        _cached_beta     = -1.0;
-        _cached_charge   = -1000.0;
-        
-    }
-    //
-    // Set constants in this material for energy loss
-    //
-    protected void setSternheimerPeierls()
-    {
-        if (_Z <= 0.0) return;
-        //
-        // This section calculates the coefficients for the most probable energy
-        // loss according to the general algorithm developed by Sternheimer and
-        // Peierls[1]. The procedure results a.o. in the computation of five
-        // density effect parameters a, m, X0, Cbar and X1, such that the density
-        // effect contribution can be written as
-        //                                       m
-        // delta(X) = 4.6052 X - Cbar + a (X1 - X)       (X0 < X < X1)
-        //          = 4.6052 X - Cbar                    (X > X1)
-        //          = 0                                 (X < X0)
-        //
-        // Since a parametrization of the mean excitation potential is used,
-        // a computation of these parameters for each substance individually is
-        // more accurate[2], so where available, tabulated results should be
-        // used.
-        //
-        // References:
-        // 1. Sternheimer & Peierls, Phys. Rev. B 3, 3681 (1971).
-        // 2. Sternheimer, Seltzer & Berger, Phys Rev B 26, 6067 (1982)
-        //
-        // All formulas quoted below are from Ref 1.
-        //
-        // - Note that in ref 1 on page 3687, there is the potential for confusion
-        // - about NTP and STP. It reads: "It should be emphasized [...] all pertain
-        // - to the gas at normal temperature (0 C) and pressure (1 atm)." This
-        // - is commonly referred to as STP ("standard temperature and pressure").
-        // - NTP ("normal temperature and pressure") is 25 C, 1 atm.
-        //
-        // Eta = rho(P, T)/rho(STP), i.e. the factor the STP density needs to
-        // be multiplied by to get the already calculated density rho for temperature
-        // T and pressure P:
-        //
-        double eta = 1.0;
-        _rho_STP = _rho;
-        if (_state.equals(MaterialState.GAS) )
-        {
-            eta = _P * (273.15 / _T);
-            _rho_STP = _rho / eta;
-        }
-        //
-        // Eq.  5: plasma energy (eV).
-        // All of this must be calculated (for gasses) at STP first (for solids and
-        // liquids it doesn't matter, or at least this assumes so). At other than
-        // STP there are density corrections to Cbar, X0 and X1, and they are taken
-        // into account using eta at the end.
-        //
-        _plen = 28.8 * Math.sqrt(_rho_STP * _ZoverA);
-        //
-        // Eq.  3: C-bar = -C
-        //
-        _Cbar = 2.0 * Math.log(_I / _plen) + 1.0;
-        //
-        // Eq.  8: Xa = Cbar / 4.6052
-        //
-        _Xa = _Cbar / 4.6052;
-        
-        if (_state.equals( MaterialState.GAS) )
-        {
-            //
-            // Eq. 29-30: X1 for gasses
-            //
-            if (_Cbar < 12.25) _X1 = 4.0;
-            else              _X1 = 5.0;
+    /**
+     * Add element by atom count.
+     *
+     * Based on G4Material::AddElement() .
+     */
+    void addElement(MaterialElement element,
+                    int nAtoms)
+    {
+        if ( _nElements < _nComponentsMax )
+        {
+            _elements.add(element);
+            _atoms.add( _nElements, nAtoms);
+            _nComponents = ++_nElements;
         }
         else
         {
-            //
-            // Eq. 27-28: X1 for solids/liquids
-            //
-            if (_I < 100.0)    _X1 = 2.0;
-            else              _X1 = 3.0;
-        }
-        //
-        // m
-        //
-        _m = 3.0;
-        
-        if (_state.equals(MaterialState.GAS) )
-        {
-            //
-            // Eq. 37-42: X0 for gasses
-            //
-            if      (_Cbar < 10.0)   _X0 = 1.6;
-            else if (_Cbar < 10.5)   _X0 = 1.7;
-            else if (_Cbar < 11.0)   _X0 = 1.8;
-            else if (_Cbar < 11.5)   _X0 = 1.9;
-            else if (_Cbar < 13.804) _X0 = 2.0;
-            else                    _X0 = 0.326 * _Cbar - 2.5;
+            throw new RuntimeException("Attempting to add more than declared number of elements for this material: " + _name);
         }
-        else
+        
+        if ( isFilled() )
         {
-            //
-            // Eq. 33-36: X0 for solids/liquids
-            //
-            if (_I < 100.0)
+            double Zmol = 0;
+            double Amol = 0;
+            
+            int atomCnt = 0;
+            for ( MaterialElement e : _elements )
             {
-                if (_Cbar < 3.681) _X0 = 0.2;
-                else              _X0 = 0.326 * _Cbar - 1.0;
-                _X1 = 2.0;
+                Amol += _atoms.get(atomCnt) * e.getA();
+                ++atomCnt;
             }
-            else
+            
+            int massCnt = 0;
+            for ( MaterialElement ee : _elements )
             {
-                if (_Cbar < 5.215) _X0 = 0.2;
-                else              _X0 = 0.326 * _Cbar - 1.5;
-                _X1 = 3.0;
-            }
-        }
-        //
-        // Eq.  9: a
-        //
-        _a = 4.6052 * (_Xa - _X0) / Math.pow(_X1 - _X0, _m);
-        //
-        // Eq. 25: A (MeV / (g /cm2))
-        //
-        _ASP = 0.1536 * _ZoverA;
-        //
-        // Eq. 26: B
-        //
-        _BSP = Math.log(511.0e9 / (_I * _I));
-        //
-        // Eta, the factor the density needs to be multiplied by to
-        // correct for temperature and pressure to not be at STP:
-        //
-        if (_state.equals(MaterialState.GAS) )
-        {
-            double _eta_corr_1 = 0.5 * Math.log(eta)/2.3026; // recall log10(x) = log(x)/log(10);
-            double _eta_corr_2 = 4.6052 * _eta_corr_1;
-            //
-            // Eq. 47,48,50: If gas under pressure (1.e. eta != 1.0) adjust paramters
-            //
-            _Cbar -= _eta_corr_2;
-            _X1   -= _eta_corr_1;
-            _X0   -= _eta_corr_1;
+                _massFractions.add(_atoms.get(massCnt) * ee.getA() / Amol);
+                ++massCnt;
+            }                        
         }
     }
     
-    public String getName()
+    /** Add element by fraction of mass. */
+    void addElement(MaterialElement element,
+                    double fraction)
     {
-        return _name;
-    }
-    
-    public void print()
-    {
-        if (_Z <= 0.0)
+        if ( _nComponents < _nComponentsMax )
         {
-            System.out.printf("CEMaterial: === vacuum ===\n");
-        }
-        else
-        {
-            if (_state == MaterialState.GAS)
-            {
-                System.out.printf("CEMaterial: === %s (gas at P=%g atm and T=%g K) ===\n", getName(), _P, _T);
-            }
-            else if (_state == MaterialState.CONDENSED)
+            int elCnt = 0;
+            while (( elCnt < _nElements ) && element != _elements.get(elCnt)) elCnt++;
+            
+            /* Element already exists.  Increase the mass fraction. */
+            if (elCnt < _nElements)
             {
-                System.out.printf("CEMaterial: === %s (solid or liquid at density %g g/cc) ===\n", getName(), _rho);
+                double currFrac = _massFractions.get(elCnt);
+                currFrac += fraction;
+                _massFractions.add(elCnt, currFrac);
             }
+            /* Element does not exist.  Add a new mass fraction. */
             else
             {
-                System.out.printf("CEMaterial: === %s (treated as solid at density %g g/cc) ===\n", getName(), _rho);
+                _elements.add(element);
+                _massFractions.add(elCnt, fraction);
+                ++_nElements;
             }
-            System.out.printf("   ----- Composition: -----\n");
-            printComposition(1);
-            System.out.printf("   ----- Properties: -----\n");
-            System.out.printf("            Z = %.4g   A = %.4g   Average Z/A = %.4g   Molecular weigt = %.4g g/mol\n\n",
-                    _Z,         _A,          _ZoverA,       _molecularWeight);
-            System.out.printf("            Average density = %10.4g g/cc     Density at STP = %10.4g g/cc\n",
-                    _rho,                             _rho_STP);
-            System.out.printf("            Ion. potential  = %10.4g eV       Plasma energy  = %10.4g eV\n\n",
-                    _I,                               _plen);
-            System.out.printf("            Radiation length            = %10.4g g/cm2 or %10.4g cm\n",
-                    _radLength,                           _radLength_m * 100.0);
-            System.out.printf("            Hadronic interaction length = %10.4g g/cm2 or %10.4g cm\n\n",
-                    _intLength,                           _intLength_m * 100.0);
-            System.out.printf("            Moliere radius     = %10.4g g/cm2 or %10.4g cm\n",
-                    _rMoliere,                            _rMoliere_m  * 100.0);
-            System.out.printf("            Critical energy    = %10.4g MeV\n",
-                    _Ec);
-            System.out.printf("   ----- Sternheimer/Peierls coefficients: -----\n");
-            System.out.printf("            A = %10.4g   B = %10.4g   Cbar = %10.4g   Xa = %10.4g\n",
-                    _ASP,         _BSP,         _Cbar,           _Xa);
-            System.out.printf("            a = %10.4g   m = %10.4g   X0   = %10.4g   X1 = %10.4g\n",
-                    _a,           _m,           _X0,             _X1);
-            System.out.printf("   ----- Sample dEdx (MeV) in 1 g/cm^2 (%g cm) material -----\n", 1.0 / _rho);
-            
-            double me  = 0.000511;
-            double mmu = 0.105;
-            double mp  = 0.935;
-            double p1  = 0.1;
-            double p2  = 1.0;
-            double p3  = 10.0;
-            double p4  = 100.0;
-            System.out.printf("   p (MeV)   : %10.4g %10.4g %10.4g %10.4g\n", p1 * 1000., p2 * 1000.,
-                    p3 * 1000., p4 * 1000.);
-            System.out.printf("   - - - - - + - - - - - - - - - - - - - - - - - - - - - - -\n");
-            System.out.printf("   dE/dx e   : %10.4g %10.4g %10.4g %10.4g\n",
-                    1000.0 * energyLoss(p1 / sqrt(me * me + p1 * p1), me, 1.0, 1.0),
-                    1000.0 * energyLoss(p2 / sqrt(me * me + p2 * p2), me, 1.0, 1.0),
-                    1000.0 * energyLoss(p3 / sqrt(me * me + p3 * p3), me, 1.0, 1.0),
-                    1000.0 * energyLoss(p4 / sqrt(me * me + p4 * p4), me, 1.0, 1.0) );
-            System.out.printf("   dE/dx mu  : %10.4g %10.4g %10.4g %10.4g\n",
-                    1000.0 * energyLoss(p1 / sqrt(mmu * mmu + p1 * p1), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(p2 / sqrt(mmu * mmu + p2 * p2), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(p3 / sqrt(mmu * mmu + p3 * p3), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(p4 / sqrt(mmu * mmu + p4 * p4), mmu, 1.0, 1.0) );
-            System.out.printf("   dE/dx p   : %10.4g %10.4g %10.4g %10.4g\n",
-                    1000.0 * energyLoss(p1 / sqrt(mp * mp + p1 * p1), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(p2 / sqrt(mp * mp + p2 * p2), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(p3 / sqrt(mp * mp + p3 * p3), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(p4 / sqrt(mp * mp + p4 * p4), mp, 1.0, 1.0) );
-            double bg1 = 0.3;
-            double bg2 = 1.0;
-            double bg3 = 3.0;
-            double bg4 = 10.0;
-            double bg5 = 100.0;
-            double bg6 = 1000.0;
-            System.out.printf("             + \n");
-            System.out.printf("   betagamma : %10.4g %10.4g %10.4g %10.4g %10.4g %10.4g\n", bg1, bg2, bg3, bg4,
-                    bg5, bg6);
-            System.out.printf("   - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n");
-            System.out.printf("   dE/dx e   : %10.4g %10.4g %10.4g %10.4g %10.4g %10.4g\n",
-                    1000.0 * energyLoss(sqrt(bg1 * bg1 / (1.0 + bg1 * bg1)), me, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg2 * bg2 / (1.0 + bg2 * bg2)), me, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg3 * bg3 / (1.0 + bg3 * bg3)), me, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg4 * bg4 / (1.0 + bg4 * bg4)), me, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg5 * bg5 / (1.0 + bg5 * bg5)), me, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg6 * bg6 / (1.0 + bg6 * bg6)), me, 1.0, 1.0) );
-            System.out.printf("   dE/dx mu  : %10.4g %10.4g %10.4g %10.4g %10.4g %10.4g\n",
-                    1000.0 * energyLoss(sqrt(bg1 * bg1 / (1.0 + bg1 * bg1)), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg2 * bg2 / (1.0 + bg2 * bg2)), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg3 * bg3 / (1.0 + bg3 * bg3)), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg4 * bg4 / (1.0 + bg4 * bg4)), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg5 * bg5 / (1.0 + bg5 * bg5)), mmu, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg6 * bg6 / (1.0 + bg6 * bg6)), mmu, 1.0, 1.0) );
-            System.out.printf("   dE/dx p   : %10.4g %10.4g %10.4g %10.4g %10.4g %10.4g\n",
-                    1000.0 * energyLoss(sqrt(bg1 * bg1 / (1.0 + bg1 * bg1)), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg2 * bg2 / (1.0 + bg2 * bg2)), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg3 * bg3 / (1.0 + bg3 * bg3)), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg4 * bg4 / (1.0 + bg4 * bg4)), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg5 * bg5 / (1.0 + bg5 * bg5)), mp, 1.0, 1.0),
-                    1000.0 * energyLoss(sqrt(bg6 * bg6 / (1.0 + bg6 * bg6)), mp, 1.0, 1.0) );
-        }
-    }
-    
-    
-    public void printComposition()
-    {
-        System.out.printf("Material %s consists of:\n", _name);
-        printComposition(1);
-        return;
+        }
+        else
+        {
+            throw new RuntimeException("Attempting to add more than declared number of components to material: " + getName() );
+        }
+        
+        if ( isFilled() )
+        {
+            checkMassSum();            
+        }
     }
     
-    public void printComposition(int level)
+    /** Add material by fraction of mass. */
+    void addMaterial(Material material,
+                     double fraction)
     {
-        if (getNumberOfParts() == 1)
+        if ( _atoms.size() > 0 )
         {
-            System.out.println("100% "+ _name);
+            throw new RuntimeException("Material is already defined by atoms: " + getName());
         }
-        else
+        
+        if ( _nComponents < _nComponentsMax )
         {
-            for (int i = 0; i < getNumberOfParts(); i++)
+            /* Loop over elements in the material. */
+            for ( int i = 0; i < material.getNumberOfElements(); i++)
             {
-                System.out.printf("%*s %6.3g%% %s (by volume)", level * 3, "", getPartialVolume(i) * 100.0,
-                        partialMaterial(i).getName());
-                if (partialMaterial(i).getNumberOfParts() == 1)
+                MaterialElement element = material.getElements().get(i);
+                int elCnt = 0;
+                /* Find the element. */
+                while (elCnt < _nElements && element != _elements.get(elCnt))
                 {
-                    System.out.printf("\n");
+                    ++elCnt;
+                }
+                if ( elCnt < _nElements )
+                {
+                    double currFrac = _massFractions.get(elCnt);
+                    currFrac += fraction;
+                    _massFractions.add(elCnt, currFrac);
                 }
                 else
                 {
-                    System.out.printf(", which consists of:\n");
-                    partialMaterial(i).printComposition(level + 1);
+                    _elements.add(element);
+                    
+                    /**
+                     * Add the fraction of this element, normalized to the percentage in the material's
+                     * mass fraction list.
+                     */
+                    _massFractions.add(elCnt, fraction * material.getMassFractions().get(i));
+                    ++_nElements;
                 }
             }
+            ++_nComponents;
+        }
+        else
+        {
+            throw new RuntimeException("Attempting to add more than declared number of components for material: " + getName() );
+        }
+        
+        if ( isFilled() )
+        {
+            checkMassSum();            
         }
-        return;
     }
-   
     
-    // attributes
+    private boolean isFilled()
+    {
+        return _nElements == _nComponentsMax;
+    }
     
-    //
-    // Radiation length
-    //
-    protected double _radLength;
-    protected double _radLength_m;
-    //
-    // Interaction length
-    //
-    protected double _intLength;
-    protected double _intLength_m;
-    //
-    // Sternheimer parameters
-    //
-    protected double _I;                       // mean excitation potential
-    protected double _plen;                    // plasma energy in eV
-    protected double _Cbar;                    // Sternheimer/Peierls variables
-    protected double _Xa;
-    protected double _a;
-    protected double _m;
-    protected double _X0;
-    protected double _X1;
-    protected double _ASP;
-    protected double _BSP;
-    protected double _rho_STP;                 // density at STP (0 C, 1 atm)
-    //
-    // Pressure/temperature
-    //
-    protected double _P;                       // Pressure in atm
-    protected double _T;                       // Temperature in K
-    
-    //
-    // Grindhammer/Peters shower simulation parameters
-    //
-    protected double _Ec;                      // Critical energy in MeV
-    protected double _Ec_GeV;                  // Critical energy in GeV
-    protected double _rMoliere;                // Moliere radius in g/cmsq
-    protected double _rMoliere_m;              // Moliere radius in m
-    
-    
-    //
-    // Calculated values for multiple scattering.
-    //
-    private double _F1, _F2, _F3, _F4, _F5;      // precalculated values
-    //
-    // Values that are recalculated only when momentum and/or particle change
-    //
-    private double _chi_c_sq_over_pl;        // square of Moliere characteristic angle
-    // divided by pathlength
-    private double _chi_alpha_sq;            // square of Moliere screening angle
-    
-    private double _v_over_pl;               // 0.5 Omega/(1 - F) / pathlength
-    // with Omega * pathlength =
-    // chi_c_sq_over_x/chi_alpha_sq
-    // the mean number of scatters
-    //
-    // Used to check if recalculation is needed
-    //
-    private double _cached_momentum;
-    private  double _cached_beta;
-    private double _cached_charge;
-    //
-    // Flag to turn energy loss/mult. sc. on or off
-    //
-    private static int _physics;
-    
-    private Random _ran = new Random();
-    
-    // constants
-    public static double ALPHA_EM            =0.00729735252;     // 1/137.036
-    public static double CEM_ALPHA_FINE_SQ   =0.0000532513538;   // (1/137.036)^2
-    public static double CEM_EPSILON         =1.0e-6;            // GeV or electron charge unit
-    
-    public static double AvogN               =6.022136736e23;    // 1/moles
-    public static double r_e                 =2.8179409238e-15;  // m
-    public static double Mec2                =0.5109990615e-3;   // GeV
-    public static double Mec2_2              =1.02199812e-3;     // GeV
-    
-    //    public static int CEM_STATE_UNKNOWN = 2;
-    //    public static int CEM_STATE_CONDENSED = 0;
-    //    public static int CEM_STATE_GAS = 2;
[truncated at 1000 lines; 45 more skipped]

GeomConverter/src/org/lcsim/material
MaterialState.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- MaterialState.java	9 Jun 2005 03:30:22 -0000	1.1
+++ MaterialState.java	30 Jun 2005 00:37:50 -0000	1.2
@@ -1,4 +1,7 @@
 package org.lcsim.material;
+
+import org.jdom.JDOMException;
+
 /** An enumeration class providing MaterialState enums
  * @author Norman A. Graf
  */
@@ -6,6 +9,11 @@
 {
     private String _stat;
     
+    public final static MaterialState UNKNOWN = new MaterialState("unknown");
+    public final static MaterialState GAS = new MaterialState("gas");
+    public final static MaterialState LIQUID = new MaterialState("liquid");
+    public final static MaterialState SOLID = new MaterialState("solid");
+    
     private MaterialState(String stat)
     {
         _stat = stat;
@@ -24,14 +32,37 @@
         return className+" "+_stat;
     }
     
-    /** State is undefined.
-     */
-    public final static MaterialState UNKNOWN = new MaterialState("UNKNOWN");
-    /** Gas.
-     */
-    public final static MaterialState GAS = new MaterialState("GAS");
-    /** Condensed.
-     */
-    public final static MaterialState CONDENSED = new MaterialState("CONDENSED");
-    
+    static MaterialState getMaterialState(org.jdom.Element materialElement) throws JDOMException
+    {
+        if ( materialElement == null )
+        {
+            throw new IllegalArgumentException("materialElement argument is null.");
+        }
+        
+        MaterialState state = MaterialState.UNKNOWN;
+                
+        if ( materialElement.getAttribute("state") != null )
+        {
+            String stateStr = materialElement.getAttributeValue("state");
+                            
+            if ( stateStr.equals("solid") )
+            {
+                state = MaterialState.SOLID;
+            }
+            else if ( stateStr.equals("gas") )
+            {
+                state = MaterialState.GAS;
+            }
+            else if ( stateStr.equals("liquid") )
+            {
+                state = MaterialState.LIQUID;
+            }
+            else 
+            {
+                throw new JDOMException("Not a valid material state: " + stateStr);
+            }
+        }
+        
+        return state;
+    }        
 }
\ No newline at end of file

GeomConverter/test/org/lcsim/material
MaterialFromGDMLCnvTest.java added at 1.1
diff -N MaterialFromGDMLCnvTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialFromGDMLCnvTest.java	30 Jun 2005 00:37:51 -0000	1.1
@@ -0,0 +1,50 @@
+/*
+ * MaterialCnvTest.java
+ *
+ * Created on June 29, 2005, 2:27 PM
+ */
+
+package org.lcsim.material;
+
+import java.io.IOException;
+import java.net.URL;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.jdom.JDOMException;
+
+/**
+ *
+ * @author jeremym
+ */
+public class MaterialFromGDMLCnvTest extends TestCase
+{
+    public static URL defURL = MaterialFromGDMLCnvTest.class.getResource("MaterialFromGDMLCnvTest.xml");
+    
+    /** Creates a new instance of MaterialCnvTest */
+    public MaterialFromGDMLCnvTest()
+    {}
+    
+    public MaterialFromGDMLCnvTest(String testName)
+    {
+        super(testName);
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite(MaterialFromGDMLCnvTest.class);
+    }
+    
+    public void test_cnvNoLCDD() throws IOException, JDOMException
+    {
+        MaterialElementData med = new MaterialElementData();
+        XMLMaterialManager f = XMLMaterialManager.create(defURL);                          
+        
+        for ( MaterialElement me : MaterialManager.elements().values() )
+        {
+            System.out.println("defined elem: " + me.name());
+        }
+        
+        f.makeMaterials(null);
+    }
+}

GeomConverter/test/org/lcsim/material
MaterialFromGDMLCnvTest.xml added at 1.1
diff -N MaterialFromGDMLCnvTest.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialFromGDMLCnvTest.xml	30 Jun 2005 00:37:51 -0000	1.1
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<materials>
+
+      <material name="TestFraction">
+	<D type="density" unit="g/cm3" value="1.0"/>
+	<fraction n="0.25" ref="N"/>
+	<fraction n="0.25" ref="O"/>
+	<fraction n="0.50" ref="Ar"/>
+      </material>
+
+      <material name="TestCompositeElementsOnly">
+	<D type="density" unit="g/cm3" value="1.0"/>
+	<composite n="1" ref="N"/>
+	<composite n="1" ref="O"/>
+	<composite n="2" ref="Ar"/>
+      </material>
+
+      <material name="TestFractionRefComplex">
+	<D type="density" unit="g/cm3" value="1.0"/>
+	<fraction n="0.5" ref="TestFraction" />
+	<fraction n="0.5" ref="TestCompositeElementsOnly" />
+      </material>
+
+      <material name="N" Z="1.0">
+	<D type="density" unit="g/cm3" value="0.0012"/>
+	<atom value="1.0" />
+      </material>
+
+</materials>
\ No newline at end of file

GeomConverter/test/org/lcsim/material
ElementDataToGDMLTest.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ElementDataToGDMLTest.java	9 Jun 2005 03:35:33 -0000	1.1
+++ ElementDataToGDMLTest.java	30 Jun 2005 00:37:51 -0000	1.2
@@ -28,6 +28,6 @@
     
     public static void testWrite() throws java.io.FileNotFoundException, java.io.IOException
     {        
-        ElementDataToGDML.write();
+        MaterialElementDataToGDMLCnv.write();
     }
 }
CVSspam 0.2.8