Print

Print


Commit in java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal on MAIN
CTPEcalClusterer.java+15-13768 -> 769
ECalUtils.java-49768 -> 769
EcalClusterIC.java+63-8768 -> 769
EcalClusterer.java+6-5768 -> 769
EcalConverterDriver.java+9-34768 -> 769
EcalEdepToTriggerConverterDriver.java+18-15768 -> 769
EcalRawConverter.java+2-5768 -> 769
EcalRawConverterDriver.java+7-2768 -> 769
EcalReadoutToTriggerConverterDriver.java+8-9768 -> 769
EcalTriggerFilterDriver.java+10-9768 -> 769
FADCConverterDriver.java+4-4768 -> 769
GTPEcalClusterer.java+7-5768 -> 769
HPSCalorimeterHit.java+41-5768 -> 769
HPSEcalCluster.java+54-36768 -> 769
+244-199
14 modified files
New verified version, a bit more user friendly

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
CTPEcalClusterer.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/CTPEcalClusterer.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/CTPEcalClusterer.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -19,6 +19,8 @@
 import org.lcsim.util.Driver;
 import org.lcsim.lcio.LCIOConstants;
 
+import org.hps.recon.ecal.HPSEcalCluster;
+
 /**
  * Creates clusters from CalorimeterHits in the HPSEcal detector.
  *
@@ -30,6 +32,8 @@
  * @version $Id: CTPEcalClusterer.java,v 1.1 2013/02/25 22:39:24 meeg Exp $
  */
 public class CTPEcalClusterer extends Driver {
+	
+	Detector detector = null;
     // The calorimeter object.
     HPSEcal3 ecal;
     IDDecoder dec;
@@ -50,10 +54,6 @@
     // The minimum energy needed for a hit to be considered.
     double addEMin = 0;
     
-    // Must be declared now to use database conditions
-    HPSEcalCluster cluster = new HPSEcalCluster();    
-    HPSCalorimeterHit seedHit = new HPSCalorimeterHit();
-    
     public CTPEcalClusterer() {
     }
     
@@ -92,9 +92,7 @@
     @Override
     public void detectorChanged(Detector detector) {
     	
-    	// Must be done to be able to use the database conditions
-    	seedHit.setDetector(detector);
-    	cluster.setDetector(detector);
+    	this.detector = detector;
     	
         // Get the Subdetector.
         ecal = (HPSEcal3) detector.getSubdetector(ecalName);
@@ -125,6 +123,9 @@
                 clusterCenters.add(cellID);
             }
         }
+        
+        System.out.println("You are using CTPEcalCluster.java with the database conditions.");
+        
     }
     
     public void process(EventHeader event) {
@@ -136,7 +137,7 @@
             // Define a list of clusters to be filled.
             List<HPSEcalCluster> clusters;
             
-            // If there is a cluster window, run the clsuter window code. A cluster window is a time
+            // If there is a cluster window, run the cluster window code. A cluster window is a time
             // period in nanoseconds during which hits can be applied to the same cluster.
             if (clusterWindow >= 0) {
                 // Create priority queues. These are sorted by the time variable associated with each hit.
@@ -204,7 +205,7 @@
         for (CalorimeterHit hit : hits) {
             // Make a hit map for quick lookup by ID.
             hitMap.put(hit.getCellID(), hit);
-       
+            
             // Get the cell ID for the current crystal's neighbors.
             Set<Long> neighbors = neighborMap.get(hit.getCellID());
             
@@ -353,17 +354,18 @@
                 }
                 
                 // Generate a new cluster seed hit from the above results.
-                seedHit.setParameters(0.0, clusterTime, possibleCluster, hits.get(0).getType());
+                HPSCalorimeterHit seedHit = new HPSCalorimeterHit(0.0, clusterTime, possibleCluster, hits.get(0).getType());               
+                seedHit.setDetector(detector);
                 seedHit.setMetaData(hits.get(0).getMetaData());
                 
                 // Generate a new cluster from the seed hit.
-                cluster.setParameters(seedHit);
-                
+                HPSEcalCluster cluster = new HPSEcalCluster();
+                cluster.setDetector(detector);
+                cluster.setSeedHit(seedHit);
                 // Populate the cluster with each of the chosen neighbors.
                 for (CalorimeterHit clusterHit : hits) {
                     cluster.addHit(clusterHit);
                 }
-                
                 // Add the cluster to the cluster list.
                 clusters.add(cluster);
             }

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
ECalUtils.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/ECalUtils.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/ECalUtils.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -75,53 +75,4 @@
         }
     }
     
