Commit in java/trunk/users/src/main/java/org/hps/users/luca on MAIN
CalibTest2.java+1-1842 -> 843
ClusterReader.java-68842 removed
FADCVariableTriggerFEEDriver.java+787added 843
FEETrigger.java+166added 843
PositronAna.java+263added 843
ReconData.java+83-11842 -> 843
ReconDataPos.java+421added 843
TriggerAna.java+419added 843
mycluster3.java+117-13842 -> 843
+2257-93
5 added + 1 removed + 3 modified, total 9 files


java/trunk/users/src/main/java/org/hps/users/luca
CalibTest2.java 842 -> 843
--- java/trunk/users/src/main/java/org/hps/users/luca/CalibTest2.java	2014-08-08 04:38:43 UTC (rev 842)
+++ java/trunk/users/src/main/java/org/hps/users/luca/CalibTest2.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -83,7 +83,7 @@
       eneMCallPlot.fill(particle.getEnergy());
       if(particle.getPDGID()==11)
       {eneEminusPlot.fill(particle.getEnergy());}
-      if(particle.getPDGID()==1 && particle.getEnergy()>2.150)
+      if(particle.getPDGID()==11 && particle.getEnergy()>2.150)
       {eneCoulombEPlot.fill(particle.getEnergy());}
     
       

java/trunk/users/src/main/java/org/hps/users/luca
ClusterReader.java removed after 842
--- java/trunk/users/src/main/java/org/hps/users/luca/ClusterReader.java	2014-08-08 04:38:43 UTC (rev 842)
+++ java/trunk/users/src/main/java/org/hps/users/luca/ClusterReader.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -1,68 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.hps.users.luca;
-
-import hep.aida.IHistogram1D;
-import hep.aida.IHistogram2D;
-import java.io.IOException;
-import java.util.*;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import org.hps.readout.ecal.ClockSingleton;
-import org.hps.readout.ecal.TriggerDriver;
-
-import org.hps.recon.ecal.ECalUtils;
-import org.hps.recon.ecal.HPSEcalCluster;
-import org.lcsim.event.Cluster;
-import org.lcsim.event.EventHeader;
-import org.lcsim.geometry.Detector;
-import org.lcsim.util.aida.AIDA;
-import org.lcsim.util.Driver;
-import hep.aida.*;
-import hep.aida.IHistogram3D;
-import java.io.FileWriter;
-import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.MCParticle;
-
-/**
- *
- * @author mac
- */
-
-
-public class ClusterReader extends Driver {
- protected String clusterCollectionName = "EcalClusters";   
-  
-  @Override
- public void process (EventHeader event){
-   
-          
-           
-           
-     
-     //get the clusters from the event
-     if(event.hasCollection(Cluster.class, "EcalClusters")) {
-        List<Cluster> clusterList =event.get(Cluster.class,clusterCollectionName );
-     
-        for(Cluster cluster : clusterList){
-           List<CalorimeterHit> hits = cluster.getCalorimeterHits();
-        if(cluster.getEnergy()>1.5){System.out.println("Ha energia maggiore! \n");}
-        else{System.out.println("ha energia minore! /n");}
-        
-        }
-        
-        
-        
-        
-     }
-    
-}
-}

