Print

Print


Commit in GeomConverter on MAIN
src/org/lcsim/material/MaterialCalculator.java+82added 1.1
                      /Material.java+63-321.7 -> 1.8
                      /MaterialElement.java+39-141.4 -> 1.5
                      /MaterialManager.java+261.4 -> 1.5
                      /RadiationLengthCalculator.java-711.1 removed
test/org/lcsim/material/MaterialManagerTest.java+1-11.1 -> 1.2
+211-118
1 added + 1 removed + 4 modified, total 6 files
Revised NIL and RL calcs based on Matprop.  Looks much better.  Left in Tsai and coulomb correction calcs but currently unused.

GeomConverter/src/org/lcsim/material
MaterialCalculator.java added at 1.1
diff -N MaterialCalculator.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ MaterialCalculator.java	1 Jul 2005 22:36:00 -0000	1.1
@@ -0,0 +1,82 @@
+/*
+ * CoulombCorrectionCalculator.java
+ *
+ * Created on July 1, 2005, 11:18 AM
+ */
+
+package org.lcsim.material;
+
+import static java.lang.Math.log;
+import static java.lang.Math.pow;
+
+/**
+ *
+ * @author jeremym
+ */
+abstract public class MaterialCalculator
+{
+    /* Coulomb correction factors from G4Element via Phys Rev. D50 3-1 (1994) page 1254 */
+    public static final double[] COULOMB_CORRECTIONS = { 0.0083, 0.20206, 0.0020, 0.0369 };
+        
+    /* Fine structure constant from PDG July 2004, Table 1.1 */
+    public static final double FINE_STRUCTURE_CONSTANT = 1 / 137.03599911;
+    
+    /* Tsai constants from G4Element::ComputeLradTsaiFactor() via Phys Rev. D50 3-1 (1994) page 1254 */
+    public static final double[] TSAI_LRAD_LIGHT = { 5.31, 4.79, 4.74, 4.71 };
+    public static final double[] TSAI_LPRAD_LIGHT = { 6.144, 5.621, 5.805, 5.924 };
+        
+    public static double computeCoulombCorrection(double Z)
+    {
+        if ( Z <= 0 )
+        {
+            throw new IllegalArgumentException("Z cannot be <= 0.");
+        }
+        
+        double az2 = (FINE_STRUCTURE_CONSTANT * Z) * (FINE_STRUCTURE_CONSTANT * Z);
+        double az4 = az2 * az2;
+        
+        double coulomb = (COULOMB_CORRECTIONS[0] * az4 + COULOMB_CORRECTIONS[1] + 
+                1.0/(1.0 + az2)) * az2 - (COULOMB_CORRECTIONS[2] * az4 + COULOMB_CORRECTIONS[3]) * az4;
+        
+        return coulomb;
+    }
+    
+    public static double computeTsaiFactor(double Z, double coulombCorrection)
+    {
+        double logZ3 = log(Z) / 3.0;
+        int iz = (int) (Z + 0.5) - 1;
+        
+        double lrad, lprad;
+        if ( iz <= 3)
+        {
+            lrad = TSAI_LRAD_LIGHT[iz];
+            lprad = TSAI_LPRAD_LIGHT[iz];
+        }
+        else
+        {
+            lrad = log(184.15) - logZ3;
+            lprad = log(1194.0) - 2 * logZ3;
+        }
+        
+        /**
+         * FINE_STRUCTURE_CONSTANT is actually 'alpha_rcl2' in G4Element but this is same as F.S.C. in CLHEP. 
+         */
+        double tsai = 4 * FINE_STRUCTURE_CONSTANT * Z * ( Z * (lrad * coulombCorrection) + lprad);
+        return tsai;
+    }
+    
+    public static double computeTsaiFactor(double Z)
+    {
+        return computeTsaiFactor(Z, computeCoulombCorrection(Z) );
+    }    
+    
+    public static double computeNuclearInteractionLengthEstimate(double A)
+    {
+        return ( 35.0 * pow(A, (1/3)) );
+    }
+    
+    public static double computeRadiationLengthEstimate(double A, double Z)
+    {
+        return (180.0 * A / ( Z * Z));
+    }
+}

GeomConverter/src/org/lcsim/material
Material.java 1.7 -> 1.8
diff -u -r1.7 -r1.8
--- Material.java	1 Jul 2005 21:59:54 -0000	1.7
+++ Material.java	1 Jul 2005 22:36:00 -0000	1.8
@@ -11,6 +11,10 @@
  *
  * Material implementation, mostly based on Geant4's G4Material.
  *