-    /** FIXME hard coded id encoding: need to use the id stuff
-     * Return the identity of a channel based on x and y coordinates of the crystal/channel, cellID is needed to create the IIdentifier
-     * The cellID should be 24 bits of the form
-     * [6 signed bits iy][8 signed bits ix][2 unsigned bits layer][6 unsigned bits system]
-     * where system is always 13 and layer is always 0.
-     * @param cellID (long), ix position (int), iy position (int)
-     * @return ID of the channel/crystal (long)
-     */
-    public static long makeID(int ix, int iy){
-
-       String binX;
-       if(0<ix){ 
-    	   binX = Integer.toBinaryString(ix);          
-           while(binX.length()<8){
-        	   binX="0".concat(binX);  
-           }   
-       }
-       else{ 
-    	   binX = Integer.toBinaryString(256+ix);	   
-           while(binX.length()<8){
-        	   binX="0".concat(binX);  
-           } 
-       }
-
-       String binY;
-       if(0<iy){ 
-    	   binY = Integer.toBinaryString(iy);          
-           while(binY.length()<6){
-        	   binY="0".concat(binY);  
-           }   
-       }
-       else{ 
-    	   binY = Integer.toBinaryString(64+iy);
-           while(binY.length()<6){
-        	   binY="0".concat(binY);  
-           } 
-       } 
-
-       String binC = Integer.toBinaryString(13);
-       while(binC.length()<8){
-    	   binC="0".concat(binC);	   
-       }     
-       
-       String strBinNumber = binY.concat(binX).concat(binC);
-    
-       long newID = Integer.parseInt ( strBinNumber , 2);
-       
-       return newID;
-    } 
 }

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalClusterIC.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterIC.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterIC.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -74,8 +74,6 @@
     // Maximum time cut window range. Units in ns.
     double timeWindow = 20.0;
     
-    HPSEcalCluster cluster = new HPSEcalCluster();
-    
        
     public void setClusterCollectionName(String clusterCollectionName) {
         this.clusterCollectionName = clusterCollectionName;
@@ -178,10 +176,6 @@
     }
 
     public void detectorChanged(Detector detector) {
-    	
-    	// Must be set to use database conditions
-    	cluster.setDetector(detector);
-    	
         // Get the calorimeter.
     	HPSEcal3 ecal = (HPSEcal3) detector.getSubdetector(ecalName);
     	
@@ -609,7 +603,7 @@
         }
     }*/
     
