Print

Print


Commit in hps-java/src/main/java/org/lcsim/hps/recon/particle on MAIN
ReconParticleDriver.java+95-481.3 -> 1.4
Extrapolate the track to the shower center instead; Some other fixes so ReconstructedParticles are created correctly

hps-java/src/main/java/org/lcsim/hps/recon/particle
ReconParticleDriver.java 1.3 -> 1.4
diff -u -r1.3 -r1.4
--- ReconParticleDriver.java	21 Mar 2013 17:33:31 -0000	1.3
+++ ReconParticleDriver.java	11 Apr 2013 02:37:26 -0000	1.4
@@ -1,22 +1,30 @@
 package org.lcsim.hps.recon.particle;
 
-import hep.physics.vec.BasicHep3Vector;
-import hep.physics.vec.Hep3Vector;
+//--- java ---//
 import java.util.ArrayList;
 import java.util.List;
+
+//--- hep ---//
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import hep.physics.vec.VecOp;
+
+//--- lcsim ---//
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.ReconstructedParticle;
 import org.lcsim.event.Track;
 import org.lcsim.event.base.BaseReconstructedParticle;
 import org.lcsim.fit.helicaltrack.HelicalTrackFit;
+import org.lcsim.recon.tracking.seedtracker.SeedCandidate;
+import org.lcsim.recon.tracking.seedtracker.SeedTrack;
+import org.lcsim.util.Driver;
+
+//--- hps-java ---//
 import org.lcsim.hps.recon.ecal.HPSEcalCluster;
 import org.lcsim.hps.recon.tracking.SvtTrackExtrapolator;
 import org.lcsim.hps.recon.vertexing.BilliorTrack;
 import org.lcsim.hps.recon.vertexing.BilliorVertex;
 import org.lcsim.hps.recon.vertexing.BilliorVertexer;