+ * NIL / RL calcs based on W.L.'s Matprop.
+ *
+ * http://www.slac.stanford.edu/comp/physics/matprop.html
+ *
  */
 public class Material
 {
@@ -18,7 +22,7 @@
     public static final double DEFAULT_TEMPERATURE = 273.15;
     
     /* Default pressure in atmospheres = 1.0 */
-    public static final double DEFAULT_PRESSURE = 1.0;        
+    public static final double DEFAULT_PRESSURE = 1.0;
     
     /* 1 mole */
     public static final double AVOGADRO = 6.022136736e23;
@@ -53,7 +57,7 @@
     private List<Double> _massFractions = new ArrayList<Double>();
     private List<Integer> _atoms = new ArrayList<Integer>();
     private List<Double> _nAtomsPerVolume = new ArrayList<Double>();
-   
+    
     /* electrons per element */
     double _totalElectronsPerVolume;
     
@@ -230,7 +234,7 @@
             {
                 _elements.add(element);
                 _massFractions.add(elCnt, fraction);
-                ++_nElements;                
+                ++_nElements;
             }
             ++_nComponents;
         }
@@ -274,7 +278,7 @@
                 if ( elCnt < _nElements )
                 {
                     double currFrac = _massFractions.get(elCnt);
-                    currFrac += fraction * material.getMassFractions().get(i) ;                    
+                    currFrac += fraction * material.getMassFractions().get(i) ;
                     _massFractions.set(elCnt, currFrac);
                 }
                 /* Add a new element. */
@@ -323,12 +327,12 @@
         if ( abs(1 - weightSum) > 0.001 )
         {
             //System.err.println("bad weight sum: " + weightSum);
-         
+            
             //System.out.println("listing weights...");
             //for ( int i = 0; i < _massFractions.size(); i++)
             //{
-            //System.out.println(_elements.get(i).getName() + " = " + _massFractions.get(i));            
-            //}                     
+            //System.out.println(_elements.get(i).getName() + " = " + _massFractions.get(i));
+            //}
             
             throw new RuntimeException("Mass fractions do not sum to 1 within 0.001 tolerance for this material: " + getName() );
         }
@@ -357,20 +361,53 @@
     public int getNElements()
     {
         return _nElements;
-    }            
+    }
     
     public void computeDerivedQuantities()
     {
-        computeNAtomsPerVolume();
+        //computeNAtomsPerVolume();
         computeRadiationLength();
         computeNuclearInteractionLength();
     }
     
+    /* compute NIL based on mass fractions */
+    private double computeNuclearInteractionLength()
+    {
+        double NILinv = 0.0;
+        
+        for (int i = 0; i < _nElements; i++)
+        {
+            MaterialElement me = _elements.get(i);
+            NILinv += _massFractions.get(i) / me.getNuclearInteractionLength();
+        }
+        
+        _nuclearInteractionLength = (NILinv <= 0.0 ? MAX_NUCLEAR_INTERACTION_LENGTH : 1.0/NILinv);
+        
+        return NILinv;
+    }
+    
+    /** compute RL based on mass fractions */
+    private double computeRadiationLength()
+    {
+        double rlinv = 0.0;
+        
+        for (int i = 0; i < _nElements; i++)
+        {
+            MaterialElement me = _elements.get(i);
+            rlinv += _massFractions.get(i) / me.getRadiationLength();
+        }
+        
+        _radiationLength = (rlinv <= 0.0 ? MAX_RADIATION_LENGTH : 1.0/rlinv);
+        
+        return rlinv;
+    }
+    
+    /*
     public void computeNAtomsPerVolume()
     {
         double Zi, Ai;
-        _totalElectronsPerVolume = 0.0;                        
-        
+        _totalElectronsPerVolume = 0.0;
+     
         for ( int i = 0; i < _nElements; i++)
         {
             Zi = _elements.get(i).getZ();
@@ -379,9 +416,9 @@
             _nAtomsPerVolume.add(i, nElec);
             _totalElectronsPerVolume += _nAtomsPerVolume.get(i);
             _totalElectronsPerVolume += _nAtomsPerVolume.get(i) * Zi;
-        }        
-    }                
-    
+        }
+    }
+     
     void computeRadiationLength()
     {
         double radinv = 0.0;
@@ -389,10 +426,12 @@
         {
             radinv += _nAtomsPerVolume.get(i) * ( _elements.get(i).getTsaiFactor() );
         }
-        _radiationLength = ( radinv <= 0.0 ? MAX_RADIATION_LENGTH : 1.0 / radinv);                
+        _radiationLength = ( radinv <= 0.0 ? MAX_RADIATION_LENGTH : 1.0 / radinv);
     }
+     */
     
     /** compute nuclear interaction length in g/cm2 */