-    // Also accounts for pathological case of cluster hits that are EXACTLY the same.
+/*    // Also accounts for pathological case of cluster hits that are EXACTLY the same.
     private static class EnergyComparator implements Comparator<CalorimeterHit> {
         public int compare(CalorimeterHit o1, CalorimeterHit o2) {
         	// If the energies are equivalent, the same, the two hits
@@ -633,8 +627,69 @@
         	else { return 1; }
         }
     }
+*/
+    private static class EnergyComparator implements Comparator<CalorimeterHit> {
+    	/**
+    	 * Compares the first hit with respect to the second. This
+    	 * method will compare hits first by energy, and the spatially.
+    	 * In the case of equal energy hits, the hit closest to the
+    	 * beam gap and closest to the positron side of the detector
+    	 * will be selected. If all of these conditions are true, the
+    	 * hit with the positive y-index will be selected. Hits with
+    	 * all four conditions matching are the same hit.
+    	 * @param hit1 The hit to compare.
+    	 * @param hit2 The hit with respect to which the first should
+    	 * be compared.
+    	 */
+    public int compare(CalorimeterHit hit1, CalorimeterHit hit2) {
+    	// Hits are sorted on a hierarchy by three conditions. First,
+    	// the hits with the highest energy come first. Next, they
+    	// are ranked by vertical proximity to the beam gap, and
+    	// lastly, they are sorted by horizontal proximity to the
+    	// positron side of the detector.
+    	
+    	// Get the hit energies.
+    	double[] e = { hit1.getCorrectedEnergy(), hit2.getCorrectedEnergy() };
+    	
+    	// Perform the energy comparison. The higher energy hit
+    	// will be ordered first.
+    	if(e[0] < e[1]) { return 1; }
+    	else if(e[0] > e[1]) { return -1; }
+    	
+    	// If the hits are the same energy, we must perform the
+    	// spatial comparisons.
+    	else {
+    		// Get the position with respect to the beam gap.
+    		int[] iy = { Math.abs(hit1.getIdentifierFieldValue("iy")), Math.abs(hit2.getIdentifierFieldValue("iy")) };
+    		
+    		// The closest hit is first.
+    		if(iy[0] > iy[1]) { return -1; }
+    		else if(iy[0] < iy[1]) { return 1; }
+    		
+    		// Hits that are identical in vertical distance from
+    		// beam gap and energy are differentiated with distance
+    		// horizontally from the positron side of the detector.
+    		else {
+        		// Get the position from the positron side.
+        		int[] ix = { hit1.getIdentifierFieldValue("ix"), hit2.getIdentifierFieldValue("ix") };
+        		
+        		// The closest hit is first.
+        		if(ix[0] > ix[1]) { return 1; }
+        		else if(ix[0] < ix[1]) { return -1; }
+    			
+        		// If all of these checks are the same, compare
+        		// the raw value for iy. If these are identical,
+        		// then the two hits are the same. Otherwise, sort
+        		// the numerical value of iy. (This removes the
+        		// issue where hits (x, y) and (x, -y) can have
+        		// the same energy and be otherwise seen as the
+        		// same hit from the above checks.
+        		else { return Integer.compare(hit1.getIdentifierFieldValue("iy"), hit2.getIdentifierFieldValue("iy")); }
+    		}
+    	}
+    }
+}
      
