lcsim/test
diff -N NeighbourFindingTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NeighbourFindingTest.java 15 Mar 2006 23:47:36 -0000 1.1
@@ -0,0 +1,118 @@
+
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.lcsim.conditions.DetectorLocator;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.compact.Subdetector;
+import org.lcsim.geometry.subdetector.CylindricalCalorimeter;
+
+public class NeighbourFindingTest extends TestCase
+{
+ public static Test suite()
+ {
+ return new TestSuite(NeighbourFindingTest.class);
+ }
+
+ public void testDetectorLocator() throws Exception
+ {
+ List<String> detNames = DetectorLocator.getDetectorNameList();
+
+ // loop over all cached detectors
+ for(String detname : detNames ) {
+ Detector det = DetectorLocator.findDetector(detname);
+ System.out.println("testing <"+det.getName()+">...");
+
+ // loop over all subdetectors
+ Map<String, Subdetector> subdetMap = det.getSubdetectors();
+ for(String subdetName : subdetMap.keySet()) {
+ Subdetector subdet = subdetMap.get(subdetName);
+
+ // test all cylindrical barrels and disk-like endcaps
+ if(subdet instanceof CylindricalCalorimeter) {
+ CylindricalCalorimeter cal = (CylindricalCalorimeter)subdet;
+ if(cal==null) continue;
+
+ IDDecoder decoder = null;
+ try {
+ decoder = cal.getIDDecoder();
+ }
+ catch(Exception x) {
+ System.out.println("Note: no decoder for <"+cal.getName()+">: cal type = "+cal);
+ continue;
+ }
+
+ if(cal.isBarrel()) {
+ // test neighbour finding at difficut situation: phi=0
+ double rmin = cal.getInnerRadius();
+ double rmax = cal.getOuterRadius();
+ double[] pos = new double[3];
+ pos[0] = (rmin+rmax)/2;
+ pos[1] = 0;
+ pos[2] = 0;
+
+ // test cell finding without previously setting a longID into the decoder
+ long refid = decoder.findCellContainingXYZ(pos);
+ assert refid != 0 : "Error: No refID cell returned. Valid input point?";
+
+ if( decoder.supportsNeighbours() ) {
+ // test neighbour finding
+ decoder.setID(refid);
+ long[] neighs = decoder.getNeighbourIDs(1,1,1);
+ assert neighs.length == 26 : "Incorrect # neighbors returned: "+neighs.length;
+ }
+ else {
+ System.out.println("Neighbor finding not supported for <"+cal.getName()+">");
+ continue;
+ }
+ }
+ else {
+ // test neighbour finding at difficut situation: phi=0
+ double rmin = cal.getInnerRadius();
+ double rmax = cal.getOuterRadius();
+ double zmin = cal.getZMin();
+ double zmax = cal.getZMax();
+
+ double[] pos = new double[3];
+ pos[0] = (rmin+rmax)/2;
+ pos[1] = 0;
+
+ // test cell finding without previously setting a longID into the decoder
+
+ // for south
+ pos[2] = (zmin+zmax)/2;
+ long refidSouth = decoder.findCellContainingXYZ(pos);
+ assert refidSouth != 0 : "Error: No refID cell returned. Valid input point?";
+
+ // for north
+ pos[2] = -(zmin+zmax)/2;
+ long refidNorth = decoder.findCellContainingXYZ(pos);
+ assert refidNorth != 0 : "Error: No refID cell returned. Valid input point?";
+
+ assert refidNorth!=refidSouth : "Same refid for north and south ("+refidNorth+")is wrong!";
+
+ if( decoder.supportsNeighbours() ) {
+ // test neighbour finding
+ long[] neighs;
+ decoder.setID(refidSouth);
+ neighs = decoder.getNeighbourIDs(1,1,1);
+ assert neighs.length == 26 : "Incorrect # neighbors returned: "+neighs.length;
+
+ decoder.setID(refidNorth);
+ neighs = decoder.getNeighbourIDs(1,1,1);
+ assert neighs.length == 26 : "Incorrect # neighbors returned: "+neighs.length;
+ }
+ else {
+ System.out.println("Neighbor finding not supported for <"+cal.getName()+">");
+ continue;
+ }
+ }
+ }
+ }
+ }
+ }
+}