java/trunk/users/src/main/java/org/hps/users/luca
FADCVariableTriggerFEEDriver.java added at 843
--- java/trunk/users/src/main/java/org/hps/users/luca/FADCVariableTriggerFEEDriver.java	                        (rev 0)
+++ java/trunk/users/src/main/java/org/hps/users/luca/FADCVariableTriggerFEEDriver.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -0,0 +1,787 @@
+package org.hps.users.luca;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+
+import org.hps.recon.ecal.ECalUtils;
+import org.hps.recon.ecal.HPSEcalCluster;
+import org.lcsim.event.EventHeader;
+import org.hps.readout.ecal.TriggerDriver;
+/**
+ * Class <code>FADCVariableTriggerDriver</code> reads reconstructed
+ * clusters and makes trigger decisions on them. It is designed to
+ * trigger off 2.2 GeV beam A' events. Cuts can either be set manually
+ * in a steering file or automatically by specifying a background level.
+ * The code for generating trigger pairs and handling the coincidence
+ * window comes from <code>FADCTriggerDriver</code>.
+ * 
+ * @author Kyle McCarty
+ * @see FADCTriggerDriver
+ */
+public class FADCVariableTriggerFEEDriver extends TriggerDriver {
+    // ==================================================================
+    // ==== Trigger Cut Default Parameters ==============================
+    // ==================================================================
+    private int minHitCount = 1;								// Minimum required cluster hit count threshold. (Hits)			
+    private double seedEnergyHigh = Double.MAX_VALUE;			// Maximum allowed cluster seed energy. (GeV)
+    private double seedEnergyLow = Double.MIN_VALUE;			// Minimum required cluster seed energy. (GeV)
+    private double clusterEnergyHigh = 1.5 * ECalUtils.GeV;		// Maximum allowed cluster total energy. (GeV)
+    private double clusterEnergyLow = .1 * ECalUtils.GeV;		// Minimum required cluster total energy. (GeV)
+    private double energySumHigh = 1.9 * ECalUtils.GeV;			// Maximum allowed pair energy sum. (GeV)
+    private double energySumLow = 0.0 * ECalUtils.GeV;			// Minimum required pair energy sum. (GeV)
+    private double energyDifferenceHigh = 2.2 * ECalUtils.GeV;	// Maximum allowed pair energy difference. (GeV)
+    private double energySlopeLow = 1.1;						// Minimum required pair energy slope value.
+    private double coplanarityHigh = 35;						// Maximum allowed pair coplanarity deviation. (Degrees)
+    
+    // ==================================================================
+    // ==== Trigger General Default Parameters ==========================
+    // ==================================================================
+    private String clusterCollectionName = "EcalClusters";		// Name for the LCIO cluster collection.
+    private int pairCoincidence = 2;							// Maximum allowed time difference between clusters. (4 ns clock-cycles)
+    private double energySlopeParamF = 0.005500;				// A parameter value used for the energy slope calculation.
+    private double originX = 1393.0 * Math.tan(0.03052);		// ECal mid-plane, defined by photon beam position (30.52 mrad) at ECal face (z=1393 mm)
+    private int backgroundLevel = -1;							// Automatically sets the cuts to achieve a predetermined background rate.
+    
+    // ==================================================================
+    // ==== Driver Internal Variables ===================================
+    // ==================================================================
+    private Queue<List<HPSEcalCluster>> topClusterQueue = null;	// Store clusters on the top half of the calorimeter.
+    private Queue<List<HPSEcalCluster>> botClusterQueue = null;	// Store clusters on the bottom half of the calorimeter.
+    private int allClusters = 0;								// Track the number of clusters processed.
+    private int allPairs = 0;									// Track the number of cluster pairs processed.
+    private int clusterTotalEnergyCount = 0;					// Track the clusters which pass the total energy cut.
+    private int clusterSeedEnergyCount = 0;						// Track the clusters which pass the seed energy cut.
+    private int clusterHitCountCount = 0;						// Track the clusters which pass the hit count cut.
+    private int pairEnergySumCount = 0;							// Track the pairs which pass the energy sum cut.
+    private int pairEnergyDifferenceCount = 0;					// Track the pairs which pass the energy difference cut.
+    private int pairEnergySlopeCount = 0;						// Track the pairs which pass the energy slope cut.
+    private int pairCoplanarityCount = 0;						// Track the pairs which pass the coplanarity cut.
+    
+    /**
+     * Prints out the results of the trigger at the end of the run.
+     */
+    @Override
+    public void endOfData() {
+    	// Print out the results of the trigger cuts.
+    	System.out.printf("Trigger Processing Results%n");
+    	System.out.printf("\tSingle-Cluster Cuts%n");
+    	System.out.printf("\t\tTotal Clusters Processed     :: %d%n", allClusters);
+    	System.out.printf("\t\tPassed Seed Energy Cut       :: %d%n", clusterSeedEnergyCount);
+    	System.out.printf("\t\tPassed Hit Count Cut         :: %d%n", clusterHitCountCount);
+    	System.out.printf("\t\tPassed Total Energy Cut      :: %d%n", clusterTotalEnergyCount);
+    	System.out.printf("%n");
+    	System.out.printf("\tCluster Pair Cuts%n");
+    	System.out.printf("\t\tTotal Pairs Processed        :: %d%n", allPairs);
+    	System.out.printf("\t\tPassed Energy Sum Cut        :: %d%n", pairEnergySumCount);
+    	System.out.printf("\t\tPassed Energy Difference Cut :: %d%n", pairEnergyDifferenceCount);
+    	System.out.printf("\t\tPassed Energy Slope Cut      :: %d%n", pairEnergySlopeCount);
+    	System.out.printf("\t\tPassed Coplanarity Cut       :: %d%n", pairCoplanarityCount);
+    	System.out.printf("%n");
+    	System.out.printf("\tTrigger Count :: %d%n", numTriggers);
+    	
+    	// Run the superclass method.
+        super.endOfData();
+    }
+    
+    /**
+     * Performs single cluster cuts for the event and passes any clusters
+     * which survive to be formed into cluster pairs for the trigger.
+     */
+    @Override
+    public void process(EventHeader event) {
+    	// Process the list of clusters for the event, if it exists.
+        if (event.hasCollection(HPSEcalCluster.class, clusterCollectionName)) {
+        	// Get the collection of clusters.
+        	List<HPSEcalCluster> clusterList = event.get(HPSEcalCluster.class, clusterCollectionName);
+        	
+        	// Create a list to hold clusters which pass the single
+        	// cluster cuts.
+        	List<HPSEcalCluster> goodClusterList = new ArrayList<HPSEcalCluster>(clusterList.size());
+        	
+        	// Sort through the cluster list and add clusters that pass
+        	// the single cluster cuts to the good list.
+        	clusterLoop:
+        	for(HPSEcalCluster cluster : clusterList) {
+        		// Increment the number of processed clusters.
+        		allClusters++;
+        		
+        		// ==== Seed Hit Energy Cut ====================================
+        		// =============================================================
+        		// If the cluster fails the cut, skip to the next cluster.
+        		if(!clusterSeedEnergyCut(cluster)) { continue clusterLoop; }
+        		
+        		// Otherwise, note that it passed the cut.
+        		clusterSeedEnergyCount++;
+        		
+        		// ==== Cluster Hit Count Cut ==================================
+        		// =============================================================
+        		// If the cluster fails the cut, skip to the next cluster.
+        		if(!clusterHitCountCut(cluster)) { continue clusterLoop; }
+        		
+        		// Otherwise, note that it passed the cut.
+        		clusterHitCountCount++;
+        		
+        		// ==== Cluster Total Energy Cut ===============================
+        		// =============================================================
+        		// If the cluster fails the cut, skip to the next cluster.
+        		if(!clusterTotalEnergyCut(cluster)) { continue clusterLoop; }
+        		
+        		// Otherwise, note that it passed the cut.
+        		clusterTotalEnergyCount++;
+        		
+        		// A cluster that passes all of the single-cluster cuts
+        		// can be used in cluster pairs.
+        		goodClusterList.add(cluster);
+        	}
+        	
+        	// Put the good clusters into the cluster queue.
+        	updateClusterQueues(goodClusterList);
+        }
+        
+        // Perform the superclass event processing.
+        super.process(event);
+    }
+    
+    /**
+     * Sets the trigger cuts automatically to a given background level.
+     * 
+     * @param backgroundLevel - The level to which the background should
+     * be set. Actual background rates equal about (5 * backgroundLevel) kHz.
+     */
+    public void setBackgroundLevel(int backgroundLevel) {
+    	this.backgroundLevel = backgroundLevel;
+    }
+    
+    /**
+     * Sets the name of the LCIO collection that contains the clusters.
+     * 
+     * @param clusterCollectionName - The cluster LCIO collection name.
+     */
+    public void setClusterCollectionName(String clusterCollectionName) {
+        this.clusterCollectionName = clusterCollectionName;
+    }
+    
+    /**
+     * Sets the highest allowed energy a cluster may have and still
+     * pass the cluster total energy single cluster cut. Value uses
+     * units of GeV.
+     *
+     * @param clusterEnergyHigh - The parameter value.
+     */
+    public void setClusterEnergyHigh(double clusterEnergyHigh) {
+        this.clusterEnergyHigh = clusterEnergyHigh * ECalUtils.GeV;
+    }
+    
+    /**
+     * Sets the lowest allowed energy a cluster may have and still
+     * pass the cluster total energy single cluster cut. Value uses
+     * units of GeV.
+     *
+     * @param clusterEnergyLow - The parameter value.
+     */
+    public void setClusterEnergyLow(double clusterEnergyLow) {
+        this.clusterEnergyLow = clusterEnergyLow * ECalUtils.GeV;
+    }
+    
+    /**
+     * Sets the maximum deviation from coplanarity that a cluster pair
+     * may possess and still pass the coplanarity pair cut. Value uses
+     * units of degrees.
+     *
+     * @param maxCoplanarityAngle - The parameter value.
+     */
+    public void setCoplanarityHigh(double coplanarityHigh) {
+        this.coplanarityHigh = coplanarityHigh;
+    }
+    
+    /**
+     * Sets the highest allowed energy difference a cluster pair may
+     * have and still pass the cluster pair energy difference cut.
+     * Value uses units of GeV.
+     *
+     * @param energyDifferenceHigh - The parameter value.
+     */
+    public void setEnergyDifferenceHigh(double energyDifferenceHigh) {
+        this.energyDifferenceHigh = energyDifferenceHigh * ECalUtils.GeV;
+    }
+    
+    /**
+     * Sets the lowest allowed energy slope a cluster pair may
+     * have and still pass the cluster pair energy slope cut.
+     *
+     * @param energySlopeLow - The parameter value.
+     */
+    public void setEnergySlopeLow(double energySlopeLow) {
+    	this.energySlopeLow = energySlopeLow;
+    }
+    
+    /**
+     * Sets the highest allowed energy a cluster pair may have and
+     * still pass the cluster pair energy sum cluster cut. Value uses
+     * units of GeV.
+     *
+     * @param energySumHigh - The parameter value.
+     */
+    public void setEnergySumHigh(double energySumHigh) {
+        this.energySumHigh = energySumHigh * ECalUtils.GeV;
+    }
+    
+    /**
+     * Sets the lowest allowed energy a cluster pair may have and
+     * still pass the cluster pair energy sum cluster cut. Value uses
+     * units of GeV.
+     *
+     * @param energySumHigh - The parameter value.
+     */
+    public void setEnergySumLow(double energySumLow) {
+        this.energySumLow = energySumLow * ECalUtils.GeV;
+    }
+    
+    /**
+     * Sets the minimum number of hits needed for a cluster to pass
+     * the hit count single cluster cut.
+     *
+     * @param minHitCount - The parameter value.
+     */
+    public void setMinHitCount(int minHitCount) {
+        this.minHitCount = minHitCount;
+    }
+    
+    /**
+     * Sets X coordinate used as the origin for cluster coplanarity and
+     * slope calculations. This defaults to the calorimeter mid-plane
+     * and is in units of millimeters.
+     *
+     * @param originX - The parameter value.
+     */
+    public void setOriginX(double originX) {
+        this.originX = originX;
+    }
+    
+    /**
+     * Sets the time range over which cluster pairs will be formed.
+     * Value uses units of clock-cycles. Note that the number of
+     * clock-cycles used is calculated as (2 * pairCoincidence) + 1.
+     * 
+     * @param pairCoincidence - The parameter value.
+     */
+    public void setPairCoincidence(int pairCoincidence) {
+        this.pairCoincidence = pairCoincidence;
+    }
+    
+    /**
+     * Sets the highest allowed energy a seed hit may have and still
+     * pass the seed hit energy single cluster cut. Value uses units
+     * of GeV.
+     *
+     * @param seedEnergyHigh - The parameter value.
+     */
+    public void setSeedEnergyHigh(double seedEnergyHigh) {
+        this.seedEnergyHigh = seedEnergyHigh * ECalUtils.GeV;
+    }
+    
+    /**
+     * Sets the lowest allowed energy a seed hit may have and still
+     * pass the seed hit energy single cluster cut. Value uses units
+     * of GeV.
+     *
+     * @param seedEnergyLow - The parameter value.
+     */
+    public void setSeedEnergyLow(double seedEnergyLow) {
+        this.seedEnergyLow = seedEnergyLow * ECalUtils.GeV;
+    }
+    
+    /**
+     * Initializes the cluster pair queues and other variables.
+     */
+    @Override
+    public void startOfData() {
+    	// Make sure that a valid cluster collection name has been
+    	// defined. If it has not, throw an exception.
+        if (clusterCollectionName == null) {
+            throw new RuntimeException("The parameter clusterCollectionName was not set!");
+        }
+    	
+        // Initialize the top and bottom cluster queues.
+        topClusterQueue = new LinkedList<List<HPSEcalCluster>>();
+        botClusterQueue = new LinkedList<List<HPSEcalCluster>>();
+        
+        // Populate the top cluster queue. It should be populated with
+        // a number of empty lists equal to (2 * pairCoincidence + 1).
+        for (int i = 0; i < 2 * pairCoincidence + 1; i++) {
+            topClusterQueue.add(new ArrayList<HPSEcalCluster>());
+        }
+        
+        // Populate the bottom cluster queue. It should be populated with
+        // a number of empty lists equal to (2 * pairCoincidence + 1).
+        for (int i = 0; i < pairCoincidence + 1; i++) {
+            botClusterQueue.add(new ArrayList<HPSEcalCluster>());
+        }
+        
+        // If a background level has been set, pick the correct cuts.
+        if(backgroundLevel != -1) { setBackgroundCuts(backgroundLevel); }
+        
+        // Run the superclass method.
+        super.startOfData();
+    }
+
+    /**
+     * Get a list of all unique cluster pairs in the event
+     *
+     * @param ecalClusters : List of ECal clusters
+     * @return list of cluster pairs
+     */
+    protected List<HPSEcalCluster[]> getClusterPairsTopBot() {
+        // Create a list to store cluster pairs. 
+        List<HPSEcalCluster[]> clusterPairs = new ArrayList<HPSEcalCluster[]>();
+        
+        // Loop over all top-bottom pairs of clusters; higher-energy cluster goes first in the pair
+        // To apply pair coincidence time, use only bottom clusters from the 
+        // readout cycle pairCoincidence readout cycles ago, and top clusters 
+        // from all 2*pairCoincidence+1 previous readout cycles
+        for (HPSEcalCluster botCluster : botClusterQueue.element()) {
+            for (List<HPSEcalCluster> topClusters : topClusterQueue) {
+                for (HPSEcalCluster topCluster : topClusters) {
+                	// The first cluster in a pair should always be
+                	// the higher energy cluster. If the top cluster
+                	// is higher energy, it goes first.
+                    if (topCluster.getEnergy() > botCluster.getEnergy()) {
+                        HPSEcalCluster[] clusterPair = {topCluster, botCluster};
+                        clusterPairs.add(clusterPair);
+                    }
+                    
+                    // Otherwise, the bottom cluster goes first.
+                    else {
+                        HPSEcalCluster[] clusterPair = {botCluster, topCluster};
+                        clusterPairs.add(clusterPair);
+                    }
+                }
+            }
+        }
+        
+        // Return the cluster pair lists.
+        return clusterPairs;
+    }
+    
+	/**
+	 * Determines if the event produces a trigger.
+	 * 
+	 * @return Returns <code>true</code> if the event produces a trigger
+	 * and <code>false</code> if it does not.
+	 */
+	@Override
+	protected boolean triggerDecision(EventHeader event) {
+    	// If there is a list of clusters present for this event,
+    	// check whether it passes the trigger conditions.
+    	if (event.hasCollection(HPSEcalCluster.class, clusterCollectionName)) {
+        	return testTrigger();
+        }
+        
+        // Otherwise, this event can not produce a trigger and should
+        // return false automatically.
+        else { return false; }
+	}
+    
+    /**
+     * Checks whether the argument cluster possesses the minimum
+     * allowed hits.
+     * 
+     * @param cluster - The cluster to check.
+     * @return Returns <code>true</code> if the cluster passes the cut
+     * and <code>false</code> if the cluster does not.
+     */
+    private boolean clusterHitCountCut(HPSEcalCluster cluster) {
+    	return (getValueClusterHitCount(cluster) >= minHitCount);
+    }
+    
+    /**
+     * Checks whether the argument cluster seed hit falls within the
+     * allowed seed hit energy range.
+     * 
+     * @param cluster - The cluster to check.
+     * @return Returns <code>true</code> if the cluster passes the cut
+     * and <code>false</code> if the cluster does not.
+     */
+    private boolean clusterSeedEnergyCut(HPSEcalCluster cluster) {
+    	// Get the cluster seed energy.
+    	double energy = getValueClusterSeedEnergy(cluster);
+    	
+    	// Check that it is above the minimum threshold and below the
+    	// maximum threshold.
+    	return (energy < seedEnergyHigh) && (energy > seedEnergyLow);
+    }
+    
+    /**
+     * Checks whether the argument cluster falls within the allowed
+     * cluster total energy range.
+     * 
+     * @param cluster - The cluster to check.
+     * @return Returns <code>true</code> if the cluster passes the cut
+     * and <code>false</code> if the cluster does not.
+     */
+    private boolean clusterTotalEnergyCut(HPSEcalCluster cluster) {
+    	// Get the total cluster energy.
+    	double energy = getValueClusterTotalEnergy(cluster);
+    	
+    	// Check that it is above the minimum threshold and below the
+    	// maximum threshold.
+    	return (energy < clusterEnergyHigh) && (energy > clusterEnergyLow);
+    }
+    
+    /**
+     * Calculates the distance between two clusters.
+     * 
+     * @param clusterPair - The cluster pair from which the value should
+     * be calculated.
+     * @return Returns the distance between the clusters.
+     */
+    private double getClusterDistance(HPSEcalCluster cluster) {
+        return Math.hypot(cluster.getSeedHit().getPosition()[0] - originX, cluster.getSeedHit().getPosition()[1]);
+    }
+    
+    /**
+     * Gets the value used for the cluster total energy cut.
+     * 
+     * @param cluster - The cluster from which the value should be
+     * derived.
+     * @return Returns the cut value.
+     */
+    private double getValueClusterTotalEnergy(HPSEcalCluster cluster) {
+    	return cluster.getEnergy();
+    }
+    
+    /**
+     * Gets the value used for the cluster hit count cut.
+     * 
+     * @param cluster - The cluster from which the value should be
+     * derived.
+     * @return Returns the cut value.
+     */
+    private int getValueClusterHitCount(HPSEcalCluster cluster) {
+    	return cluster.getCalorimeterHits().size();
+    }
+    
+    /**
+     * Gets the value used for the seed hit energy cut.
+     * 
+     * @param cluster - The cluster from which the value should be
+     * derived.
+     * @return Returns the cut value.
+     */
+    private double getValueClusterSeedEnergy(HPSEcalCluster cluster) {
+    	return cluster.getSeedHit().getCorrectedEnergy();
+    }
+    
+    /**
+     * Calculates the value used by the coplanarity cut.
+     * 
+     * @param clusterPair - The cluster pair from which the value should
+     * be calculated.
+     * @return Returns the cut value.
+     */
+    private double getValueCoplanarity(HPSEcalCluster[] clusterPair) {
+    	// Get the cluster angles.
+    	double[] clusterAngle = new double[2];
+    	for(int i = 0; i < 2; i++) {
+            double position[] = clusterPair[i].getSeedHit().getPosition();
+            //clusterAngle[i] = Math.toDegrees(Math.atan2(position[1], position[0] - originX));
+            //clusterAngle[i] = (clusterAngle[i] + 180.0) % 180.0;
+            clusterAngle[i] = (Math.toDegrees(Math.atan2(position[1], position[0] - originX)) + 180.0) % 180.0;
+    	}
+    	
+    	// Calculate the coplanarity cut value.
+        return Math.abs(clusterAngle[1] - clusterAngle[0]);
+    }
+    
+    /**
+     * Calculates the value used by the energy difference cut.
+     * 
+     * @param clusterPair - The cluster pair from which the value should
+     * be calculated.
+     * @return Returns the cut value.
+     */
+    private double getValueEnergyDifference(HPSEcalCluster[] clusterPair) {
+    	return clusterPair[0].getEnergy() - clusterPair[1].getEnergy();
+    }
+    
+    /**
+     * Calculates the value used by the energy slope cut.
+     * 
+     * @param clusterPair - The cluster pair from which the value should
+     * be calculated.
+     * @return Returns the cut value.
+     */
+    private double getValueEnergySlope(HPSEcalCluster[] clusterPair) {
+    	// E + R*F
+    	// Get the low energy cluster energy.
+    	double slopeParamE = clusterPair[1].getEnergy();
+    	
+    	// Get the low energy cluster radial distance.
+    	double slopeParamR = getClusterDistance(clusterPair[1]);
+    	
+    	// Calculate the energy slope.
+    	return slopeParamE + slopeParamR * energySlopeParamF;
+    }
+    
+    /**
+     * Calculates the value used by the energy sum cut.
+     * 
+     * @param clusterPair - The cluster pair from which the value should
+     * be calculated.
+     * @return Returns the cut value.
+     */
+    private double getValueEnergySum(HPSEcalCluster[] clusterPair) {
+    	return clusterPair[0].getEnergy() + clusterPair[1].getEnergy();
+    }
+    
+    /**
+     * Checks if a cluster pair is coplanar to the beam within a given
+     * angle.
+     *
+     * @param clusterPair - The cluster pair to check.
+     * @return Returns <code>true</code> if the cluster pair passes
+     * the cut and <code>false</code> if it does not.
+     */
+    private boolean pairCoplanarityCut(HPSEcalCluster[] clusterPair) {
+        return (getValueCoplanarity(clusterPair) < coplanarityHigh);
+    }
+    
+    /**
+     * Checks if the energy difference between the clusters making up
+     * a cluster pair is below an energy difference threshold.
+     *
+     * @param clusterPair - The cluster pair to check.
+     * @return Returns <code>true</code> if the cluster pair passes
+     * the cut and <code>false</code> if it does not.
+     */
+    private boolean pairEnergyDifferenceCut(HPSEcalCluster[] clusterPair) {
+        return (getValueEnergyDifference(clusterPair) < energyDifferenceHigh);
+    }
+    
+    /**
+     * Requires that the distance from the beam of the lowest energy
+     * cluster in a cluster pair satisfies the following:
+     * E_low + d_b*.0032 GeV/mm < [ Threshold ]
+     *
+     * @param clusterPair : pair of clusters
+     * @return true if pair is found, false otherwise
+     */
+    private boolean pairEnergySlopeCut(HPSEcalCluster[] clusterPair) {
+    	return (getValueEnergySlope(clusterPair) > energySlopeLow);
+    }
+    
+    /**
+     * Checks if the sum of the energies of clusters making up a cluster
+     * pair is below an energy sum threshold.
+     *
+     * @param clusterPair - The cluster pair to check.
+     * @return Returns <code>true</code> if the cluster pair passes
+     * the cut and <code>false</code> if it does not.
+     */
+    private boolean pairEnergySumCut(HPSEcalCluster[] clusterPair) {
+    	// Get the energy sum value.
+    	double energySum = getValueEnergySum(clusterPair);
+    	
+    	// Check that it is within the allowed range.
+        return (energySum < energySumHigh) && (energySum > energySumLow);
+    }
+	
+    private void setBackgroundCuts(int backgroundLevel) {
+    	// Make sure that the background level is valid.
+    	if(backgroundLevel < 1 || backgroundLevel > 10) {
+    		throw new RuntimeException(String.format("Trigger cuts are undefined for background level %d.", backgroundLevel));
+    	}
+    	
+    	// Otherwise, set the trigger cuts. Certain cuts are constant
+    	// across all background levels.
+    	clusterEnergyLow = 0.000;
+    	seedEnergyLow = 0.100;
+    	
+    	// Set the variable values.
+    	if(backgroundLevel == 1) {
+    		clusterEnergyHigh = 1.700;
+    		seedEnergyHigh = 1.300;
+    		energySumLow = 0.400;
+    		energySumHigh = 2.00;
+    		energyDifferenceHigh = 1.500;
+    		energySlopeLow = 1.0;
+    		coplanarityHigh = 40;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 2) {
+    		clusterEnergyHigh = 1.600;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.300;
+    		energySumHigh = 2.00;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.8;
+    		coplanarityHigh = 40;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 3) {
+    		clusterEnergyHigh = 1.600;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.200;
+    		energySumHigh = 2.000;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.7;
+    		coplanarityHigh = 40;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 4) {
+    		clusterEnergyHigh = 1.500;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.500;
+    		energySumHigh = 1.950;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.6;
+    		coplanarityHigh = 40;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 5) {
+    		clusterEnergyHigh = 1.500;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.400;
+    		energySumHigh = 2.000;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.6;
+    		coplanarityHigh = 45;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 6) {
+    		clusterEnergyHigh = 1.500;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.200;
+    		energySumHigh = 1.950;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.6;
+    		coplanarityHigh = 55;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 7) {
+    		clusterEnergyHigh = 1.700;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.200;
+    		energySumHigh = 2.000;
+    		energyDifferenceHigh = 1.500;
+    		energySlopeLow = 0.6;
+    		coplanarityHigh = 60;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 8) {
+    		clusterEnergyHigh = 1.700;
+    		seedEnergyHigh = 1.300;
+    		energySumLow = 0.200;
+    		energySumHigh = 2.000;
+    		energyDifferenceHigh = 1.500;
+    		energySlopeLow = 0.6;
+    		coplanarityHigh = 65;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 9) {
+    		clusterEnergyHigh = 1.500;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.400;
+    		energySumHigh = 1.950;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.5;
+    		coplanarityHigh = 60;
+    		minHitCount = 2;
+    	} else if(backgroundLevel == 10) {
+    		clusterEnergyHigh = 1.500;
+    		seedEnergyHigh = 1.200;
+    		energySumLow = 0.400;
+    		energySumHigh = 2.000;
+    		energyDifferenceHigh = 1.400;
+    		energySlopeLow = 0.5;
+    		coplanarityHigh = 65;
+    		minHitCount = 2;
+    	}
+    }
+    
+	/**
+	 * Tests all of the current cluster pairs for triggers.
+	 * 
+	 * @return Returns <code>true</code> if one of the cluster pairs
+	 * passes all of the cluster cuts and <code>false</code> otherwise.
+	 */
+    private boolean testTrigger() {
+    	// Get the list of cluster pairs.
+    	List<HPSEcalCluster[]> clusterPairs = getClusterPairsTopBot();
+        
+        // Iterate over the cluster pairs and perform each of the cluster
+        // pair cuts on them. A cluster pair that passes all of the
+        // cuts registers as a trigger.
+    	pairLoop:
+        for (HPSEcalCluster[] clusterPair : clusterPairs) {
+    		// Increment the number of processed cluster pairs.
+    		allPairs++;
+    		
+    		// ==== Pair Energy Sum Cut ====================================
+    		// =============================================================
+    		// If the cluster fails the cut, skip to the next pair.
+    		if(!pairEnergySumCut(clusterPair)) { continue pairLoop; }
+    		
+    		// Otherwise, note that it passed the cut.
+    		pairEnergySumCount++;
+        	
+    		// ==== Pair Energy Difference Cut =============================
+    		// =============================================================
+    		// If the cluster fails the cut, skip to the next pair.
+    		if(!pairEnergyDifferenceCut(clusterPair)) { continue pairLoop; }
+    		
+    		// Otherwise, note that it passed the cut.
+    		pairEnergyDifferenceCount++;
+    		
+    		// ==== Pair Energy Slope Cut ==================================
+    		// =============================================================
+    		// If the cluster fails the cut, skip to the next pair.
+    		//if(!energyDistanceCut(clusterPair)) { continue pairLoop; }
+    		if(!pairEnergySlopeCut(clusterPair)) { continue pairLoop; }
+    		
+    		// Otherwise, note that it passed the cut.
+    		pairEnergySlopeCount++;
+    		
+    		// ==== Pair Coplanarity Cut ===================================
+    		// =============================================================
+    		// If the cluster fails the cut, skip to the next pair.
+    		if(!pairCoplanarityCut(clusterPair)) { continue pairLoop; }
+    		
+    		// Otherwise, note that it passed the cut.
+    		pairCoplanarityCount++;
+    		
+    		// Clusters that pass all of the pair cuts produce a trigger.
+    		return true;
+        }
+        
+        // If the loop terminates without producing a trigger, there
+    	// are no cluster pairs which meet the trigger conditions.
+        return false;
+    }
+    
+    /**
+     * Adds clusters from a new event into the top and bottom cluster
+     * queues so that they may be formed into pairs.
+     * 
+     * @param clusterList - The clusters to add to the queues.
+     */
+    private void updateClusterQueues(List<HPSEcalCluster> clusterList) {
+    	// Create lists to store the top and bottom clusters.
+        ArrayList<HPSEcalCluster> topClusterList = new ArrayList<HPSEcalCluster>();
+        ArrayList<HPSEcalCluster> botClusterList = new ArrayList<HPSEcalCluster>();
+        
+        // Loop over the clusters in the cluster list.
+        for (HPSEcalCluster cluster : clusterList) {
+        	// If the cluster is on the top of the calorimeter, it
+        	// goes into the top cluster list.
+            if (cluster.getSeedHit().getIdentifierFieldValue("iy") > 0) {
+                topClusterList.add(cluster);
+            }
+            
+            // Otherwise, it goes into the bottom cluster list.
+            else { botClusterList.add(cluster); }
+        }
+        
+        // Add the new cluster lists to the cluster queues.
+        topClusterQueue.add(topClusterList);
+        botClusterQueue.add(botClusterList);
+        
+        // Remove the oldest cluster lists from the queues.
+        topClusterQueue.remove();
+        botClusterQueue.remove();
+    }
+}
\ No newline at end of file