-     
     
 
     // Handles pathological case where multiple neighboring crystals have EXACTLY the same energy.

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalClusterer.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterer.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalClusterer.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -26,6 +26,8 @@
  * @version $Id: EcalClusterer.java,v 1.1 2013/02/25 22:39:24 meeg Exp $
  */
 public class EcalClusterer extends Driver {
+	
+	Detector detector = null;
 
     HPSEcal3 ecal;
     String ecalCollectionName;
@@ -39,8 +41,6 @@
     boolean oddX;
     // Map of crystals to their neighbors.
     NeighborMap neighborMap = null;
-    
-    HPSEcalCluster cluster = new HPSEcalCluster();
 
     public EcalClusterer() {
     }
@@ -80,8 +80,7 @@
 
     public void detectorChanged(Detector detector) {
     	
-    	// Must be set to use database conditions
-    	cluster.setDetector(detector);
+    	this.detector = detector;
     	
         // Get the Subdetector.
         ecal = (HPSEcal3) detector.getSubdetector(ecalName);
@@ -164,7 +163,9 @@
             // Did we find a seed?
             if (isSeed) {
                 // Make a cluster from the hit list.
-                cluster.setParameters(hit);
+                HPSEcalCluster cluster = new HPSEcalCluster();
+                cluster.setDetector(detector);
+                cluster.setSeedHit(hit);
                 cluster.addHit(hit);
                 for (CalorimeterHit clusHit : neighborHits) {
                     cluster.addHit(clusHit);

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalConverterDriver.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -3,11 +3,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hps.conditions.TableConstants;
-import org.hps.conditions.ecal.EcalConditions;
-import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawCalorimeterHit;
@@ -22,12 +17,7 @@
  */
 public class EcalConverterDriver extends Driver {
 	
-	// To import database conditions
-    static EcalConditions ecalConditions = null;
-    static IIdentifierHelper helper = null;
-    static EcalChannelCollection channels = null; 
-	
-	HPSCalorimeterHit h = new HPSCalorimeterHit();
+	Detector detector = null;
 
     String rawCollectionName;
     String ecalReadoutName = "EcalHits";
@@ -37,25 +27,6 @@
 //    double pedestal = 0.0;
     double period = 4.0;
     double dt = 0.0;
-    
-    @Override
-    public void detectorChanged(Detector detector) {
-    	
-    	// set the detector for the converter
-        h.setDetector(detector);
-    	
-        // ECAL combined conditions object.
-        ecalConditions = ConditionsManager.defaultInstance()
-                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
-        
-        // List of channels.
-        channels = ecalConditions.getChannelCollection();
-        
-        // ID helper.
-        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
-        
-        System.out.println("You are now using the database conditions for EcalRawConverterDriver.");
-    }
 
     public EcalConverterDriver() {
         flags = 0;
@@ -84,6 +55,11 @@
             throw new RuntimeException("The parameter ecalCollectionName was not set!");
         }
     }
+    
+    @Override
+    public void detectorChanged(Detector detector) {
+    	this.detector = detector;
+    }
 
     @Override
     public void process(EventHeader event) {
@@ -110,10 +86,9 @@
     }
 
     private CalorimeterHit HitDtoA(RawCalorimeterHit hit) {
-    	
-    	h.setParameters(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
-    	
-        return h;
+    	HPSCalorimeterHit h = new HPSCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+        h.setDetector(detector);
+    	return h;
     }
 
 //    private RawCalorimeterHit HitAtoD(CalorimeterHit hit) {

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalEdepToTriggerConverterDriver.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -22,16 +22,21 @@
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
 
+
 /**
  *
  * @version $Id: HPSEcalRawConverterDriver.java,v 1.2 2012/05/03 00:17:54
  * phansson Exp $
  */
 public class EcalEdepToTriggerConverterDriver extends Driver {
-
+	
+	Detector detector = null;
     static EcalConditions ecalConditions = null;
     static IIdentifierHelper helper = null;
     static EcalChannelCollection channels = null; 
+    
+    private static boolean isBadChannelLoaded = true;
+	
     private String ecalReadoutName = "EcalHits";
     private String inputCollection = "EcalHits";
     private String readoutCollection = "EcalCalHits";
@@ -39,17 +44,14 @@
     private boolean applyBadCrystalMap = true;
     private double tp = 14.0;
     private double readoutPeriod = 4.0;
-    private int readoutThreshold = 10;
-    private int triggerThreshold = 10;
+    private int readoutThreshold = 50;
+    private int triggerThreshold = 80;
     private int truncateScale = 128;
     private double pulseIntegral = tp * Math.E / readoutPeriod;
     private double gainScale = 1.0; //gain miscalibration factor
     private double _gain = -1.0; //constant gain, activated if >0
     private boolean addNoise = false;
     private double pePerMeV = 2.0; //photoelectrons per MeV, used to calculate noise
-    private static boolean isBadChannelLoaded = true;
-    HPSCalorimeterHit h = new HPSCalorimeterHit();
-    HPSCalorimeterHit h2 = new HPSCalorimeterHit();
 
     public EcalEdepToTriggerConverterDriver() {
     }
@@ -93,12 +95,12 @@
         }
     }
 
+
     @Override
     public void detectorChanged(Detector detector) {
     	
     	//Must be set to use the database conditions
-    	h.setDetector(detector);
-    	h2.setDetector(detector);
+        this.detector = detector;
     	
         // ECAL combined conditions object.
         ecalConditions = ConditionsManager.defaultInstance()
@@ -113,8 +115,7 @@
         System.out.println("You are now using the database conditions for EcalEdepToTriggerConverterDriver.");
     }
 
-    public static boolean isBadCrystal(CalorimeterHit hit) {
-    	
+    public boolean isBadCrystal(CalorimeterHit hit) {
         // Get the channel data.
         EcalChannelConstants channelData = findChannel(hit.getCellID());
     	
@@ -179,8 +180,9 @@
 
         int truncatedIntegral = (int) Math.floor(triggerIntegral / truncateScale);
         if (truncatedIntegral > 0) {
-        	h.setParameters(truncatedIntegral, hit.getTime(), hit.getCellID(), 0);        	
-            return h;
+        	HPSCalorimeterHit h = new HPSCalorimeterHit(truncatedIntegral, hit.getTime(), hit.getCellID(), 0);
+        	h.setDetector(detector);
+            return h ;
         }
         return null;
     }
@@ -190,6 +192,7 @@
             return null;
         }
 
+        
         // Get the channel data.
         EcalChannelConstants channelData = findChannel(hit.getCellID());
         
@@ -218,8 +221,9 @@
 //        System.out.format("dumb: %f, full: %f\n",hit.getRawEnergy() * 1000.0,readoutIntegral * HPSEcalConditions.physicalToGain(id));
 
 //        System.out.format("readout: %f %f\n", amplitude, integral);
-        h2.setParameters(integral, hit.getTime(), hit.getCellID(), 0);
-        return h2;
+        HPSCalorimeterHit h = new HPSCalorimeterHit(integral, hit.getTime(), hit.getCellID(), 0);
+        h.setDetector(detector);
+        return h;
     }
 
     private double hitAmplitude(CalorimeterHit hit) {
@@ -274,5 +278,4 @@
         // Get the channel data.
         return ecalConditions.getChannelConstants(channels.findChannel(geometryId));    
     }
-    
 }

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalRawConverter.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverter.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverter.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -77,12 +77,10 @@
         double time = hit.getTime();
         long id = hit.getCellID();
         double rawEnergy = adcToEnergy(sumADC(hit), id);
-        
-        HPSCalorimeterHit h1 = new HPSCalorimeterHit();
+        HPSCalorimeterHit h1 = new HPSCalorimeterHit(rawEnergy + 0.0000001, time, id, 0);
         h1.setDetector(detector);
         
 //        double[] pos = hit.getDetectorElement().getGeometry().getPosition().v();
-        h1.setParameters(rawEnergy + 0.0000001, time, id, 0);
         //+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
         return h1;
     }
@@ -97,9 +95,8 @@
         EcalChannelConstants channelData = findChannel(id);
         double adcSum = hit.getAmplitude() - window * channelData.getCalibration().getPedestal();
         double rawEnergy = adcToEnergy(adcSum, id);
-        HPSCalorimeterHit h2 = new HPSCalorimeterHit();
+        HPSCalorimeterHit h2 = new HPSCalorimeterHit(rawEnergy + 0.0000001, time + timeOffset, id, 0);
         h2.setDetector(detector);
-        h2.setParameters(rawEnergy + 0.0000001, time + timeOffset, id, 0);
         //+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
         return h2;
     }

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalRawConverterDriver.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -37,7 +37,9 @@
     static IIdentifierHelper helper = null;
     static EcalChannelCollection channels = null; 
     