-import org.lcsim.recon.tracking.seedtracker.SeedCandidate;
-import org.lcsim.recon.tracking.seedtracker.SeedTrack;
-import org.lcsim.util.Driver;
 
 /**
  * Driver that matches SVT Tracks and Ecal Clusters and creates
@@ -24,11 +32,14 @@
  *
  * @author Mathew Graham <[log in to unmask]>
  * @author Omar Moreno <[log in to unmask]>
- * @version $Id: ReconParticleDriver.java,v 1.3 2013/03/21 17:33:31 omoreno Exp $ 
+ * @version $Id: ReconParticleDriver.java,v 1.4 2013/04/11 02:37:26 omoreno Exp $ 
  */
 public class ReconParticleDriver extends Driver {
 
 	SvtTrackExtrapolator extrapolator = new SvtTrackExtrapolator();
+
+	// Flags
+	boolean debug = false; 
 	
 	// Reconstructed particle collections
 	List<ReconstructedParticle> reconParticles;
@@ -37,10 +48,6 @@
     List<ReconstructedParticle> aprimeCandsTarget;
     List<ReconstructedParticle> electrons;
     List<ReconstructedParticle> positrons;
-
-	
-    double maxXTrackClusterMatchResidual = 100; // [mm]
-    double maxYTrackClusterMatchResidual = 100; // [mm]
     
     // Collections
     String ecalClustersCollectionName 			= "EcalClusters";
@@ -50,23 +57,29 @@
     String aprimeCandidatesConstrainedName 		= "APrimeBeamspotConstrained";
     String aprimeCandidatesTargetName 			= "APrimeTargetConstrained";
     
+    // The beamsize array is in the tracking frame
     double[] beamsize = {0.001, 0.2, 0.02};
-    // flipSign is a kludge...
-//  HelicalTrackFitter doesn't deal with B-fields in -ive Z correctly
-//  so we set the B-field in +iveZ and flip signs of fitted tracks
-//  note:  this should be -1 for Test configurations and +1 for Full (v3.X and lower) configurations
-//  this is set by the _config variable (detType in HeavyPhotonDriver)
+    double maxTrackClusterDistance = 1000; // [mm] 
+    
+     
+    //  flipSign is a kludge...
+    //  HelicalTrackFitter doesn't deal with B-fields in -ive Z correctly
+	//  so we set the B-field in +iveZ and flip signs of fitted tracks
+    //  
+    //  Note:  This should be -1 for Test configurations and +1 for 
+    //         Full (v3.X and lower) configurations this is set by the _config
+    //         variable (detType in HeavyPhotonDriver)
     int flipSign = 1;
 
     public ReconParticleDriver() {
     }
 
-    public void setMaxXTrackClusterMatchResidual(double maxXTrackClusterMatchResidual) {
-        this.maxXTrackClusterMatchResidual = maxXTrackClusterMatchResidual;
+    public void setDebug(boolean debug){
+    	this.debug = debug; 
     }
-
-    public void setMaxYTrackClusterMatchResidual(double maxYTrackClusterMatchResidual) {
-        this.maxYTrackClusterMatchResidual = maxYTrackClusterMatchResidual;
+    
+    public void setMaxTrackClusterDistance(double maxTrackClusterDistance){
+    	this.maxTrackClusterDistance = maxTrackClusterDistance; 
     }
 
     public void setEcalClusterCollectionName(String ecalClustersCollectionName) {
@@ -81,16 +94,17 @@
         this.finalStateParticlesCollectionName = reconParticlesCollectionName;
     }
 
-    public void setBeamSigmaX(double sigma) {
-        beamsize[1] = sigma;  //the beamsize[] array is in tracking frame
+    public void setBeamSigmaX(double sigma_x) {
+        beamsize[1] = sigma_x; 
     }
 
-    public void setBeamSigmaY(double sigma) {
-        beamsize[2] = sigma;   //the beamsize[] array is in tracking frame
+    public void setBeamSigmaY(double sigma_y) {
+        beamsize[2] = sigma_y;  
     }
 
     public void process(EventHeader event) {
-        
+       
+    	// Set the sign of the variable flipSign (See above for details)
     	Hep3Vector IP = new BasicHep3Vector(0., 0., 1.);
         double bfield = event.getDetector().getFieldMap().getField(IP).y();
         if (bfield < 0) flipSign = -1;
@@ -100,9 +114,13 @@
         
         // Get the clusters in the event
         List<HPSEcalCluster> clusters = event.get(HPSEcalCluster.class, ecalClustersCollectionName);
+        if(clusters.isEmpty()) return; 
+        this.printDebug("Number of Ecal clusters: " + clusters.size());
+        
         
         // Get the tracks in the event
         List<Track> tracks = event.get(Track.class, tracksCollectionName);
+        this.printDebug("Number of Tracks: " + tracks.size()); 
 
         reconParticles	= new ArrayList<ReconstructedParticle>();
         aprimeCands 	= new ArrayList<ReconstructedParticle>();
@@ -111,41 +129,62 @@
         electrons = new ArrayList<ReconstructedParticle>();
         positrons = new ArrayList<ReconstructedParticle>();
 
-        // Match tracks to clusters
+        
+        // If there are tracks present in the event, try to match them to an 
+        // Ecal cluster
         if (!tracks.isEmpty()) {
 
-            // Loop over all tracks and find the associated EcalCluster
+            // Loop over all tracks in the event
         	for(Track track : tracks){
         		
-        		// Set the track to extrapolate
+        		// Set the track to extrapolate 
         		extrapolator.setTrack(track);
-        		
-        		// Get the track position at the Ecal
-        		Hep3Vector positionAtEcal = extrapolator.getTrackPositionAtEcal();
-        		
-        		// Iterate over all Ecal clusters and find the cluster which is
-        		// closest to the track
-                double rMax = 1000;
+        			
+                double rMax = Double.MAX_VALUE;
                 HPSEcalCluster matchedCluster = null;
+        		// Loop over all Ecal clusters	
         		for(HPSEcalCluster cluster : clusters){
         			
-        			// Get the cluster position
-        			Hep3Vector clusterPosition = new BasicHep3Vector(cluster.getPosition());
+        			// Get the Ecal cluster position
+        			Hep3Vector ecalClusterPos = new BasicHep3Vector(cluster.getPosition());
+        			this.printDebug("Ecal cluster position: " + ecalClusterPos.toString());
         			
-        			double xDiff = positionAtEcal.x() - clusterPosition.x();
-                    double yDiff = positionAtEcal.y() - clusterPosition.y();
-                    double r = Math.sqrt(xDiff * xDiff + yDiff * yDiff);
-                    
-                    // TODO:  Also need to check if r is less than some maximum optimized value
-                    if (r < rMax) {
+        			// Extrapolate the track to the Ecal cluster shower max
+        			Hep3Vector trkPosAtShowerMax = extrapolator.extrapolateTrack(ecalClusterPos.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
+        			//        of the extrapolated helix is found to be non-real. This
+        			//        needs to be fixed.
+        			if(Double.isNaN(trkPosAtShowerMax.x()) || Double.isNaN(trkPosAtShowerMax.y())) continue; 
+        			this.printDebug("Track position at shower max: " + trkPosAtShowerMax.toString());
+        			
+        			// Find the distance between the track position at shower
+        			// max and the cluster position
+        			double r = VecOp.sub(trkPosAtShowerMax, ecalClusterPos).magnitude();
+        			this.printDebug("Distance between Ecal cluster and track position at shower max: " + r + " mm");
+                   
+        			// Check if the cluster is closest to the track
+                    if (r < rMax && r <= maxTrackClusterDistance) {
                         rMax = r;
                         matchedCluster = cluster;
                     }
         		}
+        	
+        		// 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){
+        			this.printDebug("No matching cluster found!");
+        			continue; 
+        		}
         		
-        		// Remove the matched Ecal cluster from the collection of clusters so 
-        		// its not matched to another track
+        		// 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
@@ -162,8 +201,11 @@
                 	electrons.add(particle);
                 }
         	}
-        }
-
+        } 
+       
+        // After iterating through all tracks, if there still
+        // exist some clusters in the list then assign them 
+        // to their own reconstructed particles
         if (!clusters.isEmpty()) {
             for (HPSEcalCluster cluster : clusters) {
                 ReconstructedParticle particle = new BaseReconstructedParticle();
@@ -220,12 +262,17 @@
             }
         }
 
-        event.put(aprimeCandidatesName, aprimeCands, ReconstructedParticle.class, 0);
         event.put(aprimeCandidatesConstrainedName, aprimeCandsCon, ReconstructedParticle.class, 0);
         event.put(aprimeCandidatesTargetName, aprimeCandsTarget, ReconstructedParticle.class, 0);
+        event.put(aprimeCandidatesName, aprimeCands, ReconstructedParticle.class, 0);
 
     }
 
+    private void printDebug(String debugMessage){
+    	if(debug)
+    		System.out.println(this.getClass().getSimpleName() + ": " + debugMessage); 
+    }
+    
     private BilliorTrack getBilliorTrack(SeedTrack st) {
         SeedTrack stEle = (SeedTrack) st;
         SeedCandidate seedEle = stEle.getSeedCandidate();
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1