java/trunk/users/src/main/java/org/hps/users/luca
FEETrigger.java added at 843
--- java/trunk/users/src/main/java/org/hps/users/luca/FEETrigger.java	                        (rev 0)
+++ java/trunk/users/src/main/java/org/hps/users/luca/FEETrigger.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -0,0 +1,166 @@
+package org.hps.users.luca;
+
+import java.util.List;
+
+import org.hps.readout.ecal.TriggerDriver;
+import org.hps.recon.ecal.HPSEcalCluster;
+
+import org.lcsim.event.EventHeader;
+
+/**
+ * Class <code>FEETrigger</code> represents a single-cluster trigger
+ * that triggers off of clusters which exceed a certain energy threshold.
+ * The trigger considers three regions, each which require a different
+ * number of clusters to occur in said region before the trigger occurs.
+ * 
+ * @author Luca Colaneri
+ */
+public class FEETrigger extends TriggerDriver {
+	// Store the LCIO cluster collection name.
+	private String clusterCollectionName = "EcalClusters";
+	
+	// Store the cluster total energy trigger threshold.
+	private double energyThreshold = 1.5;
+	
+	// Track the number of over-threshold clusters in each region.
+	private int zone1Count = 0;
+	private int zone2Count = 0;
+	private int zone3Count = 0;
+	
+    // The number of cluster over threshold that must occur in a region
+	// before a trigger occurs.
+	private int zone1Prescaling = 1000;
+	private int zone2Prescaling = 100;
+	
+	/**
+	 * Sets the energy threshold required for a cluster to be counted.
+	 * 
+	 * @param energyThreshold - The energy threshold in GeV.
+	 */
+	public void setEnergyThreshold(int energyThreshold) {
+		this.energyThreshold = energyThreshold;
+	}
+	
+	/**
+	 * Sets the number of events over threshold which must occur in the
+	 * first region in order for a trigger to occur.
+	 * 
+	 * @param zone1Prescaling - The number of over-threshold clusters needed
+	 * for a trigger.
+	 */
+	public void setZone1Prescaling(int zone1Prescaling) {
+		this.zone1Prescaling = zone1Prescaling;
+	}
+	
+	/**
+	 * Sets the number of events over threshold which must occur in the
+	 * second region in order for a trigger to occur.
+	 * 
+	 * @param zone2Prescaling - The number of over-threshold clusters needed
+	 * for a trigger.
+	 */
+	public void setZone2Prescaling(int zone2Prescaling) {
+		this.zone2Prescaling = zone2Prescaling;
+	}
+	
+	/**
+	 * Checks if any clusters exist over the set energy threshold and,
+	 * if they do, increments the appropriate over-threshold count
+	 * variable for the zone in which the cluster resides.
+	 * 
+	 * @param event - The event from which clusters should be extracted.
+	 */
+	@Override
+	public void process(EventHeader event) {
+		if(event.hasCollection(HPSEcalCluster.class, clusterCollectionName)) {
+			// Get the list of clusters from the event.
+			List<HPSEcalCluster> clusterList = event.get(HPSEcalCluster.class, clusterCollectionName);
+			
+			// Loop over the clusters and check for any that pass the threshold.
+			for(HPSEcalCluster cluster : clusterList) {
+				// Check if the current cluster exceeds the energy
+				// threshold. If it does not, continue to the next
+				// cluster in the list.
+				if(cluster.getEnergy() > energyThreshold) {
+					// Get the x-index of the seed hit.
+					int ix = cluster.getSeedHit().getIdentifierFieldValue("ix");
+					
+					// Determine in which region the cluster is located
+					// and increment the counter for that region. Zones
+					// are defined as:
+					// Zone 1 is -13 < ix < -4 and 14 < ix < 21
+					// Zone 2 is -20 < ix < -14 and ix > 20
+					// Zone 3 is -23 <= ix < -19
+					if(-23 <= ix && ix < -19) { zone3Count++; }
+					if((-20 < ix && ix < -14) || (ix > 20))  { zone2Count++; }
+					if((-13 < ix && ix < -4) || (14 < ix && ix < 21)) { zone1Count++; }
+				}
+			}
+		}
+		
+		// Run the superclass event processing.
+		super.process(event);
+	}
+	
+	/**
+	 * Checks whether or not a trigger occurred.
+	 * 
+	 * @param event - The event on which to base the trigger decision.
+	 * @return Returns <code>true</code> if a trigger occurred and <code>
+	 * false</code> if a trigger did not.
+	 */
+	@Override
+	protected boolean triggerDecision(EventHeader event) {
+		// Check if the event has clusters. An event with no clusters
+		// should never result in a trigger.
+		if(event.hasCollection(HPSEcalCluster.class, clusterCollectionName)) {
+			// Check if any of the zone counts are high enough to trigger.
+			return triggerTest();
+		}
+		
+		// Events without clusters can not trigger.
+		else { return false; }
+	}
+	
+	/**
+	 * Checks if any of the regional counts are sufficiently high to
+	 * register a trigger.
+	 * 
+	 * @return Returns <code>true</code> if a region has enough clusters
+	 * to trigger and <code>false</code> otherwise.
+	 */
+	private boolean triggerTest() {
+		// Track whether a trigger occurred.
+		boolean trigger = false;
+		
+		// If any clusters occur in zone 3, reset the count and note
+		// that a trigger occurred.
+		if(zone3Count > 0) {
+			zone3Count = 0;
+                         if(zone2Count==zone2Prescaling){zone2Count=0;}
+                         if(zone1Count==zone1Prescaling){zone1Count=0;}
+			trigger = true;
+		}
+		
+		// If zone 2 has sufficient clusters (100 by default) to
+		// trigger, reset its count and note that a trigger occurred.
+		else if(zone2Count == zone2Prescaling) {
+			zone2Count = 0;
+                        if(zone3Count>0){zone3Count=0;}
+                        if(zone1Count==zone1Prescaling){zone1Count=0;}
+			trigger = true;
+		}
+		
+		// If zone 3 has sufficient clusters (1000 by default) to
+		// trigger, reset its count and note that a trigger occurred.
+		else if(zone1Count == zone1Prescaling) {
+			zone1Count = 0;
+                        if(zone3Count>0){zone3Count=0;}
+                        if(zone2Count==zone2Prescaling){zone2Count=0;}
+			trigger = true;
+		}
+		
+		// Return whether or not a trigger occurred.
+		return trigger;
+	}
+}
\ No newline at end of file