-    EcalRawConverter converter = new EcalRawConverter();
+    Detector detector = null;
+    
+    EcalRawConverter converter = null;
     String rawCollectionName = "EcalReadoutHits";
     String ecalReadoutName = "EcalHits";
     String ecalCollectionName = "EcalCalHits";
@@ -52,6 +54,7 @@
     private static boolean isBadChannelLoaded = true;
 
     public EcalRawConverterDriver() {
+    	converter = new EcalRawConverter();    	
     }
 
     public void setUse2014Gain(boolean use2014Gain) {
@@ -104,8 +107,10 @@
     @Override
     public void detectorChanged(Detector detector) {
     	
+    	converter.setDetector(detector);
+    	
     	// set the detector for the converter
-        converter.setDetector(detector);
+        this.detector = detector;
     	
         // ECAL combined conditions object.
         ecalConditions = ConditionsManager.defaultInstance()

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalReadoutToTriggerConverterDriver.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalReadoutToTriggerConverterDriver.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalReadoutToTriggerConverterDriver.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -33,7 +33,8 @@
     static EcalConditions ecalConditions = null;
     static IIdentifierHelper helper = null;
     static EcalChannelCollection channels = null;
-    
+	Detector detector = null;
+	
     String rawCollectionName = "EcalReadoutHits";
     String ecalReadoutName = "EcalHits";
     String ecalCollectionName = "EcalCalHits";
@@ -49,8 +50,6 @@
     private double timeShift = 0;
     private int truncateScale = 128;
     private static boolean isBadChannelLoaded = true;
-    
-    HPSCalorimeterHit h = new HPSCalorimeterHit();
 
     public EcalReadoutToTriggerConverterDriver() {
     }
@@ -95,11 +94,9 @@
     }
 
     @Override
-    public void detectorChanged(Detector detector) {  
+    public void detectorChanged(Detector detector) {
+    	this.detector = detector;
     	
-    	// Must be set to use database conditions
-    	h.setDetector(detector);
-    	
         // ECAL combined conditions object.
         ecalConditions = ConditionsManager.defaultInstance()
                 .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
@@ -209,7 +206,8 @@
         if (truncatedIntegral <= 0) {
             truncatedIntegral = 0;
         }
-        h.setParameters(truncatedIntegral, hitTime, id, 0);
+        HPSCalorimeterHit h = new HPSCalorimeterHit(truncatedIntegral, hitTime, id, 0);
+        h.setDetector(detector);
 //        CalorimeterHit h = new HPSRawCalorimeterHit(triggerIntegral + 0.0000001, hit.getPosition(), hitTime, id, 0);
         //+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
         return h;
@@ -229,7 +227,7 @@
             }
         }
     }
