Commit in hps-java/src/main on MAIN
resources/org/lcsim/hps/steering/ecal_1bit_bkgd.lcsim+12-21.2 -> 1.3
                                /ecal_1bit_ap.lcsim+10-11.1 -> 1.2
java/org/lcsim/hps/recon/ecal/HPSTriggerDriver.java+120added 1.1
                             /HPSEcalWindowDiscriminatorReadoutDriver.java+90added 1.1
                             /HPSEcalDiscriminatorReadoutDriver.java+11-31.2 -> 1.3
                             /HPSEcal1BitClusterer.java+11-61.16 -> 1.17
                             /HPSEcalPrintDriver.java+2-11.1 -> 1.2
                             /HPSEcal3Clusterer.java-2161.3 removed
java/org/lcsim/hps/util/ClockSingleton.java+25-51.1 -> 1.2
                       /ClockDriver.java+6-21.1 -> 1.2
java/org/lcsim/hps/analysis/ecal/HPSEcalPlotsDriver.java+5-341.12 -> 1.13
+292-270
2 added + 1 removed + 8 modified, total 11 files
Broke HPSTriggerDriver out of HPSEcalPlotsDriver in preparation for adding fADC trigger. Added window discriminator.

hps-java/src/main/resources/org/lcsim/hps/steering
ecal_1bit_bkgd.lcsim 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- ecal_1bit_bkgd.lcsim	3 Sep 2011 16:48:51 -0000	1.2
+++ ecal_1bit_bkgd.lcsim	7 Oct 2011 23:14:54 -0000	1.3
@@ -1,7 +1,10 @@
 <!--
     Example LCSim steering file to run simple HPS ECal clustering and analysis.
+    @author Sho Uemura <[log in to unmask]>
+    @version $Id: ecal_1bit_bkgd.lcsim,v 1.3 2011/10/07 23:14:54 meeg Exp $
+
 -->
-<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
+<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
        xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd">
     <inputFiles>
         <file>${inputFile}.slcio</file>
@@ -17,6 +20,7 @@
         <driver name="EventMarkerDriver"/>
         <driver name="EcalReadout"/>
         <driver name="EcalClusterer"/>
+        <driver name="EcalTrigger"/>
         <driver name="EcalPlots"/>
         <driver name="Writer"/>
         <driver name="AidaSaveDriver"/>
@@ -29,7 +33,7 @@
         </driver>
         <driver name="EcalReadout"
                 type="org.lcsim.hps.recon.ecal.HPSEcalDiscriminatorReadoutDriver">
-            <readoutCycle>8</readoutCycle>
+            <readoutPeriod>15.0</readoutPeriod>
             <ecalName>Ecal</ecalName>
             <ecalCollectionName>EcalHits</ecalCollectionName>
             <ecalRawCollectionName>EcalRawHits</ecalRawCollectionName>
@@ -42,6 +46,12 @@
             <ecalName>Ecal</ecalName>
             <ecalCollectionName>EcalRawHits</ecalCollectionName>
         </driver>
+        <driver name="EcalTrigger"
+                type="org.lcsim.hps.recon.ecal.HPSTriggerDriver">
+            <clusterCollectionName>EcalClusters</clusterCollectionName>
+            <outputFilePath>${inputFile}_triggers</outputFilePath>
+            <ecalName>Ecal</ecalName>
+        </driver>
         <driver name="EcalPlots"
                 type="org.lcsim.hps.analysis.ecal.HPSEcalPlotsDriver">
             <ecalCollectionName>EcalRawHits</ecalCollectionName>

hps-java/src/main/resources/org/lcsim/hps/steering
ecal_1bit_ap.lcsim 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ecal_1bit_ap.lcsim	3 Sep 2011 16:27:22 -0000	1.1
+++ ecal_1bit_ap.lcsim	7 Oct 2011 23:14:54 -0000	1.2
@@ -1,7 +1,9 @@
 <!--
     Example LCSim steering file to run simple HPS ECal clustering and analysis.
+    @author Sho Uemura <[log in to unmask]>
+    @version $Id: ecal_1bit_ap.lcsim,v 1.2 2011/10/07 23:14:54 meeg Exp $
 -->