java/trunk/users/src/main/java/org/hps/users/luca
PositronAna.java added at 843
--- java/trunk/users/src/main/java/org/hps/users/luca/PositronAna.java	                        (rev 0)
+++ java/trunk/users/src/main/java/org/hps/users/luca/PositronAna.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -0,0 +1,263 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.hps.users.luca;
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogram2D;
+import java.io.IOException;
+import java.util.*;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import org.hps.readout.ecal.ClockSingleton;
+import org.hps.readout.ecal.TriggerDriver;
+
+import org.hps.recon.ecal.ECalUtils;
+import org.hps.recon.ecal.HPSEcalCluster;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.util.Driver;
+import hep.aida.*;
+import hep.aida.IHistogram3D;
+import java.io.FileWriter;
+import org.lcsim.event.ReconstructedParticle;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.MCParticle;
+import org.hps.recon.particle.HpsReconParticleDriver;
+/**
+ *
+ * @author Luca
+ */
+public class PositronAna extends Driver {
+   private FileWriter writer;
+   
+   AIDA aida = AIDA.defaultInstance();
+   IHistogram1D ParticleMass=aida.histogram1D("particles mass", 100, 0, 0.001);
+   IHistogram1D ParticleID=aida.histogram1D("particle ID",100,-20,20);
+   IHistogram1D ParticleCharge=aida.histogram1D("particle charge", 10, -5,5);
+   
+   
+   int poscount=0;
+   int cluscount=0;
+ //   private FileWriter writer2;
+    String outputFileName = "PositronAna.txt";
+ //   String outputFileName2 = "AllHitSlic.txt"; 
+  @Override   
+public void startOfData(){
+
+    
+    
+    
+    
+    try{
+    //initialize the writers
+    writer=new FileWriter(outputFileName);
+   // writer2=new FileWriter(outputFileName2);
+    //Clear the files
+    writer.write("");
+   // writer2.write("");
+    
+    
+    
+}
+catch(IOException e ){
+System.err.println("Error initializing output file for event display.");
+}
+}
+  
+@Override
+public void endOfData(){
+System.out.println("ci sono " + poscount + "positroni e " + cluscount + " clusters \n" );
+    
+    try{
+//close the file writer.
+    writer.close();
+   // writer2.close();
+    }
+catch(IOException e){
+    System.err.println("Error closing utput file for event display.");
+}
+} 
+    public void setOutputFileName(String outputFileName){
+this.outputFileName = outputFileName;
+} 
+    
+    @Override  
+ public void process (EventHeader event){
+ 
+ if(event.hasCollection(ReconstructedParticle.class, "FinalStateParticles")){
+ List<ReconstructedParticle> particles = event.get(ReconstructedParticle.class, "FinalStateParticles");
+ 
+ for(ReconstructedParticle particle: particles){
+ 
+     if(particle.getCharge()>0){
+         poscount++;
+       ParticleCharge.fill(particle.getCharge());
+       ParticleID.fill(particle.getType());
+      
+       double mass=Math.sqrt(particle.getEnergy()*particle.getEnergy() - particle.getMomentum().magnitudeSquared());
+        ParticleMass.fill(mass);
+       List<Cluster> clusters = particle.getClusters();
+      
+      for(Cluster cluster : clusters){
+      cluscount++;
+          int id=getCrystal(cluster);
+          try{
+          writer.append(id + " " + cluster.getEnergy() + " " + cluster.getSize() + " " + HPSEcalCluster.getSeedHit(cluster).getCorrectedEnergy() + " " + HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("ix")+" " +HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("iy")+ "\n");
+          }
+          
+        catch(IOException e ){System.err.println("Error writing to output for event display");} 
+      }
+      
+      
+     }
+ 
+ 
+ }
+ 
+ }
+ 
+ 
+ }
+    
+   
+ public int getCrystal (Cluster cluster){
+ int x,y,id=0;
+ x= (-1)*HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("ix");
+ y= HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("iy");
+ 
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
+ 
+ public int getCrystal (CalorimeterHit hit){
+ int x,y,id=0;
+ x= (-1)*hit.getIdentifierFieldValue("ix");
+ y= hit.getIdentifierFieldValue("iy");
+ 
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }  
+    
+    
+}

java/trunk/users/src/main/java/org/hps/users/luca
ReconData.java 842 -> 843
--- java/trunk/users/src/main/java/org/hps/users/luca/ReconData.java	2014-08-08 04:38:43 UTC (rev 842)
+++ java/trunk/users/src/main/java/org/hps/users/luca/ReconData.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -41,9 +41,9 @@
     
     ArrayList<IHistogram1D> SeedHistograms = new ArrayList<IHistogram1D>(442);
     ArrayList<IHistogram1D> ClustHistograms = new ArrayList<IHistogram1D>(442);
+    // ArrayList<IHistogram1D> HitHistograms = new ArrayList<IHistogram1D>(442);
     
     
-    
     int posx, posy;
     int radius=2;
     int Clustercount=0;
@@ -58,9 +58,9 @@
  
  
     private FileWriter writer;
-    //private FileWriter writer2;
-    String outputFileName = "BeamReadout.txt";
-   // String outputFileName2 = "ClusterEnePos2.txt";
+   // private FileWriter writer2;
+    String outputFileName = "TriTrigRecon.txt";
+   // String outputFileName2 = "TriTrigReconHits.txt";
 
    
  
@@ -108,22 +108,24 @@
     try{
     //initialize the writers
     writer=new FileWriter(outputFileName);
- //   writer2=new FileWriter(outputFileName2);
+  //writer2=new FileWriter(outputFileName2);
     //Clear the files
     writer.write("");
-  //  writer2.write("");
+ //   writer2.write("");
     
   //initialize histograms  
     for(int t=0; t<442; t++){
       String cristallo=String.valueOf(t);  
       String seedhistogram="Seed Hit in Cristal nr " + String.valueOf(t);
       String Clushistogram="Clusters in Cristal nr " + String.valueOf(t);
+      String HitHistogram="All Hits in Crystal nr " + String.valueOf(t);
       
       IHistogram1D seedhisto=aida.histogram1D(seedhistogram, 150, 0.0,3.0);
       IHistogram1D clushisto=aida.histogram1D(Clushistogram, 150, 0.0,3.0);
-      
+    //  IHistogram1D hitshisto=aida.histogram1D(HitHistogram,150,0.0,3.0);
     SeedHistograms.add(seedhisto);
     ClustHistograms.add(clushisto);
+  //  HitHistograms.add(hitshisto);
     }
 }
 catch(IOException e ){
@@ -149,8 +151,8 @@
  public void process (EventHeader event){
    
           
+     
            
-           
      
      //get the clusters from the event
      if(event.hasCollection(Cluster.class, "EcalClusters")) {
@@ -170,6 +172,13 @@
     //Run the sorting algorithm;
      ClusterAnalyzer();
      }
+     
+    
+     
+     
+     
+     
+     
 }
 
  
@@ -202,8 +211,8 @@
      {writer.append(hit.getRawEnergy()+ " ");
        }*/
      writer.append("\n");
-     SeedHistograms.get(id).fill(HPSEcalCluster.getSeedHit(cluster).getCorrectedEnergy());
-     ClustHistograms.get(id).fill(cluster.getEnergy());
+     SeedHistograms.get(id-1).fill(HPSEcalCluster.getSeedHit(cluster).getCorrectedEnergy());
+     ClustHistograms.get(id-1).fill(cluster.getEnergy());
     
      }
      
@@ -302,7 +311,7 @@
      if(x>0){
   id=-x+245;}
  else if(x==-1 )id=245;
- else if(x<-1){id=-x+257;}}
+ else if(x<-1){id=-x+235;}}
  
  
  else if(y==-2)
