GeomConverter/test/org/lcsim/detector
diff -u -r1.3 -r1.4
--- SimpleDetectorTest.java 3 Mar 2007 13:59:18 -0000 1.3
+++ SimpleDetectorTest.java 6 Mar 2007 20:22:33 -0000 1.4
@@ -1,14 +1,15 @@
package org.lcsim.detector;
-import static org.lcsim.units.clhep.SystemOfUnits.cm;
import static org.lcsim.units.clhep.SystemOfUnits.m;
import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.lcsim.detector.material.IMaterial;
import org.lcsim.detector.material.MaterialElement;
import org.lcsim.detector.solids.Box;
+import org.lcsim.detector.solids.Tube;
public class SimpleDetectorTest extends TestCase
{
@@ -32,59 +33,160 @@
public void testBasicAccess()
{
- System.out.println("pv world = " + world.getName());
+ //System.out.println("pv world = " + world.getName());
ILogicalVolume lvWorld = world.getLogicalVolume();
- System.out.println("lv world = " + lvWorld.getName());
- IPhysicalVolume pvDau = lvWorld.getDaughter(0);
- System.out.println("pv dau = " + pvDau.getName());
+ //System.out.println("lv world = " + lvWorld.getName());
+ IPhysicalVolume pvDau = lvWorld.getDaughter(0);
+ //System.out.println("pv dau = " + pvDau.getName());
ILogicalVolume lvDau = pvDau.getLogicalVolume();
- System.out.println("lv dau = " + lvDau.getName());
+ //System.out.println("lv dau = " + lvDau.getName());
Box boxDau = (Box)lvDau.getSolid();
- System.out.println("box dau = " + boxDau.getName() + "; halfx halfy halfz = " + boxDau.getXHalfLength() + " " + boxDau.getYHalfLength() + " " + boxDau.getZHalfLength());
+ //System.out.println("box dau = " + boxDau.getName() + "; halfx halfy halfz = " + boxDau.getXHalfLength() + " " + boxDau.getYHalfLength() + " " + boxDau.getZHalfLength());
IMaterial material = lvDau.getMaterial();
- System.out.println("mat dau = " + material.getName());
+ //System.out.println("mat dau = " + material.getName());
}
-
- static double[] xpoints = {0.0,10.1,9.9,5.1,4.9,2.6,2.4,1.1,0.9,0.5,0.25,0.2};
- public void testNavigator()
+
+ static double [] xpoints = {10.0,10.1,9.9,5.1,4.9,2.6,2.4,1.1,.9,.6,.4,.2,.1,0};
+ private String[] testnames = {"/box1","box1","box1/","/box1"};
+ public void testNavigator()
{
- IPhysicalVolumeNavigator nav = new PhysicalVolumeNavigator(world);
-
- IPhysicalVolumePath path = nav.getPath("box1");
- System.out.println("got path = " + path.toString());
+ IPhysicalVolumeNavigator nav = new PhysicalVolumeNavigator(world);
- path = nav.getPath("box1/box2");
- System.out.println("got path = " + path.toString());
+ // The string "/" should give back a reference
+ // to the top volume, which is encoded by a
+ // single "/".
+ assertTrue("/".equals(nav.getPath("/").toString()));
- path = nav.getPath("box1/box2/box3");
- System.out.println("got path = " + path.toString());
+ // The navigator should normalize all the testnames to "/box1".
+ for (String testname : testnames)
+ {
+ //System.out.println("testname: " + testname);
+
+ IPhysicalVolumePath path = nav.getPath(testname);
+
+ //System.out.println("got path <"+path.toString()+"> from testname <"+testname+">.");
+
+ assertEquals(path.size(),2);
+ assertTrue("/box1".equals(path.toString() ));
+ assertTrue( "box1".equals(path.getLeafVolume().getName() ));
+ assertTrue("world".equals(path.getTopVolume().getName() ));
+ }
+
+ IPhysicalVolumePath path = nav.getPath("/box1");
ICoordinateTransformation3D t = nav.getTransform(path);
- System.out.println("transform to <" + path.toString() +"> = " + t.toString());
+
+ //System.out.println("transform to <" + path.toString() +"> = " + t.toString());
for (double x : xpoints)
{
IPhysicalVolumePath path3 = nav.getPath(new BasicHep3Vector(x,0,0));
- System.out.println("nav thinks x=" + x + " has path <" + path3.toString()+">");
+
+ if (x<5.0)
+ {
+ assertTrue("/box1".equals(path3.toString()));
+ }
+ else {
+ assertTrue("/".equals(path3.toString()));
+ }
}
for (double x : xpoints)
{
IPhysicalVolumePath path3 = nav.getPath(new BasicHep3Vector(-x,0,0));
- System.out.println("nav thinks x=" + -x + " has path <" + path3.toString()+">");
+
+ //System.out.println("nav thinks x=" + -x + " has path <" + path3.toString()+">");
+
+ if (-x > -5.0)
+ {
+ //System.out.println("x > -5.0 : path3 : " + path3.toString());
+ assertTrue("/box1".equals(path3.toString()));
+ }
+ else {
+ //System.out.println("x < -5.0 : path3 : " + path3.toString());
+ assertTrue("/".equals(path3.toString()));
+ }
+ }
+
+ for (double x : new double[] {44.9,45.1,47.9,48.1,51.9,52.1,49.9,54.9,55.1})
+ {
+ System.out.println("x="+x);
+ IPhysicalVolumePath path4 = nav.getPath(new BasicHep3Vector(x,0,0));
+ System.out.println("path4 : " + path4.toString());
+ if (x>45 && x<55)
+ {
+ assertTrue("/box2".equals(path4.toString()));
+ }
}
+
+ // Create a dummy DE.
+ IDetectorElement dummyDE = new DummyDE(nav.getPath("/box1"));
+ IGeometryInfo gi = dummyDE.getGeometry();
+ assertTrue("/box1".equals(gi.getPhysicalVolumePath().toString()));
+ //System.out.println("dummyDE LV : " + gi.getLogicalVolume().getName());
+ //System.out.println("dummyDE LV : " + gi.getPosition());
+ //System.out.println("global to local : " + gi.getGlobalToLocal().toString());
+
+ //System.out.println("checking isinside for DE : " + dummyDE.getName());
+
+ // Positive points.
+ for (double x : xpoints)
+ {
+ Hep3Vector thisx = new BasicHep3Vector(x,0,0);
+ boolean isInside = gi.isInside(thisx);
+ //System.out.println("isinside " + thisx.toString() + " : " + isInside);
+
+ if (x<5.0)
+ {
+ assertTrue(isInside);
+ }
+ }
+
+ for (double y : new double[] {44.9,45.1,47.9,48.1,51.9,52.1,49.9,54.9,55.1})
+ {
+ Hep3Vector point = new BasicHep3Vector(0,y,0);
+ IPhysicalVolumePath path5 = nav.getPath(point);
+
+ System.out.println("point : " + point.toString());
+ System.out.println("path : " + path5.toString());
+
+ if ( y < 45.0 || y > 55.0)
+ {
+ assertTrue(path5.size()==1);
+ assertTrue("/".equals(path5.toString()));
+ }
+
+ if ((y > 45.0 && y < 48.0) || (y > 52.0 && y < 55.0))
+ {
+ assertTrue("/box3".equals(path5.toString()));
+ }
+ else if (y > 48.0 && y < 52.0)
+ {
+ assertTrue("/box3/box4".equals(path5.toString()));
+ }
+ }
+
+ IPhysicalVolumePath path6 = nav.getPath(new BasicHep3Vector(101,0,0));
+ assertTrue("/tube1".equals(path6.toString()));
+ System.out.println("at x = 101 : " + path6.toString());
+ path6 = nav.getPath("/tube1");
+ assert("/tube1".equals(path6.toString()));
+ System.out.println("tube path : " + path6.toString());
+ path6 = nav.getPath(new BasicHep3Vector(111.0,0,0));
+ assertTrue("/tube1/tube2".equals(path6.toString()));
}
- public static IPhysicalVolume createTestGeometry()
+ public IPhysicalVolume createTestGeometry()
{
IPhysicalVolume world = createWorld();
- createTestGeometryBoxes(world);
+ createTestSolids(world);
return world;
}
- public static final void createTestGeometryBoxes(IPhysicalVolume mom)
+ public final void createTestSolids(IPhysicalVolume mom)
{
- Box box = new Box("test_box1",10.0,10.0,10.0);
+ // 10 cm box at 0,0,0
+ Box box = new Box("test_box1",5.0,5.0,5.0);
LogicalVolume lvTest = new LogicalVolume("lvTest",box,dummymat);
new PhysicalVolume(
new CoordinateTransformation3D(),
@@ -92,27 +194,58 @@
lvTest,
mom.getLogicalVolume(),
0);
-
+
+ // 10 cm box at 50,0,0
Box box2 = new Box("test_box2",5.0,5.0,5.0);
LogicalVolume lvTest2 = new LogicalVolume("lvTest2",box2,dummymat);
new PhysicalVolume(
- new CoordinateTransformation3D(new BasicHep3Vector(0,0,0)),
+ new CoordinateTransformation3D(new BasicHep3Vector(50.0,0,0)),
"box2",
lvTest2,
- lvTest,
- 0);
-
- Box box3 = new Box("test_box3",1.0,1.0,1.0);
+ mom.getLogicalVolume(),
+ 1);
+
+ // 10 cm box at 0,50,0
+ Box box3 = new Box("test_box3",5.0,5.0,5.0);
LogicalVolume lvTest3 = new LogicalVolume("lvTest3",box3,dummymat);
new PhysicalVolume(
- new CoordinateTransformation3D(),
+ new CoordinateTransformation3D(new BasicHep3Vector(0,50.0,0)),
"box3",
lvTest3,
- lvTest2,
- 0);
+ mom.getLogicalVolume(),
+ 2);
+
+ // A 2 cm box inside of box3.
+ Box box4 = new Box("test_box4",2.0,2.0,2.0);
+ LogicalVolume lvTest4 = new LogicalVolume("lvTest4",box4,dummymat);
+ new PhysicalVolume(
+ null,
+ "box4",
+ lvTest4,
+ lvTest3,
+ 0);
+
+ Tube tube1 = new Tube("test_tube1",100.0,200.0,1000.0);
+ //new CoordinateTransformation3D(new BasicHep3Vector(0,0,0))
+ LogicalVolume lvTest5 = new LogicalVolume("lvTest5",tube1,dummymat);
+ new PhysicalVolume(
+ null,
+ "tube1",
+ lvTest5,
+ mom.getLogicalVolume(),
+ 6);
+
+ Tube tube2 = new Tube("test_tube2",110.0,120.0,1000.0);
+ LogicalVolume lvTest6 = new LogicalVolume("lvTest6",tube2,dummymat);
+ new PhysicalVolume(
+ null,
+ "tube2",
+ lvTest6,
+ lvTest5,
+ 7);
}
- public static final IPhysicalVolume createWorld()
+ public final IPhysicalVolume createWorld()
{
Box boxWorld = new Box(
"world_box",
@@ -136,4 +269,13 @@
return pvTop;
}
+
+ public class DummyDE
+ extends DetectorElement
+ {
+ DummyDE(IPhysicalVolumePath support)
+ {
+ super("dummy",null,support,null);
+ }
+ }
}
\ No newline at end of file