hps-java/src/main/java/org/lcsim/hps/recon/tracking
diff -u -r1.2 -r1.3
--- TrackerHitUtils.java 29 Sep 2012 00:24:15 -0000 1.2
+++ TrackerHitUtils.java 22 Oct 2012 21:17:26 -0000 1.3
@@ -1,7 +1,3 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
package org.lcsim.hps.recon.tracking;
import hep.physics.vec.*;
@@ -11,46 +7,47 @@
import java.util.Map;
import org.lcsim.detector.IDetectorElement;
import org.lcsim.detector.ITransform3D;
+import org.lcsim.detector.identifier.ExpandedIdentifier;
+import org.lcsim.detector.identifier.IExpandedIdentifier;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierDictionary;
+import org.lcsim.detector.identifier.IIdentifierHelper;
import org.lcsim.detector.tracker.silicon.ChargeCarrier;
import org.lcsim.detector.tracker.silicon.SiSensor;
import org.lcsim.detector.tracker.silicon.SiSensorElectrodes;
import org.lcsim.event.RawTrackerHit;
import org.lcsim.event.SimTrackerHit;
-import org.lcsim.event.Track;
import org.lcsim.fit.helicaltrack.HelicalTrackFit;
import org.lcsim.fit.helicaltrack.HelicalTrackStrip;
import org.lcsim.fit.helicaltrack.HelixUtils;
import org.lcsim.hps.event.HPSTransformations;
-import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHit;
-import org.lcsim.recon.tracking.digitization.sisim.SiTrackerHitStrip1D;
-import org.lcsim.recon.tracking.seedtracker.SeedCandidate;
-import org.lcsim.recon.tracking.seedtracker.SeedTrack;
/**
*
- * @author phansson
+ * @author Per Hansson <[log in to unmask]>
+ * @version $Id: TrackerHitUtils.java,v 1.3 2012/10/22 21:17:26 omoreno Exp $
*/
public class TrackerHitUtils {
-
+
private boolean _DEBUG = false;
private HPSTransformations _detToTrk = new HPSTransformations();
public TrackerHitUtils() {
}
-
+
public TrackerHitUtils(boolean debug) {
_DEBUG = debug;
}
-
+
public void setDebug(boolean debug) {
_DEBUG = debug;
}
-
+
public Hep3Matrix detToTrackRotationMatrix() {
return (BasicHep3Matrix) _detToTrk.getMatrix();
}
-
+
public ITransform3D GetGlobalToLocal(HelicalTrackStrip strip) {
//Transform from JLab frame (RawTrackerHit) to sensor frame (i.e. u,v,w)
RawTrackerHit rth = (RawTrackerHit) strip.rawhits().get(0);
@@ -59,10 +56,10 @@
SiSensorElectrodes electrodes = sensor.getReadoutElectrodes(ChargeCarrier.HOLE);
return electrodes.getGlobalToLocal();
}
-
+
public Hep3Matrix getStripToTrackRotation(HelicalTrackStrip strip) {
//This function transforms the hit to the tracking coordinates
-
+
//Transform from JLab frame to sensor frame (done through the RawTrackerHit)
ITransform3D detToStrip = GetGlobalToLocal(strip);
//Get rotation matrix
@@ -81,10 +78,10 @@
return (Hep3Matrix) VecOp.mult(detToTrackMatrix,VecOp.inverse(detToStripMatrix));
}
-
- public Hep3Matrix getTrackToStripRotation(HelicalTrackStrip strip) {
+
+ public Hep3Matrix getTrackToStripRotation(HelicalTrackStrip strip) {
//This function transforms the hit to the sensor coordinates
-
+
//Transform from JLab frame to sensor frame (done through the RawTrackerHit)
ITransform3D detToStrip = this.GetGlobalToLocal(strip);
//Get rotation matrix
@@ -105,9 +102,8 @@
}
-
- public Hep3Vector getClusterPosition(HelicalTrackStrip strip, boolean stripInTrackingFrame)
- {
+
+ public Hep3Vector getClusterPosition(HelicalTrackStrip strip, boolean stripInTrackingFrame) {
if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " getClusterPosition--");
Hep3Vector origin = stripInTrackingFrame ? strip.origin() : VecOp.mult(_detToTrk.getMatrix(),strip.origin());
if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " origin " + origin.toString());
@@ -119,17 +115,17 @@
if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " hit_vec_TRACK " + hit_vec_TRACK.toString());
Hep3Vector strip_pos = VecOp.add(origin, hit_vec_TRACK);
if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " strip_pos " + strip_pos.toString());
-
-// Hep3Vector hit_vec_LOCAL_dep = new BasicHep3Vector(strip.umeas(),0,0.16);
-// if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " hit_vec_LOCAL_dep " + hit_vec_LOCAL_dep.toString());
-// Hep3Vector hit_vec_TRACK_dep = VecOp.mult(stripToTrack, hit_vec_LOCAL_dep);
-// Hep3Vector strip_pos_dep = VecOp.add(origin, hit_vec_TRACK_dep);
-// if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " strip_pos ALTERNATE " + strip_pos_dep.toString());
-
+
+ // Hep3Vector hit_vec_LOCAL_dep = new BasicHep3Vector(strip.umeas(),0,0.16);
+ // if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " hit_vec_LOCAL_dep " + hit_vec_LOCAL_dep.toString());
+ // Hep3Vector hit_vec_TRACK_dep = VecOp.mult(stripToTrack, hit_vec_LOCAL_dep);
+ // Hep3Vector strip_pos_dep = VecOp.add(origin, hit_vec_TRACK_dep);
+ // if(_DEBUG) System.out.println(this.getClass().getSimpleName() + " strip_pos ALTERNATE " + strip_pos_dep.toString());
+
return strip_pos;
}
-
- public Hep3Vector CalculateStripUncertaintyInGlobalFrame(HelicalTrackStrip strip, HelicalTrackFit trk, double msdrdphi, double msdz) {
+
+ public Hep3Vector CalculateStripUncertaintyInGlobalFrame(HelicalTrackStrip strip, HelicalTrackFit trk, double msdrdphi, double msdz) {
if(_DEBUG) System.out.println("--- CalculateStripUncertainyInGlobalFrame ---");
if(_DEBUG) System.out.println("Strip origin = " + strip.origin().toString());
@@ -137,7 +133,7 @@
Hep3Vector v = strip.v();
Hep3Vector w = strip.w();
Hep3Vector corigin = strip.origin();
-
+
double phi0 = trk.phi0();
double R = trk.R();
double xint = strip.origin().x();
@@ -147,7 +143,7 @@
if(_DEBUG) System.out.println("phi0 " + phi0 + " R " + R + " xint " + xint + " s " + s + " phi " + phi);
//if(_DEBUG) System.out.println("trkpos = "+trkpos.toString());
//if(_DEBUG) System.out.println("origin = "+corigin.toString());
-
+
Hep3Vector mserr = new BasicHep3Vector(msdrdphi * Math.sin(phi), msdrdphi * Math.sin(phi), msdz);
if(_DEBUG) System.out.println("msdrdphi = " + msdrdphi + " msdz = " + msdz);
if(_DEBUG) System.out.println("mserr = " + mserr.toString());
@@ -164,7 +160,7 @@
double mswError = VecOp.dot(mserr, w);
double wError = Math.sqrt(wHitError * wHitError + mswError * mswError);
if(_DEBUG) System.out.println("wError = " + wError + "(MS "+mswError + ",w=" + w.toString()+")");
-
+
Hep3Vector dq_local = new BasicHep3Vector(uError,vError,wError);
if(_DEBUG) System.out.println("dq_local = " + dq_local.toString());
Hep3Matrix trackToStripRot = getTrackToStripRotation(strip);
@@ -175,13 +171,12 @@
if(_DEBUG) System.out.println("q_global = " + dq_global.toString());
return dq_global;
}
-
- public List<SimTrackerHit> stripClusterToSimHits(HelicalTrackStrip strip, List<SimTrackerHit> simTrackerHits, boolean stripsInTrackingFrame)
- {
-
+
+ public List<SimTrackerHit> stripClusterToSimHits(HelicalTrackStrip strip, List<SimTrackerHit> simTrackerHits, boolean stripsInTrackingFrame){
+
int layer = strip.layer();
Hep3Vector stripPosition = this.getClusterPosition(strip,stripsInTrackingFrame);
-
+
// Sort the SimTrackerHits by Layer
Map<Integer, List<SimTrackerHit>> layerToSimTrackerHit = new HashMap<Integer, List<SimTrackerHit>>();
for(SimTrackerHit simTrackerHit : simTrackerHits){
@@ -189,7 +184,7 @@
layerToSimTrackerHit.put(simTrackerHit.getLayer(), new ArrayList<SimTrackerHit>());
layerToSimTrackerHit.get(simTrackerHit.getLayer()).add(simTrackerHit);
}
-
+
//
List<SimTrackerHit> simhits = new ArrayList<SimTrackerHit>();
@@ -231,27 +226,50 @@
System.out.println(this.getClass().getSimpleName() + ": Cluster position: " + stripPosition);
}
}
-
-
+
+
return simhits;
}
-
-// public List<SiTrackerHit> stripClusterToSiHits(HelicalTrackStrip strip, List<SiTrackerHit> siTrackerHits, boolean stripsInTrackingFrame)
-// {
-//
-// //Should be a one to one match with a strip!
-// Hep3Vector stripPosition = this.getClusterPosition(strip,stripsInTrackingFrame);
-// if(_DEBUG) System.out.println("Strip position " + stripPosition.toString() + " ( " + strip.origin().toString() + ")");
-//
-// for(SiTrackerHit siTrackerHit : siTrackerHits){
-// SiTrackerHitStrip1D h = (SiTrackerHitStrip1D) siTrackerHit;
-// if(_DEBUG) System.out.println("SiTrackerHit origin position " + h.getPositionAsVector().toString());
-//
-// }
-//
-// List<SiTrackerHit> hits = new ArrayList<SiTrackerHit>();
-// return hits;
-//
-// }
+
+ /**
+ * Make a SimTrackerHit {@link IIdentifier} for a given layer number
+ *
+ * @param sensor : The sensor on which the SimTrackerHit is created on
+ * @return A 32-bit SimTrackerHit identifier
+ */
+ public static IIdentifier makeSimTrackerHitId(SiSensor sensor){
+
+ // Get the sensors identifier
+ IExpandedIdentifier id = new ExpandedIdentifier(sensor.getExpandedIdentifier());
+
+ // Get the helper and dictionary
+ IIdentifierHelper helper = sensor.getIdentifierHelper();
+ IIdentifierDictionary dictionary = helper.getIdentifierDictionary();
+
+ // Fill in the layer number
+ id.setValue(dictionary.getFieldIndex("layer"), SvtUtils.getInstance().getLayerNumber(sensor));
+
+ // Pack and return the identifier
+ return helper.pack(id);
+
+ }
+
+ // public List<SiTrackerHit> stripClusterToSiHits(HelicalTrackStrip strip, List<SiTrackerHit> siTrackerHits, boolean stripsInTrackingFrame)
+ // {
+ //
+ // //Should be a one to one match with a strip!
+ // Hep3Vector stripPosition = this.getClusterPosition(strip,stripsInTrackingFrame);
+ // if(_DEBUG) System.out.println("Strip position " + stripPosition.toString() + " ( " + strip.origin().toString() + ")");
+ //
+ // for(SiTrackerHit siTrackerHit : siTrackerHits){
+ // SiTrackerHitStrip1D h = (SiTrackerHitStrip1D) siTrackerHit;
+ // if(_DEBUG) System.out.println("SiTrackerHit origin position " + h.getPositionAsVector().toString());
+ //
+ // }
+ //
+ // List<SiTrackerHit> hits = new ArrayList<SiTrackerHit>();
+ // return hits;
+ //
+ // }
}