hps-java/src/main/java/org/lcsim/hps/recon/particle
diff -u -r1.4 -r1.5
--- ReconParticleDriver.java 11 Apr 2013 02:37:26 -0000 1.4
+++ ReconParticleDriver.java 12 Apr 2013 17:25:07 -0000 1.5
@@ -32,12 +32,16 @@
*
* @author Mathew Graham <[log in to unmask]>
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: ReconParticleDriver.java,v 1.4 2013/04/11 02:37:26 omoreno Exp $
+ * @version $Id: ReconParticleDriver.java,v 1.5 2013/04/12 17:25:07 omoreno Exp $
*/
public class ReconParticleDriver extends Driver {
SvtTrackExtrapolator extrapolator = new SvtTrackExtrapolator();
-
+
+ // List to contained all tracks which have been matched in an event
+ List<Track> matchedTracks;
+ List<HPSEcalCluster> matchedClusters;
+
// Flags
boolean debug = false;
@@ -108,7 +112,7 @@
Hep3Vector IP = new BasicHep3Vector(0., 0., 1.);
double bfield = event.getDetector().getFieldMap().getField(IP).y();
if (bfield < 0) flipSign = -1;
-
+
// If the event does not have Ecal clusters, skip the event
if (!event.hasCollection(HPSEcalCluster.class, ecalClustersCollectionName)) return;
@@ -122,6 +126,13 @@
List<Track> tracks = event.get(Track.class, tracksCollectionName);
this.printDebug("Number of Tracks: " + tracks.size());
+
+
+ // Instantiate the list of matched tracks and clusters. This list
+ // will be used to check if a track has already been previously matched
+ matchedTracks = new ArrayList<Track>();
+ matchedClusters = new ArrayList<HPSEcalCluster>();
+
reconParticles = new ArrayList<ReconstructedParticle>();
aprimeCands = new ArrayList<ReconstructedParticle>();
aprimeCandsCon = new ArrayList<ReconstructedParticle>();
@@ -129,28 +140,40 @@
electrons = new ArrayList<ReconstructedParticle>();
positrons = new ArrayList<ReconstructedParticle>();
-
- // If there are tracks present in the event, try to match them to an
- // Ecal cluster
- if (!tracks.isEmpty()) {
-
- // Loop over all tracks in the event
- for(Track track : tracks){
+ // If there are clusters and tracks in the event, try to match them
+ // to each other
+ if (!tracks.isEmpty() && !clusters.isEmpty()) {
+
+ // Loop over all Ecal clusters in the event
+ HPSEcalCluster matchedCluster = null;
+ for(HPSEcalCluster cluster : clusters){
- // Set the track to extrapolate
- extrapolator.setTrack(track);
-
+ // If the cluster has already been matched to a track, continue
+ // on to the next cluster
+ if(matchedClusters.contains(cluster)) continue;
+ matchedCluster = cluster;
+
+ // Get the Ecal cluster position
+ Hep3Vector clusterPos = new BasicHep3Vector(cluster.getPosition());
+ this.printDebug("Ecal cluster position: " + clusterPos.toString());
+
+ Track matchedTrack = null;
+ Hep3Vector matchedTrackPosition = null;
double rMax = Double.MAX_VALUE;
- HPSEcalCluster matchedCluster = null;
- // Loop over all Ecal clusters
- for(HPSEcalCluster cluster : clusters){
-
- // Get the Ecal cluster position
- Hep3Vector ecalClusterPos = new BasicHep3Vector(cluster.getPosition());
- this.printDebug("Ecal cluster position: " + ecalClusterPos.toString());
+ // Loop over all tracks in the event
+ for(Track track : tracks){
+
+ // Check if the track has already been matched to another cluster
+ if(matchedTracks.contains(track)){
+ this.printDebug("Track has already been matched");
+ continue;
+ }
+
+ // Set the track to extrapolate
+ extrapolator.setTrack(track);
// Extrapolate the track to the Ecal cluster shower max
- Hep3Vector trkPosAtShowerMax = extrapolator.extrapolateTrack(ecalClusterPos.z());
+ Hep3Vector trkPosAtShowerMax = extrapolator.extrapolateTrack(clusterPos.z());
// Check if any of the extrapolated values are invalid.
// TODO: There are some track whose extrapolated coordinates
// are NaN. The problem seems to be that the y-coordinate
@@ -161,46 +184,64 @@
// Find the distance between the track position at shower
// max and the cluster position
- double r = VecOp.sub(trkPosAtShowerMax, ecalClusterPos).magnitude();
+ double r = VecOp.sub(trkPosAtShowerMax, clusterPos).magnitude();
this.printDebug("Distance between Ecal cluster and track position at shower max: " + r + " mm");
-
- // Check if the cluster is closest to the track
+
+ // Check if the track is the closest to the cluster. If it is, then
+ // save the track and contineu looping over all other tracks
if (r < rMax && r <= maxTrackClusterDistance) {
rMax = r;
- matchedCluster = cluster;
+ matchedTrack = track;
+ matchedTrackPosition = trkPosAtShowerMax;
}
}
-
- // If there isn't a matched cluster found continue to the next
- // track. This will occur when a track is found to have NaN
- // coordinate values as explained above or when a the distance
- // between a cluster and a track fails the maximum track
- // cluster distance.
- if(matchedCluster == null){
+
+ // If a matching track isn't found, continue to the next cluster
+ // in the event. This will occur when a track is found to have
+ // NaN coordinate values as explained above or when the distance
+ // between a cluster and a track fails the maximum track cluster
+ // distance.
+ if(matchedTrack == null){
this.printDebug("No matching cluster found!");
- continue;
- }
-
- // Remove the matched Ecal cluster from the collection of
- // clusters so it's not matched to another track
- clusters.remove(matchedCluster);
- this.printDebug("Remaining number of Ecal clusters: " + clusters.size());
-
- // Create a reconstructed particle and add it to collection of
- // reconstructed particles
- ReconstructedParticle particle = new BaseReconstructedParticle();
- particle.addCluster(matchedCluster);
- particle.addTrack(track);
- reconParticles.add(particle);
-
+ continue;
+ }
+
+ // Check if the track is a closer match to any other cluster in
+ // the event
+ for(HPSEcalCluster ecalCluster : clusters){
+ if(ecalCluster.equals(cluster) || matchedClusters.contains(ecalCluster)) continue;
+
+ Hep3Vector ecalClusterPos = new BasicHep3Vector(ecalCluster.getPosition());
+ this.printDebug("Ecal cluster position: " + ecalClusterPos.toString());
+ extrapolator.setTrack(matchedTrack);
+ Hep3Vector trkPosAtShowerMax = extrapolator.extrapolateTrack(ecalClusterPos.z());
+ this.printDebug("Track position at shower max: " + trkPosAtShowerMax.toString());
+ double r = VecOp.sub(trkPosAtShowerMax, ecalClusterPos).magnitude();
+ if(r < rMax && r <= maxTrackClusterDistance){
+ rMax = r;
+ matchedCluster = ecalCluster;
+ }
+ }
+
+ // Add the track to the list of matched tracks
+ matchedTracks.add(matchedTrack);
+ matchedClusters.add(matchedCluster);
+ this.printDebug("Matched track position: " + matchedTrackPosition.toString());
+ this.printDebug("Matched Cluster Position: " + (new BasicHep3Vector(matchedCluster.getPosition()).toString()));
+
+ // Create a reconstructed particle and add it to the
+ // collection of final state particles
+ ReconstructedParticle particle = new BaseReconstructedParticle();
+ particle.addCluster(matchedCluster);
+ particle.addTrack(matchedTrack);
+ reconParticles.add(particle);
+
// Add the particle to either the collection of possible
// electrons or positrons
- if (track.getCharge() * flipSign > 0){
- positrons.add(particle);
- } else {
- electrons.add(particle);
- }
- }
+ if(matchedTrack.getCharge()*flipSign > 0) positrons.add(particle);
+ else electrons.add(particle);
+
+ }
}
// After iterating through all tracks, if there still