-    
+
     /** 
      * Convert physical ID to gain value.
      * @param cellID (long)
@@ -276,4 +274,5 @@
         return util.getSlot(helper, cellID);         
     }
     
+    
 }

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
EcalTriggerFilterDriver.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalTriggerFilterDriver.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/EcalTriggerFilterDriver.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -17,9 +17,6 @@
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.detector.identifier.IIdentifier;
 import org.lcsim.detector.identifier.IIdentifierHelper;
-import org.lcsim.detector.identifier.Identifier;
-import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
-import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.geometry.Detector;
@@ -36,6 +33,8 @@
     static EcalConditions ecalConditions = null;
     static IIdentifierHelper helper = null;
     static EcalChannelCollection channels = null;
+    int systemId;
+    Detector detector = null;
     
     private String ecalReadoutName = "EcalHits";
     private String inputCollection = "EcalReadoutHits";
@@ -44,8 +43,6 @@
     private int bottomDelay = 5;
     private Queue<List<CalorimeterHit>> topHitsQueue = null;
     private Queue<List<CalorimeterHit>> bottomHitsQueue = null;
-    
-    HPSCalorimeterHit h = new HPSCalorimeterHit();
 
     public EcalTriggerFilterDriver() {
     }
@@ -77,8 +74,7 @@
     @Override
     public void detectorChanged(Detector detector) {
     	
-    	// Must be set to use database conditions
-    	h.setDetector(detector);
+    	this.detector = detector;
     	
         // ECAL combined conditions object.
         ecalConditions = ConditionsManager.defaultInstance()
@@ -89,6 +85,8 @@
         
         // ID helper.
         helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+
+        systemId = detector.getSubdetector("Ecal").getSystemID();
         
         System.out.println("You are now using the database conditions for EcalTriggerFilterDriver.");
     }
@@ -144,11 +142,14 @@
             ix = 24 - ix;
         }
      
+        int values[] = {systemId, ix, iy};
+        GeometryId geomId = new GeometryId(helper, values);       
         // Creating the new channel from cell id, ix and iy, then reading its ID       
-        long newID = ECalUtils.makeID(ix,iy);      
+        long newID = geomId.encode();      
         
-        h.setParameters(hit.getRawEnergy(), hit.getTime()+delay*4, newID, hit.getType());
         //make new hit; set position to null so it gets recalculated
+        HPSCalorimeterHit h = new HPSCalorimeterHit(hit.getRawEnergy(), hit.getTime()+delay*4, newID, hit.getType());
+        h.setDetector(detector);
         return h;
     }
     

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
FADCConverterDriver.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -24,9 +24,9 @@
  */
 public class FADCConverterDriver extends Driver {
 
-    static EcalConditions ecalConditions = null;
-    static IIdentifierHelper helper = null;
-    static EcalChannelCollection channels = null; 
+    EcalConditions ecalConditions = null;
+    IIdentifierHelper helper = null;
+    EcalChannelCollection channels = null; 
     EcalRawConverter converter = null;
     String rawCollectionName = "EcalReadoutHits";
     String ecalReadoutName = "EcalHits";
@@ -133,7 +133,7 @@
      * @param cellID (long)
      * @return channel constants (EcalChannelConstants)
      */
-    private static EcalChannelConstants findChannel(long cellID) {
+    private EcalChannelConstants findChannel(long cellID) {
         // Make an ID object from raw hit ID.
         IIdentifier id = new Identifier(cellID);
         

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
GTPEcalClusterer.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/GTPEcalClusterer.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/GTPEcalClusterer.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -34,9 +34,10 @@
  * @author Sho Uemura
  */
 public class GTPEcalClusterer extends Driver {
+
+	Detector detector = null;
 	
-	HPSEcalCluster cluster = new HPSEcalCluster();
-
+	
     /**
      * <b>calorimeter</b><br/><br/>
      * <code>private HPSEcal3 <b>calorimeter</b></code><br/><br/>
@@ -113,8 +114,7 @@
     @Override
     public void detectorChanged(Detector detector) {
     	
-    	// Must be set to use database conditions
-    	cluster.setDetector(detector);
+    	this.detector = detector;
     	
         // Get the calorimeter object.
         calorimeter = (HPSEcal3) detector.getSubdetector(ecalName);
@@ -159,7 +159,9 @@
 
             // Store the crystals that are part of this potential cluster, 
             // starting with the cluster seed candidate.
-            cluster.setParameters(currentHit);
+            HPSEcalCluster cluster = new HPSEcalCluster();
+            cluster.setDetector(detector);
+            cluster.setSeedHit(currentHit);
             cluster.addHit(currentHit);
 
             // Get the set of neighbors for this hit.

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
HPSCalorimeterHit.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSCalorimeterHit.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSCalorimeterHit.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -35,12 +35,25 @@
     static EcalChannelCollection channels = null; 
 
     /**
-     * Fully qualified constructor
-     * WARNING: any HPSCalorimeterHit created should be created empty
-     * then yourHit.setDetector(detector) called in detectorChanged
-     * then one can use yourHit.setParameters(...) to set the parameters
+     * Fully qualified constructor that sets rawEnergy
+     *
+     * @param energy   Raw energy for this cell
+     * @param position Global Cartesian coordinate for this cell
+     * @param time     Time of energy deposition
+     * @param id       Cell ID
+     * @param type     Type
+     * WARNING: setDetector(detector° must be called after initialization
      */
-    public HPSCalorimeterHit() {
+    public HPSCalorimeterHit(double energy, double time, long id, int type) {
+        this.rawEnergy = energy;
+//      if (position != null) {
+//          this.positionVec = new BasicHep3Vector(position);
+//      } else {
+//          positionVec = null;
+//      }
+      this.time = time;
+      this.id = id;
+      this.type = type;
     }
     
     /**
@@ -51,7 +64,29 @@
      * @param time     Time of energy deposition
      * @param id       Cell ID
      * @param type     Type
+     * WARNING: setDetector(detector) must be called after initialization
      */
+    public HPSCalorimeterHit(CalorimeterHit hit) {
+        this.rawEnergy = hit.getRawEnergy();
+//      if (position != null) {
+//          this.positionVec = new BasicHep3Vector(position);
+//      } else {
+//          positionVec = null;
+//      }
+      this.time = hit.getTime();
+      this.id = hit.getCellID();
+      this.type = hit.getType();
+    }
+    
+    /**
+     * Fully qualified constructor that sets rawEnergy
+     *
+     * @param energy   Raw energy for this cell
+     * @param position Global Cartesian coordinate for this cell
+     * @param time     Time of energy deposition
+     * @param id       Cell ID
+     * @param type     Type
+     */
     public void setParameters(double energy, double time, long id, int type) {
         this.rawEnergy = energy;
 //        if (position != null) {
@@ -117,4 +152,5 @@
 //        System.out.println("You are now using the database conditions for HPSCalorimeterHit.");
     }
     
+    
 }

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
HPSEcalCluster.java 768 -> 769
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSEcalCluster.java	2014-07-15 05:50:52 UTC (rev 768)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/HPSEcalCluster.java	2014-07-15 09:40:38 UTC (rev 769)
@@ -14,6 +14,7 @@
 import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.detector.solids.Trd;
 import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.Cluster;
 import org.lcsim.event.base.BaseCluster;
 import org.lcsim.geometry.Detector;
 
@@ -24,16 +25,14 @@
  * @version $Id: HPSEcalCluster.java,v 1.11 2013/02/25 22:39:24 meeg Exp $
  */
 public class HPSEcalCluster extends BaseCluster {
-
-    private CalorimeterHit seedHit = null;
-    private long cellID;
-    
-    HPSCalorimeterHit h1 = new HPSCalorimeterHit();
-    
+	
     Detector detector = null;    
     static EcalConditions ecalConditions = null;
     static IIdentifierHelper helper = null;
-    static EcalChannelCollection channels = null; 
+    static EcalChannelCollection channels = null;
+
+    private HPSCalorimeterHit seedHit = null;
+    private long cellID;
     
     static final double eCriticalW = 800.0*ECalUtils.MeV/(74+1);
     static final double radLenW = 8.8; //mm
@@ -41,55 +40,74 @@
     private boolean needsElectronPosCalculation = true;
     double[] photonPosAtDepth = new double[3];
     private boolean needsPhotonPosCalculation = true;
-    
+
     /** 
-     * Must be set when an object is created.
-     * @param detector (long)
-     */   
-    public void setDetector(Detector detector) {
-    	
-    	h1.setDetector(detector);
-    	
-        this.detector = detector;
-        
-        // ECAL combined conditions object.
-        ecalConditions = ConditionsManager.defaultInstance()
-                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
-        
-        // List of channels.
-        channels = ecalConditions.getChannelCollection();
-        
-        // ID helper.
-        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
-        
-        System.out.println("You are now using the database conditions for HPSEcalCluster.");
-    }
-    
+     * After the declaration, yourHPSEcalCluster.setDetector(detector) must be called
+     * @param cellID (long)
+     */
     public HPSEcalCluster() {
-    }
+    }    
     
-    public void setParameters(Long cellID) {
+    /** 
+     * After the declaration, yourHPSEcalCluster.setDetector(detector) must be called
+     * @param cellID (long)
+     */
+    public HPSEcalCluster(Long cellID) {
         this.cellID = cellID;
     }
 
-    public void setParameters(CalorimeterHit seedHit) {
-        this.seedHit = seedHit;
+    /** 
+     * Before using this method yourHPSEcalCluster.setDetector(detector) must be called
+     * @param CalorimeterHit
+     */ 
+    public void setSeedHit(CalorimeterHit seedHit) {
+        this.seedHit = new HPSCalorimeterHit(seedHit);
+        ((HPSCalorimeterHit) seedHit).setDetector(detector);
         this.cellID = seedHit.getCellID();
     }
 
+    /**
+     * 
+     * @param 
+     * @return CalorimeterHit
+     */
     public CalorimeterHit getSeedHit() {
         if (seedHit == null) {
             CalorimeterHit hit = hits.get(0);
             if (hit == null) {
                 throw new RuntimeException("HPSEcalCluster has no hits");
             }
-            h1.setParameters(0.0, 0.0, cellID, hit.getType());
-            seedHit = h1;
+            seedHit = new HPSCalorimeterHit(0.0, 0.0, cellID, hit.getType());
+            seedHit.setDetector(detector);
             seedHit.setMetaData(hit.getMetaData());
         }
         return seedHit;
     }
     
+    /** 
+     * Must be set when an object HPSEcalCluster is created.
+     * @param detector (long)
+     */
+    public void setDetector(Detector detector) {
+        this.detector = detector;
+    }
+    
+    /**
+     * Find highest-energy hit in a cluster. For clusters made by GTPEcalClusterer, HPSEcalCluster.getSeedHit(cluster) should be equivalent to cluster.getSeedHit().
+     * Since this method doesn't require that the cluster be an HPSEcalCluster, it will work on clusters read from LCIO.
+     * @param cluster
+     * @return CalorimeterHit
+     */
+    public static CalorimeterHit getSeedHit(Cluster cluster) {
+        CalorimeterHit seedHit = null;
+        for (CalorimeterHit hit : cluster.getCalorimeterHits()) {
+            if (seedHit == null || hit.getCorrectedEnergy() > seedHit.getCorrectedEnergy()) {
+                seedHit = hit;
+            }
+        }
+        return seedHit;
+    }
+    
 //    public double[] getPosition() {
 //        return getSeedHit().getPosition();
 //    }
SVNspam 0.1