lcsim/src/org/lcsim/contrib/seedtracker
diff -u -r1.3 -r1.4
--- MaterialManager.java 5 Feb 2008 17:08:47 -0000 1.3
+++ MaterialManager.java 18 Feb 2008 23:26:24 -0000 1.4
@@ -21,7 +21,10 @@
import org.lcsim.detector.ILogicalVolume;
import org.lcsim.detector.IPhysicalVolume;
import org.lcsim.detector.material.IMaterial;
+import org.lcsim.detector.solids.Box;
import org.lcsim.detector.solids.ISolid;
+import org.lcsim.detector.solids.Point3D;
+import org.lcsim.detector.solids.Polycone;
import org.lcsim.detector.solids.Tube;
import org.lcsim.geometry.Detector;
@@ -140,10 +143,9 @@
double vtot = 0.;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // Only consider tubes until we can trust getCubicVolume
- if (solid instanceof Tube) {
- vtot += solid.getCubicVolume();
- }
+
+ vtot += safeCubicVolume(solid);
+
}
return vtot;
}
@@ -154,14 +156,13 @@
double vtot = 0.;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // Only consider tubes until we can trust getCubicVolume
- if (solid instanceof Tube) {
- double vol = solid.getCubicVolume();
- vtot += vol;
- IMaterial mat = pv.getLogicalVolume().getMaterial();
- double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
- if (X0 > 0.) invX0 += vol / X0;
- }
+
+ double vol = safeCubicVolume(solid);
+ vtot += vol;
+ IMaterial mat = pv.getLogicalVolume().getMaterial();
+ double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
+ if (X0 > 0.) invX0 += vol / X0;
+
}
if (invX0 > 0.) X0wgt = vtot / invX0;
return X0wgt;
@@ -171,11 +172,7 @@
double rmin = 1.e10;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // For now, only consider elements that are tubes
- if (solid instanceof Tube) {
- Tube tube = (Tube) solid;
- rmin = Math.min(rmin, tube.getInnerRadius());
- }
+ rmin = Math.min(rmin, calculateRMinSolid(solid));
}
return rmin;
}
@@ -184,11 +181,7 @@
double rmax = 0.;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // For now, only consider elements that are tubes
- if (solid instanceof Tube) {
- Tube tube = (Tube) solid;
- rmax = Math.max(rmax, tube.getOuterRadius());
- }
+ rmax = Math.max(rmax, calculateRMaxSolid(solid));
}
return rmax;
}
@@ -197,12 +190,21 @@
double zmin = 1.e10;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // For now, only consider elements that are tubes
+
+
+ double z0 = pvtree.getTranslation().z();
if (solid instanceof Tube) {
Tube tube = (Tube) solid;
- double z0 = pvtree.getTranslation().z();
zmin = Math.min(zmin, z0-tube.getZHalfLength());
}
+ else if (solid instanceof Box) {
+ Box box = (Box) solid;
+ zmin = Math.min(zmin, z0-box.getZHalfLength());
+ }
+ else if (solid instanceof Polycone) {
+ Polycone polycone = (Polycone) solid;
+ zmin = Math.min(zmin, z0-polycone.getZHalfLength());
+ }
}
return zmin;
}
@@ -211,12 +213,20 @@
double zmax = -1.e10;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // For now, only consider elements that are tubes
+
+ double z0 = pvtree.getTranslation().z();
if (solid instanceof Tube) {
Tube tube = (Tube) solid;
- double z0 = pvtree.getTranslation().z();
zmax = Math.max(zmax, z0+tube.getZHalfLength());
}
+ else if (solid instanceof Box) {
+ Box box = (Box) solid;
+ zmax = Math.max(zmax, z0+box.getZHalfLength());
+ }
+ else if (solid instanceof Polycone) {
+ Polycone polycone = (Polycone) solid;
+ zmax = Math.max(zmax, z0+polycone.getZHalfLength());
+ }
}
return zmax;
}
@@ -234,18 +244,16 @@
double totwgt = 0.;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // For now, only consider elements that are tubes
- if (solid instanceof Tube) {
- Tube tube = (Tube) solid;
- double rmin = tube.getInnerRadius();
- double rmax = tube.getOuterRadius();
- double vol = solid.getCubicVolume();
- IMaterial mat = pv.getLogicalVolume().getMaterial();
- double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
- double wgt = vol / X0;
- rwgt += 0.5 * (rmin + rmax) * wgt;
- totwgt += wgt;
- }
+
+ double rmin = calculateRMinSolid(solid);
+ double rmax = calculateRMaxSolid(solid);
+ double vol = safeCubicVolume(solid);
+ IMaterial mat = pv.getLogicalVolume().getMaterial();
+ double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
+ double wgt = vol / X0;
+ rwgt += 0.5 * (rmin + rmax) * wgt;
+ totwgt += wgt;
+
}
if (totwgt > 0.) rwgt /= totwgt;
return rwgt;
@@ -256,19 +264,88 @@
double totwgt = 0.;
for (IPhysicalVolume pv : pvlist) {
ISolid solid = pv.getLogicalVolume().getSolid();
- // For now, only consider elements that are tubes
- if (solid instanceof Tube) {
- Tube tube = (Tube) solid;
- double z0 = pvtree.getTranslation().z();
- double vol = solid.getCubicVolume();
- IMaterial mat = pv.getLogicalVolume().getMaterial();
- double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
- double wgt = vol / X0;
- zwgt += z0 * wgt;
- totwgt += wgt;
- }
+
+ double z0 = pvtree.getTranslation().z();
+ double vol = safeCubicVolume(solid);
+ IMaterial mat = pv.getLogicalVolume().getMaterial();
+ double X0 = 10. * mat.getRadiationLength() / mat.getDensity();
+ double wgt = vol / X0;
+ zwgt += z0 * wgt;
+ totwgt += wgt;
+
}
if (totwgt > 0.) zwgt /= totwgt;
return zwgt;
}
-}
\ No newline at end of file
+
+
+ //calculates the cubic volume and represses runtime exceptions by returning 0....
+ //just in case there's something that isn't implemented
+ private double safeCubicVolume(ISolid solid){
+
+ try {
+ return solid.getCubicVolume();
+ }
+ catch(Exception e) {
+ return 0.0;
+ }
+ }
+
+
+ //functions that give the rmin and rmax of a solid...
+ private double calculateRMinSolid(ISolid solid){
+
+ double rmin = 1e10;
+ if (solid instanceof Tube) {
+ Tube tube = (Tube) solid;
+ return tube.getInnerRadius();
+ }
+
+ //this essentially finds the vertex with the minimum magnitude
+ else if (solid instanceof Box) {
+ Box box = (Box) solid;
+ List<Point3D> vtx = box.getVertices();
+
+ for (Point3D p : vtx) {
+ rmin = Math.min(rmin, p.magnitude());
+ }
+ return rmin;
+ }
+
+ //this takes the inner radius at z = 0 of the polycone
+ else if (solid instanceof Polycone) {
+ Polycone poly = (Polycone) solid;
+ return poly.getInnerRadiusAtZ(0);
+ }
+
+ return rmin;
+ }
+
+ //this (hopefully) does the exact opposite of calculateRMinSolid
+ private double calculateRMaxSolid(ISolid solid){
+
+ double rMax = 0;
+ if (solid instanceof Tube) {
+ Tube tube = (Tube) solid;
+ return tube.getOuterRadius();
+ }
+
+ else if (solid instanceof Box) {
+ Box box = (Box) solid;
+ List<Point3D> vtx = box.getVertices();
+
+ for (Point3D p : vtx) {
+ rMax = Math.max(rMax, p.magnitude());
+ }
+ return rMax;
+ }
+
+ else if (solid instanceof Polycone) {
+ Polycone poly = (Polycone) solid;
+ return poly.getOuterRadiusAtZ(0);
+ }
+
+ return rMax;
+ }
+
+}