+    /*
     void computeNuclearInteractionLength()
     {
         double NILinv = 0.0;
@@ -401,19 +440,10 @@
             NILinv += _nAtomsPerVolume.get(i) * pow(_elements.get(i).getN(), 0.6666667);
         }
         NILinv *= AMU/LAMBDA0;
-        
+     
         _nuclearInteractionLength = (NILinv <= 0.0 ? MAX_NUCLEAR_INTERACTION_LENGTH : 1.0/NILinv);
     }
-    
-    double estimateNuclearInteractionLength()
-    {
-        return ( 35.0 * pow(_A, (1/3)) );
-    }
-    
-    double estimateRadiationLength()
-    {
-        return (180.0 * _A / ( _Z * _Z));
-    }
+     */
     
     public double getRadiationLength()
     {
@@ -433,14 +463,15 @@
     
     public String toString()
     {
-        return "Material=" + getName() + "; nComponents=" + _nComponents + 
+        return "Material=" + getName() + "; nComponents=" + _nComponents +
                 "; nElements=" + _nElements + "; temp=" + _temp + "\t\n" +
-                "pressure=" + _pressure + "; density=" + _density + 
+                "pressure=" + _pressure + "; density=" + _density +
                 "; state=" + _state.toString() + "\t\n" + "elecPerVol=" +
-                _totalElectronsPerVolume + "; NIL=" + _nuclearInteractionLength + 
+                _totalElectronsPerVolume + "; NIL=" + _nuclearInteractionLength +
                 "; NILmat=" + getNuclearInteractionLengthForMaterial() +
-                "; RL=" + _radiationLength +
-                "; NILestimate: " + estimateNuclearInteractionLength() +
-                "; RLestimate: " + estimateRadiationLength();
+                "; RL=" + _radiationLength;
+        //        +
+        //                "; NILestimate: " + estimateNuclearInteractionLength() +
+        //                "; RLestimate: " + estimateRadiationLength();
     }
 }
\ No newline at end of file

GeomConverter/src/org/lcsim/material
MaterialElement.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- MaterialElement.java	1 Jul 2005 21:59:54 -0000	1.4
+++ MaterialElement.java	1 Jul 2005 22:36:00 -0000	1.5
@@ -13,6 +13,8 @@
     private double _ionizationPotential;  // Ionization potential (eV)        
     private double _coulombCorrection;    
     private double _tsai;
+    private double _nuclearInteractionLength;
+    private double _radiationLength;
     
     /*
     private static String[] ElementNotes = {
@@ -50,7 +52,10 @@
         _meltingPoint = mp;
         _boilingPoint = bp;
         _ionizationPotential = ip;
-        MaterialManager.addElement(this);        
+        
+        computeDerivedQuantities();
+        
+        MaterialManager.addElement(this);                      
     }    
     
     MaterialElement(String name,                    
@@ -100,16 +105,7 @@
     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()
     {
@@ -121,21 +117,50 @@
         return _tsai;
     }
     
+    public double getNuclearInteractionLength()
+    {
+        return _nuclearInteractionLength;
+    }   
+    
+    public double getRadiationLength()
+    {
+        return _radiationLength;
+    }
+    
     public void computeCoulombFactor()
     {
         /* calculate radiation length */
-        _coulombCorrection = RadiationLengthCalculator.computeCoulombCorrection(_Z);        
+        _coulombCorrection = MaterialCalculator.computeCoulombCorrection(_Z);        
     }
     
     public void computeTsaiFactor()
     {
         /* compute Tsai factor, using Z plus coulomb (so it doesn't need to be recomputed) */
-        _tsai = RadiationLengthCalculator.computeTsaiFactor(_Z, _coulombCorrection);
+        _tsai = MaterialCalculator.computeTsaiFactor(_Z, _coulombCorrection);
     }
     
     public void computeDerivedQuantities()
     {
         computeCoulombFactor();
-        computeTsaiFactor();
+        computeTsaiFactor();        
+        computeNuclearInteractionLength();
+        computeRadiationLength();
+    }
+    
+    void computeNuclearInteractionLength()
+    {
+        _nuclearInteractionLength = MaterialCalculator.computeNuclearInteractionLengthEstimate( getZ() );
+    }
+    
+    void computeRadiationLength()
+    {
+        _radiationLength = MaterialCalculator.computeRadiationLengthEstimate( getA(), getZ() );
+    }
+    
+    public String toString()
+    {
+        return "Element=" + name() + "; Z=" + _Z + "; A=" + _A + "; N=" + _N + "; density=" + _density + "\n"
+                + "MP=" + _meltingPoint + "; BP=" + _boilingPoint + "; IonPoten=" + _ionizationPotential + "\n"
+                + "coulomb=" + _coulombCorrection + "; tsai=" + _tsai;                
     }
 }
\ No newline at end of file

