lcsim/src/org/lcsim/recon/tracking/gtrdetector
diff -u -r1.7 -r1.8
--- GtrDetector.java 6 May 2008 23:48:48 -0000 1.7
+++ GtrDetector.java 7 May 2008 21:47:41 -0000 1.8
@@ -3,7 +3,7 @@
*
* Created on July 30, 2005, 3:30 PM
*
- * $Id: GtrDetector.java,v 1.7 2008/05/06 23:48:48 jeremy Exp $
+ * $Id: GtrDetector.java,v 1.8 2008/05/07 21:47:41 ngraf Exp $
*/
package org.lcsim.recon.tracking.gtrdetector;
@@ -16,11 +16,15 @@
import java.util.Map;
import java.util.Set;
+import static java.lang.Math.sin;
+import static java.lang.Math.PI;
+
import org.lcsim.conditions.DetectorLocator;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.IRotation3D;
import org.lcsim.detector.material.IMaterial;
import org.lcsim.detector.solids.Box;
+import org.lcsim.detector.solids.Point3D;
import org.lcsim.geometry.compact.Subdetector;
import org.lcsim.geometry.layer.Layer;
import org.lcsim.geometry.layer.LayerSlice;
@@ -29,7 +33,10 @@
import org.lcsim.geometry.subdetector.MultiLayerTracker;
import org.lcsim.geometry.subdetector.SiTrackerBarrel;
import org.lcsim.recon.tracking.spacegeom.CartesianPoint;
+import org.lcsim.recon.tracking.spacegeom.CartesianTwoPoint;
import org.lcsim.recon.tracking.spacegeom.SpacePoint;
+import org.lcsim.recon.tracking.spacegeom.TwoSegment;
+import org.lcsim.recon.tracking.spacegeom.TwoSpacePoint;
import org.lcsim.recon.tracking.trfbase.Interactor;
import org.lcsim.recon.tracking.trfbase.MultiInteractor;
import org.lcsim.recon.tracking.trfcyl.ClusterFindCyl;
@@ -48,10 +55,10 @@
*/
public class GtrDetector extends Detector
{
- public GtrDetector(org.lcsim.geometry.Detector det)
- {
- System.out.println("building GtrDetector from " + det.getDetectorName());
- Map<String, Subdetector> subDetMap = det.getSubdetectors();
+ public GtrDetector(org.lcsim.geometry.Detector det)
+ {
+ System.out.println("building GtrDetector from " + det.getDetectorName());
+ Map<String, Subdetector> subDetMap = det.getSubdetectors();
Set<String> keys = subDetMap.keySet();
Collection<Subdetector> subDets = subDetMap.values();
// TODO need a mechanism to define what the digitization for each subdetector is.
@@ -68,10 +75,10 @@
}
else if (subDet instanceof SiTrackerBarrel)
{
- add((SiTrackerBarrel) subDet);
+ add((SiTrackerBarrel) subDet);
}
}
- }
+ }
/** Creates a new instance of GtrDetector */
public GtrDetector(String detectorName)
@@ -300,51 +307,92 @@
// TODO: Handle modules with multiple sensitive components.
private void add(SiTrackerBarrel barrel)
{
- IDetectorElement subdet = barrel.getDetectorElement();
- for (IDetectorElement layer : subdet.getChildren())
- {
- //System.out.println(layer.getName());
- for (IDetectorElement module : layer.getChildren())
- {
- //System.out.println(" " + module.getName());
- double x0 = calculateModuleX0(module);
- //System.out.println(" module <" + module.getName() + "> x0="+x0);
- IDetectorElement sensor = null;
- for (IDetectorElement component : module.getChildren())
- {
- if (component.getGeometry().getPhysicalVolume().isSensitive())
- {
- sensor = component;
- //System.out.println(" sensor <" + component.getName() +">");
- break;
- }
- }
- if (sensor == null)
- throw new RuntimeException("No sensor found!");
-
- // Get position.
- Hep3Vector position = sensor.getGeometry().getPosition();
- SpacePoint point = new CartesianPoint(position.v());
- //System.out.print(point);
- double rxy = point.rxy();
-
- // Get global rotation.
- IRotation3D rot = sensor.getGeometry().getLocalToGlobal().getRotation();
- //System.out.println("rot="+rot.toString());
-
- // Get width (x) and length (y).
- Box box = (Box)sensor.getGeometry().getLogicalVolume().getSolid();
- double u = box.getXHalfLength();
- double v = box.getYHalfLength();
-
- // TODO: Convert rotation to phi measurement.
- // FIXME: Assert error!
- //BSurfXYPlane xyp = new BSurfXYPlane(rxy, point.phi(), -v, v, -u, u);
+ IDetectorElement subdet = barrel.getDetectorElement();
+ for (IDetectorElement layer : subdet.getChildren())
+ {
+ //System.out.println(layer.getName());
+ for (IDetectorElement module : layer.getChildren())
+ {
+ //System.out.println(" " + module.getName());
+ double x0 = calculateModuleX0(module);
+ //System.out.println(" module <" + module.getName() + "> x0="+x0);
+ IDetectorElement sensor = null;
+ for (IDetectorElement component : module.getChildren())
+ {
+ if (component.getGeometry().getPhysicalVolume().isSensitive())
+ {
+ sensor = component;
+ //System.out.println(" sensor <" + component.getName() +">");
+ break;
+ }
+ }
+ if (sensor == null)
+ throw new RuntimeException("No sensor found!");
+
+ // Get position.
+ Hep3Vector position = sensor.getGeometry().getPosition();
+ SpacePoint point = new CartesianPoint(position.v());
+ //System.out.print(point);
+ double rxy = point.rxy();
+
+ // Get global rotation.
+ IRotation3D rot = sensor.getGeometry().getLocalToGlobal().getRotation();
+// System.out.println("rot="+rot.toString());
+
+ // Get width (x) and length (y).
+ Box box = (Box)sensor.getGeometry().getLogicalVolume().getSolid();
+ List<Point3D> vertices = box.getVertices();
+// System.out.println("sensor has "+vertices.size()+" vertices");
+ int[] point_ordering = box.getHepRepVertexOrdering();
+ for (int i = 0; i< point_ordering.length; i++)
+ {
+ Point3D pt = vertices.get(point_ordering[i]);
+// System.out.println("Local : "+i+" x= "+pt.x()+" y= "+pt.y()+" z= "+ pt.z());
+ Hep3Vector p = sensor.getGeometry().transformLocalToGlobal(pt);
+// System.out.println("Global: "+i+" x= "+p.x()+" y= "+p.y()+" z= "+ p.z());
+ }
+ double u = box.getXHalfLength();
+ double v = box.getYHalfLength();
+
+ // create the sensor plane.
+ // use the heprep ordering
+ // TODO verify that the heprep ordering is correct
+ Point3D p1 = vertices.get(point_ordering[0]);
+ Point3D p2 = vertices.get(point_ordering[1]);
+ Point3D p3 = vertices.get(point_ordering[2]); // needed for +z extent
+
+ // reset the z value so we get the plane at the center of the sensor
+ //TODO check that the sensor is always centered on zero. appears to be the case
+ p1.setV(p1.x(), p1.y(), 0. );
+ p2.setV(p2.x(), p2.y(), 0. );
+
+ Hep3Vector globalP1 = sensor.getGeometry().transformLocalToGlobal(p1);
+ Hep3Vector globalP2 = sensor.getGeometry().transformLocalToGlobal(p2);
+ Hep3Vector globalP3 = sensor.getGeometry().transformLocalToGlobal(p3);
+
+ TwoSpacePoint global2D1 = new CartesianTwoPoint(globalP1.x(), globalP1.y());
+ TwoSpacePoint global2D2 = new CartesianTwoPoint(globalP2.x(), globalP2.y());
+
+ TwoSegment seg = new TwoSegment(global2D1, global2D2);
+// System.out.println("2d segment: "+seg);
- //System.out.println("XYPlane for sensor <" + sensor.getName() + ">");
- //System.out.println(xyp);
- }
- }
+ TwoSpacePoint origin = new CartesianTwoPoint(0.,0.);
+ double rdist = seg.minimumDistance(origin);
+// System.out.println("rdist: "+rdist + " rxy: "+rxy+" segment phi: "+seg.phi()+" point phi "+point.phi());
+ // TODO: calculate u and v extents, v is probably OK, but u is mot likely wrong.
+ // first, the angle of the normal to the sensor plane
+ // note that this is the segment phi - pi/2
+ double phi0 = seg.phi()-PI/2.;
+ double u1 = global2D1.rxy()*sin(phi0-global2D1.phi());
+ double u2 = global2D2.rxy()*sin(phi0-global2D2.phi());
+// System.out.println("v= "+v+ " u= "+u+" u1= "+u1+" u2= "+u2+" segment length= "+seg.length());
+ if(phi0<0.) phi0+=2.*PI;
+ BSurfXYPlane xyp = new BSurfXYPlane(rdist, phi0, u1, u2, globalP1.z(), globalP3.z());
+
+ System.out.println("XYPlane for sensor <" + sensor.getName() + ">");
+ System.out.println(xyp);
+ }
+ }
}
// return effective x/x0 for this layer
@@ -361,24 +409,24 @@
}
return xOverX0;
}
-
+
private double calculateModuleX0(IDetectorElement module)
{
- double xOverX0 = 0.;
- for (IDetectorElement component : module.getChildren())
- {
- Box b = (Box)component.getGeometry().getLogicalVolume().getSolid();
- double thickness = b.getZHalfLength() * 2;
- IMaterial material = component.getGeometry().getLogicalVolume().getMaterial();
- double x0 = material.getRadiationLengthWithDensity();
- xOverX0 += thickness/(x0*cm);
- }
- return xOverX0;
+ double xOverX0 = 0.;
+ for (IDetectorElement component : module.getChildren())
+ {
+ Box b = (Box)component.getGeometry().getLogicalVolume().getSolid();
+ double thickness = b.getZHalfLength() * 2;
+ IMaterial material = component.getGeometry().getLogicalVolume().getMaterial();
+ double x0 = material.getRadiationLengthWithDensity();
+ xOverX0 += thickness/(x0*cm);
+ }
+ return xOverX0;
}
public static void main(String[] args)
{
- GtrDetector gtrdet = new GtrDetector("sidaug05");
+ GtrDetector gtrdet = new GtrDetector("sid01");
System.out.println("\n\n\n\n\n"+gtrdet);
}