@@ -329,7 +338,70 @@
  
  }
  
+ public int getCrystal (CalorimeterHit hit){
+ int x,y,id=0;
+ x= (-1)*hit.getIdentifierFieldValue("ix");
+ y= hit.getIdentifierFieldValue("iy");
  
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
  } //chiusura driver  
     
     

java/trunk/users/src/main/java/org/hps/users/luca
ReconDataPos.java added at 843
--- java/trunk/users/src/main/java/org/hps/users/luca/ReconDataPos.java	                        (rev 0)
+++ java/trunk/users/src/main/java/org/hps/users/luca/ReconDataPos.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -0,0 +1,421 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.hps.users.luca;
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogram2D;
+import java.io.IOException;
+import java.util.*;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import org.hps.readout.ecal.ClockSingleton;
+import org.hps.readout.ecal.TriggerDriver;
+
+import org.hps.recon.ecal.ECalUtils;
+import org.hps.recon.ecal.HPSEcalCluster;
+import org.lcsim.event.Cluster;
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.util.Driver;
+import hep.aida.*;
+import hep.aida.IHistogram3D;
+import java.io.FileWriter;
+import org.lcsim.event.CalorimeterHit;
+import org.lcsim.event.MCParticle;
+
+/**
+ * 
+ * @author Luca Colaneri 
+ */
+public class ReconDataPos extends Driver {
+    
+    AIDA aida = AIDA.defaultInstance();
+    
+    ArrayList<IHistogram1D> SeedHistograms = new ArrayList<IHistogram1D>(442);
+    ArrayList<IHistogram1D> ClustHistograms = new ArrayList<IHistogram1D>(442);
+    // ArrayList<IHistogram1D> HitHistograms = new ArrayList<IHistogram1D>(442);
+    
+    
+    int posx, posy;
+    int radius=2;
+    int Clustercount=0;
+    int clusterWindow=50;
+    int TotalCluster=0;
+    int TotalCluster2=0;
+    double timeDifference;
+    double energyThreshold=1.5;
+    private LinkedList<ArrayList<Cluster>> clusterBuffer;
+    protected String clusterCollectionName = "EcalClusters";
+    
+ 
+ 
+    private FileWriter writer;
+    private FileWriter writer2;
+    String outputFileName1 = "TriTrigReconAllSeeds.txt";
+    String outputFileName2 = "TriTrigReconAllHits.txt";
+
+   
+ 
+   
+   public void setRadius (int radius){
+         this.radius=radius;
+                 }
+    
+    public void setEnergyThreshold (double threshold){
+    this.energyThreshold=threshold;
+    }
+   
+    public void setClusterCollectionName(String clusterCollectionName) {
+        this.clusterCollectionName = clusterCollectionName;
+    }
+ 
+   public void setOutputFileName1(String outputFileName){
+this.outputFileName1 = outputFileName;
+}
+    public void setOutputFileName2(String outputFileName2){
+this.outputFileName2 = outputFileName2;
+}
+   public void settimeDifference(double time){
+   this.timeDifference=time;
+   
+   }
+  /*
+   *
+   *
+   *
+   */
+   
+   @Override   
+public void startOfData(){
+
+    //initialize the clusterbuffer
+    clusterBuffer= new LinkedList<ArrayList<Cluster>>();
+ //populate the clusterbuffer with (2*clusterWindow + 1)
+ // empty events, representing the fact that the first few events will not have any events in the past portion of the buffer
+    int bufferSize=(2*clusterWindow)+1;
+    for(int i = 0;i<bufferSize; i++){
+    clusterBuffer.add(new ArrayList<Cluster>());
+    }
+    
+    
+    
+    
+    try{
+    //initialize the writers
+    writer=new FileWriter(outputFileName1);
+    writer2=new FileWriter(outputFileName2);
+    //Clear the files
+    writer.write("");
+    writer2.write("");
+    
+  //initialize histograms  
+    for(int t=0; t<442; t++){
+      String cristallo=String.valueOf(t);  
+      String seedhistogram="Seed Hit in Cristal nr " + String.valueOf(t);
+      String Clushistogram="Clusters in Cristal nr " + String.valueOf(t);
+      String HitHistogram="All Hits in Crystal nr " + String.valueOf(t);
+      
+      IHistogram1D seedhisto=aida.histogram1D(seedhistogram, 150, 0.0,3.0);
+      IHistogram1D clushisto=aida.histogram1D(Clushistogram, 150, 0.0,3.0);
+    //  IHistogram1D hitshisto=aida.histogram1D(HitHistogram,150,0.0,3.0);
+    SeedHistograms.add(seedhisto);
+    ClustHistograms.add(clushisto);
+  //  HitHistograms.add(hitshisto);
+    }
+}
+catch(IOException e ){
+System.err.println("Error initializing output file for event display.");
+}
+}
+  
+@Override
+public void endOfData(){
+System.out.println("Ho contato" + TotalCluster + " clusters di cui " +TotalCluster2 + "con E>1.5 e "+ Clustercount + "isolati\n");
+    
+    try{
+//close the file writer.
+    writer.close();
+    writer2.close();
+    }
+catch(IOException e){
+    System.err.println("Error closing output file for event display.");
+}
+} 
+   
+ @Override  
+ public void process (EventHeader event){
+   
+          
+     
+           
+     
+     //get the clusters from the event
+     if(event.hasCollection(Cluster.class, "EcalClusters")) {
+        List<Cluster> clusterList =event.get(Cluster.class,clusterCollectionName );    
+             
+     //put the clusters in the arraylist
+     
+     ArrayList<Cluster> clusterSet = new ArrayList<Cluster>(); 
+     for(Cluster cluster : clusterList){
+         TotalCluster++;
+         if(cluster.getEnergy()>1.5){TotalCluster2++;}
+         clusterSet.add(cluster);
+     }
+     //remove the last event from cluster buffer and add the new one
+     clusterBuffer.removeLast();
+     clusterBuffer.addFirst(clusterSet);
+    //Run the sorting algorithm;
+     ClusterAnalyzer();
+     }
+     
+        if(event.hasCollection(CalorimeterHit.class, "EcalCorrectedHits")) {
+     List<CalorimeterHit> hits=event.get(CalorimeterHit.class,"EcalCorrectedHits");
+         for(CalorimeterHit hit : hits){
+         int idd=getCrystal(hit);
+         try{writer2.append(idd+" "+hit.getCorrectedEnergy()+" "+ hit.getIdentifierFieldValue("ix")+ " " + hit.getIdentifierFieldValue("iy")+"\n ");}
+         catch(IOException e ){System.err.println("Error writing to output for event display");}
+         }    
+             
+     }
+ 
+    
+     
+     
+     
+     
+     
+}
+
+ 
+ /**
+  * For each crystal, looks for clusters that hit that clystar, if it is an isolated cluster, it's put in goodclusterqueue
+  */
+ public void ClusterAnalyzer(){
+ //get the cluster list at the current time in the buffer
+ArrayList<Cluster> currentClusters = clusterBuffer.get(clusterWindow+1);
+
+
+ ///cerca i cluster nella posizione che ci interessa poi chiama la funzione che decide se sono "isolati"
+   //System.out.println("Sta partendo il for sulla Queue \n");
+ for(int y=-5;y<6;y++){
+     for(int x=-23;x<24;x++){
+      posx=x;
+      posy=y;
+         
+         //ciclo for nel set di currentCluster, ovvero il set nel mezzo del buffer
+    for(Cluster cluster : currentClusters){ 
+    if((HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("ix")== posx) && (HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("iy")==posy )){
+        
+           if(ClusterChecker(cluster)){
+            int id;
+            Clustercount++;
+           id=getCrystal(cluster);
+           try{
+     writer.append(id + " " + cluster.getEnergy()+ " " + cluster.getSize() + " " + HPSEcalCluster.getSeedHit(cluster).getCorrectedEnergy() + " " + HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("ix")+" " +HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("iy"));
+     /*for(CalorimeterHit hit : cluster.getCalorimeterHits())
+     {writer.append(hit.getRawEnergy()+ " ");
+       }*/
+     writer.append("\n");
+     SeedHistograms.get(id-1).fill(HPSEcalCluster.getSeedHit(cluster).getCorrectedEnergy());
+     ClustHistograms.get(id-1).fill(cluster.getEnergy());
+    
+     }
+     
+   catch(IOException e ){System.err.println("Error writing to output for event display");}   
+           
+           }
+      }
+     
+     
+    }
+ 
+ 
+ 
+ }
+ }
+ 
+ 
+ 
+ 
+
+ }
+ /**
+  * Check if the cluster is isolaterd checking if there are clusters near it in time and in space in the buffer
+  * @param cluster
+  * @return 
+  */
+ 
+public boolean ClusterChecker (Cluster cluster){
+//System.out.println("Sono nel clustercheck! \n");
+    
+boolean check=true;
+  
+    //ciclo sulle liste del buffer
+loops:
+     for(ArrayList<Cluster> currentList : clusterBuffer){
+     //ciclo sui cluster della lista corrente
+         for(Cluster currentcluster : currentList){
+           if(currentcluster!= cluster){
+             //if there is a cluster in the buffer that is in the considered radius in a time window lower than expected, the loop is brocken and the analyzed cluster is not good
+         if(!((HPSEcalCluster.getSeedHit(currentcluster).getIdentifierFieldValue("ix") < posx-radius || HPSEcalCluster.getSeedHit(currentcluster).getIdentifierFieldValue("ix")> posx+radius)&& (HPSEcalCluster.getSeedHit(currentcluster).getIdentifierFieldValue("iy")< posy-radius || HPSEcalCluster.getSeedHit(currentcluster).getIdentifierFieldValue("iy")> posy+radius))&& Math.abs(HPSEcalCluster.getSeedHit(cluster).getTime()-HPSEcalCluster.getSeedHit(currentcluster).getTime())<timeDifference){
+         check=false;
+         break loops;
+         }
+           }
+           
+        
+         
+         }
+      
+     
+     }
+        
+        
+   
+return check;
+
+}
+      
+ 
+ 
+ public int getCrystal (Cluster cluster){
+ int x,y,id=0;
+ x= (-1)*HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("ix");
+ y= HPSEcalCluster.getSeedHit(cluster).getIdentifierFieldValue("iy");
+ 
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
+ 
+ public int getCrystal (CalorimeterHit hit){
+ int x,y,id=0;
+ x= (-1)*hit.getIdentifierFieldValue("ix");
+ y= hit.getIdentifierFieldValue("iy");
+ 
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
+ } //chiusura driver  
+    
+    
+    

java/trunk/users/src/main/java/org/hps/users/luca
TriggerAna.java added at 843
--- java/trunk/users/src/main/java/org/hps/users/luca/TriggerAna.java	                        (rev 0)
+++ java/trunk/users/src/main/java/org/hps/users/luca/TriggerAna.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -0,0 +1,419 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.hps.users.luca;
+import hep.aida.IHistogram1D;
+import hep.aida.IHistogram2D;
+import java.io.IOException;
+import java.util.*;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import org.hps.readout.ecal.ClockSingleton;
+import org.hps.readout.ecal.TriggerDriver;
+
+import org.hps.recon.ecal.ECalUtils;
+import org.hps.recon.ecal.HPSEcalCluster;
+
+import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
+import org.lcsim.util.aida.AIDA;
+import org.lcsim.util.Driver;
+import hep.aida.*;
+
+import java.io.FileWriter;
+import org.lcsim.event.CalorimeterHit;
+
+
+/**
+ * 
+ * @author Luca Colaneri 
+ */
+public class TriggerAna extends Driver {
+    int posx, posy;
+    int radius=2;
+    int Clustercount=0;
+    int clusterWindow=50;
+    int TotalCluster=0;
+    double timeDifference;
+    double energyThreshold=1.5;
+    private LinkedList<ArrayList<HPSEcalCluster>> clusterBuffer;
+    protected String clusterCollectionName = "EcalClusters";
+    
+ AIDA aida = AIDA.defaultInstance();
+IHistogram1D clusterEne=aida.histogram1D("Clusters energy with Kyle's trigger",300, 0, 3);
+    private FileWriter writer;
+    private FileWriter writer2;
+    private FileWriter writer3;
+    private FileWriter writer4;
+    String outputFileName = "KyleTriggerFEE.txt";
+    String outputFileName2 = "KyleTriggerHits.txt";
+    String outputFileName3 = "NoTriggerFEE.txt";
+   
+   
+ 
+   
+   public void setRadius (int radius){
+         this.radius=radius;
+                 }
+    
+    public void setEnergyThreshold (double threshold){
+    this.energyThreshold=threshold;
+    }
+   
+    public void setClusterCollectionName(String clusterCollectionName) {
+        this.clusterCollectionName = clusterCollectionName;
+    }
+ 
+   public void setOutputFileName(String outputFileName){
+this.outputFileName = outputFileName;
+}
+   public void setOutputFileName2(String outputFileName2){
+this.outputFileName2 = outputFileName2;
+   }
+   public void settimeDifference(double time){
+   this.timeDifference=time;
+   
+   }
+  /*
+   *
+   *
+   *
+   */
+   
+   @Override   
+public void startOfData(){
+
+    //initialize the clusterbuffer
+    clusterBuffer= new LinkedList<ArrayList<HPSEcalCluster>>();
+ //populate the clusterbuffer with (2*clusterWindow + 1)
+ // empty events, representing the fact that the first few events will not have any events in the past portion of the buffer
+    int bufferSize=(2*clusterWindow)+1;
+    for(int i = 0;i<bufferSize; i++){
+    clusterBuffer.add(new ArrayList<HPSEcalCluster>(0));
+    }
+    
+    
+    
+    
+    try{
+    //initialize the writers
+    writer=new FileWriter(outputFileName);
+    writer2=new FileWriter(outputFileName2);
+    writer3=new FileWriter(outputFileName3);
+    
+    //Clear the files
+    writer.write("");
+    writer2.write("");
+    writer3.write("");
+    
+    
+    
+}
+catch(IOException e ){
+System.err.println("Error initializing output file for event display.");
+}
+}
+  
+@Override
+public void endOfData(){
+System.out.println("Ho contato" + TotalCluster + " clusters di cui " + Clustercount + "isolati\n");
+    
+    try{
+//close the file writer.
+    writer.close();
+    writer2.close();
+    writer3.close();
+    
+    }
+catch(IOException e){
+    System.err.println("Error closing utput file for event display.");
+}
+} 
+   
+ @Override  
+ public void process (EventHeader event){
+   
+          if(event.hasCollection(HPSEcalCluster.class, "EcalClusters")) {
+        List<HPSEcalCluster> clusterList =event.get(HPSEcalCluster.class,clusterCollectionName );   
+            for(HPSEcalCluster cluster : clusterList){
+                
+                if(cluster.getEnergy()>energyThreshold){
+                 int idd=getCrystal(cluster); 
+                    try{
+                        writer3.append(idd + " " + cluster.getEnergy()+ " " + cluster.getSize() + " " + cluster.getSeedHit().getRawEnergy() + " " + cluster.getSeedHit().getIdentifierFieldValue("ix")+" " +cluster.getSeedHit().getIdentifierFieldValue("iy")+"\n");
+                        }
+                    catch(IOException e ){System.err.println("Error writing to output for event display");} 
+                 }
+            }
+          
+          }
+           
+     
+     //get the clusters from the event IF they are triggered
+    if(TriggerDriver.triggerBit()){
+     if(event.hasCollection(HPSEcalCluster.class, "EcalClusters")) {
+        List<HPSEcalCluster> clusterList =event.get(HPSEcalCluster.class,clusterCollectionName );    
+             
+     //put the clusters in the arraylist
+     
+     ArrayList<HPSEcalCluster> clusterSet = new ArrayList<HPSEcalCluster>(); 
+     for(HPSEcalCluster cluster : clusterList){
+         clusterEne.fill(cluster.getEnergy());
+         TotalCluster++;
+         clusterSet.add(cluster);
+     }
+     //remove the last event from cluster buffer and add the new one
+     clusterBuffer.removeLast();
+     clusterBuffer.addFirst(clusterSet);
+    //Run the sorting algorithm;
+     ClusterAnalyzer();
+     }
+     
+      //get the hits from the event
+     if(event.hasCollection(CalorimeterHit.class,"EcalCorrectedHits")){
+     List<CalorimeterHit> hits =event.get(CalorimeterHit.class,"EcalCorrectedHits");
+     
+     for(CalorimeterHit hit : hits){
+     int id=getCrystal(hit)-1;
+     
+     try{    writer2.append(id + " " + hit.getRawEnergy()+ "\n");}
+      catch(IOException e ){System.err.println("Error writing to output for event display");} 
+     }
+     
+     }
+     
+    }
+     
+}
+
+ 
+ /**
+  * For each crystal, looks for clusters that hit that clystar, if it is an isolated cluster, it's put in goodclusterqueue
+  */
+ public void ClusterAnalyzer(){
+ //get the cluster list at the current time in the buffer
+ArrayList<HPSEcalCluster> currentClusters = clusterBuffer.get(clusterWindow+1);
+
+
+ ///cerca i cluster nella posizione che ci interessa poi chiama la funzione che decide se sono "isolati"
+   //System.out.println("Sta partendo il for sulla Queue \n");
+ for(int y=-5;y<6;y++){
+     for(int x=-23;x<24;x++){
+      posx=x;
+      posy=y;
+         
+         //ciclo for nel set di currentCluster, ovvero il set nel mezzo del buffer
+    for(HPSEcalCluster cluster : currentClusters){ 
+    if((cluster.getSeedHit().getIdentifierFieldValue("ix")== posx) && (cluster.getSeedHit().getIdentifierFieldValue("iy")==posy )&& (cluster.getEnergy() > energyThreshold)){
+        
+           if(ClusterChecker(cluster)){
+            int id;
+            Clustercount++;
+           id=getCrystal(cluster);
+           try{
+     writer.append(id + " " + cluster.getEnergy()+ " " + cluster.getSize() + " " + cluster.getSeedHit().getRawEnergy() + " " + cluster.getSeedHit().getIdentifierFieldValue("ix")+" " +cluster.getSeedHit().getIdentifierFieldValue("iy"));
+     /*for(CalorimeterHit hit : cluster.getCalorimeterHits())
+     {writer.append(hit.getRawEnergy()+ " ");
+       }*/
+     writer.append("\n");
+    
+     }
+     
+   catch(IOException e ){System.err.println("Error writing to output for event display");}   
+           
+           }
+      }
+     
+     
+    }
+ 
+ 
+ 
+ }
+ }
+ 
+ 
+ 
+ 
+
+ }
+ /**
+  * Check if the cluster is isolaterd checking if there are clusters near it in time and in space in the buffer
+  * @param cluster
+  * @return 
+  */
+ 
+public boolean ClusterChecker (HPSEcalCluster cluster){
+//System.out.println("Sono nel clustercheck! \n");
+    
+boolean check=true;
+  
+    //ciclo sulle liste del buffer
+loops:
+     for(ArrayList<HPSEcalCluster> currentList : clusterBuffer){
+     //ciclo sui cluster della lista corrente
+         for(HPSEcalCluster currentcluster : currentList){
+           if(currentcluster!= cluster){
+             //if there is a cluster in the buffer that is in the considered radius in a time window lower than expected, the loop is brocken and the analyzed cluster is not good
+         if(!((currentcluster.getSeedHit().getIdentifierFieldValue("ix") < posx-radius || currentcluster.getSeedHit().getIdentifierFieldValue("ix")> posx+radius)&& (currentcluster.getSeedHit().getIdentifierFieldValue("iy")< posy-radius || currentcluster.getSeedHit().getIdentifierFieldValue("iy")> posy+radius))&& Math.abs(cluster.getSeedHit().getTime()-currentcluster.getSeedHit().getTime())<timeDifference){
+         check=false;
+         break loops;
+         }
+           }
+           
+        
+         
+         }
+      
+     
+     }
+        
+        
+   
+return check;
+
+}
+      
+ 
+ 
+ public int getCrystal (HPSEcalCluster cluster){
+ int x,y,id=0;
+ x= (-1)*cluster.getSeedHit().getIdentifierFieldValue("ix");
+ y= cluster.getSeedHit().getIdentifierFieldValue("iy");
+ 
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
+ 
+ public int getCrystal (CalorimeterHit hit){
+ int x,y,id=0;
+ x= (-1)*hit.getIdentifierFieldValue("ix");
+ y= hit.getIdentifierFieldValue("iy");
+ 
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
+ 
+ } //chiusura driver  
+    
+    
+    

java/trunk/users/src/main/java/org/hps/users/luca
mycluster3.java 842 -> 843
--- java/trunk/users/src/main/java/org/hps/users/luca/mycluster3.java	2014-08-08 04:38:43 UTC (rev 842)
+++ java/trunk/users/src/main/java/org/hps/users/luca/mycluster3.java	2014-08-08 12:36:13 UTC (rev 843)
@@ -20,17 +20,17 @@
 
 import org.hps.recon.ecal.ECalUtils;
 import org.hps.recon.ecal.HPSEcalCluster;
-import org.lcsim.event.Cluster;
+
 import org.lcsim.event.EventHeader;
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.aida.AIDA;
 import org.lcsim.util.Driver;
 import hep.aida.*;
-import hep.aida.IHistogram3D;
+
 import java.io.FileWriter;
 import org.lcsim.event.CalorimeterHit;
-import org.lcsim.event.MCParticle;
 
+
 /**
  * 
  * @author Luca Colaneri 
@@ -46,12 +46,15 @@
     private LinkedList<ArrayList<HPSEcalCluster>> clusterBuffer;
     protected String clusterCollectionName = "EcalClusters";
     
- 
- 
+ AIDA aida = AIDA.defaultInstance();
+ IHistogram1D clusterEne=aida.histogram1D("Clusters energy with Luca's trigger",300, 0, 3);
+// ArrayList<IHistogram1D> SeedHistograms = new ArrayList<IHistogram1D>(442);
+  //  ArrayList<IHistogram1D> ClustHistograms = new ArrayList<IHistogram1D>(442);
+ //    ArrayList<IHistogram1D> HitHistograms = new ArrayList<IHistogram1D>(442);
     private FileWriter writer;
-    //private FileWriter writer2;
-    String outputFileName = "ClusterInfonew.txt";
-   // String outputFileName2 = "ClusterEnePos2.txt";
+    private FileWriter writer2;
+    String outputFileName = "LucaTriggerFEE.txt";
+    String outputFileName2 = "LucaTriggerHits.txt";
 
    
  
@@ -71,6 +74,9 @@
    public void setOutputFileName(String outputFileName){
 this.outputFileName = outputFileName;
 }
+   public void setOutputFileName2(String outputFileName2){
+this.outputFileName2 = outputFileName2;
+   }
    public void settimeDifference(double time){
    this.timeDifference=time;
    
@@ -99,10 +105,26 @@
     try{
     //initialize the writers
     writer=new FileWriter(outputFileName);
- //   writer2=new FileWriter(outputFileName2);
+    writer2=new FileWriter(outputFileName2);
     //Clear the files
     writer.write("");
-  //  writer2.write("");
+    writer2.write("");
+    
+     //initialize histograms  
+  /*  for(int t=0; t<442; t++){
+      String cristallo=String.valueOf(t);  
+      String seedhistogram="SeedHit_" + String.valueOf(t);
+      String Clushistogram="Clusters_" + String.valueOf(t);
+      String HitHistogram="Hits_" + String.valueOf(t);
+      
+      IHistogram1D seedhisto=aida.histogram1D(seedhistogram, 150, 0.0,3.0);
+      IHistogram1D clushisto=aida.histogram1D(Clushistogram, 150, 0.0,3.0);
+      IHistogram1D hitshisto=aida.histogram1D(HitHistogram,150,0.0,3.0);
+    SeedHistograms.add(seedhisto);
+    ClustHistograms.add(clushisto);
+    HitHistograms.add(hitshisto);
+    }*/
+    
 }
 catch(IOException e ){
 System.err.println("Error initializing output file for event display.");
@@ -116,7 +138,7 @@
     try{
 //close the file writer.
     writer.close();
-   // writer2.close();
+    writer2.close();
     }
 catch(IOException e){
     System.err.println("Error closing utput file for event display.");
@@ -131,6 +153,7 @@
            
      
      //get the clusters from the event
+    if(TriggerDriver.triggerBit()){ //if they have triggered!
      if(event.hasCollection(HPSEcalCluster.class, "EcalClusters")) {
         List<HPSEcalCluster> clusterList =event.get(HPSEcalCluster.class,clusterCollectionName );    
              
@@ -138,6 +161,7 @@
      
      ArrayList<HPSEcalCluster> clusterSet = new ArrayList<HPSEcalCluster>(); 
      for(HPSEcalCluster cluster : clusterList){
+         clusterEne.fill(cluster.getEnergy());
          TotalCluster++;
          clusterSet.add(cluster);
      }
@@ -147,6 +171,21 @@
     //Run the sorting algorithm;
      ClusterAnalyzer();
      }
+     
+      //get the hits from the event
+     if(event.hasCollection(CalorimeterHit.class,"EcalCorrectedHits")){
+     List<CalorimeterHit> hits =event.get(CalorimeterHit.class,"EcalCorrectedHits");
+     
+        for(CalorimeterHit hit : hits){
+            int id=getCrystal(hit)-1;
+          //  HitHistograms.get(id).fill(hit.getRawEnergy());
+                try{    writer2.append(id + " " + hit.getRawEnergy()+ "\n");}
+                catch(IOException e ){System.err.println("Error writing to output for event display");} 
+        }//end of for cycle
+     }
+     
+    }
+     
 }
 
  
@@ -179,7 +218,8 @@
      {writer.append(hit.getRawEnergy()+ " ");
        }*/
      writer.append("\n");
-    
+  //  SeedHistograms.get(id-1).fill(cluster.getSeedHit().getRawEnergy());
+  //   ClustHistograms.get(id-1).fill(cluster.getEnergy());
      }
      
    catch(IOException e ){System.err.println("Error writing to output for event display");}   
@@ -277,7 +317,7 @@
      if(x>0){
   id=-x+245;}
  else if(x==-1 )id=245;
- else if(x<-1){id=-x+257;}}
+ else if(x<-1){id=-x+235;}}
  
  
  else if(y==-2)
@@ -304,7 +344,71 @@
  
  }
  
