Author: [log in to unmask] Date: Wed Feb 11 11:51:12 2015 New Revision: 2107 Log: Adding HPS specific cluster property calculators. (Not used in reconstruction right now.) Added: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/HardwareClusterPropertyCalculator.java java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ReconClusterPropertyCalculator.java Added: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/HardwareClusterPropertyCalculator.java ============================================================================= --- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/HardwareClusterPropertyCalculator.java (added) +++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/HardwareClusterPropertyCalculator.java Wed Feb 11 11:51:12 2015 @@ -0,0 +1,42 @@ +package org.hps.recon.ecal.cluster; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.hps.recon.ecal.cluster.ClusterUtilities.UniqueEnergyComparator; +import static org.hps.recon.ecal.cluster.ClusterUtilities.isHardwareCluster; +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.Cluster; +import org.lcsim.event.base.AbstractClusterPropertyCalculator; + +/** + * Cluster property calculator for hardware clusters. + * @author Jeremy McCormick <[log in to unmask]> + */ +public class HardwareClusterPropertyCalculator extends AbstractClusterPropertyCalculator { + + @Override + public void calculateProperties(List<CalorimeterHit> hits) { + reset(); + List<CalorimeterHit> sortedHits = new ArrayList<CalorimeterHit>(hits); + Collections.sort(sortedHits, new UniqueEnergyComparator()); + CalorimeterHit seedHit = sortedHits.get(0); + this.position = new double[] {seedHit.getPosition()[0], seedHit.getPosition()[1], seedHit.getPosition()[2]}; + } + + @Override + public void calculateProperties(Cluster cluster) { + reset(); + if (isHardwareCluster(cluster)) { + setPositionFromSeedHit(cluster); + } else { + throw new IllegalArgumentException("The cluster has the wrong type: " + ClusterType.getClusterType(cluster.getType()).toString()); + } + } + + void setPositionFromSeedHit(Cluster cluster) { + CalorimeterHit seedHit = ClusterUtilities.findSeedHit(cluster); + this.position = new double[] {seedHit.getPosition()[0], seedHit.getPosition()[1], seedHit.getPosition()[2]}; + } +} Added: java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ReconClusterPropertyCalculator.java ============================================================================= --- java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ReconClusterPropertyCalculator.java (added) +++ java/trunk/ecal-recon/src/main/java/org/hps/recon/ecal/cluster/ReconClusterPropertyCalculator.java Wed Feb 11 11:51:12 2015 @@ -0,0 +1,60 @@ +package org.hps.recon.ecal.cluster; + +import hep.physics.vec.Hep3Vector; + +import java.util.List; + +import org.lcsim.detector.converter.compact.EcalCrystal; +import org.lcsim.event.CalorimeterHit; +import org.lcsim.event.Cluster; +import org.lcsim.event.base.AbstractClusterPropertyCalculator; + +class ReconClusterPropertyCalculator extends AbstractClusterPropertyCalculator { + + public void calculateProperties(List<CalorimeterHit> hits) { + // This is unsupported because the cluster's energy is required for the position algorithm. + throw new IllegalArgumentException("This method is not supported for recon clustering."); + } + + /** + * Calculates the position of each cluster with no correction for particle type, + * as documented in HPS Note 2014-001. + * @param cluster The input Cluster. + */ + public void calculateProperties(Cluster cluster) { + + reset(); + + // Calculate the position of the cluster. + calculatePosition(cluster); + } + + private void calculatePosition(Cluster cluster) { + final double w0 = 3.1; + double xCl = 0.0; + // calculated cluster y position + double yCl = 0.0; + double eNumX = 0.0; + double eNumY = 0.0; + double eDen = 0.0; + List<CalorimeterHit> clusterHits = cluster.getCalorimeterHits(); + for (CalorimeterHit hit : clusterHits) { + + EcalCrystal crystal = (EcalCrystal) hit.getDetectorElement(); + Hep3Vector crystalPosition = crystal.getPositionFront(); + + eNumX += Math.max(0.0, (w0 + Math.log(hit.getCorrectedEnergy() / cluster.getEnergy()))) * (crystalPosition.x() / 10.0); + eNumY += Math.max(0.0, (w0 + Math.log(hit.getCorrectedEnergy() / cluster.getEnergy()))) * (crystalPosition.y() / 10.0); + eDen += Math.max(0.0, (w0 + Math.log(hit.getCorrectedEnergy() / cluster.getEnergy()))); + + } // end for iteration through clusterHits + + xCl = eNumX / eDen; + yCl = eNumY / eDen; + + position[0] = xCl * 10.0;// mm + position[1] = yCl * 10.0;// mm + CalorimeterHit seedHit = clusterHits.get(0); + this.position[2] = ((EcalCrystal)seedHit.getDetectorElement()).getPositionFront().z(); + } +}