lcsim/src/org/lcsim/recon/cluster/util
diff -N UpperSubLayerDecision.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ UpperSubLayerDecision.java 21 Oct 2008 22:52:28 -0000 1.1
@@ -0,0 +1,55 @@
+package org.lcsim.recon.cluster.util;
+
+import hep.physics.vec.*;
+import org.lcsim.util.*;
+import org.lcsim.util.decision.*;
+import org.lcsim.geometry.subdetector.CylindricalCalorimeter;
+import org.lcsim.geometry.*;
+import org.lcsim.event.*;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.contrib.uiowa.ReclusterDriver;
+
+/**
+ * Utility class to handle the case where there are two active elements
+ * in a single layer. This class will figure out whether this is the
+ * inner or the outer/upper element.
+ *
+ * @version $Id: UpperSubLayerDecision.java,v 1.1 2008/10/21 22:52:28 mcharles Exp $
+ */
+
+public class UpperSubLayerDecision implements DecisionMakerSingle<CalorimeterHit>
+{
+ public UpperSubLayerDecision() {}
+
+ /**
+ * Returns true if this is the upper/outer element and false if it is the inner element.
+ * Note that both elements have the same cell ID, but that the outer one has a
+ * bigger radius (barrel) or |z| (endcap).
+ */
+ public boolean valid(CalorimeterHit hit) {
+ Hep3Vector cellPos = cellIDPosition(hit);
+ Hep3Vector hitPos = new BasicHep3Vector(hit.getPosition());
+ boolean isEndcap = hit.getSubdetector().isEndcap();
+ double hitZ = Math.abs(hitPos.z());
+ double cellZ = Math.abs(cellPos.z());
+ double hitR = Math.sqrt(hitPos.x()*hitPos.x() + hitPos.y()*hitPos.y());
+ double cellR = Math.sqrt(cellPos.x()*cellPos.x() + cellPos.y()*cellPos.y());
+ if (isEndcap) {
+ boolean upper = (hitZ > cellZ + 0.1); // offset of 0.1 to account for rounding effects
+ return upper;
+ } else {
+ boolean upper = (hitR > cellR + 0.1); // offset of 0.1 to account for rounding effects
+ return upper;
+ }
+ }
+
+ protected Hep3Vector cellIDPosition(CalorimeterHit hit){
+ IDDecoder id = hit.getIDDecoder();
+ id.setID(hit.getCellID());
+ double x = id.getPosition()[0];
+ double y = id.getPosition()[1];
+ double z = id.getPosition()[2];
+ Hep3Vector v = new BasicHep3Vector(x,y,z);
+ return v;
+ }
+}