Print

Print


Commit in lcsim/src/org/lcsim/contrib/tracking on MAIN
TrackerHitSmearing.java+90added 1.1
New class to smear hit positions and return smearing covariance matrix

lcsim/src/org/lcsim/contrib/tracking
TrackerHitSmearing.java added at 1.1
diff -N TrackerHitSmearing.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TrackerHitSmearing.java	19 Jul 2007 17:57:29 -0000	1.1
@@ -0,0 +1,90 @@
+/*
+ * TrackerHitSmearing.java
+ *
+ * Created on July 18, 2007, 11:51 AM
+ *
+ */
+
+package org.lcsim.contrib.tracking;
+
+import hep.physics.matrix.SymmetricMatrix;
+import hep.physics.vec.BasicHep3Vector;
+import hep.physics.vec.Hep3Vector;
+import java.util.Random;
+
+/**
+ * This class smears hit positions and returns the covariance matrix associated with the smearing.
+ * Gaussian smearing is performed using the java.util.Random class.
+ * Currently, only smearing in the azimuthal (r*phi) and z coordinates is performed.
+ * @author Richard Partridge
+ */
+public class TrackerHitSmearing {
+    Random rn = new Random();
+    double drphi;
+    double dz;
+    
+    /**
+     * Creates a new instance of TrackerHitSmearing
+     * @param drphi RMS of smearing in the azimuthal coordinate r*phi
+     * @param dz RMS of smearing in the z coordinate
+     */
+    public TrackerHitSmearing(double drphi, double dz) {
+        this.drphi = drphi;
+        this.dz = dz;
+    }
+    /**
+     * Creates a new instance of TrackerHitSmearing
+     * @param drphi RMS of smearing in the azimuthal coordinate r*phi
+     * @param dz RMS of smearing in the z coordinate
+     * @param seed Initial random number seed
+     */
+    public TrackerHitSmearing(double drphi, double dz, long seed) {
+        this.drphi = drphi;
+        this.dz = dz;
+        rn.setSeed(seed);
+    }
+    
+    /**
+     * Smear the hit position
+     * @param pos Unsmeared hit position
+     * @return Smeared hit position
+     */
+    public Hep3Vector SmearedPosition(Hep3Vector pos) {
+        double x = pos.x();
+        double y = pos.y();
+        double z = pos.z();
+        double r = Math.sqrt(x*x + y*y);
+        // Smear the phi coordinate of the hit position and re-calculate the cartesian coordinates
+        if (r>0) {
+            double phi = Math.atan2(y,x);
+            phi = phi + (drphi / r) * rn.nextGaussian();
+            x = r * Math.cos(phi);
+            y = r * Math.sin(phi);
+        }
+        // Smear the z coordinate of the hit position
+        z = z + dz * rn.nextGaussian();
+        // Return the smeared hit position as a new Hep3Vector
+        Hep3Vector smpos = new BasicHep3Vector(x,y,z);
+        return smpos;
+    }
+    
+    /**
+     * Calculate the covariance matrix for the hit smearing
+     * @param pos Unsmeared hit position
+     * @return Covariance matrix for hit smearing
+     */
+    public SymmetricMatrix getCovariance(Hep3Vector pos) {
+        // covariance matrix
+        SymmetricMatrix cov = new SymmetricMatrix(3);
+        double x = pos.x();
+        double y = pos.y();
+        double r = Math.sqrt(x*x + y*y);
+        cov.setElement(0,0,Math.pow(y*drphi/r,2));
+        cov.setElement(1,0,-x*y*Math.pow(drphi/r,2));
+        cov.setElement(1,1,Math.pow(x*drphi/r,2));
+        cov.setElement(2,0,0.);
+        cov.setElement(2,1,0.);
+        cov.setElement(2,2,dz*dz);
+        return cov;
+    }
+}
CVSspam 0.2.8