GeomConverter/src/org/lcsim/material
diff -u -r1.16 -r1.17
--- Material.java 22 Jul 2005 00:11:32 -0000 1.16
+++ Material.java 22 Jul 2005 23:23:24 -0000 1.17
@@ -11,20 +11,20 @@
*
* Material implementation, mostly based on Geant4's G4Material.
*
- * NIL and RL calcs based on W.L.'s Matprop.
+ * lambda and X0 calcs based on W.L.'s CEPack classes from lelaps.
*
* http://www.slac.stanford.edu/comp/physics/matprop.html
*
*/
public class Material
{
- /* Default temperature in kelvin */
+ /* default temperature in kelvin */
public static final double DEFAULT_TEMPERATURE = 273.15;
- /* Default pressure in atmospheres = 1.0 */
+ /* default pressure in atmospheres = 1.0 */
public static final double DEFAULT_PRESSURE = 1.0;
- /* Maximum RL and NIL */
+ /* maximum X0 and lambda */
public static final double MAX_RADIATION_LENGTH = java.lang.Double.MAX_VALUE;
public static final double MAX_NUCLEAR_INTERACTION_LENGTH = java.lang.Double.MAX_VALUE;
@@ -40,11 +40,11 @@
/* corresponds to single MaterialElement? */
boolean _isElement;
- /* Z value */
- public double _Z;
+ /* effective, computed Z value */
+ public double _Zeff;
- /* A value */
- public double _A;
+ /* effective, computed A value */
+ public double _Aeff;
/* state */
MaterialState _state;
@@ -55,8 +55,11 @@
/* chemical formula */
String _formula;
+ /* number of components added thusfar */
int _nComponents;
- int _nComponentsMax;
+
+ /* number of components (non-recursive) that can be added to this material */
+ int _nComponentsMax;
/* number of elements in mass fraction list */
int _nElements;
@@ -82,7 +85,7 @@
/* NIL in cm, taking into account the density */
double _nuclearInteractionLengthWithDensity;
- /* Construct base material with all info, creating a MaterialElement, also. */
+ /** Construct base material with all info, creating a MaterialElement, also. */
public Material(String name,
double z,
double a,
@@ -103,19 +106,19 @@
throw new IllegalArgumentException("Z must be >= 0.");
}
- _Z = z;
+ _Zeff = z;
if ( a <= 0 )
{
throw new IllegalArgumentException("A must be >= 0.");
}
- _A = a;
+ _Aeff = a;
_nComponents = _nComponentsMax = _nElements = 1;
_isElement = true;
- MaterialManager.addElement(new MaterialElement(_name, _Z, _A) );
+ MaterialManager.addElement(new MaterialElement(_name, _Zeff, _Aeff) );
_massFractions.add(1.0);
computeDerivedQuantities();
@@ -123,6 +126,7 @@
MaterialManager.addMaterial(this);
}
+ /** Construct a material with a number of components. */
public Material(String name,
int nComponents,
double density,
@@ -149,67 +153,81 @@
MaterialManager.addMaterial(this);
}
+ /** @return name (key) string */
public String getName()
{
return _name;
}
+ /** @return density in g/cm3*/
public double getDensity()
{
return _density;
}
+ /** @return pressure in atmospheres */
public double getPressure()
{
return _pressure;
}
+ /** @return whether this material has a 1 to 1 correspondance to a single chemical element */
public boolean isElement()
{
return _isElement;
}
- public double getZ()
+ /** @return effective Z of this material */
+ public double getZeff()
{
- return _Z;
+ return _Zeff;
}
- public double getA()
+ /** @return effective A of this material */
+ public double getAeff()
{
- return _A;
+ return _Aeff;
}
+ /** @return temperature of material in Kelvein */
public double getTemperature()
{
return _temp;
}
+ /** Set the chemical formula of this material. */
public void setFormula(String formula)
{
_formula = formula;
}
- public int getNComponents()
+ /** @return maximum number of 1st-level (non-recursive) components that can be defined */
+ public int getNComponentsMax()
{
- return _nComponents;
+ return _nComponentsMax;
}
- public int getNComponentsMax()
+ /** @return number of components defined so far in this material */
+ public int getNComponents()
{
- return _nComponentsMax;
+ return _nComponents;
}
+ /** @return number of elements defined in this material */
public int getNElements()
{
return _nElements;
}
+ /**
+ * @return the state of this material
+ */
public MaterialState getState()
{
return _state;
}
- /* compute NIL based on mass fractions */
+ /** @return lambda (nuclear interaction length) based on mass fractions of elements */
private double computeNuclearInteractionLength()
{
double NILinv = 0.0;
@@ -226,7 +244,7 @@
return NILinv;
}
- /** compute RL based on mass fractions */
+ /** compute X0 (radiation length) based on mass fractions of elements */
private double computeRadiationLength()
{
double rlinv = 0.0;
@@ -243,53 +261,61 @@
return _radiationLength;
}
+ /** Caches computed quantities after all components have been added to the material. */
private void computeDerivedQuantities()
- {
+ {
+ computeZeff();
+ computeAeff();
computeRadiationLength();
computeNuclearInteractionLength();
}
+ /** @return X0 */
public double getRadiationLength()
{
return _radiationLength;
}
+ /** @return lambda */
public double getNuclearInteractionLength()
{
return _nuclearInteractionLength;
}
- /* get NIL/density in cm */
+ /** @return lambda in cm = (lambda/density) */
public double getNuclearInteractionLengthWithDensity()
{
return _nuclearInteractionLengthWithDensity;
}
- /* get RL/density in cm */
+ /** @return X0 in cm = (X0/density) */
public double getRadiationLengthWithDensity()
{
return _radiationLengthWithDensity;
}
+ /** @return total number of (unique) elements in the element list for this material */
public int getNumberOfElements()
{
return _nElements;
}
+ /** @return a list of elements referenced by this material */
public List<MaterialElement> getElements()
{
return _elements;
}
+ /** @return corresponding mass fractions for each element in the material */
public List<Double> getMassFractions()
{
return _massFractions;
}
/**
- * Add element by atom count.
+ * Add an element to the material by atom count.
*
- * Based on G4Material::AddElement() .
+ * Based on Geant4's G4Material::AddElement() .
*/
public void addElement(MaterialElement element,
int nAtoms)
@@ -299,8 +325,6 @@
_elements.add(element);
_atoms.add( _nElements, nAtoms);
_nComponents = ++_nElements;
-
- //System.out.println("ncomp, nelem: " + _nComponents + " " + _nElements);
}
else
{
@@ -309,9 +333,6 @@
if ( isFilled() )
{
- //System.out.println(getName() + " is filled");
- //System.out.println("setting mass fractions");
-
double Zmol = 0;
double Amol = 0;
@@ -333,13 +354,12 @@
}
}
- /** Add element by fraction of mass. */
+ /**
+ * Add element to the material by fraction of mass. (out of 1.0)
+ */
public void addElement(MaterialElement element,
double fraction)
{
-
-// System.out.println("Material.addElement() - fraction add " + element.getName() + " to " + getName() );
-
if ( _nComponents < _nComponentsMax )
{
int elCnt = 0;
@@ -368,7 +388,6 @@
if ( isFilled() )
{
- //System.out.println(getName() + " is filled");
checkMassSum();
computeDerivedQuantities();
}
@@ -377,10 +396,7 @@
/** Add material by fraction of mass. */
public void addMaterial(Material material,
double fraction)
- {
-
-// System.out.println("Material.addElement() - fraction add " + material.getName() + " to " + getName() );
-
+ {
if ( _atoms.size() > 0 )
{
throw new RuntimeException("Material is already defined by atoms: " + getName());
@@ -435,15 +451,15 @@
}
}
- /** @return true if all sub-materials have been added (externally); false if not */
+ /** @return true if all 1st-level (non-recursive) component elements and materials have been added */
public boolean isFilled()
{
return (_nComponents == _nComponentsMax);
}
+ /** Check that the massFractions list adds up to 1.0 */
private void checkMassSum()
{
- //System.out.println("checking mass sum for: " + getName() );
double weightSum = 0;
for ( int i = 0; i < _massFractions.size(); i++)
{
@@ -456,14 +472,65 @@
}
}
+ /** Compute effective Z for this material using element list. */
+ private double computeZeff()
+ {
+ double ZsumNotNorm = 0;
+ double atomCntFracSum = 0;
+
+ int nelem = this.getNElements();
+ for ( int i = 0; i < nelem; i++ )
+ {
+ MaterialElement me = this.getElements().get(i);
+ double elemZ = me.getZ();
+ double massFrac = this.getMassFractions().get(i);
+ double atomCntFrac = massFrac / me.getA();
+ ZsumNotNorm += atomCntFrac * me.getZ();
+ atomCntFracSum += atomCntFrac;
+ }
+
+ double ZsumNorm = ZsumNotNorm / atomCntFracSum;
+ _Zeff = ZsumNorm;
+ return _Zeff;
+ }
+
+ /** Compute effective A for this material using element list. */
+ private double computeAeff()
+ {
+ double AsumNotNorm = 0;
+ double atomCntFracSum = 0;
+
+ int nelem = this.getNElements();
+ for ( int i = 0; i < nelem; i++ )
+ {
+ MaterialElement me = this.getElements().get(i);
+ double massFrac = this.getMassFractions().get(i);
+ double atomCntFrac = massFrac / me.getA();
+ AsumNotNorm += atomCntFrac * me.getA();
+ atomCntFracSum += atomCntFrac;
+ }
+ double ZsumNorm = AsumNotNorm / atomCntFracSum;
+ _Aeff = ZsumNorm;
+ return _Aeff;
+ }
+
+ /** Translate this material to human-readable string. */
public String toString()
{
- return "Material=" + getName() + "; nComponents=" + _nComponents +
+ String s = "Material=" + getName() + "; nComponents=" + _nComponents +
"; nComponentsMax=" + _nComponentsMax + "; nElements=" + _nElements +
- "; temp(K)=" + _temp + "\n\t" + "pressure(atmos)=" + _pressure +
- "; density(g/cm3)=" + _density + "; state=" + _state.toString() +
- "\n\t" + "lambda(gcm2)=" + _nuclearInteractionLength +
+ "\n" + "Zeff=" + _Zeff + "; Aeff=" + _Aeff + "; temp(K)=" + _temp + "; pressure(atmos)=" + _pressure + "\n" +
+ "density(g/cm3)=" + _density + "; state=" + _state.toString() +
+ "\n" + "lambda(gcm2)=" + _nuclearInteractionLength +
"; X0(gcm2)=" + _radiationLength + "; lambda(cm)=" + getNuclearInteractionLengthWithDensity() +
"; X0(cm)=" + getRadiationLengthWithDensity();
+
+ s += "\n\telements: " + _nElements;
+ for ( int i = 0; i < this.getNElements(); i++)
+ {
+ s += "\n\t" + this.getElements().get(i).getName() + " " + this.getMassFractions().get(i) * 100;
+ }
+
+ return s;
}
}
\ No newline at end of file