GeomConverter/src/org/lcsim/material
MaterialManager.java 1.4 -> 1.5
diff -u -r1.4 -r1.5
--- MaterialManager.java	1 Jul 2005 21:59:54 -0000	1.4
+++ MaterialManager.java	1 Jul 2005 22:36:00 -0000	1.5
@@ -127,8 +127,34 @@
         }
     }
     
+    public static void printElements(PrintStream ps)
+    {
+        ps.println("MaterialManager - dumping elements database...");
+        for ( MaterialElement me : elements().values() )
+        {
+            ps.println(me.toString());
+        }
+    }
+    
     public static void printMaterials()
     {
         printMaterials(System.out);        
     }
+    
+    public static void printElements()
+    {
+        printElements(System.out);
+    }
+    
+    public static void print()
+    {
+        printElements(System.out);
+        printMaterials(System.out);
+    }
+    
+    public static void print(PrintStream ps)
+    {
+        printElements(ps);
+        printMaterials(ps);
+    }
 }
\ No newline at end of file

GeomConverter/src/org/lcsim/material
RadiationLengthCalculator.java removed after 1.1
diff -N RadiationLengthCalculator.java
--- RadiationLengthCalculator.java	1 Jul 2005 21:59:54 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,71 +0,0 @@
-/*
- * CoulombCorrectionCalculator.java
- *
- * Created on July 1, 2005, 11:18 AM
- */
-
-package org.lcsim.material;
-
-import static java.lang.Math.log;
-
-/**
- *
- * @author jeremym
- */
-abstract public class RadiationLengthCalculator
-{
-    /* Coulomb correction factors from G4Element via Phys Rev. D50 3-1 (1994) page 1254 */
-    public static final double[] COULOMB_CORRECTIONS = { 0.0083, 0.20206, 0.0020, 0.0369 };
-        
-    /* Fine structure constant from PDG July 2004, Table 1.1 */
-    public static final double FINE_STRUCTURE_CONSTANT = 1 / 137.03599911;
-    
-    /* Tsai constants from G4Element::ComputeLradTsaiFactor() via Phys Rev. D50 3-1 (1994) page 1254 */
-    public static final double[] TSAI_LRAD_LIGHT = { 5.31, 4.79, 4.74, 4.71 };
-    public static final double[] TSAI_LPRAD_LIGHT = { 6.144, 5.621, 5.805, 5.924 };
-        
-    public static double computeCoulombCorrection(double Z)
-    {
-        if ( Z <= 0 )
-        {
-            throw new IllegalArgumentException("Z cannot be <= 0.");
-        }
-        
-        double az2 = (FINE_STRUCTURE_CONSTANT * Z) * (FINE_STRUCTURE_CONSTANT * Z);
-        double az4 = az2 * az2;
-        
-        double coulomb = (COULOMB_CORRECTIONS[0] * az4 + COULOMB_CORRECTIONS[1] + 
-                1.0/(1.0 + az2)) * az2 - (COULOMB_CORRECTIONS[2] * az4 + COULOMB_CORRECTIONS[3]) * az4;
-        
-        return coulomb;
-    }
-    
-    public static double computeTsaiFactor(double Z, double coulombCorrection)
-    {
-        double logZ3 = log(Z) / 3.0;
-        int iz = (int) (Z + 0.5) - 1;
-        
-        double lrad, lprad;
-        if ( iz <= 3)
-        {
-            lrad = TSAI_LRAD_LIGHT[iz];
-            lprad = TSAI_LPRAD_LIGHT[iz];
-        }
-        else
-        {
-            lrad = log(184.15) - logZ3;
-            lprad = log(1194.0) - 2 * logZ3;
-        }
-        
-        /**
-         * FINE_STRUCTURE_CONSTANT is actually 'alpha_rcl2' in G4Element but this is same as F.S.C. in CLHEP. 
-         */
-        double tsai = 4 * FINE_STRUCTURE_CONSTANT * Z * ( Z * (lrad * coulombCorrection) + lprad);
-        return tsai;
-    }
-    
-    public static double computeTsaiFactor(double Z)
-    {
-        return computeTsaiFactor(Z, computeCoulombCorrection(Z) );
-    }    
-}

GeomConverter/test/org/lcsim/material
MaterialManagerTest.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- MaterialManagerTest.java	1 Jul 2005 21:59:55 -0000	1.1
+++ MaterialManagerTest.java	1 Jul 2005 22:36:01 -0000	1.2
@@ -38,6 +38,6 @@
     public void test_materialsBasic()
     {
         MaterialManager mgr = MaterialManager.instance();
-        mgr.printMaterials();
+        mgr.print();
     }
 }
\ No newline at end of file
CVSspam 0.2.8