lcsim/src/org/lcsim/contrib/uiowa/structural/likelihood
diff -u -r1.1 -r1.2
--- MiscUtilities.java 29 Sep 2005 21:04:50 -0000 1.1
+++ MiscUtilities.java 14 Oct 2005 17:39:48 -0000 1.2
@@ -2,10 +2,13 @@
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.Cluster;
+import org.lcsim.recon.cluster.util.BasicCluster;
import hep.physics.vec.BasicHep3Vector;
+import org.lcsim.recon.cluster.util.TensorClusterPropertyCalculator;
import hep.physics.vec.Hep3Vector;
import hep.physics.vec.VecOp;
import java.util.List;
+import org.lcsim.util.swim.Line;
class MiscUtilities
{
@@ -57,4 +60,34 @@
Hep3Vector displacement = VecOp.sub(vect1, vect2);
return displacement.magnitude();
}
+
+ // Make a line from a cluster
+ static protected Line makeLine(Cluster clus) {
+ Hep3Vector[] posAndDir1 = MiscUtilities.getPositionAndDirection(clus);
+ Line line = new Line(posAndDir1[0], posAndDir1[1]);
+ return line;
+ }
+
+ // Find the direction of a cluster
+ static protected Hep3Vector[] getPositionAndDirection(Cluster clus)
+ {
+ if (clus.getCalorimeterHits().size() < 4) {
+ // Too few hits to calculate the tensor
+ return null;
+ }
+
+ BasicCluster copy = new BasicCluster();
+ copy.addCluster(clus);
+ TensorClusterPropertyCalculator calc = new TensorClusterPropertyCalculator();
+ copy.setPropertyCalculator(calc);
+ copy.calculateProperties();
+ double[][]axes = calc.getPrincipleAxis();
+ if (axes == null) {
+ throw new AssertionError("Principal axes not calculated");
+ }
+ Hep3Vector[] posAndDir = new Hep3Vector[2];
+ posAndDir[0] = new BasicHep3Vector(copy.getPosition());
+ posAndDir[1] = new BasicHep3Vector(axes[0][0], axes[0][1], axes[0][2]);
+ return posAndDir;
+ }
}