Print

Print


Commit in lcsim/src/org/lcsim/recon/cluster/util on MAIN
BothCalorimetersDecision.java+75added 1.1
Check that a pair of clusters consists of one from ECAL and one from HCAL

lcsim/src/org/lcsim/recon/cluster/util
BothCalorimetersDecision.java added at 1.1
diff -N BothCalorimetersDecision.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ BothCalorimetersDecision.java	4 Jul 2006 21:10:45 -0000	1.1
@@ -0,0 +1,75 @@
+package org.lcsim.recon.cluster.util;
+
+import org.lcsim.util.decision.*;
+import org.lcsim.util.*;
+import org.lcsim.event.*;
+
+/**
+ * Require one cluster to be in the ECAL and one to be in the HCAL
+ *
+ * @version $Id: BothCalorimetersDecision.java,v 1.1 2006/07/04 21:10:45 mcharles Exp $
+ */
+public class BothCalorimetersDecision implements DecisionMakerPair<Cluster,Cluster>
+{
+    /**
+     * Constructor.
+     */
+    public BothCalorimetersDecision() {
+	// empty
+    }
+
+    /**
+     * Check a pair of clusters. Return true if one cluster contains hits
+     * in the ECAL but not the HCAL, and the other contains clusters in the
+     * HCAL but not the ECAL. Otherwise, return false.
+     */
+    public boolean valid(Cluster clus1, Cluster clus2) 
+    {
+	// Require at least one hit in each
+	if (clus1.getCalorimeterHits().size()<1 || clus2.getCalorimeterHits().size()<1 ) {
+	    return false;
+	}
+
+	// Check whether the first cluster is (1) pure ECAL, or (2) pure ECAL.
+	boolean onlyECAL1 = true;
+	boolean onlyHCAL1 = true;
+	for (CalorimeterHit hit : clus1.getCalorimeterHits()) {
+	    boolean hitIsECAL = isECAL(hit);
+	    boolean hitIsHCAL = isHCAL(hit);
+	    if (hitIsECAL && hitIsHCAL) {
+		throw new AssertionError("Hit ["+hit+"] is in ECAL and HCAL simultaneously!");
+	    }
+	    onlyECAL1 = onlyECAL1 && hitIsECAL;
+	    onlyHCAL1 = onlyHCAL1 && hitIsHCAL;
+	}
+
+	// Check whether the second cluster is (1) pure ECAL, or (2) pure ECAL.
+	boolean onlyECAL2 = true;
+	boolean onlyHCAL2 = true;
+	for (CalorimeterHit hit : clus2.getCalorimeterHits()) {
+	    boolean hitIsECAL = isECAL(hit);
+	    boolean hitIsHCAL = isHCAL(hit);
+	    if (hitIsECAL && hitIsHCAL) {
+		throw new AssertionError("Hit ["+hit+"] is in ECAL and HCAL simultaneously!");
+	    }
+	    onlyECAL2 = onlyECAL2 && hitIsECAL;
+	    onlyHCAL2 = onlyHCAL2 && hitIsHCAL;
+	}
+
+	// Check that we have one of each
+	return ( (onlyECAL1 && onlyHCAL2) || (onlyECAL2 && onlyHCAL1) );
+    }
+
+    // Inefficient, not general.
+    private boolean isHCAL(CalorimeterHit hit) {
+	org.lcsim.geometry.Subdetector subdet = hit.getSubdetector();
+	String name = subdet.getName();
+	return (name.compareTo("HADBarrel") == 0 || name.compareTo("HADEndcap") == 0);
+    }
+    // Inefficient, not general.
+    private boolean isECAL(CalorimeterHit hit) {
+	org.lcsim.geometry.Subdetector subdet = hit.getSubdetector();
+	String name = subdet.getName();
+	return (name.compareTo("EMBarrel") == 0 || name.compareTo("EMDEndcap") == 0);
+    }
+}
CVSspam 0.2.8