+ public int getCrystal (CalorimeterHit hit){
+ int x,y,id=0;
+ x= (-1)*hit.getIdentifierFieldValue("ix");
+ y= hit.getIdentifierFieldValue("iy");
  
+ if(y==5){
+ if(x<0)
+ {id=x+24;}
+ else id= x+23;
+ }
+ 
+ else if(y==4)
+ {if(x<0){
+  id=x+70;}
+ else id=x+69;}
+ 
+ else if(y==3)
+ {if(x<0){
+  id=x+116;}
+ else id=x+115;}
+ 
+ else if(y==2)
+ {if(x<0){
+  id=x+162;}
+ else id=x+161;}
+ 
+ else if(y==1)
+ {x=-x;
+     if(x>0){
+  id=-x+208;}
+ else if(x==-1){id=208;}
+ else if(x<-1) id=-x+198;}
+ 
+  else if(y==-1)
+ {x=-x;
+     if(x>0){
+  id=-x+245;}
+ else if(x==-1 )id=245;
+ else if(x<-1){id=-x+235;}}
+ 
+ 
+ else if(y==-2)
+ {if(x<0){
+  id=x+282;}
+ else id=x+281;}
+ 
+  else if(y==-3)
+ {if(x<0){
+  id=x+328;}
+ else id=x+327;}
+ 
+ else if(y==-4)
+ {if(x<0){
+  id=x+374;}
+ else id=x+373;}
+ 
+ else if(y==-5)
+ {if(x<0){
+  id=x+420;}
+ else id=x+419;}
+ 
+ return id;
+ 
+ }
+ 
  } //chiusura driver  
     
     
SVNspam 0.1