-<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
+<lcsim xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
        xs:noNamespaceSchemaLocation="http://www.lcsim.org/schemas/lcsim/1.0/lcsim.xsd">
     <inputFiles>
         <file>${inputFile}.slcio</file>
@@ -17,6 +19,7 @@
         <driver name="EventMarkerDriver"/>
         <driver name="EcalReadout"/>
         <driver name="EcalClusterer"/>
+        <driver name="EcalTrigger"/>
         <driver name="EcalPlots"/>
         <driver name="Writer"/>
         <driver name="AidaSaveDriver"/>
@@ -42,6 +45,12 @@
             <ecalName>Ecal</ecalName>
             <ecalCollectionName>EcalRawHits</ecalCollectionName>
         </driver>
+        <driver name="EcalTrigger"
+                type="org.lcsim.hps.recon.ecal.HPSTriggerDriver">
+            <clusterCollectionName>EcalClusters</clusterCollectionName>
+            <outputFilePath>${inputFile}_triggers</outputFilePath>
+            <ecalName>Ecal</ecalName>
+        </driver>
         <driver name="EcalPlots"
                 type="org.lcsim.hps.analysis.ecal.HPSEcalPlotsDriver">
             <ecalCollectionName>EcalRawHits</ecalCollectionName>

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSTriggerDriver.java added at 1.1
diff -N HPSTriggerDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSTriggerDriver.java	7 Oct 2011 23:14:54 -0000	1.1
@@ -0,0 +1,120 @@
+package org.lcsim.hps.recon.ecal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.hps.util.ClockSingleton;
+import org.lcsim.util.Driver;
+
+/**
+ * Reads clusters and makes trigger decision using opposite quadrant criterion.
+ * Prints triggers to file if file path specified.
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSTriggerDriver.java,v 1.1 2011/10/07 23:14:54 meeg Exp $
+ */
+public class HPSTriggerDriver extends Driver {
+
+    Subdetector ecal;
+    String ecalName;
+    String clusterCollectionName;
+    IDDecoder dec = null;
+    String outputFilePath;
+    PrintWriter outputStream = null;
+    int numTriggers;
+
+    public HPSTriggerDriver() {
+    }
+
+    public void setClusterCollectionName(String clusterCollectionName) {
+        this.clusterCollectionName = clusterCollectionName;
+    }
+
+    public void setEcalName(String ecalName) {
+        this.ecalName = ecalName;
+    }
+
+    public void setOutputFilePath(String outputFilePath) {
+        this.outputFilePath = outputFilePath;
+    }
+
+    public void startOfData() {
+        if (clusterCollectionName == null) {
+            throw new RuntimeException("The parameter ecalCollectionName was not set!");
+        }
+
+        if (ecalName == null) {
+            throw new RuntimeException("The parameter ecalName was not set!");
+        }
+
+        if (outputFilePath != null) {
+            try {
+                outputStream = new PrintWriter(outputFilePath);
+            } catch (IOException ex) {
+                throw new RuntimeException("Invalid outputFilePath!");
+            }
+        }
+
+        numTriggers = 0;
+    }
+
+    public void detectorChanged(Detector detector) {
+        // Get the Subdetector.
+        ecal = detector.getSubdetector(ecalName);
+
+        // Cache ref to decoder.
+        dec = ecal.getIDDecoder();
+    }
+
+    public void process(EventHeader event) {
+        //System.out.println(this.getClass().getCanonicalName() + " - process");
+
+        // Get the list of raw ECal hits.
+        List<HPSEcalCluster> clusters = event.get(HPSEcalCluster.class, clusterCollectionName);
+        if (clusters == null)
+            throw new RuntimeException("Event is missing ECal clusters collection!");
+
+        boolean quadrants[] = new boolean[4];
+
+        for (HPSEcalCluster clus : clusters) {
+            dec.setID(clus.getSeedHit().getCellID());
+            int ix = dec.getValue("ix");
+            int iy = dec.getValue("iy");
+            //System.out.printf("ix = %d, iy = %d\n", ix, iy);
+
+            if (ix > 0) {
+                if (iy > 0) {
+                    quadrants[0] = true;
+                } else {
+                    quadrants[3] = true;
+                }
+            } else {
+                if (iy > 0) {
+                    quadrants[1] = true;
+                } else {
+                    quadrants[2] = true;
+                }
+            }
+        }
+
+        if ((quadrants[0] && quadrants[2]) || (quadrants[1] && quadrants[3])) {
+            numTriggers++;
+            if (outputStream != null)
+                outputStream.printf("Trigger on event %d\n", event.getEventNumber());
+            ClockSingleton.setTrigger();
+        }
+    }
+
+    public void endOfData() {
+        if (outputStream != null) {
+            outputStream.printf("Trigger count: %d\n", numTriggers);
+            outputStream.close();
+        }
+            System.out.printf("Trigger count: %d\n", numTriggers);
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSEcalWindowDiscriminatorReadoutDriver.java added at 1.1
diff -N HPSEcalWindowDiscriminatorReadoutDriver.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ HPSEcalWindowDiscriminatorReadoutDriver.java	7 Oct 2011 23:14:54 -0000	1.1
@@ -0,0 +1,90 @@
+package org.lcsim.hps.recon.ecal;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.IDDecoder;
+import org.lcsim.hps.util.ClockSingleton;
+import org.lcsim.hps.util.RingBuffer;
+
+/**
+ * Performs readout of ECal hits.
+ * Simulates time evolution of preamp output pulse and leading-edge discriminator.
+ * Uses lower and upper thresholds, with upper discriminator acting as a veto.
+ *
+ *
+ * @author Sho Uemura <[log in to unmask]>
+ * @version $Id: HPSEcalWindowDiscriminatorReadoutDriver.java,v 1.1 2011/10/07 23:14:54 meeg Exp $
+ */
+public class HPSEcalWindowDiscriminatorReadoutDriver extends HPSEcalDiscriminatorReadoutDriver {
+    //last time we saw a rising edge
+    Map<Long, Double> lowTimeMap = null;
+    //last time we saw a rising edge
+    Map<Long, Double> highTimeMap = null;
+    double highThreshold = 10.0;
+
+    public HPSEcalWindowDiscriminatorReadoutDriver() {
+    }
+
+    public void setHighThreshold(double highThreshold) {
+        this.highThreshold = highThreshold;
+    }
+
+    protected void readHits(List<HPSRawCalorimeterHit> hits) {
+        IDDecoder dec = ecal.getIDDecoder();
+        for (Long cellID : lowTimeMap.keySet()) {
+            //if there's an output pulse, make a hit
+            if (ClockSingleton.getTime() - lowTimeMap.get(cellID) < outputWidth) {
+                if (highTimeMap.containsKey(cellID) && ClockSingleton.getTime() - highTimeMap.get(cellID) < outputWidth)
+                    continue;
+                dec.setID(cellID);
+                hits.add(new HPSRawCalorimeterHit(outputEnergy, dec.getPosition(), 0.0, cellID, hitType));
+            }
+        }
+    }
+
+    protected void putHits(List<CalorimeterHit> hits) {
+        //fill the readout buffers
+        for (CalorimeterHit hit : hits) {
+            IDDecoder dec = ecal.getIDDecoder();
+            dec.setID(hit.getCellID());
+//            int ix = dec.getValue("ix");
+//            int iy = dec.getValue("iy");
+//            //temporary hack to disable crystals and flip X coordinate
+//            int side = dec.getValue("side");
+//            if (iy == 1 && ix * side >= -10 && ix * side <= -2)
+//                continue;
+
+            RingBuffer eDepBuffer = eDepMap.get(hit.getCellID());
+            if (eDepBuffer == null) {
+                eDepBuffer = new RingBuffer(bufferLength);
+                eDepMap.put(hit.getCellID(), eDepBuffer);
+            }
+            for (int i = 0; i < bufferLength; i++) {
+                eDepBuffer.addToCell(i, hit.getRawEnergy() * pulseAmplitude(i * ClockSingleton.getDt() - hit.getTime()));
+            }
+        }
+
+        //check for rising edges
+        for (Long cellID : eDepMap.keySet()) {
+            RingBuffer eDepBuffer = eDepMap.get(cellID);
+            //if there's a rising edge between now and the next time step, note the time
+            if ((eDepBuffer.currentValue() < threshold)
+                    && (eDepBuffer.getValue(1) > threshold))
+                lowTimeMap.put(cellID, ClockSingleton.getTime());
+            if ((eDepBuffer.currentValue() < highThreshold)
+                    && (eDepBuffer.getValue(1) > highThreshold))
+                highTimeMap.put(cellID, ClockSingleton.getTime());
+            eDepBuffer.step();
+        }
+    }
+
+    protected void initReadout() {
+        //initialize buffers
+        eDepMap = new HashMap<Long, RingBuffer>();
+        lowTimeMap = new HashMap<Long, Double>();
+        highTimeMap = new HashMap<Long, Double>();
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSEcalDiscriminatorReadoutDriver.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- HPSEcalDiscriminatorReadoutDriver.java	30 Sep 2011 23:31:27 -0000	1.2
+++ HPSEcalDiscriminatorReadoutDriver.java	7 Oct 2011 23:14:54 -0000	1.3
@@ -11,10 +11,10 @@
 
 /**
  * Performs readout of ECal hits.
- * Simulates time evolution of preamp output pulse.
+ * Simulates time evolution of preamp output pulse and leading-edge discriminator.
  *
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: HPSEcalDiscriminatorReadoutDriver.java,v 1.2 2011/09/30 23:31:27 meeg Exp $
+ * @version $Id: HPSEcalDiscriminatorReadoutDriver.java,v 1.3 2011/10/07 23:14:54 meeg Exp $
  */
 public class HPSEcalDiscriminatorReadoutDriver extends HPSEcalReadoutDriver {
 
@@ -43,6 +43,11 @@
         this.outputWidth = outputWidth;
     }
 
+    /*
+     * Set shaper time constant.
+     * Positive values interpreted as shaping time of CR-RC pulse;
+     * negative values interpreted as width of rectangular pulse.
+     */
     public void setT0(double t0) {
         this.t0 = t0;
     }
@@ -97,7 +102,10 @@
         edgeTimeMap = new HashMap<Long, Double>();
     }
 
-    private double pulseAmplitude(double time) {
+    /*
+     * Pulse shape as a function of time; normalized to have a peak height of 1.
+     */
+    protected double pulseAmplitude(double time) {
         if (time < 0.0)
             return 0.0;
         if (t0 > 0.0) {

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSEcal1BitClusterer.java 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- HPSEcal1BitClusterer.java	30 Sep 2011 23:31:27 -0000	1.16
+++ HPSEcal1BitClusterer.java	7 Oct 2011 23:14:54 -0000	1.17
@@ -26,7 +26,7 @@
  * @author Jeremy McCormick <[log in to unmask]>
  * @author Tim Nelson <[log in to unmask]>
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: HPSEcal1BitClusterer.java,v 1.16 2011/09/30 23:31:27 meeg Exp $
+ * @version $Id: HPSEcal1BitClusterer.java,v 1.17 2011/10/07 23:14:54 meeg Exp $
  */
 public class HPSEcal1BitClusterer extends Driver implements Clusterer {
 
@@ -36,6 +36,7 @@
     String clusterCollectionName = "EcalClusters";
     // Threshold E for discriminator.
     double hitEMin = .05;
+    double hitEMax = 100.0;
     // Threshold hit count for cluster. Cluster must have more than this many hits.
     int clusterThreshold = 5;
     // Map of crystals to their neighbors.
@@ -56,6 +57,10 @@
         this.hitEMin = hitEMin;
     }
 
+    public void setHitEMax(double hitEMax) {
+        this.hitEMax = hitEMax;
+    }
+
     public void setClusterThreshold(int clusterThreshold) {
         this.clusterThreshold = clusterThreshold;
     }
@@ -127,8 +132,8 @@
         Collection<CalorimeterHit> hitCollection = map.values();
         // Loop over ECal hits to count hit towers
         for (CalorimeterHit hit : hitCollection) {
-            // Cut on min seed E.
-            if (hit.getRawEnergy() < hitEMin) {
+            // Cut on seed E.
+            if (hit.getRawEnergy() < hitEMin || hit.getRawEnergy() > hitEMax) {
                 continue;
             }
 
@@ -188,7 +193,7 @@
                 // Get ID field values.
                 int x2 = dec.getValue("ix");
                 int y2 = dec.getValue("iy");
-                if (y1>0) {
+                if (y1 > 0) {
                     if (x1 > 0) {
                         //quadrant 1
                         if (x1 == 1) {
@@ -301,14 +306,14 @@
                 //System.out.printf("Cluster: x: %d, y: %d, side:%d, hits: %d\n",x1,y1,side1,hitCount);
                 HPSEcalCluster cluster = new HPSEcalCluster(possibleCluster);
                 CalorimeterHit hit = map.get(possibleCluster);
-                if (hit != null && hit.getRawEnergy() > hitEMin) {
+                if (hit != null && hit.getRawEnergy() > hitEMin && hit.getRawEnergy() < hitEMax) {
                     cluster.addHit(hit);
                 }
 
                 for (Long neighborId : neighbors) {
                     // Find the neighbor hit in the event if it exists.
                     hit = map.get(neighborId);
-                    if (hit != null && hit.getRawEnergy() > hitEMin) {
+                    if (hit != null && hit.getRawEnergy() > hitEMin && hit.getRawEnergy() < hitEMax) {
                         cluster.addHit(hit);
                     }
                 }

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSEcalPrintDriver.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- HPSEcalPrintDriver.java	30 Sep 2011 23:31:27 -0000	1.1
+++ HPSEcalPrintDriver.java	7 Oct 2011 23:14:54 -0000	1.2
@@ -16,7 +16,7 @@
  * Performs readout of ECal hits.
  *
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: HPSEcalPrintDriver.java,v 1.1 2011/09/30 23:31:27 meeg Exp $
+ * @version $Id: HPSEcalPrintDriver.java,v 1.2 2011/10/07 23:14:54 meeg Exp $
  */
 public class HPSEcalPrintDriver extends Driver {
 
@@ -51,6 +51,7 @@
 
         if (ecalName == null)
             throw new RuntimeException("The parameter ecalName was not set!");
+
         try {
             outputStream = new PrintWriter(outputFilePath);
         } catch (IOException ex) {

hps-java/src/main/java/org/lcsim/hps/recon/ecal
HPSEcal3Clusterer.java removed after 1.3
diff -N HPSEcal3Clusterer.java
--- HPSEcal3Clusterer.java	3 Sep 2011 00:32:53 -0000	1.3
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,216 +0,0 @@
-package org.lcsim.hps.recon.ecal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.Cluster;
-import org.lcsim.event.EventHeader;
-import org.lcsim.geometry.Detector;
-import org.lcsim.geometry.IDDecoder;
-import org.lcsim.geometry.subdetector.HPSEcal3.NeighborMap;
-import org.lcsim.geometry.subdetector.HPSEcal3;
-import org.lcsim.recon.cluster.util.BasicCluster;
-import org.lcsim.util.Driver;
-import org.lcsim.util.lcio.LCIOConstants;
-
-/**
- * This Driver creates clusters from the CalorimeterHits of an 
- * {@link org.lcsim.geometry.subdetectur.HPSEcal3} detector.
- * 
- * This is based on {@link HPSEcalClusterer}.  It removes the concept
- * of side and uses signed Y indices.
- *  
- * The clustering algorithm is from pages 83 and 84 of the HPS Proposal.
- * 
- * @author Jeremy McCormick <[log in to unmask]>
- * @author Tim Nelson <[log in to unmask]>
- * 
- * @version $Id: HPSEcal3Clusterer.java,v 1.3 2011/09/03 00:32:53 jeremy Exp $
- */
-public class HPSEcal3Clusterer extends Driver 
-{
-    // Reference to the HPSEcal3 subdetector.
-    HPSEcal3 ecal;
-    
-    // Name of collection containing Ecal hits.
-    String ecalCollectionName;
-    
-    // Name of Ecal detector.
-    String ecalName;
-    
-    // Name of Ecal cluster output collection.
-    String clusterCollectionName = "EcalClusters";
-
-    // Execute debug code?
-    boolean debug = false;
-        
-    // Minimum energy [GeV] for cluster seed.
-    double seedEMin = .05;
-    
-    // Minimum energy [GeV] to add hit to cluster.
-    double addEMin = .03;
-        
-    // Map of crystals to their neighbors.
-    NeighborMap neighborMap = null;
-    
-    public HPSEcal3Clusterer()
-    {}
-    
-    public void setDebug(boolean debug)
-    {
-        this.debug = debug;
-    }
-    
-    public void setClusterCollectionName(String clusterCollectionName)
-    {
-        this.clusterCollectionName = clusterCollectionName;
-    }
-    
-    public void setSeedEMin(double seedEMin)
-    {
-        this.seedEMin = seedEMin;
-    }
-    
-    public void setAddEMin(double addEMin)
-    {
-        this.addEMin = addEMin;
-    }
-    
-    public void setEcalCollectionName(String ecalCollectionName)
-    {
-        this.ecalCollectionName = ecalCollectionName;
-    }
-    
-    public void setEcalName(String ecalName)
-    {
-        this.ecalName = ecalName;
-    }
-    
-    public void startOfData()
-    {
-        if (ecalCollectionName == null)
-            throw new RuntimeException("The parameter ecalCollectionName was not set!");
-        
-        if (ecalName == null)
-            throw new RuntimeException("The parameter ecalName was not set!");
-    }   
-    
-    public void detectorChanged(Detector detector)
-    {        
-        // Get the Subdetector.        
-        ecal = (HPSEcal3)detector.getSubdetector(ecalName);
-        
-        // Cache the ref to neighbor map.
-        neighborMap = ecal.getNeighborMap();
-        
-        // Print out subdet params and neighbor map.
-        if (debug)
-        {            
-            System.out.println(ecal.getName());
-            System.out.println("  nx="+ecal.nx());
-            System.out.println("  ny="+ecal.ny());
-            System.out.println("  beamgap="+ecal.beamGap());
-            System.out.println("  dface="+ecal.distanceToFace());
-            
-            System.out.println(neighborMap.toString());
-        }
-    }    
-    
-    public void process(EventHeader event)
-    {
-        //System.out.println(this.getClass().getCanonicalName() + " - process");
-   
-        // Get the list of ECal hits.
-        List<CalorimeterHit> hits = event.get(CalorimeterHit.class, ecalCollectionName);
-        if (hits == null)
-            throw new RuntimeException("Event is missing ECal raw hits collection!");
-                    
-        // Get the decoder for the ECal IDs.
-        IDDecoder dec = ecal.getIDDecoder();
-               
-        // Hit map.
-        Map<Long,CalorimeterHit> hitMap = new HashMap<Long,CalorimeterHit>();
-        
-        // Make a hit map for quick lookup by ID.
-        for (CalorimeterHit hit : hits)
-        {
-            hitMap.put(hit.getCellID(), hit);
-        }
-        
-        // New Cluster list to be added to event.
-        List<Cluster> clusters = new ArrayList<Cluster>();
-        
-        // Loop over ECal hits to find cluster seeds.
-        for (CalorimeterHit hit : hits)
-        {
-            // Cut on min seed E.
-            if (hit.getRawEnergy() < seedEMin)
-                continue;
-             
-            // Get neighbor crystal IDs.
-            Set<Long> neighbors = neighborMap.get(hit.getCellID());
-            
-            /*
-            if (debug)
-            {
-                dec.setID(hit.getCellID());
-                System.out.println(dec.getValue("system") + ", " + dec.getValue("ix") + ", " + dec.getValue("iy"));
-                if (neighbors == null)
-                {                                
-                    throw new RuntimeException("Oops!  Set of neighbors is null!");
-                }
-            }
-            */
-                        
-            // New list for neighboring hits.
-            List<CalorimeterHit> neighborHits = new ArrayList<CalorimeterHit>();
-
-            // Loop over this hit's neighbors to make a hit list for the cluster.
-            boolean isSeed = true;                      
-            for (Long neighborId : neighbors)
-            {                               
-                // Look for the neighbor hit.
-                CalorimeterHit neighborHit = hitMap.get(neighborId);
-                
-                // Does this neighboring crystal have a hit in the event?
-                if (neighborHit != null)
-                {                                             
-                    // Check if the neighbor cell has more energy.
-                    if (neighborHit.getRawEnergy() > hit.getRawEnergy())
-                    {
-                        // Neighbor has more energy, so this cell cannot be a seed.
-                        isSeed = false;
-                        break;
-                    } 
-                    
-                    // Add to the cluster if hit is above the minimum energy.
-                    if (neighborHit.getRawEnergy() >= addEMin)
-                    {
-                        neighborHits.add(neighborHit);
-                    }
-                }                                
-            }
-                      
-            // Did we find a seed?
-            if (isSeed)
-            {
-                // Make a new cluster from the hit list.
-                BasicCluster cluster = new BasicCluster();
-                cluster.addHit(hit);
-                for (CalorimeterHit clusHit : neighborHits)
-                {
-                    cluster.addHit(clusHit);
-                }            
-                clusters.add(cluster);
-            }
-        }
-        
-        // Put Cluster collection into event.
-        int flag = 1 << LCIOConstants.CLBIT_HITS;
-        event.put(clusterCollectionName, clusters, Cluster.class, flag);        
-    }         
-}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/util
ClockSingleton.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ClockSingleton.java	29 Aug 2011 23:03:20 -0000	1.1
+++ ClockSingleton.java	7 Oct 2011 23:14:55 -0000	1.2
@@ -6,21 +6,28 @@
 
 /**
  * singleton clock class - use ClockDriver to control.
- * A better solution might be to store event number/absolute time in the event.
- * 
+ * Also stores trigger state.
+ * A better solution might be to store absolute time and triggers in the event.
+ *
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: ClockSingleton.java,v 1.1 2011/08/29 23:03:20 meeg Exp $
+ * @version $Id: ClockSingleton.java,v 1.2 2011/10/07 23:14:55 meeg Exp $
  */
 public class ClockSingleton {
     public static final ClockSingleton _instance = new ClockSingleton();
 
-    private int clock = 0;
+    private int clock;
     //time between events (bunch spacing)
     private double dt = 2.0;
 
+    private boolean trigger = false;
+
     private ClockSingleton() {
     }
 
+    public static void init() {
+        _instance.clock = 0;
+    }
+
     public static int getClock() {
         return _instance.clock;
     }
@@ -36,8 +43,21 @@
     public static void setDt(double dt) {
         _instance.dt = dt;
     }
-    
+
+    public static boolean triggered() {
+        return _instance.trigger;
+    }
+
+    public static void setTrigger(boolean trigger) {
+        _instance.trigger = trigger;
+    }
+
+    public static void setTrigger() {
+        _instance.trigger = true;
+    }
+
     public static void step() {
         _instance.clock++;
+        _instance.trigger = false;
     }
 }

hps-java/src/main/java/org/lcsim/hps/util
ClockDriver.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ClockDriver.java	29 Aug 2011 23:03:20 -0000	1.1
+++ ClockDriver.java	7 Oct 2011 23:14:55 -0000	1.2
@@ -9,9 +9,9 @@
 
 /**
  * Driver to run the clock in ClockSingleton. Run this driver last.
- * 
+ *
  * @author Sho Uemura <[log in to unmask]>
- * @version $Id: ClockDriver.java,v 1.1 2011/08/29 23:03:20 meeg Exp $
+ * @version $Id: ClockDriver.java,v 1.2 2011/10/07 23:14:55 meeg Exp $
  */
 public class ClockDriver extends Driver {
     public void setDt(double dt) {
@@ -21,4 +21,8 @@
     public void process(EventHeader event) {
         ClockSingleton.step();
     }
+
+    public void startOfData() {
+        ClockSingleton.init();
+    }
 }

hps-java/src/main/java/org/lcsim/hps/analysis/ecal
HPSEcalPlotsDriver.java 1.12 -> 1.13
diff -u -r1.12 -r1.13
--- HPSEcalPlotsDriver.java	30 Sep 2011 23:31:27 -0000	1.12
+++ HPSEcalPlotsDriver.java	7 Oct 2011 23:14:55 -0000	1.13
@@ -34,7 +34,7 @@
  * Diagnostic plots for HPS ECal.
  *
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: HPSEcalPlotsDriver.java,v 1.12 2011/09/30 23:31:27 meeg Exp $
+ * @version $Id: HPSEcalPlotsDriver.java,v 1.13 2011/10/07 23:14:55 meeg Exp $
  */
 public class HPSEcalPlotsDriver extends Driver {
 
@@ -221,6 +221,8 @@
     }
 
     public void process(EventHeader event) {
+        if (ClockSingleton.triggered()) numTriggers++;
+
         // MCParticles
         List<MCParticle> mcparticles = event.get(MCParticle.class).get(0);
 
@@ -287,19 +289,12 @@
         Map<CalorimeterHit, Integer> hitClusMap = new HashMap<CalorimeterHit, Integer>();
 
         double clusE = 0;
-        boolean quadrants[] = new boolean[4];
-        boolean trigger = false;
-        if (!clusters.isEmpty())
-            System.out.printf("Clusters for event %d:\n", event.getEventNumber());
 
         // Get ID helper.
         IIdentifierHelper helper =
                 event.getMetaData(hits).getIDDecoder().getSubdetector().getDetectorElement().getIdentifierHelper();
 
         for (HPSEcalCluster clus : clusters) {
-            int ix = helper.unpack(clus.getSeedHit().getIdentifier()).getValue(helper.getFieldIndex("ix"));
-            int iy = helper.unpack(clus.getSeedHit().getIdentifier()).getValue(helper.getFieldIndex("iy"));
-            System.out.printf("ix = %d, iy = %d\n", ix, iy);
 
             clusNHits.fill(clus.getCalorimeterHits().size());
 
@@ -331,27 +326,7 @@
 
             // Seed E.
             clusSeedEPlot.fill(seedHit.getRawEnergy());
-            if (ix > 0) {
-                if (iy > 0) {
-                    quadrants[0] = true;
-                } else {
-                    quadrants[3] = true;
-                }
-            } else {
-                if (iy > 0) {
-                    quadrants[1] = true;
-                } else {
-                    quadrants[2] = true;
-                }
-            }
-        }
-
-        if ((quadrants[0] && quadrants[2]) || (quadrants[1] && quadrants[3])) {
-            trigger = true;
-            numTriggers++;
-            System.out.printf("Trigger on event %d\n", event.getEventNumber());
         }
-
         // Total E in all clusters.
         clusTotEPlot.fill(clusE);
 
@@ -381,7 +356,7 @@
         int nhits100MeV = 0;
         int nhitsOver100MeV = 0;
 
-        if (trigger && numTriggers <= 100) {
+        if (ClockSingleton.triggered() && numTriggers <= 100) {
             hitXYPlot = aida.histogram2D(
                     ecalCollectionName + " : hit E, event " + String.format("%07d", ClockSingleton.getClock()),
                     47, -23.5, 23.5, 11, -5.5, 5.5);
@@ -435,7 +410,7 @@
             crystalXPlot.fill(ix);
             crystalYPlot.fill(iy);
             crystalXYPlot.fill(ix, iy);
-            if (trigger && numTriggers <= 100)
+            if (ClockSingleton.triggered() && numTriggers <= 100)
                 hitXYPlot.fill(ix, iy, eraw);
         }
 
@@ -488,8 +463,4 @@
         }
         return fsParticles;
     }
-
-    public void endOfData() {
-        System.out.printf("Trigger count: %d\n", numTriggers);
-    }
 }
CVSspam 0.2.8